Plasma-framework

corona.h
1/*
2 SPDX-FileCopyrightText: 2007 Aaron Seigo <aseigo@kde.org>
3 SPDX-FileCopyrightText: 2007 Matt Broadstone <mbroadst@gmail.com>
4 SPDX-FileCopyrightText: 2012 Marco Martin <mart@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef PLASMA_CORONA_H
10#define PLASMA_CORONA_H
11
12#include <plasma/containment.h>
13#include <plasma/plasma.h>
14#include <plasma/plasma_export.h>
15
16class QAction;
17
18namespace Plasma
19{
20class CoronaPrivate;
21
22/**
23 * @class Corona plasma/Corona.h <Plasma/Corona>
24 *
25 * @short A bookkeeping Scene for Plasma::Applets
26 */
27class PLASMA_EXPORT Corona : public QObject
28{
29 Q_OBJECT
30 Q_PROPERTY(bool isStartupCompleted READ isStartupCompleted NOTIFY startupCompleted)
31 Q_PROPERTY(bool editMode READ isEditMode WRITE setEditMode NOTIFY editModeChanged)
32 Q_PROPERTY(KPackage::Package kPackage READ kPackage NOTIFY kPackageChanged)
33
34public:
35 explicit Corona(QObject *parent = nullptr);
36 ~Corona() override;
37
38 /**
39 * Accessor for the associated Package object if any.
40 * A Corona package defines how Containments are laid out in a View,
41 * ToolBoxes, default layout, error messages
42 * and in genelal all the furniture specific of a particular
43 * device form factor.
44 *
45 * @return the Package object, or an invalid one if none
46 * @since 5.5
47 **/
48 KPackage::Package kPackage() const;
49
50 /**
51 * Setting the package for the corona
52 * @since 5.5
53 */
54 void setKPackage(const KPackage::Package &package);
55
56 /**
57 * @return all containments on this Corona
58 */
59 QList<Containment *> containments() const;
60
61 /**
62 * @returns true when the startup is over, and
63 * all the ui graphics has been instantiated
64 */
65 bool isStartupCompleted() const;
66
67 /**
68 * Returns the config file used to store the configuration for this Corona
69 */
70 KSharedConfig::Ptr config() const;
71
72 /**
73 * Adds a Containment to the Corona
74 *
75 * @param name the plugin name for the containment, as given by
76 * KPluginInfo::pluginName(). If an empty string is passed in, the default
77 * containment plugin will be used (usually DesktopContainment). If the
78 * string literal "null" is passed in, then no plugin will be loaded and
79 * a simple Containment object will be created instead.
80 * @param args argument list to pass to the containment
81 *
82 * @return a pointer to the containment on success, or 0 on failure. Failure can be
83 * caused by too restrictive of an Immutability type, as containments cannot be added
84 * when widgets are locked.
85 * If the requested containment plugin can not be located or successfully loaded, the Containment will have an invalid pluginInfo().
86 */
87 Containment *createContainment(const QString &name, const QVariantList &args = QVariantList());
88
89 /**
90 * Returns the Containment for a given physical screen and desktop, creating one
91 * if none exists
92 *
93 * @param screen number of the physical screen to locate
94 * @param activity the activity id of the containment we want,
95 * and empty string if the activity is not important
96 * @param defaultPluginIfNonExistent the plugin to load by default; "null" won't
97 * create it and "default" creates the default plugin
98 * @param defaultArgs optional arguments to pass in when creating a Containment if needed
99 * @since 5.45
100 */
102 containmentForScreen(int screen, const QString &activity, const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs = QVariantList());
103
104 /**
105 * Returns all containments which match a particular activity, for any screen
106 * @param activity the activity id we want
107 * @returns the list of matching containments if any, empty if activity is an empty string
108 * @since 5.45
109 */
110 QList<Containment *> containmentsForActivity(const QString &activity);
111
112 /**
113 * Returns all containments which match a particular screen, for any activity
114 * @param screen the screen number we want
115 * @returns the list of matching containments if any, empty if screen is < 0
116 * @since 5.45
117 */
118 QList<Containment *> containmentsForScreen(int screen);
119
120 /**
121 * Returns the number of screens available to plasma.
122 * Subclasses should override this method as the default
123 * implementation returns a meaningless value.
124 */
125 virtual int numScreens() const;
126
127 /**
128 * Returns the geometry of a given screen.
129 * Valid screen ids are 0 to numScreen()-1, or -1 for the full desktop geometry.
130 * Subclasses should override this method as the default
131 * implementation returns a meaningless value.
132 */
133 virtual QRect screenGeometry(int id) const = 0;
134
135 /**
136 * Returns the available region for a given screen.
137 * The available region excludes panels and similar windows.
138 * Valid screen ids are 0 to numScreens()-1.
139 * By default this method returns a rectangular region
140 * equal to screenGeometry(id); subclasses that need another
141 * behavior should override this method.
142 */
143 virtual QRegion availableScreenRegion(int id) const;
144
145 /**
146 * Returns the available rect for a given screen.
147 * The difference between this and availableScreenRegion()
148 * is that this method returns only a rectangular
149 * available space (it doesn't care if your panel is not 100% width).
150 * The available rect excludes panels and similar windows.
151 * Valid screen ids are 0 to numScreens()-1.
152 * By default this method returns a rectangular region
153 * equal to screenGeometry(id); subclasses that need another
154 * behavior should override this method.
155 */
156 virtual QRect availableScreenRect(int id) const;
157
158 /**
159 * This method is useful in order to retrieve the list of available
160 * screen edges for panel type containments.
161 * @param screen the id of the screen to look for free edges.
162 * @returns a list of free edges not filled with panel type containments.
163 */
164 QList<Plasma::Types::Location> freeEdges(int screen) const;
165
166 /**
167 * @returns The action with the given name, if any
168 */
169 Q_INVOKABLE QAction *action(const QString &name) const;
170
171 /**
172 * Defines a new action with the given name in the internal collection
173 */
174 void setAction(const QString &name, QAction *action);
175
176 /**
177 * Remove the action with the given name, if exists
178 */
179 void removeAction(const QString &name);
180
181 /**
182 * @returns all the actions supported by the corona
183 */
184 QList<QAction *> actions() const;
185
186 /**
187 * Imports an applet layout from a config file. The results will be added to the
188 * current set of Containments.
189 *
190 * @param config the name of the config file to load from,
191 * or the default config file if QString()
192 * @return the list of containments that were loaded
193 * @since 4.6
194 */
195 QList<Plasma::Containment *> importLayout(const KConfigGroup &config);
196
197 /**
198 * Exports a set of containments to a config file.
199 *
200 * @param config the config group to save to
201 * @param containments the list of containments to save
202 * @since 4.6
203 */
204 void exportLayout(KConfigGroup &config, QList<Containment *> containments);
205
206 /**
207 * @returns the id of the screen which is showing @p containment
208 * -1 is returned if the containment is not associated with a screen.
209 */
210 virtual int screenForContainment(const Containment *containment) const;
211
212 /**
213 * @return The type of immutability of this Corona
214 */
215 Types::ImmutabilityType immutability() const;
216
217 /**
218 * Set the Corona globally into "edit mode"
219 * Only when the corona is of mutable type can be set of edit mode.
220 * This indicates the UI to make easy for the user to manipulate applets.
221 * @param edit
222 * @since 5.63
223 */
224 void setEditMode(bool edit);
225
226 /**
227 * @returns true if the corona is in edit mode
228 * @since 5.63
229 */
230 bool isEditMode() const;
231
232 // TODO: make them not slots anymore
233public Q_SLOTS:
234 /**
235 * Load applet layout from a config file. The results will be added to the
236 * current set of Containments.
237 *
238 * @param config the name of the config file to load from,
239 * or the default config file if QString()
240 */
241 void loadLayout(const QString &config = QString());
242
243 /**
244 * Save applets layout to file
245 * @param config the file to save to, or the default config file if QString()
246 */
247 void saveLayout(const QString &config = QString()) const;
248
249 /**
250 * Sets the immutability type for this Corona (not immutable,
251 * user immutable or system immutable)
252 * @param immutable the new immutability type of this applet
253 */
254 void setImmutability(const Types::ImmutabilityType immutable);
255
256 /**
257 * Schedules a flush-to-disk synchronization of the configuration state
258 * at the next convenient moment.
259 */
260 void requestConfigSync();
261
262 /**
263 * Schedules a time sensitive flush-to-disk synchronization of the
264 * configuration state. Since this method does not provide any sort of
265 * event compression, it should only be used when an *immediate* disk
266 * sync is *absolutely* required. Otherwise, use @see requestConfigSync()
267 * which does do event compression.
268 */
269 void requireConfigSync();
270
271Q_SIGNALS:
272 /**
273 * This signal indicates a new containment has been added to
274 * the Corona: it may occur after creation or restore from config
275 */
277
278 /**
279 * This signal indicates a new containment has been created
280 * in the Corona. Compared to containmentAdded it can only happen
281 * after the creation of a new containment.
282 *
283 * @see containmentAdded
284 * @since 5.16
285 */
287
288 /**
289 * This signal indicates that a containment has been newly
290 * associated (or dissociated) with a physical screen.
291 *
292 * @param isScreen the screen it is now associated with
293 */
294 void screenOwnerChanged(int isScreen);
295
296 /**
297 * This signal indicates that the configuration file was flushed to disk.
298 */
300
301 /**
302 * This signal indicates that a change in available screen geometry occurred.
303 */
305
306 /**
307 * This signal indicates that a change in available screen geometry occurred.
308 */
310
311 /**
312 * This signal indicates that a change in geometry for the screen occurred.
313 */
315
316 /**
317 * emitted when immutability changes.
318 * this is for use by things that don't get constraints events, like plasmaapp.
319 * it's NOT for containments or applets or any of the other stuff on the scene.
320 * if your code's not in shells/ it probably shouldn't be using it.
321 */
323
324 /** This signal indicates the screen with the specified id was removed.
325 * @since 5.40
326 */
327 void screenRemoved(int id);
328
329 /** This signal indicates a new screen with the specified id was added.
330 * @since 5.40
331 */
332 void screenAdded(int id);
333
334 /**
335 * emitted when the editMode state changes
336 * @see isEditMode()
337 * @since 5.63
338 */
339 void editModeChanged(bool edit);
340
341 /**
342 * Emitted when the package for this corona has been changed.
343 * Shells must support changing the shell package on the fly (for instance due to device form factor changing)
344 *
345 * @param package the new package that defines the Corona furniture and behavior
346 */
347 void kPackageChanged(const KPackage::Package &package);
348
349 /**
350 * Emitted when the startup phase has been completed
351 */
353
354protected:
355 /**
356 * Loads the default (system wide) layout for this user
357 **/
358 virtual void loadDefaultLayout();
359
360 /**
361 * Loads a containment with delayed initialization, primarily useful
362 * for implementations of loadDefaultLayout. The caller is responsible
363 * for all initialization, saving and notification of a new containment.
364 *
365 * @param name the plugin name for the containment, as given by
366 * KPluginInfo::pluginName(). If an empty string is passed in, the default
367 * containment plugin will be used (usually DesktopContainment). If the
368 * string literal "null" is passed in, then no plugin will be loaded and
369 * a simple Containment object will be created instead.
370 * @param args argument list to pass to the containment
371 *
372 * @return a pointer to the containment on success, or 0 on failure. Failure can
373 * be caused by the Immutability type being too restrictive, as containments can't be added
374 * when widgets are locked, or if the requested containment plugin can not be located
375 * or successfully loaded.
376 * @see addContainment
377 **/
378 Containment *createContainmentDelayed(const QString &name, const QVariantList &args = QVariantList());
379
380private:
381 CoronaPrivate *const d;
382
383 Q_PRIVATE_SLOT(d, void containmentDestroyed(QObject *))
384 Q_PRIVATE_SLOT(d, void syncConfig())
385 Q_PRIVATE_SLOT(d, void toggleImmutability())
386 Q_PRIVATE_SLOT(d, void containmentReady(bool))
387
388 friend class CoronaPrivate;
389 friend class View;
390};
391
392} // namespace Plasma
393
394#endif
The base class for plugins that provide backgrounds and applet grouping containers.
Definition containment.h:47
A bookkeeping Scene for Plasma::Applets.
Definition corona.h:28
void kPackageChanged(const KPackage::Package &package)
Emitted when the package for this corona has been changed.
void containmentAdded(Plasma::Containment *containment)
This signal indicates a new containment has been added to the Corona: it may occur after creation or ...
void configSynced()
This signal indicates that the configuration file was flushed to disk.
void immutabilityChanged(Plasma::Types::ImmutabilityType immutability)
emitted when immutability changes.
virtual QRect screenGeometry(int id) const =0
Returns the geometry of a given screen.
void startupCompleted()
Emitted when the startup phase has been completed.
void containmentCreated(Plasma::Containment *containment)
This signal indicates a new containment has been created in the Corona.
void screenOwnerChanged(int isScreen)
This signal indicates that a containment has been newly associated (or dissociated) with a physical s...
void screenAdded(int id)
This signal indicates a new screen with the specified id was added.
void editModeChanged(bool edit)
emitted when the editMode state changes
void availableScreenRegionChanged(int id)
This signal indicates that a change in available screen geometry occurred.
void screenGeometryChanged(int id)
This signal indicates that a change in geometry for the screen occurred.
void availableScreenRectChanged(int id)
This signal indicates that a change in available screen geometry occurred.
void screenRemoved(int id)
This signal indicates the screen with the specified id was removed.
ImmutabilityType
Defines the immutability of items like applets, corona and containments they can be free to modify,...
Definition plasma.h:99
Namespace for everything in libplasma.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:54:11 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.