summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-07-30 18:06:31 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-07-30 18:06:31 +0200
commit2bf195a1f5cbf5f473cbbcc929ad64d675e829cb (patch)
treef5070a61bb505fb66413a95c817a952367ffc08d
parent8dc99625d54dbe15816b4b4d0f6c87850289d30d (diff)
downloadkube-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.
-rw-r--r--framework/qml/TextEditor.qml17
-rw-r--r--framework/src/domain/textdocumenthandler.cpp34
-rw-r--r--framework/src/domain/textdocumenthandler.h1
-rw-r--r--views/composer/qml/View.qml19
4 files changed, 40 insertions, 31 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
35bool 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
35void TextDocumentHandler::resetFormat() 63void 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
diff --git a/views/composer/qml/View.qml b/views/composer/qml/View.qml
index 1c08dda6..117c8e01 100644
--- a/views/composer/qml/View.qml
+++ b/views/composer/qml/View.qml
@@ -303,19 +303,7 @@ Kube.View {
303 303
304 spacing: Kube.Units.largeSpacing 304 spacing: Kube.Units.largeSpacing
305 305
306 Kube.Switch {
307 id: html
308 text: checked ? qsTr("plain") : qsTr("html")
309 focusPolicy: Qt.TabFocus
310 focus: false
311 checked: false
312 onCheckedChanged: {
313 textEditor.htmlEnabled = checked
314 }
315 }
316
317 Row { 306 Row {
318 visible: html.checked
319 spacing: 1 307 spacing: 1
320 308
321 Kube.IconButton { 309 Kube.IconButton {
@@ -342,6 +330,12 @@ Kube.View {
342 focusPolicy: Qt.TabFocus 330 focusPolicy: Qt.TabFocus
343 focus: false 331 focus: false
344 } 332 }
333 Kube.TextButton {
334 id: deleteButton
335 text: qsTr("Remove Formatting")
336 visible: textEditor.htmlEnabled
337 onClicked: textEditor.clearFormatting()
338 }
345 } 339 }
346 340
347 Item { 341 Item {
@@ -379,7 +373,6 @@ Kube.View {
379 Layout.fillWidth: true 373 Layout.fillWidth: true
380 Layout.fillHeight: true 374 Layout.fillHeight: true
381 onHtmlEnabledChanged: { 375 onHtmlEnabledChanged: {
382 html.checked = htmlEnabled
383 composerController.htmlBody = htmlEnabled; 376 composerController.htmlBody = htmlEnabled;
384 } 377 }
385 378