Lomiri
WindowControlButtons.qml
1 /*
2  * Copyright (C) 2014-2016 Canonical Ltd.
3  *
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
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
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/>.
15  */
16 
17 import QtQuick 2.12
18 import Lomiri.Components 1.3
19 
20 Row {
21  id: root
22  spacing: overlayShown ? units.gu(2) : windowIsMaximized ? 0 : units.gu(1)
23  Behavior on spacing {
24  LomiriNumberAnimation {}
25  }
26 
27  // to be set from outside
28  property bool active: false
29  property bool windowIsMaximized: false
30  property bool closeButtonShown: true
31  property bool maximizeButtonShown: true
32  property bool minimizeButtonVisible: true
33  property bool overlayShown
34 
35  signal closeClicked()
36  signal minimizeClicked()
37  signal maximizeClicked()
38  signal maximizeVerticallyClicked()
39  signal maximizeHorizontallyClicked()
40 
41  MouseArea {
42  id: closeWindowButton
43  objectName: "closeWindowButton"
44  hoverEnabled: true
45  height: parent.height
46  width: height
47  onClicked: root.closeClicked()
48  visible: root.closeButtonShown
49 
50  Rectangle {
51  anchors.fill: parent
52  anchors.margins: windowIsMaximized ? units.dp(3) : 0
53  radius: height / 2
54  color: theme.palette.normal.negative
55  visible: parent.containsMouse && !overlayShown
56  }
57  Icon {
58  anchors.fill: parent
59  anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
60  source: "graphics/window-close.svg"
61  color: root.active ? "white" : LomiriColors.slate
62  }
63  }
64 
65  MouseArea {
66  id: minimizeWindowButton
67  objectName: "minimizeWindowButton"
68  hoverEnabled: true
69  height: parent.height
70  width: height
71  onClicked: root.minimizeClicked()
72  visible: root.minimizeButtonVisible
73 
74  Rectangle {
75  anchors.fill: parent
76  anchors.margins: windowIsMaximized ? units.dp(3) : 0
77  radius: height / 2
78  color: root.active ? LomiriColors.graphite : LomiriColors.ash
79  visible: parent.containsMouse && !overlayShown
80  }
81  Icon {
82  anchors.fill: parent
83  anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
84  source: "graphics/window-minimize.svg"
85  color: root.active ? "white" : LomiriColors.slate
86  }
87  }
88 
89  MouseArea {
90  id: maximizeWindowButton
91  objectName: "maximizeWindowButton"
92  hoverEnabled: true
93  height: parent.height
94  width: height
95  visible: root.maximizeButtonShown
96  acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
97  onClicked: {
98  if (mouse.button == Qt.LeftButton) {
99  root.maximizeClicked();
100  } else if (mouse.button == Qt.RightButton) {
101  root.maximizeHorizontallyClicked();
102  } else if (mouse.button == Qt.MiddleButton) {
103  root.maximizeVerticallyClicked();
104  }
105  }
106 
107  Rectangle {
108  anchors.fill: parent
109  anchors.margins: windowIsMaximized ? units.dp(3) : 0
110  radius: height / 2
111  color: root.active ? LomiriColors.graphite : LomiriColors.ash
112  visible: parent.containsMouse && !overlayShown
113  }
114  Icon {
115  anchors.fill: parent
116  anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
117  source: root.windowIsMaximized ? "graphics/window-window.svg" : "graphics/window-maximize.svg"
118  color: root.active ? "white" : LomiriColors.slate
119  }
120  }
121 }