diff --git a/cdocumentreader.cpp b/cdocumentreader.cpp new file mode 100644 index 0000000..3d1de6c --- /dev/null +++ b/cdocumentreader.cpp @@ -0,0 +1,1910 @@ +#include "cdocumentreader.h" +#include "ctextdocument.h" + +#include "common.h" + +#include +#include + +#include + +#include +#include + +cDocumentReader::cDocumentReader(const QString &szFileName) : + m_bFirstBlock(true), + m_szFileName(szFileName) +{ +} + +cDocumentReader::~cDocumentReader() +{ + close(); +} + +bool cDocumentReader::open() +{ + m_file.setFileName(m_szFileName); + + if(!m_file.open(QFile::ReadOnly | QFile::Text)) + return(false); + + return(true); +} + +bool cDocumentReader::close() +{ + if(m_file.isOpen()) + m_file.close();; + + return(true); +} + +cTextDocument* cDocumentReader::readDocument() +{ + if(!m_file.isOpen()) + return(0); + + cTextDocument* lpDocument; + QDomDocument doc; + QString errorStr; + int errorLine; + int errorColumn; + 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(); + } + + m_file.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; + QTextImageFormat::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 = (QTextImageFormat::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; + QTextImageFormat::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 = (QTextImageFormat::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; + QTextImageFormat::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 = (QTextImageFormat::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(); + } + + int indent; + + if(m_bFirstBlock) + m_bFirstBlock = false; + else + { + if(listFormatIndex != -1) + { + indent = allFormats[listFormatIndex].listFormat.indent(); + + if(!m_textLists.value(indent)) + { + m_textLists.insert(allFormats[listFormatIndex].listFormat.indent(), lpCursor->insertList(allFormats[listFormatIndex].listFormat)); + lpCursor->setBlockFormat(allFormats[blockFormatIndex].blockFormat); + lpCursor->setCharFormat(allFormats[charFormatIndex].charFormat); + lpCursor->setBlockCharFormat(allFormats[charFormatIndex].charFormat); + } + else + { + lpCursor->insertBlock(); + lpCursor->setBlockFormat(allFormats[blockFormatIndex].blockFormat); + lpCursor->setCharFormat(allFormats[charFormatIndex].charFormat); + lpCursor->setBlockCharFormat(allFormats[charFormatIndex].charFormat); + } + + QTextBlock block = lpCursor->block(); + QTextList* list = m_textLists.value(indent); + list->add(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; + QTextImageFormat::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 = (QTextImageFormat::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 new file mode 100644 index 0000000..9391c32 --- /dev/null +++ b/cdocumentreader.h @@ -0,0 +1,207 @@ +#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 + + +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); + ~cDocumentReader(); + + bool open(); + bool close(); + + cTextDocument* readDocument(); +private: + bool m_bFirstBlock; + QString m_szFileName; + QFile m_file; + + 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 new file mode 100644 index 0000000..893cfc2 --- /dev/null +++ b/cdocumentwriter.cpp @@ -0,0 +1,620 @@ +#include "cdocumentwriter.h" +#include "ctextdocument.h" + +#include + + +cDocumentWriter::cDocumentWriter(const QString &szFileName) : + m_szFileName(szFileName) +{ +} + +cDocumentWriter::~cDocumentWriter() +{ + close(); +} + +bool cDocumentWriter::open() +{ + if(m_szFileName.isEmpty()) + return(false); + + m_file.setFileName(m_szFileName); + if(!m_file.open(QFile::WriteOnly | QFile::Text)) + return(false); + + setDevice(&m_file); + setAutoFormatting(true); + setAutoFormattingIndent(-1); + writeStartDocument(); + writeStartElement("document"); + + return(true); +} + +bool cDocumentWriter::close() +{ + if(m_file.isOpen()) + { + writeEndElement(); + writeEndDocument(); + m_file.close(); + } + + return(true); +} + +bool cDocumentWriter::writeDocument(cTextDocument *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())); + } + } +} + +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 new file mode 100644 index 0000000..3a76a32 --- /dev/null +++ b/cdocumentwriter.h @@ -0,0 +1,75 @@ +#ifndef CDOCUMENTWRITER_H +#define CDOCUMENTWRITER_H + + +#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); + ~cDocumentWriter(); + + bool open(); + bool close(); + + bool writeDocument(cTextDocument* lpDocument); + +private: + QString m_szFileName; + QFile m_file; + + 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 new file mode 100644 index 0000000..5e209a2 --- /dev/null +++ b/cmainwindow.cpp @@ -0,0 +1,278 @@ +#include "cmainwindow.h" +#include "ui_cmainwindow.h" + +#include "ctextdocument.h" +#include "cdocumentreader.h" + +#include +#include +#include + +#include +#include +#include +#include + + +cTextDocument* g_lpInputDocument = 0; +cTextDocument* g_lpOutputDocument = 0; + + +QTextBlockFormat createTextBlockFormat(Qt::Alignment alignment, qreal leftMargin, qreal topMargin, qreal rightMargin, qreal bottomMargin, int indent, qreal lineHeight, int lineHeightType, + bool nonBreakableLines, QTextBlockFormat::PageBreakFlags pageBreakPolicy, const QList& tabPositions, qreal textIndent, + QBrush background, QBrush foreground, Qt::LayoutDirection layoutDirection, int objectIndex, int objectType /* property*/) +{ + 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.setTabPositions(tabPositions); + format.setTextIndent(textIndent); + + format.setBackground(background); + format.setForeground(foreground); + format.setLayoutDirection(layoutDirection); + format.setObjectIndex(objectIndex); + format.setObjectType(objectType); + //property + + return(format); +} + +QTextCharFormat createTextCharFormat(bool anchor, const QString& anchorHref, const QStringList& anchorNames, const QFont& font, QTextCharFormat::FontPropertiesInheritanceBehavior behavior, + const QPen& textOutline, const QString& toolTip, const QColor& underlineColor, QTextCharFormat::UnderlineStyle underlineStyle, QTextCharFormat::VerticalAlignment verticalAlignment, + QBrush background, QBrush foreground, Qt::LayoutDirection layoutDirection, int objectIndex, int objectType /* property*/) +{ + QTextCharFormat format; + + format.setAnchor(anchor); + format.setAnchorHref(anchorHref); + format.setAnchorNames(anchorNames); + format.setFont(font, behavior); + format.setTextOutline(textOutline); + format.setToolTip(toolTip); + format.setUnderlineColor(underlineColor); + format.setUnderlineStyle(underlineStyle); + format.setVerticalAlignment(verticalAlignment); + + format.setBackground(background); + format.setForeground(foreground); + format.setLayoutDirection(layoutDirection); + format.setObjectIndex(objectIndex); + format.setObjectType(objectType); + //property + + return(format); +} + +void readWriteTest1() +{ + if(!QFile::exists(":/example.html")) + return; + QFile file(":/example.html"); + + if(!file.open(QFile::ReadOnly)) + return; + + QByteArray data = file.readAll(); + QTextCodec* codec = Qt::codecForHtml(data); + QString str = codec->toUnicode(data); + if(Qt::mightBeRichText(str)) + { + g_lpInputDocument->setHtml(str); + } + else + { + str = QString::fromLocal8Bit(data); + g_lpInputDocument->setPlainText(str); + } + + file.close(); +} + +void readWriteTest2() +{ + QTextCursor cursor(g_lpInputDocument); + + // TEXT BLOCK FORMAT + Qt::Alignment alignment = Qt::AlignCenter; + qreal leftMargin = 0; + qreal topMargin = 0; + qreal rightMargin = 0; + qreal bottomMargin = 0; + int indent = 0; + qreal lineHeight = 1; + int lineHeightType = QTextBlockFormat::SingleHeight; // QTextBlockFormat::SingleHeight 0 This is the default line height: single spacing. + // QTextBlockFormat::ProportionalHeight 1 This sets the spacing proportional to the line (in percentage). For example, set to 200 for double spacing. + // QTextBlockFormat::FixedHeight 2 This sets the line height to a fixed line height (in pixels). + // QTextBlockFormat::MinimumHeight 3 This sets the minimum line height (in pixels). + // QTextBlockFormat::LineDistanceHeight 4 This adds the specified height between lines (in pixels). + bool nonBreakableLines = false; + QTextBlockFormat::PageBreakFlags pageBreakPolicy = QTextFormat::PageBreak_Auto; // QTextFormat::PageBreak_Auto 0 The page break is determined automatically depending on the available space on the current page + // QTextFormat::PageBreak_AlwaysBefore 0x001 The page is always broken before the paragraph/table + // QTextFormat::PageBreak_AlwaysAfter 0x010 A new page is always started after the paragraph/table + const QList tabPositions; + qreal textIndent = 0; + QBrush background = QBrush(QColor("lightGray")); + QBrush foreground = QBrush(QColor("black")); + Qt::LayoutDirection layoutDirection = Qt::LeftToRight; // Qt::LeftToRight 0 Left-to-right layout. + // Qt::RightToLeft 1 Right-to-left layout. + // Qt::LayoutDirectionAuto 2 Automatic layout. + int objectIndex = 0; + int objectType = QTextFormat::NoObject; // QTextFormat::NoObject 0 + // QTextFormat::ImageObject 1 + // QTextFormat::TableObject 2 + // QTextFormat::TableCellObject 3 + // QTextFormat::UserObject 0x1000 The first object that can be used for application-specific purposes. + //property + + + // TEXT CHAR FORMAT + bool anchor = false; + QString anchorHref = ""; + QStringList anchorNames; + QFont font = QFont("Arial"); + QTextCharFormat::FontPropertiesInheritanceBehavior behavior = QTextCharFormat::FontPropertiesAll;// QTextCharFormat::FontPropertiesSpecifiedOnly 0 If a property is not explicitly set, do not change the text format's property value. + // QTextCharFormat::FontPropertiesAll 1 If a property is not explicitly set, override the text format's property with a default value. + QPen textOutline = QPen(QColor("blue")); + QString toolTip = "toolTip"; + QColor underlineColor = QColor("yellow"); + QTextCharFormat::UnderlineStyle underlineStyle = QTextCharFormat::NoUnderline; // QTextCharFormat::NoUnderline 0 Text is draw without any underlining decoration. + // QTextCharFormat::SingleUnderline 1 A line is drawn using Qt::SolidLine. + // QTextCharFormat::DashUnderline 2 Dashes are drawn using Qt::DashLine. + // QTextCharFormat::DotLine 3 Dots are drawn using Qt::DotLine; + // QTextCharFormat::DashDotLine 4 Dashs and dots are drawn using Qt::DashDotLine. + // QTextCharFormat::DashDotDotLine 5 Underlines draw drawn using Qt::DashDotDotLine. + // QTextCharFormat::WaveUnderline 6 The text is underlined using a wave shaped line. + // QTextCharFormat::SpellCheckUnderline 7 The underline is drawn depending on the SpellCheckUnderlineStyle theme hint of QPlatformTheme. By default this is mapped to WaveUnderline, on macOS it is mapped to DotLine. + QTextCharFormat::VerticalAlignment verticalAlignment = QTextCharFormat::AlignNormal; // QTextCharFormat::AlignNormal 0 Adjacent characters are positioned in the standard way for text in the writing system in use. + // QTextCharFormat::AlignSuperScript 1 Characters are placed above the base line for normal text. + // QTextCharFormat::AlignSubScript 2 Characters are placed below the base line for normal text. + // QTextCharFormat::AlignMiddle 3 The center of the object is vertically aligned with the base line. Currently, this is only implemented for inline objects. + // QTextCharFormat::AlignBottom 5 The bottom edge of the object is vertically aligned with the base line. + // QTextCharFormat::AlignTop 4 The top edge of the object is vertically aligned with the base line. + // QTextCharFormat::AlignBaseline 6 The base lines of the characters are aligned. + QBrush background1 = QBrush(QColor("red")); + QBrush foreground1 = QBrush(QColor("green")); + Qt::LayoutDirection layoutDirection1 = Qt::LeftToRight; // Qt::LeftToRight 0 Left-to-right layout. + // Qt::RightToLeft 1 Right-to-left layout. + // Qt::LayoutDirectionAuto 2 Automatic layout. + int objectIndex1 = 0; + int objectType1 = QTextFormat::NoObject; // QTextFormat::NoObject 0 + // QTextFormat::ImageObject 1 + // QTextFormat::TableObject 2 + // QTextFormat::TableCellObject 3 + // QTextFormat::UserObject 0x1000 The first object that can be used for application-specific purposes. + //property + + QTextBlockFormat blockFormat1 = createTextBlockFormat(alignment, leftMargin, topMargin, rightMargin, bottomMargin, indent, lineHeight, lineHeightType, nonBreakableLines, pageBreakPolicy, tabPositions, textIndent, background, foreground, layoutDirection, objectIndex, objectType); + QTextCharFormat charFormat1 = createTextCharFormat(anchor, anchorHref, anchorNames, font, behavior, textOutline, toolTip, underlineColor, underlineStyle, verticalAlignment, background1, foreground1, layoutDirection1, objectIndex1, objectType1); // property); + + cursor.setBlockFormat(blockFormat1); + cursor.setBlockCharFormat(charFormat1); + + cursor.insertText("TestText"); +} + +#include + +void readWriteTest3() +{ + QTextCursor cursor(g_lpInputDocument); + + QTextListFormat* lpFormat = new QTextListFormat; + QString numberSuffix = lpFormat->numberSuffix(); + + lpFormat->setNumberSuffix("."); + numberSuffix = lpFormat->numberSuffix(); + + delete lpFormat; + + QTextList* list1; + QTextList* list2; + QTextList* list3; + QTextBlock textBlock; + + QTextListFormat format1; + QTextListFormat format2; + QTextListFormat format3; + format1.setStyle(QTextListFormat::ListDecimal); + format1.setIndent(1); + format2.setStyle(QTextListFormat::ListLowerAlpha); + format2.setIndent(2); + format3.setStyle(QTextListFormat::ListUpperAlpha); + format3.setIndent(3); + + list1 = cursor.insertList(format1); + textBlock = cursor.block(); cursor.insertText("Introduction"); list1->add(textBlock); + cursor.insertBlock(); textBlock = cursor.block(); cursor.insertText("Tools"); list1->add(textBlock); + + list2 = cursor.insertList(format2); + textBlock = cursor.block(); cursor.insertText("Assistant"); list2->add(textBlock); + cursor.insertBlock(); textBlock = cursor.block(); cursor.insertText("Designer"); list2->add(textBlock); + + list3 = cursor.insertList(format3); + textBlock = cursor.block(); cursor.insertText("Form Editor"); list3->add(textBlock); + cursor.insertBlock(); textBlock = cursor.block(); cursor.insertText("Component Architecture"); list3->add(textBlock); + + cursor.insertBlock(); textBlock = cursor.block(); cursor.insertText("Qt Linguist"); list2->add(textBlock); +} + +cMainWindow::cMainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::cMainWindow) +{ + ui->setupUi(this); + ui->m_lpTabWidget->setCurrentIndex(0); + + g_lpInputDocument = new cTextDocument(ui->m_lpInput); + g_lpOutputDocument = new cTextDocument(ui->m_lpOutput); + + ui->m_lpInput->setDocument(g_lpInputDocument); + + readWriteTest1(); +// readWriteTest2(); +// readWriteTest3(); +} + +cMainWindow::~cMainWindow() +{ + delete ui; + + if(g_lpInputDocument) + delete g_lpInputDocument; + + if(g_lpOutputDocument) + delete g_lpOutputDocument; +} + +void cMainWindow::on_actionTest1_triggered() +{ + QTextBlockFormat blockFormatStyle; + blockFormatStyle.setBackground(QColor("red")); + + QTextCursor cursor(g_lpInputDocument); + cursor.setBlockFormat(blockFormatStyle); + + QTextCharFormat charFormatStyle; + +} + +void cMainWindow::on_actionSave_triggered() +{ + g_lpInputDocument->saveAs("C:/Temp/documentText.xml"); + + cDocumentReader reader("C:/Temp/documentText.xml"); + reader.open(); + g_lpOutputDocument = reader.readDocument(); + reader.close(); + + ui->m_lpOutput->setDocument(g_lpOutputDocument); +} diff --git a/cmainwindow.h b/cmainwindow.h new file mode 100644 index 0000000..3f84cb7 --- /dev/null +++ b/cmainwindow.h @@ -0,0 +1,27 @@ +#ifndef CMAINWINDOW_H +#define CMAINWINDOW_H + +#include + +namespace Ui { +class cMainWindow; +} + +class cMainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit cMainWindow(QWidget *parent = 0); + ~cMainWindow(); + +private slots: + void on_actionTest1_triggered(); + + void on_actionSave_triggered(); + +private: + Ui::cMainWindow *ui; +}; + +#endif // CMAINWINDOW_H diff --git a/cmainwindow.ui b/cmainwindow.ui new file mode 100644 index 0000000..11431fb --- /dev/null +++ b/cmainwindow.ui @@ -0,0 +1,88 @@ + + + cMainWindow + + + + 0 + 0 + 569 + 460 + + + + cMainWindow + + + + + + + 0 + + + + Input + + + + + + + + + + Output + + + + + + + + + + + + + + + 0 + 0 + 569 + 21 + + + + + Test + + + + + + + + + TopToolBarArea + + + false + + + + + + Test1 + + + + + Save + + + + + + + diff --git a/common.cpp b/common.cpp new file mode 100644 index 0000000..67c02a2 --- /dev/null +++ b/common.cpp @@ -0,0 +1 @@ +#include "common.h" diff --git a/common.h b/common.h new file mode 100644 index 0000000..d4e2cb9 --- /dev/null +++ b/common.h @@ -0,0 +1,11 @@ +#ifndef COMMON_H +#define COMMON_H + + +#include + + +#define myDebug qDebug() << __FILE__ << "(" << __LINE__ << ") - " << __PRETTY_FUNCTION__ << ":" + + +#endif // COMMON_H diff --git a/ctextdocument.cpp b/ctextdocument.cpp new file mode 100644 index 0000000..d69a7a2 --- /dev/null +++ b/ctextdocument.cpp @@ -0,0 +1,115 @@ +#include "ctextdocument.h" +#include "cdocumentwriter.h" + +#include + +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include + +#include + + +#if defined(QT_PRINTSUPPORT_LIB) + #include + #if QT_CONFIG(printer) + #if QT_CONFIG(printdialog) + #include + #endif + #include + #if QT_CONFIG(printpreviewdialog) + #include + #endif + #endif +#endif + + +cTextDocument::cTextDocument(QObject *parent) : + QTextDocument(parent) +{ + init(); +} + +cTextDocument::cTextDocument(const QString &text, QObject *parent) : + QTextDocument(text, parent), + m_szFileName(QString()) +{ + init(); +} + +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() +{ + if(!m_szFileName.isEmpty()) + return(saveDocument()); + return(false); +} + +bool cTextDocument::saveAs(const QString& szFileName) +{ + m_szFileName = szFileName; + return(saveDocument()); +} + +bool cTextDocument::saveDocument() +{ + cDocumentWriter docWriter(m_szFileName); + if(!docWriter.open()) + return(false); + + docWriter.writeDocument(this); + + docWriter.close(); + return(true); +} + +void cTextDocument::printPreview(QPrinter* lpPrinter) +{ +#ifdef QT_NO_PRINTER + Q_UNUSED(lpPrinter); +#else + lpPrinter->setPageSizeMM(QSizeF(210, 297)); + print(lpPrinter); +#endif +} diff --git a/ctextdocument.h b/ctextdocument.h new file mode 100644 index 0000000..9e5d8d3 --- /dev/null +++ b/ctextdocument.h @@ -0,0 +1,37 @@ +#ifndef CTEXTDOCUMENT_H +#define CTEXTDOCUMENT_H + + +#include +#include + +QT_BEGIN_NAMESPACE +class QAction; +class QComboBox; +class QFontComboBox; +class QTextEdit; +class QTextCharFormat; +class QMenu; +class QPrinter; +QT_END_NAMESPACE + + +class cTextDocument : public QTextDocument +{ +public: + cTextDocument(QObject *parent = Q_NULLPTR); + cTextDocument(const QString &text, QObject *parent = Q_NULLPTR); + + bool save(); + bool saveAs(const QString& szFileName); + + void printPreview(QPrinter* lpPrinter); +private: + QString m_szFileName; + + void init(); + bool saveDocument(); +private slots: +}; + +#endif // CTEXTDOCUMENT_H diff --git a/example.html b/example.html new file mode 100644 index 0000000..e3a56d1 --- /dev/null +++ b/example.html @@ -0,0 +1,79 @@ +QTextEdit Example +

QTextEdit

+

The QTextEdit widget is an advanced editor that supports formatted rich text. It can be used to display HTML and other rich document formats. Internally, QTextEdit uses the QTextDocument class to describe both the high-level structure of each document and the low-level formatting of paragraphs.

+

If you are viewing this document in the textedit example, you can edit this document to explore Qt's rich text editing features. We have included some comments in each of the following sections to encourage you to experiment.

+

Font and Paragraph Styles

+

QTextEdit supports bold, italic, and underlined font styles, and can display multicolored text. Font families such as Times New Roman and Courier can also be used directly. If you place the cursor in a region of styled text, the controls in the tool bars will change to reflect the current style.

+

Paragraphs can be formatted so that the text is left-aligned, right-aligned, centered, or fully justified.

+

Try changing the alignment of some text and resize the editor to see how the text layout changes.

+

Lists

+

Different kinds of lists can be included in rich text documents. Standard bullet lists can be nested, using different symbols for each level of the list:

+
  • Disc symbols are typically used for top-level list items.
+
  • Circle symbols can be used to distinguish between items in lower-level lists.
+
  • Square symbols provide a reasonable alternative to discs and circles.
+

Ordered lists can be created that can be used for tables of contents. Different characters can be used to enumerate items, and we can use both Roman and Arabic numerals in the same list structure:

+
  1. Introduction
  2. +
  3. Qt Tools
+
  1. Qt Assistant
  2. +
  3. Qt Designer
  4. +
    1. Form Editor
    2. +
    3. Component Architecture
    +
  5. Qt Linguist
+

+

The list will automatically be renumbered if you add or remove items. Try adding new sections to the above list or removing existing item to see the numbers change.

+

+

Images

+

Inline images are treated like ordinary ranges of characters in the text editor, so they flow with the surrounding text. Images can also be selected in the same way as text, making it easy to cut, copy, and paste them.

+

Try to select this image by clicking and dragging over it with the mouse, or use the text cursor to select it by holding down Shift and using the arrow keys. You can then cut or copy it, and paste it into different parts of this document.

+

Tables

+

QTextEdit can arrange and format tables, supporting features such as row and column spans, text formatting within cells, and size constraints for columns.

+

+

+ + + + + + + + + + + + + + + + + + + + + + +
+

+

Development Tools

+

Programming Techniques

+

Graphical User Interfaces

+

9:00 - 11:00

+

Introduction to Qt

+

11:00 - 13:00

+

Using qmake

+

Object-oriented Programming

+

Layouts in Qt

+

13:00 - 15:00

+

Qt Designer Tutorial

+

Extreme Programming

+

Writing Custom Styles

+

15:00 - 17:00

+

Qt Linguist and Internationalization

+

+

Try adding text to the cells in the table and experiment with the alignment of the paragraphs.

+

Hyperlinks

+

QTextEdit is designed to support hyperlinks between documents, and this feature is used extensively in Qt Assistant. Hyperlinks are automatically created when an HTML file is imported into an editor. Since the rich text framework supports hyperlinks natively, they can also be created programatically.

+

Undo and Redo

+

Full support for undo and redo operations is built into QTextEdit and the underlying rich text framework. Operations on a document can be packaged together to make editing a more comfortable experience for the user.

+

Try making changes to this document and press Ctrl+Z to undo them. You can always recover the original contents of the document.

diff --git a/images/logo32.png b/images/logo32.png new file mode 100644 index 0000000..5f91e98 Binary files /dev/null and b/images/logo32.png differ diff --git a/images/mac/editcopy.png b/images/mac/editcopy.png new file mode 100644 index 0000000..f551364 Binary files /dev/null and b/images/mac/editcopy.png differ diff --git a/images/mac/editcut.png b/images/mac/editcut.png new file mode 100644 index 0000000..a784fd5 Binary files /dev/null and b/images/mac/editcut.png differ diff --git a/images/mac/editpaste.png b/images/mac/editpaste.png new file mode 100644 index 0000000..64c0b2d Binary files /dev/null and b/images/mac/editpaste.png differ diff --git a/images/mac/editredo.png b/images/mac/editredo.png new file mode 100644 index 0000000..8875bf2 Binary files /dev/null and b/images/mac/editredo.png differ diff --git a/images/mac/editundo.png b/images/mac/editundo.png new file mode 100644 index 0000000..a3bd5e0 Binary files /dev/null and b/images/mac/editundo.png differ diff --git a/images/mac/exportpdf.png b/images/mac/exportpdf.png new file mode 100644 index 0000000..ebb44e6 Binary files /dev/null and b/images/mac/exportpdf.png differ diff --git a/images/mac/filenew.png b/images/mac/filenew.png new file mode 100644 index 0000000..d3882c7 Binary files /dev/null and b/images/mac/filenew.png differ diff --git a/images/mac/fileopen.png b/images/mac/fileopen.png new file mode 100644 index 0000000..fc06c5e Binary files /dev/null and b/images/mac/fileopen.png differ diff --git a/images/mac/fileprint.png b/images/mac/fileprint.png new file mode 100644 index 0000000..10ca56c Binary files /dev/null and b/images/mac/fileprint.png differ diff --git a/images/mac/filesave.png b/images/mac/filesave.png new file mode 100644 index 0000000..b41ecf5 Binary files /dev/null and b/images/mac/filesave.png differ diff --git a/images/mac/textbold.png b/images/mac/textbold.png new file mode 100644 index 0000000..38400bd Binary files /dev/null and b/images/mac/textbold.png differ diff --git a/images/mac/textcenter.png b/images/mac/textcenter.png new file mode 100644 index 0000000..2ef5b2e Binary files /dev/null and b/images/mac/textcenter.png differ diff --git a/images/mac/textitalic.png b/images/mac/textitalic.png new file mode 100644 index 0000000..0170ee2 Binary files /dev/null and b/images/mac/textitalic.png differ diff --git a/images/mac/textjustify.png b/images/mac/textjustify.png new file mode 100644 index 0000000..39cd6c1 Binary files /dev/null and b/images/mac/textjustify.png differ diff --git a/images/mac/textleft.png b/images/mac/textleft.png new file mode 100644 index 0000000..83a66d5 Binary files /dev/null and b/images/mac/textleft.png differ diff --git a/images/mac/textright.png b/images/mac/textright.png new file mode 100644 index 0000000..e7c0464 Binary files /dev/null and b/images/mac/textright.png differ diff --git a/images/mac/textunder.png b/images/mac/textunder.png new file mode 100644 index 0000000..968bac5 Binary files /dev/null and b/images/mac/textunder.png differ diff --git a/images/mac/zoomin.png b/images/mac/zoomin.png new file mode 100644 index 0000000..d46f5af Binary files /dev/null and b/images/mac/zoomin.png differ diff --git a/images/mac/zoomout.png b/images/mac/zoomout.png new file mode 100644 index 0000000..4632656 Binary files /dev/null and b/images/mac/zoomout.png differ diff --git a/images/win/editcopy.png b/images/win/editcopy.png new file mode 100644 index 0000000..1121b47 Binary files /dev/null and b/images/win/editcopy.png differ diff --git a/images/win/editcut.png b/images/win/editcut.png new file mode 100644 index 0000000..38e55f7 Binary files /dev/null and b/images/win/editcut.png differ diff --git a/images/win/editpaste.png b/images/win/editpaste.png new file mode 100644 index 0000000..ffab15a Binary files /dev/null and b/images/win/editpaste.png differ diff --git a/images/win/editredo.png b/images/win/editredo.png new file mode 100644 index 0000000..9d679fe Binary files /dev/null and b/images/win/editredo.png differ diff --git a/images/win/editundo.png b/images/win/editundo.png new file mode 100644 index 0000000..eee23d2 Binary files /dev/null and b/images/win/editundo.png differ diff --git a/images/win/exportpdf.png b/images/win/exportpdf.png new file mode 100644 index 0000000..eef5132 Binary files /dev/null and b/images/win/exportpdf.png differ diff --git a/images/win/filenew.png b/images/win/filenew.png new file mode 100644 index 0000000..af5d122 Binary files /dev/null and b/images/win/filenew.png differ diff --git a/images/win/fileopen.png b/images/win/fileopen.png new file mode 100644 index 0000000..fc6f17e Binary files /dev/null and b/images/win/fileopen.png differ diff --git a/images/win/fileprint.png b/images/win/fileprint.png new file mode 100644 index 0000000..ba7c02d Binary files /dev/null and b/images/win/fileprint.png differ diff --git a/images/win/filesave.png b/images/win/filesave.png new file mode 100644 index 0000000..8feec99 Binary files /dev/null and b/images/win/filesave.png differ diff --git a/images/win/textbold.png b/images/win/textbold.png new file mode 100644 index 0000000..9cbc713 Binary files /dev/null and b/images/win/textbold.png differ diff --git a/images/win/textcenter.png b/images/win/textcenter.png new file mode 100644 index 0000000..11efb4b Binary files /dev/null and b/images/win/textcenter.png differ diff --git a/images/win/textitalic.png b/images/win/textitalic.png new file mode 100644 index 0000000..b30ce14 Binary files /dev/null and b/images/win/textitalic.png differ diff --git a/images/win/textjustify.png b/images/win/textjustify.png new file mode 100644 index 0000000..9de0c88 Binary files /dev/null and b/images/win/textjustify.png differ diff --git a/images/win/textleft.png b/images/win/textleft.png new file mode 100644 index 0000000..16f80bc Binary files /dev/null and b/images/win/textleft.png differ diff --git a/images/win/textright.png b/images/win/textright.png new file mode 100644 index 0000000..16872df Binary files /dev/null and b/images/win/textright.png differ diff --git a/images/win/textunder.png b/images/win/textunder.png new file mode 100644 index 0000000..c72eff5 Binary files /dev/null and b/images/win/textunder.png differ diff --git a/images/win/zoomin.png b/images/win/zoomin.png new file mode 100644 index 0000000..2e586fc Binary files /dev/null and b/images/win/zoomin.png differ diff --git a/images/win/zoomout.png b/images/win/zoomout.png new file mode 100644 index 0000000..a736d39 Binary files /dev/null and b/images/win/zoomout.png differ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..a90eb7a --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "cmainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + cMainWindow w; + w.show(); + + return a.exec(); +} diff --git a/qtStoryWriter.pro b/qtStoryWriter.pro new file mode 100644 index 0000000..8e013b9 --- /dev/null +++ b/qtStoryWriter.pro @@ -0,0 +1,49 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2018-03-26T11:30:37 +# +#------------------------------------------------- + +QT += core gui xml + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = qtStoryWriter +TEMPLATE = app +qtHaveModule(printsupport): QT += printsupport + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + cmainwindow.cpp \ + cdocumentreader.cpp \ + cdocumentwriter.cpp \ + ctextdocument.cpp \ + common.cpp + +HEADERS += \ + cmainwindow.h \ + cdocumentreader.h \ + cdocumentwriter.h \ + ctextdocument.h \ + common.h + +FORMS += \ + cmainwindow.ui + +DISTFILES += \ + example.html + +RESOURCES += \ + qtstorywriter.qrc diff --git a/qtstorywriter.qrc b/qtstorywriter.qrc new file mode 100644 index 0000000..def5add --- /dev/null +++ b/qtstorywriter.qrc @@ -0,0 +1,44 @@ + + + example.html + images/logo32.png + images/mac/editcopy.png + images/mac/editcut.png + images/mac/editpaste.png + images/mac/editredo.png + images/mac/editundo.png + images/mac/exportpdf.png + images/mac/filenew.png + images/mac/fileopen.png + images/mac/fileprint.png + images/mac/filesave.png + images/mac/textbold.png + images/mac/textcenter.png + images/mac/textitalic.png + images/mac/textjustify.png + images/mac/textleft.png + images/mac/textright.png + images/mac/textunder.png + images/mac/zoomin.png + images/mac/zoomout.png + images/win/editcopy.png + images/win/editcut.png + images/win/editpaste.png + images/win/editredo.png + images/win/editundo.png + images/win/exportpdf.png + images/win/filenew.png + images/win/fileopen.png + images/win/fileprint.png + images/win/filesave.png + images/win/textbold.png + images/win/textcenter.png + images/win/textitalic.png + images/win/textjustify.png + images/win/textleft.png + images/win/textright.png + images/win/textunder.png + images/win/zoomin.png + images/win/zoomout.png + +