on xenial help sign in
Refactor textarea visible to make it more flexible.
cece9ccGary.Wzl
qml/Dash/Previews/Preview.qml+49
@@ -61,8 +61,24 @@ Item {
61 property real columnWidth: width / columns
61 property real columnWidth: width / columns
62
62
63 Repeater {
63 Repeater {
64+ id: repeater;
64 model: previewModel
65 model: previewModel
65
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 delegate: ListView {
82 delegate: ListView {
67 id: column
83 id: column
68 objectName: "previewListRow" + index
84 objectName: "previewListRow" + index
@@ -70,6 +86,39 @@ Item {
70 width: row.columnWidth
86 width: row.columnWidth
71 spacing: row.spacing
87 spacing: row.spacing
72 bottomMargin: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
88 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+ }
73
122
74 model: columnModel
123 model: columnModel
75 cacheBuffer: height
124 cacheBuffer: height
qml/Dash/Previews/PreviewCommentInput.qml−22
@@ -39,28 +39,6 @@ PreviewWidget {
39 id: commentTextArea
39 id: commentTextArea
40 objectName: "commentTextArea"
40 objectName: "commentTextArea"
41
41
42− property var flickableItem: null;
43− property bool inputMethodVisible: Qt.inputMethod.visible;
44− onInputMethodVisibleChanged: {
45− //A workaround to automatically move textArea up on u-touch
46− if (inputMethodVisible && commentTextArea.activeFocus) {
47− var obj = root.parent.parent.parent;
48− if (obj.objectName.indexOf("previewListRow") === 0) {
49− flickableItem = obj;
50−
51− var textAreaPos = commentTextArea.mapToItem(flickableItem, 0, 0);
52− var textAreaGlobalHeight = textAreaPos.y + commentTextArea.implicitHeight
53− + flickableItem.height / 2.0;
54−
55− if (textAreaGlobalHeight > flickableItem.height) {
56− flickableItem.contentY += textAreaGlobalHeight - flickableItem.height;
57− }
58− }
59− } else {
60− flickableItem = null;
61− }
62− }
63−
64 anchors {
42 anchors {
65 top: parent.top
43 top: parent.top
66 left: parent.left
44 left: parent.left
qml/Dash/Previews/PreviewRatingInput.qml−22
@@ -144,28 +144,6 @@ PreviewWidget {
144 id: reviewTextArea
144 id: reviewTextArea
145 objectName: "reviewTextArea"
145 objectName: "reviewTextArea"
146
146
147− property var flickableItem: null;
148− property bool inputMethodVisible: Qt.inputMethod.visible;
149− onInputMethodVisibleChanged: {
150− //A workaround to automatically move textArea up on u-touch
151− if (inputMethodVisible && reviewTextArea.activeFocus) {
152− var obj = root.parent.parent.parent;
153− if (obj.objectName.indexOf("previewListRow") === 0) {
154− flickableItem = obj;
155−
156− var textAreaPos = reviewSubmitContainer.mapToItem(flickableItem, 0, 0);
157− var textAreaGlobalHeight = textAreaPos.y + reviewSubmitContainer.implicitHeight
158− + flickableItem.height / 2.0;
159−
160− if (textAreaGlobalHeight > flickableItem.height) {
161− flickableItem.contentY += textAreaGlobalHeight - flickableItem.height;
162− }
163− }
164− } else {
165− flickableItem = null;
166− }
167− }
168−
169 anchors {
147 anchors {
170 top: parent.top
148 top: parent.top
171 left: parent.left
149 left: parent.left