From 2bf195a1f5cbf5f473cbbcc929ad64d675e829cb Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 30 Jul 2018 18:06:31 +0200 Subject: Removed the html switch. Instead of having a switch we're going to always use an html editor, and simply send as plaintext if there is no formatting. To easily remove all formatting a button is added. --- framework/src/domain/textdocumenthandler.cpp | 34 ++++++++++++++++++++++++---- framework/src/domain/textdocumenthandler.h | 1 + 2 files changed, 30 insertions(+), 5 deletions(-) (limited to 'framework/src/domain') diff --git a/framework/src/domain/textdocumenthandler.cpp b/framework/src/domain/textdocumenthandler.cpp index ea312282..f0cde10d 100644 --- a/framework/src/domain/textdocumenthandler.cpp +++ b/framework/src/domain/textdocumenthandler.cpp @@ -32,13 +32,37 @@ TextDocumentHandler::TextDocumentHandler(QObject *parent) { } +bool TextDocumentHandler::containsFormatting() +{ + if (mDocument) { + for (const auto &format : mDocument->textDocument()->allFormats()) { + switch(format.type()) { + case QTextFormat::CharFormat: { + const auto charFormat = format.toCharFormat(); + if (charFormat.fontWeight() != QFont::Normal) { + return true; + } + if (charFormat.fontItalic()) { + return true; + } + if (charFormat.fontUnderline()) { + return true; + } + break; + } + case QTextFormat::BlockFormat: + case QTextFormat::FrameFormat: + default: + break; + } + } + } + return false; +} + void TextDocumentHandler::resetFormat() { - //Clear all formatting from the document. - auto cursor = textCursor(); - cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor); - cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); - cursor.setCharFormat({}); + mDocument->textDocument()->setPlainText(mDocument->textDocument()->toPlainText()); mCachedTextFormat = {}; reset(); } diff --git a/framework/src/domain/textdocumenthandler.h b/framework/src/domain/textdocumenthandler.h index 38de917d..cb4d4e29 100644 --- a/framework/src/domain/textdocumenthandler.h +++ b/framework/src/domain/textdocumenthandler.h @@ -87,6 +87,7 @@ public: void setFontSize(int size); Q_INVOKABLE void resetFormat(); + Q_INVOKABLE bool containsFormatting(); Q_INVOKABLE static bool isHtml(const QString &); -- cgit v1.2.3