on xenial help sign in
Hide the maximize window button based on size restrictions (LP: #1541982)
e910467Lukáš Tinkl
qml/Components/WindowControlButtons.qml+2
@@ -29,6 +29,7 @@ Row {
29 property bool active: false
29 property bool active: false
30 property bool windowIsMaximized: false
30 property bool windowIsMaximized: false
31 property bool closeButtonShown: true
31 property bool closeButtonShown: true
32+ property bool maximizeButtonShown: true
32 property bool overlayShown
33 property bool overlayShown
33
34
34 signal closeClicked()
35 signal closeClicked()
@@ -88,6 +89,7 @@ Row {
88 hoverEnabled: true
89 hoverEnabled: true
89 height: parent.height
90 height: parent.height
90 width: height
91 width: height
92+ visible: root.maximizeButtonShown
91 acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
93 acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
92 onClicked: {
94 onClicked: {
93 if (mouse.button == Qt.LeftButton) {
95 if (mouse.button == Qt.LeftButton) {
qml/Stages/DecoratedWindow.qml+5−4
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2014-2015 Canonical, Ltd.
2+ * Copyright (C) 2014-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -12,8 +12,6 @@
12 *
12 *
13 * You should have received a copy of the GNU General Public License
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors: Michael Zanetti <michael.zanetti@canonical.com>
17 */
15 */
18
16
19import QtQuick 2.4
17import QtQuick 2.4
@@ -31,6 +29,7 @@ FocusScope {
31 property alias active: decoration.active
29 property alias active: decoration.active
32 readonly property alias title: applicationWindow.title
30 readonly property alias title: applicationWindow.title
33 property alias fullscreen: applicationWindow.fullscreen
31 property alias fullscreen: applicationWindow.fullscreen
32+ property alias maximizeButtonShown: decoration.maximizeButtonShown
34
33
35 readonly property bool decorationShown: !fullscreen
34 readonly property bool decorationShown: !fullscreen
36 property bool highlightShown: false
35 property bool highlightShown: false
@@ -38,6 +37,7 @@ FocusScope {
38
37
39 property real requestedWidth
38 property real requestedWidth
40 property real requestedHeight
39 property real requestedHeight
40+
41 property alias surfaceOrientationAngle: applicationWindow.surfaceOrientationAngle
41 property alias surfaceOrientationAngle: applicationWindow.surfaceOrientationAngle
42 readonly property real visibleDecorationHeight: root.decorationShown ? decoration.height : 0
42 readonly property real visibleDecorationHeight: root.decorationShown ? decoration.height : 0
43 readonly property bool counterRotate: surfaceOrientationAngle != 0 && surfaceOrientationAngle != 180
43 readonly property bool counterRotate: surfaceOrientationAngle != 0 && surfaceOrientationAngle != 180
@@ -45,7 +45,8 @@ FocusScope {
45 readonly property int minimumWidth: !counterRotate ? applicationWindow.minimumWidth : applicationWindow.minimumHeight
45 readonly property int minimumWidth: !counterRotate ? applicationWindow.minimumWidth : applicationWindow.minimumHeight
46 readonly property int minimumHeight: visibleDecorationHeight + (!counterRotate ? applicationWindow.minimumHeight : applicationWindow.minimumWidth)
46 readonly property int minimumHeight: visibleDecorationHeight + (!counterRotate ? applicationWindow.minimumHeight : applicationWindow.minimumWidth)
47 readonly property int maximumWidth: !counterRotate ? applicationWindow.maximumWidth : applicationWindow.maximumHeight
47 readonly property int maximumWidth: !counterRotate ? applicationWindow.maximumWidth : applicationWindow.maximumHeight
48+ readonly property int maximumHeight: (root.decorationShown && applicationWindow.maximumHeight > 0 ? decoration.height : 0)
48− readonly property int maximumHeight: visibleDecorationHeight + (!counterRotate ? applicationWindow.maximumHeight : applicationWindow.maximumWidth)
49+ + (!counterRotate ? applicationWindow.maximumHeight : applicationWindow.maximumWidth)
49 readonly property int widthIncrement: !counterRotate ? applicationWindow.widthIncrement : applicationWindow.heightIncrement
50 readonly property int widthIncrement: !counterRotate ? applicationWindow.widthIncrement : applicationWindow.heightIncrement
50 readonly property int heightIncrement: !counterRotate ? applicationWindow.heightIncrement : applicationWindow.widthIncrement
51 readonly property int heightIncrement: !counterRotate ? applicationWindow.heightIncrement : applicationWindow.widthIncrement
51
52
qml/Stages/DesktopStage.qml+2
@@ -654,6 +654,8 @@ AbstractStage {
654 surface: model.surface
654 surface: model.surface
655 active: appDelegate.focus
655 active: appDelegate.focus
656 focus: true
656 focus: true
657+ maximizeButtonShown: (maximumWidth == 0 || maximumWidth >= appContainer.width) &&
658+ (maximumHeight == 0 || maximumHeight >= appContainer.height)
657 overlayShown: touchControls.overlayShown
659 overlayShown: touchControls.overlayShown
658
660
659 requestedWidth: appDelegate.requestedWidth
661 requestedWidth: appDelegate.requestedWidth
qml/Stages/WindowDecoration.qml+2−1
@@ -26,6 +26,7 @@ MouseArea {
26
26
27 property Item target
27 property Item target
28 property alias title: titleLabel.text
28 property alias title: titleLabel.text
29+ property alias maximizeButtonShown: buttons.maximizeButtonShown
29 property bool active: false
30 property bool active: false
30 acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
31 acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
31 property alias overlayShown: buttons.overlayShown
32 property alias overlayShown: buttons.overlayShown
@@ -37,7 +38,7 @@ MouseArea {
37 signal maximizeVerticallyClicked()
38 signal maximizeVerticallyClicked()
38
39
39 onDoubleClicked: {
40 onDoubleClicked: {
40− if (mouse.button == Qt.LeftButton) {
41+ if (maximizeButtonShown && mouse.button == Qt.LeftButton) {
41 root.maximizeClicked();
42 root.maximizeClicked();
42 }
43 }
43 }
44 }
tests/qmltests/Stages/tst_DesktopStage.qml+26
@@ -691,6 +691,32 @@ Item {
691 tryCompare(closeButton, "visible", false);
691 tryCompare(closeButton, "visible", false);
692 }
692 }
693
693
694+ function test_hideMaximizeButtonWhenSizeConstrained() {
695+ var dialerDelegate = startApplication("dialer-app");
696+
697+ var dialerMaximizeButton = findChild(dialerDelegate, "maximizeWindowButton");
698+ tryCompare(dialerMaximizeButton, "visible", true);
699+
700+ // add size restrictions, smaller than our stage
701+ dialerDelegate.surface.setMaximumWidth(40);
702+ dialerDelegate.surface.setMaximumHeight(30);
703+ tryCompare(dialerMaximizeButton, "visible", false);
704+
705+ // try double clicking the decoration, shouldn't maximize it
706+ var sizeBefore = Qt.size(dialerDelegate.width, dialerDelegate.height);
707+ var deco = findChild(dialerDelegate, "appWindowDecoration");
708+ verify(deco);
709+ tryCompare(deco, "maximizeButtonShown", false);
710+ mouseDoubleClick(deco);
711+ var sizeAfter = Qt.size(dialerDelegate.width, dialerDelegate.height);
712+ tryCompareFunction(function(){ return sizeBefore; }, sizeAfter);
713+
714+ // remove restrictions, the maximize button should again be visible
715+ dialerDelegate.surface.setMaximumWidth(0);
716+ dialerDelegate.surface.setMaximumHeight(0);
717+ tryCompare(dialerMaximizeButton, "visible", true);
718+ }
719+
694 function test_canMoveWindowWithLeftMouseButtonOnly_data() {
720 function test_canMoveWindowWithLeftMouseButtonOnly_data() {
695 return [
721 return [
696 {tag: "left mouse button", button: Qt.LeftButton },
722 {tag: "left mouse button", button: Qt.LeftButton },