Merge lp:~zsombi/ubuntu-ui-toolkit/textinputs-stay-disabled-when-reenabled into lp:ubuntu-ui-toolkit

Proposed by Zsombor Egri
Status: Merged
Approved by: Florian Boucault
Approved revision: 431
Merged at revision: 430
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/textinputs-stay-disabled-when-reenabled
Merge into: lp:ubuntu-ui-toolkit
Prerequisite: lp:~zsombi/ubuntu-ui-toolkit/textinputs-delegate-color-styling
Diff against target: 335 lines (+106/-80)
6 files modified
modules/Ubuntu/Components/TextArea.qml (+0/-18)
modules/Ubuntu/Components/TextField.qml (+0/-18)
modules/Ubuntu/Components/plugin/quickutils.cpp (+28/-0)
modules/Ubuntu/Components/plugin/quickutils.h (+5/-0)
tests/unit/tst_components/tst_textarea.qml (+21/-10)
tests/unit/tst_components/tst_textfield.qml (+52/-34)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/textinputs-stay-disabled-when-reenabled
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Florian Boucault Pending
Review via email: mp+159616@code.launchpad.net

This proposal supersedes a proposal from 2013-04-18.

Commit message

Fix for text inputs staying disabled after being re-enabled. The previous workaround for removing input panel was blocking re-enabling a previously enabled input.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Florian Boucault (fboucault) wrote : Posted in a previous version of this proposal

How about using http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#inherits instead of qobject_cast?
It seems more adapted to the purpose of the checks in QuickUtils::activeFocus.
Feel free to ignore this comment.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/TextArea.qml'
2--- modules/Ubuntu/Components/TextArea.qml 2013-04-17 16:19:42 +0000
3+++ modules/Ubuntu/Components/TextArea.qml 2013-04-18 12:28:28 +0000
4@@ -919,24 +919,6 @@
5 // autosize handling
6 onLineCountChanged: internal.frameSize()
7
8- // FIXME: workaround for bug https://bugreports.qt-project.org/browse/QTBUG-30729
9- // input panel does not get removed when no active input is active
10- activeFocusOnPress: false
11- onActiveFocusChanged: {
12- if (activeFocus) {
13- internal.showInputPanel();
14- } else {
15- internal.hideInputPanel();
16- }
17- }
18- // watch inputMethod's visible change to be able to open input panel back
19- // removed by a previous active focus being deactivated
20- // workaround for bug https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1163371
21- Connections {
22- target: Qt.inputMethod
23- onVisibleChanged: if (editor.activeFocus) internal.showInputPanel();
24- }
25-
26 // remove selection when typing starts or input method start entering text
27 onInputMethodComposingChanged: {
28 if (inputMethodComposing)
29
30=== modified file 'modules/Ubuntu/Components/TextField.qml'
31--- modules/Ubuntu/Components/TextField.qml 2013-04-17 16:19:42 +0000
32+++ modules/Ubuntu/Components/TextField.qml 2013-04-18 12:28:28 +0000
33@@ -617,24 +617,6 @@
34 // forward keys to the root element so it can be captured outside of it
35 Keys.forwardTo: [control]
36
37- // FIXME: workaround for bug https://bugreports.qt-project.org/browse/QTBUG-30729
38- // input panel does not get removed when no active input is active
39- activeFocusOnPress: false
40- onActiveFocusChanged: {
41- if (activeFocus) {
42- internal.showInputPanel();
43- } else {
44- internal.hideInputPanel();
45- }
46- }
47- // watch inputMethod's visible change to be able to open input panel back
48- // removed by a previous active focus being deactivated
49- // workaround for bug https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1163371
50- Connections {
51- target: Qt.inputMethod
52- onVisibleChanged: if (editor.activeFocus) internal.showInputPanel()
53- }
54-
55 // handle virtual keyboard and cursor positioning, as the MouseArea overrides
56 // those functionalities of the TextInput
57 MouseArea {
58
59=== modified file 'modules/Ubuntu/Components/plugin/quickutils.cpp'
60--- modules/Ubuntu/Components/plugin/quickutils.cpp 2013-03-07 12:40:45 +0000
61+++ modules/Ubuntu/Components/plugin/quickutils.cpp 2013-04-18 12:28:28 +0000
62@@ -25,10 +25,15 @@
63 #include <QtCore/QAbstractProxyModel>
64 #include <QtQml/QQmlPropertyMap>
65
66+#include <private/qquicktextinput_p.h>
67+#include <private/qquicktextedit_p.h>
68+
69 QuickUtils::QuickUtils(QObject *parent) :
70 QObject(parent)
71 {
72 QGuiApplication::instance()->installEventFilter(this);
73+ // connect to focusObjectChanged() to get the latest active focus object
74+ QObject::connect(QGuiApplication::instance(), SIGNAL(focusObjectChanged(QObject*)), this, SLOT(activeFocus(QObject*)));
75 }
76
77 /*!
78@@ -45,6 +50,23 @@
79 return QObject::eventFilter(obj, event);
80 }
81
82+/*!
83+ * \internal
84+ * Catch active focus object change to detecte whether we need to remove OSK or not.
85+ */
86+void QuickUtils::activeFocus(QObject *active)
87+{
88+ // FIXME: workaround for bug https://bugreports.qt-project.org/browse/QTBUG-30729
89+ // input panel does not get removed when no input is active
90+ // remove input panel if there's no more active object or the new active object
91+ // is not a text input
92+ // workaround for bug https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1163371
93+ if (QGuiApplication::inputMethod()->isVisible() && (!active || (active &&
94+ !qobject_cast<QQuickTextInput*>(active) &&
95+ !qobject_cast<QQuickTextEdit*>(active)))) {
96+ QGuiApplication::inputMethod()->hide();
97+ }
98+}
99
100 /*!
101 * \internal
102@@ -57,6 +79,12 @@
103 return (m_rootView) ? m_rootView->rootObject() : 0;
104 }
105
106+QString QuickUtils::inputMethodProvider() const
107+{
108+ return QString(getenv("QT_IM_MODULE"));
109+}
110+
111+
112 /*!
113 * \internal
114 * Creates an instance out of a delegate using the roles specified in the
115
116=== modified file 'modules/Ubuntu/Components/plugin/quickutils.h'
117--- modules/Ubuntu/Components/plugin/quickutils.h 2013-03-07 12:40:45 +0000
118+++ modules/Ubuntu/Components/plugin/quickutils.h 2013-04-18 12:28:28 +0000
119@@ -29,6 +29,7 @@
120 {
121 Q_OBJECT
122 Q_PROPERTY(QQuickItem *rootObject READ rootObject NOTIFY rootObjectChanged)
123+ Q_PROPERTY(QString inputMethodProvider READ inputMethodProvider)
124 public:
125 static QuickUtils& instance()
126 {
127@@ -37,6 +38,7 @@
128 }
129
130 QQuickItem *rootObject();
131+ QString inputMethodProvider() const;
132
133 Q_INVOKABLE qreal modelDelegateHeight(QQmlComponent *delegate, const QVariant &model);
134 Q_INVOKABLE QString className(QQuickItem *item);
135@@ -47,6 +49,9 @@
136 protected:
137 bool eventFilter(QObject *, QEvent *);
138
139+private Q_SLOTS:
140+ void activeFocus(QObject*);
141+
142 private:
143 explicit QuickUtils(QObject *parent = 0);
144 QQuickView *m_rootView;
145
146=== modified file 'tests/unit/tst_components/tst_textarea.qml'
147--- tests/unit/tst_components/tst_textarea.qml 2013-04-18 12:28:28 +0000
148+++ tests/unit/tst_components/tst_textarea.qml 2013-04-18 12:28:28 +0000
149@@ -22,6 +22,8 @@
150 Item {
151 width: 200; height: 200
152
153+ property bool hasOSK: QuickUtils.inputMethodProvider !== ""
154+
155 TextArea {
156 id: textArea
157 SignalSpy {
158@@ -414,12 +416,8 @@
159 }
160
161 function test_OSK_ShownWhenNextTextAreaIsFocused() {
162- // detect whether we have OSK support
163- Qt.inputMethod.show();
164- if (!Qt.inputMethod.visible)
165+ if (!hasOSK)
166 expectFail("", "OSK can be tested only when present");
167- else
168- Qt.inputMethod.hide();
169 t1.focus = true;
170 compare(Qt.inputMethod.visible, true, "OSK is shown for the first TextArea");
171 t2.focus = true;
172@@ -427,18 +425,31 @@
173 }
174
175 function test_RemoveOSKWhenFocusLost() {
176- // detect whether we have OSK support
177- Qt.inputMethod.show();
178- if (!Qt.inputMethod.visible)
179+ if (!hasOSK)
180 expectFail("", "OSK can be tested only when present");
181- else
182- Qt.inputMethod.hide();
183 t1.focus = true;
184 compare(Qt.inputMethod.visible, true, "OSK is shown when TextArea gains focus");
185 t1.focus = false;
186 compare(Qt.inputMethod.visible, false, "OSK is hidden when TextArea looses focus");
187 }
188
189+ function test_ReEnabledInput() {
190+ textArea.forceActiveFocus();
191+ textArea.enabled = false;
192+ compare(textArea.enabled, false, "textArea is disabled");
193+ compare(textArea.focus, true, "textArea is focused");
194+ compare(textArea.activeFocus, false, "textArea is not active focus");
195+ compare(Qt.inputMethod.visible, false, "OSK removed");
196+
197+ textArea.enabled = true;
198+ compare(textArea.enabled, true, "textArea is enabled");
199+ compare(textArea.focus, true, "textArea is focused");
200+ compare(textArea.activeFocus, true, "textArea is active focus");
201+ if (!hasOSK)
202+ expectFail("", "OSK can be tested only when present");
203+ compare(Qt.inputMethod.visible, true, "OSK shown");
204+ }
205+
206 // make it to b ethe last test case executed
207 function test_zz_TextareaInListItem_RichTextEnterCaptured() {
208 textArea.text = "a<br />b";
209
210=== modified file 'tests/unit/tst_components/tst_textfield.qml'
211--- tests/unit/tst_components/tst_textfield.qml 2013-04-18 12:28:28 +0000
212+++ tests/unit/tst_components/tst_textfield.qml 2013-04-18 12:28:28 +0000
213@@ -22,37 +22,46 @@
214 id: textItem
215 width: 200; height: 200
216
217+ property bool hasOSK: QuickUtils.inputMethodProvider !== ""
218+
219+ function reset() {
220+ colorTest.focus = false;
221+ textField.focus = false;
222+ t1.focus = false;
223+ t2.focus = false;
224+ }
225+
226 TextField {
227 id: colorTest
228 color: colorTest.text.length < 4 ? "#0000ff" : "#00ff00"
229 }
230
231+ TextField {
232+ id: textField
233+ SignalSpy {
234+ id: signalSpy
235+ target: parent
236+ }
237+
238+ property int keyPressData
239+ property int keyReleaseData
240+ Keys.onPressed: keyPressData = event.key
241+ Keys.onReleased: keyReleaseData = event.key
242+ }
243+
244+ Item {
245+ TextField {
246+ id: t1
247+ }
248+ TextField {
249+ id: t2
250+ }
251+ }
252+
253 TestCase {
254 name: "TextFieldAPI"
255 when: windowShown
256
257- TextField {
258- id: textField
259- SignalSpy {
260- id: signalSpy
261- target: parent
262- }
263-
264- property int keyPressData
265- property int keyReleaseData
266- Keys.onPressed: keyPressData = event.key
267- Keys.onReleased: keyReleaseData = event.key
268- }
269-
270- Item {
271- TextField {
272- id: t1
273- }
274- TextField {
275- id: t2
276- }
277- }
278-
279 function initTestCase() {
280 textField.forceActiveFocus();
281 compare(textField.focus, true, "TextField is focused");
282@@ -228,32 +237,41 @@
283 }
284
285 // need to make the very first test case, otherwise OSK detection fails on phablet
286- function test_00_OSK_ShownWhenNextTextFieldIsFocused() {
287- // detect whether we have OSK support
288- Qt.inputMethod.show();
289- if (!Qt.inputMethod.visible)
290+ function test_zz_OSK_ShownWhenNextTextFieldIsFocused() {
291+ if (!hasOSK)
292 expectFail("", "OSK can be tested only when present");
293- else
294- Qt.inputMethod.hide();
295 t1.focus = true;
296 compare(Qt.inputMethod.visible, true, "OSK is shown for the first TextField");
297 t2.focus = true;
298 compare(Qt.inputMethod.visible, true, "OSK is shown for the second TextField");
299 }
300
301- function test_RemoveOSKWhenFocusLost() {
302- // detect whether we have OSK support
303- Qt.inputMethod.show();
304- if (!Qt.inputMethod.visible)
305+ function test_zz_RemoveOSKWhenFocusLost() {
306+ if (!hasOSK)
307 expectFail("", "OSK can be tested only when present");
308- else
309- Qt.inputMethod.hide();
310 t1.focus = true;
311 compare(Qt.inputMethod.visible, true, "OSK is shown when TextField gains focus");
312 t1.focus = false;
313 compare(Qt.inputMethod.visible, false, "OSK is hidden when TextField looses focus");
314 }
315
316+ function test_zz_ReEnabledInput() {
317+ textField.forceActiveFocus();
318+ textField.enabled = false;
319+ compare(textField.enabled, false, "textField is disabled");
320+ compare(textField.focus, true, "textField is focused");
321+ compare(textField.activeFocus, false, "textField is not active focus");
322+ compare(Qt.inputMethod.visible, false, "OSK removed");
323+
324+ textField.enabled = true;
325+ compare(textField.enabled, true, "textField is enabled");
326+ compare(textField.focus, true, "textField is focused");
327+ compare(textField.activeFocus, true, "textField is active focus");
328+ if (!hasOSK)
329+ expectFail("", "OSK can be tested only when present");
330+ compare(Qt.inputMethod.visible, true, "OSK shown");
331+ }
332+
333 RegExpValidator {
334 id: regExpValidator
335 regExp: /[a-z]*/

Subscribers

People subscribed via source and target branches

to status/vote changes: