From 4cf33e9ae71c19f85169842c5dc7dc1bf8ccfba2 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Thu, 19 Apr 2018 16:21:23 +0200 Subject: [PATCH] . --- cbook.cpp | 3 +- cbook.h | 2 +- cchapter.cpp | 3 +- cchapter.h | 5 +- ccharacter.cpp | 310 +++++++ ccharacter.h | 147 ++++ cdocumentreader.cpp | 1960 ------------------------------------------- cdocumentreader.h | 212 ----- cdocumentwriter.cpp | 688 --------------- cdocumentwriter.h | 82 -- cmainwindow.cpp | 4 +- cmainwindow.ui | 17 +- cpart.cpp | 3 +- cpart.h | 2 +- cscene.cpp | 3 +- cscene.h | 2 +- cstorybook.cpp | 7 +- cstorybook.h | 2 +- ctextdocument.cpp | 50 +- ctextdocument.h | 6 +- qtStoryWriter.pro | 24 +- 21 files changed, 516 insertions(+), 3016 deletions(-) create mode 100644 ccharacter.cpp create mode 100644 ccharacter.h delete mode 100644 cdocumentreader.cpp delete mode 100644 cdocumentreader.h delete mode 100644 cdocumentwriter.cpp delete mode 100644 cdocumentwriter.h diff --git a/cbook.cpp b/cbook.cpp index 645d494..7114871 100644 --- a/cbook.cpp +++ b/cbook.cpp @@ -8,7 +8,8 @@ #include -cBook::cBook(const QString &szTitle) : +cBook::cBook(const QString &szTitle, QObject *parent) : + QObject(parent), m_szTitle(szTitle), m_szSubtitle(""), m_szShortDescription(""), diff --git a/cbook.h b/cbook.h index 2b94888..1d3e096 100644 --- a/cbook.h +++ b/cbook.h @@ -12,7 +12,7 @@ class cBook : public QObject { Q_OBJECT public: - cBook(const QString& szTitle = ""); + explicit cBook(const QString& szTitle = "", QObject *parent = nullptr); bool load(); bool save(); diff --git a/cchapter.cpp b/cchapter.cpp index aeb0cb1..38e2641 100644 --- a/cchapter.cpp +++ b/cchapter.cpp @@ -6,7 +6,8 @@ #include -cChapter::cChapter(qint32 iID) : +cChapter::cChapter(qint32 iID, QObject *parent) : + QObject(parent), m_iID(iID), m_lpPart(0), m_szName(""), diff --git a/cchapter.h b/cchapter.h index aa2a08c..de8b02b 100644 --- a/cchapter.h +++ b/cchapter.h @@ -10,10 +10,11 @@ #include -class cChapter +class cChapter : public QObject { + Q_OBJECT public: - cChapter(qint32 iID = -1); + explicit cChapter(qint32 iID = -1, QObject *parent = nullptr); void setID(const qint32& iID); qint32 id(); diff --git a/ccharacter.cpp b/ccharacter.cpp new file mode 100644 index 0000000..55a1f3a --- /dev/null +++ b/ccharacter.cpp @@ -0,0 +1,310 @@ +#include "ccharacter.h" + + +cCharacter::cCharacter(qint32 iID, QObject *parent) : + m_id(id), + QObject(parent), + m_bMainCharacter(false), + m_szCreature(QString("")), + m_gender(GENDER::GENDER_undefined), + m_szTitle(QString("")), + m_szFirstName(QString("")), + m_szMiddleName(QString("")), + m_szLastName(QString("")), + m_szNickName(QString("")), + m_dHeight(-1), + m_dWeight(-1), + m_dAge(-1), + m_dateOfBirth(QDate(1, 1, 1)), + m_szPlaceOfBirth(QString("")), + m_dateOfDeath(QDate(1, 1, 1)), + m_szPlaceOfDeath(QString("")), + m_szHairColor(QString("")), + m_szHairCut(QString("")), + m_szHairLength(QString("")), + m_szFigure(QString("")), + m_szNature(QString("")), + m_szSpokenLanguages(QString("")), + m_szSkin(QString("")), + m_szSchool(QString("")), + m_szJob(QString("")), + m_szDescription(QString("")) +{ +} + +void cCharacter::setID(const qint32& iID) +{ + m_id = id; +} + +qint32 cCharacter::id() +{ + return(m_id); +} + +void cCharacter::setMainCharacter(bool bMainCharacter) +{ + m_bMainCharacter = bMainCharacter; +} + +bool cCharacter::mainCharacter() +{ + return(m_bMainCharacter); +} + +void cCharacter::setCreature(const QString& szCreature) +{ + m_szCreature = szCreature; +} + +QString cCharacter::creature() +{ + return(m_szCreature); +} + +void cCharacter::setGender(GENDER gender) +{ + m_gender = gender; +} + +GENDER cCharacter::gender() +{ + return(gender); +} + +void cCharacter::setTitle(const QString& szTitle) +{ + m_szTitle = szTitle; +} + +QString cCharacter::title() +{ + return(m_szTitle); +} + +void cCharacter::setFirstName(const QString& szFirstName) +{ + m_szFirstName = szFirstName; +} + +QString cCharacter::firstName() +{ + return(m_szFirstName); +} + +void cCharacter::setMiddleName(const QString& szMiddleName) +{ + m_szMiddleName = szMiddleName; +} + +QString cCharacter::middleName() +{ + return(m_szMiddleName); +} + +void cCharacter::setLastName(const QString& szLastName) +{ + m_szLastName = szLastName; +} + +QString cCharacter::lastName() +{ + return(m_szLastName); +} + +void cCharacter::setNickName(const QString& szNickName) +{ + m_szNickName = szNickName; +} + +QString cCharacter::nickName() +{ + return(m_szNickName); +} + +void cCharacter::setHeight(qreal dHeight) +{ + m_dHeight = dHeight; +} + +qreal cCharacter::height() +{ + return(m_dHeight); +} + +void cCharacter::setWeight(qreal dWeight) +{ + m_dWeight = dWeight; +} + +qreal cCharacter::weight() +{ + return(m_dWeight); +} + +void cCharacter::setAge(qreal dAge) +{ + m_dAge = dAge; +} + +qreal cCharacter::age() +{ + return(m_dAge); +} + +void cCharacter::setDateOfBirth(const QDate& dateOfBirth) +{ + m_dateOfBirth = dateOfBirth; +} + +QDateTime cCharacter::dateOfBirth() +{ + return(m_dateOfBirth); +} + +void cCharacter::setPlaceOfBirth(const QString& szPlaceOfBirth) +{ + m_szPlaceOfBirth = szPlaceOfBirth; +} + +QString cCharacter::placeOfBirth() +{ + return(m_szPlaceOfBirth); +} + +void cCharacter::setDateOfDeath(const QDate& dateOfDeath) +{ + m_dateOfDeath = dateOfDeath; +} + +QDateTime cCharacter::dateOfDeath() +{ + return(m_dateOfDeath); +} + +void cCharacter::setPlaceOfDeath(const QString& szPlaceOfDeath) +{ + m_szPlaceOfDeath = szPlaceOfDeath; +} + +QString cCharacter::placeOfDeath() +{ + return(m_szPlaceOfDeath); +} + +void cCharacter::setHairColor(const QString& szHairColor) +{ + m_szHairColor = szHairColor; +} + +QString cCharacter::hairColor() +{ + return(m_szHairColor); +} + +void cCharacter::setHairCut(const QString& szHairCut) +{ + m_szHairCut = szHairCut; +} + +QString cCharacter::hairCut() +{ + return(m_szHairCut); +} + +void cCharacter::setHairLength(const QString& szHairLength) +{ + m_szHairLength = szHairLength; +} + +QString cCharacter::hairLength() +{ + return(m_szHairLength); +} + +void cCharacter::setFigure(const QString& szFigure) +{ + m_szFigure = szFigure; +} + +QString cCharacter::figure() +{ + return(m_szFigure); +} + +void cCharacter::setNature(const QString& szNature) +{ + m_szNature = szNature; +} + +QString cCharacter::nature() +{ + return(m_szNature); +} + +void cCharacter::setSpokenLanguages(const QString& szSpokenLanguages) +{ + m_szSpokenLanguages = szSpokenLanguages; +} + +QString cCharacter::spokenLanguages() +{ + return(m_szSpokenLanguages); +} + +void cCharacter::setSkin(const QString& szSkin) +{ + m_szSkin = szSkin; +} + +QString cCharacter::skin() +{ + return(m_szSkin); +} + +void cCharacter::setSchool(const QString& szSchool) +{ + m_szSchool = szSchool; +} + +QString cCharacter::school() +{ + return(m_szSchool); +} + +void cCharacter::setJob(const QString& szJob) +{ + m_szJob = szJob; +} + +QString cCharacter::job() +{ + return(m_szJob); +} + +void cCharacter::setDescription(const QString& szDescription) +{ + m_szDescription = szDescription; +} + +QString cCharacter::description() +{ + return(m_szDescription); +} + +bool cCharacterList::load() +{ + cScene* lpScene = find(iID); + + if(!lpScene) + { + lpScene = new cScene(iID); + append(lpScene); + } + + return(lpScene); +} + +bool cCharacterList::save(); +cCharacter* cCharacterList::add(const qint32& iID); +cCharacter* cCharacterList::find(const qint32& iID); diff --git a/ccharacter.h b/ccharacter.h new file mode 100644 index 0000000..a2a7589 --- /dev/null +++ b/ccharacter.h @@ -0,0 +1,147 @@ +#ifndef CCHARACTER_H +#define CCHARACTER_H + + +#include +#include +#include +#include +#include +#include + + +class cCharacter : public QObject +{ + Q_OBJECT +public: + enum GENDER + { + GENDER_undefined = 0, + GENDER_male = 1, + GENDER_female = 2, + }; + + explicit cCharacter(qint32 iID = -1, QObject *parent = nullptr); + + void setID(const qint32& iID); + qint32 id(); + + void setMainCharacter(bool bMainCharacter); + bool mainCharacter(); + + void setCreature(const QString& szCreature); + QString creature(); + + void setGender(GENDER gender); + GENDER gender(); + + void setTitle(const QString& szTitle); + QString title(); + + void setFirstName(const QString& szFirstName); + QString firstName(); + + void setMiddleName(const QString& szMiddleName); + QString middleName(); + + void setLastName(const QString& szLastName); + QString lastName(); + + void setNickName(const QString& szNickName); + QString nickName(); + + void setHeight(qreal dHeight); + qreal height(); + + void setWeight(qreal dWeight); + qreal weight(); + + void setAge(qreal dAge); + qreal age(); + + void setDateOfBirth(const QDate& dateOfBirth); + QDateTime dateOfBirth(); + + void setPlaceOfBirth(const QString& szPlaceOfBirth); + QString placeOfBirth(); + + void setDateOfDeath(const QDate& dateOfDeath); + QDateTime dateOfDeath(); + + void setPlaceOfDeath(const QString& szPlaceOfDeath); + QString placeOfDeath(); + + void setHairColor(const QString& szHairColor); + QString hairColor(); + + void setHairCut(const QString& szHairCut); + QString hairCut(); + + void setHairLength(const QString& szHairLength); + QString hairLength(); + + void setFigure(const QString& szFigure); + QString figure(); + + void setNature(const QString& szNature); + QString nature(); + + void setSpokenLanguages(const QString& szSpokenLanguages); + QString spokenLanguages(); + + void setSkin(const QString& szSkin); + QString skin(); + + void setSchool(const QString& szSchool); + QString school(); + + void setJob(const QString& szJob); + QString job(); + + void setDescription(const QString& szDescription); + QString description(); +private: + qint32 m_id; + bool m_bMainCharacter; + QString m_szCreature; + GENDER m_gender; + QString m_szTitle; + QString m_szFirstName; + QString m_szMiddleName; + QString m_szLastName; + QString m_szNickName; + qreal m_dHeight; + qreal m_dWeight; + qreal m_dAge; + QDate m_dateOfBirth; + QString m_szPlaceOfBirth; + QDate m_dateOfDeath; + QString m_szPlaceOfDeath; + QString m_szHairColor; + QString m_szHairCut; + QString m_szHairLength; + QString m_szFigure; + QString m_szNature; + QString m_szSpokenLanguages; + QString m_szSkin; + QString m_szSchool; + QString m_szJob; + QString m_szDescription; +signals: + +public slots: +}; + +Q_DECLARE_METATYPE(cCharacter*) + +class cCharacterList : public QList +{ +public: + bool load(); + bool save(); + + cCharacter* add(const qint32& iID); + cCharacter* find(const qint32& iID); +}; + +#endif // CCHARACTER_H diff --git a/cdocumentreader.cpp b/cdocumentreader.cpp deleted file mode 100644 index d42643b..0000000 --- a/cdocumentreader.cpp +++ /dev/null @@ -1,1960 +0,0 @@ -#include "cdocumentreader.h" -#include "ctextdocument.h" - -#include "common.h" - -#include - -#include -#include - -#include - -#include -#include - -cDocumentReader::cDocumentReader(const QString &szFileName, bool bZip) : - m_bFirstBlock(true), - m_bZip(bZip), - m_szFileName(szFileName) -{ -} - -cDocumentReader::~cDocumentReader() -{ - close(); -} - -bool cDocumentReader::open() -{ - if(m_bZip) - { - m_zip.setZipName(m_szFileName); - - if(!m_zip.open(QuaZip::mdUnzip)) - return(false); - - m_zip.setCurrentFile("document.xml"); - m_zipFile.setZip(&m_zip); - - if(!m_zipFile.open(QIODevice::ReadOnly)) - { - m_zip.close(); - return(false); - } - } - else - { - m_file.setFileName(m_szFileName); - - if(!m_file.open(QIODevice::ReadOnly)) - return(false); - } - - return(true); -} - -bool cDocumentReader::close() -{ - if(m_bZip) - { - if(m_zip.isOpen()) - { - if(m_zipFile.isOpen()) - m_zipFile.close(); - m_zip.close(); - } - } - else - { - if(m_file.isOpen()) - m_file.close(); - } - - return(true); -} - -cTextDocument* cDocumentReader::readDocument() -{ - if(!open()) - return(0); - - cTextDocument* lpDocument; - QDomDocument doc; - QString errorStr; - int errorLine; - int errorColumn; - - if(m_bZip) - { - if(!doc.setContent(&m_zipFile, false, &errorStr, &errorLine, &errorColumn)) - return(0); - } - else - { - if(!doc.setContent(&m_file, false, &errorStr, &errorLine, &errorColumn)) - return(0); - } - - QDomElement root = doc.documentElement(); - if(root.tagName().compare("document", Qt::CaseInsensitive)) - return(0); - - lpDocument = new cTextDocument; - QDomNode child = root.firstChild(); - QVector allFormats; - - QTextCursor cursor(lpDocument); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("documentSettings", Qt::CaseInsensitive)) - parseSettings(child.toElement(), lpDocument); - else if(!child.toElement().tagName().compare("defaults", Qt::CaseInsensitive)) - parseDefaults(child.toElement(), lpDocument); - else if(!child.toElement().tagName().compare("allFormats", Qt::CaseInsensitive)) - allFormats = parseAllFormats(child.toElement()); - else if(!child.toElement().tagName().compare("textBlockFormats", Qt::CaseInsensitive)) - { - // SHOULD BE COVERED BY TEXTBLOCKS - } - else if(!child.toElement().tagName().compare("textBlocks", Qt::CaseInsensitive)) - { - QDomNode block = child.firstChild(); - - while(!block.isNull()) - { - if(!block.toElement().tagName().compare("textBlock", Qt::CaseInsensitive)) - parseTextBlock(block.toElement(), &cursor, allFormats); - else - myDebug << "readDocument: unknown element: " << child.toElement().tagName(); - - block = block.nextSibling(); - } - } - else - myDebug << "readDocument: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - close(); - - return(lpDocument); -} - -void cDocumentReader::parseSettings(const QDomElement &element, cTextDocument* lpDocument) -{ - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("documentMargin", Qt::CaseInsensitive)) - lpDocument->setDocumentMargin(node.toAttr().nodeValue().toDouble()); - else if(!node.toAttr().name().compare("indentWidth", Qt::CaseInsensitive)) - lpDocument->setIndentWidth(node.toAttr().nodeValue().toDouble()); - else if(!node.toAttr().name().compare("textWidth", Qt::CaseInsensitive)) - lpDocument->setTextWidth(node.toAttr().nodeValue().toDouble()); - else if(!node.toAttr().name().compare("useDesignMetrics", Qt::CaseInsensitive)) - lpDocument->setUseDesignMetrics(node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false); - else - myDebug << "parseSettings: unknown attribute: " << node.toAttr().name(); - } - - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("metaInformation", Qt::CaseInsensitive)) - { - attributes = child.toElement().attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - if(!node.toAttr().name().compare("documentTitle", Qt::CaseInsensitive)) - lpDocument->setMetaInformation(QTextDocument::DocumentTitle, node.toAttr().nodeValue()); - else if(!node.toAttr().name().compare("documentUrl", Qt::CaseInsensitive)) - lpDocument->setMetaInformation(QTextDocument::DocumentUrl, node.toAttr().nodeValue()); - else - myDebug << "parseSettings: unknown attribute: " << node.toAttr().name(); - } - } - else if(!child.toElement().tagName().compare("baseUrl", Qt::CaseInsensitive)) - { - attributes = child.toElement().attributes(); - QString authority; - QString fragment; - QString host; - QString password; - QString path; - int port; - QString query; - QString scheme; - QString urlName; - QString userInfo; - QString userName; - - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - if(!node.toAttr().name().compare("authority", Qt::CaseInsensitive)) - authority = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("fragment", Qt::CaseInsensitive)) - fragment = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("host", Qt::CaseInsensitive)) - host = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("password", Qt::CaseInsensitive)) - password = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("path", Qt::CaseInsensitive)) - path = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("port", Qt::CaseInsensitive)) - port = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("query", Qt::CaseInsensitive)) - query = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("scheme", Qt::CaseInsensitive)) - scheme = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("url", Qt::CaseInsensitive)) - urlName = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("userInfo", Qt::CaseInsensitive)) - userInfo = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("userName", Qt::CaseInsensitive)) - userName =node.toAttr().nodeValue(); - else - myDebug << "parseSettings: unknown attribute: " << node.toAttr().name(); - } - - if(!urlName.isEmpty()) - { - QUrl url(urlName); - url.setAuthority(authority); - url.setFragment(fragment); - url.setHost(host); - url.setPassword(password); - url.setPath(path); - url.setPort(port); - url.setQuery(query); - url.setScheme(scheme); - url.setUserInfo(userInfo); - url.setUserName(userName); - - if(url.isValid()) - lpDocument->setBaseUrl(url); - } - } - else if(!child.toElement().tagName().compare("pageSize", Qt::CaseInsensitive)) - { - attributes = child.toElement().attributes(); - QSizeF size; - - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - if(!node.toAttr().name().compare("width", Qt::CaseInsensitive)) - size.setWidth(node.toAttr().nodeValue().toDouble()); - else if(!node.toAttr().name().compare("height", Qt::CaseInsensitive)) - size.setHeight(node.toAttr().nodeValue().toDouble()); - } - if(size.isValid()) - lpDocument->setPageSize(size); - } - else - myDebug << "parseSettings: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } -} - -void cDocumentReader::parseDefaults(const QDomElement &element, cTextDocument* lpDocument) -{ - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("defaultCursorMoveStyle", Qt::CaseInsensitive)) - lpDocument->setDefaultCursorMoveStyle((Qt::CursorMoveStyle)node.toAttr().nodeValue().toInt()); - else if(!node.toAttr().name().compare("defaultStyleSheet", Qt::CaseInsensitive)) - lpDocument->setDefaultStyleSheet(node.toAttr().nodeValue()); - else - myDebug << "parseDefaults: unknown attribute: " << node.toAttr().name(); - } - - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("defaultFont", Qt::CaseInsensitive)) - lpDocument->setDefaultFont(parseFont(child.toElement())); - else if(!child.toElement().tagName().compare("defaultTextOption", Qt::CaseInsensitive)) - lpDocument->setDefaultTextOption(parseDefaultTextOption(child.toElement())); - else - myDebug << "parseDefaults: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } -} - -QFont cDocumentReader::parseFont(const QDomElement& element) -{ - QDomNamedNodeMap attributes = element.attributes(); - - bool bold; - QFont::Capitalization capitalization; - QString family; - bool fixedPitch; - QFont::HintingPreference hintingPreference; - bool italic; - bool kerning; - qreal letterSpacing; - QFont::SpacingType letterSpacingType; - int overline; - int pixelSize; - int pointSize; - qreal pointSizeF; - int stretch; - bool strikeOut; - QFont::Style style; - QFont::StyleHint styleHint; - QString styleName; - QFont::StyleStrategy styleStrategy; - bool underline; - int weight; - qreal wordSpacing; - - - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("bold", Qt::CaseInsensitive)) - bold = node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false; - else if(!node.toAttr().name().compare("capitalization", Qt::CaseInsensitive)) - capitalization = (QFont::Capitalization)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("family", Qt::CaseInsensitive)) - family = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("fixedPitch", Qt::CaseInsensitive)) - fixedPitch = node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false; - else if(!node.toAttr().name().compare("hintingPreference", Qt::CaseInsensitive)) - hintingPreference = (QFont::HintingPreference)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("italic", Qt::CaseInsensitive)) - italic = node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false; - else if(!node.toAttr().name().compare("kerning", Qt::CaseInsensitive)) - kerning = node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false; - else if(!node.toAttr().name().compare("letterSpacing", Qt::CaseInsensitive)) - letterSpacing = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("letterSpacingType", Qt::CaseInsensitive)) - letterSpacingType = (QFont::SpacingType)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("overline", Qt::CaseInsensitive)) - overline = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("pixelSize", Qt::CaseInsensitive)) - pixelSize = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("pointSize", Qt::CaseInsensitive)) - pointSize = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("pointSizeF", Qt::CaseInsensitive)) - pointSizeF = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("stretch", Qt::CaseInsensitive)) - stretch = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("strikeOut", Qt::CaseInsensitive)) - strikeOut = node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false; - else if(!node.toAttr().name().compare("style", Qt::CaseInsensitive)) - style = (QFont::Style)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("styleHint", Qt::CaseInsensitive)) - styleHint = (QFont::StyleHint)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("styleName", Qt::CaseInsensitive)) - styleName = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("styleStrategy", Qt::CaseInsensitive)) - styleStrategy = (QFont::StyleStrategy)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("underline", Qt::CaseInsensitive)) - underline = node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false; - else if(!node.toAttr().name().compare("weight", Qt::CaseInsensitive)) - weight = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("wordSpacing", Qt::CaseInsensitive)) - wordSpacing = node.toAttr().nodeValue().toDouble(); - else - myDebug << "parseFont: unknown attribute: " << node.toAttr().name(); - } - - QFont font(family); - font.setBold(bold); - font.setCapitalization(capitalization); - font.setFixedPitch(fixedPitch); - font.setHintingPreference(hintingPreference); - font.setItalic(italic); - font.setKerning(kerning); - font.setLetterSpacing(letterSpacingType, letterSpacing); - font.setOverline(overline); - if(pointSizeF > 0) - font.setPointSizeF(pointSizeF); - else if(pointSize > 0) - font.setPointSize(pointSize); - else if(pixelSize > 0) - font.setPixelSize(pixelSize); - font.setStretch(stretch); - font.setStretch(strikeOut); - font.setStyle(style); - font.setStyleHint(styleHint); - font.setStyleName(styleName); - font.setStyleStrategy(styleStrategy); - font.setUnderline(underline); - font.setWeight(weight); - font.setWordSpacing(wordSpacing); - - return(font); -} - -QTextOption cDocumentReader::parseDefaultTextOption(const QDomElement& element) -{ - QTextOption textOption; - - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("alignment", Qt::CaseInsensitive)) - textOption.setAlignment((Qt::AlignmentFlag)node.toAttr().nodeValue().toInt()); - else if(!node.toAttr().name().compare("flags", Qt::CaseInsensitive)) - textOption.setFlags((QTextOption::Flag)node.toAttr().nodeValue().toInt()); - else if(!node.toAttr().name().compare("tabStopDistance", Qt::CaseInsensitive)) - textOption.setTabStopDistance(node.toAttr().nodeValue().toDouble()); - else if(!node.toAttr().name().compare("textDirection", Qt::CaseInsensitive)) - textOption.setTextDirection((Qt::LayoutDirection)node.toAttr().nodeValue().toInt()); - else if(!node.toAttr().name().compare("useDesignMetrics", Qt::CaseInsensitive)) - textOption.setUseDesignMetrics(node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false); - else if(!node.toAttr().name().compare("wrapMode", Qt::CaseInsensitive)) - textOption.setWrapMode((QTextOption::WrapMode)node.toAttr().nodeValue().toInt()); - else - myDebug << "parseDefaultTextOption: unknown attribute: " << node.toAttr().name(); - } - - QList tabArray; - QList tabs; - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("tabArray", Qt::CaseInsensitive)) - { - QDomNode tab = child.toElement().firstChild(); - - while(!tab.isNull()) - { - if(!tab.toElement().tagName().compare("tab", Qt::CaseInsensitive)) - tabArray.append(tab.toElement().nodeValue().toDouble()); - - tab = tab.nextSibling(); - } - } - else if(!child.toElement().tagName().compare("tabs", Qt::CaseInsensitive)) - tabs = parseTabPositions(child.toElement()); - else - myDebug << "parseDefaultTextOption: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - if(!tabArray.isEmpty()) - textOption.setTabArray(tabArray); - if(!tabs.isEmpty()) - textOption.setTabs(tabs); - - return(textOption); -} - -QList cDocumentReader::parseTabPositions(const QDomElement& element) -{ - QList tabs; - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("tabPosition", Qt::CaseInsensitive)) - { - QTextOption::Tab tab; - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("delimiter", Qt::CaseInsensitive)) - tab.delimiter = node.toAttr().nodeValue().at(0); - else if(!node.toAttr().name().compare("position", Qt::CaseInsensitive)) - tab.position = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("type", Qt::CaseInsensitive)) - tab.type = (QTextOption::TabType)node.toAttr().nodeValue().toInt(); - } - tabs.append(tab); - } - else - myDebug << "parseTabPositions: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - return(tabs); -} - -QVector cDocumentReader::parseAllFormats(const QDomElement& element) -{ - QVector allFormats; - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("format", Qt::CaseInsensitive)) - { - cTextFormat format = parseFormat(child.toElement()); - if(format.isValid()) - allFormats.append(format); - } - else - myDebug << "parseAllFormats: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - return(allFormats); -} - -cTextFormat cDocumentReader::parseFormat(const QDomElement& element) -{ - QString typeText; - Qt::LayoutDirection layoutDirection; - //UNUSED - int id; - int type; - - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("id", Qt::CaseInsensitive)) - id = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("type", Qt::CaseInsensitive)) - type = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("typeText", Qt::CaseInsensitive)) - typeText = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("layoutDirection", Qt::CaseInsensitive)) - layoutDirection = (Qt::LayoutDirection)node.toAttr().nodeValue().toInt(); - //else - // myDebug << "parseFormat: unknown attribute: " << node.toAttr().name(); - } - - //UNUSED - id = id; - type = type; - - cTextFormat format(typeText); - - if(!typeText.compare("tableCellFormat", Qt::CaseInsensitive)) - format.tableCellFormat = parseTextTableCellFormat(element); - else if(!typeText.compare("tableFormat", Qt::CaseInsensitive)) - format.tableFormat = parseTextTableFormat(element); - else if(!typeText.compare("imageFormat", Qt::CaseInsensitive)) - format.imageFormat = parseTextImageFormat(element); - else if(!typeText.compare("frameFormat", Qt::CaseInsensitive)) - format.frameFormat = parseTextFrameFormat(element); - else if(!typeText.compare("listFormat", Qt::CaseInsensitive)) - format.listFormat = parseTextListFormat(element); - else if(!typeText.compare("blockFormat", Qt::CaseInsensitive)) - format.blockFormat = parseTextBlockFormat(element); - else if(!typeText.compare("charFormat", Qt::CaseInsensitive)) - format.charFormat = parseTextCharFormat(element); - format.setLayoutDirection(layoutDirection); - - return(format); -} - -QPen cDocumentReader::parsePen(const QDomElement& element) -{ - QDomNamedNodeMap attributes = element.attributes(); - Qt::PenCapStyle capStyle; - qreal dashOffset; - bool isCosmetic; - Qt::PenJoinStyle joinStyle; - qreal miterLimit; - Qt::PenStyle style; - int width; - qreal widthF; - QBrush brush; - QColor color; - QVector dashPattern; - - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("capStyle", Qt::CaseInsensitive)) - capStyle = (Qt::PenCapStyle)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("dashOffset", Qt::CaseInsensitive)) - dashOffset = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("isCosmetic", Qt::CaseInsensitive)) - isCosmetic = node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false; - else if(!node.toAttr().name().compare("joinStyle", Qt::CaseInsensitive)) - joinStyle = (Qt::PenJoinStyle)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("miterLimit", Qt::CaseInsensitive)) - miterLimit = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("style", Qt::CaseInsensitive)) - style = (Qt::PenStyle)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("width", Qt::CaseInsensitive)) - width = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("widthF", Qt::CaseInsensitive)) - widthF = node.toAttr().nodeValue().toDouble(); - else - myDebug << "parsePen: unknown attribute: " << node.toAttr().name(); - } - - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("brush", Qt::CaseInsensitive)) - brush = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("color", Qt::CaseInsensitive)) - color = parseColor(child.toElement()); - else if(!child.toElement().tagName().compare("dashPattern", Qt::CaseInsensitive)) - { - QDomNode pattern = child.toElement().firstChild(); - - while(!pattern.isNull()) - { - if(!pattern.toElement().tagName().compare("pattern", Qt::CaseInsensitive)) - dashPattern.append(pattern.toElement().nodeValue().toDouble()); - else - qDebug() << " parsePen: unknown element: " << pattern.toElement().tagName(); - - pattern = pattern.nextSibling(); - } - } - else - myDebug << " parsePen: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - QPen pen(color); - - pen.setBrush(brush); - if(widthF > 0) - pen.setWidthF(widthF); - else - pen.setWidth(width); - pen.setCapStyle(capStyle); - pen.setDashOffset(dashOffset); - pen.setCosmetic(isCosmetic); - pen.setJoinStyle(joinStyle); - pen.setMiterLimit(miterLimit); - pen.setStyle(style); - if(dashPattern.count()) - pen.setDashPattern(dashPattern); - - return(pen); -} - -QBrush cDocumentReader::parseBrush(const QDomElement& element) -{ - QDomNamedNodeMap attributes = element.attributes(); - Qt::BrushStyle style; - - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("style", Qt::CaseInsensitive)) - style = (Qt::BrushStyle)node.toAttr().nodeValue().toInt(); - else - myDebug << " parseBrush: unknown attribute: " << node.toAttr().name(); - } - - QDomNode child = element.firstChild(); - QColor color; - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("color", Qt::CaseInsensitive)) - color = parseColor(child.toElement()); - else - myDebug << " parseBrush: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - return(QBrush(color, style)); -} - -QColor cDocumentReader::parseColor(const QDomElement& element) -{ - QDomNamedNodeMap attributes = element.attributes(); - int alpha; - int r; - int g; - int b; - - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("alpha", Qt::CaseInsensitive)) - alpha = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("r", Qt::CaseInsensitive)) - r = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("g", Qt::CaseInsensitive)) - g = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("b", Qt::CaseInsensitive)) - b = node.toAttr().nodeValue().toInt(); - else - myDebug << " parseColor: unknown attribute: " << node.toAttr().name(); - } - - return(QColor(r, g, b, alpha)); -} - -QTextTableCellFormat cDocumentReader::parseTextTableCellFormat(const QDomElement& element) -{ - int leftPadding; - int topPadding; - int rightPadding; - int bottomPadding; - Qt::LayoutDirection layoutDirection; - - QString anchorHref; - bool isAnchor; - QString toolTip; - QTextCharFormat::VerticalAlignment verticalAlignment; - - QBrush background; - QBrush foreground; - QPen textOutline; - QStringList anchorNames; - QMap properties; - QFont font; - QColor underlineColor; - - //UNUSED - int id; - int type; - QString typeText; - - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("id", Qt::CaseInsensitive)) - id = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("type", Qt::CaseInsensitive)) - type = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("typeText", Qt::CaseInsensitive)) - typeText = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("anchorHref", Qt::CaseInsensitive)) - anchorHref = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("isAnchor", Qt::CaseInsensitive)) - isAnchor = node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false; - else if(!node.toAttr().name().compare("toolTip", Qt::CaseInsensitive)) - toolTip = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("verticalAlignment", Qt::CaseInsensitive)) - verticalAlignment = (QTextCharFormat::VerticalAlignment)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("leftPadding", Qt::CaseInsensitive)) - leftPadding = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("topPadding", Qt::CaseInsensitive)) - topPadding = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("rightPadding", Qt::CaseInsensitive)) - rightPadding = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("bottomPadding", Qt::CaseInsensitive)) - bottomPadding = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("layoutDirection", Qt::CaseInsensitive)) - layoutDirection = (Qt::LayoutDirection)node.toAttr().nodeValue().toInt(); - else - myDebug << " parseTextTableCellFormat: unknown attribute: " << node.toAttr().name(); - } - - //UNUSED - id = id; - type = type; - typeText = typeText; - - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("background", Qt::CaseInsensitive)) - background = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("foreground", Qt::CaseInsensitive)) - foreground = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("properties", Qt::CaseInsensitive)) - { - int key; - QVariant::Type type; - QString value; - - QDomNode property = child.toElement().firstChild(); - - while(!property.isNull()) - { - if(!property.toElement().tagName().compare("key", Qt::CaseInsensitive)) - key = property.toElement().toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("type", Qt::CaseInsensitive)) - type = (QVariant::Type)property.toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("value", Qt::CaseInsensitive)) - value = property.toElement().nodeValue(); - - QVariant propertyValue(value); - propertyValue.convert(type); - properties.insert(key, propertyValue); - - property = property.nextSibling(); - } - } - else if(!child.toElement().tagName().compare("textOutline", Qt::CaseInsensitive)) - textOutline = parsePen(child.toElement()); - else if(!child.toElement().tagName().compare("anchorNames", Qt::CaseInsensitive)) - { - - QDomNode anchors = child.toElement().firstChild(); - - while(!anchors.isNull()) - { - if(!child.toElement().tagName().compare("anchor", Qt::CaseInsensitive)) - anchorNames.append(child.toElement().nodeValue()); - - anchors = anchors.nextSibling(); - } - } - else if(!child.toElement().tagName().compare("font", Qt::CaseInsensitive)) - font = parseFont(child.toElement()); - else if(!child.toElement().tagName().compare("underlineColor", Qt::CaseInsensitive)) - underlineColor = parseColor(child.toElement()); - else - myDebug << " parseTextTableCellFormat: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - QTextTableCellFormat format; - - format.setAnchorHref(anchorHref); - format.setAnchor(isAnchor); - format.setToolTip(toolTip); - format.setVerticalAlignment(verticalAlignment); - format.setLeftPadding(leftPadding); - format.setTopPadding(topPadding); - format.setRightPadding(rightPadding); - format.setBottomPadding(bottomPadding); - format.setLayoutDirection(layoutDirection); - format.setBackground(background); - format.setForeground(foreground); - format.setTextOutline(textOutline); - format.setAnchorNames(anchorNames); - - QMapIterator property(properties); - while(property.hasNext()) - { - property.next(); - format.setProperty(property.key(), property.value()); - } - - format.setFont(font); - format.setUnderlineColor(underlineColor); - - return(format); -} - -QTextTableFormat cDocumentReader::parseTextTableFormat(const QDomElement& element) -{ - Qt::AlignmentFlag alignment; - int cellPadding; - int cellSpacing; - int columns; - int headerRowCount; - qreal border; - QTextTableFormat::BorderStyle borderStyle; - qreal margin; - qreal leftMargin; - qreal topMargin; - qreal rightMargin; - qreal bottomMargin; - qreal width; - qreal height; - qreal padding; - QTextTableFormat::PageBreakFlags pageBreakPolicy; - QTextTableFormat::Position position; - Qt::LayoutDirection layoutDirection; - QVector columnWidthContraints; - QBrush borderBrush; - QBrush background; - QBrush foreground; - QMap properties; - - //UNUSED - int id; - int type; - QString typeText; - - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("id", Qt::CaseInsensitive)) - id = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("type", Qt::CaseInsensitive)) - type = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("typeText", Qt::CaseInsensitive)) - typeText = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("alignment", Qt::CaseInsensitive)) - alignment = (Qt::AlignmentFlag)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("cellPadding", Qt::CaseInsensitive)) - cellPadding = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("cellSpacing", Qt::CaseInsensitive)) - cellSpacing = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("columns", Qt::CaseInsensitive)) - columns = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("headerRowCount", Qt::CaseInsensitive)) - headerRowCount = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("border", Qt::CaseInsensitive)) - border = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("borderStyle", Qt::CaseInsensitive)) - borderStyle = (QTextTableFormat::BorderStyle)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("margin", Qt::CaseInsensitive)) - margin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("leftMargin", Qt::CaseInsensitive)) - leftMargin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("topMargin", Qt::CaseInsensitive)) - topMargin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("rightMargin", Qt::CaseInsensitive)) - rightMargin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("bottomMargin", Qt::CaseInsensitive)) - bottomMargin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("width", Qt::CaseInsensitive)) - width = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("height", Qt::CaseInsensitive)) - height = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("padding", Qt::CaseInsensitive)) - padding = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("pageBreakPolicy", Qt::CaseInsensitive)) - pageBreakPolicy = (QTextTableFormat::PageBreakFlags)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("position", Qt::CaseInsensitive)) - position = (QTextTableFormat::Position)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("layoutDirection", Qt::CaseInsensitive)) - layoutDirection = (Qt::LayoutDirection)node.toAttr().nodeValue().toInt(); - else - myDebug << " parseTextTableFormat: unknown attribute: " << node.toAttr().name(); - } - - //UNUSED - id = id; - type = type; - typeText = typeText; - - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("columnWidthConstraints", Qt::CaseInsensitive)) - { - QDomNode constraints = child.toElement().firstChild(); - while(!constraints.isNull()) - { - if(!constraints.toElement().tagName().compare("columnWidthConstraint", Qt::CaseInsensitive)) - { - qreal rawValue; - QTextLength::Type type; - QDomNamedNodeMap constraint = constraints.attributes(); - - for(int x = 0;x < constraint.count();x++) - { - QDomNode node = constraint.item(x); - - if(!node.toAttr().name().compare("rawValue", Qt::CaseInsensitive)) - rawValue = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("type", Qt::CaseInsensitive)) - type = (QTextLength::Type)node.toAttr().nodeValue().toInt(); - } - - columnWidthContraints.append(QTextLength(type, rawValue)); - } - else - myDebug << " parseTextTableFormat: unknown element: " << child.toElement().tagName(); - - constraints = constraints.nextSibling(); - } - } - else if(!child.toElement().tagName().compare("borderBrush", Qt::CaseInsensitive)) - borderBrush = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("background", Qt::CaseInsensitive)) - background = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("foreground", Qt::CaseInsensitive)) - foreground = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("properties", Qt::CaseInsensitive)) - { - int key; - QVariant::Type type; - QString value; - - QDomNode property = child.toElement().firstChild(); - - while(!property.isNull()) - { - if(!property.toElement().tagName().compare("key", Qt::CaseInsensitive)) - key = property.toElement().toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("type", Qt::CaseInsensitive)) - type = (QVariant::Type)property.toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("value", Qt::CaseInsensitive)) - value = property.toElement().nodeValue(); - - QVariant propertyValue(value); - propertyValue.convert(type); - properties.insert(key, propertyValue); - - property = property.nextSibling(); - } - } - else - myDebug << " parseTextTableFormat: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - QTextTableFormat format; - - format.setAlignment(alignment); - format.setCellPadding(cellPadding); - format.setCellSpacing(cellSpacing); - format.setColumns(columns); - format.setHeaderRowCount(headerRowCount); - format.setBorder(border); - format.setBorderStyle(borderStyle); - format.setMargin(margin); - format.setLeftMargin(leftMargin); - format.setTopMargin(topMargin); - format.setRightMargin(rightMargin); - format.setBottomMargin(bottomMargin); - format.setWidth(width); - format.setHeight(height); - format.setPadding(padding); - format.setPageBreakPolicy(pageBreakPolicy); - format.setPosition(position); - format.setLayoutDirection(layoutDirection); - format.setColumnWidthConstraints(columnWidthContraints); - format.setBorderBrush(borderBrush); - format.setBackground(background); - format.setForeground(foreground); - - QMapIterator property(properties); - while(property.hasNext()) - { - property.next(); - format.setProperty(property.key(), property.value()); - } - - return(format); -} - -QTextImageFormat cDocumentReader::parseTextImageFormat(const QDomElement& element) -{ - QString name; - qreal height; - qreal width; - QString anchorHref; - bool isAnchor; - QString toolTip; - QTextCharFormat::VerticalAlignment verticalAlignment; - QBrush background; - QBrush foreground; - QPen textOutline; - QStringList anchorNames; - QMap properties; - QFont font; - QColor underlineColor; - Qt::LayoutDirection layoutDirection; - - //UNUSED - int id; - int type; - QString typeText; - - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("id", Qt::CaseInsensitive)) - id = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("type", Qt::CaseInsensitive)) - type = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("typeText", Qt::CaseInsensitive)) - typeText = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("anchorHref", Qt::CaseInsensitive)) - anchorHref = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("height", Qt::CaseInsensitive)) - height = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("width", Qt::CaseInsensitive)) - width = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("name", Qt::CaseInsensitive)) - name = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("isAnchor", Qt::CaseInsensitive)) - isAnchor = node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false; - else if(!node.toAttr().name().compare("toolTip", Qt::CaseInsensitive)) - toolTip = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("verticalAlignment", Qt::CaseInsensitive)) - verticalAlignment = (QTextCharFormat::VerticalAlignment)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("layoutDirection", Qt::CaseInsensitive)) - layoutDirection = (Qt::LayoutDirection)node.toAttr().nodeValue().toInt(); - else - myDebug << " parseTextImageFormat: unknown attribute: " << node.toAttr().name(); - } - - //UNUSED - id = id; - type = type; - typeText = typeText; - - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("background", Qt::CaseInsensitive)) - background = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("foreground", Qt::CaseInsensitive)) - foreground = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("properties", Qt::CaseInsensitive)) - { - int key; - QVariant::Type type; - QString value; - - QDomNode property = child.toElement().firstChild(); - - while(!property.isNull()) - { - if(!property.toElement().tagName().compare("key", Qt::CaseInsensitive)) - key = property.toElement().toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("type", Qt::CaseInsensitive)) - type = (QVariant::Type)property.toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("value", Qt::CaseInsensitive)) - value = property.toElement().nodeValue(); - - QVariant propertyValue(value); - propertyValue.convert(type); - properties.insert(key, propertyValue); - - property = property.nextSibling(); - } - } - else if(!child.toElement().tagName().compare("textOutline", Qt::CaseInsensitive)) - textOutline = parsePen(child.toElement()); - else if(!child.toElement().tagName().compare("anchorNames", Qt::CaseInsensitive)) - { - - QDomNode anchors = child.toElement().firstChild(); - - while(!anchors.isNull()) - { - if(!child.toElement().tagName().compare("anchor", Qt::CaseInsensitive)) - anchorNames.append(child.toElement().nodeValue()); - - anchors = anchors.nextSibling(); - } - } - else if(!child.toElement().tagName().compare("font", Qt::CaseInsensitive)) - font = parseFont(child.toElement()); - else if(!child.toElement().tagName().compare("underlineColor", Qt::CaseInsensitive)) - underlineColor = parseColor(child.toElement()); - else - myDebug << " parseTextTableCellFormat: unknown element: " << child.toElement().tagName(); - child = child.nextSibling(); - } - - QTextImageFormat format; - - format.setName(name); - format.setHeight(height); - format.setWidth(width); - format.setAnchorHref(anchorHref); - format.setFont(font); - format.setAnchor(isAnchor); - format.setToolTip(toolTip); - format.setVerticalAlignment(verticalAlignment); - format.setBackground(background); - format.setForeground(foreground); - format.setTextOutline(textOutline); - format.setAnchorNames(anchorNames); - format.setLayoutDirection(layoutDirection); - - QMapIterator property(properties); - while(property.hasNext()) - { - property.next(); - format.setProperty(property.key(), property.value()); - } - - format.setUnderlineColor(underlineColor); - - return(format); -} - -QTextFrameFormat cDocumentReader::parseTextFrameFormat(const QDomElement& element) -{ - qreal border; - QTextTableFormat::BorderStyle borderStyle; - qreal margin; - qreal leftMargin; - qreal topMargin; - qreal rightMargin; - qreal bottomMargin; - qreal width; - qreal height; - qreal padding; - QTextTableFormat::PageBreakFlags pageBreakPolicy; - QTextTableFormat::Position position; - QBrush background; - QBrush foreground; - QBrush borderBrush; - QMap properties; - Qt::LayoutDirection layoutDirection; - - //UNUSED - int id; - int type; - QString typeText; - - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("id", Qt::CaseInsensitive)) - id = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("type", Qt::CaseInsensitive)) - type = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("typeText", Qt::CaseInsensitive)) - typeText = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("border", Qt::CaseInsensitive)) - border = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("borderStyle", Qt::CaseInsensitive)) - borderStyle = (QTextTableFormat::BorderStyle)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("margin", Qt::CaseInsensitive)) - margin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("leftMargin", Qt::CaseInsensitive)) - leftMargin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("topMargin", Qt::CaseInsensitive)) - topMargin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("rightMargin", Qt::CaseInsensitive)) - rightMargin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("bottomMargin", Qt::CaseInsensitive)) - bottomMargin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("width", Qt::CaseInsensitive)) - width = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("height", Qt::CaseInsensitive)) - height = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("padding", Qt::CaseInsensitive)) - padding = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("pageBreakPolicy", Qt::CaseInsensitive)) - pageBreakPolicy = (QTextTableFormat::PageBreakFlags)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("position", Qt::CaseInsensitive)) - position = (QTextTableFormat::Position)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("layoutDirection", Qt::CaseInsensitive)) - layoutDirection = (Qt::LayoutDirection)node.toAttr().nodeValue().toInt(); - else - myDebug << " parseTextTableFormat: unknown attribute: " << node.toAttr().name(); - } - - //UNUSED - id = id; - type = type; - typeText = typeText; - - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("background", Qt::CaseInsensitive)) - background = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("foreground", Qt::CaseInsensitive)) - foreground = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("borderBrush", Qt::CaseInsensitive)) - borderBrush = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("properties", Qt::CaseInsensitive)) - { - int key; - QVariant::Type type; - QString value; - - QDomNode property = child.toElement().firstChild(); - - while(!property.isNull()) - { - if(!property.toElement().tagName().compare("key", Qt::CaseInsensitive)) - key = property.toElement().toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("type", Qt::CaseInsensitive)) - type = (QVariant::Type)property.toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("value", Qt::CaseInsensitive)) - value = property.toElement().nodeValue(); - - QVariant propertyValue(value); - propertyValue.convert(type); - properties.insert(key, propertyValue); - - property = property.nextSibling(); - } - } - else - myDebug << " parseTextFrameFormat: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - QTextFrameFormat format; - - format.setBorder(border); - format.setBorderStyle(borderStyle); - format.setMargin(margin); - format.setLeftMargin(leftMargin); - format.setTopMargin(topMargin); - format.setRightMargin(rightMargin); - format.setBottomMargin(bottomMargin); - format.setWidth(width); - format.setHeight(height); - format.setPadding(padding); - format.setPageBreakPolicy(pageBreakPolicy); - format.setPosition(position); - format.setLayoutDirection(layoutDirection); - format.setBackground(background); - format.setForeground(foreground); - format.setBorderBrush(borderBrush); - - QMapIterator property(properties); - while(property.hasNext()) - { - property.next(); - format.setProperty(property.key(), property.value()); - } - - return(format); -} - -QTextListFormat cDocumentReader::parseTextListFormat(const QDomElement& element) -{ - int indent; - QString numberPrefix; - QString numberSuffix; - QTextListFormat::Style style; - Qt::LayoutDirection layoutDirection; - QBrush background; - QBrush foreground; - QMap properties; - - //UNUSED - int id; - int type; - QString typeText; - - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("id", Qt::CaseInsensitive)) - id = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("type", Qt::CaseInsensitive)) - type = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("typeText", Qt::CaseInsensitive)) - typeText = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("indent", Qt::CaseInsensitive)) - indent = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("numberPrefix", Qt::CaseInsensitive)) - numberPrefix = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("numberSuffix", Qt::CaseInsensitive)) - numberSuffix = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("style", Qt::CaseInsensitive)) - style = (QTextListFormat::Style)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("layoutDirection", Qt::CaseInsensitive)) - layoutDirection = (Qt::LayoutDirection)node.toAttr().nodeValue().toInt(); - else - myDebug << " parseTextListFormat: unknown attribute: " << node.toAttr().name(); - } - - //UNUSED - id = id; - type = type; - typeText = typeText; - - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("background", Qt::CaseInsensitive)) - background = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("foreground", Qt::CaseInsensitive)) - foreground = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("properties", Qt::CaseInsensitive)) - { - int key; - QVariant::Type type; - QString value; - - QDomNode property = child.toElement().firstChild(); - - while(!property.isNull()) - { - if(!property.toElement().tagName().compare("key", Qt::CaseInsensitive)) - key = property.toElement().toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("type", Qt::CaseInsensitive)) - type = (QVariant::Type)property.toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("value", Qt::CaseInsensitive)) - value = property.toElement().nodeValue(); - - QVariant propertyValue(value); - propertyValue.convert(type); - properties.insert(key, propertyValue); - - property = property.nextSibling(); - } - } - else - myDebug << " parseTextListFormat: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - QTextListFormat format; - - format.setIndent(indent); - format.setNumberPrefix(numberPrefix); - format.setNumberSuffix(numberSuffix); - format.setStyle(style); - format.setLayoutDirection(layoutDirection); - format.setBackground(background); - format.setForeground(foreground); - - QMapIterator property(properties); - while(property.hasNext()) - { - property.next(); - format.setProperty(property.key(), property.value()); - } - - return(format); -} - -QTextBlockFormat cDocumentReader::parseTextBlockFormat(const QDomElement& element) -{ - Qt::AlignmentFlag alignment; - qreal leftMargin; - qreal topMargin; - qreal rightMargin; - qreal bottomMargin; - int indent; - int lineHeight; - int lineHeightType; - bool nonBreakableLines; - QTextTableFormat::PageBreakFlags pageBreakPolicy; - int textIndent; - Qt::LayoutDirection layoutDirection; - QList tabs; - QBrush background; - QBrush foreground; - QMap properties; - - //UNUSED - int id; - int type; - QString typeText; - - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("id", Qt::CaseInsensitive)) - id = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("type", Qt::CaseInsensitive)) - type = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("typeText", Qt::CaseInsensitive)) - typeText = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("alignment", Qt::CaseInsensitive)) - alignment = (Qt::AlignmentFlag)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("leftMargin", Qt::CaseInsensitive)) - leftMargin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("topMargin", Qt::CaseInsensitive)) - topMargin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("rightMargin", Qt::CaseInsensitive)) - rightMargin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("bottomMargin", Qt::CaseInsensitive)) - bottomMargin = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("indent", Qt::CaseInsensitive)) - indent = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("lineHeight", Qt::CaseInsensitive)) - lineHeight = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("lineHeightType", Qt::CaseInsensitive)) - lineHeightType = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("nonBreakableLines", Qt::CaseInsensitive)) - nonBreakableLines = node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false; - else if(!node.toAttr().name().compare("pageBreakPolicy", Qt::CaseInsensitive)) - pageBreakPolicy = (QTextTableFormat::PageBreakFlags)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("textIndent", Qt::CaseInsensitive)) - textIndent = node.toAttr().nodeValue().toDouble(); - else if(!node.toAttr().name().compare("layoutDirection", Qt::CaseInsensitive)) - layoutDirection = (Qt::LayoutDirection)node.toAttr().nodeValue().toInt(); - else - myDebug << " parseTextBlockFormat: unknown attribute: " << node.toAttr().name(); - } - - //UNUSED - id = id; - type = type; - typeText = typeText; - - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("background", Qt::CaseInsensitive)) - background = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("foreground", Qt::CaseInsensitive)) - foreground = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("properties", Qt::CaseInsensitive)) - { - int key; - QVariant::Type type; - QString value; - - QDomNode property = child.toElement().firstChild(); - - while(!property.isNull()) - { - if(!property.toElement().tagName().compare("key", Qt::CaseInsensitive)) - key = property.toElement().toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("type", Qt::CaseInsensitive)) - type = (QVariant::Type)property.toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("value", Qt::CaseInsensitive)) - value = property.toElement().nodeValue(); - - QVariant propertyValue(value); - propertyValue.convert(type); - properties.insert(key, propertyValue); - - property = property.nextSibling(); - } - } - else if(!child.toElement().tagName().compare("tabPositions", Qt::CaseInsensitive)) - tabs = parseTabPositions(child.toElement()); - else - myDebug << " parseTextBlockFormat: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - QTextBlockFormat format; - - format.setAlignment(alignment); - format.setLeftMargin(leftMargin); - format.setTopMargin(topMargin); - format.setRightMargin(rightMargin); - format.setBottomMargin(bottomMargin); - format.setIndent(indent); - format.setLineHeight(lineHeight, lineHeightType); - format.setNonBreakableLines(nonBreakableLines); - format.setPageBreakPolicy(pageBreakPolicy); - format.setTextIndent(textIndent); - format.setTabPositions(tabs); - format.setLayoutDirection(layoutDirection); - - background.setColor(QColor((int)(255*0.827451), (int)(255*0.827451), (int)(255*0.827451), (int)(255*1))); - format.setBackground(background); - format.setForeground(foreground); - - QMapIterator property(properties); - while(property.hasNext()) - { - property.next(); - format.setProperty(property.key(), property.value()); - } - - return(format); -} - -QTextCharFormat cDocumentReader::parseTextCharFormat(const QDomElement& element) -{ - QString anchorHref; - bool isAnchor; - QString toolTip; - QTextCharFormat::VerticalAlignment verticalAlignment; - QPen textOutline; - QStringList anchorNames; - QFont font; - QColor underlineColor; - QBrush background; - QBrush foreground; - QMap properties; - Qt::LayoutDirection layoutDirection; - - //UNUSED - int id; - int type; - QString typeText; - - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("id", Qt::CaseInsensitive)) - id = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("type", Qt::CaseInsensitive)) - type = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("typeText", Qt::CaseInsensitive)) - typeText = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("anchorHref", Qt::CaseInsensitive)) - anchorHref = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("type", Qt::CaseInsensitive)) - anchorHref = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("isAnchor", Qt::CaseInsensitive)) - isAnchor = node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false; - else if(!node.toAttr().name().compare("toolTip", Qt::CaseInsensitive)) - toolTip = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("verticalAlignment", Qt::CaseInsensitive)) - verticalAlignment = (QTextCharFormat::VerticalAlignment)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("layoutDirection", Qt::CaseInsensitive)) - layoutDirection = (Qt::LayoutDirection)node.toAttr().nodeValue().toInt(); - else - myDebug << " parseTextCharFormat: unknown attribute: " << node.toAttr().name(); - } - - //UNUSED - id = id; - type = type; - typeText = typeText; - - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("background", Qt::CaseInsensitive)) - background = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("foreground", Qt::CaseInsensitive)) - foreground = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("properties", Qt::CaseInsensitive)) - { - int key; - QVariant::Type type; - QString value; - - QDomNode property = child.toElement().firstChild(); - - while(!property.isNull()) - { - if(!property.toElement().tagName().compare("key", Qt::CaseInsensitive)) - key = property.toElement().toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("type", Qt::CaseInsensitive)) - type = (QVariant::Type)property.toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("value", Qt::CaseInsensitive)) - value = property.toElement().nodeValue(); - - QVariant propertyValue(value); - propertyValue.convert(type); - properties.insert(key, propertyValue); - - property = property.nextSibling(); - } - } - else if(!child.toElement().tagName().compare("textOutline", Qt::CaseInsensitive)) - textOutline = parsePen(child.toElement()); - else if(!child.toElement().tagName().compare("anchorNames", Qt::CaseInsensitive)) - { - - QDomNode anchors = child.toElement().firstChild(); - - while(!anchors.isNull()) - { - if(!child.toElement().tagName().compare("anchor", Qt::CaseInsensitive)) - anchorNames.append(child.toElement().nodeValue()); - - anchors = anchors.nextSibling(); - } - } - else if(!child.toElement().tagName().compare("font", Qt::CaseInsensitive)) - font = parseFont(child.toElement()); - else if(!child.toElement().tagName().compare("underlineColor", Qt::CaseInsensitive)) - underlineColor = parseColor(child.toElement()); - else - myDebug << " parseTextCharFormat: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - QTextCharFormat format; - - format.setAnchorHref(anchorHref); - format.setFont(font); - format.setAnchor(isAnchor); - format.setToolTip(toolTip); - format.setVerticalAlignment(verticalAlignment); - format.setBackground(background); - format.setForeground(foreground); - format.setTextOutline(textOutline); - format.setAnchorNames(anchorNames); - format.setLayoutDirection(layoutDirection); - - QMapIterator property(properties); - while(property.hasNext()) - { - property.next(); - format.setProperty(property.key(), property.value()); - } - - format.setUnderlineColor(underlineColor); - - return(format); -} - -void cDocumentReader::parseTextBlock(const QDomElement& element, QTextCursor* lpCursor, const QVector &allFormats) -{ - int blockFormatIndex; - int charFormatIndex; - int listFormatIndex; - int tableFormatIndex; - QVector textFormats; - QString text; - - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("blockFormatIndex", Qt::CaseInsensitive)) - blockFormatIndex = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("charFormatIndex", Qt::CaseInsensitive)) - charFormatIndex = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("listFormatIndex", Qt::CaseInsensitive)) - listFormatIndex = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("tableFormatIndex", Qt::CaseInsensitive)) - tableFormatIndex = node.toAttr().nodeValue().toInt(); - else - myDebug << " parseTextBlock: unknown attribute: " << node.toAttr().name(); - } - - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("textFormats", Qt::CaseInsensitive)) - textFormats = parseTextFormats(child.toElement()); - else if(!child.toElement().tagName().compare("text", Qt::CaseInsensitive)) - text = child.toElement().text(); - else - myDebug << " parseTextBlock: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - if(m_bFirstBlock) - { - m_bFirstBlock = false; - lpCursor->setBlockFormat(allFormats[blockFormatIndex].blockFormat); - lpCursor->setCharFormat(allFormats[charFormatIndex].charFormat); - lpCursor->setBlockCharFormat(allFormats[charFormatIndex].charFormat); - } - else - { - if(listFormatIndex != -1) - { - int indent = allFormats[listFormatIndex].listFormat.indent(); - indent = allFormats[listFormatIndex].listFormat.indent(); - - if(!m_textLists.contains(indent)) - { - QTextListFormat format = allFormats[listFormatIndex].listFormat; - QTextList* lpList = lpCursor->insertList(format); - m_textLists.insert(indent, lpList); - - lpCursor->mergeBlockFormat(allFormats[blockFormatIndex].blockFormat); - lpCursor->mergeCharFormat(allFormats[charFormatIndex].charFormat); - lpCursor->mergeBlockCharFormat(allFormats[charFormatIndex].charFormat); - } - else - { - lpCursor->insertBlock(); - - lpCursor->mergeBlockFormat(allFormats[blockFormatIndex].blockFormat); - lpCursor->mergeCharFormat(allFormats[charFormatIndex].charFormat); - lpCursor->mergeBlockCharFormat(allFormats[charFormatIndex].charFormat); - - QTextList* list = m_textLists.value(indent); - list->add(lpCursor->block()); - } - } -// else if(tableFormatIndex != -1) -// lpCursor->insertTable(allFormats[tableFormatIndex].tableFormat); - else - { - m_textLists.clear(); - lpCursor->insertBlock(); - lpCursor->setBlockFormat(allFormats[blockFormatIndex].blockFormat); - lpCursor->setCharFormat(allFormats[charFormatIndex].charFormat); - lpCursor->setBlockCharFormat(allFormats[charFormatIndex].charFormat); - } - } - - for(int x = 0;x < textFormats.count();x++) - { - QTextLayout::FormatRange textFormat = textFormats[x]; - int start = textFormat.start; - int length = textFormat.length; - QTextCharFormat format = textFormat.format; - QString textPart = text.mid(start, length); - lpCursor->insertText(textPart, format); - } -} - -QVector cDocumentReader::parseTextFormats(const QDomElement& element) -{ - QDomNode child = element.firstChild(); - QVector formats; - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("range", Qt::CaseInsensitive)) - { - QTextLayout::FormatRange range = parseRange(child.toElement()); - formats.append(range); - } - else - myDebug << " parseTextFormats: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - return(formats); -} - -QTextLayout::FormatRange cDocumentReader::parseRange(const QDomElement& element) -{ - int start; - int length; - QString anchorHref; - bool isAnchor; - QString toolTip; - QTextCharFormat::VerticalAlignment verticalAlignment; - Qt::LayoutDirection layoutDirection; - - QBrush background; - QBrush foreground; - QPen textOutline; - QStringList anchorNames; - QMap properties; - QFont font; - QColor underlineColor; - - QDomNamedNodeMap attributes = element.attributes(); - for(int x = 0;x < attributes.count();x++) - { - QDomNode node = attributes.item(x); - - if(!node.toAttr().name().compare("start", Qt::CaseInsensitive)) - start = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("length", Qt::CaseInsensitive)) - length = node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("anchorHref", Qt::CaseInsensitive)) - anchorHref = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("isAnchor", Qt::CaseInsensitive)) - isAnchor = node.toAttr().nodeValue().compare("true", Qt::CaseInsensitive) == 0 ? true : false; - else if(!node.toAttr().name().compare("toolTip", Qt::CaseInsensitive)) - toolTip = node.toAttr().nodeValue(); - else if(!node.toAttr().name().compare("verticalAlignment", Qt::CaseInsensitive)) - verticalAlignment = (QTextCharFormat::VerticalAlignment)node.toAttr().nodeValue().toInt(); - else if(!node.toAttr().name().compare("layoutDirection", Qt::CaseInsensitive)) - layoutDirection = (Qt::LayoutDirection)node.toAttr().nodeValue().toInt(); - else - myDebug << " parseRange: unknown attribute: " << node.toAttr().name(); - } - - QDomNode child = element.firstChild(); - - while(!child.isNull()) - { - if(!child.toElement().tagName().compare("background", Qt::CaseInsensitive)) - background = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("foreground", Qt::CaseInsensitive)) - foreground = parseBrush(child.toElement()); - else if(!child.toElement().tagName().compare("properties", Qt::CaseInsensitive)) - { - int key; - QVariant::Type type; - QString value; - - QDomNode property = child.toElement().firstChild(); - - while(!property.isNull()) - { - if(!property.toElement().tagName().compare("key", Qt::CaseInsensitive)) - key = property.toElement().toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("type", Qt::CaseInsensitive)) - type = (QVariant::Type)property.toElement().nodeValue().toInt(); - else if(!property.toElement().tagName().compare("value", Qt::CaseInsensitive)) - value = property.toElement().nodeValue(); - - QVariant propertyValue(value); - propertyValue.convert(type); - properties.insert(key, propertyValue); - - property = property.nextSibling(); - } - } - else if(!child.toElement().tagName().compare("textOutline", Qt::CaseInsensitive)) - textOutline = parsePen(child.toElement()); - else if(!child.toElement().tagName().compare("anchorNames", Qt::CaseInsensitive)) - { - - QDomNode anchors = child.toElement().firstChild(); - - while(!anchors.isNull()) - { - if(!child.toElement().tagName().compare("anchor", Qt::CaseInsensitive)) - anchorNames.append(child.toElement().nodeValue()); - - anchors = anchors.nextSibling(); - } - } - else if(!child.toElement().tagName().compare("font", Qt::CaseInsensitive)) - font = parseFont(child.toElement()); - else if(!child.toElement().tagName().compare("underlineColor", Qt::CaseInsensitive)) - underlineColor = parseColor(child.toElement()); - else - myDebug << " parseTextCharFormat: unknown element: " << child.toElement().tagName(); - - child = child.nextSibling(); - } - - QTextCharFormat format; - - format.setAnchorHref(anchorHref); - format.setFont(font); - format.setAnchor(isAnchor); - format.setToolTip(toolTip); - format.setVerticalAlignment(verticalAlignment); - format.setBackground(background); - format.setForeground(foreground); - format.setTextOutline(textOutline); - format.setAnchorNames(anchorNames); - format.setLayoutDirection(layoutDirection); - - QMapIterator property(properties); - while(property.hasNext()) - { - property.next(); - format.setProperty(property.key(), property.value()); - } - - format.setUnderlineColor(underlineColor); - - QTextLayout::FormatRange range; - - range.start = start; - range.length = length; - range.format = format; - - return(range); -} diff --git a/cdocumentreader.h b/cdocumentreader.h deleted file mode 100644 index 7d9f80d..0000000 --- a/cdocumentreader.h +++ /dev/null @@ -1,212 +0,0 @@ -#ifndef CDOCUMENTREADER_H -#define CDOCUMENTREADER_H - - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - - -class cTextDocument; - -class cTextFormat -{ -public: - enum TextFormatType - { - TextFormatTypeUnknown = 0, - TextFormatTypeTableCell = 1, - TextFormatTypeTable = 2, - TextFormatTypeImage = 3, - TextFormatTypeFrame = 4, - TextFormatTypeList = 5, - TextFormatTypeBlock = 6, - TextFormatTypeChar = 7, - }; - - cTextFormat(TextFormatType type = TextFormatTypeUnknown) : m_type(type) {} - cTextFormat(const QString& szType) : m_type(TextFormatTypeUnknown) - { - if(szType.compare("tableCellFormat", Qt::CaseInsensitive)) - m_type = TextFormatTypeTableCell; - else if(szType.compare("tableFormat", Qt::CaseInsensitive)) - m_type = TextFormatTypeTable; - else if(szType.compare("imageFormat", Qt::CaseInsensitive)) - m_type = TextFormatTypeImage; - else if(szType.compare("frameFormat", Qt::CaseInsensitive)) - m_type = TextFormatTypeFrame; - else if(szType.compare("listFormat", Qt::CaseInsensitive)) - m_type = TextFormatTypeList; - else if(szType.compare("blockFormat", Qt::CaseInsensitive)) - m_type = TextFormatTypeBlock; - else if(szType.compare("charFormat", Qt::CaseInsensitive)) - m_type = TextFormatTypeChar; - } - - void setTableCellFormat(const QTextTableCellFormat& format) - { - tableCellFormat = format; - m_type = TextFormatTypeTableCell; - } - void setTableFormat(const QTextTableFormat& format) - { - tableFormat = format; - m_type = TextFormatTypeTable; - } - void setImageFormat(const QTextImageFormat& format) - { - imageFormat = format; - m_type = TextFormatTypeImage; - } - void setFrameFormat(const QTextFrameFormat& format) - { - frameFormat = format; - m_type = TextFormatTypeFrame; - } - void setListFormat(const QTextListFormat& format) - { - listFormat = format; - m_type = TextFormatTypeList; - } - void setBlockFormat(const QTextBlockFormat& format) - { - blockFormat = format; - m_type = TextFormatTypeBlock; - } - void setCharFormat(const QTextCharFormat& format) - { - charFormat = format; - m_type = TextFormatTypeChar; - } - - bool isValid() - { - switch(m_type) - { - case TextFormatTypeTableCell: - return(tableCellFormat.isValid()); - case TextFormatTypeTable: - return(tableFormat.isValid()); - case TextFormatTypeImage: - return(imageFormat.isValid()); - case TextFormatTypeFrame: - return(frameFormat.isValid()); - case TextFormatTypeList: - return(listFormat.isValid()); - case TextFormatTypeBlock: - return(blockFormat.isValid()); - case TextFormatTypeChar: - return(charFormat.isValid()); - case TextFormatTypeUnknown: - return(false); - } - return(false); - } - - void setLayoutDirection(Qt::LayoutDirection layoutDirection) - { - switch(m_type) - { - case TextFormatTypeTableCell: - tableCellFormat.setLayoutDirection(layoutDirection); - break; - case TextFormatTypeTable: - tableFormat.setLayoutDirection(layoutDirection); - break; - case TextFormatTypeImage: - imageFormat.setLayoutDirection(layoutDirection); - break; - case TextFormatTypeFrame: - frameFormat.setLayoutDirection(layoutDirection); - break; - case TextFormatTypeList: - listFormat.setLayoutDirection(layoutDirection); - break; - case TextFormatTypeBlock: - blockFormat.setLayoutDirection(layoutDirection); - break; - case TextFormatTypeChar: - charFormat.setLayoutDirection(layoutDirection); - break; - case TextFormatTypeUnknown: - break; - } - } - - QTextTableCellFormat tableCellFormat; - QTextTableFormat tableFormat; - QTextImageFormat imageFormat; - QTextFrameFormat frameFormat; - QTextListFormat listFormat; - QTextBlockFormat blockFormat; - QTextCharFormat charFormat; - TextFormatType m_type; -}; - -class cDocumentReader : public QXmlStreamReader -{ -public: - cDocumentReader(const QString& szFileName, bool bZip = true); - ~cDocumentReader(); - - bool open(); - bool close(); - - cTextDocument* readDocument(); -private: - bool m_bFirstBlock; - bool m_bZip; - QString m_szFileName; - QFile m_file; - QuaZip m_zip; - QuaZipFile m_zipFile; - - QMap m_textLists; - - void parseSettings(const QDomElement& element, cTextDocument* lpDocument); - void parseDefaults(const QDomElement& element, cTextDocument* lpDocument); - void parseTextBlock(const QDomElement& element, QTextCursor *lpCursor, const QVector& allFormats); - - QVector parseTextFormats(const QDomElement& element); - QTextLayout::FormatRange parseRange(const QDomElement& element); - QFont parseFont(const QDomElement& element); - QTextOption parseDefaultTextOption(const QDomElement& element); - QList parseTabPositions(const QDomElement& element); - QVector parseAllFormats(const QDomElement& element); - cTextFormat parseFormat(const QDomElement& element); - QPen parsePen(const QDomElement& element); - QBrush parseBrush(const QDomElement& element); - QColor parseColor(const QDomElement& element); - - QTextTableCellFormat parseTextTableCellFormat(const QDomElement& element); - QTextTableFormat parseTextTableFormat(const QDomElement& element); - QTextImageFormat parseTextImageFormat(const QDomElement& element); - QTextFrameFormat parseTextFrameFormat(const QDomElement& element); - QTextListFormat parseTextListFormat(const QDomElement& element); - QTextBlockFormat parseTextBlockFormat(const QDomElement& element); - QTextCharFormat parseTextCharFormat(const QDomElement& element); -}; - -#endif // CDOCUMENTREADER_H diff --git a/cdocumentwriter.cpp b/cdocumentwriter.cpp deleted file mode 100644 index 685c97e..0000000 --- a/cdocumentwriter.cpp +++ /dev/null @@ -1,688 +0,0 @@ -#include "cdocumentwriter.h" -#include "ctextdocument.h" - -#include - -#include - - -cDocumentWriter::cDocumentWriter(const QString &szFileName, bool bZip) : - m_bZip(bZip), - m_szFileName(szFileName), - m_lpDocument(0) -{ - QFileInfo fileInfo(szFileName); - m_szPath = fileInfo.absolutePath(); -} - -cDocumentWriter::~cDocumentWriter() -{ - close(); -} - -bool cDocumentWriter::open() -{ - if(m_szFileName.isEmpty()) - return(false); - - if(m_bZip) - { - m_zip.setZipName(m_szFileName); - m_zip.open(QuaZip::mdCreate); - - QuaZipNewInfo info("document.xml"); - m_zipFile.setZip(&m_zip); - - if(!m_zipFile.open(QIODevice::WriteOnly, info)) - { - m_zip.close(); - return(false); - } - - setDevice(&m_zipFile); - } - else - { - m_file.setFileName(m_szFileName); - if(!m_file.open(QIODevice::WriteOnly | QFile::Text)) - return(false); - - setDevice(&m_file); - } - - setAutoFormatting(true); - setAutoFormattingIndent(-1); - writeStartDocument(); - writeStartElement("document"); - - return(true); -} - -bool cDocumentWriter::close() -{ - if(m_bZip) - { - if(m_zipFile.isOpen()) - { - writeEndElement(); - writeEndDocument(); - m_zipFile.close(); - } - } - else - { - if(m_file.isOpen()) - { - writeEndElement(); - writeEndDocument(); - m_file.close(); - } - } - - return(true); -} - -bool cDocumentWriter::writeDocument(cTextDocument *lpDocument) -{ - m_lpDocument = lpDocument; - - QList> textBlockFormats; - QTextBlock textBlock = lpDocument->firstBlock(); - - while(textBlock.isValid()) - { - int x; - for(x = 0;x < textBlockFormats.count();x++) - { - if(textBlockFormats[x].first == textBlock.blockFormatIndex()) - break; - } - if(x >= textBlockFormats.count()) - textBlockFormats.append(QPair(textBlock.blockFormatIndex(), textBlock.blockFormat())); - - textBlock = textBlock.next(); - } - - writeStartElement("documentSettings"); - writeAttribute("documentMargin", QString::number(lpDocument->documentMargin())); - writeAttribute("indentWidth", QString::number(lpDocument->indentWidth())); - writeAttribute("textWidth", QString::number(lpDocument->textWidth())); - writeAttribute("useDesignMetrics", lpDocument->useDesignMetrics() == true ? "true" : "false"); - - writeStartElement("metaInformation"); - writeAttribute("documentTitle", lpDocument->metaInformation(QTextDocument::DocumentTitle)); - writeAttribute("documentUrl", lpDocument->metaInformation(QTextDocument::DocumentUrl)); - writeEndElement(); - - writeStartElement("baseUrl"); - writeAttribute("authority", lpDocument->baseUrl().authority()); - writeAttribute("fragment", lpDocument->baseUrl().fragment()); - writeAttribute("host", lpDocument->baseUrl().host()); - writeAttribute("password", lpDocument->baseUrl().password()); - writeAttribute("path", lpDocument->baseUrl().path()); - writeAttribute("port", QString::number(lpDocument->baseUrl().port())); - writeAttribute("query", lpDocument->baseUrl().query()); - writeAttribute("scheme", lpDocument->baseUrl().scheme()); - writeAttribute("url", lpDocument->baseUrl().url()); - writeAttribute("userInfo", lpDocument->baseUrl().userInfo()); - writeAttribute("userName", lpDocument->baseUrl().userName()); - writeEndElement(); - - writeStartElement("pageSize"); - writeAttribute("width", QString::number(lpDocument->pageSize().width())); - writeAttribute("height", QString::number(lpDocument->pageSize().height())); - writeEndElement(); - writeEndElement(); - - writeStartElement("defaults"); - writeAttribute("defaultCursorMoveStyle", QString::number(lpDocument->defaultCursorMoveStyle())); - writeAttribute("defaultStyleSheet", lpDocument->defaultStyleSheet()); - - writeStartElement("defaultFont"); - writeFont(lpDocument->defaultFont()); - writeEndElement(); - - writeStartElement("defaultTextOption"); - writeTextOption(lpDocument->defaultTextOption()); - writeEndElement(); - writeEndElement(); - - writeFormats(lpDocument->allFormats()); - writeTextBlockFormats(textBlockFormats); - - textBlock = lpDocument->firstBlock(); - writeTextBlocks(textBlock); - - return(true); -} - -void cDocumentWriter::writeTextBlockFormats(const QList> textBlockFormats) -{ - writeStartElement("textBlockFormats"); - for(int x = 0;x < textBlockFormats.count();x++) - { - writeStartElement("format"); - writeFormat(textBlockFormats[x].second, textBlockFormats[x].first); - writeEndElement(); - } - writeEndElement(); -} - -void cDocumentWriter::writeTextBlocks(QTextBlock& textBlock) -{ - writeStartElement("textBlocks"); - while(textBlock.isValid()) - { - writeStartElement("textBlock"); - writeTextBlock(textBlock); - writeEndElement(); - textBlock = textBlock.next(); - } - writeEndElement(); -} - -#include -#include - -void cDocumentWriter::writeTextBlock(const QTextBlock& textBlock) -{ - QTextCursor cursor(textBlock); - QTextList* lpTextList = cursor.currentList(); - QTextTable* lpTextTable = cursor.currentTable(); - - writeAttribute("blockFormatIndex", QString::number(textBlock.blockFormatIndex())); - writeAttribute("charFormatIndex", QString::number(textBlock.charFormatIndex())); - writeAttribute("listFormatIndex", QString::number(lpTextList == 0 ? -1 : lpTextList->formatIndex())); - writeAttribute("tableFormatIndex", QString::number(lpTextTable == 0 ? -1 : lpTextTable->formatIndex())); - - QVector textFormats = textBlock.textFormats(); - writeStartElement("textFormats"); - for(int x = 0;x < textFormats.count();x++) - { - QTextLayout::FormatRange range = textFormats[x]; - QTextCharFormat format = range.format; - writeStartElement("range"); - writeAttribute("start", QString::number(range.start)); - writeAttribute("length", QString::number(range.length)); - writeTextCharFormat((QTextCharFormat*)&format, -1, WriteAttribute); - writeTextFormat((QTextFormat*)&format, -1, WriteAll); - writeTextCharFormat((QTextCharFormat*)&format, -1, WriteElements); - writeEndElement(); - } - writeEndElement(); - - writeTextElement("text", textBlock.text()); -} - -void cDocumentWriter::writeColor(QColor color) -{ - writeAttribute("alpha", QString::number(color.alpha())); - writeAttribute("r", QString::number(color.red())); - writeAttribute("g", QString::number(color.green())); - writeAttribute("b", QString::number(color.blue())); -} - -void cDocumentWriter::writeGradient(const QGradient* lpGradient) -{ - writeAttribute("type", QString::number(lpGradient->type())); - writeTextElement("spread", QString::number(lpGradient->spread())); - - for(int x = 0;x < lpGradient->stops().count();x++) - { - writeStartElement("stop"); - writeAttribute("pos", QString::number(lpGradient->stops()[x].first)); - - writeStartElement("color"); - writeColor(lpGradient->stops()[x].second); - writeEndElement(); - - writeEndElement(); - } -} - -void cDocumentWriter::writePen(const QPen& pen) -{ - writeAttribute("capStyle", QString::number(pen.capStyle())); - writeAttribute("dashOffset", QString::number(pen.dashOffset())); - writeAttribute("isCosmetic", pen.isCosmetic() == true ? "true" : "false"); - writeAttribute("joinStyle", QString::number(pen.joinStyle())); - writeAttribute("miterLimit", QString::number(pen.miterLimit())); - writeAttribute("style", QString::number(pen.style())); - writeAttribute("width", QString::number(pen.width())); - writeAttribute("widthF", QString::number(pen.widthF())); - - writeStartElement("brush"); - writeBrush(pen.brush()); - writeEndElement(); - - writeStartElement("color"); - writeColor(pen.color()); - writeEndElement(); - - if(pen.dashPattern().count()) - { - writeStartElement("dashPattern"); - for(int x = 0;x < pen.dashPattern().count();x++) - writeTextElement("pattern", QString::number(pen.dashPattern()[x])); - writeEndElement(); - } -} - -void cDocumentWriter::writeBrush(const QBrush& brush) -{ - writeAttribute("style", QString::number(brush.style())); - - writeStartElement("color"); - writeColor(brush.color()); - writeEndElement(); - - if(brush.gradient()) - { - writeStartElement("gradient"); - writeGradient(brush.gradient()); - writeEndElement(); - } - - //matrix - //texture oder textureImage -} - -void cDocumentWriter::writeFont(const QFont& font) -{ - writeAttribute("bold", font.bold() == true ? "true" : "false"); - writeAttribute("capitalization", QString::number(font.capitalization())); -// writeAttribute("defaultFamily", font.defaultFamily()); -// writeAttribute("exactMatch", font.exactMatch() == true ? "true" : "false"); - writeAttribute("family", font.family()); - writeAttribute("fixedPitch", font.fixedPitch() == true ? "true" : "false"); - writeAttribute("hintingPreference", QString::number(font.hintingPreference())); - writeAttribute("italic", font.italic() == true ? "true" : "false"); - writeAttribute("kerning", font.kerning() == true ? "true" : "false"); - writeAttribute("letterSpacing", QString::number(font.letterSpacing())); - writeAttribute("letterSpacingType", QString::number(font.letterSpacingType())); - writeAttribute("overline", QString::number(font.overline())); - writeAttribute("pixelSize", QString::number(font.pixelSize())); - writeAttribute("pointSize", QString::number(font.pointSize())); - writeAttribute("pointSizeF", QString::number(font.pointSizeF())); - writeAttribute("stretch", QString::number(font.stretch())); - writeAttribute("strikeOut", font.strikeOut() == true ? "true" : "false"); - writeAttribute("style", QString::number(font.style())); - writeAttribute("styleHint", QString::number(font.styleHint())); - writeAttribute("styleName", font.styleName()); - writeAttribute("styleStrategy", QString::number(font.styleStrategy())); - writeAttribute("underline", font.underline() == true ? "true" : "false"); - writeAttribute("weight", QString::number(font.weight())); - writeAttribute("wordSpacing", QString::number(font.wordSpacing())); -} - -void cDocumentWriter::writeFormat(const QTextFormat& textFormat, int id) -{ - writeAttribute("type", QString::number(textFormat.type())); - - if(textFormat.isTableCellFormat()) - { - writeAttribute("typeText", "tableCellFormat"); - writeTextTableCellFormat((QTextTableCellFormat*)&textFormat, id, WriteAttribute); - writeTextCharFormat((QTextCharFormat*)&textFormat, id, WriteAttribute); - writeTextFormat((QTextFormat*)&textFormat, id, WriteAll); - writeTextTableCellFormat((QTextTableCellFormat*)&textFormat, id, WriteElements); - writeTextCharFormat((QTextCharFormat*)&textFormat, id, WriteElements); - } - else if(textFormat.isTableFormat()) - { - writeAttribute("typeText", "tableFormat"); - writeTextTableFormat((QTextTableFormat*)&textFormat, id, WriteAttribute); - writeTextFrameFormat((QTextFrameFormat*)&textFormat, id, WriteAttribute); - writeTextFormat((QTextFormat*)&textFormat, id, WriteAll); - writeTextTableFormat((QTextTableFormat*)&textFormat, id, WriteElements); - writeTextFrameFormat((QTextFrameFormat*)&textFormat, id, WriteElements); - } - else if(textFormat.isImageFormat()) - { - writeAttribute("typeText", "imageFormat"); - writeTextImageFormat((QTextImageFormat*)&textFormat, id, WriteAttribute); - writeTextCharFormat((QTextCharFormat*)&textFormat, id, WriteAttribute); - writeTextFormat((QTextFormat*)&textFormat, id, WriteAll); - writeTextImageFormat((QTextImageFormat*)&textFormat, id, WriteElements); - writeTextCharFormat((QTextCharFormat*)&textFormat, id, WriteElements); - } - else if(textFormat.isFrameFormat()) - { - writeAttribute("typeText", "frameFormat"); - writeTextFrameFormat((QTextFrameFormat*)&textFormat, id, WriteAttribute); - writeTextFormat((QTextFormat*)&textFormat, id, WriteAll); - writeTextFrameFormat((QTextFrameFormat*)&textFormat, id, WriteElements); - } - else if(textFormat.isListFormat()) - { - writeAttribute("typeText", "listFormat"); - writeTextListFormat((QTextListFormat*)&textFormat, id, WriteAttribute); - writeTextFormat((QTextFormat*)&textFormat, id, WriteAll); - writeTextListFormat((QTextListFormat*)&textFormat, id, WriteElements); - } - else if(textFormat.isBlockFormat()) - { - writeAttribute("typeText", "blockFormat"); - writeTextBlockFormat((QTextBlockFormat*)&textFormat, id, WriteAttribute); - writeTextFormat((QTextFormat*)&textFormat, id, WriteAll); - writeTextBlockFormat((QTextBlockFormat*)&textFormat, id, WriteElements); - } - else if(textFormat.isCharFormat()) - { - writeAttribute("typeText", "charFormat"); - writeTextCharFormat((QTextCharFormat*)&textFormat, id, WriteAttribute); - writeTextFormat((QTextFormat*)&textFormat, id, WriteAll); - writeTextCharFormat((QTextCharFormat*)&textFormat, id, WriteElements); - } -} - -void cDocumentWriter::writeTextFormat(QTextFormat* lpTextFormat, int /*id*/, WritePart part) -{ - if(lpTextFormat->isValid()) - { - if(part & WriteAttribute) - { - writeAttribute("layoutDirection", QString::number(lpTextFormat->layoutDirection())); - } - - if(part & WriteElements) - { - writeStartElement("background"); - writeBrush(lpTextFormat->background()); - writeEndElement(); - - writeStartElement("foreground"); - writeBrush(lpTextFormat->foreground()); - writeEndElement(); - - writeStartElement("properties"); - QMap properties = lpTextFormat->properties(); - QMapIterator property(properties); - - while(property.hasNext()) - { - property.next(); - - writeStartElement("property"); - writeAttribute("key", QString::number(property.key())); - writeAttribute("type", QString::number(property.value().type())); - writeTextElement("value", property.value().toString()); - writeEndElement(); - } - writeEndElement(); - } - } -} - -void cDocumentWriter::writeFormats(const QVector formats) -{ - writeStartElement("allFormats"); - for(int x = 0;x < formats.count();x++) - { - writeStartElement("format"); - writeAttribute("id", QString::number(x)); - writeFormat(formats[x]); - writeEndElement(); - } - writeEndElement(); -} - -void cDocumentWriter::writeTabPositions(const QList tabs) -{ - for(int x = 0;x < tabs.count();x++) - { - QTextOption::Tab tab = tabs[x]; - writeStartElement("tabPosition"); - writeAttribute("delimiter", tab.delimiter); - writeAttribute("position", QString::number(tab.position)); - writeAttribute("type", QString::number(tab.type)); - writeEndElement(); - } -} - -void cDocumentWriter::writeTextBlockFormat(QTextBlockFormat* lpTextBlockFormat, int id, WritePart part) -{ - if(part & WriteAttribute && id != -1) - writeAttribute("id", QString::number(id)); - - if(lpTextBlockFormat->isValid()) - { - if(part & WriteAttribute) - { - writeAttribute("alignment", QString::number(lpTextBlockFormat->alignment())); - writeAttribute("topMargin", QString::number(lpTextBlockFormat->topMargin())); - writeAttribute("leftMargin", QString::number(lpTextBlockFormat->leftMargin())); - writeAttribute("bottomMargin", QString::number(lpTextBlockFormat->bottomMargin())); - writeAttribute("rightMargin", QString::number(lpTextBlockFormat->rightMargin())); - writeAttribute("indent", QString::number(lpTextBlockFormat->indent())); - writeAttribute("lineHeight", QString::number(lpTextBlockFormat->lineHeight())); - writeAttribute("lineHeightType", QString::number(lpTextBlockFormat->lineHeightType())); - writeAttribute("nonBreakableLines", lpTextBlockFormat->nonBreakableLines() == true ? "true" : "false"); - writeAttribute("pageBreakPolicy", QString::number(lpTextBlockFormat->pageBreakPolicy())); - writeAttribute("textIndent", QString::number(lpTextBlockFormat->textIndent())); - } - - if(part & WriteElements) - { - writeStartElement("tabPositions"); - writeTabPositions(lpTextBlockFormat->tabPositions()); - writeEndElement(); - } - } -} - -void cDocumentWriter::writeTextCharFormat(QTextCharFormat* lpTextCharFormat, int id, WritePart part) -{ - if(part & WriteAttribute && id != -1) - writeAttribute("id", QString::number(id)); - - if(lpTextCharFormat->isValid()) - { - if(part & WriteAttribute) - { - writeAttribute("anchorHref", lpTextCharFormat->anchorHref()); -// writeAttribute("fontCapitalization", QString::number(lpTextCharFormat->fontCapitalization())); -// writeAttribute("fontFamily", lpTextCharFormat->fontFamily()); -// writeAttribute("fontFixedPitch", lpTextCharFormat->fontFixedPitch() == true ? "true" : "false"); -// writeAttribute("fontHintingPreference", QString::number(lpTextCharFormat->fontHintingPreference())); -// writeAttribute("fontItalic", lpTextCharFormat->fontItalic() == true ? "true" : "false"); -// writeAttribute("fontKerning", lpTextCharFormat->fontKerning() == true ? "true" : "false"); -// writeAttribute("fontLetterSpacing", QString::number(lpTextCharFormat->fontLetterSpacing())); -// writeAttribute("fontLetterSpacingType", QString::number(lpTextCharFormat->fontLetterSpacingType())); -// writeAttribute("fontOverline", QString::number(lpTextCharFormat->fontOverline())); -// writeAttribute("fontPointSize", QString::number(lpTextCharFormat->fontPointSize())); -// writeAttribute("fontStretch", QString::number(lpTextCharFormat->fontStretch())); -// writeAttribute("fontStrikeOut", lpTextCharFormat->fontStrikeOut() == true ? "true" : "false"); -// writeAttribute("fontStyleHint", QString::number(lpTextCharFormat->fontStyleHint())); -// writeAttribute("fontStyleStrategy", QString::number(lpTextCharFormat->fontStyleStrategy())); -// writeAttribute("fontUnderline", lpTextCharFormat->fontUnderline() == true ? "true" : "false"); -// writeAttribute("fontWeight", QString::number(lpTextCharFormat->fontWeight())); -// writeAttribute("fontWordSpacing", QString::number(lpTextCharFormat->fontWordSpacing())); - writeAttribute("isAnchor", lpTextCharFormat->isAnchor() == true ? "true" : "false"); - writeAttribute("toolTip", lpTextCharFormat->toolTip()); - writeAttribute("verticalAlignment", QString::number(lpTextCharFormat->verticalAlignment())); - } - - if(part & WriteElements) - { - writeStartElement("textOutline"); - writePen(lpTextCharFormat->textOutline()); - writeEndElement(); - - writeStartElement("anchorNames"); - for(int x = 0;x < lpTextCharFormat->anchorNames().count();x++) - writeTextElement("anchor", lpTextCharFormat->anchorNames()[x]); - writeEndElement(); - - writeStartElement("font"); - writeFont(lpTextCharFormat->font()); - writeEndElement(); - - writeStartElement("underlineColor"); - writeColor(lpTextCharFormat->underlineColor()); - writeEndElement(); - } - } -} - -void cDocumentWriter::writeTextFrameFormat(QTextFrameFormat* lpTextFrameFormat, int id, WritePart part) -{ - if(part & WriteAttribute && id != -1) - writeAttribute("id", QString::number(id)); - - if(lpTextFrameFormat->isValid()) - { - if(part & WriteAttribute) - { - writeAttribute("border", QString::number(lpTextFrameFormat->border())); - writeAttribute("borderStyle", QString::number(lpTextFrameFormat->borderStyle())); - writeAttribute("margin", QString::number(lpTextFrameFormat->margin())); - writeAttribute("leftMargin", QString::number(lpTextFrameFormat->leftMargin())); - writeAttribute("topMargin", QString::number(lpTextFrameFormat->topMargin())); - writeAttribute("rightMargin", QString::number(lpTextFrameFormat->rightMargin())); - writeAttribute("bottomMargin", QString::number(lpTextFrameFormat->bottomMargin())); - writeAttribute("width", QString::number(lpTextFrameFormat->width().rawValue())); - writeAttribute("height", QString::number(lpTextFrameFormat->height().rawValue())); - writeAttribute("padding", QString::number(lpTextFrameFormat->padding())); - writeAttribute("pageBreakPolicy", QString::number(lpTextFrameFormat->pageBreakPolicy())); - writeAttribute("position", QString::number(lpTextFrameFormat->position())); - } - - if(part & WriteElements) - { - writeStartElement("borderBrush"); - writeBrush(lpTextFrameFormat->borderBrush()); - writeEndElement(); - } - } -} - -void cDocumentWriter::writeTextImageFormat(QTextImageFormat* lpTextImageFormat, int id, WritePart part) -{ - if(part & WriteAttribute && id != -1) - writeAttribute("id", QString::number(id)); - - if(lpTextImageFormat->isValid()) - { - if(part & WriteAttribute) - { - writeAttribute("name", lpTextImageFormat->name()); - writeAttribute("height", QString::number(lpTextImageFormat->height())); - writeAttribute("width", QString::number(lpTextImageFormat->width())); - } - - if(m_lpDocument) - { - QPixmap pixmap = m_lpDocument->resource(2, lpTextImageFormat->name()).value(); - if(!pixmap.isNull()) - { - QString name = lpTextImageFormat->name(); - if(name.left(1) == ':') - name = name.mid(1); - if(name.left(1) == '/') - name = name.mid(1); - - name = m_szPath + "/" + name; - QString path = name.left(name.lastIndexOf("/")); - - QFileInfo fileInfo(name); - if(fileInfo.suffix().isEmpty()) - name.append(".png"); - - QDir dir; - dir.mkpath(path); - bool ret = pixmap.save(name); - if(!ret) - return; - } - - } - } -} - -void cDocumentWriter::writeTextListFormat(QTextListFormat* lpTextListFormat, int id, WritePart part) -{ - if(part & WriteAttribute && id != -1) - writeAttribute("id", QString::number(id)); - - if(lpTextListFormat->isValid()) - { - if(part & WriteAttribute) - { - writeAttribute("indent", QString::number(lpTextListFormat->indent())); - writeAttribute("numberPrefix", lpTextListFormat->numberPrefix()); - writeAttribute("numberSuffix", lpTextListFormat->numberSuffix()); - writeAttribute("style", QString::number(lpTextListFormat->style())); - } - } -} - -void cDocumentWriter::writeTextTableCellFormat(QTextTableCellFormat* lpTextTableCellFormat, int id, WritePart part) -{ - if(part & WriteAttribute && id != -1) - writeAttribute("id", QString::number(id)); - - if(lpTextTableCellFormat->isValid()) - { - if(part & WriteAttribute) - { - writeAttribute("leftPadding", QString::number(lpTextTableCellFormat->leftPadding())); - writeAttribute("topPadding", QString::number(lpTextTableCellFormat->topPadding())); - writeAttribute("rightPadding", QString::number(lpTextTableCellFormat->rightPadding())); - writeAttribute("bottomPadding", QString::number(lpTextTableCellFormat->bottomPadding())); - } - } -} - -void cDocumentWriter::writeTextTableFormat(QTextTableFormat* lpTextTableFormat, int id, WritePart part) -{ - if(part & WriteAttribute && id != -1) - writeAttribute("id", QString::number(id)); - - if(lpTextTableFormat->isValid()) - { - if(part & WriteAttribute) - { - writeAttribute("alignment", QString::number(lpTextTableFormat->alignment())); - writeAttribute("cellPadding", QString::number(lpTextTableFormat->cellPadding())); - writeAttribute("cellSpacing", QString::number(lpTextTableFormat->cellSpacing())); - writeAttribute("columns", QString::number(lpTextTableFormat->columns())); - writeAttribute("headerRowCount", QString::number(lpTextTableFormat->headerRowCount())); - } - - if(part & WriteElements) - { - if(lpTextTableFormat->columnWidthConstraints().count()) - { - writeStartElement("columnWidthConstraints"); - for(int x = 0;x < lpTextTableFormat->columnWidthConstraints().count();x++) - { - writeStartElement("columnWidthConstraint"); - writeAttribute("rawValue", QString::number(lpTextTableFormat->columnWidthConstraints()[x].rawValue())); - writeAttribute("type", QString::number(lpTextTableFormat->columnWidthConstraints()[x].type())); - writeEndElement(); - } - writeEndElement(); - } - } - } -} - -void cDocumentWriter::writeTextOption(const QTextOption& textOption) -{ - writeAttribute("alignment", QString::number(textOption.alignment())); - writeAttribute("flags", QString::number(textOption.flags())); - writeAttribute("tabStopDistance", QString::number(textOption.tabStopDistance())); - writeAttribute("textDirection", QString::number(textOption.textDirection())); - writeAttribute("useDesignMetrics", textOption.useDesignMetrics() == true ? "true" : "false"); - writeAttribute("wrapMode", QString::number(textOption.wrapMode())); - - writeStartElement("tabArray"); - for(int x = 0;x < textOption.tabArray().count();x++) - writeTextElement("tab", QString::number(textOption.tabArray()[x])); - writeEndElement(); - - writeStartElement("tabs"); - writeTabPositions(textOption.tabs()); - writeEndElement(); -} diff --git a/cdocumentwriter.h b/cdocumentwriter.h deleted file mode 100644 index 0b257ab..0000000 --- a/cdocumentwriter.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef CDOCUMENTWRITER_H -#define CDOCUMENTWRITER_H - - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - - -class cTextDocument; - - -class cDocumentWriter : public QXmlStreamWriter -{ -public: - enum WritePart - { - WriteAll = 3, - WriteAttribute = 1, - WriteElements = 2, - }; - - cDocumentWriter(const QString& szFileName, bool bZip = true); - ~cDocumentWriter(); - - bool open(); - bool close(); - - bool writeDocument(cTextDocument* lpDocument); - -private: - bool m_bZip; - QString m_szFileName; - QString m_szPath; - QFile m_file; - QuaZip m_zip; - QuaZipFile m_zipFile; - cTextDocument* m_lpDocument; - - void writeTextBlockFormats(const QList> textBlockFormats); - void writeTextBlocks(QTextBlock& textBlock); - void writeColor(QColor color); - void writeGradient(const QGradient* lpGradient); - void writePen(const QPen& pen); - void writeBrush(const QBrush& brush); - void writeFormat(const QTextFormat& textFormat, int id = -1); - void writeFont(const QFont& font); - - void writeTextBlock(const QTextBlock& textBlock); - - void writeFormats(const QVector formats); - - void writeTextFormat(QTextFormat* lpTextFormat, int id = -1, WritePart part = WriteAll); - void writeTextBlockFormat(QTextBlockFormat* lpTextBlockFormat, int id = -1, WritePart part = WriteAll); - void writeTextCharFormat(QTextCharFormat* lpTextCharFormat, int id = -1, WritePart part = WriteAll); - void writeTextFrameFormat(QTextFrameFormat* lpTextFrameFormat, int id = -1, WritePart part = WriteAll); - void writeTextImageFormat(QTextImageFormat* lpTextImageFormat, int id = -1, WritePart part = WriteAll); - void writeTextListFormat(QTextListFormat* lpTextListFormat, int id = -1, WritePart part = WriteAll); - void writeTextTableCellFormat(QTextTableCellFormat* lpTextTableCellFormat, int id = -1, WritePart part = WriteAll); - void writeTextTableFormat(QTextTableFormat* lpTextTableFormat, int id = -1, WritePart part = WriteAll); - - void writeTextOption(const QTextOption &textOption); - - void writeTabPositions(const QList tabs); -}; - -#endif // CDOCUMENTWRITER_H diff --git a/cmainwindow.cpp b/cmainwindow.cpp index f946b5b..bea28bd 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -2,7 +2,6 @@ #include "ui_cmainwindow.h" #include "ctextdocument.h" -#include "cdocumentreader.h" #include "cstructurewindow.h" #include "cwidget.h" @@ -16,6 +15,8 @@ #include +#include + cMainWindow::cMainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::cMainWindow), @@ -41,6 +42,7 @@ cMainWindow::cMainWindow(QWidget *parent) : QMainWindow* lpMainWindow = new QMainWindow(this); lpMainWindow->setWindowTitle("Bla"); + cWidget* lpWidget2 = new cWidget(lpMainWindow); lpWidget2->setWindow(ui->m_lpMdiArea->addSubWindow(lpMainWindow)); diff --git a/cmainwindow.ui b/cmainwindow.ui index d16e368..68905b3 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -35,7 +35,7 @@ 0 0 - 147 + 194 477 @@ -45,6 +45,15 @@ + + QAbstractItemView::NoEditTriggers + + + false + + + true + false @@ -57,7 +66,7 @@ 0 0 - 147 + 194 477 @@ -70,7 +79,7 @@ 0 0 - 147 + 194 477 @@ -83,7 +92,7 @@ 0 0 - 147 + 194 477 diff --git a/cpart.cpp b/cpart.cpp index 631d33a..488a36d 100644 --- a/cpart.cpp +++ b/cpart.cpp @@ -6,7 +6,8 @@ #include -cPart::cPart(qint32 iID) : +cPart::cPart(qint32 iID, QObject *parent) : + QObject(parent), m_iID(iID), m_szName(""), m_iSortOrder(-1), diff --git a/cpart.h b/cpart.h index 618ed01..05b7805 100644 --- a/cpart.h +++ b/cpart.h @@ -12,7 +12,7 @@ class cPart : public QObject { Q_OBJECT public: - cPart(qint32 iID = -1); + explicit cPart(qint32 iID = -1, QObject *parent = nullptr); void setID(const qint32& iID); qint32 id(); diff --git a/cscene.cpp b/cscene.cpp index b045467..c1d309b 100644 --- a/cscene.cpp +++ b/cscene.cpp @@ -6,7 +6,8 @@ #include -cScene::cScene(qint32 iID) : +cScene::cScene(qint32 iID, QObject *parent) : + QObject(parent), m_iID(iID), m_lpChapter(0), m_szName(""), diff --git a/cscene.h b/cscene.h index 9d383d7..b47d096 100644 --- a/cscene.h +++ b/cscene.h @@ -26,7 +26,7 @@ public: STATE_finished = 4, }; - cScene(qint32 iID = -1); + explicit cScene(qint32 iID = -1, QObject *parent = nullptr); void setID(const qint32& iID); qint32 id(); diff --git a/cstorybook.cpp b/cstorybook.cpp index 36d0ee5..97e1aed 100644 --- a/cstorybook.cpp +++ b/cstorybook.cpp @@ -18,7 +18,8 @@ #include -cStoryBook::cStoryBook(const QString &szProjectPath) : +cStoryBook::cStoryBook(const QString &szProjectPath, QObject *parent) : + QObject(parent), m_szProjectPath(szProjectPath), m_bIsOpen(false) { @@ -149,13 +150,15 @@ bool cStoryBook::createDatabase() " id INTEGER PRIMARY KEY AUTOINCREMENT " " UNIQUE, " " mainCharacter BOOLEAN, " - " gender BOOLEAN, " + " gender INTEGER, " " title TEXT, " " firstName TEXT, " " middleName TEXT, " " lastName TEXT, " + " nickName TEXT, " " height DOUBLE, " " weight DOUBLE, " + " age DOUBLE, " " dateOfBirth DATE, " " placeOfBirth TEXT, " " dateOfDeath DATE, " diff --git a/cstorybook.h b/cstorybook.h index 2fa8228..636b681 100644 --- a/cstorybook.h +++ b/cstorybook.h @@ -20,7 +20,7 @@ class cStoryBook : public QObject { Q_OBJECT public: - cStoryBook(const QString& szProjectPath); + explicit cStoryBook(const QString& szProjectPath, QObject *parent = nullptr); ~cStoryBook(); bool openDatabase(); diff --git a/ctextdocument.cpp b/ctextdocument.cpp index 0c1d251..b0b7746 100644 --- a/ctextdocument.cpp +++ b/ctextdocument.cpp @@ -1,5 +1,4 @@ #include "ctextdocument.h" -#include "cdocumentwriter.h" #include @@ -52,55 +51,36 @@ cTextDocument::cTextDocument(const QString &text, QObject *parent) : void cTextDocument::init() { setPageSize((QSizeF(210, 297))); -/* - QTextCursor* myCursor = new QTextCursor(this); - - QTextBlockFormat format; - format.setBackground(Qt::red); - myCursor->setBlockFormat(format); - - myCursor->insertText("the "); - - format.setBackground(Qt::green); - myCursor->insertBlock(format); - myCursor->insertText("fish "); - - format.setBackground(Qt::yellow); - myCursor->insertBlock(format); - myCursor->insertText("are "); - - format.setBackground(Qt::red); - myCursor->insertBlock(format); - myCursor->insertText("coming!"); - - format.setBackground(Qt::green); - myCursor->insertBlock(format); - myCursor->insertText(QString("%1 blocks").arg(this->blockCount())); -*/ } -bool cTextDocument::save(bool bZip) +bool cTextDocument::save() { if(!m_szFileName.isEmpty()) - return(saveDocument(bZip)); + return(saveDocument()); return(false); } -bool cTextDocument::saveAs(const QString& szFileName, bool bZip) +bool cTextDocument::saveAs(const QString& szFileName) { m_szFileName = szFileName; - return(saveDocument(bZip)); + return(saveDocument()); } -bool cTextDocument::saveDocument(bool bZip) +#include + +bool cTextDocument::saveDocument() { - cDocumentWriter docWriter(m_szFileName, bZip); - if(!docWriter.open()) + QFile file(m_szFileName); + QByteArray data = this->toHtml().toUtf8(); + + if(!file.open(QFile::WriteOnly | QFile::Truncate)) return(false); - docWriter.writeDocument(this); + QByteArray zipped = qCompress(data); + file.write(zipped); + + file.close(); - docWriter.close(); return(true); } diff --git a/ctextdocument.h b/ctextdocument.h index 2ecffec..9e5d8d3 100644 --- a/ctextdocument.h +++ b/ctextdocument.h @@ -22,15 +22,15 @@ public: cTextDocument(QObject *parent = Q_NULLPTR); cTextDocument(const QString &text, QObject *parent = Q_NULLPTR); - bool save(bool bZip = true); - bool saveAs(const QString& szFileName, bool bZip = true); + bool save(); + bool saveAs(const QString& szFileName); void printPreview(QPrinter* lpPrinter); private: QString m_szFileName; void init(); - bool saveDocument(bool bZip = true); + bool saveDocument(); private slots: }; diff --git a/qtStoryWriter.pro b/qtStoryWriter.pro index 3d9888a..e2d9ace 100644 --- a/qtStoryWriter.pro +++ b/qtStoryWriter.pro @@ -28,35 +28,21 @@ win32-msvc* { message("msvc 32-bit") } else { message("msvc 64-bit") - INCLUDEPATH += C:/dev/3rdParty/quazip/include - DEPENDPATH += C:/dev/3rdParty/quazip/include - LIBS += C:/dev/3rdParty/quazip/msc/lib/quazip.lib - INCLUDEPATH += C:/dev/3rdParty/zlib/include - DEPENDPATH += C:/dev/3rdParty/zlib/include - LIBS += C:/dev/3rdParty/zlib/msc/lib/zlib.lib } } win32-g++ { message("mingw") - INCLUDEPATH += C:/dev/3rdParty/quazip/include - DEPENDPATH += C:/dev/3rdParty/quazip/include - LIBS += -LC:/dev/3rdParty/quazip/gcc/lib -lquazip - INCLUDEPATH += C:/dev/3rdParty/zlib/include - DEPENDPATH += C:/dev/3rdParty/zlib/include - LIBS += -LC:/dev/3rdParty/zlib/gcc/lib -lz } unix { - LIBS += -lquazip + message("*nix") } SOURCES += \ main.cpp \ cmainwindow.cpp \ - cdocumentreader.cpp \ - cdocumentwriter.cpp \ ctextdocument.cpp \ common.cpp \ ctextedit.cpp \ @@ -66,12 +52,11 @@ SOURCES += \ cbook.cpp \ cpart.cpp \ cchapter.cpp \ - cscene.cpp + cscene.cpp \ + ccharacter.cpp HEADERS += \ cmainwindow.h \ - cdocumentreader.h \ - cdocumentwriter.h \ ctextdocument.h \ common.h \ ctextedit.h \ @@ -82,7 +67,8 @@ HEADERS += \ cbook.h \ cpart.h \ cchapter.h \ - cscene.h + cscene.h \ + ccharacter.h FORMS += \ cmainwindow.ui \