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 ++ views/composer/main.qml | 9 +++++++++ views/composer/qml/View.qml | 13 ++++++++++--- 5 files changed, 31 insertions(+), 4 deletions(-) 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(); diff --git a/views/composer/main.qml b/views/composer/main.qml index 6c7fd581..a7f72880 100644 --- a/views/composer/main.qml +++ b/views/composer/main.qml @@ -76,6 +76,15 @@ ApplicationWindow { cc: ["ccLoooooooooooooooooooooooooooooooooooooooooooooooooong@example.org"], bcc: ["bccLoooooooooooooooooooooooooooooooooooooooooooooooooong@example.org"], draft: true + }, + { + resource: "resource1", + messageId: "", + date: "2017-07-23T16:46:29", + subject: "HTML", + body: "

body

", + to: ["html@example.org"], + draft: true } ] }], diff --git a/views/composer/qml/View.qml b/views/composer/qml/View.qml index 9afc5316..ffab3545 100644 --- a/views/composer/qml/View.qml +++ b/views/composer/qml/View.qml @@ -36,7 +36,6 @@ Kube.View { resources: [ Kube.ComposerController { id: composerController - htmlBody: html.checked sign: signCheckbox.checked encrypt: encryptCheckbox.checked onDone: root.done() @@ -305,6 +304,9 @@ Kube.View { focusPolicy: Qt.TabFocus focus: false checked: false + onCheckedChanged: { + textEditor.htmlEnabled = checked + } } Row { @@ -369,12 +371,17 @@ Kube.View { Layout.fillWidth: true Layout.fillHeight: true - htmlEnabled: html.checked + onHtmlEnabledChanged: { + html.checked = htmlEnabled + composerController.htmlBody = htmlEnabled; + } onActiveFocusChanged: closeFirstSplitIfNecessary() Keys.onEscapePressed: recipients.forceActiveFocus() initialText: composerController.body - onTextChanged: composerController.body = text; + onTextChanged: { + composerController.body = text; + } } } } -- cgit v1.2.3