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
24import QtQuick.Layouts
25
26import QtQuick.Effects
27
28import org.mauikit.controls as Maui
29
30/**
31 * @inherit QtQuick.Window
32 * @brief A base window implementation for window dialogs and the main application window.
33 * For using a detached dialog window use the WindowDialog control.
34 */
35ApplicationWindow
36{
37 id: control
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 | (control.isDialog ? Qt.Dialog : Qt.Window) ): ((control.isDialog ? Qt.Dialog : Qt.Window) & ~Qt.FramelessWindowHint)
46
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: control
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
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 : control.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: control.visibility === Window.Maximized
89
90 /**
91 * @brief Convenient property to check if the application window is in a full screen mode.
92 **/
93 readonly property bool isFullScreen: control.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 readonly property bool canResizeH: control.width !== control.maximumWidth || control.width !== control.minimumWidth
101 readonly property bool canResizeV: control.height !== control.maximumHeight || control.height !== control.maximumHeight
102
103 background: null
105 Item
106 {
107 id: _container
108 anchors.fill: parent
109 readonly property bool showBorders: Maui.CSD.enabled && control.visibility !== Window.FullScreen && !Maui.Handy.isMobile && control.visibility !== Window.Maximized
110
111 Item
112 {
113 id: _content
114 anchors.fill: parent
115 }
116
117 Loader
118 {
119 id: _toastAreaLoader
120 anchors.fill: parent
121 }
122
123 layer.enabled: GraphicsInfo.api !== GraphicsInfo.Software && _container.showBorders
124 layer.effect: MultiEffect
125 {
126 maskEnabled: true
127 maskThresholdMin: 0.5
128 maskSpreadAtMin: 1.0
129 maskSpreadAtMax: 0.0
130 maskThresholdMax: 1.0
131 maskSource: ShaderEffectSource
132 {
133 sourceItem: Rectangle
134 {
135 x: _container.x
136 y: _container.y
137 width: _container.width
138 height: _container.height
139 radius: Maui.Style.radiusV
140 }
141 }
142 }
143 }
144
145 Loader
146 {
147 active: _container.showBorders
148 visible: active
149 z: Overlay.overlay.z
150 anchors.fill: parent
151 asynchronous: true
152
153 sourceComponent: Rectangle
154 {
155 radius: Maui.Style.radiusV
156 color: "transparent"
157 border.color: Qt.darker(Maui.Theme.backgroundColor, 3)
158 opacity: 0.7
159
160 Behavior on color
161 {
162 Maui.ColorTransition{}
163 }
164
165 Rectangle
166 {
167 anchors.fill: parent
168 anchors.margins: 1
169 color: "transparent"
170 radius: parent.radius
171 border.color: Qt.lighter(Maui.Theme.backgroundColor, 2)
172 opacity: 0.7
173
174 Behavior on color
175 {
176 Maui.ColorTransition{}
177 }
178 }
179 }
180 }
181
182 Loader
183 {
184 asynchronous: true
185 active: Maui.CSD.enabled
186 visible: active
187 anchors.fill: parent
188
189 sourceComponent: WindowResizeHandlers
190 {
191
192 }
193 }
194
195
196 Overlay.overlay.modal: Item
197 {
198 Rectangle
199 {
200 color: Maui.Theme.backgroundColor
201 anchors.fill: parent
202 opacity : 0.8
203 radius: Maui.Style.radiusV
204 Behavior on color
205 {
206 Maui.ColorTransition{}
207 }
208 }
209 }
210
211 Overlay.overlay.modeless: Rectangle
212 {
213 radius: Maui.Style.radiusV
214
215 color: Qt.rgba( control.Maui.Theme.backgroundColor.r, control.Maui.Theme.backgroundColor.g, control.Maui.Theme.backgroundColor.b, 0.7)
216 Behavior on opacity { NumberAnimation { duration: 150 } }
217
218 Behavior on color
219 {
220 Maui.ColorTransition{}
221 }
222 }
223
224 Component.onCompleted:
225 {
226 // Explicitly break the binding as we need this to be set only at startup.
227 // if the bindings are active, after this the window is resized by the
228 // compositor and then the bindings are reevaluated, then the window
229 // size would reset ignoring what the compositor asked.
230 // see BUG 433849
231 control.width = control.width;
232 control.height = control.height;
233 }
234
235 /**
236 * @brief Switch between maximized and normal state
237 **/
238 function toggleMaximized()
239 {
240 if (control.isMaximized)
241 {
242 control.showNormal();
243 } else
244 {
245 control.showMaximized();
246 }
247 }
248
249 /**
250 * @brief Switch between full-screen mode and normal mode
251 **/
252 function toggleFullscreen()
253 {
254 if (control.isFullScreen)
255 {
256 control.showNormal();
257 } else
258 {
259 control.showFullScreen()();
260 }
261 }
262
263 /**
264 * @brief Send an inline notification
265 * @param icon icon name to be used
266 * @param title the notification title
267 * @param body the message body of the notification
268 * @param actions a list of possible callback actions, this is represented as a button
269 **/
270 function notify(icon, title, body, actions)
271 {
272 if(!_toastAreaLoader.item)
273 {
274 _toastAreaLoader.setSource("ToastArea.qml")
275 }
276 _toastAreaLoader.item.add(icon, title, body, actions)
277 }
278}
bool isMaximized
Convenient property to check if the application window surface is maximized.
alias content
Items to be placed inside the ApplicationWindow.
bool isWide
Determines when the application window size is wide enough.
bool isPortrait
Convenient property to check if the application window is in portrait mode, otherwise it means it is ...
bool canResizeH
bool canResizeV
bool isFullScreen
Convenient property to check if the application window is in a full screen mode.
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri May 2 2025 11:57:11 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.