.
This commit is contained in:
+32
-13
@@ -1719,6 +1719,7 @@ void cDocumentReader::parseTextBlock(const QDomElement& element, QTextCursor* lp
|
||||
QVector<QTextLayout::FormatRange> textFormats;
|
||||
QString text;
|
||||
|
||||
qDebug() << "***** parseTextBlock start *****";
|
||||
QDomNamedNodeMap attributes = element.attributes();
|
||||
for(int x = 0;x < attributes.count();x++)
|
||||
{
|
||||
@@ -1750,10 +1751,9 @@ void cDocumentReader::parseTextBlock(const QDomElement& element, QTextCursor* lp
|
||||
child = child.nextSibling();
|
||||
}
|
||||
|
||||
int indent;
|
||||
|
||||
if(m_bFirstBlock)
|
||||
{
|
||||
qDebug() << "block #1";
|
||||
m_bFirstBlock = false;
|
||||
lpCursor->setBlockFormat(allFormats[blockFormatIndex].blockFormat);
|
||||
lpCursor->setCharFormat(allFormats[charFormatIndex].charFormat);
|
||||
@@ -1761,28 +1761,46 @@ void cDocumentReader::parseTextBlock(const QDomElement& element, QTextCursor* lp
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "block #n";
|
||||
if(listFormatIndex != -1)
|
||||
{
|
||||
int indent = allFormats[listFormatIndex].listFormat.indent();
|
||||
qDebug() << "listFormat";
|
||||
qDebug() << "--> " << text;
|
||||
indent = allFormats[listFormatIndex].listFormat.indent();
|
||||
|
||||
if(!m_textLists.value(indent))
|
||||
if(!m_textLists.contains(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);
|
||||
qDebug() << "list does not exist";
|
||||
qDebug() << " indent: " << indent;
|
||||
QTextListFormat format = allFormats[listFormatIndex].listFormat;
|
||||
QTextList* lpList = lpCursor->insertList(format);
|
||||
qDebug() << " list: " << (int)lpList;
|
||||
m_textLists.insert(indent, lpList);
|
||||
DO MUASS I UMMANANDATUAN ... INDEX FOISCH?
|
||||
// lpCursor->setBlockFormat(allFormats[blockFormatIndex].blockFormat);
|
||||
// lpCursor->setCharFormat(allFormats[charFormatIndex].charFormat);
|
||||
// lpCursor->setBlockCharFormat(allFormats[charFormatIndex].charFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "list already exists";
|
||||
qDebug() << " indent: " << indent;
|
||||
lpCursor->insertBlock();
|
||||
lpCursor->setBlockFormat(allFormats[blockFormatIndex].blockFormat);
|
||||
lpCursor->setCharFormat(allFormats[charFormatIndex].charFormat);
|
||||
lpCursor->setBlockCharFormat(allFormats[charFormatIndex].charFormat);
|
||||
// lpCursor->setBlockFormat(allFormats[blockFormatIndex].blockFormat);
|
||||
// lpCursor->setCharFormat(allFormats[charFormatIndex].charFormat);
|
||||
// lpCursor->setBlockCharFormat(allFormats[charFormatIndex].charFormat);
|
||||
QTextList* list = m_textLists.value(indent);
|
||||
qDebug() << " list: " << (int)list;
|
||||
list->add(lpCursor->block());
|
||||
}
|
||||
|
||||
QTextBlock block = lpCursor->block();
|
||||
QTextList* list = m_textLists.value(indent);
|
||||
list->add(block);
|
||||
// qDebug() << "process further";
|
||||
// QTextBlock block = lpCursor->block();
|
||||
// qDebug() << " indent: " << indent;
|
||||
// QTextList* list = m_textLists.value(indent);
|
||||
// qDebug() << " list: " << (int)list;
|
||||
// list->add(block);
|
||||
}
|
||||
// else if(tableFormatIndex != -1)
|
||||
// lpCursor->insertTable(allFormats[tableFormatIndex].tableFormat);
|
||||
@@ -1805,6 +1823,7 @@ void cDocumentReader::parseTextBlock(const QDomElement& element, QTextCursor* lp
|
||||
QString textPart = text.mid(start, length);
|
||||
lpCursor->insertText(textPart, format);
|
||||
}
|
||||
qDebug() << "****** parseTextBlock end ******";
|
||||
}
|
||||
|
||||
QVector<QTextLayout::FormatRange> cDocumentReader::parseTextFormats(const QDomElement& element)
|
||||
|
||||
+8
-2
@@ -585,9 +585,15 @@ void cDocumentWriter::writeTextImageFormat(QTextImageFormat* lpTextImageFormat,
|
||||
name = m_szPath + "/" + name;
|
||||
QString path = name.left(name.lastIndexOf("/"));
|
||||
|
||||
QDir dir;
|
||||
QFileInfo fileInfo(name);
|
||||
if(fileInfo.suffix().isEmpty())
|
||||
name.append(".png");
|
||||
|
||||
QDir dir;
|
||||
dir.mkpath(path);
|
||||
pixmap.save(name);
|
||||
bool ret = pixmap.save(name);
|
||||
if(!ret)
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+21
-8
@@ -14,6 +14,9 @@
|
||||
#include <QFile>
|
||||
|
||||
|
||||
//#define WITH_ZIP
|
||||
|
||||
|
||||
cTextDocument* g_lpInputDocument = 0;
|
||||
cTextDocument* g_lpOutputDocument = 0;
|
||||
|
||||
@@ -267,13 +270,23 @@ void cMainWindow::on_actionTest1_triggered()
|
||||
|
||||
void cMainWindow::on_actionSave_triggered()
|
||||
{
|
||||
// g_lpInputDocument->saveAs("C:/Temp/qtStoryWriter/documentText.zip");
|
||||
// cDocumentReader reader("C:/Temp/qtStoryWriter/documentText.zip");
|
||||
// g_lpOutputDocument = reader.readDocument();
|
||||
// ui->m_lpOutput->setDocument(g_lpOutputDocument);
|
||||
|
||||
g_lpInputDocument->saveAs("C:/Temp/qtStoryWriter/documentText.xml", false);
|
||||
cDocumentReader reader("C:/Temp/qtStoryWriter/documentText.xml", false);
|
||||
#ifdef __linux__
|
||||
#ifdef WITH_ZIP
|
||||
g_lpInputDocument->saveAs("/tmp/qtStoryWriter/documentText.zip", false);
|
||||
cDocumentReader reader("/tmp/qtStoryWriter/documentText.zip", false);
|
||||
#else
|
||||
g_lpInputDocument->saveAs("/tmp/qtStoryWriter/documentText.xml", false);
|
||||
cDocumentReader reader("/tmp/qtStoryWriter/documentText.xml", false);
|
||||
#endif
|
||||
#elif _WIN32
|
||||
#ifdef WITH_ZIP
|
||||
g_lpInputDocument->saveAs("C:/Temp/qtStoryWriter/documentText.zip", false);
|
||||
cDocumentReader reader("C:/Temp/qtStoryWriter/documentText.zip", false);
|
||||
#else
|
||||
g_lpInputDocument->saveAs("C:/Temp/qtStoryWriter/documentText.xml", false);
|
||||
cDocumentReader reader("C:/Temp/qtStoryWriter/documentText.xml", false);
|
||||
#endif
|
||||
g_lpOutputDocument = reader.readDocument();
|
||||
// ui->m_lpOutput->setDocument(g_lpOutputDocument);
|
||||
ui->m_lpOutput->setDocument(g_lpOutputDocument);
|
||||
#endif
|
||||
}
|
||||
|
||||
+10
-3
@@ -18,7 +18,7 @@
|
||||
<item row="0" column="0">
|
||||
<widget class="QTabWidget" name="m_lpTabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="m_lpInputTab">
|
||||
<attribute name="title">
|
||||
@@ -26,7 +26,7 @@
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTextEdit" name="m_lpInput"/>
|
||||
<widget class="cTextEdit" name="m_lpInput"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@@ -36,7 +36,7 @@
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTextEdit" name="m_lpOutput"/>
|
||||
<widget class="cTextEdit" name="m_lpOutput"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@@ -83,6 +83,13 @@
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>cTextEdit</class>
|
||||
<extends>QTextEdit</extends>
|
||||
<header>ctextedit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "ctextedit.h"
|
||||
|
||||
#include <QMimeData>
|
||||
#include <QFileInfo>
|
||||
#include <QFile>
|
||||
#include <QImageReader>
|
||||
|
||||
|
||||
cTextEdit::cTextEdit(QWidget* parent) :
|
||||
QTextEdit(parent)
|
||||
{
|
||||
}
|
||||
|
||||
cTextEdit::cTextEdit(const QString& text, QWidget* parent) :
|
||||
QTextEdit(text, parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool cTextEdit::canInsertFromMimeData(const QMimeData* source) const
|
||||
{
|
||||
return source->hasImage() || source->hasUrls() || QTextEdit::canInsertFromMimeData(source);
|
||||
}
|
||||
|
||||
void cTextEdit::insertFromMimeData(const QMimeData* source)
|
||||
{
|
||||
if(source->hasImage())
|
||||
{
|
||||
static int i = 1;
|
||||
QUrl url(QString("dropped_image_%1").arg(i++));
|
||||
dropImage(url, qvariant_cast<QImage>(source->imageData()));
|
||||
}
|
||||
else if(source->hasUrls())
|
||||
{
|
||||
foreach(QUrl url, source->urls())
|
||||
{
|
||||
QFileInfo info(url.toLocalFile());
|
||||
if(QImageReader::supportedImageFormats().contains(info.suffix().toLower().toLatin1()))
|
||||
dropImage(url, QImage(info.filePath()));
|
||||
else
|
||||
dropTextFile(url);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextEdit::insertFromMimeData(source);
|
||||
}
|
||||
}
|
||||
|
||||
void cTextEdit::dropImage(const QUrl& url, const QImage& image)
|
||||
{
|
||||
if(!image.isNull())
|
||||
{
|
||||
document()->addResource(QTextDocument::ImageResource, url, image);
|
||||
textCursor().insertImage(url.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void cTextEdit::dropTextFile(const QUrl& url)
|
||||
{
|
||||
QFile file(url.toLocalFile());
|
||||
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
textCursor().insertText(file.readAll());
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#ifndef CTEXTEDIT_H
|
||||
#define CTEXTEDIT_H
|
||||
|
||||
|
||||
#include <QTextEdit>
|
||||
|
||||
|
||||
class cTextEdit : public QTextEdit
|
||||
{
|
||||
public:
|
||||
cTextEdit(QWidget* parent = Q_NULLPTR);
|
||||
cTextEdit(const QString& text, QWidget* parent = Q_NULLPTR);
|
||||
|
||||
bool canInsertFromMimeData(const QMimeData* source) const;
|
||||
void insertFromMimeData(const QMimeData* source);
|
||||
|
||||
private:
|
||||
void dropImage(const QUrl& url, const QImage& image);
|
||||
void dropTextFile(const QUrl& url);
|
||||
};
|
||||
|
||||
#endif // CTEXTEDIT_H
|
||||
+4
-3
@@ -41,7 +41,6 @@ win32-g++ {
|
||||
message("mingw")
|
||||
INCLUDEPATH += C:/dev/3rdParty/quazip/include
|
||||
DEPENDPATH += C:/dev/3rdParty/quazip/include
|
||||
#LIBS += -LC:/dev/3rdParty/quazip/gcc/lib -lquazip.a
|
||||
LIBS += -LC:/dev/3rdParty/quazip/gcc/lib -lquazip
|
||||
INCLUDEPATH += C:/dev/3rdParty/zlib/include
|
||||
DEPENDPATH += C:/dev/3rdParty/zlib/include
|
||||
@@ -59,14 +58,16 @@ SOURCES += \
|
||||
cdocumentreader.cpp \
|
||||
cdocumentwriter.cpp \
|
||||
ctextdocument.cpp \
|
||||
common.cpp
|
||||
common.cpp \
|
||||
ctextedit.cpp
|
||||
|
||||
HEADERS += \
|
||||
cmainwindow.h \
|
||||
cdocumentreader.h \
|
||||
cdocumentwriter.h \
|
||||
ctextdocument.h \
|
||||
common.h
|
||||
common.h \
|
||||
ctextedit.h
|
||||
|
||||
FORMS += \
|
||||
cmainwindow.ui
|
||||
|
||||
Reference in New Issue
Block a user