on xenial help sign in
Make the scope settings list scroll to text visible area
abba1e3Albert 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.4
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 1.3
18import Ubuntu.Components 1.3
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/ScopeSettings/ScopeSetting.qml+9
@@ -32,6 +32,15 @@ Item {
32 */
32 */
33 signal updated(var value)
33 signal updated(var value)
34
34
35+ /*! \brief This signal should be emitted when widget gains the focus
36+ * and input method popups.
37+ * And preview widget should reposition in visible area to avoid
38+ * keyboard appears over the widget.
39+ *
40+ * \param item, id of specified item which is needed to reposition.
41+ */
42+ signal makeSureVisible(var item)
43+
35 //! \internal
44 //! \internal
36 readonly property real settingMargins: units.gu(2)
45 readonly property real settingMargins: units.gu(2)
37}
46}
qml/Dash/ScopeSettings/ScopeSettingString.qml+6
@@ -78,6 +78,12 @@ ScopeSetting {
78 updateText();
78 updateText();
79 }
79 }
80 }
80 }
81+
82+ readonly property bool inputMethodVisible: Qt.inputMethod.visible
83+ onInputMethodVisibleChanged: {
84+ if(inputMethodVisible && activeFocus)
85+ root.makeSureVisible(control);
86+ }
81 }
87 }
82 }
88 }
83}
89}
qml/Dash/ScopeSettings/ScopeSettingsWidgetFactory.qml+4
@@ -30,6 +30,9 @@ Loader {
30 //! Triggered signal forwarded from the widgets.
30 //! Triggered signal forwarded from the widgets.
31 signal updated(var value)
31 signal updated(var value)
32
32
33+ //! makeSureVisible signal forwarded from the widgets.
34+ signal makeSureVisible(var item)
35+
33 source: widgetSource
36 source: widgetSource
34
37
35 //! \cond private
38 //! \cond private
@@ -53,5 +56,6 @@ Loader {
53 Connections {
56 Connections {
54 target: root.item
57 target: root.item
55 onUpdated: if (value !== widgetData.value) root.updated(value)
58 onUpdated: if (value !== widgetData.value) root.updated(value)
59+ onMakeSureVisible: root.makeSureVisible(item)
56 }
60 }
57}
61}
qml/Dash/ScopeSettingsPage.qml+9
@@ -51,6 +51,11 @@ Item {
51 model: root.scope ? root.scope.settings : null
51 model: root.scope ? root.scope.settings : null
52 clip: true
52 clip: true
53
53
54+ ListViewOSKScroller {
55+ id: oskScroller
56+ list: scopeSettings
57+ }
58+
54 delegate: ScopeSettingsWidgetFactory {
59 delegate: ScopeSettingsWidgetFactory {
55 objectName: "scopeSettingItem" + index
60 objectName: "scopeSettingItem" + index
56 width: root.width
61 width: root.width
@@ -58,6 +63,10 @@ Item {
58 scopeStyle: root.scopeStyle
63 scopeStyle: root.scopeStyle
59
64
60 onUpdated: model.value = value;
65 onUpdated: model.value = value;
66+
67+ onMakeSureVisible: { // var item
68+ oskScroller.setMakeSureVisibleItem(item);
69+ }
61 }
70 }
62 }
71 }
63}
72}