diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-06-23 00:44:12 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-06-23 00:44:12 +0200 |
commit | 6025a2856ea086b9c226a08a4821bedcf29501d4 (patch) | |
tree | 6b289bc53157a9401b46cf44811dd2e0ae889614 /framework/qml/TextEditor.qml | |
parent | 4032ac6653ca910bb6ffa3aeaaa33dc6630600d4 (diff) | |
download | kube-6025a2856ea086b9c226a08a4821bedcf29501d4.tar.gz kube-6025a2856ea086b9c226a08a4821bedcf29501d4.zip |
Use the implcit flickable to simplify the code
Diffstat (limited to 'framework/qml/TextEditor.qml')
-rw-r--r-- | framework/qml/TextEditor.qml | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/framework/qml/TextEditor.qml b/framework/qml/TextEditor.qml index 9c2298b6..0ef91157 100644 --- a/framework/qml/TextEditor.qml +++ b/framework/qml/TextEditor.qml | |||
@@ -26,30 +26,24 @@ ScrollView { | |||
26 | id: root | 26 | id: root |
27 | property alias text: edit.text | 27 | property alias text: edit.text |
28 | 28 | ||
29 | Flickable { | 29 | horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff |
30 | id: flick | ||
31 | 30 | ||
32 | contentWidth: root.viewport.width | 31 | function ensureVisible(r) |
33 | contentHeight: Math.max(edit.contentHeight + edit.topPadding + edit.bottomPadding, flick.height) | 32 | { |
34 | clip: true | 33 | if (flickableItem.contentY >= r.y) |
35 | 34 | flickableItem.contentY = r.y; | |
36 | function ensureVisible(r) | 35 | else if (flickableItem.contentY + height <= r.y + r.height) |
37 | { | 36 | flickableItem.contentY = r.y + r.height - height + edit.padding; |
38 | if (contentY >= r.y) | 37 | } |
39 | contentY = r.y; | ||
40 | else if (contentY + height <= r.y + r.height) | ||
41 | contentY = r.y+r.height-height; | ||
42 | } | ||
43 | 38 | ||
44 | Kube.TextArea { | 39 | Kube.TextArea { |
45 | //TODO drop all sizes and use the following once we have qt 5.9 | 40 | //TODO drop all sizes and use the following once we have qt 5.9 |
46 | // Controls2.TextArea.flickable: Kube.TextArea { | 41 | // Controls2.TextArea.flickable: Kube.TextArea { |
47 | id: edit | 42 | id: edit |
48 | width: flick.contentWidth - edit.leftPadding - edit.rightPadding | 43 | width: root.viewport.width |
49 | height: flick.contentHeight | 44 | height: Math.max(edit.contentHeight + edit.topPadding + edit.bottomPadding, root.height) |
50 | selectByMouse: true | 45 | selectByMouse: true |
51 | onCursorRectangleChanged: flick.ensureVisible(cursorRectangle) | 46 | onCursorRectangleChanged: root.ensureVisible(cursorRectangle) |
52 | wrapMode: TextEdit.Wrap | 47 | wrapMode: TextEdit.Wrap |
53 | } | ||
54 | } | 48 | } |
55 | } | 49 | } |