on xenial help sign in
Create a generic ListViewOSKScroller
a9f41f1Albert Astals Cid
qml/Components/ListViewOSKScroller.qmlnew file+53
@@ -0,0 +1,53 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.2
18+import "../Components"
19+
20+Item {
21+ id: root
22+
23+ property ListView list
24+
25+ Binding {
26+ target: list
27+ property: "bottomMargin"
28+ value: d.bottomMargin
29+ }
30+
31+ function setMakeSureVisibleItem(item) {
32+ d.previousVisibleHeight = d.visibleHeight;
33+ d.makeSureVisibleItem = item;
34+ }
35+
36+ QtObject {
37+ id: d
38+ property var makeSureVisibleItem
39+ property real previousVisibleHeight: 0
40+ readonly property real visibleHeight: list.height - list.bottomMargin
41+ readonly property real bottomMargin: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
42+
43+ onVisibleHeightChanged: {
44+ if (makeSureVisibleItem && makeSureVisibleItem.activeFocus && previousVisibleHeight > visibleHeight) {
45+ var textAreaPos = makeSureVisibleItem.mapToItem(list, 0, 0);
46+ if (textAreaPos.y + makeSureVisibleItem.height > visibleHeight) {
47+ list.contentY += textAreaPos.y + makeSureVisibleItem.height - visibleHeight
48+ }
49+ }
50+ previousVisibleHeight = visibleHeight;
51+ }
52+ }
53+}
qml/Dash/Previews/Preview.qml+9−16
@@ -16,6 +16,7 @@
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18import Ubuntu.Components 0.1
18import Ubuntu.Components 0.1
19+import "../../Components"
19
20
20/*! \brief This component constructs the Preview UI.
21/*! \brief This component constructs the Preview UI.
21 *
22 *
@@ -72,18 +73,10 @@ Item {
72 }
73 }
73 width: row.columnWidth
74 width: row.columnWidth
74 spacing: row.spacing
75 spacing: row.spacing
75− bottomMargin: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
76+
76− property var makeSureVisibleItem
77+ ListViewOSKScroller {
77− property real previousVisibleHeight: 0
78+ id: oskScroller
78− property real visibleHeight: height - bottomMargin
79+ list: column
79− onVisibleHeightChanged: {
80− if (makeSureVisibleItem && makeSureVisibleItem.activeFocus && previousVisibleHeight > visibleHeight) {
81− var textAreaPos = makeSureVisibleItem.mapToItem(column, 0, 0);
82− if (textAreaPos.y + makeSureVisibleItem.height > column.visibleHeight) {
83− column.contentY += textAreaPos.y + makeSureVisibleItem.height - column.visibleHeight
84− }
85− }
86− previousVisibleHeight = visibleHeight;
87 }
80 }
88
81
89 model: columnModel
82 model: columnModel
@@ -107,10 +100,10 @@ Item {
107 onTriggered: {
100 onTriggered: {
108 previewModel.triggered(widgetId, actionId, data);
101 previewModel.triggered(widgetId, actionId, data);
109 }
102 }
103+
110− onMakeSureVisible: {
104+ onMakeSureVisible: {
111− column.previousVisibleHeight=column.visibleHeight
105+ oskScroller.setMakeSureVisibleItem(item);
112− column.makeSureVisibleItem=item
113− }
106+ }
114
107
115 onFocusChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
108 onFocusChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
116
109
qml/Dash/ScopeSettingsPage.qml+4−14
@@ -50,19 +50,10 @@ Item {
50 }
50 }
51 model: root.scope ? root.scope.settings : null
51 model: root.scope ? root.scope.settings : null
52 clip: true
52 clip: true
53− bottomMargin: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
54
53
55− property var makeSureVisibleItem
54+ ListViewOSKScroller {
56− property real previousVisibleHeight: 0
55+ id: oskScroller
57− readonly property real visibleHeight: height - bottomMargin
56+ list: scopeSettings
58− onVisibleHeightChanged: {
59− if (makeSureVisibleItem && makeSureVisibleItem.activeFocus && previousVisibleHeight > visibleHeight) {
60− var textAreaPos = makeSureVisibleItem.mapToItem(scopeSettings, 0, 0);
61− if (textAreaPos.y + makeSureVisibleItem.height > scopeSettings.visibleHeight) {
62− scopeSettings.contentY += textAreaPos.y + makeSureVisibleItem.height - scopeSettings.visibleHeight
63− }
64− }
65− previousVisibleHeight = visibleHeight;
66 }
57 }
67
58
68 delegate: ScopeSettingsWidgetFactory {
59 delegate: ScopeSettingsWidgetFactory {
@@ -74,8 +65,7 @@ Item {
74 onUpdated: model.value = value;
65 onUpdated: model.value = value;
75
66
76 onMakeSureVisible: { // var item
67 onMakeSureVisible: { // var item
77− scopeSettings.previousVisibleHeight = scopeSettings.visibleHeight;
68+ oskScroller.setMakeSureVisibleItem(item);
78− scopeSettings.makeSureVisibleItem = item;
79 }
69 }
80 }
70 }
81 }
71 }