From 36271954aada008d4ea91df79ee4cc11b750274f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 19 Jun 2017 17:28:25 +0200 Subject: A texteditor that does scrolling Something is not quite right with the sizes, but at least it works otherwise. --- components/kube/contents/ui/ComposerView.qml | 8 +--- framework/qml/TextEditor.qml | 56 ++++++++++++++++++++++++++++ framework/qmldir | 1 + 3 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 framework/qml/TextEditor.qml diff --git a/components/kube/contents/ui/ComposerView.qml b/components/kube/contents/ui/ComposerView.qml index b8da8a83..7bc3b061 100644 --- a/components/kube/contents/ui/ComposerView.qml +++ b/components/kube/contents/ui/ComposerView.qml @@ -297,16 +297,12 @@ Kube.View { } } - Kube.TextArea { - id: content + Kube.TextEditor { Layout.fillWidth: true Layout.fillHeight: true - - selectByMouse: true - + onActiveFocusChanged: closeFirstSplitIfNecessary() text: composerController.body onTextChanged: composerController.body = text; - onActiveFocusChanged: closeFirstSplitIfNecessary() } } } diff --git a/framework/qml/TextEditor.qml b/framework/qml/TextEditor.qml new file mode 100644 index 00000000..c21f3748 --- /dev/null +++ b/framework/qml/TextEditor.qml @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2017 Michael Bohlender, + * Copyright (C) 2017 Christian Mollekopf, + * + * 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.Controls 1.3 + +import org.kube.framework 1.0 as Kube + +ScrollView { + id: root + property alias text: edit.text + + Flickable { + id: flick + + contentWidth: root.viewport.width + contentHeight: edit.height + clip: true + + 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; + } + + Kube.TextArea { + id: edit + width: flick.width + height: edit.contentHeight > flick.height ? edit.contentHeight : flick.height + selectByMouse: true + onCursorRectangleChanged: flick.ensureVisible(cursorRectangle) + } + } +} diff --git a/framework/qmldir b/framework/qmldir index 74f8a4af..4328548b 100644 --- a/framework/qmldir +++ b/framework/qmldir @@ -23,6 +23,7 @@ ComboBox 1.0 ComboBox.qml PositiveButton 1.0 PositiveButton.qml TextField 1.0 TextField.qml TextArea 1.0 TextArea.qml +TextEditor 1.0 TextEditor.qml Label 1.0 Label.qml View 1.0 View.qml AutocompleteLineEdit 1.0 AutocompleteLineEdit.qml -- cgit v1.2.3