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 QtQuick.Effects
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: MultiEffect
122 {
123 maskEnabled: true
124 maskThresholdMin: 0.5
125 maskSpreadAtMin: 1.0
126 maskSpreadAtMax: 0.0
127 maskThresholdMax: 1.0
128 maskSource: ShaderEffectSource
129 {
130 sourceItem: Rectangle
131 {
132 x: _container.x
133 y: _container.y
134 width: _container.width
135 height: _container.height
136 radius: Maui.Style.radiusV
137 }
138 }
139 }
140 }
141
142 Loader
143 {
144 active: _container.showBorders
145 visible: active
146 z: Overlay.overlay.z
147 anchors.fill: parent
148 asynchronous: true
149
150 sourceComponent: Rectangle
151 {
152 radius: Maui.Style.radiusV
153 color: "transparent"
154 border.color: Qt.darker(Maui.Theme.backgroundColor, 3)
155 opacity: 0.7
156
157 Behavior on color
158 {
159 Maui.ColorTransition{}
160 }
161
162 Rectangle
163 {
164 anchors.fill: parent
165 anchors.margins: 1
166 color: "transparent"
167 radius: parent.radius
168 border.color: Qt.lighter(Maui.Theme.backgroundColor, 2)
169 opacity: 0.7
170
171 Behavior on color
172 {
173 Maui.ColorTransition{}
174 }
175 }
176 }
177 }
178
179 Loader
180 {
181 asynchronous: true
182 active: Maui.CSD.enabled
183 visible: active
184 anchors.fill: parent
185
186 sourceComponent: WindowResizeHandlers
187 {
188
189 }
190 }
191
192
193 Overlay.overlay.modal: Item
194 {
195 Rectangle
196 {
197 color: Maui.Theme.backgroundColor
198 anchors.fill: parent
199 opacity : 0.8
200 radius: Maui.Style.radiusV
201 }
202 }
203
204 Overlay.overlay.modeless: Rectangle
205 {
206 radius: Maui.Style.radiusV
207
208 color: Qt.rgba( root.Maui.Theme.backgroundColor.r, root.Maui.Theme.backgroundColor.g, root.Maui.Theme.backgroundColor.b, 0.7)
209 Behavior on opacity { NumberAnimation { duration: 150 } }
210
211 Behavior on color
212 {
213 Maui.ColorTransition{}
214 }
215 }
216
217 Component.onCompleted:
218 {
219 // Explicitly break the binding as we need this to be set only at startup.
220 // if the bindings are active, after this the window is resized by the
221 // compositor and then the bindings are reevaluated, then the window
222 // size would reset ignoring what the compositor asked.
223 // see BUG 433849
224 root.width = root.width;
225 root.height = root.height;
226 }
227
228 /**
229 * @brief Switch between maximized and normal state
230 **/
231 function toggleMaximized()
232 {
233 if (root.isMaximized)
234 {
235 root.showNormal();
236 } else
237 {
238 root.showMaximized();
239 }
240 }
241
242 /**
243 * @brief Switch between full-screen mode and normal mode
244 **/
245 function toggleFullscreen()
246 {
247 if (root.isFullScreen)
248 {
249 root.showNormal();
250 } else
251 {
252 root.showFullScreen()();
253 }
254 }
255
256 /**
257 * @brief Send an inline notification
258 * @param icon icon name to be used
259 * @param title the notification title
260 * @param body the message body of the notification
261 * @param actions a list of possible callback actions, this is represented as a button
262 **/
263 function notify(icon, title, body, actions)
264 {
265 if(!_toastAreaLoader.item)
266 {
267 _toastAreaLoader.setSource("ToastArea.qml")
268 }
269 _toastAreaLoader.item.add(icon, title, body, actions)
270 }
271}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:46:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.