on xenial help sign in
Refactor preview widget reposition when inputmethod popups.

Add a signal makeSureVisible(var item) for preview widget, which can be passed up and preview catches it and does the needed movement. This change is to avoid inputhmethod appears over preview widget which contains textarea.

commit8b6dd427127d7cbff7dd1d1d28222381ffa0ef20 authorGary.Wzl <Gary.Wang@canonical.com> dateMon 17 Aug 2015, 23:42 (11 years ago) parentcece9cc
5 files changed+39−51
qml/Dash/Previews/Preview.qml+13−50 qml/Dash/Previews/PreviewCommentInput.qml+6 qml/Dash/Previews/PreviewRatingInput.qml+7−1 qml/Dash/Previews/PreviewWidget.qml+9 qml/Dash/Previews/PreviewWidgetFactory.qml+4
qml/Dash/Previews/Preview.qml+13−50
@@ -63,22 +63,7 @@ Item {
6363 Repeater {
6464 id: repeater;
6565 model: previewModel
66−
67− function findChild(obj, objectName) {
68− var childs = new Array(0);
69− childs.push(obj)
70− while (childs.length > 0) {
71− if (childs[0].objectName === objectName) {
72− return childs[0]
73− }
74− for (var i in childs[0].data) {
75− childs.push(childs[0].data[i])
76− }
77− childs.splice(0, 1);
78− }
79− return null;
80− }
81−
66+
8267 delegate: ListView {
8368 id: column
8469 objectName: "previewListRow" + index
@@ -86,40 +71,6 @@ Item {
8671 width: row.columnWidth
8772 spacing: row.spacing
8873 bottomMargin: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
89−
90− readonly property int inputMethodMargin: 30;
91− property bool inputMethodVisible: Qt.inputMethod.visible;
92− onInputMethodVisibleChanged: {
93− if (!inputMethodVisible)
94− return;
95−
96− var textArea = null;
97− var contentItem = column.contentItem;
98−
99− var reviewTextArea = repeater.findChild(contentItem, "reviewTextArea");
100− if (reviewTextArea !== null && reviewTextArea.activeFocus) {
101− textArea = reviewTextArea;
102− }
103−
104− if (textArea === null) {
105− var commentTextArea = repeater.findChild(contentItem, "commentTextArea");
106− if (commentTextArea !== null && commentTextArea.activeFocus) {
107− textArea = commentTextArea;
108− }
109− }
110−
111− if (textArea === null)
112− return;
113−
114− var textAreaPos = textArea.mapToItem(column, 0, 0);
115− var textAreaGlobalHeight = textAreaPos.y + textArea.implicitHeight
116− + column.height / 2.0;
117−
118− if (textAreaGlobalHeight > column.height) {
119− column.contentY += textAreaGlobalHeight - column.height + inputMethodMargin;
120− }
121− }
122−
12374 model: columnModel
12475 cacheBuffer: height
12576
@@ -131,6 +82,8 @@ Item {
13182 widgetData: model.properties
13283 isCurrentPreview: root.isCurrent
13384 scopeStyle: root.scopeStyle
85+ readonly property int inputMethodMargin: units.gu(2);
86+
13487 anchors {
13588 left: parent.left
13689 right: parent.right
@@ -141,6 +94,16 @@ Item {
14194 onTriggered: {
14295 previewModel.triggered(widgetId, actionId, data);
14396 }
97+
98+ onMakeSureVisible: {
99+ var textAreaPos = item.mapToItem(column, 0, 0);
100+ var textAreaGlobalHeight = textAreaPos.y + item.implicitHeight
101+ + column.height / 2.0;
102+
103+ if (textAreaGlobalHeight > column.height) {
104+ column.contentY += textAreaGlobalHeight - column.height + inputMethodMargin;
105+ }
106+ }
144107
145108 onFocusChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
146109
qml/Dash/Previews/PreviewCommentInput.qml+6
@@ -39,6 +39,12 @@ PreviewWidget {
3939 id: commentTextArea
4040 objectName: "commentTextArea"
4141
42+ property bool inputMethodVisible: Qt.inputMethod.visible;
43+ onInputMethodVisibleChanged: {
44+ if(inputMethodVisible && activeFocus)
45+ root.makeSureVisible(commentTextArea);
46+ }
47+
4248 anchors {
4349 top: parent.top
4450 left: parent.left
qml/Dash/Previews/PreviewRatingInput.qml+7−1
@@ -143,7 +143,13 @@ PreviewWidget {
143143 TextArea {
144144 id: reviewTextArea
145145 objectName: "reviewTextArea"
146−
146+
147+ property bool inputMethodVisible: Qt.inputMethod.visible;
148+ onInputMethodVisibleChanged: {
149+ if(inputMethodVisible && activeFocus)
150+ root.makeSureVisible(reviewTextArea);
151+ }
152+
147153 anchors {
148154 top: parent.top
149155 left: parent.left
qml/Dash/Previews/PreviewWidget.qml+9
@@ -41,5 +41,14 @@ Item {
4141 */
4242 signal triggered(string widgetId, string actionId, var data)
4343
44+ /*! \brief This signal should be emitted when widget gains the focus
45+ * and input method popups.
46+ * And preview widget should reposition in visible area to avoid
47+ * keyboard appears over the widget.
48+ *
49+ * \param item, id of specified item which is needed to reposition.
50+ */
51+ signal makeSureVisible(var item)
52+
4453 objectName: widgetId
4554}
qml/Dash/Previews/PreviewWidgetFactory.qml+4
@@ -43,6 +43,9 @@ Loader {
4343 //! Triggered signal forwarded from the widgets.
4444 signal triggered(string widgetId, string actionId, var data)
4545
46+ //! MakesureVisible signal forwarded from the widgets.
47+ signal makeSureVisible(var item)
48+
4649 source: widgetSource
4750
4851 //! \cond private
@@ -81,5 +84,6 @@ Loader {
8184 Connections {
8285 target: root.item
8386 onTriggered: root.triggered(widgetId, actionId, data)
87+ onMakeSureVisible: root.makeSureVisible(item)
8488 }
8589}