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

KDE's Doxygen guidelines are available online.