From: Peter Hedlund Date: Tue, 1 Nov 2005 02:25:35 +0000 (+0000) Subject: This moves the new KEduVocDocument class and related classes to libkdeedu/kdeeducore... X-Git-Tag: v3.80.2~237 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=ebdf711161033571b9ba23a0b856c5e07886fa89;p=libqmvoc.git This moves the new KEduVocDocument class and related classes to libkdeedu/kdeeducore. Currently used by KWordQuiz, but other applications using kvtml files are encouraged to use theses classes to prevent data loss for the user when using the same vocabulary file in different programs. All are encouraged to help refine the code and provide comments. CCMAIL:kde-edu@kde.org svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=476300 --- ebdf711161033571b9ba23a0b856c5e07886fa89 diff --cc kdeeducore/Makefile.am index 57110b5,0000000..235d770 mode 100644,000000..100644 --- a/kdeeducore/Makefile.am +++ b/kdeeducore/Makefile.am @@@ -1,17 -1,0 +1,23 @@@ - INCLUDES= $(all_includes) ++INCLUDES = $(all_includes) +# there's nothing in tests for the moment, so I'm removing it from the compilation +#SUBDIRS = . tests +SUBDIRS = . + +lib_LTLIBRARIES = libkdeeducore.la + - libkdeeducore_la_SOURCES = keduvocdata.cpp - libkdeeducore_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 3:0:2 ++libkdeeducore_la_SOURCES = keduvocdata.cpp keduvocdocument.cpp \ ++ keduvocexpression.cpp keduvocgrammar.cpp keduvockvtmlreader.cpp keduvockvtmlwriter.cpp \ ++ keduvocmultiplechoice.cpp keduvowqlreader.cpp keduvowqlwriter.cpp leitnerbox.cpp \ ++ leitnersystem.cpp leitnersystemview.cpp prefleitner.cpp prefleitnerbase.ui ++libkdeeducore_la_LDFLAGS = -no-undefined $(all_libraries) -version-info 3:0:2 + - libkdeeducode_includedir = $(includedir)/libkdeedu - libkdeeducode_include_HEADERS = keduvocdata.h ++libkdeeducore_includedir = $(includedir)/libkdeedu ++libkdeeducore_include_HEADERS = keduvocdata.h keduvocdocument.h \ ++ keduvocexpression.h keduvocgrammar.h keduvockvtmlreader.h keduvockvtmlwriter.h \ ++ keduvocmultiplechoice.h keduvowqlreader.h keduvowqlwriter.h leitnerbox.h leitnersystem.h \ ++ leitnersystemview.h prefleitner.h + - libkdeeducore_la_LIBADD = $(LIB_KDECORE) ++libkdeeducore_la_LIBADD = $(LIB_KDECORE) $(LIB_KFILE) + +METASOURCES = AUTO + diff --cc kdeeducore/keduvocdocument.cpp index 0000000,75f5eba..dd9e315 mode 000000,100644..100644 --- a/kdeeducore/keduvocdocument.cpp +++ b/kdeeducore/keduvocdocument.cpp @@@ -1,0 -1,1174 +1,1174 @@@ + /*************************************************************************** + Vocabulary Document for KDE Edu + ----------------------------------------------------------------------- + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund + ***************************************************************************/ + + /*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + + #include "keduvocdocument.h" + + #include + #include + #include + #include + + #include + #include + #include + #include + #include + + #include "keduvockvtmlwriter.h" + #include "keduvockvtmlreader.h" + #include "keduvocwqlwriter.h" + #include "keduvocwqlreader.h" + #include "leitnersystem.h" + + //******************************************************** + // KEduVocDocument + //******************************************************** + + KEduVocDocument::KEduVocDocument(QObject */*parent*/) + { + Init(); + } + + + KEduVocDocument::~KEduVocDocument() + { + delete m_font; + } + + + void KEduVocDocument::setVersion (const QString & vers) + { + m_version = vers; + } + + + void KEduVocDocument::version(int &, int &, int &) + { + } + + + void KEduVocDocument::Init () + { + m_lessonDescriptions.clear(); + m_typeDescriptions.clear(); + m_tenseDescriptions.clear(); + m_identifiers.clear(); + m_sortIdentifier.clear(); + m_extraSizeHints.clear(); + m_sizeHints.clear(); + m_vocabulary.clear(); + m_dirty = false; + m_enableSorting = true; + m_unknownAttribute = false; + m_unknownElement = false; + m_sortLesson = false; + setCurrentLesson (0); + m_queryorg = ""; + m_querytrans = ""; + m_url.setFileName(i18n("Untitled")); + m_title = ""; + m_author = ""; + m_remark = ""; + m_version = ""; + m_font = NULL; + + m_activeLeitnerSystem = false; + m_leitnerSystem = NULL; + } + + + bool KEduVocDocument::open(const KURL& url, bool /*append*/) + { + Init(); + if (!url.isEmpty()) + m_url = url; + + // TODO EPT connect( this, SIGNAL(progressChanged(KEduVocDocument*,int)), parent, SLOT(slotProgress(KEduVocDocument*,int)) ); + + QString tmpfile; + if (KIO::NetAccess::download( url, tmpfile, 0 )) + { + QFile f(tmpfile); + if (!f.open(QIODevice::ReadOnly)) + { + KMessageBox::error(0, i18n("Cannot open file
%1
").arg(url.path())); + return false; + } + + FileType ft = detectFileType(url.path()); + + bool read = false; + while (!read) { + + QApplication::setOverrideCursor( Qt::WaitCursor ); + switch (ft) { + case kvtml: + { + KEduVocKvtmlReader kvtmlReader(&f); + read = kvtmlReader.readDoc(this); + } + break; + + case wql: + { + KEduVocWqlReader wqlReader(&f); + read = wqlReader.readDoc(this); + } + break; + + case vt_lex: + { + QTextStream is (&f); + //TODO read = loadFromLex (is); + } + break; + + case vt_vcb: + { + QTextStream is (&f); + //TODO read = loadFromVcb (is); + } + break; + + case csv: + { + QTextStream is(&f); + //TODO read = loadFromCsv(is); + } + break; + + default: + { + KEduVocKvtmlReader kvtmlReader(&f); + read = kvtmlReader.readDoc(this); + } + } + + QApplication::restoreOverrideCursor(); + + if (!read) { + if (m_unknownAttribute || m_unknownElement ) { + Init(); + return false; + } + // TODO new readers provide an explicite error message + // the two messages should be merged + QString format = i18n("Could not load \"%1\"\nDo you want to try again?"); + QString msg = format.arg(url.path()); + int result = KMessageBox::warningContinueCancel(0, msg, + kapp->makeStdCaption(i18n("I/O Failure")), + i18n("&Retry")); + if ( result == KMessageBox::Cancel ) { + Init(); + return false; + } + } + } + f.close(); + KIO::NetAccess::removeTempFile( tmpfile ); + } + return true; + } + + + bool KEduVocDocument::saveAs(QObject *parent, const KURL & url, FileType ft, const QString & generator) + { + connect( this, SIGNAL(progressChanged(KEduVocDocument*,int)), parent, SLOT(slotProgress(KEduVocDocument*,int)) ); + + KURL tmp (url); + + if (ft == automatic) + { + if (tmp.path().right(strlen("." KVTML_EXT)) == "." KVTML_EXT) + ft = kvtml; + else if (tmp.path().right(strlen("." WQL_EXT)) == "." WQL_EXT) + ft = wql; + else if (tmp.path().right(strlen("." VT5_LEX_EXT)) == "." VT5_LEX_EXT) + ft = vt_lex; + else if (tmp.path().right(strlen("." VCB_EXT)) == "." VCB_EXT) + ft = vt_vcb; + else if (tmp.path().right(strlen("." CSV_EXT)) == "." CSV_EXT) + ft = csv; + else + { + tmp.setFileName(tmp.path() + "." KVTML_EXT); + ft = kvtml; + } + } + + bool saved = false; + while (!saved) + { + + QFile f(tmp.path()); + + if (!f.open(QIODevice::WriteOnly)) + { + KMessageBox::error(0, i18n("Cannot write to file
%1
").arg(tmp.path())); + return false; + } + + QApplication::setOverrideCursor(Qt::WaitCursor); + switch (ft) { + case kvtml: { + KEduVocKvtmlWriter kvtmlWriter(&f); + saved = kvtmlWriter.writeDoc(this, generator); + } + break; + + case wql: { + KEduVocWqlWriter wqlWriter(&f); + saved = wqlWriter.writeDoc(this); + } + break; + + case vt_lex: { + QTextStream os( &f ); // serialize using f + //TODO saved = saveToLex(os, title); + } + break; + + case vt_vcb: { + QTextStream os( &f ); // serialize using f + //TODO saved = saveToVcb(os, title); + } + break; + + case csv: { + QTextStream os( &f ); // serialize using f + //TODO saved = saveToCsv(os, title); + } + break; + + default: { + kdError() << "kvcotrainDoc::saveAs(): unknown filetype" << endl; + } + break; + } + f.close(); + QApplication::restoreOverrideCursor(); + + if (!saved) { + // TODO new writers provide an explicite error message + // the two messages should be merged + QString format = i18n("Could not save \"%1\"\nDo you want to try again?"); + QString msg = format.arg(tmp.path()); + int result = KMessageBox::warningContinueCancel(0, msg, + kapp->makeStdCaption(i18n("I/O Failure")), + i18n("&Retry")); + if ( result == KMessageBox::Cancel ) return false; + } + } + m_url = tmp; + m_dirty = false; + emit docModified(false); + return true; + } + + + KEduVocExpression *KEduVocDocument::entry(int index) + { + if (index < 0 || index >= (int)m_vocabulary.size() ) + return 0; + else + return &m_vocabulary[index]; + } + + + void KEduVocDocument::removeEntry(int index) + { + if (index >= 0 && index < (int)m_vocabulary.size() ) + m_vocabulary.removeAt( index ); + } + + + int KEduVocDocument::findIdentifier(const QString &lang) const + { + QStringList::const_iterator first = m_identifiers.begin(); + int count = 0; + while (first != m_identifiers.end()) { + if ( *first == lang) + return count; + first++; + count++; + } + return -1; + } + + + QString KEduVocDocument::identifier(int index) const + { + if (index >= (int)m_identifiers.size() || index < 1 ) + return ""; + else + return m_identifiers[index]; + } + + + void KEduVocDocument::setIdentifier(int idx, const QString &id) + { + if (idx < (int)m_identifiers.size() && idx >= 1 ) { + m_identifiers[idx] = id; + } + } + + + QString KEduVocDocument::typeName (int index) const + { + if (index >= (int)m_typeDescriptions.count()) + return ""; + else + return m_typeDescriptions[index]; + } + + + void KEduVocDocument::setTypeName(int idx, QString &id) + { + if (idx >= (int)m_typeDescriptions.size()) + for (int i = (int)m_typeDescriptions.size(); i <= idx; i++) + m_typeDescriptions.push_back (""); + + m_typeDescriptions[idx] = id; + } + + + QString KEduVocDocument::tenseName(int index) const + { + if (index >= (int)m_tenseDescriptions.size()) + return ""; + else + return m_tenseDescriptions[index]; + } + + + void KEduVocDocument::setTenseName(int idx, QString &id) + { + if (idx >= (int)m_tenseDescriptions.size()) + for (int i = (int)m_tenseDescriptions.size(); i <= idx; i++) + m_tenseDescriptions.push_back (""); + + m_tenseDescriptions[idx] = id; + } + + + QString KEduVocDocument::usageName(int index) const + { + if (index >= (int)m_usageDescriptions.size()) + return ""; + else + return m_usageDescriptions[index]; + } + + + void KEduVocDocument::setUsageName(int idx, QString &id) + { + if (idx >= (int)m_usageDescriptions.size()) + for (int i = (int)m_usageDescriptions.size(); i <= idx; i++) + m_usageDescriptions.push_back (""); + + m_usageDescriptions[idx] = id; + } + + + void KEduVocDocument::setConjugation(int idx, const KEduVocConjugation &con) + { + if ( idx < 0) return; + + // extend conjugation with empty elements + if ((int)m_conjugations.size() <= idx ) + for (int i = m_conjugations.size(); i < idx+1; i++) + m_conjugations.push_back (KEduVocConjugation()); + + m_conjugations[idx] = con; + } + + + KEduVocConjugation KEduVocDocument::conjugation (int idx) const + { + if (idx >= (int)m_conjugations.size() || idx < 0) { + return KEduVocConjugation(); + } + else { + return m_conjugations[idx]; + } + } + + + void KEduVocDocument::setArticle(int idx, const KEduVocArticle &art) + { + if ( idx < 0) return; + + // extend conjugation with empty elements + if ((int)m_articles.size() <= idx ) + for (int i = m_articles.size(); i < idx+1; i++) + m_articles.push_back (KEduVocArticle()); + + m_articles[idx] = art; + } + + + KEduVocArticle KEduVocDocument::article (int idx) const + { + if (idx >= (int)m_articles.size() || idx < 0) { + return KEduVocArticle(); + } + else { + return m_articles[idx]; + } + } + + + int KEduVocDocument::sizeHint (int idx) const + { + if (idx < 0) { + idx = -idx; + if (idx >= (int)m_extraSizeHints.size() ) + return 80; // make a good guess about column size + else { + // cout << "gsh " << idx << " " << extraSizehints[idx] << endl; + return m_extraSizeHints[idx]; + } + } + else { + if (idx >= (int)m_sizeHints.size() ) + return 150; // make a good guess about column size + else { + // cout << "gsh " << idx << " " << sizehints[idx] << endl; + return m_sizeHints[idx]; + } + } + } + + + void KEduVocDocument::setSizeHint (int idx, const int width) + { + // cout << "ssh " << idx << " " << width << endl; + if (idx < 0) { + idx = -idx; + if (idx >= (int)m_extraSizeHints.size()) { + for (int i = (int)m_extraSizeHints.size(); i <= idx; i++) + m_extraSizeHints.push_back (80); + } + m_extraSizeHints[idx] = width; + + } + else { + if (idx >= (int)m_sizeHints.size()) { + for (int i = (int)m_sizeHints.size(); i <= idx; i++) + m_sizeHints.push_back (150); + } + m_sizeHints[idx] = width; + } + } + + /* + class eraseTrans : public unary_function + { + + public: + + eraseTrans (int idx) + : index (idx) {} + + void operator() (KEduVocExpression& x) const + { + x.removeTranslation(index); + } + + private: + int index; + }; + */ + + void KEduVocDocument::removeIdentifier(int index) + { + if (index < (int)m_identifiers.size() && index >= 1 ) + { + m_identifiers.takeAt(index); + foreach( KEduVocExpression exp, m_vocabulary ) + exp.removeTranslation(index); + } + } + + + QString KEduVocDocument::originalIdentifier() const + { + if (m_identifiers.size() > 0) + return m_identifiers[0]; + else + return ""; + } + + + void KEduVocDocument::setOriginalIdentifier(const QString &id) + { + if (m_identifiers.size() > 0) { + m_identifiers[0] = id; + } + } + + /* + class sortByOrg : public binary_function + { + + public: + + sortByOrg (bool _dir) + : dir (_dir) {} + + bool operator() (const KEduVocExpression& x, const KEduVocExpression& y) const + { + return + !dir + ? (QString::compare(x.original().upper(), + y.original().upper() ) < 0) + : (QString::compare(x.original().upper(), + y.original().upper() ) > 0); + } + + private: + bool dir; + }; + + + class sortByLessonAndOrg_alpha + : public binary_function + { + + public: + + sortByLessonAndOrg_alpha (bool _dir, KEduVocDocument &_doc) + : dir (_dir), doc(_doc) {} + + bool operator() (const KEduVocExpression& x, const KEduVocExpression& y) const + { + if (x.lesson() != y.lesson() ) + return + !dir + ? (QString::compare(doc.lessonDescription(x.lesson()).upper(), + doc.lessonDescription(y.lesson()).upper() ) < 0) + : (QString::compare(doc.lessonDescription(x.lesson()).upper(), + doc.lessonDescription(y.lesson()).upper() ) > 0); + else + return + !dir + ? (QString::compare(x.original().upper(), + y.original().upper() ) < 0) + : (QString::compare(x.original().upper(), + y.original().upper() ) > 0); + } + + private: + bool dir; + KEduVocDocument &doc; + }; + + + class sortByLessonAndOrg_index + : public binary_function + { + + public: + + sortByLessonAndOrg_index (bool _dir, KEduVocDocument &_doc) + : dir (_dir), doc(_doc) {} + + bool operator() (const KEduVocExpression& x, const KEduVocExpression& y) const + { + if (x.lesson() != y.lesson() ) + return + !dir + ? x.lesson() < y.lesson() + : y.lesson() < x.lesson(); + else + return + !dir + ? (QString::compare(x.original().upper(), + y.original().upper() ) < 0) + : (QString::compare(x.original().upper(), + y.original().upper() ) > 0); + } + + private: + bool dir; + KEduVocDocument &doc; + }; + + + class sortByTrans : public binary_function + { + + public: + + sortByTrans (int i, bool _dir) + : index(i), dir (_dir) {} + + bool operator() (const KEduVocExpression& x, const KEduVocExpression& y) const + { + return + !dir + ? (QString::compare(x.translation(index).upper(), + y.translation(index).upper() ) < 0) + : (QString::compare(x.translation(index).upper(), + y.translation(index).upper() ) > 0); + } + + private: + int index; + bool dir; + }; + */ + /**@todo implement sorting based on lesson index and name. + * Will be done when KVocTrain is ported to this class + */ + int sortIndex; + bool sortAscending; + + bool operator< (const KEduVocExpression &e1, const KEduVocExpression &e2) + { + if (sortAscending) + if (sortIndex == 0) + return ! (e1.original() > e2.original()); + else + return ! (e1.translation(sortIndex) > e2.translation(sortIndex)); + else + if (sortIndex == 0) + return ! (e1.original() < e2.original()); + else + return ! (e1.translation(sortIndex) < e2.translation(sortIndex)); + } + + bool KEduVocDocument::sort(int index) + { + bool result = false; + if (m_enableSorting && index < numIdentifiers()) + { + if (m_sortIdentifier.count() < m_identifiers.count()) + for (int i = m_sortIdentifier.count(); i < (int) m_identifiers.count(); i++) + m_sortIdentifier.append(false); + + sortAscending = m_sortIdentifier[index]; + sortIndex = index; + ///@todo port qStableSort(m_vocabulary); + m_sortIdentifier[index] = !m_sortIdentifier[index]; + result = m_sortIdentifier[index]; + } + return result; + + /*if (!sort_allowed) + return false; + + if (index >= numLangs()) + return false; + + if (sort_lang.size() < langs.size()) + for (int i = sort_lang.size(); i < (int) langs.size(); i++) + sort_lang.push_back(false); + + if (index == 0) + std::sort (vocabulary.begin(), vocabulary.end(), sortByOrg(sort_lang[0])); + else + std::sort (vocabulary.begin(), vocabulary.end(), sortByTrans(index, sort_lang[index])); + sort_lang[index] = !sort_lang[index]; + return sort_lang[index];*/ + } + + + bool KEduVocDocument::sortByLessonAlpha () + { + /* if (!sort_allowed) + return false; + + std::sort (vocabulary.begin(), vocabulary.end(), sortByLessonAndOrg_alpha(sort_lesson, *this )); + sort_lesson = !sort_lesson; + return sort_lesson;*/ + } + + + bool KEduVocDocument::sortByLessonIndex () + { + /* if (!sort_allowed) + return false; + + if (sort_lang.size() < langs.size()) + for (int i = sort_lang.size(); i < (int) langs.size(); i++) + sort_lang.push_back(false); + + std::sort (vocabulary.begin(), vocabulary.end(), sortByLessonAndOrg_index(sort_lesson, *this )); + sort_lesson = !sort_lesson; + sort_lang[0] = sort_lesson; + return sort_lesson;*/ + } + + bool KEduVocDocument::leitnerSystemActive() + { + return m_activeLeitnerSystem; + } + + void KEduVocDocument::setLeitnerSystemActive( bool yes ) + { + if( yes ) + { + if (m_leitnerSystem == 0) + createStandardLeitnerSystem(); //if nothing is loaded yet + + m_activeLeitnerSystem = true; + } + else if( !yes ) + m_activeLeitnerSystem = false; + } + + void KEduVocDocument::createStandardLeitnerSystem() + { + LeitnerSystem* tmpSystem = new LeitnerSystem(); + QString name = "Standard"; + + tmpSystem->setSystemName( name ); + tmpSystem->insertBox( "Box 1" ); + tmpSystem->insertBox( "Box 2" ); + tmpSystem->insertBox( "Box 3" ); + tmpSystem->insertBox( "Box 4" ); + tmpSystem->insertBox( "Box 5" ); + + tmpSystem->setCorrectBox( "Box 1", "Box 2" ); + tmpSystem->setWrongBox( "Box 1", "Box 1" ); + + tmpSystem->setCorrectBox( "Box 2", "Box 3" ); + tmpSystem->setWrongBox( "Box 2", "Box 1" ); + + tmpSystem->setCorrectBox( "Box 3", "Box 4" ); + tmpSystem->setWrongBox( "Box 3", "Box 1" ); + + tmpSystem->setCorrectBox( "Box 4", "Box 5" ); + tmpSystem->setWrongBox( "Box 4", "Box 1" ); + + tmpSystem->setCorrectBox( "Box 5", "Box 1" ); + tmpSystem->setWrongBox( "Box 5", "Box 1" ); + + m_leitnerSystem = tmpSystem; + } + + void KEduVocDocument::setLeitnerSystem( LeitnerSystem* system ) + { + m_leitnerSystem = system; + + /*KWordQuizApp* app = (KWordQuizApp*) parent(); + app->slotLeitnerSystem();*/ + } + + LeitnerSystem* KEduVocDocument::leitnerSystem() + { + return m_leitnerSystem; + } + + /* + class resetAll : public unary_function + { + + public: + + resetAll (int less) + : lesson(less) {} + + void operator() (KEduVocExpression& x) + { + for (int i = 0; i <= x.numTranslations(); i++) { + if (lesson == 0 || lesson == x.lesson()) + { + x.setGrade(i, KV_NORM_GRADE, false); + x.setGrade(i, KV_NORM_GRADE, true); + x.setQueryCount (i, 0, true); + x.setQueryCount (i, 0, false); + x.setBadCount (i, 0, true); + x.setBadCount (i, 0, false); + QDateTime dt; + dt.setTime_t(0); + x.setQueryDate (i, dt, true); + x.setQueryDate (i, dt, false); + } + } + } + private: + int lesson; + }; + + + class resetOne : public unary_function + { + + public: + + resetOne (int idx, int less) + : index (idx), lesson(less) {} + + void operator() (KEduVocExpression& x) + { + if (lesson == 0 || lesson == x.lesson()) + { + x.setGrade(index, KV_NORM_GRADE, false); + x.setGrade(index, KV_NORM_GRADE, true); + x.setQueryCount (index, 0, true); + x.setQueryCount (index, 0, false); + x.setBadCount (index, 0, true); + x.setBadCount (index, 0, false); + QDateTime dt; + dt.setTime_t(0); + x.setQueryDate (index, dt, true); + x.setQueryDate (index, dt, false); + } + } + + private: + int index; + int lesson; + }; + */ + + void KEduVocDocument::resetEntry(int index, int lesson) + { + if (index < 0) + { + foreach( KEduVocExpression exp, m_vocabulary ) + { + for (int i = 0; i <= exp.numTranslations(); i++) + { + if (lesson == 0 || lesson == exp.lesson()) + { + exp.setGrade(i, KV_NORM_GRADE, false); + exp.setGrade(i, KV_NORM_GRADE, true); + exp.setQueryCount(i, 0, true); + exp.setQueryCount(i, 0, false); + exp.setBadCount(i, 0, true); + exp.setBadCount(i, 0, false); + QDateTime dt; + dt.setTime_t(0); + exp.setQueryDate(i, dt, true); + exp.setQueryDate(i, dt, false); + } + } + } + } + else + { - foreach( KEduVocExpression exp, m_vocabulary ) ++ foreach( KEduVocExpression exp, m_vocabulary ) + if (lesson == 0 || lesson == exp.lesson()) + { + exp.setGrade(index, KV_NORM_GRADE, false); + exp.setGrade(index, KV_NORM_GRADE, true); + exp.setQueryCount(index, 0, true); + exp.setQueryCount(index, 0, false); + exp.setBadCount(index, 0, true); + exp.setBadCount(index, 0, false); + QDateTime dt; + dt.setTime_t(0); + exp.setQueryDate(index, dt, true); + exp.setQueryDate(index, dt, false); + } + } + } + + + QString KEduVocDocument::lessonDescription(int idx) const + { + if (idx == 0) + return i18n(""); + + if (idx <= 0 || idx > (int) m_lessonDescriptions.size() ) + return ""; + + return m_lessonDescriptions[idx-1]; + } + + + QList KEduVocDocument::lessonsInQuery() const + { + QList iqvec; + for (unsigned i = 0; i < m_lessonsInQuery.size(); i++) + if (m_lessonsInQuery[i]) { + iqvec.push_back(i+1); // Offset + // cout << "getliq: " << i+1 << endl; + } + return iqvec; + } + + + void KEduVocDocument::setLessonsInQuery(QList lesson_iq) + { + m_lessonsInQuery.clear(); + for (unsigned i = 0; i < m_lessonDescriptions.size(); i++) + m_lessonsInQuery.push_back(false); + + foreach( int i, lesson_iq ) + if (lesson_iq[i] <= (int) m_lessonsInQuery.size() ) + { + m_lessonsInQuery[lesson_iq[i]-1] = true; // Offset + // cout << "setliq: " << lesson_iq[i] << " " << i << endl; + } + } + + + QString KEduVocDocument::title() const + { + if (m_title.isEmpty()) + return m_url.fileName(); + else + return m_title; + } + + + QString KEduVocDocument::author() const + { + return m_author; + } + + + QString KEduVocDocument::license() const + { + return m_license; + } + + + QString KEduVocDocument::docRemark() const + { + return m_remark; + } + + + QFont* KEduVocDocument::font() const + { + return m_font; + } + + + void KEduVocDocument::setTitle(const QString & title) + { + m_title = title.stripWhiteSpace(); + } + + + void KEduVocDocument::setAuthor(const QString & s) + { + m_author = s.stripWhiteSpace(); + } + + + void KEduVocDocument::setLicense(const QString & s) + { + m_license = s.stripWhiteSpace(); + } + + + void KEduVocDocument::setDocRemark(const QString & s) + { + m_remark = s.stripWhiteSpace(); + } + + + void KEduVocDocument::setFont(QFont* font) + { + delete this->m_font; + this->m_font = font; + } + + + int KEduVocDocument::search(QString substr, int id, int first, int last, bool word_start) + { + if (last >= numEntries() || last < 0) + last = numEntries(); + + if (first < 0) + first = 0; + + if (id >= numIdentifiers() || last < first) + return -1; + + if (id == 0) { + for (int i = first; i < last; i++) { + if (word_start) { + if (entry(i)->original().find(substr, 0, false) == 0) // case insensitive + return i; + } + else { + if (entry(i)->original().find(substr, 0, false) > -1) // case insensitive + return i; + } + } + } + else { + for (int i = first; i < last; i++) { + if (word_start) { + if (entry(i)->translation(id).find(substr, 0, false) == 0) // case insensitive + return i; + } + else { + if (entry(i)->translation(id).find(substr, 0, false) > -1) // case insensitive + return i; + } + } + } + return -1; + } + + + KEduVocDocument::FileType KEduVocDocument::detectFileType(const QString &filename) + { + QFile f( filename ); + if (!f.open( QIODevice::ReadOnly )) + return csv; + + QDataStream is( &f ); + + Q_INT8 c1, c2, c3, c4, c5; + is >> c1 + >> c2 + >> c3 + >> c4 + >> c5; // guess filetype by first x bytes + + QTextStream ts (&f); + QString line; + line = ts.readLine(); + line.insert (0, c5); + line.insert (0, c4); + line.insert (0, c3); + line.insert (0, c2); + line.insert (0, c1); + f.close(); + + bool stat = is.device()->status(); + if (stat != IO_Ok) + return kvd_none; + if (c1 == '<' && c2 == '?' && c3 == 'x' && c4 == 'm' && c5 == 'l') + return kvtml; + + if (line == WQL_IDENT) + return wql; + + if (line.find (VCB_SEPARATOR) >= 0) + return vt_vcb; + + if (line == LEX_IDENT_50) + return vt_lex; + + return csv; + } + + + class ExpRef { + + public: + ExpRef() {} + ExpRef (KEduVocExpression *_exp, int _idx) + { + idx = _idx; + exp = _exp; + } + + bool operator< (const ExpRef& y) const + { + QString s1 = exp->original(); + QString s2 = y.exp->original(); + int cmp = QString::compare(s1.upper(), s2.upper()); + if (cmp != 0) + return cmp < 0; + + for (int i = 1; i < (int) exp->numTranslations(); i++) { + + s1 = exp->translation(i); + s2 = y.exp->translation(i); + cmp = QString::compare(s1.upper(), s2.upper() ); + if (cmp != 0) + return cmp < 0; + } + return cmp < 0; + } + + int idx; + KEduVocExpression *exp; + }; + + typedef QList ExpRefList; + + int KEduVocDocument::cleanUp() + { + int count = 0; + KEduVocExpression *kve1, *kve2; + ExpRefList shadow; + QList to_delete; + + for (int i = 0; i < (int) m_vocabulary.size(); i++) + shadow.push_back (ExpRef (entry(i), i)); + ///@todo port qStableSort(shadow.begin(), shadow.end()); + + #ifdef CLEAN_BUG + ofstream sso ("shadow.out"); + for (int i = shadow.size()-1; i > 0; i--) { + kve1 = shadow[i].exp; + sso << kve1->original() << " "; + for (int l = 1; l < (int) numLangs(); l++ ) + sso << kve1->translation(l) << " "; + sso << endl; + } + #endif + + int ent_no = 0; + int ent_percent = m_vocabulary.size () / 100; + float f_ent_percent = m_vocabulary.size () / 100.0; + emit progressChanged(this, 0); + + for (int i = shadow.size()-1; i > 0; i--) { + kve1 = shadow[i].exp; + kve2 = shadow[i-1].exp; + + ent_no++; + if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) + emit progressChanged(this, (int)((ent_no / f_ent_percent) / 2.0)); + + bool equal = true; + if (kve1->original() == kve2->original() ) { + for (int l = 1; equal && l < (int) numIdentifiers(); l++ ) + if (kve1->translation(l) != kve2->translation(l)) + equal = false; + + if (equal) { + to_delete.push_back(shadow[i-1].idx); + count++; + } + } + } + + // removing might take very long + ent_no = 0; + ent_percent = to_delete.size () / 100; + f_ent_percent = to_delete.size () / 100.0; + emit progressChanged(this, 0); + + ///@todo port qStableSort(to_delete.begin(), to_delete.end()); + //std::sort (to_delete.begin(), to_delete.end() ); + for (int i = (int) to_delete.size()-1; i >= 0; i--) { + ent_no++; + if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) + emit progressChanged(this, (int)(50 + ent_no / f_ent_percent / 2.0)); + #ifdef CLEAN_BUG + sso << getEntry(to_delete[i])->getOriginal() << endl; + #endif + removeEntry (to_delete[i]); + setModified(); + } + + return count; + } diff --cc kdeeducore/keduvocdocument.h index 0000000,ce679f5..ce679f5 mode 000000,100644..100644 --- a/kdeeducore/keduvocdocument.h +++ b/kdeeducore/keduvocdocument.h diff --cc kdeeducore/keduvocexpression.cpp index 0000000,95af8ca..95af8ca mode 000000,100644..100644 --- a/kdeeducore/keduvocexpression.cpp +++ b/kdeeducore/keduvocexpression.cpp diff --cc kdeeducore/keduvocexpression.h index 0000000,7a38718..7a38718 mode 000000,100644..100644 --- a/kdeeducore/keduvocexpression.h +++ b/kdeeducore/keduvocexpression.h diff --cc kdeeducore/keduvocgrammar.cpp index 0000000,4a648b8..4a648b8 mode 000000,100644..100644 --- a/kdeeducore/keduvocgrammar.cpp +++ b/kdeeducore/keduvocgrammar.cpp diff --cc kdeeducore/keduvocgrammar.h index 0000000,d3dd2e0..d3dd2e0 mode 000000,100644..100644 --- a/kdeeducore/keduvocgrammar.h +++ b/kdeeducore/keduvocgrammar.h diff --cc kdeeducore/keduvockvtmlreader.cpp index 0000000,32c2e2e..32c2e2e mode 000000,100644..100644 --- a/kdeeducore/keduvockvtmlreader.cpp +++ b/kdeeducore/keduvockvtmlreader.cpp diff --cc kdeeducore/keduvockvtmlreader.h index 0000000,1b707e8..1b707e8 mode 000000,100644..100644 --- a/kdeeducore/keduvockvtmlreader.h +++ b/kdeeducore/keduvockvtmlreader.h diff --cc kdeeducore/keduvockvtmlwriter.cpp index 0000000,3a43581..3a43581 mode 000000,100644..100644 --- a/kdeeducore/keduvockvtmlwriter.cpp +++ b/kdeeducore/keduvockvtmlwriter.cpp diff --cc kdeeducore/keduvockvtmlwriter.h index 0000000,46ceb7d..46ceb7d mode 000000,100644..100644 --- a/kdeeducore/keduvockvtmlwriter.h +++ b/kdeeducore/keduvockvtmlwriter.h diff --cc kdeeducore/keduvocmultiplechoice.cpp index 0000000,9cc9243..9cc9243 mode 000000,100644..100644 --- a/kdeeducore/keduvocmultiplechoice.cpp +++ b/kdeeducore/keduvocmultiplechoice.cpp diff --cc kdeeducore/keduvocmultiplechoice.h index 0000000,55efe69..55efe69 mode 000000,100644..100644 --- a/kdeeducore/keduvocmultiplechoice.h +++ b/kdeeducore/keduvocmultiplechoice.h diff --cc kdeeducore/keduvocwqlreader.cpp index 0000000,35a0817..35a0817 mode 000000,100644..100644 --- a/kdeeducore/keduvocwqlreader.cpp +++ b/kdeeducore/keduvocwqlreader.cpp diff --cc kdeeducore/keduvocwqlreader.h index 0000000,06829ec..06829ec mode 000000,100644..100644 --- a/kdeeducore/keduvocwqlreader.h +++ b/kdeeducore/keduvocwqlreader.h diff --cc kdeeducore/keduvocwqlwriter.cpp index 0000000,9beda3d..9beda3d mode 000000,100644..100644 --- a/kdeeducore/keduvocwqlwriter.cpp +++ b/kdeeducore/keduvocwqlwriter.cpp diff --cc kdeeducore/keduvocwqlwriter.h index 0000000,ddf2f29..ddf2f29 mode 000000,100644..100644 --- a/kdeeducore/keduvocwqlwriter.h +++ b/kdeeducore/keduvocwqlwriter.h diff --cc kdeeducore/keduvowqlreader.cpp index 0000000,0000000..35a0817 new file mode 100644 --- /dev/null +++ b/kdeeducore/keduvowqlreader.cpp @@@ -1,0 -1,0 +1,161 @@@ ++/*************************************************************************** ++ read a KEduVocDocument from a WQL file ++ ----------------------------------------------------------------------- ++ copyright : (C) 2004 Peter Hedlund ++ (C) 2005 Eric Pignet ++ email : peter.hedlund@kdemail.net ++ ***************************************************************************/ ++ ++/*************************************************************************** ++ * * ++ * This program is free software; you can redistribute it and/or modify * ++ * it under the terms of the GNU General Public License as published by * ++ * the Free Software Foundation; either version 2 of the License, or * ++ * (at your option) any later version. * ++ * * ++ ***************************************************************************/ ++ ++#include ++#include ++#include ++#include ++ ++#include ++#include ++ ++#include "keduvocwqlreader.h" ++#include "keduvocdocument.h" ++ ++KEduVocWqlReader::KEduVocWqlReader(QFile *file) ++{ ++ // the file must be already open ++ m_inputFile = file; ++} ++ ++KEduVocWqlReader::~KEduVocWqlReader() ++{ ++} ++ ++bool KEduVocWqlReader::readDoc(KEduVocDocument *doc) ++{ ++ m_doc = doc; ++ ++ QTextStream inputStream(m_inputFile); ++ inputStream.setEncoding(QTextStream::Latin1); ++ ++ QString s = ""; ++ s=inputStream.readLine(); ++ if (s != "WordQuiz") ++ { ++ KMessageBox::error(0, i18n("This does not appear to be a (K)WordQuiz file") + s); ++ return false; ++ } ++ s = inputStream.readLine(); ++ s = s.left(1); ++ int iFV = s.toInt(0); ++ if (iFV != 5) ++ { ++ KMessageBox::error(0, i18n("KWordQuiz can only open files created by WordQuiz 5.x")); ++ return false; ++ } ++ // TODO these loops cause crashes if the input file is invalid ! ++ while (inputStream.readLine() != "[Font Info]"); ++ s = inputStream.readLine(); ++ int p = s.find("=", 0); ++ QString fam = s.right(s.length() - (p + 1)); ++ fam = fam.mid(1, fam.length() - 2); ++ //g->font().setFamily(s); ++ ++ s = inputStream.readLine(); ++ p = s.find("=", 0); ++ s = s.right(s.length() - (p + 1)); ++ int ps = s.toInt(0); ++ ++ s = inputStream.readLine(); ++ p = s.find("=", 0); ++ s = s.right(s.length() - (p + 1)); ++ int b = 0; ++ if (s == "1") ++ { ++ b = QFont::Bold; ++ } ++ ++ s = inputStream.readLine(); ++ p = s.find("=", 0); ++ s = s.right(s.length() - (p + 1)); ++ bool it = (s == "1"); ++ ++ m_doc->setFont(new QFont(fam, ps, b, it)); ++ ++/* TODO ++ while (inputStream.readLine() != "[Character Info]"); ++ s = inputStream.readLine(); ++ p = s.find("=", 0); ++ m_specialCharacters = s.right(s.length() - (p + 1)); ++*/ ++ while (inputStream.readLine() != "[Grid Info]"); ++ inputStream.readLine(); //skip value for width of row headers ++ ++ s = inputStream.readLine(); ++ p = s.find("=", 0); ++ s = s.right(s.length() - (p + 1)); ++ m_doc->setSizeHint(0, s.toInt()); ++ ++ s = inputStream.readLine(); ++ p = s.find("=", 0); ++ s = s.right(s.length() - (p + 1)); ++ m_doc->setSizeHint(1, s.toInt()); ++ ++/* TODO ++ s = inputStream.readLine(); ++ p = s.find("=", 0); ++ s = s.right(s.length() - (p + 1)); ++ m_numRows = (s.toInt() - 1); //We need to reduce by one since the header is not included ++ // Selection ++ s = inputStream.readLine(); ++ p = s.find("=", 0); ++ s = s.right(s.length() - (p + 1)); ++ m_topLeft =s.toInt(0, 10) - 1; ++ ++ s = inputStream.readLine(); ++ p = s.find("=", 0); ++ s = s.right(s.length() - (p + 1)); ++ m_topRight =s.toInt(0, 10) - 1; ++ ++ s = inputStream.readLine(); ++ p = s.find("=", 0); ++ s = s.right(s.length() - (p + 1)); ++ m_bottomLeft =s.toInt(0, 10) - 1; ++ ++ s = inputStream.readLine(); ++ p = s.find("=", 0); ++ s = s.right(s.length() - (p + 1)); ++ m_bottomRight =s.toInt(0, 10) - 1 ; ++*/ ++ while ((inputStream.readLine() != "[Vocabulary]")); ++ ++ s = inputStream.readLine(); ++ p = s.find(" [", 0); ++ s = s.left(p); ++ s = s.stripWhiteSpace(); ++ m_doc->m_identifiers.push_back(s); ++ m_doc->m_identifiers.push_back(inputStream.readLine()); ++ ++ while (!s.isNull()) ++ { ++ s = inputStream.readLine(); ++ p = s.find("[", 0); ++ QString r = s.mid(p + 1, 10); ++ int h = r.toInt(); ++ s = s.left(p); ++ s = s.stripWhiteSpace(); ++ ++ QString b; ++ b = inputStream.readLine(); ++ ++ KEduVocExpression expr = KEduVocExpression(s); ++ expr.setTranslation(1, b); ++ m_doc->appendEntry(&expr); ++ } ++ return true; ++} diff --cc kdeeducore/keduvowqlreader.h index 0000000,0000000..06829ec new file mode 100644 --- /dev/null +++ b/kdeeducore/keduvowqlreader.h @@@ -1,0 -1,0 +1,40 @@@ ++/*************************************************************************** ++ read a KEduVocDocument from a WQL file ++ ----------------------------------------------------------------------- ++ copyright : (C) 2004 Peter Hedlund ++ : (c) 2005 Eric Pignet ++ email : peter.hedlund@kdemail.net ++ ***************************************************************************/ ++ ++/*************************************************************************** ++ * * ++ * This program is free software; you can redistribute it and/or modify * ++ * it under the terms of the GNU General Public License as published by * ++ * the Free Software Foundation; either version 2 of the License, or * ++ * (at your option) any later version. * ++ * * ++ ***************************************************************************/ ++ ++#ifndef KEDUVOCWQLREADER_H ++#define KEDUVOCWQLREADER_H ++ ++#include ++ ++#include "keduvocdocument.h" ++ ++class KEduVocDocument; ++ ++class KEduVocWqlReader : public QObject ++{ ++public: ++ KEduVocWqlReader(QFile *file); ++ ~KEduVocWqlReader(); ++ ++ bool readDoc(KEduVocDocument *doc); ++ ++private: ++ QFile *m_inputFile; ++ KEduVocDocument *m_doc; ++}; ++ ++#endif diff --cc kdeeducore/keduvowqlwriter.cpp index 0000000,0000000..9beda3d new file mode 100644 --- /dev/null +++ b/kdeeducore/keduvowqlwriter.cpp @@@ -1,0 -1,0 +1,127 @@@ ++/*************************************************************************** ++ export a KEduVocDocument to a WQL file ++ ----------------------------------------------------------------------- ++ copyright : (C) 2004 Peter Hedlund ++ (C) 2005 Eric Pignet ++ email : peter.hedlund@kdemail.net ++ ***************************************************************************/ ++ ++/*************************************************************************** ++ * * ++ * This program is free software; you can redistribute it and/or modify * ++ * it under the terms of the GNU General Public License as published by * ++ * the Free Software Foundation; either version 2 of the License, or * ++ * (at your option) any later version. * ++ * * ++ ***************************************************************************/ ++ ++#include ++#include ++#include ++#include ++ ++#include "keduvocwqlwriter.h" ++#include "keduvocdocument.h" ++ ++#define winendl "\r\n" ++ ++KEduVocWqlWriter::KEduVocWqlWriter(QFile *file) ++{ ++ // the file must be already open ++ m_outputFile = file; ++} ++ ++KEduVocWqlWriter::~KEduVocWqlWriter() ++{ ++} ++ ++bool KEduVocWqlWriter::writeDoc(KEduVocDocument *doc) ++{ ++ m_doc = doc; ++ ++ m_outputStream.setDevice(m_outputFile); ++ m_outputStream.setEncoding(QTextStream::Latin1); ++ ++ m_outputStream << "WordQuiz" << winendl; ++ m_outputStream << "5.9.0" << winendl << winendl; ++ ++ if (doc->font() != NULL) ++ writeFont(*(doc->font())); ++ // TODO writeCharacters(Prefs::specialCharacters()); ++ // TODO Find the vertical header width, handle the case where there are not exactly two languages ++ writeGridInfo(10, m_doc->sizeHint(0), m_doc->sizeHint(1), m_doc->numEntries()); ++ /* TODO Find the selected cells ++ if (g->numSelections() > 0) ++ { ++ QTableSelection qts = g->selection(0); ++ writeSelection(qts.leftCol(), qts.topRow(), qts.rightCol(), qts.bottomRow()); ++ } ++ else ++ { ++ writeSelection(g->currentColumn(), g->currentRow(), g->currentColumn(), g->currentRow()); ++ }*/ ++ writeFirstItem(m_doc->originalIdentifier(), m_doc->identifier(1)); ++ int r = m_doc->numEntries(); ++ for (int w=0; w < r; w++) ++ { ++ // TODO Find the row height (g->rowHeight(w)) ++ writeItem(m_doc->entry(w)->original(), m_doc->entry(w)->translation(1), 30); ++ } ++} ++ ++void KEduVocWqlWriter::writeFont( const QFont & font ) ++{ ++ m_outputStream << "[Font Info]" << winendl; ++ m_outputStream << "FontName1=\"" << font.family() << "\"" << winendl; ++ m_outputStream << "FontSize1=" << QString::number(font.pointSize()) << winendl; ++ m_outputStream << QString("FontBold1=%1").arg(font.bold() ? "1" : "0") < ++#include ++#include ++ ++class KEduVocDocument; ++ ++class KEduVocWqlWriter ++{ ++public: ++ KEduVocWqlWriter(QFile *file); ++ ~KEduVocWqlWriter(); ++ ++ bool writeDoc(KEduVocDocument *doc); ++ ++ void writeFont(const QFont & font); ++ void writeCharacters(const QString & s); ++ void writeGridInfo(int col0, int col1, int col2, int numRows); ++ void writeSelection(int lc, int tr, int rc, int br); ++ void writeFirstItem(const QString &ll, const QString &rl); ++ void writeItem(const QString &left, const QString &right, int rh); ++ ++private: ++ QFile *m_outputFile; ++ QTextStream m_outputStream; ++ KEduVocDocument *m_doc; ++}; ++ ++#endif diff --cc kdeeducore/leitnerbox.cpp index 0000000,a96d7c4..a96d7c4 mode 000000,100644..100644 --- a/kdeeducore/leitnerbox.cpp +++ b/kdeeducore/leitnerbox.cpp diff --cc kdeeducore/leitnerbox.h index 0000000,c32fa83..c32fa83 mode 000000,100644..100644 --- a/kdeeducore/leitnerbox.h +++ b/kdeeducore/leitnerbox.h diff --cc kdeeducore/leitnersystem.cpp index 0000000,f7d6627..f7d6627 mode 000000,100644..100644 --- a/kdeeducore/leitnersystem.cpp +++ b/kdeeducore/leitnersystem.cpp diff --cc kdeeducore/leitnersystem.h index 0000000,c95ed4b..c95ed4b mode 000000,100644..100644 --- a/kdeeducore/leitnersystem.h +++ b/kdeeducore/leitnersystem.h diff --cc kdeeducore/leitnersystemview.cpp index 0000000,261200f..42658a8 mode 000000,100644..100644 --- a/kdeeducore/leitnersystemview.cpp +++ b/kdeeducore/leitnersystemview.cpp @@@ -1,0 -1,205 +1,205 @@@ + // + // C++ Implementation: leitnersystemview + // + // Description: + // + // + // Author: Martin Pfeiffer , (C) 2005 + // + // Copyright: See COPYING file that comes with this distribution + // + // + #include "leitnersystemview.h" + + #include "leitnersystem.h" -#include "kwordquiz.h" ++//#include "kwordquiz.h" + + #include + #include + #include + //Added by qt3to4: + #include + + #include + + LeitnerSystemView::LeitnerSystemView(QWidget * parent, const char* name, Qt::WFlags f) + : Q3ScrollView(parent, name, f) + { + m_highlightedBox = -1; + } + + + LeitnerSystemView::~LeitnerSystemView() + { + } + + void LeitnerSystemView::drawSystem(QPainter* p) + { + m_imageY = height() / 2 - 32; + + //draw the boxes' icons + for(int i = 0; i < m_leitnerSystem->getNumberOfBoxes(); i++) + { + if(i == m_highlightedBox) + { + //p->drawPixmap(12 + i * 64 + i*10, m_imageY, KGlobal::iconLoader()->loadIcon("leitnerbox", KIcon::Panel)); + p->drawRect(12 + i * 64 + i*10, m_imageY,64,64); + p->fillRect(12 + i * 64 + i*10, m_imageY,64,64, QBrush(Qt::red)); + } + else + { //for each box 74 = 64(pixmap) + 10(distance between two boxes) + //p->drawPixmap(12 + i * 74, m_imageY, KGlobal::iconLoader()->loadIcon("leitnerbox", KIcon::Panel)); + p->drawRect(12 + i * 64 + i*10, m_imageY,64,64); + } + } + } + + void LeitnerSystemView::drawConnections(QPainter* p) + { + //dist = number of boxes that are in between the two boxes + //width = width of the rect for the arc + int dist, width = 0; + int numberOfBoxes = m_leitnerSystem->getNumberOfBoxes(); + + p->setPen( QPen(Qt::green, 2) ); + + //paint the connections for the correct word boxes, above the boxes + for(int i = 0; i < numberOfBoxes; i++) + { + if( m_leitnerSystem->correctBoxNumber( i ) != -1 ) + { + dist = m_leitnerSystem->correctBoxNumber( i ) - i; + + if(dist <= 0) + { + // (dist*(-1) -1)*64 == for each box in between take 64 + // dist*(-1)*10 == the gaps in between + // 2*22; 2*21 == the distances of the endings on the picture + width = (dist*(-1) -1)*64 + dist*(-1)*10 + 2*22 + 2*21; + + p->drawArc( 12 + (dist+i)*74 + 21, m_imageY-(width/3), width, /*(height()/2 - 12-32) *2*/ width/3*2, 0, 180*16); + } + else + { + width = (dist-1)*64 + dist*10 + 2*21; + p->drawArc(12 + i*74 + 21+22 ,m_imageY-(width/3) , width, /*(height()/2 - 12-32) *2*/width/3*2, 0, 180*16); + } + } + } + + //paint the connections for the wrong word boxes, below the boxes + p->setPen(QPen(Qt::red, 2)); + + for(int i = 0; i < numberOfBoxes; i++) + { + if( m_leitnerSystem->wrongBoxNumber( i ) != -1 ) + { + dist = m_leitnerSystem->wrongBoxNumber( i ) - i; + + if(dist <= 0) + { + width = (dist*(-1) -1)*64 + dist*(-1)*10 + 2*22 + 2*21; + p->drawArc(12+ (dist+i)*74 + 21 ,m_imageY+64-width/3 , width, width/3*2 , 180*16, 180*16); + } + else + { + width = (dist-1)*64 + dist*10 + 2*21; + p->drawArc(12 + i*74 + 21+22 ,m_imageY+64-width/3 , width, width/3*2, 180*16, 180*16); + } + } + } + } + + void LeitnerSystemView::setSystem(LeitnerSystem* leitnersystem) + { + m_leitnerSystem = leitnersystem; + + //calculate the new sizes + calculateSize(); + updateContents(); + } + + void LeitnerSystemView::highlightBox(int box) + { + m_highlightedBox = box; + updateContents(); + } + + void LeitnerSystemView::drawContents(QPainter* p, int clipx, int clipy, int clipw, int cliph) + { + p->eraseRect(0,0,width(),height()); + + drawSystem( p ); + + drawConnections( p ); + } + + void LeitnerSystemView::calculateSize() + { + //margin = 12 + //distance between boxes = 10 + //boxes = 64*64 + + int numberOfBoxes = m_leitnerSystem->getNumberOfBoxes(); + QString x; + int height, dist, tmpMaxC, tmpMaxW; + tmpMaxC = 0; + tmpMaxW = 0; + height = 0; + + for(int i = 0; i < numberOfBoxes; i++) + { + if( m_leitnerSystem->correctBoxNumber( i ) != -1 ) + { + dist = m_leitnerSystem->correctBoxNumber( i ) - i; + + if( abs(dist) >= abs(tmpMaxC) ) + tmpMaxC = dist; + } + + if( m_leitnerSystem->wrongBoxNumber( i ) != -1 ) + { + dist = m_leitnerSystem->wrongBoxNumber( i ) - i; + + if( abs(dist) >= abs(tmpMaxW) ) + tmpMaxW = dist; + } + } + + if( tmpMaxC <= 0 ) + height += (( abs(tmpMaxC) -1)*64 + abs(tmpMaxC)*10 + 2*22 + 2*21)/3; + else + height += ((tmpMaxC-1)*64 + tmpMaxC*10 + 2*21)/3; + + if( tmpMaxW <= 0 ) + height += (( abs(tmpMaxW) -1)*64 + abs(tmpMaxW)*10 + 2*22 + 2*21)/3; + else + height += (( tmpMaxW-1)*64 + tmpMaxW*10 + 2*21)/3; + + height += 24+64; + + resizeContents( numberOfBoxes * 64 + (numberOfBoxes - 1)*10 + 2 * 12, height ); + setMinimumSize( numberOfBoxes * 64 + (numberOfBoxes - 1)*10 + 2 * 12, height ); + } + + void LeitnerSystemView::mousePressEvent(QMouseEvent* e) + { + kdDebug() << "mouseClick" << endl; + //if the user has clicked into a box + if( e->y() > m_imageY && e->y() < m_imageY + 64 && e->x() < contentsWidth() ) + { + int d = (e->x()-12)/74; + + if((e->x()-12-74*d) <= 64) + { + //signal for prefLeitner to set the comboboxes to the clicked box + emit boxClicked( d ); + m_highlightedBox = d; + + updateContents(); + } + } + } + + #include "leitnersystemview.moc" + diff --cc kdeeducore/leitnersystemview.h index 0000000,5642b02..5642b02 mode 000000,100644..100644 --- a/kdeeducore/leitnersystemview.h +++ b/kdeeducore/leitnersystemview.h diff --cc kdeeducore/prefleitner.cpp index 0000000,34961ba..34961ba mode 000000,100644..100644 --- a/kdeeducore/prefleitner.cpp +++ b/kdeeducore/prefleitner.cpp diff --cc kdeeducore/prefleitner.h index 0000000,da97f4e..4a3acb7 mode 000000,100644..100644 --- a/kdeeducore/prefleitner.h +++ b/kdeeducore/prefleitner.h @@@ -1,0 -1,54 +1,54 @@@ + // + // C++ Interface: prefleitner + // + // Description: the part of the preferences to change the settings for the LeitnerSystem + // + // + // Author: Martin Pfeiffer , (C) 2005 + // + // Copyright: See COPYING file that comes with this distribution + // + // + #ifndef PREFLEITNER_H + #define PREFLEITNER_H + -#include ++#include "prefleitnerbase.h" + + class LeitnerSystemView; + class LeitnerSystem; + class LeitnerBox; + + /** + @author Martin Pfeiffer + */ + class PrefLeitner : public QDialog, public Ui::PrefLeitnerBase + { + Q_OBJECT - ++ + public: + PrefLeitner(QWidget * parent, LeitnerSystem* system); + + LeitnerSystem* getSystem(); + + public slots: + void slotCorrectWord( const QString& newBox ); + void slotWrongWord( const QString& newBox ); + void slotBoxName( const QString& newName ); + void slotAddBox(); + void slotDeleteBox(); + void slotDiscard(); + void slotApply(); + + private slots: + void slotBoxClicked(int); //catches the signal from the view if user clicks on box + + private: + LeitnerSystemView* m_leitnerSystemView; //the LeitnerSystemView which shows the selected system + LeitnerSystem* m_selectedSystem; //the currently selected system to be changed + LeitnerBox* m_selectedBox; //the currently selected box + + void refreshSystemView(); //refresh the LeitnerSystemView + void newSystem(); + }; + + #endif diff --cc kdeeducore/prefleitnerbase.ui index 0000000,881381c..881381c mode 000000,100644..100644 --- a/kdeeducore/prefleitnerbase.ui +++ b/kdeeducore/prefleitnerbase.ui