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:
|
2012-01-07 16:25:21 +00:00
|
|
|
return decoration.closeable;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonMaximizeRestore:
|
2012-01-07 16:25:21 +00:00
|
|
|
return decoration.maximizeable;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonMinimize:
|
2012-01-07 16:25:21 +00:00
|
|
|
return decoration.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
|
|
|
|
decoration.menuClicked();
|
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonApplicationMenu:
|
2012-12-27 09:29:13 +00:00
|
|
|
// app menu
|
|
|
|
decoration.appMenuClicked();
|
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonOnAllDesktops:
|
2012-01-07 16:25:21 +00:00
|
|
|
// all desktops
|
|
|
|
decoration.toggleOnAllDesktops();
|
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonQuickHelp:
|
2012-01-07 16:25:21 +00:00
|
|
|
// help
|
|
|
|
decoration.showContextHelp();
|
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonMinimize:
|
2012-01-07 16:25:21 +00:00
|
|
|
// minimize
|
|
|
|
decoration.minimize();
|
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonMaximizeRestore:
|
2012-01-07 16:25:21 +00:00
|
|
|
// maximize
|
2012-01-08 10:36:04 +00:00
|
|
|
decoration.maximize(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
|
|
|
|
decoration.closeWindow();
|
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonKeepAbove:
|
2012-01-07 16:25:21 +00:00
|
|
|
// keep above
|
|
|
|
decoration.toggleKeepAbove();
|
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonKeepBelow:
|
2012-01-07 16:25:21 +00:00
|
|
|
// keep below
|
|
|
|
decoration.toggleKeepBelow();
|
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonShade:
|
2012-01-07 16:25:21 +00:00
|
|
|
// shade
|
|
|
|
decoration.toggleShade();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onDoubleClicked: {
|
2013-10-10 13:40:25 +00:00
|
|
|
if (button.buttonType == DecorationOptions.DecorationButtonMenu) {
|
2012-01-07 16:25:21 +00:00
|
|
|
decoration.closeWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
button.toggled = decoration.onAllDesktops;
|
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonKeepAbove:
|
2012-01-07 16:25:21 +00:00
|
|
|
button.toggled = decoration.keepAbove;
|
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonKeepBelow:
|
2012-01-07 16:25:21 +00:00
|
|
|
button.toggled = decoration.keepBelow;
|
|
|
|
break;
|
2013-10-10 13:40:25 +00:00
|
|
|
case DecorationOptions.DecorationButtonShade:
|
2012-01-07 16:25:21 +00:00
|
|
|
button.toggled = decoration.shade;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Connections {
|
|
|
|
target: decoration
|
|
|
|
onShadeChanged: {
|
2013-10-10 13:40:25 +00:00
|
|
|
if (button.buttonType != DecorationOptions.DecorationButtonShade) {
|
2012-01-07 16:25:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
button.toggled = decoration.shade;
|
|
|
|
}
|
|
|
|
onKeepBelowChanged: {
|
2013-10-10 13:40:25 +00:00
|
|
|
if (button.buttonType != DecorationOptions.DecorationButtonKeepBelow) {
|
2012-01-07 16:25:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
button.toggled = decoration.keepBelow;
|
|
|
|
}
|
|
|
|
onKeepAboveChanged: {
|
2013-10-10 13:40:25 +00:00
|
|
|
if (button.buttonType != DecorationOptions.DecorationButtonKeepAbove) {
|
2012-01-07 16:25:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
button.toggled = decoration.keepAbove;
|
|
|
|
}
|
|
|
|
onDesktopChanged: {
|
2013-10-10 13:40:25 +00:00
|
|
|
if (button.buttonType != DecorationOptions.DecorationButtonOnAllDesktops) {
|
2012-01-07 16:25:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
button.toggled = decoration.onAllDesktops;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|