on xenial help sign in
Refactor preview widget reposition when inputmethod popups.
8b6dd42Gary.Wzl
qml/Dash/Previews/Preview.qml+13−50
@@ -63,22 +63,7 @@ Item {
63 Repeater {
63 Repeater {
64 id: repeater;
64 id: repeater;
65 model: previewModel
65 model: previewModel
66−
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−
82 delegate: ListView {
67 delegate: ListView {
83 id: column
68 id: column
84 objectName: "previewListRow" + index
69 objectName: "previewListRow" + index
@@ -86,40 +71,6 @@ Item {
86 width: row.columnWidth
71 width: row.columnWidth
87 spacing: row.spacing
72 spacing: row.spacing
88 bottomMargin: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
73 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−
123 model: columnModel
74 model: columnModel
124 cacheBuffer: height
75 cacheBuffer: height
125
76
@@ -131,6 +82,8 @@ Item {
131 widgetData: model.properties
82 widgetData: model.properties
132 isCurrentPreview: root.isCurrent
83 isCurrentPreview: root.isCurrent
133 scopeStyle: root.scopeStyle
84 scopeStyle: root.scopeStyle
85+ readonly property int inputMethodMargin: units.gu(2);
86+
134 anchors {
87 anchors {
135 left: parent.left
88 left: parent.left
136 right: parent.right
89 right: parent.right
@@ -141,6 +94,16 @@ Item {
141 onTriggered: {
94 onTriggered: {
142 previewModel.triggered(widgetId, actionId, data);
95 previewModel.triggered(widgetId, actionId, data);
143 }
96 }
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+ }
144
107
145 onFocusChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
108 onFocusChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
146
109
qml/Dash/Previews/PreviewCommentInput.qml+6
@@ -39,6 +39,12 @@ PreviewWidget {
39 id: commentTextArea
39 id: commentTextArea
40 objectName: "commentTextArea"
40 objectName: "commentTextArea"
41
41
42+ property bool inputMethodVisible: Qt.inputMethod.visible;
43+ onInputMethodVisibleChanged: {
44+ if(inputMethodVisible && activeFocus)
45+ root.makeSureVisible(commentTextArea);
46+ }
47+
42 anchors {
48 anchors {
43 top: parent.top
49 top: parent.top
44 left: parent.left
50 left: parent.left
qml/Dash/Previews/PreviewRatingInput.qml+7−1
@@ -143,7 +143,13 @@ PreviewWidget {
143 TextArea {
143 TextArea {
144 id: reviewTextArea
144 id: reviewTextArea
145 objectName: "reviewTextArea"
145 objectName: "reviewTextArea"
146−
146+
147+ property bool inputMethodVisible: Qt.inputMethod.visible;
148+ onInputMethodVisibleChanged: {
149+ if(inputMethodVisible && activeFocus)
150+ root.makeSureVisible(reviewTextArea);
151+ }
152+
147 anchors {
153 anchors {
148 top: parent.top
154 top: parent.top
149 left: parent.left
155 left: parent.left
qml/Dash/Previews/PreviewWidget.qml+9
@@ -41,5 +41,14 @@ Item {
41 */
41 */
42 signal triggered(string widgetId, string actionId, var data)
42 signal triggered(string widgetId, string actionId, var data)
43
43
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+
44 objectName: widgetId
53 objectName: widgetId
45}
54}
qml/Dash/Previews/PreviewWidgetFactory.qml+4
@@ -43,6 +43,9 @@ Loader {
43 //! Triggered signal forwarded from the widgets.
43 //! Triggered signal forwarded from the widgets.
44 signal triggered(string widgetId, string actionId, var data)
44 signal triggered(string widgetId, string actionId, var data)
45
45
46+ //! MakesureVisible signal forwarded from the widgets.
47+ signal makeSureVisible(var item)
48+
46 source: widgetSource
49 source: widgetSource
47
50
48 //! \cond private
51 //! \cond private
@@ -81,5 +84,6 @@ Loader {
81 Connections {
84 Connections {
82 target: root.item
85 target: root.item
83 onTriggered: root.triggered(widgetId, actionId, data)
86 onTriggered: root.triggered(widgetId, actionId, data)
87+ onMakeSureVisible: root.makeSureVisible(item)
84 }
88 }
85}
89}