Kirigami-addons

StatefulWindow.qml
1// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
2// SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
3//
4// SPDX-License-Identifier: LGPL-2.1-or-later
5
6import QtQuick
7import QtQuick.Controls as QQC2
8import QtQuick.Layouts
9
10import org.kde.kirigami as Kirigami
11import org.kde.kirigamiaddons.formcard as FormCard
12import org.kde.kirigamiaddons.statefulapp as StatefulApp
13import org.kde.kirigamiaddons.statefulapp.private as Private
14import org.kde.coreaddons as Core
15
16/**
17 * @brief StatefulWindow takes care of providing standard functionalities
18 * for your application main window.
19 *
20 * This includes:
21 * * Restoration of the window size accross restarts
22 * * Handling some of the standard actions defined in your KirigamiAbstractApplication
23 * (AboutKDE and AboutApp)
24 * * A command bar to access all the defined actions
25 * * A shortcut editor
26 *
27 * @code
28 * import org.kde.kirigamiaddons.statefulapp as StatefulApp
29 * import org.kde.kirigamiaddons.settings as Settings
30 *
31 * StatefulApp.StatefulWindow {
32 * id: root
33 *
34 * windowName: 'Main'
35 * application: MyApplication {
36 * configurationView: Settings.ConfigurationView { ... }
37 * }
38 * }
39 * @endcode
40 *
41 * @since KirigamiAddons 1.4.0
42 */
43Kirigami.ApplicationWindow {
44 id: root
45
46 /**
47 * This property holds the window's name.
48 *
49 * This needs to be an unique identifier for your application and will be used to store
50 * the state of the window in your application config.
51 */
52 property alias windowName: windowStateSaver.configGroupName
53
54 /**
55 * This property holds the AbstractKirigamiApplication of your application.
56 *
57 * The default AbstractKirigamiApplication provides the following actions:
58 * * KStandardActions::quit
59 * * KStandardActions::keyBindings
60 * * "Open Command Bar"
61 * * "About App"
62 * * "About KDE" (if your application id starts with org.kde.)
63 *
64 * If you need more actions provide your own AbstractKirigamiApplication and overwrite
65 * AbstractKirigamiApplication::setupActions.
66 *
67 * @see AbstractKirigamiApplication
68 */
69 property StatefulApp.AbstractKirigamiApplication application: Private.DefaultKirigamiApplication
70
71 Private.WindowStateSaver {
72 id: windowStateSaver
73 }
74
75 Connections {
76 target: root.application
77
78 function onOpenKCommandBarAction(): void {
79 kcommandbarLoader.active = true;
80 }
81
82 function onShortcutsEditorAction(): void {
83 const openDialogWindow = pageStack.pushDialogLayer(Qt.createComponent("org.kde.kirigamiaddons.statefulapp.private", 'ShortcutsEditor'), {
84 width: root.width,
85 model: root.application.shortcutsModel,
86 }, {
87 width: Kirigami.Units.gridUnit * 30,
88 height: Kirigami.Units.gridUnit * 30,
89 title: i18ndc("kirigami-addons6", "@title:window", "Shortcuts"),
90 });
91 }
92
93 function onOpenAboutPage(): void {
94 const openDialogWindow = pageStack.pushDialogLayer(Qt.createComponent("org.kde.kirigamiaddons.formcard", "AboutPage"), {
95 width: root.width
96 }, {
97 width: Kirigami.Units.gridUnit * 30,
98 height: Kirigami.Units.gridUnit * 30,
99 title: i18ndc("kirigami-addons6", "@title:window", "About %1", Core.AboutData.displayName),
100 });
101 openDialogWindow.Keys.escapePressed.connect(function() {
102 openDialogWindow.closeDialog();
103 });
104 }
105
106 function onOpenAboutKDEPage(): void {
107 const openDialogWindow = pageStack.pushDialogLayer(Qt.createComponent("org.kde.kirigamiaddons.formcard", "AboutKDE"), {
108 width: root.width
109 }, {
110 width: Kirigami.Units.gridUnit * 30,
111 height: Kirigami.Units.gridUnit * 30,
112 title: i18ndc("kirigami-addons6", "@title:window", "About KDE"),
113 });
114 openDialogWindow.Keys.escapePressed.connect(function() {
115 openDialogWindow.closeDialog();
116 });
117 }
118 }
119
120 Loader {
121 id: kcommandbarLoader
122 active: false
123 sourceComponent: Private.KQuickCommandBarPage {
124 application: root.application
125 onClosed: kcommandbarLoader.active = false
126 parent: root.QQC2.Overlay.overlay
127 }
128 onActiveChanged: if (active) {
129 item.open()
130 }
131 }
132}
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:54:39 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.