KCMUtils

kquickconfigmodule.h
1/*
2 SPDX-FileCopyrightText: 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
3 SPDX-FileCopyrightText: 2001 Michael Goffioul <kdeprint@swing.be>
4 SPDX-FileCopyrightText: 2004 Frans Englich <frans.englich@telia.com>
5 SPDX-FileCopyrightText: 2009 Dario Freddi <drf@kde.org>
6 SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
7 SPDX-FileCopyrightText: 2023 Alexander Lohnau <alexander.lohnau@gmx.de>
8
9 SPDX-License-Identifier: LGPL-2.0-or-later
10*/
11
12#ifndef KQUICKCONFIGMODULE_H
13#define KQUICKCONFIGMODULE_H
14
15#include "kcmutilsquick_export.h"
16
17#include <QObject>
18#include <QQmlComponent>
19#include <QStringList>
20#include <QVariant>
21
22#include <KPluginFactory>
23#include <KPluginMetaData>
24
25#include <memory>
26#include <qqmlintegration.h>
27
28#include "kabstractconfigmodule.h"
29#include "kquickconfigmoduleloader.h"
30
31class QQuickItem;
32class QQmlEngine;
33class KQuickConfigModulePrivate;
34
35/**
36 * @class KQuickConfigModule kquickconfigmodule.h KQuickConfigModule
37 *
38 * The base class for QtQuick configuration modules.
39 * Configuration modules are realized as plugins that are dynamically loaded.
40 *
41 * All the necessary glue logic and the GUI bells and whistles
42 * are provided by the control center and must not concern
43 * the module author.
44 *
45 * To write a config module, you have to create a C++ plugin
46 * and an accompaning QML user interface.
47 *
48 * To allow KCMUtils to load your ConfigModule subclass, you must create a KPluginFactory implementation.
49 *
50 * \code
51 * #include <KPluginFactory>
52 *
53 * K_PLUGIN_CLASS_WITH_JSON(MyConfigModule, "yourmetadata.json")
54 * \endcode
55 *
56 * The constructor of the ConfigModule then looks like this:
57 * \code
58 * YourConfigModule::YourConfigModule(QObject *parent, const KPluginMetaData &metaData)
59 * : KQuickConfigModule(parent, metaData)
60 * {
61 * }
62 * \endcode
63 *
64 * The QML part must be in the KPackage format, installed under share/kpackage/kcms.
65 * @see KPackage::Package
66 *
67 * The package must have the same name as the plugin filename, to be installed
68 * by CMake with the command:
69 * \code
70 * kpackage_install_package(packagedir kcm_yourconfigmodule kcms)
71 * \endcode
72 * The "packagedir" is the subdirectory in the source tree where the package sources are
73 * located, and "kcm_yourconfigmodule" is id of the plugin.
74 * Finally "kcms" is the literal string "kcms", so that the package is
75 * installed as a configuration module (and not some other kind of package).
76 *
77 * The QML part can access all the properties of ConfigModule (together with the properties
78 * defined in its subclass) by accessing to the global object "kcm", or with the
79 * import of "org.kde.kcmutils" the ConfigModule attached property.
80 *
81 * \code
82 * import QtQuick
83 * import QtQuick.Controls as QQC2
84 * import org.kde.kcmutils as KCMUtils
85 * import org.kde.kirigami as Kirigami
86 *
87 * Item {
88 * // implicit size will be used as initial size when loaded in kcmshell6
89 * implicitWidth: Kirigami.Units.gridUnit * 30
90 * implicitHeight: Kirigami.Units.gridUnit * 30
91 *
92 * KCMUtils.ConfigModule.buttons: KCMUtils.ConfigModule.Help | KCMUtils.ConfigModule.Apply
93 *
94 * QQC2.Label {
95 * // The following two bindings are equivalent:
96 * text: kcm.needsSave
97 * enabled: KCMUtils.ConfigModule.needsSave
98 * }
99 * }
100 * \endcode
101 *
102 * See https://develop.kde.org/docs/extend/kcm/ for more detailed documentation.
103 * @since 6.0
104 */
105class KCMUTILSQUICK_EXPORT KQuickConfigModule : public KAbstractConfigModule
106{
107 Q_OBJECT
108
109 Q_PROPERTY(QQuickItem *mainUi READ mainUi CONSTANT)
110 Q_PROPERTY(int columnWidth READ columnWidth WRITE setColumnWidth NOTIFY columnWidthChanged)
111 Q_PROPERTY(int depth READ depth NOTIFY depthChanged)
112 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
113
114 QML_NAMED_ELEMENT(ConfigModule)
115 QML_ATTACHED(KQuickConfigModule)
116
117public:
118 /**
119 * Destroys the module.
120 */
121 ~KQuickConfigModule() override;
122
123 /**
124 * @return the qml engine that built the main config UI
125 */
126 std::shared_ptr<QQmlEngine> engine() const;
127
128 /**
129 * The error string in case the mainUi failed to load.
130 */
131 QString errorString() const;
132
133 // QML property accessors
134
135 /**
136 * @return The main UI for this configuration module. It's a QQuickItem coming from
137 * the QML package named the same as the KAboutData's component name for
138 * this config module
139 */
141
142 /*
143 * @return a subpage at a given depth
144 * @note This does not include the mainUi. i.e a depth of 2 is a mainUi and one subPage
145 * at index 0
146 */
147 QQuickItem *subPage(int index) const;
148
149 /**
150 * returns the width the kcm wants in column mode.
151 * If a columnWidth is valid ( > 0 ) and less than the systemsettings' view width,
152 * more than one will be visible at once, and the first page will be a sidebar to the last page pushed.
153 * As default, this is -1 which will make the shell always show only one page at a time.
154 */
155 int columnWidth() const;
156
157 /**
158 * Sets the column width we want.
159 */
160 void setColumnWidth(int width);
161
162 /**
163 * @returns how many pages this kcm has.
164 * It is guaranteed to be at least 1 (the main ui) plus how many times a new page has been pushed without pop
165 */
166 int depth() const;
167
168 /**
169 * Sets the current page index this kcm should display
170 */
171 void setCurrentIndex(int index);
172
173 /**
174 * @returns the index of the page this kcm should display
175 */
176 int currentIndex() const;
177
178 static KQuickConfigModule *qmlAttachedProperties(QObject *object);
179
180public Q_SLOTS:
181 /**
182 * Push a new sub page in the KCM hierarchy: pages will be seen as a Kirigami PageRow
183 */
184 void push(const QString &fileName, const QVariantMap &initialProperties = QVariantMap());
185
186 /**
187 *
188 */
189 void push(QQuickItem *item);
190
191 /**
192 * pop the last page of the KCM hierarchy, the page is destroyed
193 */
194 void pop();
195
196 /**
197 * remove and return the last page of the KCM hierarchy:
198 * the popped page won't be deleted, it's the caller's responsibility to manage the lifetime of the returned item
199 * @returns the last page if any, nullptr otherwise
200 */
201 QQuickItem *takeLast();
202
204
205 // QML NOTIFY signaling
206
207 /**
208 * Emitted when a new sub page is pushed
209 */
211
212 /**
213 * Emitted when a sub page is popped
214 */
215 // RFC: page argument?
217
218 /**
219 * Emitted when the wanted column width of the kcm changes
220 */
221 void columnWidthChanged(int width);
222
223 /**
224 * Emitted when the current page changed
225 */
226 void currentIndexChanged(int index);
227
228 /**
229 * Emitted when the number of pages changed
230 */
231 void depthChanged(int index);
232
233 /**
234 * Emitted when the main Ui has loaded successfully and `mainUi()` is available
235 */
237
238protected:
239 /**
240 * Base class for all QtQuick config modules.
241 * Use KQuickConfigModuleLoader to instantiate this class
242 *
243 * @note do not emit changed signals here, since they are not yet connected to any slot.
244 */
245 explicit KQuickConfigModule(QObject *parent, const KPluginMetaData &metaData);
246
247private:
248 void setInternalEngine(const std::shared_ptr<QQmlEngine> &engine);
250 KQuickConfigModuleLoader::loadModule(const KPluginMetaData &metaData, QObject *parent, const QVariantList &args, const std::shared_ptr<QQmlEngine> &engine);
251 const std::unique_ptr<KQuickConfigModulePrivate> d;
252};
253
254#endif // KQUICKCONFIGMODULE_H
Base class for QML and QWidgets config modules.
The base class for QtQuick configuration modules.
void mainUiReady()
Emitted when the main Ui has loaded successfully and mainUi() is available.
void columnWidthChanged(int width)
Emitted when the wanted column width of the kcm changes.
void depthChanged(int index)
Emitted when the number of pages changed.
void currentIndexChanged(int index)
Emitted when the current page changed.
void pagePushed(QQuickItem *page)
Emitted when a new sub page is pushed.
void pageRemoved()
Emitted when a sub page is popped.
QQuickItem * mainUi()
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:20 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.