diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-07-30 18:06:31 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-07-30 18:06:31 +0200 |
commit | 2bf195a1f5cbf5f473cbbcc929ad64d675e829cb (patch) | |
tree | f5070a61bb505fb66413a95c817a952367ffc08d /framework | |
parent | 8dc99625d54dbe15816b4b4d0f6c87850289d30d (diff) | |
download | kube-2bf195a1f5cbf5f473cbbcc929ad64d675e829cb.tar.gz kube-2bf195a1f5cbf5f473cbbcc929ad64d675e829cb.zip |
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.
Diffstat (limited to 'framework')
-rw-r--r-- | framework/qml/TextEditor.qml | 17 | ||||
-rw-r--r-- | framework/src/domain/textdocumenthandler.cpp | 34 | ||||
-rw-r--r-- | framework/src/domain/textdocumenthandler.h | 1 |
3 files changed, 34 insertions, 18 deletions
diff --git a/framework/qml/TextEditor.qml b/framework/qml/TextEditor.qml index 7b1c5dee..45bf2ecd 100644 --- a/framework/qml/TextEditor.qml +++ b/framework/qml/TextEditor.qml | |||
@@ -34,21 +34,11 @@ FocusScope { | |||
34 | 34 | ||
35 | property string initialText | 35 | property string initialText |
36 | onInitialTextChanged: { | 36 | onInitialTextChanged: { |
37 | htmlEnabled = document.isHtml(initialText) | ||
38 | edit.text = initialText | 37 | edit.text = initialText |
39 | } | 38 | } |
40 | 39 | ||
41 | onHtmlEnabledChanged: { | 40 | function clearFormatting() { |
42 | if (htmlEnabled) { | 41 | document.resetFormat() |
43 | var t = document.htmlText | ||
44 | edit.textFormat = Qt.RichText | ||
45 | edit.text = t | ||
46 | } else { | ||
47 | var t = document.plainText | ||
48 | document.resetFormat() | ||
49 | edit.textFormat = Qt.PlainText | ||
50 | edit.text = t | ||
51 | } | ||
52 | } | 42 | } |
53 | 43 | ||
54 | Kube.TextDocumentHandler { | 44 | Kube.TextDocumentHandler { |
@@ -57,6 +47,7 @@ FocusScope { | |||
57 | selectionStart: edit.selectionStart | 47 | selectionStart: edit.selectionStart |
58 | selectionEnd: edit.selectionEnd | 48 | selectionEnd: edit.selectionEnd |
59 | onTextChanged: { | 49 | onTextChanged: { |
50 | root.htmlEnabled = containsFormatting(); | ||
60 | root.htmlEnabled ? root.text = htmlText : root.text = plainText | 51 | root.htmlEnabled ? root.text = htmlText : root.text = plainText |
61 | } | 52 | } |
62 | cursorPosition: edit.cursorPosition | 53 | cursorPosition: edit.cursorPosition |
@@ -105,7 +96,7 @@ FocusScope { | |||
105 | focus: true | 96 | focus: true |
106 | selectByMouse: true | 97 | selectByMouse: true |
107 | wrapMode: TextEdit.Wrap | 98 | wrapMode: TextEdit.Wrap |
108 | textFormat: Qt.PlainText | 99 | textFormat: Qt.RichText |
109 | onCursorRectangleChanged: flickableItem.ensureVisible(cursorRectangle) | 100 | onCursorRectangleChanged: flickableItem.ensureVisible(cursorRectangle) |
110 | 101 | ||
111 | color: Kube.Colors.textColor | 102 | color: Kube.Colors.textColor |
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) | |||
32 | { | 32 | { |
33 | } | 33 | } |
34 | 34 | ||
35 | bool TextDocumentHandler::containsFormatting() | ||
36 | { | ||
37 | if (mDocument) { | ||
38 | for (const auto &format : mDocument->textDocument()->allFormats()) { | ||
39 | switch(format.type()) { | ||
40 | case QTextFormat::CharFormat: { | ||
41 | const auto charFormat = format.toCharFormat(); | ||
42 | if (charFormat.fontWeight() != QFont::Normal) { | ||
43 | return true; | ||
44 | } | ||
45 | if (charFormat.fontItalic()) { | ||
46 | return true; | ||
47 | } | ||
48 | if (charFormat.fontUnderline()) { | ||
49 | return true; | ||
50 | } | ||
51 | break; | ||
52 | } | ||
53 | case QTextFormat::BlockFormat: | ||
54 | case QTextFormat::FrameFormat: | ||
55 | default: | ||
56 | break; | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | return false; | ||
61 | } | ||
62 | |||
35 | void TextDocumentHandler::resetFormat() | 63 | void TextDocumentHandler::resetFormat() |
36 | { | 64 | { |
37 | //Clear all formatting from the document. | 65 | mDocument->textDocument()->setPlainText(mDocument->textDocument()->toPlainText()); |
38 | auto cursor = textCursor(); | ||
39 | cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor); | ||
40 | cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); | ||
41 | cursor.setCharFormat({}); | ||
42 | mCachedTextFormat = {}; | 66 | mCachedTextFormat = {}; |
43 | reset(); | 67 | reset(); |
44 | } | 68 | } |
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: | |||
87 | void setFontSize(int size); | 87 | void setFontSize(int size); |
88 | 88 | ||
89 | Q_INVOKABLE void resetFormat(); | 89 | Q_INVOKABLE void resetFormat(); |
90 | Q_INVOKABLE bool containsFormatting(); | ||
90 | 91 | ||
91 | Q_INVOKABLE static bool isHtml(const QString &); | 92 | Q_INVOKABLE static bool isHtml(const QString &); |
92 | 93 | ||