on 16fa310 help sign in
unity8/qml/Components/WindowControlButtons.qml
119 lines 4.0 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 Rectangle {
50 anchors.fill: parent
51 anchors.margins: windowIsMaximized ? units.dp(3) : 0
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: windowIsMaximized ? units.dp(6) : units.dp(3)
59 source: "graphics/window-close.svg"
60 color: root.active ? "white" : UbuntuColors.slate
61 }
62 }
64 MouseArea {
65 id: minimizeWindowButton
66 objectName: "minimizeWindowButton"
67 hoverEnabled: true
68 height: parent.height
69 width: height
70 onClicked: root.minimizeClicked()
72 Rectangle {
73 anchors.fill: parent
74 anchors.margins: windowIsMaximized ? units.dp(3) : 0
75 radius: height / 2
76 color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
77 visible: parent.containsMouse && !overlayShown
78 }
79 Icon {
80 anchors.fill: parent
81 anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
82 source: "graphics/window-minimize.svg"
83 color: root.active ? "white" : UbuntuColors.slate
84 }
85 }
87 MouseArea {
88 id: maximizeWindowButton
89 objectName: "maximizeWindowButton"
90 hoverEnabled: true
91 height: parent.height
92 width: height
93 visible: root.maximizeButtonShown
94 acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
95 onClicked: {
96 if (mouse.button == Qt.LeftButton) {
97 root.maximizeClicked();
98 } else if (mouse.button == Qt.RightButton) {
99 root.maximizeHorizontallyClicked();
100 } else if (mouse.button == Qt.MiddleButton) {
101 root.maximizeVerticallyClicked();
102 }
103 }
105 Rectangle {
106 anchors.fill: parent
107 anchors.margins: windowIsMaximized ? units.dp(3) : 0
108 radius: height / 2
109 color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
110 visible: parent.containsMouse && !overlayShown
111 }
112 Icon {
113 anchors.fill: parent
114 anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
115 source: root.windowIsMaximized ? "graphics/window-window.svg" : "graphics/window-maximize.svg"
116 color: root.active ? "white" : UbuntuColors.slate
117 }
118 }