2012-01-07 16:25:21 +00:00
|
|
|
/********************************************************************
|
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
2013-10-01 09:45:46 +00:00
|
|
|
import QtQuick 2.0
|
2013-10-10 13:40:25 +00:00
|
|
|
import org.kde.kwin.decoration 0.1
|
2012-01-07 16:25:21 +00:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: button
|
2013-10-10 13:40:25 +00:00
|
|
|
property int buttonType : DecorationOptions.DecorationButtonNone
|
2012-01-07 16:25:21 +00:00
|
|
|
property bool hovered: false
|
|
|
|
property bool pressed: false
|
|
|
|
property bool toggled: false
|
|
|
|
enabled: {
|
|
|
|
switch (button.buttonType) {
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonClose:
|
2014-10-24 11:48:31 +00:00
|
|
|
return decoration.client.closeable;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonMaximizeRestore:
|
2014-10-24 11:48:31 +00:00
|
|
|
return decoration.client.maximizeable;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonMinimize:
|
2014-10-24 11:48:31 +00:00
|
|
|
return decoration.client.minimizeable;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonExplicitSpacer:
|
2012-01-07 16:25:21 +00:00
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
acceptedButtons: {
|
|
|
|
switch (button.buttonType) {
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonMenu:
|
2012-01-07 16:25:21 +00:00
|
|
|
return Qt.LeftButton | Qt.RightButton;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonMaximizeRestore:
|
2012-01-07 16:25:21 +00:00
|
|
|
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) {
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonMenu:
|
2012-01-07 16:25:21 +00:00
|
|
|
// menu
|
2014-10-24 11:48:31 +00:00
|
|
|
decoration.requestShowWindowMenu();
|
2012-01-07 16:25:21 +00:00
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonApplicationMenu:
|
2012-12-27 09:29:13 +00:00
|
|
|
// app menu
|
2014-10-24 11:48:31 +00:00
|
|
|
// decoration.appMenuClicked();
|
2012-12-27 09:29:13 +00:00
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonOnAllDesktops:
|
2012-01-07 16:25:21 +00:00
|
|
|
// all desktops
|
2014-10-24 11:48:31 +00:00
|
|
|
decoration.requestToggleOnAllDesktops();
|
2012-01-07 16:25:21 +00:00
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonQuickHelp:
|
2012-01-07 16:25:21 +00:00
|
|
|
// help
|
2014-10-24 11:48:31 +00:00
|
|
|
decoration.requestContextHelp();
|
2012-01-07 16:25:21 +00:00
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonMinimize:
|
2012-01-07 16:25:21 +00:00
|
|
|
// minimize
|
2014-10-24 11:48:31 +00:00
|
|
|
decoration.requestMinimize();
|
2012-01-07 16:25:21 +00:00
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonMaximizeRestore:
|
2012-01-07 16:25:21 +00:00
|
|
|
// maximize
|
2014-11-11 12:20:15 +00:00
|
|
|
decoration.requestToggleMaximization(mouse.button);
|
2012-01-07 16:25:21 +00:00
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonClose:
|
2012-01-07 16:25:21 +00:00
|
|
|
// close
|
2014-10-24 11:48:31 +00:00
|
|
|
decoration.requestClose();
|
2012-01-07 16:25:21 +00:00
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonKeepAbove:
|
2012-01-07 16:25:21 +00:00
|
|
|
// keep above
|
2014-10-24 11:48:31 +00:00
|
|
|
decoration.requestToggleKeepAbove();
|
2012-01-07 16:25:21 +00:00
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonKeepBelow:
|
2012-01-07 16:25:21 +00:00
|
|
|
// keep below
|
2014-10-24 11:48:31 +00:00
|
|
|
decoration.requestToggleKeepBelow();
|
2012-01-07 16:25:21 +00:00
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonShade:
|
2012-01-07 16:25:21 +00:00
|
|
|
// shade
|
2014-10-24 11:48:31 +00:00
|
|
|
decoration.requestToggleShade();
|
2012-01-07 16:25:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onDoubleClicked: {
|
2013-10-10 13:40:25 +00:00
|
|
|
if (button.buttonType == DecorationOptions.DecorationButtonMenu) {
|
2014-10-24 11:48:31 +00:00
|
|
|
decoration.requestClose();
|
2012-01-07 16:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
|
|
switch (button.buttonType) {
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonOnAllDesktops:
|
2012-01-07 16:25:21 +00:00
|
|
|
// all desktops
|
2015-11-02 09:08:07 +00:00
|
|
|
button.toggled = Qt.binding(function() { return decoration.client.onAllDesktops; });
|
2012-01-07 16:25:21 +00:00
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonKeepAbove:
|
2015-11-02 09:08:07 +00:00
|
|
|
button.toggled = Qt.binding(function() { return decoration.client.keepAbove; });
|
2012-01-07 16:25:21 +00:00
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonKeepBelow:
|
2015-11-02 09:08:07 +00:00
|
|
|
button.toggled = Qt.binding(function() { return decoration.client.keepBelow; });
|
2012-01-07 16:25:21 +00:00
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonShade:
|
2015-11-02 09:08:07 +00:00
|
|
|
button.toggled = Qt.binding(function() { return decoration.client.shaded; });
|
2012-01-07 16:25:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|