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 --- framework/qml/TextEditor.qml | 30 +++++++++++++++++++++++++++++- framework/src/domain/documenthandler.cpp | 16 ++++++++++------ framework/src/domain/documenthandler.h | 3 --- 3 files changed, 39 insertions(+), 10 deletions(-) (limited to 'framework') 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