summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@digia.com>2014-01-21 13:07:21 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-22 16:09:31 +0100
commit5dc805c86077ee9cd10af530f802fdda879cfb6a (patch)
tree44a13a83b6e79d0e81420b2167eaf20b018f01c6
parent5e022a65531b92d4d2f4cf9a0dd6b843aadf3797 (diff)
downloadqtquickcontrols-5dc805c86077ee9cd10af530f802fdda879cfb6a.tar.gz
Controls: Fixed support for Keys attached property on controls allowing text input
By forwarding key events from the internal control. It includes TextField, TextArea, ComboBox, SpinBox. The key events from internal are Keys.forwardTo controls, then user could customize their own behavior for those controls. Autotest are included. [ChangeLog][QtQuickControls] Fixed support for Keys attached property on controls allowing text input, by forwarding key events from the internal control. Task-number: QTBUG-33493 Task-number: QTBUG-34101 Task-number: QTBUG-35763 Change-Id: I00ea131160e55048b34fe0713e1ee02ff9472f05 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com> Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
-rw-r--r--src/controls/ComboBox.qml1
-rw-r--r--src/controls/SpinBox.qml2
-rw-r--r--src/controls/TextArea.qml2
-rw-r--r--src/controls/TextField.qml2
-rw-r--r--tests/auto/controls/data/combobox/cb_keys.qml62
-rw-r--r--tests/auto/controls/data/spinbox/sb_keys.qml63
-rw-r--r--tests/auto/controls/data/textarea/ta_keys.qml62
-rw-r--r--tests/auto/controls/data/textfield/tf_keys.qml62
-rw-r--r--tests/auto/controls/data/tst_combobox.qml32
-rw-r--r--tests/auto/controls/data/tst_spinbox.qml32
-rw-r--r--tests/auto/controls/data/tst_textarea.qml32
-rw-r--r--tests/auto/controls/data/tst_textfield.qml32
12 files changed, 384 insertions, 0 deletions
diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml
index fe2b9e2b..4a9ce967 100644
--- a/src/controls/ComboBox.qml
+++ b/src/controls/ComboBox.qml
@@ -427,6 +427,7 @@ Control {
}
property bool allowComplete: false
+ Keys.forwardTo: comboBox
Keys.onPressed: allowComplete = (event.key !== Qt.Key_Backspace && event.key !== Qt.Key_Delete);
onTextChanged: {
diff --git a/src/controls/SpinBox.qml b/src/controls/SpinBox.qml
index 4dc03d97..8fc964a0 100644
--- a/src/controls/SpinBox.qml
+++ b/src/controls/SpinBox.qml
@@ -268,6 +268,8 @@ Control {
selectValue()
}
+ Keys.forwardTo: spinbox
+
onEditingFinished: spinbox.editingFinished()
color: __panel ? __panel.foregroundColor : "black"
diff --git a/src/controls/TextArea.qml b/src/controls/TextArea.qml
index 72697919..66e7faf6 100644
--- a/src/controls/TextArea.qml
+++ b/src/controls/TextArea.qml
@@ -720,6 +720,8 @@ ScrollView {
selectByMouse: true
readOnly: false
+ Keys.forwardTo: area
+
KeyNavigation.priority: KeyNavigation.BeforeItem
KeyNavigation.tab: area.tabChangesFocus ? area.KeyNavigation.tab : null
KeyNavigation.backtab: area.tabChangesFocus ? area.KeyNavigation.backtab : null
diff --git a/src/controls/TextField.qml b/src/controls/TextField.qml
index ba380b68..d9ba3625 100644
--- a/src/controls/TextField.qml
+++ b/src/controls/TextField.qml
@@ -598,6 +598,8 @@ Control {
renderType: __style ? __style.renderType : Text.NativeRendering
+ Keys.forwardTo: textfield
+
onAccepted: {
Qt.inputMethod.commit()
Qt.inputMethod.hide()
diff --git a/tests/auto/controls/data/combobox/cb_keys.qml b/tests/auto/controls/data/combobox/cb_keys.qml
new file mode 100644
index 00000000..0e75fddb
--- /dev/null
+++ b/tests/auto/controls/data/combobox/cb_keys.qml
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Quick Controls module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+import QtQuick.Controls 1.1
+
+Row {
+ width: 100
+ height: 50
+ spacing: 10
+
+ property alias control1: _control1
+ ComboBox {
+ id: _control1
+ editable: true
+ property bool gotit: false
+ Keys.onPressed: {
+ if ((!gotit) && (event.key === Qt.Key_B)) {
+ gotit = true;
+ event.accepted = true;
+ return;
+ }
+ }
+ }
+}
diff --git a/tests/auto/controls/data/spinbox/sb_keys.qml b/tests/auto/controls/data/spinbox/sb_keys.qml
new file mode 100644
index 00000000..39671835
--- /dev/null
+++ b/tests/auto/controls/data/spinbox/sb_keys.qml
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Quick Controls module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+import QtQuick.Controls 1.1
+
+Row {
+ width: 100
+ height: 50
+ spacing: 10
+
+ property alias control1: _control1
+ SpinBox {
+ id: _control1
+ value: 9
+ property bool gotit: false
+ Keys.onPressed: {
+ if ((!gotit) && (event.key === Qt.Key_B)) {
+ gotit = true;
+ value = value - 2;
+ event.accepted = true;
+ return;
+ }
+ }
+ }
+}
diff --git a/tests/auto/controls/data/textarea/ta_keys.qml b/tests/auto/controls/data/textarea/ta_keys.qml
new file mode 100644
index 00000000..e810bbc9
--- /dev/null
+++ b/tests/auto/controls/data/textarea/ta_keys.qml
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Quick Controls module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+import QtQuick.Controls 1.1
+
+Row {
+ width: 100
+ height: 50
+ spacing: 10
+
+ property alias control1: _control1
+ TextArea {
+ id: _control1
+ text: ""
+ property bool gotit: false
+ Keys.onPressed: {
+ if ((!gotit) && (event.key === Qt.Key_B)) {
+ gotit = true;
+ event.accepted = true;
+ return;
+ }
+ }
+ }
+}
diff --git a/tests/auto/controls/data/textfield/tf_keys.qml b/tests/auto/controls/data/textfield/tf_keys.qml
new file mode 100644
index 00000000..4124651d
--- /dev/null
+++ b/tests/auto/controls/data/textfield/tf_keys.qml
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Quick Controls module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+import QtQuick.Controls 1.1
+
+Row {
+ width: 100
+ height: 50
+ spacing: 10
+
+ property alias control1: _control1
+ TextField {
+ id: _control1
+ text: ""
+ property bool gotit: false
+ Keys.onPressed: {
+ if ((!gotit) && (event.key === Qt.Key_B)) {
+ gotit = true;
+ event.accepted = true;
+ return;
+ }
+ }
+ }
+}
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 6758c982..4d5117fb 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -697,5 +697,37 @@ TestCase {
comboBox.destroy()
}
}
+
+ function test_keys() {
+ var component = Qt.createComponent("combobox/cb_keys.qml")
+ compare(component.status, Component.Ready)
+ var test = component.createObject(container);
+ verify(test !== null, "test control created is null")
+ var control1 = test.control1
+ verify(control1 !== null)
+
+ control1.forceActiveFocus()
+ verify(control1.activeFocus)
+
+ verify(control1.gotit === false)
+ verify(control1.editText === "0")
+
+ keyPress(Qt.Key_A)
+ verify(control1.activeFocus)
+ verify(control1.gotit === false)
+ verify(control1.editText === "0a")
+
+ keyPress(Qt.Key_B)
+ verify(control1.activeFocus)
+ verify(control1.gotit === true)
+ verify(control1.editText === "0a")
+
+ keyPress(Qt.Key_B)
+ verify(control1.activeFocus)
+ verify(control1.gotit === true)
+ verify(control1.editText === "0ab")
+
+ test.destroy()
+ }
}
}
diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml
index 260fc0c1..4a01c6c2 100644
--- a/tests/auto/controls/data/tst_spinbox.qml
+++ b/tests/auto/controls/data/tst_spinbox.qml
@@ -645,6 +645,38 @@ Item {
spinbox.destroy()
}
+
+ function test_keys() {
+ var component = Qt.createComponent("spinbox/sb_keys.qml")
+ compare(component.status, Component.Ready)
+ var test = component.createObject(container);
+ verify(test !== null, "test control created is null")
+ var control1 = test.control1
+ verify(control1 !== null)
+
+ control1.forceActiveFocus()
+ verify(control1.activeFocus)
+
+ verify(control1.gotit === false)
+ verify(control1.value === 9)
+
+ keyPress(Qt.Key_A)
+ verify(control1.activeFocus)
+ verify(control1.gotit === false)
+ verify(control1.value === 9)
+
+ keyPress(Qt.Key_B)
+ verify(control1.activeFocus)
+ verify(control1.gotit === true)
+ verify(control1.value === 7)
+
+ keyPress(Qt.Key_B)
+ verify(control1.activeFocus)
+ verify(control1.gotit === true)
+ verify(control1.value === 7)
+
+ test.destroy()
+ }
}
}
diff --git a/tests/auto/controls/data/tst_textarea.qml b/tests/auto/controls/data/tst_textarea.qml
index 5d0778f1..31239bef 100644
--- a/tests/auto/controls/data/tst_textarea.qml
+++ b/tests/auto/controls/data/tst_textarea.qml
@@ -155,5 +155,37 @@ TestCase {
verify(!control.control3.activeFocus)
control.destroy()
}
+
+ function test_keys() {
+ var component = Qt.createComponent("textarea/ta_keys.qml")
+ compare(component.status, Component.Ready)
+ var test = component.createObject(container);
+ verify(test !== null, "test control created is null")
+ var control1 = test.control1
+ verify(control1 !== null)
+
+ control1.forceActiveFocus()
+ verify(control1.activeFocus)
+
+ verify(control1.gotit === false)
+ verify(control1.text === "")
+
+ keyPress(Qt.Key_A)
+ verify(control1.activeFocus)
+ verify(control1.gotit === false)
+ verify(control1.text === "a")
+
+ keyPress(Qt.Key_B)
+ verify(control1.activeFocus)
+ verify(control1.gotit === true)
+ verify(control1.text === "a")
+
+ keyPress(Qt.Key_B)
+ verify(control1.activeFocus)
+ verify(control1.gotit === true)
+ verify(control1.text === "ab")
+
+ test.destroy()
+ }
}
}
diff --git a/tests/auto/controls/data/tst_textfield.qml b/tests/auto/controls/data/tst_textfield.qml
index a526d1f0..c8f59b7f 100644
--- a/tests/auto/controls/data/tst_textfield.qml
+++ b/tests/auto/controls/data/tst_textfield.qml
@@ -396,5 +396,37 @@ TestCase {
test.destroy()
}
+
+ function test_keys() {
+ var component = Qt.createComponent("textfield/tf_keys.qml")
+ compare(component.status, Component.Ready)
+ var test = component.createObject(container);
+ verify(test !== null, "test control created is null")
+ var control1 = test.control1
+ verify(control1 !== null)
+
+ control1.forceActiveFocus()
+ verify(control1.activeFocus)
+
+ verify(control1.gotit === false)
+ verify(control1.text === "")
+
+ keyPress(Qt.Key_A)
+ verify(control1.activeFocus)
+ verify(control1.gotit === false)
+ verify(control1.text === "a")
+
+ keyPress(Qt.Key_B)
+ verify(control1.activeFocus)
+ verify(control1.gotit === true)
+ verify(control1.text === "a")
+
+ keyPress(Qt.Key_B)
+ verify(control1.activeFocus)
+ verify(control1.gotit === true)
+ verify(control1.text === "ab")
+
+ test.destroy()
+ }
}
}