on 3610fcc help sign in
unity8/qml/Components/WindowControlButtons.qml
140 lines 4.7 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 overlayShown
34 signal closeClicked()
35 signal minimizeClicked()
36 signal maximizeClicked()
37 signal maximizeVerticallyClicked()
38 signal maximizeHorizontallyClicked()
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
49 // We dont want touch events to fall through to parent,
50 // otherwise the containsMouse will not work.
51 MouseArea {
52 anchors.fill: parent
53 propagateComposedEvents: true
54 }
56 Rectangle {
57 anchors.fill: parent
58 anchors.margins: windowIsMaximized ? units.dp(3) : 0
59 radius: height / 2
60 color: theme.palette.normal.negative
61 visible: parent.containsMouse && !overlayShown
62 }
63 Icon {
64 anchors.fill: parent
65 anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
66 source: "graphics/window-close.svg"
67 color: root.active ? "white" : UbuntuColors.slate
68 }
69 }
71 MouseArea {
72 id: minimizeWindowButton
73 objectName: "minimizeWindowButton"
74 hoverEnabled: true
75 height: parent.height
76 width: height
77 onClicked: root.minimizeClicked()
79 // We dont want touch events to fall through to parent,
80 // otherwise the containsMouse will not work.
81 MouseArea {
82 anchors.fill: parent
83 propagateComposedEvents: true
84 }
86 Rectangle {
87 anchors.fill: parent
88 anchors.margins: windowIsMaximized ? units.dp(3) : 0
89 radius: height / 2
90 color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
91 visible: parent.containsMouse && !overlayShown
92 }
93 Icon {
94 anchors.fill: parent
95 anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
96 source: "graphics/window-minimize.svg"
97 color: root.active ? "white" : UbuntuColors.slate
98 }
99 }
101 MouseArea {
102 id: maximizeWindowButton
103 objectName: "maximizeWindowButton"
104 hoverEnabled: true
105 height: parent.height
106 width: height
107 visible: root.maximizeButtonShown
108 acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
109 onClicked: {
110 if (mouse.button == Qt.LeftButton) {
111 root.maximizeClicked();
112 } else if (mouse.button == Qt.RightButton) {
113 root.maximizeHorizontallyClicked();
114 } else if (mouse.button == Qt.MiddleButton) {
115 root.maximizeVerticallyClicked();
116 }
117 }
119 // We dont want touch events to fall through to parent,
120 // otherwise the containsMouse will not work.
121 MouseArea {
122 anchors.fill: parent
123 propagateComposedEvents: true
124 }
126 Rectangle {
127 anchors.fill: parent
128 anchors.margins: windowIsMaximized ? units.dp(3) : 0
129 radius: height / 2
130 color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
131 visible: parent.containsMouse && !overlayShown
132 }
133 Icon {
134 anchors.fill: parent
135 anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
136 source: root.windowIsMaximized ? "graphics/window-window.svg" : "graphics/window-maximize.svg"
137 color: root.active ? "white" : UbuntuColors.slate
138 }
139 }