diff options
author | Liang Qi <liang.qi@digia.com> | 2013-11-13 11:48:15 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-15 19:00:32 +0100 |
commit | 5b38d395a821967b48406faf18f638e252d627fa (patch) | |
tree | 95957b585fdca1d023807d5bbe8ee2498754e70e | |
parent | fc710d6a3548f218f853adb2f2cb908398815be6 (diff) | |
download | qtquickcontrols-5b38d395a821967b48406faf18f638e252d627fa.tar.gz |
SpinBox: get active focus when up or down was pressed
This behavior also needs activeFocusOnPress was true.
Task-number: QTBUG-34773
Change-Id: I681c1cb20c1803e3bf7f60af5cdf45ae3fe34dae
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
-rw-r--r-- | src/controls/SpinBox.qml | 5 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_spinbox.qml | 70 |
2 files changed, 75 insertions, 0 deletions
diff --git a/src/controls/SpinBox.qml b/src/controls/SpinBox.qml index 0cc2f5a7..bba4eae1 100644 --- a/src/controls/SpinBox.qml +++ b/src/controls/SpinBox.qml @@ -271,6 +271,7 @@ Control { MouseArea { id: mouseUp + objectName: "mouseUp" hoverEnabled: true property var upRect: __panel ? __panel.upRect : null @@ -285,6 +286,7 @@ Control { height: upRect ? upRect.height : 0 onClicked: __increment() + onPressed: if (activeFocusOnPress) input.forceActiveFocus() property bool autoincrement: false; onReleased: autoincrement = false @@ -296,9 +298,12 @@ Control { MouseArea { id: mouseDown + objectName: "mouseDown" hoverEnabled: true onClicked: __decrement() + onPressed: if (activeFocusOnPress) input.forceActiveFocus() + property var downRect: __panel ? __panel.downRect : null anchors.left: parent.left diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml index 67dd3dba..9a68907c 100644 --- a/tests/auto/controls/data/tst_spinbox.qml +++ b/tests/auto/controls/data/tst_spinbox.qml @@ -343,6 +343,76 @@ Item { spinbox2.destroy() } + function test_get_active_focus_when_up_or_down_was_pressed(){ + var test_control = 'import QtQuick 2.1; \ + import QtQuick.Controls 1.1; \ + Column { \ + property alias spinbox: _spinbox; \ + property alias textfield: _textfield; \ + SpinBox { \ + id: _spinbox; \ + } \ + TextField { \ + id: _textfield; \ + text: "textfile"; \ + } \ + } ' + + var control = Qt.createQmlObject(test_control, container, '') + verify(control !== null) + + var spinbox = control.spinbox + var textfield = control.textfield + verify(spinbox !== null) + verify(textfield !== null) + + waitForRendering(control) + + var up = getMouseArea(spinbox, "mouseUp") + verify(up !== null) + var down = getMouseArea(spinbox, "mouseDown") + verify(down !== null) + + textfield.forceActiveFocus() + verify(!spinbox.activeFocus) + verify(textfield.activeFocus) + + mouseClick(up, up.width/2, up.height/2) + verify(spinbox.activeFocus) + verify(!textfield.activeFocus) + + textfield.forceActiveFocus() + verify(!spinbox.activeFocus) + verify(textfield.activeFocus) + + mouseClick(down, down.width/2, down.height/2) + verify(spinbox.activeFocus) + verify(!textfield.activeFocus) + + textfield.forceActiveFocus() + verify(!spinbox.activeFocus) + verify(textfield.activeFocus) + spinbox.activeFocusOnPress = false + + mouseClick(up, up.width/2, up.height/2) + verify(!spinbox.activeFocus) + verify(textfield.activeFocus) + + mouseClick(down, down.width/2, down.height/2) + verify(!spinbox.activeFocus) + verify(textfield.activeFocus) + + control.destroy() + } + + function getMouseArea(control, name) { + for (var i = 0; i < control.children.length; i++) { + if (control.children[i].objectName === name) + return control.children[i] + } + return null + } + function test_activeFocusOnPress(){ var spinbox = Qt.createQmlObject('import QtQuick.Controls 1.1; SpinBox {x: 20; y: 20; width: 100; height: 50}', container, '') spinbox.activeFocusOnPress = false |