diff options
Diffstat (limited to 'framework/qml/TextEditor.qml')
-rw-r--r-- | framework/qml/TextEditor.qml | 56 |
1 files changed, 56 insertions, 0 deletions
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 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 Michael Bohlender, <michael.bohlender@kdemail.net> | ||
3 | * Copyright (C) 2017 Christian Mollekopf, <mollekopf@kolabsys.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License along | ||
16 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | import QtQuick 2.7 | ||
21 | import QtQuick.Controls 1.3 | ||
22 | |||
23 | import org.kube.framework 1.0 as Kube | ||
24 | |||
25 | ScrollView { | ||
26 | id: root | ||
27 | property alias text: edit.text | ||
28 | |||
29 | Flickable { | ||
30 | id: flick | ||
31 | |||
32 | contentWidth: root.viewport.width | ||
33 | contentHeight: edit.height | ||
34 | clip: true | ||
35 | |||
36 | function ensureVisible(r) | ||
37 | { | ||
38 | if (contentX >= r.x) | ||
39 | contentX = r.x; | ||
40 | else if (contentX + width <= r.x + r.width) | ||
41 | contentX = r.x+r.width-width; | ||
42 | if (contentY >= r.y) | ||
43 | contentY = r.y; | ||
44 | else if (contentY + height <= r.y + r.height) | ||
45 | contentY = r.y+r.height-height; | ||
46 | } | ||
47 | |||
48 | Kube.TextArea { | ||
49 | id: edit | ||
50 | width: flick.width | ||
51 | height: edit.contentHeight > flick.height ? edit.contentHeight : flick.height | ||
52 | selectByMouse: true | ||
53 | onCursorRectangleChanged: flick.ensureVisible(cursorRectangle) | ||
54 | } | ||
55 | } | ||
56 | } | ||