Unity 8
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.4
18 import Ubuntu.Components 1.3
19 
20 Row {
21  id: root
22  spacing: overlayShown ? units.gu(2) : units.gu(1)
23  Behavior on spacing {
24  UbuntuNumberAnimation {}
25  }
26 
27  // to be set from outside
28  property Item target
29  property bool active: false
30  property bool windowIsMaximized: false
31  property bool closeButtonShown: true
32  property bool maximizeButtonShown: 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  radius: height / 2
53  color: theme.palette.normal.negative
54  visible: parent.containsMouse && !overlayShown
55  }
56  Icon {
57  anchors.fill: parent
58  anchors.margins: units.dp(3)
59  source: "graphics/window-close.svg"
60  color: root.active ? "white" : UbuntuColors.slate
61  }
62  }
63 
64  MouseArea {
65  id: minimizeWindowButton
66  objectName: "minimizeWindowButton"
67  hoverEnabled: true
68  height: parent.height
69  width: height
70  onClicked: root.minimizeClicked()
71 
72  Rectangle {
73  anchors.fill: parent
74  radius: height / 2
75  color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
76  visible: parent.containsMouse && !overlayShown
77  }
78  Icon {
79  anchors.fill: parent
80  anchors.margins: units.dp(3)
81  source: "graphics/window-minimize.svg"
82  color: root.active ? "white" : UbuntuColors.slate
83  }
84  }
85 
86  MouseArea {
87  id: maximizeWindowButton
88  objectName: "maximizeWindowButton"
89  hoverEnabled: true
90  height: parent.height
91  width: height
92  visible: root.maximizeButtonShown
93  acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
94  onClicked: {
95  if (mouse.button == Qt.LeftButton) {
96  root.maximizeClicked();
97  } else if (mouse.button == Qt.RightButton) {
98  root.maximizeHorizontallyClicked();
99  } else if (mouse.button == Qt.MiddleButton) {
100  root.maximizeVerticallyClicked();
101  }
102  }
103 
104  Rectangle {
105  anchors.fill: parent
106  radius: height / 2
107  color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
108  visible: parent.containsMouse && !overlayShown
109  }
110  Icon {
111  anchors.fill: parent
112  anchors.margins: units.dp(3)
113  source: root.windowIsMaximized ? "graphics/window-window.svg" : "graphics/window-maximize.svg"
114  color: root.active ? "white" : UbuntuColors.slate
115  }
116  }
117 }