diff options
author | Adriano Rezende <adriano.1.rezende@nokia.com> | 2012-07-03 18:41:35 +0200 |
---|---|---|
committer | Jens Bache-Wiig <jens.bache-wiig@nokia.com> | 2012-07-04 16:18:35 +0200 |
commit | 0df696bcdc3cd17a517e442530eb8c1718ebbbf8 (patch) | |
tree | c40d6b51e3b4645f5e6cd8323bcb7098868ce1fa | |
parent | 98d7781e9e7fb98430edac089a479d846121f8bc (diff) | |
download | qtquickcontrols-0df696bcdc3cd17a517e442530eb8c1718ebbbf8.tar.gz |
Handle key press and release correctly for buttons
The clicked signal should not be emitted multiple times when the
button is just pressed.
Change-Id: I3f1f3ab7f135b366150af985b41409afa0130568
Reviewed-by: Leonardo Sobral Cunha <leo.cunha@nokia.com>
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@nokia.com>
-rw-r--r-- | components/Button.qml | 2 | ||||
-rw-r--r-- | components/private/BasicButton.qml | 20 | ||||
-rw-r--r-- | components/private/ButtonBehavior.qml | 1 |
3 files changed, 12 insertions, 11 deletions
diff --git a/components/Button.qml b/components/Button.qml index 10908b7f..4ae591d1 100644 --- a/components/Button.qml +++ b/components/Button.qml @@ -52,8 +52,6 @@ BasicButton { Accessible.name: text - Keys.onSpacePressed:animateClick() - delegate: StyleItem { id: styleitem anchors.fill: parent diff --git a/components/private/BasicButton.qml b/components/private/BasicButton.qml index daa17adf..e5509661 100644 --- a/components/private/BasicButton.qml +++ b/components/private/BasicButton.qml @@ -67,16 +67,18 @@ Item { implicitWidth: loader.item.implicitWidth implicitHeight: loader.item.implicitHeight - function animateClick() { - behavior.keyPressed = true - button.clicked() - animateClickTimer.start() + Keys.onPressed: { + if (event.key == Qt.Key_Space && !event.isAutoRepeat && !behavior.pressed) + behavior.keyPressed = true; } - Timer { - id: animateClickTimer - interval: 250 - onTriggered: behavior.keyPressed = false + Keys.onReleased: { + if (event.key == Qt.Key_Space && !event.isAutoRepeat && behavior.keyPressed) { + behavior.keyPressed = false; + if (checkable) + checked = !checked; + button.clicked(); + } } Loader { @@ -93,7 +95,7 @@ Item { onClicked: button.clicked() onExited: Internal.hideToolTip() onCanceled: Internal.hideToolTip() - onPressed: if (activeFocusOnPress) button.focus = true + onPressed: if (activeFocusOnPress) button.forceActiveFocus() Timer { interval: 1000 diff --git a/components/private/ButtonBehavior.qml b/components/private/ButtonBehavior.qml index fdf0c79c..c8f010c9 100644 --- a/components/private/ButtonBehavior.qml +++ b/components/private/ButtonBehavior.qml @@ -47,6 +47,7 @@ MouseArea { property bool effectivePressed: pressed && containsMouse || keyPressed hoverEnabled: true + enabled: !keyPressed onCheckableChanged: { if (!checkable) |