From bc6ac986dc9dde942b0a9185940e748c3a0e87c9 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 1 Jul 2018 10:00:11 +0200 Subject: Enable HTML mode when loading an html message. --- framework/qml/TextEditor.qml | 5 ++++- framework/src/domain/textdocumenthandler.cpp | 6 ++++++ framework/src/domain/textdocumenthandler.h | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) (limited to 'framework') diff --git a/framework/qml/TextEditor.qml b/framework/qml/TextEditor.qml index e5cc665c..7b1c5dee 100644 --- a/framework/qml/TextEditor.qml +++ b/framework/qml/TextEditor.qml @@ -34,6 +34,7 @@ FocusScope { property string initialText onInitialTextChanged: { + htmlEnabled = document.isHtml(initialText) edit.text = initialText } @@ -55,7 +56,9 @@ FocusScope { document: edit.textDocument selectionStart: edit.selectionStart selectionEnd: edit.selectionEnd - onTextChanged: root.htmlEnabled ? root.text = htmlText : root.text = plainText + onTextChanged: { + root.htmlEnabled ? root.text = htmlText : root.text = plainText + } cursorPosition: edit.cursorPosition } diff --git a/framework/src/domain/textdocumenthandler.cpp b/framework/src/domain/textdocumenthandler.cpp index 6c2bc323..ea312282 100644 --- a/framework/src/domain/textdocumenthandler.cpp +++ b/framework/src/domain/textdocumenthandler.cpp @@ -289,3 +289,9 @@ void TextDocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &fo } } } + + +bool TextDocumentHandler::isHtml(const QString &text) +{ + return Qt::mightBeRichText(text); +} diff --git a/framework/src/domain/textdocumenthandler.h b/framework/src/domain/textdocumenthandler.h index 91cd8489..38de917d 100644 --- a/framework/src/domain/textdocumenthandler.h +++ b/framework/src/domain/textdocumenthandler.h @@ -88,6 +88,8 @@ public: Q_INVOKABLE void resetFormat(); + Q_INVOKABLE static bool isHtml(const QString &); + Q_SIGNALS: void documentChanged(); void cursorPositionChanged(); -- cgit v1.2.3