Unity 8
WindowControlButtons.qml
1 /*
2  * Copyright (C) 2014-2015 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: units.gu(1)
23 
24  // to be set from outside
25  property bool active: false
26  property bool closeButtonShown: true
27 
28  signal closeClicked()
29  signal minimizeClicked()
30  signal maximizeClicked()
31  signal maximizeVerticallyClicked()
32  signal maximizeHorizontallyClicked()
33 
34  MouseArea {
35  id: closeWindowButton
36  objectName: "closeWindowButton"
37  hoverEnabled: true
38  height: parent.height
39  width: height
40  onClicked: root.closeClicked()
41  visible: root.closeButtonShown
42 
43  Rectangle {
44  anchors.centerIn: parent
45  width: units.gu(2)
46  height: units.gu(2)
47  radius: height / 2
48  color: theme.palette.normal.negative
49  visible: parent.containsMouse
50  }
51  Icon {
52  width: height
53  height: parent.height *.5
54  anchors.centerIn: parent
55  source: "graphics/window-close.svg"
56  color: root.active ? "white" : UbuntuColors.slate
57  keyColor: "black"
58  }
59  }
60 
61  MouseArea {
62  id: minimizeWindowButton
63  objectName: "minimizeWindowButton"
64  hoverEnabled: true
65  height: parent.height
66  width: height
67  onClicked: root.minimizeClicked()
68 
69  Rectangle {
70  anchors.centerIn: parent
71  width: units.gu(2)
72  height: units.gu(2)
73  radius: height / 2
74  color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
75  visible: parent.containsMouse
76  }
77  Icon {
78  width: height
79  height: parent.height *.5
80  anchors.centerIn: parent
81  source: "graphics/window-minimize.svg"
82  color: root.active ? "white" : UbuntuColors.slate
83  keyColor: "black"
84  }
85  }
86 
87  MouseArea {
88  id: maximizeWindowButton
89  objectName: "maximizeWindowButton"
90  hoverEnabled: true
91  height: parent.height
92  width: height
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.centerIn: parent
106  width: units.gu(2)
107  height: units.gu(2)
108  radius: height / 2
109  color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
110  visible: parent.containsMouse
111  }
112  Icon {
113  width: height
114  height: parent.height *.5
115  anchors.centerIn: parent
116  source: "graphics/window-maximize.svg"
117  color: root.active ? "white" : UbuntuColors.slate
118  keyColor: "black"
119  }
120  }
121 }