From 5a00c8ec010d3c883dd9aaefc978b82d5229339f Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 8 Nov 2011 20:34:39 +0100 Subject: [PATCH] better shadow state chooser --- .../plasmacomponents/qml/Button.qml | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/declarativeimports/plasmacomponents/qml/Button.qml b/declarativeimports/plasmacomponents/qml/Button.qml index be87f67f5..72344b87a 100644 --- a/declarativeimports/plasmacomponents/qml/Button.qml +++ b/declarativeimports/plasmacomponents/qml/Button.qml @@ -45,6 +45,13 @@ Item { id: internal property bool userPressed: false + function belongsToButtonGroup() + { + return button.parent + && button.parent.hasOwnProperty("checkedButton") + && button.parent.exclusive + } + function pressButton() { userPressed = true @@ -57,7 +64,7 @@ Item { return } - if (button.checkable) { + if ((!belongsToButtonGroup() || !button.checked) && button.checkable) { button.checked = !button.checked } @@ -74,19 +81,20 @@ Item { internal.releaseButton(); } - onActiveFocusChanged: { - if (activeFocus) { - shadow.state = "focus" - } else if (checked) { - shadow.state = "hidden" - } else { - shadow.state = "shadow" - } - } - ButtonShadow { id: shadow anchors.fill: parent + state: { + if (internal.userPressed || checked) { + return "hidden" + } else if (mouse.containsMouse) { + return "hover" + } else if (button.activeFocus) { + return "focus" + } else { + return "shadow" + } + } } // The normal button state @@ -186,17 +194,5 @@ Item { hoverEnabled: true onPressed: internal.pressButton() onReleased: internal.releaseButton() - onEntered: { - shadow.state = "hover" - } - onExited: { - if (button.activeFocus) { - shadow.state = "focus" - } else if (checked) { - shadow.state = "hidden" - } else { - shadow.state = "shadow" - } - } } } \ No newline at end of file