.
@@ -0,0 +1,207 @@
|
||||
#ifndef CDOCUMENTREADER_H
|
||||
#define CDOCUMENTREADER_H
|
||||
|
||||
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#include <QFile>
|
||||
#include <QDomDocument>
|
||||
#include <QDomElement>
|
||||
#include <QDomNode>
|
||||
|
||||
#include <QFont>
|
||||
#include <QTextOption>
|
||||
#include <QTextFormat>
|
||||
#include <QBrush>
|
||||
#include <QColor>
|
||||
|
||||
#include <QTextTableCellFormat>
|
||||
#include <QTextTableFormat>
|
||||
#include <QTextImageFormat>
|
||||
#include <QTextFrameFormat>
|
||||
#include <QTextListFormat>
|
||||
#include <QTextBlockFormat>
|
||||
#include <QTextCharFormat>
|
||||
#include <QTextLayout>
|
||||
#include <QTextBlock>
|
||||
#include <QTextCursor>
|
||||
|
||||
|
||||
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<int, QTextList*> 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<cTextFormat>& allFormats);
|
||||
|
||||
QVector<QTextLayout::FormatRange> parseTextFormats(const QDomElement& element);
|
||||
QTextLayout::FormatRange parseRange(const QDomElement& element);
|
||||
QFont parseFont(const QDomElement& element);
|
||||
QTextOption parseDefaultTextOption(const QDomElement& element);
|
||||
QList<QTextOption::Tab> parseTabPositions(const QDomElement& element);
|
||||
QVector<cTextFormat> 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
|
||||
@@ -0,0 +1,620 @@
|
||||
#include "cdocumentwriter.h"
|
||||
#include "ctextdocument.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
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<QPair<int, QTextBlockFormat>> 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<int, QTextBlockFormat>(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<QPair<int, QTextBlockFormat>> 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 <QTextList>
|
||||
#include <QTextTable>
|
||||
|
||||
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<QTextLayout::FormatRange> 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<int, QVariant> properties = lpTextFormat->properties();
|
||||
QMapIterator<int, QVariant> 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<QTextFormat> 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<QTextOption::Tab> 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();
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#ifndef CDOCUMENTWRITER_H
|
||||
#define CDOCUMENTWRITER_H
|
||||
|
||||
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
|
||||
#include <QColor>
|
||||
#include <QGradient>
|
||||
#include <QPen>
|
||||
#include <QBrush>
|
||||
#include <QVector>
|
||||
#include <QPair>
|
||||
|
||||
#include <QTextBlock>
|
||||
#include <QTextBlockFormat>
|
||||
#include <QTextCharFormat>
|
||||
#include <QTextFormat>
|
||||
|
||||
|
||||
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<QPair<int, QTextBlockFormat>> 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<QTextFormat> 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<QTextOption::Tab> tabs);
|
||||
};
|
||||
|
||||
#endif // CDOCUMENTWRITER_H
|
||||
@@ -0,0 +1,278 @@
|
||||
#include "cmainwindow.h"
|
||||
#include "ui_cmainwindow.h"
|
||||
|
||||
#include "ctextdocument.h"
|
||||
#include "cdocumentreader.h"
|
||||
|
||||
#include <QTextDocument>
|
||||
#include <QTextBlockFormat>
|
||||
#include <QTextCharFormat>
|
||||
|
||||
#include <QTextDocumentWriter>
|
||||
#include <QByteArray>
|
||||
#include <QTextCodec>
|
||||
#include <QFile>
|
||||
|
||||
|
||||
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<QTextOption::Tab>& 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<QTextOption::Tab> 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 <QTextList>
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef CMAINWINDOW_H
|
||||
#define CMAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
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
|
||||
@@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>cMainWindow</class>
|
||||
<widget class="QMainWindow" name="cMainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>569</width>
|
||||
<height>460</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>cMainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTabWidget" name="m_lpTabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="m_lpInputTab">
|
||||
<attribute name="title">
|
||||
<string>Input</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTextEdit" name="m_lpInput"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="m_lpOutputTab">
|
||||
<attribute name="title">
|
||||
<string>Output</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTextEdit" name="m_lpOutput"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>569</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuTest">
|
||||
<property name="title">
|
||||
<string>Test</string>
|
||||
</property>
|
||||
<addaction name="actionTest1"/>
|
||||
<addaction name="actionSave"/>
|
||||
</widget>
|
||||
<addaction name="menuTest"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<action name="actionTest1">
|
||||
<property name="text">
|
||||
<string>Test1</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1 @@
|
||||
#include "common.h"
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
#define myDebug qDebug() << __FILE__ << "(" << __LINE__ << ") - " << __PRETTY_FUNCTION__ << ":"
|
||||
|
||||
|
||||
#endif // COMMON_H
|
||||
@@ -0,0 +1,115 @@
|
||||
#include "ctextdocument.h"
|
||||
#include "cdocumentwriter.h"
|
||||
|
||||
#include <QVector>
|
||||
|
||||
#include <QTextCursor>
|
||||
#include <QTextBlock>
|
||||
#include <QTextBlockFormat>
|
||||
#include <QTextFormat>
|
||||
#include <QTextOption>
|
||||
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
#include <QFile>
|
||||
#include <QByteArray>
|
||||
#include <QTextCodec>
|
||||
#include <QList>
|
||||
#include <QSizeF>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
#if defined(QT_PRINTSUPPORT_LIB)
|
||||
#include <QtPrintSupport/qtprintsupportglobal.h>
|
||||
#if QT_CONFIG(printer)
|
||||
#if QT_CONFIG(printdialog)
|
||||
#include <QPrintDialog>
|
||||
#endif
|
||||
#include <QPrinter>
|
||||
#if QT_CONFIG(printpreviewdialog)
|
||||
#include <QPrintPreviewDialog>
|
||||
#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
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef CTEXTDOCUMENT_H
|
||||
#define CTEXTDOCUMENT_H
|
||||
|
||||
|
||||
#include <QObject>
|
||||
#include <QTextDocument>
|
||||
|
||||
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
|
||||
@@ -0,0 +1,79 @@
|
||||
<html><head><meta name="qrichtext" content="1" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>QTextEdit Example</title><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
|
||||
<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:20pt; font-weight:600;">QTextEdit</span></p>
|
||||
<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">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.</span></p>
|
||||
<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">If you are viewing this document in the <span style=" font-style:italic;">textedit</span> 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. </p>
|
||||
<p style=" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:18pt; font-weight:600;"><span style=" font-size:16pt;">Font and Paragraph Styles</span></p>
|
||||
<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">QTextEdit supports </span><span style=" font-size:11pt; font-weight:600;">bold</span><span style=" font-size:11pt;">, </span><span style=" font-size:11pt; font-style:italic;">italic</span><span style=" font-size:11pt;">, and </span><span style=" font-size:11pt; text-decoration: underline;">underlined</span><span style=" font-size:11pt;"> font styles, and can display </span><span style=" font-size:11pt; font-weight:600; color:#00007f;">multicolored</span><span style=" font-size:11pt;"> </span><span style=" font-size:11pt; font-weight:600; color:#aa0000;">text</span><span style=" font-size:11pt;">. Font families such as </span><span style=" font-family:'Times New Roman'; font-size:11pt; font-weight:600;">Times New Roman</span><span style=" font-size:11pt;"> and </span><span style=" font-family:'Courier'; font-size:11pt; font-weight:600;">Courier</span><span style=" font-size:11pt;"> can also be used directly. </span><span style=" font-size:11pt; font-style:italic;">If you place the cursor in a region of styled text, the controls in the tool bars will change to reflect the current style.</span></p>
|
||||
<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Paragraphs can be formatted so that the text is left-aligned, right-aligned, centered, or fully justified.</p>
|
||||
<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-style:italic;">Try changing the alignment of some text and resize the editor to see how the text layout changes.</span> </p>
|
||||
<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:16pt; font-weight:600;">Lists</span></p>
|
||||
<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">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: </span></p>
|
||||
<ul style="-qt-list-indent: 1;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Disc symbols are typically used for top-level list items. </li></ul>
|
||||
<ul type=circle style="-qt-list-indent: 2;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Circle symbols can be used to distinguish between items in lower-level lists.</li></ul>
|
||||
<ul type=square style="-qt-list-indent: 3;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Square symbols provide a reasonable alternative to discs and circles. </li></ul>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">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: </p>
|
||||
<ol style="-qt-list-indent: 1;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Introduction</li>
|
||||
<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Tools </li></ol>
|
||||
<ol type=a style="-qt-list-indent: 2;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Assistant</li>
|
||||
<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Designer</li>
|
||||
<ol type=A style="-qt-list-indent: 3;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Form Editor</li>
|
||||
<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Component Architecture</li></ol>
|
||||
<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Linguist</li></ol>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">The list will automatically be renumbered if you add or remove items. <span style=" font-style:italic;">Try adding new sections to the above list or removing existing item to see the numbers change.</span> </p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
|
||||
<p style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Images</span></p>
|
||||
<p style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">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. </span></p>
|
||||
<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><img src=":/images/logo32.png" /><span style=" font-style:italic;"> 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.</span></p>
|
||||
<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Tables</span></p>
|
||||
<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">QTextEdit can arrange and format tables, supporting features such as row and column spans, text formatting within cells, and size constraints for columns. </span></p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
|
||||
<table border="1" align="center" width="90%" cellspacing="0" cellpadding="4">
|
||||
<tr>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> </p></td>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Development Tools </span></p></td>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Programming Techniques </span></p></td>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Graphical User Interfaces </span></p></td></tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">9:00 - 11:00 </span></p></td>
|
||||
<td colspan="3">
|
||||
<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Introduction to <span style=" font-style:italic;">Qt </span></p></td></tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">11:00 - 13:00 </span></p></td>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Using <span style=" font-style:italic;">qmake</span> </p></td>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Object-oriented Programming </p></td>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Layouts in <span style=" font-style:italic;">Qt</span> </p></td></tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">13:00 - 15:00 </span></p></td>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Qt Designer</span> Tutorial </p></td>
|
||||
<td rowspan="2">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Extreme Programming </p></td>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Writing Custom Styles </p></td></tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">15:00 - 17:00 </span></p></td>
|
||||
<td>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Qt Linguist</span> and Internationalization </p></td>
|
||||
<td></td></tr></table>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt; font-style:italic;">Try adding text to the cells in the table and experiment with the alignment of the paragraphs.</p>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Hyperlinks</span></p>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">QTextEdit is designed to support hyperlinks between documents, and this feature is used extensively in </span><span style=" font-size:11pt; font-style:italic;">Qt Assistant</span><span style=" font-size:11pt;">. 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.</span></p>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Undo and Redo</span></p>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">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.</p>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-style:italic;">Try making changes to this document and press Ctrl+Z to undo them. You can always recover the original contents of the document.</span> </p></body></html>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 768 B |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 627 B |
|
After Width: | Height: | Size: 829 B |
|
After Width: | Height: | Size: 695 B |
|
After Width: | Height: | Size: 673 B |
|
After Width: | Height: | Size: 677 B |
|
After Width: | Height: | Size: 971 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,11 @@
|
||||
#include "cmainwindow.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
cMainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,44 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>example.html</file>
|
||||
<file>images/logo32.png</file>
|
||||
<file>images/mac/editcopy.png</file>
|
||||
<file>images/mac/editcut.png</file>
|
||||
<file>images/mac/editpaste.png</file>
|
||||
<file>images/mac/editredo.png</file>
|
||||
<file>images/mac/editundo.png</file>
|
||||
<file>images/mac/exportpdf.png</file>
|
||||
<file>images/mac/filenew.png</file>
|
||||
<file>images/mac/fileopen.png</file>
|
||||
<file>images/mac/fileprint.png</file>
|
||||
<file>images/mac/filesave.png</file>
|
||||
<file>images/mac/textbold.png</file>
|
||||
<file>images/mac/textcenter.png</file>
|
||||
<file>images/mac/textitalic.png</file>
|
||||
<file>images/mac/textjustify.png</file>
|
||||
<file>images/mac/textleft.png</file>
|
||||
<file>images/mac/textright.png</file>
|
||||
<file>images/mac/textunder.png</file>
|
||||
<file>images/mac/zoomin.png</file>
|
||||
<file>images/mac/zoomout.png</file>
|
||||
<file>images/win/editcopy.png</file>
|
||||
<file>images/win/editcut.png</file>
|
||||
<file>images/win/editpaste.png</file>
|
||||
<file>images/win/editredo.png</file>
|
||||
<file>images/win/editundo.png</file>
|
||||
<file>images/win/exportpdf.png</file>
|
||||
<file>images/win/filenew.png</file>
|
||||
<file>images/win/fileopen.png</file>
|
||||
<file>images/win/fileprint.png</file>
|
||||
<file>images/win/filesave.png</file>
|
||||
<file>images/win/textbold.png</file>
|
||||
<file>images/win/textcenter.png</file>
|
||||
<file>images/win/textitalic.png</file>
|
||||
<file>images/win/textjustify.png</file>
|
||||
<file>images/win/textleft.png</file>
|
||||
<file>images/win/textright.png</file>
|
||||
<file>images/win/textunder.png</file>
|
||||
<file>images/win/zoomin.png</file>
|
||||
<file>images/win/zoomout.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||