Kirigami-addons

abstractkirigamiapplication.h
1// SPDX-FileCopyrightText: 2024 Carl Schwan <carl@carlschwan.eu>
2// SPDX-License-Identifier: LGPL-2.1-only or LGPL-3.0-only or LicenseRef-KDE-Accepted-LGPL
3
4#pragma once
5
6#include <kirigamiactioncollection.h>
7#include <kirigamiaddonsstatefulapp_export.h>
8#include <QObject>
9#include <QSortFilterProxyModel>
10#include <QtQml/qqmlregistration.h>
11
12/**
13 * @class AbstractKirigamiApplication AbstractKirigamiApplication
14 * @short The main container for your actions.
15 *
16 * AbstractKirigamiApplication is a class that needs to be inherited in your application.
17 * It allows to expose the various actions of your application to the QML frontend. Depending
18 * on the complexitiy of the application, you can either reimplement setupActions only
19 * and put all your actions inside the mainCollection, or, if you want to organize your actions
20 * in multiple collections, you can also expose the custom collections by overwriting
21 * actionCollections.
22 *
23 * @code{.cpp}
24 * class MyKoolApp : public AbstractKirigamiApplication
25 * {
26 * Q_OBJECT
27 * QML_ELEMENT
28 *
29 * public:
30 * explicit MyKoolApp(QObject *parent = nullptr);
31 *
32 * void setupActions() override;
33 * };
34 *
35 * MyKoolApp::MyKoolApp(QObject *parent)
36 * : AbstractKirigamiApplication(parent)
37 * {
38 * setupActions();
39 * }
40 *
41 * void MyKoolApp::setupActions()
42 * {
43 * AbstractKirigamiApplication::setupActions();
44 *
45 * auto actionName = QLatin1String("add_notebook");
46 * if (KAuthorized::authorizeAction(actionName)) {
47 * auto action = mainCollection()->addAction(actionName, this, &MyKoolApp::newNotebook);
48 * action->setText(i18nc("@action:inmenu", "New Notebook"));
49 * action->setIcon(QIcon::fromTheme(QStringLiteral("list-add-symbolic")));
50 * mainCollection()->addAction(action->objectName(), action);
51 * mainCollection()->setDefaultShortcut(action, QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_N));
52 * }
53 * }
54 * @endcode
55 *
56 * The application object then need to be assigned to the application property in a StatefulWindow.
57 *
58 * @code{.qml}
59 * import org.kde.kirigamiaddons.StatefulApplication as StatefulApplication
60 *
61 * StatefulApplication.StatefulWindow {
62 * id: root
63 *
64 * application: MyKoolApp {}
65 *
66 * StatefulApplication.Action {
67 * actionName: 'add_notebook'
68 * application: root.application
69 * }
70 * }
71 * @endcode{}
72 *
73 * @since KirigamiAddons 1.4.0
74 */
75class KIRIGAMIADDONSSTATEFULAPP_EXPORT AbstractKirigamiApplication : public QObject
76{
77 Q_OBJECT
78 QML_ELEMENT
79 QML_UNCREATABLE("Abstract class")
80
81 /// @internal Used by StatefulApp.ManagedWindow
82 Q_PROPERTY(QSortFilterProxyModel *actionsModel READ actionsModel CONSTANT)
83
84 /// @internal Used by StatefulApp.ManagedWindow
85 Q_PROPERTY(QAbstractListModel *shortcutsModel READ shortcutsModel CONSTANT)
86
87 /// This property holds the configurationView of the application
88 ///
89 /// When set, AbstractKirigamiApplication will setup a "options_configure" action
90 /// that will open the configurationView when triggered.
91 Q_PROPERTY(QObject *configurationView READ configurationView WRITE setConfigurationView NOTIFY configurationViewChanged)
92
93public:
94 /// Default constructor of AbstractKirigamiApplication
95 explicit AbstractKirigamiApplication(QObject *parent = nullptr);
96
97 /// Default destructor of AbstractKirigamiApplication
99
100 /// Return the list of KirigamiActionCollection setup in your application.
101 ///
102 /// Overwrite this method if you are using custom collections.
103 virtual QList<KirigamiActionCollection *> actionCollections() const;
104
105 /// Return the main action collection.
106 KirigamiActionCollection *mainCollection() const;
107
108 /// @internal Used by StatefulApp.StatefulWindow
109 QSortFilterProxyModel *actionsModel();
110
111 /// @internal Used by the shortcuts editor
112 QAbstractListModel *shortcutsModel();
113
114 /// Get the named action.
115 /// \return nullptr is not such action is defined.
116 Q_INVOKABLE QAction *action(const QString &actionName);
117
118 /// Getter for the configurationView property.
119 QObject *configurationView() const;
120
121 /// Setter for the configurationView property.
122 void setConfigurationView(QObject *configurationView);
123
124Q_SIGNALS:
125 /// @internal Used by StatefulApp.StatefulWindow
126 void openAboutPage();
127
128 /// @internal Used by StatefulApp.StatefulWindow
129 void openAboutKDEPage();
130
131 /// @internal Used by StatefulApp.StatefulWindow
132 void openKCommandBarAction();
133
134 /// @internal Used by StatefulApp.StatefulWindow
135 void shortcutsEditorAction();
136
137 /// Changed signal for the configurationView property.
138 void configurationViewChanged();
139
140protected:
141 /// Entry points to declare your actions.
142 ///
143 /// Don't forget to call the parent implementation to get the following actions
144 /// setup for you:
145 ///
146 /// - CommandBar
147 /// - About page for your application
148 /// - About page for KDE
149 ///
150 /// Once the actions are setup, call readSettings to read the configured shortcuts.
151 virtual void setupActions();
152
153 /// Read the configured settings for the action.
154 void readSettings();
155
156private:
157 void KIRIGAMIADDONSSTATEFULAPP_NO_EXPORT quit();
158
159 class Private;
160 std::unique_ptr<Private> d;
161};
The main container for your actions.
A container for a set of QAction objects.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.