From 44f1baac26944c1c5061fadf163846958095a425 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 3 Oct 2017 10:01:55 +0200 Subject: A working Html TextEditor It's just the TextArea that is broken, it seems the TextEdit works fine with html content. --- framework/qml/TextArea.qml | 39 --------------------------------- framework/qml/TextEditor.qml | 51 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 48 deletions(-) delete mode 100644 framework/qml/TextArea.qml (limited to 'framework/qml') diff --git a/framework/qml/TextArea.qml b/framework/qml/TextArea.qml deleted file mode 100644 index 1f968560..00000000 --- a/framework/qml/TextArea.qml +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2017 Michael Bohlender, - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -import QtQuick 2.7 -import QtQuick.Templates 2.0 as T - -import org.kube.framework 1.0 as Kube - -T.TextArea { - id: root - - padding: Kube.Units.smallSpacing + 1 //(boder width) - - color: Kube.Colors.textColor - selectionColor: Kube.Colors.highlightColor - selectedTextColor: Kube.Colors.highlightedTextColor - - background: Rectangle { - color: Kube.Colors.viewBackgroundColor - border.width: 1 - border.color: root.activeFocus ? Kube.Colors.highlightColor : Kube.Colors.buttonColor - } -} diff --git a/framework/qml/TextEditor.qml b/framework/qml/TextEditor.qml index e14e60b0..570bc322 100644 --- a/framework/qml/TextEditor.qml +++ b/framework/qml/TextEditor.qml @@ -18,7 +18,7 @@ */ import QtQuick 2.7 -import QtQuick.Controls 2.2 +import QtQuick.Controls 2 import org.kube.framework 1.0 as Kube @@ -44,29 +44,62 @@ FocusScope { document: edit.textDocument selectionStart: edit.selectionStart selectionEnd: edit.selectionEnd - //textColor: colorDialog.color onTextChanged: root.htmlEnabled ? root.text = htmlText : root.text = plainText - cursorPosition: edit.cursorPosition } - Kube.ScrollHelper { + + Rectangle { anchors.fill: parent - flickable: flickableItem + border.width: 1 + border.color: root.activeFocus ? Kube.Colors.highlightColor : Kube.Colors.buttonColor + color: Kube.Colors.viewBackgroundColor + Flickable { id: flickableItem anchors.fill: parent ScrollBar.vertical: Kube.ScrollBar {} + clip: true + + Kube.ScrollHelper { + anchors.fill: parent + flickable: flickableItem + } + + contentWidth: edit.paintedWidth + contentHeight: edit.paintedHeight - Kube.TextArea { + function ensureVisible(r) { + if (contentX >= r.x) { + contentX = r.x + } else if (contentX+width <= r.x+r.width) { + contentX = r.x+r.width-width; + } + if (contentY >= r.y) { + contentY = r.y; + } else if (contentY+height <= r.y+r.height) { + contentY = r.y+r.height-height; + } + } + + + TextEdit { id: edit + + width: flickableItem.width + height: flickableItem.height + focus: true - anchors.fill: parent selectByMouse: true - wrapMode: TextEdit.Wrap + wrapMode: TextEdit.WordWrap textFormat: root.htmlEnabled ? Qt.RichText : Qt.PlainText + onCursorRectangleChanged: flickableItem.ensureVisible(cursorRectangle) + + color: Kube.Colors.textColor + font.family: Kube.Font.fontFamily + selectionColor: Kube.Colors.highlightColor + padding: Kube.Units.smallSpacing } - TextArea.flickable: edit } } } -- cgit v1.2.3