Yet to do: handle special characters, selected cells, row heights (these datas don't exist in the new document
class).
Fixed the undo mechanism.
svn path=/branches/work/kwordquiz/src/keduvocwqlwriter.h; revision=433409
#include "keduvockvtmlwriter.h"
#include "keduvockvtmlreader.h"
+#include "keduvocwqlwriter.h"
+#include "keduvocwqlreader.h"
#include "leitnersystem.h"
//#include "prefs.h"
KEduVocDocument::~KEduVocDocument()
{
+ delete font;
}
doc_url.setFileName(i18n("Untitled"));
doctitle = "";
author = "";
+ doc_remark = "";
+ doc_version = "";
+ font = NULL;
activeLeitnerSystem = false;
- leitnerSystem = 0;
+ leitnerSystem = NULL;
}
}
break;
+ case wql:
+ {
+ KEduVocWqlReader wqlReader(&f);
+ read = wqlReader.readDoc(this);
+ }
+ break;
+
case vt_lex:
{
QTextStream is (&f);
{
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)
}
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);
}
+QFont* KEduVocDocument::getFont() const
+{
+ return font;
+}
+
+
void KEduVocDocument::setTitle(const QString & title)
{
doctitle = title.stripWhiteSpace();
}
+void KEduVocDocument::setFont(QFont* font)
+{
+ delete this->font;
+ this->font = font;
+}
+
+
int KEduVocDocument::search(QString substr, int id,
int first, int last,
bool word_start,
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;
#endif
#include <qobject.h>
-
+#include <qfont.h>
#include <kurl.h>
#include "keduvocexpression.h"
#define KV_CONJ_COMMON "common" // female contains common for all three
#define LEX_IDENT_50 "Vocabulary Trainer V5.0"
+#define WQL_IDENT "WordQuiz"
#define KVTML_EXT "kvtml"
#define VT5_LEX_EXT "lex"
#define KVL_EXT "vl"
#define CSV_EXT "csv"
#define TXT_EXT "txt"
+#define WQL_EXT "wql"
#define VCB_SEPARATOR "__"
Q_OBJECT
friend class KEduVocKvtmlWriter;
friend class KEduVocKvtmlReader;
+ friend class KEduVocWqlReader;
public:
enum FileType { kvd_none, automatic,
kvtml,
+ wql,
kvtbin,
vt_lex, vt_vcb, csv /*, kvoclearn, qvocab*/ };
*/
void removeEntry (int index);
+ /** removes all entries from doc (clears vocabulary)
+ */
+ inline void removeAllEntries ()
+ { vocabulary.clear(); dirty = true; }
+
/** sorts vocabulary alphabetically
*
* @param index index expression
/** returns remark of file */
QString getDocRemark() const;
+ /** returns font */
+ QFont* getFont() const;
+
inline void getQueryLang(QString &org, QString &trans) const
{ org = queryorg; trans = querytrans; }
/** sets remark of file */
void setDocRemark(const QString & rem);
+ /** sets font */
+ void setFont(QFont *font);
+
/** gets version of loaded file */
void getVersion(int &major, int &minor, int &patch);
int current_lesson;
vector<int> extraSizehints;
vector<int> sizehints;
+ QFont* font;
+
QString generator;
QString queryorg,
querytrans;
vector<Article> articles;
vector<Conjugation> conjugations;
- LeitnerSystem* leitnerSystem;
- bool activeLeitnerSystem;
+ LeitnerSystem* leitnerSystem;
+ bool activeLeitnerSystem;
};
//-----------
// Attributes
- if (!readExpressionChildAttributes( domElementExpressionChild,
- lang,
- grade, r_grade,
- qcount, r_qcount,
- qdate, r_qdate,
- remark,
- bcount, r_bcount,
- query_id,
- pronunce,
- width,
- type,
- faux_ami_t,
- faux_ami_f,
- synonym,
- example,
- antonym,
- usage,
- paraphrase))
+ if (!readExpressionChildAttributes( domElementExpressionChild,
+ lang,
+ grade, r_grade,
+ qcount, r_qcount,
+ qdate, r_qdate,
+ remark,
+ bcount, r_bcount,
+ query_id,
+ pronunce,
+ width,
+ type,
+ faux_ami_t,
+ faux_ami_f,
+ synonym,
+ example,
+ antonym,
+ usage,
+ paraphrase))
return false;
--- /dev/null
+/***************************************************************************
+ read a KEduVocDocument from a WQL file
+ -----------------------------------------------------------------------
+ copyright : (C) 2004 Peter Hedlung
+ (C) 2005 The KDE-EDU team
+ email : peter@peterandlinda.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 <kapplication.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+
+#include <qdom.h>
+#include <qtextstream.h>
+
+#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->langs.push_back(s);
+ m_doc->langs.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;
+}
--- /dev/null
+/***************************************************************************
+ read a KEduVocDocument from a WQL file
+ -----------------------------------------------------------------------
+ copyright : (C) 2004 Peter Hedlund
+ : (c) 2005 The KDE-EDU team
+ email : peter@peterandlinda.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 <qfile.h>
+
+#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
--- /dev/null
+/***************************************************************************
+ export a KEduVocDocument to a WQL file
+ -----------------------------------------------------------------------
+ copyright : (C) 2004 Peter Hedlung
+ (C) 2005 The KDE-EDU team
+ email : peter@peterandlinda.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 <kdebug.h>
+#include <qdom.h>
+#include <qtextstream.h>
+#include <qfont.h>
+
+#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->getFont() != NULL)
+ writeFont(*(doc->getFont()));
+ // TODO writeCharacters(Prefs::specialCharacters());
+ // TODO Find the vertical header width, handle the case where there are not exactly two languages
+ writeGridInfo(10, m_doc->getSizeHint(0), m_doc->getSizeHint(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->getOriginalIdent(), m_doc->getIdent(1));
+ int r = m_doc->numEntries();
+ for (int w=0; w < r; w++)
+ {
+ // TODO Find the row height (g->rowHeight(w))
+ writeItem(m_doc->getEntry(w)->getOriginal(), m_doc->getEntry(w)->getTranslation(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") <<winendl;
+ m_outputStream << QString("FontItalic1=%1").arg(font.italic() ? "1" : "0") <<winendl;
+ m_outputStream << "FontColor1=0" << winendl;
+ m_outputStream << "CharSet1=0" << winendl;
+ m_outputStream << "Layout1=0" << winendl;
+
+ m_outputStream << "FontName2=\"" << font.family() << "\"" << winendl;
+ m_outputStream << "FontSize2=" << QString::number(font.pointSize()) << winendl;
+ m_outputStream << QString("FontBold2=%1").arg(font.bold() ? "1" : "0") <<winendl;
+ m_outputStream << QString("FontItalic2=%1").arg(font.italic() ? "1" : "0") <<winendl;
+ m_outputStream << "FontColor2=0" << winendl;
+ m_outputStream << "CharSet2=0" << winendl;
+ m_outputStream << "Layout2=0" << winendl << winendl;
+}
+
+void KEduVocWqlWriter::writeCharacters( const QString & s )
+{
+ m_outputStream << "[Character Info]" << winendl;
+ m_outputStream << "Characters1=" << s << winendl;
+ m_outputStream << "Characters2=" << s << winendl << winendl;
+}
+
+void KEduVocWqlWriter::writeGridInfo( int col0, int col1, int col2, int numRows )
+{
+ m_outputStream << "[Grid Info]" << winendl;
+ m_outputStream << "ColWidth0=" << QString::number(col0) << winendl;
+ m_outputStream << "ColWidth1=" << QString::number(col1) << winendl;
+ m_outputStream << "ColWidth2=" << QString::number(col2) << winendl;
+ m_outputStream << "RowCount=" << QString::number(numRows + 1) << winendl; //Add one for the header
+}
+
+void KEduVocWqlWriter::writeSelection( int lc, int tr, int rc, int br ) //part of [Grid Info]
+{
+ m_outputStream << "SelLeft=" << QString::number(lc + 1) << winendl;
+ m_outputStream << "SelTop=" << QString::number(tr + 1) << winendl;
+ m_outputStream << "SelRight=" << QString::number(rc + 1) << winendl;
+ m_outputStream << "SelBottom=" << QString::number(br + 1) << winendl << winendl;
+}
+
+void KEduVocWqlWriter::writeFirstItem( const QString & ll, const QString & rl )
+{
+ m_outputStream << "[Vocabulary]" << winendl;
+ m_outputStream << ll << " [0000000300]" << winendl;
+ m_outputStream << rl << winendl;
+}
+
+void KEduVocWqlWriter::writeItem( const QString & left, const QString & right, int rh )
+{
+ m_outputStream << left << QString( " [%1]").arg(rh * 15, 10, 10 ) << winendl ;
+ m_outputStream << right << winendl;
+}
\ No newline at end of file
--- /dev/null
+/***************************************************************************
+ export a KEduVocDocument to a WQL file
+ -----------------------------------------------------------------------
+ copyright : (C) 2004 Peter Hedlung
+ (C) 2005 The KDE-EDU team
+ email : peter@peterandlinda.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 KEDUVOCWQLWRITER_H
+#define KEDUVOCWQLWRITER_H
+
+#include <qfile.h>
+#include <qfont.h>
+
+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
return m_selectedSystem;
}
-#include "prefleitner.moc"
+//#include "prefleitner.moc"