on xenial help sign in
Create a generic ListViewOSKScroller
commita9f41f1f4df95eb1d1ccb2d4772c0c45d191375c authorAlbert Astals Cid <albert.astals@canonical.com> dateMon 19 Oct 2015, 12:51 (11 years ago) parent289ccd8
3 files changed+66−30
qml/Components/ListViewOSKScroller.qml+53 qml/Dash/Previews/Preview.qml+9−16 qml/Dash/ScopeSettingsPage.qml+4−14
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 @@
1616
1717import QtQuick 2.0
1818import Ubuntu.Components 0.1
19+import "../../Components"
1920
2021/*! \brief This component constructs the Preview UI.
2122 *
@@ -72,18 +73,10 @@ Item {
7273 }
7374 width: row.columnWidth
7475 spacing: row.spacing
75− bottomMargin: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
76− property var makeSureVisibleItem
77− property real previousVisibleHeight: 0
78− property real visibleHeight: height - bottomMargin
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;
76+
77+ ListViewOSKScroller {
78+ id: oskScroller
79+ list: column
8780 }
8881
8982 model: columnModel
@@ -107,10 +100,10 @@ Item {
107100 onTriggered: {
108101 previewModel.triggered(widgetId, actionId, data);
109102 }
110− onMakeSureVisible: {
111− column.previousVisibleHeight=column.visibleHeight
112− column.makeSureVisibleItem=item
113− }
103+
104+ onMakeSureVisible: {
105+ oskScroller.setMakeSureVisibleItem(item);
106+ }
114107
115108 onFocusChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
116109
qml/Dash/ScopeSettingsPage.qml+4−14
@@ -50,19 +50,10 @@ Item {
5050 }
5151 model: root.scope ? root.scope.settings : null
5252 clip: true
53− bottomMargin: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
5453
55− property var makeSureVisibleItem
56− property real previousVisibleHeight: 0
57− readonly property real visibleHeight: height - bottomMargin
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;
54+ ListViewOSKScroller {
55+ id: oskScroller
56+ list: scopeSettings
6657 }
6758
6859 delegate: ScopeSettingsWidgetFactory {
@@ -74,8 +65,7 @@ Item {
7465 onUpdated: model.value = value;
7566
7667 onMakeSureVisible: { // var item
77− scopeSettings.previousVisibleHeight = scopeSettings.visibleHeight;
78− scopeSettings.makeSureVisibleItem = item;
68+ oskScroller.setMakeSureVisibleItem(item);
7969 }
8070 }
8171 }