From f96f5c979ecc888e313e4aac81178ab27404a3f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 10 Jan 2012 19:26:59 +0100 Subject: [PATCH] Better Maximized/Restore button Use just one button with the two variants embedded. Makes the state transitions more robust. --- clients/aurorae/src/CMakeLists.txt | 1 + clients/aurorae/src/qml/AuroraeButton.qml | 20 ------ .../aurorae/src/qml/AuroraeButtonGroup.qml | 6 +- .../aurorae/src/qml/AuroraeMaximizeButton.qml | 66 +++++++++++++++++++ 4 files changed, 70 insertions(+), 23 deletions(-) create mode 100644 clients/aurorae/src/qml/AuroraeMaximizeButton.qml diff --git a/clients/aurorae/src/CMakeLists.txt b/clients/aurorae/src/CMakeLists.txt index cee7f85397..d74aa0f677 100644 --- a/clients/aurorae/src/CMakeLists.txt +++ b/clients/aurorae/src/CMakeLists.txt @@ -21,6 +21,7 @@ install( FILES qml/aurorae.qml qml/AuroraeButton.qml qml/AuroraeButtonGroup.qml + qml/AuroraeMaximizeButton.qml qml/Decoration.qml qml/DecorationButton.qml qml/MenuButton.qml diff --git a/clients/aurorae/src/qml/AuroraeButton.qml b/clients/aurorae/src/qml/AuroraeButton.qml index cba1a7d447..5a1d6f4d46 100644 --- a/clients/aurorae/src/qml/AuroraeButton.qml +++ b/clients/aurorae/src/qml/AuroraeButton.qml @@ -193,9 +193,6 @@ DecorationButton { } else { visible = buttonSvg.imagePath != ""; } - if (buttonType == "R") { - visible = decoration.maximized; - } } onHoveredChanged: { if (state == "active-pressed" || state == "inactive-pressed") { @@ -331,22 +328,5 @@ DecorationButton { state = "active"; } } - onMaximizedChanged: { - if (buttonType != "A" && buttonType != "R") { - return; - } - if (auroraeTheme.restoreButtonPath != "") { - if (buttonType == "A") { - visible = !decoration.maximized; - } else if (buttonType == "R") { - visible = decoration.maximized; - } - if (!decoration.active && buttonSvg.supportsInactive) { - state = "inactive"; - } else { - state = "active"; - } - } - } } } diff --git a/clients/aurorae/src/qml/AuroraeButtonGroup.qml b/clients/aurorae/src/qml/AuroraeButtonGroup.qml index dd28b9c99b..78eaf25bfa 100644 --- a/clients/aurorae/src/qml/AuroraeButtonGroup.qml +++ b/clients/aurorae/src/qml/AuroraeButtonGroup.qml @@ -35,11 +35,11 @@ Item { } else if (buttons.charAt(i) == "M") { Qt.createQmlObject("import QtQuick 1.1; MenuButton { width: auroraeTheme.buttonWidthMenu; height: auroraeTheme.buttonHeight }", groupRow, "menuButton" + buttons + i); + } else if (buttons.charAt(i) == "A") { + var maximizeComponent = Qt.createComponent("AuroraeMaximizeButton.qml"); + maximizeComponent.createObject(groupRow); } else { component.createObject(groupRow, {buttonType: buttons.charAt(i)}); - if (buttons.charAt(i) == "A") { - component.createObject(groupRow, {buttonType: "R"}); - } } } } diff --git a/clients/aurorae/src/qml/AuroraeMaximizeButton.qml b/clients/aurorae/src/qml/AuroraeMaximizeButton.qml new file mode 100644 index 0000000000..024707ba96 --- /dev/null +++ b/clients/aurorae/src/qml/AuroraeMaximizeButton.qml @@ -0,0 +1,66 @@ +/******************************************************************** +Copyright (C) 2012 Martin Gräßlin + +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 . +*********************************************************************/ +import QtQuick 1.1 + +Item { + function checkState() { + if (decoration.maximized && auroraeTheme.restoreButtonPath != "") { + button.state = "restore"; + } else { + button.state = "maximize"; + } + } + id: button + width: auroraeTheme.buttonWidthMaximizeRestore + height: auroraeTheme.buttonHeight + states: [ + State { name: "maximize" }, + State { name: "restore" } + ] + AuroraeButton { + id: maximizeButton + anchors.fill: parent + buttonType: "A" + } + AuroraeButton { + id: restoreButton + anchors.fill: parent + buttonType: "R" + opacity: 0 + } + transitions: [ + Transition { + to: "maximize" + ParallelAnimation { + NumberAnimation { target: maximizeButton; property: "opacity"; to: 1; duration: auroraeTheme.animationTime } + NumberAnimation { target: restoreButton; property: "opacity"; to: 0; duration: auroraeTheme.animationTime } + } + }, + Transition { + to: "restore" + ParallelAnimation { + NumberAnimation { target: maximizeButton; property: "opacity"; to: 0; duration: auroraeTheme.animationTime } + NumberAnimation { target: restoreButton; property: "opacity"; to: 1; duration: auroraeTheme.animationTime } + } + } + ] + Connections { + target: decoration + onMaximizedChanged: button.checkState() + } + Component.onCompleted: button.checkState() +}