on xenial help sign in
Make the scope settings list scroll to text visible area

Fixes: #1499084 Approved by: Michael Terry

commitabba1e3fd43e3799873592dbe88bad67d076d086 authorAlbert Astals Cid <albert.astals@canonical.com> dateWed 4 Nov 2015, 14:57 (11 years ago) parent95cf8bd160c2a1
6 files changed+90−16
qml/Components/ListViewOSKScroller.qml+53 qml/Dash/Previews/Preview.qml+9−16 qml/Dash/ScopeSettings/ScopeSetting.qml+9 qml/Dash/ScopeSettings/ScopeSettingString.qml+6 qml/Dash/ScopeSettings/ScopeSettingsWidgetFactory.qml+4 qml/Dash/ScopeSettingsPage.qml+9
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 @@
1616
1717import QtQuick 2.0
1818import Ubuntu.Components 1.3
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/ScopeSettings/ScopeSetting.qml+9
@@ -32,6 +32,15 @@ Item {
3232 */
3333 signal updated(var value)
3434
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+
3544 //! \internal
3645 readonly property real settingMargins: units.gu(2)
3746}
qml/Dash/ScopeSettings/ScopeSettingString.qml+6
@@ -78,6 +78,12 @@ ScopeSetting {
7878 updateText();
7979 }
8080 }
81+
82+ readonly property bool inputMethodVisible: Qt.inputMethod.visible
83+ onInputMethodVisibleChanged: {
84+ if(inputMethodVisible && activeFocus)
85+ root.makeSureVisible(control);
86+ }
8187 }
8288 }
8389}
qml/Dash/ScopeSettings/ScopeSettingsWidgetFactory.qml+4
@@ -30,6 +30,9 @@ Loader {
3030 //! Triggered signal forwarded from the widgets.
3131 signal updated(var value)
3232
33+ //! makeSureVisible signal forwarded from the widgets.
34+ signal makeSureVisible(var item)
35+
3336 source: widgetSource
3437
3538 //! \cond private
@@ -53,5 +56,6 @@ Loader {
5356 Connections {
5457 target: root.item
5558 onUpdated: if (value !== widgetData.value) root.updated(value)
59+ onMakeSureVisible: root.makeSureVisible(item)
5660 }
5761}
qml/Dash/ScopeSettingsPage.qml+9
@@ -51,6 +51,11 @@ Item {
5151 model: root.scope ? root.scope.settings : null
5252 clip: true
5353
54+ ListViewOSKScroller {
55+ id: oskScroller
56+ list: scopeSettings
57+ }
58+
5459 delegate: ScopeSettingsWidgetFactory {
5560 objectName: "scopeSettingItem" + index
5661 width: root.width
@@ -58,6 +63,10 @@ Item {
5863 scopeStyle: root.scopeStyle
5964
6065 onUpdated: model.value = value;
66+
67+ onMakeSureVisible: { // var item
68+ oskScroller.setMakeSureVisibleItem(item);
69+ }
6170 }
6271 }
6372}