use onclicked

it gets canceled when it should
This commit is contained in:
Marco Martin 2011-11-28 21:41:26 +01:00
parent 42aeaebb4e
commit 13a3d33681
3 changed files with 25 additions and 38 deletions

View File

@ -59,26 +59,21 @@ Item {
// disabled buttons // disabled buttons
opacity: enabled ? 1.0 : 0.5 opacity: enabled ? 1.0 : 0.5
Keys.onSpacePressed: internal.pressButton() Keys.onSpacePressed: internal.userPressed = true
Keys.onReturnPressed: internal.pressButton() Keys.onReturnPressed: internal.userPressed = true
Keys.onReleased: { Keys.onReleased: {
internal.userPressed = false
if (event.key == Qt.Key_Space || if (event.key == Qt.Key_Space ||
event.key == Qt.Key_Return) event.key == Qt.Key_Return)
internal.releaseButton() internal.clickButton()
} }
QtObject { QtObject {
id: internal id: internal
property bool userPressed: false property bool userPressed: false
function pressButton() function clickButton()
{ {
userPressed = true
}
function releaseButton()
{
userPressed = false
if (!button.enabled) { if (!button.enabled) {
return return
} }
@ -229,9 +224,9 @@ Item {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
onPressed: internal.pressButton(); onPressed: internal.userPressed = true
onReleased: internal.userPressed = false
onReleased: internal.releaseButton(); onClicked: internal.clickButton()
} }
} }

View File

@ -60,12 +60,7 @@ Item {
&& button.parent.exclusive && button.parent.exclusive
} }
function pressButton() function clickButton()
{
userPressed = true
}
function releaseButton()
{ {
userPressed = false userPressed = false
if (!button.enabled) { if (!button.enabled) {
@ -81,12 +76,13 @@ Item {
} }
} }
Keys.onSpacePressed: internal.pressButton() Keys.onSpacePressed: internal.userPressed = true
Keys.onReturnPressed: internal.pressButton() Keys.onReturnPressed: internal.userPressed = true
Keys.onReleased: { Keys.onReleased: {
internal.userPressed = false
if (event.key == Qt.Key_Space || if (event.key == Qt.Key_Space ||
event.key == Qt.Key_Return) event.key == Qt.Key_Return)
internal.releaseButton(); internal.clickButton();
} }
ButtonShadow { ButtonShadow {
@ -210,8 +206,9 @@ Item {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
onPressed: internal.pressButton() onPressed: internal.userPressed = true
onReleased: internal.releaseButton() onReleased: internal.userPressed = false
onCanceled: internal.releaseButton() onCanceled: internal.userPressed = false
onClicked: internal.clickButton()
} }
} }

View File

@ -59,12 +59,13 @@ Item {
// disabled buttons // disabled buttons
opacity: enabled ? 1.0 : 0.5 opacity: enabled ? 1.0 : 0.5
Keys.onSpacePressed: internal.pressButton() Keys.onSpacePressed: internal.userPressed = true
Keys.onReturnPressed: internal.pressButton() Keys.onReturnPressed: internal.userPressed = true
Keys.onReleased: { Keys.onReleased: {
internal.userPressed = false
if (event.key == Qt.Key_Space || if (event.key == Qt.Key_Space ||
event.key == Qt.Key_Return) event.key == Qt.Key_Return)
internal.releaseButton() internal.clickButton()
} }
onActiveFocusChanged: { onActiveFocusChanged: {
@ -81,14 +82,8 @@ Item {
id: internal id: internal
property bool userPressed: false property bool userPressed: false
function pressButton() function clickButton()
{ {
userPressed = true
}
function releaseButton()
{
userPressed = false
if (!button.enabled) { if (!button.enabled) {
return return
} }
@ -186,9 +181,9 @@ Item {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
onPressed: internal.pressButton(); onPressed: internal.userPressed = true
onReleased: internal.userPressed = false
onReleased: internal.releaseButton(); onClicked: internal.clickButton()
onEntered: { onEntered: {
if (!flat) { if (!flat) {