on 28d9cb4 help sign in
unity8/qml/Components/WindowControlButtons.qml
117 lines 3.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) : units.gu(1)
23 Behavior on spacing {
24 UbuntuNumberAnimation {}
25 }
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 maximizeButtonShown: 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 Rectangle {
51 anchors.fill: parent
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: 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 radius: height / 2
75 color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
76 visible: parent.containsMouse && !overlayShown
77 }
78 Icon {
79 anchors.fill: parent
80 anchors.margins: units.dp(3)
81 source: "graphics/window-minimize.svg"
82 color: root.active ? "white" : UbuntuColors.slate
83 }
84 }
86 MouseArea {
87 id: maximizeWindowButton
88 objectName: "maximizeWindowButton"
89 hoverEnabled: true
90 height: parent.height
91 width: height
92 visible: root.maximizeButtonShown
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 }
104 Rectangle {
105 anchors.fill: parent
106 radius: height / 2
107 color: root.active ? UbuntuColors.graphite : UbuntuColors.ash
108 visible: parent.containsMouse && !overlayShown
109 }
110 Icon {
111 anchors.fill: parent
112 anchors.margins: units.dp(3)
113 source: root.windowIsMaximized ? "graphics/window-window.svg" : "graphics/window-maximize.svg"
114 color: root.active ? "white" : UbuntuColors.slate
115 }
116 }