Lomiri
Loading...
Searching...
No Matches
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
17import QtQuick 2.15
18import Lomiri.Components 1.3
19
20Row {
21 id: root
22 spacing: overlayShown ? units.gu(2) : windowIsMaximized ? 0 : units.gu(1)
23 Behavior on spacing {
24 LomiriNumberAnimation {}
25 }
26
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
34
35 readonly property color color: theme.palette.normal.baseText
36
37 signal closeClicked()
38 signal minimizeClicked()
39 signal maximizeClicked()
40 signal maximizeVerticallyClicked()
41 signal maximizeHorizontallyClicked()
42
43 MouseArea {
44 id: closeWindowButton
45 objectName: "closeWindowButton"
46 hoverEnabled: true
47 height: parent.height
48 width: height
49 onClicked: root.closeClicked()
50 visible: root.closeButtonShown
51
52 Rectangle {
53 anchors.fill: parent
54 anchors.margins: windowIsMaximized ? units.dp(3) : 0
55 radius: height / 2
56 color: theme.palette.normal.negative
57 visible: parent.containsMouse && !overlayShown
58 }
59 Icon {
60 anchors.fill: parent
61 anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
62 source: "graphics/window-close.svg"
63 color: root.active ? root.color : LomiriColors.jet
64 }
65 }
66
67 MouseArea {
68 id: minimizeWindowButton
69 objectName: "minimizeWindowButton"
70 hoverEnabled: true
71 height: parent.height
72 width: height
73 onClicked: root.minimizeClicked()
74 visible: root.minimizeButtonVisible
75
76 Rectangle {
77 anchors.fill: parent
78 anchors.margins: windowIsMaximized ? units.dp(3) : 0
79 radius: height / 2
80 color: root.active ? LomiriColors.graphite : LomiriColors.ash
81 visible: parent.containsMouse && !overlayShown
82 }
83 Icon {
84 anchors.fill: parent
85 anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
86 source: "graphics/window-minimize.svg"
87 color: root.active ? root.color : LomiriColors.slate
88 }
89 }
90
91 MouseArea {
92 id: maximizeWindowButton
93 objectName: "maximizeWindowButton"
94 hoverEnabled: true
95 height: parent.height
96 width: height
97 visible: root.maximizeButtonShown
98 acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
99 onClicked: {
100 if (mouse.button == Qt.LeftButton) {
101 root.maximizeClicked();
102 } else if (mouse.button == Qt.RightButton) {
103 root.maximizeHorizontallyClicked();
104 } else if (mouse.button == Qt.MiddleButton) {
105 root.maximizeVerticallyClicked();
106 }
107 }
108
109 Rectangle {
110 anchors.fill: parent
111 anchors.margins: windowIsMaximized ? units.dp(3) : 0
112 radius: height / 2
113 color: root.active ? LomiriColors.graphite : LomiriColors.ash
114 visible: parent.containsMouse && !overlayShown
115 }
116 Icon {
117 anchors.fill: parent
118 anchors.margins: windowIsMaximized ? units.dp(6) : units.dp(3)
119 source: root.windowIsMaximized ? "graphics/window-window.svg" : "graphics/window-maximize.svg"
120 color: root.active ? root.color : LomiriColors.slate
121 }
122 }
123}