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 overlayShown
33 
34  signal closeClicked()
35  signal minimizeClicked()
36  signal maximizeClicked()
37  signal maximizeVerticallyClicked()
38  signal maximizeHorizontallyClicked()
39 
40  MouseArea {
41  id: closeWindowButton
42  objectName: "closeWindowButton"
43  hoverEnabled: true
44  height: parent.height
45  width: height
46  onClicked: root.closeClicked()
47  visible: root.closeButtonShown
48 
49  Rectangle {
50  anchors.fill: parent
51  radius: height / 2
52  color: theme.palette.normal.negative
53  visible: parent.containsMouse && !overlayShown
54  }
55  Icon {
56  anchors.fill: parent
57  anchors.margins: units.dp(3)
58  source: "graphics/window-close.svg"
59  color: root.active ? "white" : UbuntuColors.slate
60  }
61  }
62 
63  MouseArea {
64  id: minimizeWindowButton
65  objectName: "minimizeWindowButton"
66  hoverEnabled: true
67  height: parent.height
68  width: height
69  onClicked: root.minimizeClicked()
70 
71  Rectangle {
72  anchors.fill: parent
73  radius: height / 2
74  color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
75  visible: parent.containsMouse && !overlayShown
76  }
77  Icon {
78  anchors.fill: parent
79  anchors.margins: units.dp(3)
80  source: "graphics/window-minimize.svg"
81  color: root.active ? "white" : UbuntuColors.slate
82  }
83  }
84 
85  MouseArea {
86  id: maximizeWindowButton
87  objectName: "maximizeWindowButton"
88  hoverEnabled: true
89  height: parent.height
90  width: height
91  acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
92  onClicked: {
93  if (mouse.button == Qt.LeftButton) {
94  root.maximizeClicked();
95  } else if (mouse.button == Qt.RightButton) {
96  root.maximizeHorizontallyClicked();
97  } else if (mouse.button == Qt.MiddleButton) {
98  root.maximizeVerticallyClicked();
99  }
100  }
101 
102  Rectangle {
103  anchors.fill: parent
104  radius: height / 2
105  color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
106  visible: parent.containsMouse && !overlayShown
107  }
108  Icon {
109  anchors.fill: parent
110  anchors.margins: units.dp(3)
111  source: root.windowIsMaximized ? "graphics/window-window.svg" : "graphics/window-maximize.svg"
112  color: root.active ? "white" : UbuntuColors.slate
113  }
114  }
115 }