From 8edb362d96ed740cf5f387649d760c17c7c17d31 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 13 Sep 2017 11:01:42 +0200 Subject: Keep TextEditor as our html editor --- components/kube/contents/ui/ComposerView.qml | 41 ++++++++++++---------------- framework/qml/TextEditor.qml | 30 +++++++++++++++++++- framework/src/domain/documenthandler.cpp | 16 +++++++---- framework/src/domain/documenthandler.h | 3 -- 4 files changed, 56 insertions(+), 34 deletions(-) diff --git a/components/kube/contents/ui/ComposerView.qml b/components/kube/contents/ui/ComposerView.qml index 1571a746..29858767 100644 --- a/components/kube/contents/ui/ComposerView.qml +++ b/components/kube/contents/ui/ComposerView.qml @@ -287,24 +287,24 @@ Kube.View { Kube.IconButton { iconName: Kube.Icons.bold checkable: true - checked: document.bold - onClicked: document.bold = !document.bold + checked: textEditor.bold + onClicked: textEditor.bold = !textEditor.bold focusPolicy: Qt.TabFocus focus: false } Kube.IconButton { iconName: Kube.Icons.italic checkable: true - checked: document.italic - onClicked: document.italic = !document.italic + checked: textEditor.italic + onClicked: textEditor.italic = !textEditor.italic focusPolicy: Qt.TabFocus focus: false } Kube.IconButton { iconName: Kube.Icons.underline checkable: true - checked: document.underline - onClicked: document.underline = !document.underline + checked: textEditor.underline + onClicked: textEditor.underline = !textEditor.underline focusPolicy: Qt.TabFocus focus: false } @@ -337,31 +337,24 @@ Kube.View { } } - Kube.DocumentHandler { - id: document - document: textEditor.textDocument - cursorPosition: textEditor.cursorPosition - selectionStart: textEditor.selectionStart - selectionEnd: textEditor.selectionEnd - //textColor: colorDialog.color - } - - Kube.TextArea { + Kube.TextEditor { id: textEditor Layout.fillWidth: true Layout.fillHeight: true - - textFormat: Qt.RichText - wrapMode: TextArea.Wrap - focus: true - selectByMouse: true - persistentSelection: true + htmlEnabled: html.checked onActiveFocusChanged: closeFirstSplitIfNecessary() Keys.onEscapePressed: recipients.forceActiveFocus() - cursorPosition: document.cursorPosition - text: composerController.body + initialText: composerController.body + /** + * We need to: + * * initially load the text from the controller (for replies and whatnot) + * * Then only read from documenthandler in either html or plain (depending on the format). + * * Convert between html and plain when switching the format. + * * Skip invisible chars + * * Remove invisible chars from copied text somehow + */ onTextChanged: composerController.body = text; } } diff --git a/framework/qml/TextEditor.qml b/framework/qml/TextEditor.qml index 5f29cef3..047c9b77 100644 --- a/framework/qml/TextEditor.qml +++ b/framework/qml/TextEditor.qml @@ -23,7 +23,32 @@ import QtQuick.Controls 2.2 import org.kube.framework 1.0 as Kube FocusScope { - property alias text: edit.text + id: root + property string text: "" + + property bool htmlEnabled: false + + property alias bold: document.bold + property alias italic: document.italic + property alias underline: document.underline + + property string initialText + onInitialTextChanged: { + if (text == "") { + edit.text = initialText + } + } + + Kube.DocumentHandler { + id: document + document: edit.textDocument + cursorPosition: edit.cursorPosition + selectionStart: edit.selectionStart + selectionEnd: edit.selectionEnd + //textColor: colorDialog.color + onTextChanged: root.text = text + } + Kube.ScrollHelper { anchors.fill: parent flickable: flickableItem @@ -37,7 +62,10 @@ FocusScope { focus: true anchors.fill: parent selectByMouse: true + persistentSelection: true wrapMode: TextEdit.Wrap + textFormat: Qt.RichText + cursorPosition: document.cursorPosition } TextArea.flickable: edit } diff --git a/framework/src/domain/documenthandler.cpp b/framework/src/domain/documenthandler.cpp index 266f4a27..0f949da8 100644 --- a/framework/src/domain/documenthandler.cpp +++ b/framework/src/domain/documenthandler.cpp @@ -94,16 +94,20 @@ void DocumentHandler::setCursorPosition(int position) //Skip over invisible char if (m_cursorPosition < position) { auto cursor = textCursor(); - cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); - if (cursor.selectedText() == "\u2063") { - position++; + if (!cursor.atEnd()) { + cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); + if (cursor.selectedText() == "\u2063") { + position++; + } } } if (m_cursorPosition > position) { auto cursor = textCursor(); - cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor); - if (cursor.selectedText() == "\u2063") { - position--; + if (!cursor.atStart()) { + cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor); + if (cursor.selectedText() == "\u2063") { + position--; + } } } m_cursorPosition = position; diff --git a/framework/src/domain/documenthandler.h b/framework/src/domain/documenthandler.h index 74b7c4f9..24b3b35f 100644 --- a/framework/src/domain/documenthandler.h +++ b/framework/src/domain/documenthandler.h @@ -145,9 +145,6 @@ private: int m_cursorPosition; int m_selectionStart; int m_selectionEnd; - - QFont m_font; - int m_fontSize; }; #endif // DOCUMENTHANDLER_H -- cgit v1.2.3