MauiKit Controls

BaseWindow.qml
1/*
2 * Copyright 2018 Camilo Higuita <milo.h@aol.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20import QtQuick
21
22import QtQuick.Window
23import QtQuick.Controls
24
25import Qt5Compat.GraphicalEffects
26
27import org.mauikit.controls as Maui
28
29/**
30 * @inherit QtQuick.Window
31 * @brief A base window implementation for window dialogs and the main application window.
32 * For using a detached dialog window use the WindowDialog control.
33 */
34
35ApplicationWindow
36{
37 id: root
38
39 visible: true
40
41 minimumHeight: Maui.Handy.isMobile ? 0 : Math.min(300, Screen.desktopAvailableHeight)
42 minimumWidth: Maui.Handy.isMobile ? 0 : Math.min(200, Screen.desktopAvailableWidth)
43
44 color: "transparent"
45 flags: Maui.CSD.enabled? (Qt.FramelessWindowHint | (root.isDialog ? Qt.Dialog : Qt.Window) ): ((root.isDialog ? Qt.Dialog : Qt.Window) & ~Qt.FramelessWindowHint)
47 // Window shadows for CSD
48 Loader
49 {
50 active: Maui.CSD.enabled && !Maui.Handy.isMobile && Maui.Handy.isLinux
51 asynchronous: true
52 sourceComponent: Maui.WindowShadow
53 {
54 view: root
55 radius: Maui.Style.radiusV
56 strength: 7.8
57 }
58 }
59
60 /***************************************************/
61 /********************* COLORS *********************/
62 /*************************************************/
63 Maui.Theme.colorSet: isDialog ? Maui.Theme.Window : Maui.Theme.Window
64
65 /**
66 * @brief Items to be placed inside the ApplicationWindow.
67 * This is used as the default container, and it helps to correctly mask the contents when using CSD with rounded border corners.
68 * @property list<QtObject> content
69 **/
70 default property alias content : _content.data
71
72 property bool isDialog : false
73
74 /***************************************************/
75 /**************** READONLY PROPS ******************/
76 /*************************************************/
77
78 /**
79 * @brief Determines when the application window size is wide enough.
80 * This property can be changed to any arbitrary condition. This will affect how some controls are positioned and displayed - as for a true wide value, it will assume there is more space to place contents, or for a `false` value it will work in the opposite way.
81 * Keep in mind this property is widely used in other MauiKit components to determined if items should be hidden, collapsed, or expanded, etc.
82 **/
83 property bool isWide : root.width >= Maui.Style.units.gridUnit * 30
84
85 /**
86 * @brief Convenient property to check if the application window surface is maximized.
87 **/
88 readonly property bool isMaximized: root.visibility === Window.Maximized
90 /**
91 * @brief Convenient property to check if the application window is in a full screen mode.
92 **/
93 readonly property bool isFullScreen: root.visibility === Window.FullScreen
94
95 /**
96 * @brief Convenient property to check if the application window is in portrait mode, otherwise it means it is in landscape mode.
97 **/
98 readonly property bool isPortrait: Screen.primaryOrientation === Qt.PortraitOrientation || Screen.primaryOrientation === Qt.InvertedPortraitOrientation
99
100 background: null
101
102 Item
103 {
104 id: _container
105 anchors.fill: parent
106 readonly property bool showBorders: Maui.CSD.enabled && root.visibility !== Window.FullScreen && !Maui.Handy.isMobile && root.visibility !== Window.Maximized
107
108 Item
109 {
110 id: _content
111 anchors.fill: parent
112 }
113
114 Loader
115 {
116 id: _toastAreaLoader
117 anchors.fill: parent
118 }
119
120 layer.enabled: _container.showBorders
121 layer.effect: OpacityMask
122 {
123 maskSource: Rectangle
124 {
125 width: _content.width
126 height: _content.height
127 radius: Maui.Style.radiusV
128 }
129 }
130 }
131
132 Loader
133 {
134 active: _container.showBorders
135 visible: active
136 z: Overlay.overlay.z
137 anchors.fill: parent
138 asynchronous: true
139
140 sourceComponent: Rectangle
141 {
142 radius: Maui.Style.radiusV
143 color: "transparent"
144 border.color: Qt.darker(Maui.Theme.backgroundColor, 3)
145 opacity: 0.7
146
147 Behavior on color
148 {
149 Maui.ColorTransition{}
150 }
151
152 Rectangle
153 {
154 anchors.fill: parent
155 anchors.margins: 1
156 color: "transparent"
157 radius: parent.radius
158 border.color: Qt.lighter(Maui.Theme.backgroundColor, 2)
159 opacity: 0.7
160
161 Behavior on color
162 {
163 Maui.ColorTransition{}
164 }
165 }
166 }
167 }
168
169 Loader
170 {
171 asynchronous: true
172 active: Maui.CSD.enabled
173 visible: active
174 height: 16
175 width: height
176 anchors.bottom: parent.bottom
177 anchors.left: parent.left
178
179 sourceComponent: Item
180 {
181 MouseArea
182 {
183 anchors.fill: parent
184 cursorShape: Qt.SizeBDiagCursor
185 acceptedButtons: Qt.NoButton // don't handle actual events
186 }
187
188 DragHandler
189 {
190 grabPermissions: TapHandler.TakeOverForbidden
191 target: null
192 onActiveChanged:
193 {
194 if (active)
195 {
196 root.startSystemResize(Qt.LeftEdge | Qt.BottomEdge);
197 }
198 }
199 }
200 }
201 }
202
203 Loader
204 {
205 asynchronous: true
206 active: Maui.CSD.enabled
207 visible: active
208 height: 16
209 width: height
210 anchors.bottom: parent.bottom
211 anchors.right: parent.right
212
213 sourceComponent: Item
214 {
215 MouseArea
216 {
217 anchors.fill: parent
218 cursorShape: Qt.SizeFDiagCursor
219 acceptedButtons: Qt.NoButton // don't handle actual events
220 }
221
222 DragHandler
223 {
224 grabPermissions: TapHandler.TakeOverForbidden
225 target: null
226 onActiveChanged:
227 {
228 if (active)
229 {
230 root.startSystemResize(Qt.RightEdge | Qt.BottomEdge)
231 }
232 }
233 }
234 }
235 }
236
237 Overlay.overlay.modal: Item
238 {
239 Rectangle
240 {
241 color: Maui.Theme.backgroundColor
242 anchors.fill: parent
243 opacity : 0.8
244 radius: Maui.Style.radiusV
245 }
246 }
247
248 Overlay.overlay.modeless: Rectangle
249 {
250 radius: Maui.Style.radiusV
251
252 color: Qt.rgba( root.Maui.Theme.backgroundColor.r, root.Maui.Theme.backgroundColor.g, root.Maui.Theme.backgroundColor.b, 0.7)
253 Behavior on opacity { NumberAnimation { duration: 150 } }
254
255 Behavior on color
256 {
257 Maui.ColorTransition{}
258 }
259 }
260
261 Component.onCompleted:
262 {
263 // Explicitly break the binding as we need this to be set only at startup.
264 // if the bindings are active, after this the window is resized by the
265 // compositor and then the bindings are reevaluated, then the window
266 // size would reset ignoring what the compositor asked.
267 // see BUG 433849
268 root.width = root.width;
269 root.height = root.height;
270 }
271
272 /**
273 * @brief Switch between maximized and normal state
274 **/
275 function toggleMaximized()
276 {
277 if (root.isMaximized)
278 {
279 root.showNormal();
280 } else
281 {
282 root.showMaximized();
283 }
284 }
285
286 /**
287 * @brief Switch between full-screen mode and normal mode
288 **/
289 function toggleFullscreen()
290 {
291 if (root.isFullScreen)
292 {
293 root.showNormal();
294 } else
295 {
296 root.showFullScreen()();
297 }
298 }
299
300 /**
301 * @brief Send an inline notification
302 * @param icon icon name to be used
303 * @param title the notification title
304 * @param body the message body of the notification
305 * @param callback a callback function to be triggered when the action button is pressed, this is represented as a button
306 * @param buttonText the text associated to the previous callback function, to be used in the button
307 **/
308 function notify(icon, title, body, callback, buttonText)
309 {
310 if(!_toastAreaLoader.item)
311 {
312 _toastAreaLoader.setSource("ToastArea.qml")
313 }
314 _toastAreaLoader.item.add(icon, title, body, callback, buttonText)
315 }
316}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.