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{
78 QML_ELEMENT
79 QML_UNCREATABLE("Abstract class")
80
81 /// @internal Used by StatefulApp.ManagedWindow
83
84 /// @internal Used by StatefulApp.ManagedWindow
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.
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.
104
105 /// Return the main action collection.
107
108 /// @internal Used by StatefulApp.StatefulWindow
110
111 /// @internal Used by the shortcuts editor
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.
123
125 /// @internal Used by StatefulApp.StatefulWindow
127
128 /// @internal Used by StatefulApp.StatefulWindow
130
131 /// @internal Used by StatefulApp.StatefulWindow
133
134 /// @internal Used by StatefulApp.StatefulWindow
136
137 /// Changed signal for the configurationView property.
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};
void configurationViewChanged()
Changed signal for the configurationView property.
void setConfigurationView(QObject *configurationView)
Setter for the configurationView property.
void readSettings()
Read the configured settings for the action.
KirigamiActionCollection * mainCollection() const
Return the main action collection.
Q_INVOKABLE QAction * action(const QString &actionName)
Get the named action.
QML_ELEMENTQSortFilterProxyModel * actionsModel
QObject * configurationView
This property holds the configurationView of the application.
virtual QList< KirigamiActionCollection * > actionCollections() const
Return the list of KirigamiActionCollection setup in your application.
virtual void setupActions()
Entry points to declare your actions.
AbstractKirigamiApplication(QObject *parent=nullptr)
Default constructor of AbstractKirigamiApplication.
A container for a set of QAction objects.
QObject(QObject *parent)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:49:11 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.