on ccd07fa help sign in
unity8/qml/Components/WindowControlButtons.qml
142 lines 4.8 kB history raw
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 */
17import QtQuick 2.4
18import Ubuntu.Components 1.3
20Row {
21 id: root
22 spacing: overlayShown ? units.gu(2) : windowIsMaximized ? 0 : units.gu(1)
23 Behavior on spacing {
24 UbuntuNumberAnimation {}
25 }
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
35 signal closeClicked()
36 signal minimizeClicked()
37 signal maximizeClicked()
38 signal maximizeVerticallyClicked()
39 signal maximizeHorizontallyClicked()
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
50 // We dont want touch events to fall through to parent,
51 // otherwise the containsMouse will not work.
52 MouseArea {
53 anchors.fill: parent
54 propagateComposedEvents: true
55 }
57 Rectangle {
58 anchors.fill: parent
59 anchors.margins: windowIsMaximized ? units.dp(3) : 0
60 radius: height / 2
61 color: theme.palette.normal.negative
62 visible: parent.containsMouse && !overlayShown
63 }
64 Icon {
65 anchors.fill: parent
66 anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
67 source: "graphics/window-close.svg"
68 color: root.active ? "white" : UbuntuColors.slate
69 }
70 }
72 MouseArea {
73 id: minimizeWindowButton
74 objectName: "minimizeWindowButton"
75 hoverEnabled: true
76 height: parent.height
77 width: height
78 onClicked: root.minimizeClicked()
79 visible: root.minimizeButtonVisible
81 // We dont want touch events to fall through to parent,
82 // otherwise the containsMouse will not work.
83 MouseArea {
84 anchors.fill: parent
85 propagateComposedEvents: true
86 }
88 Rectangle {
89 anchors.fill: parent
90 anchors.margins: windowIsMaximized ? units.dp(3) : 0
91 radius: height / 2
92 color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
93 visible: parent.containsMouse && !overlayShown
94 }
95 Icon {
96 anchors.fill: parent
97 anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
98 source: "graphics/window-minimize.svg"
99 color: root.active ? "white" : UbuntuColors.slate
100 }
101 }
103 MouseArea {
104 id: maximizeWindowButton
105 objectName: "maximizeWindowButton"
106 hoverEnabled: true
107 height: parent.height
108 width: height
109 visible: root.maximizeButtonShown
110 acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
111 onClicked: {
112 if (mouse.button == Qt.LeftButton) {
113 root.maximizeClicked();
114 } else if (mouse.button == Qt.RightButton) {
115 root.maximizeHorizontallyClicked();
116 } else if (mouse.button == Qt.MiddleButton) {
117 root.maximizeVerticallyClicked();
118 }
119 }
121 // We dont want touch events to fall through to parent,
122 // otherwise the containsMouse will not work.
123 MouseArea {
124 anchors.fill: parent
125 propagateComposedEvents: true
126 }
128 Rectangle {
129 anchors.fill: parent
130 anchors.margins: windowIsMaximized ? units.dp(3) : 0
131 radius: height / 2
132 color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
133 visible: parent.containsMouse && !overlayShown
134 }
135 Icon {
136 anchors.fill: parent
137 anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
138 source: root.windowIsMaximized ? "graphics/window-window.svg" : "graphics/window-maximize.svg"
139 color: root.active ? "white" : UbuntuColors.slate
140 }
141 }