kwin/clients/aurorae/src/qml/DecorationButton.qml
Martin Gräßlin e6542f01d3 [aurorae] Use property binding for toggled state
So far we manually updated the toggled state depending on the button
type and the corresponding client property. This had an error sneaked
in for onAllDesktops: it was bound to desktop change instead of on all
desktop change causing the button to not reflect the state correctly.

To prevent such errors it's now setup to a property binding to the
client's state directly.

BUG: 354702
FIXED-IN: 5.4.3
REVIEW: 125917
2015-11-02 10:11:32 +01:00

124 lines
4.9 KiB
QML

/********************************************************************
Copyright (C) 2012 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
import QtQuick 2.0
import org.kde.kwin.decoration 0.1
Item {
id: button
property int buttonType : DecorationOptions.DecorationButtonNone
property bool hovered: false
property bool pressed: false
property bool toggled: false
enabled: {
switch (button.buttonType) {
case DecorationOptions.DecorationButtonClose:
return decoration.client.closeable;
case DecorationOptions.DecorationButtonMaximizeRestore:
return decoration.client.maximizeable;
case DecorationOptions.DecorationButtonMinimize:
return decoration.client.minimizeable;
case DecorationOptions.DecorationButtonExplicitSpacer:
return false;
default:
return true;
}
}
MouseArea {
anchors.fill: parent
acceptedButtons: {
switch (button.buttonType) {
case DecorationOptions.DecorationButtonMenu:
return Qt.LeftButton | Qt.RightButton;
case DecorationOptions.DecorationButtonMaximizeRestore:
return Qt.LeftButton | Qt.RightButton | Qt.MiddleButton;
default:
return Qt.LeftButton;
}
}
hoverEnabled: true
onEntered: button.hovered = true
onExited: button.hovered = false
onPressed: button.pressed = true
onReleased: button.pressed = false
onClicked: {
switch (button.buttonType) {
case DecorationOptions.DecorationButtonMenu:
// menu
decoration.requestShowWindowMenu();
break;
case DecorationOptions.DecorationButtonApplicationMenu:
// app menu
// decoration.appMenuClicked();
break;
case DecorationOptions.DecorationButtonOnAllDesktops:
// all desktops
decoration.requestToggleOnAllDesktops();
break;
case DecorationOptions.DecorationButtonQuickHelp:
// help
decoration.requestContextHelp();
break;
case DecorationOptions.DecorationButtonMinimize:
// minimize
decoration.requestMinimize();
break;
case DecorationOptions.DecorationButtonMaximizeRestore:
// maximize
decoration.requestToggleMaximization(mouse.button);
break;
case DecorationOptions.DecorationButtonClose:
// close
decoration.requestClose();
break;
case DecorationOptions.DecorationButtonKeepAbove:
// keep above
decoration.requestToggleKeepAbove();
break;
case DecorationOptions.DecorationButtonKeepBelow:
// keep below
decoration.requestToggleKeepBelow();
break;
case DecorationOptions.DecorationButtonShade:
// shade
decoration.requestToggleShade();
break;
}
}
onDoubleClicked: {
if (button.buttonType == DecorationOptions.DecorationButtonMenu) {
decoration.requestClose();
}
}
Component.onCompleted: {
switch (button.buttonType) {
case DecorationOptions.DecorationButtonOnAllDesktops:
// all desktops
button.toggled = Qt.binding(function() { return decoration.client.onAllDesktops; });
break;
case DecorationOptions.DecorationButtonKeepAbove:
button.toggled = Qt.binding(function() { return decoration.client.keepAbove; });
break;
case DecorationOptions.DecorationButtonKeepBelow:
button.toggled = Qt.binding(function() { return decoration.client.keepBelow; });
break;
case DecorationOptions.DecorationButtonShade:
button.toggled = Qt.binding(function() { return decoration.client.shaded; });
break;
}
}
}
}