Plasma-framework

containment.h
1/*
2 SPDX-FileCopyrightText: 2007 Aaron Seigo <aseigo@kde.org>
3 SPDX-FileCopyrightText: 2008 Ménard Alexis <darktears31@gmail.com>
4 SPDX-FileCopyrightText: 2009 Chani Armitage <chani@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef PLASMA_CONTAINMENT_H
10#define PLASMA_CONTAINMENT_H
11
12#include <KPluginMetaData>
13#include <KSharedConfig>
14#include <plasma/applet.h>
15#include <qtmetamacros.h>
16
17class QQuickItem;
18
19namespace Plasma
20{
21class Corona;
22class ContainmentActions;
23class ContainmentPrivate;
24
25/**
26 * @class Containment plasma/containment.h <Plasma/Containment>
27 *
28 * @short The base class for plugins that provide backgrounds and applet grouping containers
29 *
30 * Containment objects provide the means to group applets into functional sets.
31 * They also provide the following:
32 *
33 * creation of focusing event
34 * - drawing of the background image (which can be interactive)
35 * - form factors (e.g. panel, desktop, full screen, etc)
36 * - applet layout management
37 *
38 * Since containment is actually just a Plasma::Applet, all the techniques used
39 * for writing the visual presentation of Applets is applicable to Containtments.
40 * Containments are differentiated from Applets by being marked with the ServiceType
41 * of Plasma/Containment. Plugins registered with both the Applet and the Containment
42 * ServiceTypes can be loaded for us in either situation.
43 *
44 * See techbase.kde.org for a tutorial on writing Containments using this class.
45 */
46class PLASMA_EXPORT Containment : public Applet
47{
48 Q_OBJECT
49
50 /**
51 * List of applets this containment has: the containments
52 * KF6: this should be AppletQuickItem *
53 */
54 Q_PROPERTY(QList<Plasma::Applet *> applets READ applets NOTIFY appletsChanged)
55
56 /**
57 * The corona for this contaiment
58 */
59 Q_PROPERTY(Plasma::Corona *corona READ corona CONSTANT)
60
61 /**
62 * Type of this containment
63 */
64 Q_PROPERTY(Plasma::Containment::Type containmentType READ containmentType NOTIFY containmentTypeChanged)
65
66 /**
67 * Activity UID of this containment
68 */
69 Q_PROPERTY(QString activity READ activity NOTIFY activityChanged)
70
71 /**
72 * Activity name of this containment
73 */
74 Q_PROPERTY(QString activityName READ activityName NOTIFY activityNameChanged)
75
76 Q_PROPERTY(Plasma::Types::ContainmentDisplayHints containmentDisplayHints READ containmentDisplayHints WRITE setContainmentDisplayHints NOTIFY
77 containmentDisplayHintsChanged)
78
79 Q_PROPERTY(QString wallpaperPlugin READ wallpaperPlugin WRITE setWallpaperPlugin NOTIFY wallpaperPluginChanged)
80 Q_PROPERTY(QObject *wallpaperGraphicsObject READ wallpaperGraphicsObject WRITE setWallpaperGraphicsObject NOTIFY wallpaperGraphicsObjectChanged)
81
82 Q_PROPERTY(bool isUiReady READ isUiReady NOTIFY uiReadyChanged)
83
84 /**
85 * The screen number this containment is serving as the desktop for, or -1 if none
86 */
87 Q_PROPERTY(int screen READ screen NOTIFY screenChanged)
88
89 /**
90 * screen area free of panels: the coordinates are relative to the containment,
91 * it's independent from the screen position
92 * For more precise available geometry use availableScreenRegion()
93 */
94 Q_PROPERTY(QRectF availableScreenRect READ availableRelativeScreenRect NOTIFY availableRelativeScreenRectChanged)
95
96 /**
97 * The available region of this screen, panels excluded. It's a list of rectangles
98 */
99 Q_PROPERTY(QList<QRectF> availableScreenRegion READ availableRelativeScreenRegion NOTIFY availableRelativeScreenRegionChanged)
100
101 /**
102 * Provides access to the geometry of the applet is in.
103 * Can be useful to figure out what's the absolute position of the applet.
104 */
105 Q_PROPERTY(QRectF screenGeometry READ screenGeometry NOTIFY screenGeometryChanged)
106
107public:
108 /**
109 * This constructor can be used with the KCoreAddons plugin loading system.
110 * The argument list is expected to have contain the KPackage of the applet,
111 * the meta data file path (for compatibility) and an applet ID which must be a base 10 number.
112 *
113 * @param parent a QObject parent; you probably want to pass in 0
114 * @param data, KPluginMetaData used to create this plugin
115 * @param args a list of strings containing the applet id
116 * @since 5.86
117 */
118 explicit Containment(QObject *parentObject, const KPluginMetaData &data, const QVariantList &args);
119
120 ~Containment() override;
121
122 /**
123 * Reimplemented from Applet
124 */
125 void init() override;
126
127 /**
128 * This enumeration describes the type of the Containment.
129 * DesktopContainments represent main containments that will own a screen in a mutually exclusive fashion,
130 * while PanelContainments are accessories which can be present multiple per screen.
131 *
132 * This value is specified in the "X-Plasma-ContainmentType" JSON-metadata value of containments.
133 */
134 enum Type {
135 NoContainment = -1, /**< @internal */
136 Desktop = 0, /**< A desktop containment */
137 Panel, /**< A desktop panel */
138 Custom = 127, /**< A containment that is neither a desktop nor a panel but something application specific */
139 CustomPanel = 128, /**< A customized desktop panel. "CustomPanel" in metadata */
140 CustomEmbedded = 129, /**< A customized containment embedded in another applet */
141 };
142 Q_ENUM(Type)
143
144 /**
145 * Returns the type of containment
146 */
147 Type containmentType() const;
148
149 /**
150 * Returns the Corona (if any) that this Containment is hosted by
151 */
152 Corona *corona() const;
153
154 /**
155 * Adds an applet to this Containment
156 *
157 * @param name the plugin name for the applet, as given by
158 * KPluginInfo::pluginName()
159 * @param args argument list to pass to the plasmoid
160 * @param geometryHint an hint to pass to the GUI on the location
161 * and size we prefer for the newly created applet;
162 * the gui might choose whether to respect or not this hint.
163 * The default position is (-1, -1) and the default size
164 * is (0, 0).
165 *
166 * @return a pointer to the applet on success, or 0 on failure
167 */
168 Applet *createApplet(const QString &name, const QVariantList &args = QVariantList(), const QRectF &geometryHint = QRectF(-1, -1, 0, 0));
169
170 /**
171 * Add an existing applet to this Containment
172 *
173 * @param applet the applet that should be added
174 * @param geometryHint an hint to pass to the GUI on the location
175 * and size we prefer for the newly created applet;
176 * the gui might choose whether to respect or not this hint
177 */
178 Q_INVOKABLE void addApplet(Applet *applet, const QRectF &geometryHint = QRectF());
179
180 /**
181 * @return the applets currently in this Containment
182 */
183 QList<Applet *> applets() const;
184
185 /**
186 * @return the screen number this containment is serving as the desktop for
187 * or -1 if none
188 * TODO KF6 virtual? this shouldbe available to applet as well
189 */
190 int screen() const;
191
192 /**
193 * @return the last screen number this containment had
194 * only returns -1 if it's never ever been on a screen
195 * @since 4.5
196 */
197 int lastScreen() const;
198
199 /**
200 * @reimp
201 * @sa Applet::save(KConfigGroup &)
202 */
203 void save(KConfigGroup &group) const override;
204
205 /**
206 * @reimp
207 * @sa Applet::restore(KConfigGroup &)
208 */
209 void restore(KConfigGroup &group) override;
210
211 /**
212 * Sets wallpaper plugin.
213 *
214 * @param pluginName the name of the wallpaper to attempt to load
215 */
216 void setWallpaperPlugin(const QString &pluginName);
217
218 /**
219 * Return wallpaper plugin.
220 */
221 QString wallpaperPlugin() const;
222
223 /**
224 * Sets the current activity by id
225 *
226 * @param activity the id of the activity
227 */
228 void setActivity(const QString &activityId);
229
230 /**
231 * @return the current activity id associated with this containment
232 * TODO KF6: this should be available to Appelt as well as a property... virtual?
233 */
234 QString activity() const;
235
236 /**
237 * @return Activity name corresponding to the activity UID
238 * @see activity
239 */
240 QString activityName() const;
241
242 /**
243 * Sets a containmentactions plugin.
244 *
245 * @param trigger the mouse button (and optional modifier) to associate the plugin with
246 * @param pluginName the name of the plugin to attempt to load. blank = set no plugin.
247 * @since 4.4
248 */
249 void setContainmentActions(const QString &trigger, const QString &pluginName);
250
251 /**
252 * @return All the loaded containment action plugins, indexed by trigger name
253 * @since 5.0
254 */
255 QHash<QString, ContainmentActions *> &containmentActions();
256
257 /**
258 * @returns true when the ui of this containment is fully loaded, as well the ui of every applet in it
259 */
260 bool isUiReady() const;
261
262 /**
263 * @returns The available screen rect (excluding panels) for the screen this containment is associated to,
264 * empty rectangle if the containment is not active in a screen
265 */
266 QRectF availableRelativeScreenRect() const;
267
268 /**
269 * @returns The available region of this screen, panels excluded. It's a list of rectangles
270 */
271 QList<QRectF> availableRelativeScreenRegion() const;
272
273 /**
274 * @returns The geometry of the screen this containment is associated to
275 */
276 QRectF screenGeometry() const;
277
278Q_SIGNALS:
279 /**
280 * This signal is emitted when a new applet is added in the containment
281 * It may happen in the following situations:
282 * * The user created the applet
283 * * The applet was moved in from another containment
284 * * The applet got restored at startup
285 * @param applet the applet that has been added
286 * @param geometryHint an hint to pass to the GUI on the location
287 * and size we prefer for the newly created applet;
288 * the gui might choose whether to respect or not this hint
289 */
290 void appletAdded(Plasma::Applet *applet, const QRectF &geometryHint);
291
292 /**
293 * This signal is emitted right before appletAdded, it can be used
294 * to do a preliminary setup on the applet before the handlers of appletAdded are executed.
295 * Useful for instance to prepare the GUI for the applet
296 * @param applet the applet that is about to be added
297 * @param geometryHint an hint to pass to the GUI on the location
298 * and size we prefer for the newly created applet;
299 * the gui might choose whether to respect or not this hint
300 */
301 void appletAboutToBeAdded(Plasma::Applet *applet, const QRectF &geometryHint);
302
303 /**
304 * This signal is emitted when an applet is destroyed
305 */
307
308 /**
309 * This signal is emitted right before appletRemoved, it can be used
310 * to do a preliminary setup on the applet before the handlers of appletRemoved are executed.
311 * Useful for instance to prepare or teardown the GUI for the applet
312 */
314
315 /**
316 * This signal is emitted when a new applet is created by the containment.
317 * Compared to appletAdded, this gets emitted only when the user explicitly
318 * creates a new applet, either via the widget explorer or the scripting
319 * environment.
320 * @see appletAdded
321 * @since 5.16
322 */
323 void appletCreated(Plasma::Applet *applet, const QRectF &geometryHint);
324
325 /**
326 * Emitted when the list of applets has changed, either added or removed
327 */
329
330 /**
331 * Emitted when the activity id has changed
332 */
333 void activityChanged(const QString &activity);
334
335 /**
336 * Emitted when the activity name has changed
337 */
338 void activityNameChanged(const QString &name);
339
340 /**
341 * Emitted when the containment requests an add widgets dialog is shown.
342 * Usually only used for desktop containments.
343 *
344 * @param pos where in the containment this request was made from, or
345 * an invalid position (QPointF()) is not location specific
346 */
348
349 /**
350 * This signal indicates that a containment has been
351 * associated (or dissociated) with a physical screen.
352 *
353 * @param newScreen the screen it is now associated with
354 */
355 void screenChanged(int newScreen);
356
357 /**
358 * Emitted when the user wants to configure/change the containment, or an applet inside it.
359 */
361
362 /**
363 * Emitted when the user wants to chose an alternative for this applet or containment.
364 */
366
367 /**
368 * Emitted when the wallpaper plugin is changed
369 */
371
372 /**
373 * Emitted when the location has changed
374 * @since 5.0
375 */
377
378 /**
379 * Emitted when the formFactor has changed
380 * @since 5.0
381 */
383
384 /**
385 * Emitted when the containment disaplay hints change
386 */
388
389 /**
390 * Emitted when the ui has been fully loaded and is fully working
391 * @param uiReady true when the ui of the containment is ready, as well the ui of each applet in it
392 */
393 void uiReadyChanged(bool uiReady);
394
395 /**
396 * emitted when the containment type changed
397 */
399
400 /**
401 * Emitted when the available screen rectangle has changed
402 */
404
405 /**
406 * Emitted when the available screen rectangle has changed
407 */
409
410 /**
411 * Emitted when the screen geometry has changed
412 */
413 void screenGeometryChanged(const QRectF &rect);
414
415 /**
416 * Emitted when the root wallpaper item has changed
417 */
419
420public Q_SLOTS:
421 /**
422 * Informs the Corona as to what position it is in. This is informational
423 * only, as the Corona doesn't change its actual location. This is,
424 * however, passed on to Applets that may be managed by this Corona.
425 *
426 * @param location the new location of this Corona
427 */
428 void setLocation(Plasma::Types::Location location);
429
430 /**
431 * Sets the form factor for this Containment. This may cause changes in both
432 * the arrangement of Applets as well as the display choices of individual
433 * Applets.
434 */
435 void setFormFactor(Plasma::Types::FormFactor formFactor);
436
437 /**
438 * Set Display hints that come from the containment that suggest the applet how to look and behave.
439 *
440 * @param hints the new hints, as bitwise OR
441 * @since 5.77
442 */
443 void setContainmentDisplayHints(Plasma::Types::ContainmentDisplayHints hints);
444
445 void reactToScreenChange();
446
447protected:
448 /**
449 * Called when the contents of the containment should be saved. By default this saves
450 * all loaded Applets
451 *
452 * @param group the KConfigGroup to save settings under
453 */
454 virtual void saveContents(KConfigGroup &group) const;
455
456 /**
457 * Called when the contents of the containment should be loaded. By default this loads
458 * all previously saved Applets
459 *
460 * @param group the KConfigGroup to save settings under
461 */
462 virtual void restoreContents(KConfigGroup &group);
463
464private:
465 /**
466 * @internal This constructor is to be used with the Package loading system.
467 *
468 * @param parent a QObject parent; you probably want to pass in 0
469 * @since 4.3
470 */
471 Containment(const KPluginMetaData &md, uint appletId);
472
473 /**
474 * @internal Return root wallpaper item
475 */
476 QObject *wallpaperGraphicsObject() const;
477 void setWallpaperGraphicsObject(QObject *object);
478
479 QUrl compactApplet() const;
480
481 Q_PRIVATE_SLOT(d, void appletDeleted(Plasma::Applet *))
482 Q_PRIVATE_SLOT(d, void triggerShowAddWidgets())
483 Q_PRIVATE_SLOT(d, void checkStatus(Plasma::Types::ItemStatus))
484
485 friend class Applet;
486 friend class AppletPrivate;
487 friend class CoronaPrivate;
488 friend class ContainmentPrivate;
489 friend class ContainmentActions;
490 friend class PlasmaQuick::AppletQuickItem;
491 ContainmentPrivate *const d;
492};
493
494} // Plasma namespace
495
496#endif // multiple inclusion guard
The base Applet class.
Definition applet.h:64
The base ContainmentActions class.
The base class for plugins that provide backgrounds and applet grouping containers.
Definition containment.h:47
void containmentTypeChanged()
emitted when the containment type changed
void uiReadyChanged(bool uiReady)
Emitted when the ui has been fully loaded and is fully working.
void configureRequested(Plasma::Applet *applet)
Emitted when the user wants to configure/change the containment, or an applet inside it.
void containmentDisplayHintsChanged(Plasma::Types::ContainmentDisplayHints hints)
Emitted when the containment disaplay hints change.
void formFactorChanged(Plasma::Types::FormFactor formFactor)
Emitted when the formFactor has changed.
Type
This enumeration describes the type of the Containment.
@ Panel
A desktop panel.
void appletCreated(Plasma::Applet *applet, const QRectF &geometryHint)
This signal is emitted when a new applet is created by the containment.
void activityChanged(const QString &activity)
Emitted when the activity id has changed.
void wallpaperPluginChanged()
Emitted when the wallpaper plugin is changed.
void availableRelativeScreenRegionChanged(const QList< QRectF > &region)
Emitted when the available screen rectangle has changed.
void activityNameChanged(const QString &name)
Emitted when the activity name has changed.
void appletRemoved(Plasma::Applet *applet)
This signal is emitted when an applet is destroyed.
void appletAboutToBeRemoved(Plasma::Applet *applet)
This signal is emitted right before appletRemoved, it can be used to do a preliminary setup on the ap...
void showAddWidgetsInterface(const QPointF &pos)
Emitted when the containment requests an add widgets dialog is shown.
void locationChanged(Plasma::Types::Location location)
Emitted when the location has changed.
void screenGeometryChanged(const QRectF &rect)
Emitted when the screen geometry has changed.
void wallpaperGraphicsObjectChanged()
Emitted when the root wallpaper item has changed.
void appletAboutToBeAdded(Plasma::Applet *applet, const QRectF &geometryHint)
This signal is emitted right before appletAdded, it can be used to do a preliminary setup on the appl...
void appletAlternativesRequested(Plasma::Applet *applet)
Emitted when the user wants to chose an alternative for this applet or containment.
void appletsChanged()
Emitted when the list of applets has changed, either added or removed.
void screenChanged(int newScreen)
This signal indicates that a containment has been associated (or dissociated) with a physical screen.
void appletAdded(Plasma::Applet *applet, const QRectF &geometryHint)
This signal is emitted when a new applet is added in the containment It may happen in the following s...
void availableRelativeScreenRectChanged(const QRectF &rect)
Emitted when the available screen rectangle has changed.
A bookkeeping Scene for Plasma::Applets.
Definition corona.h:28
Enums and constants used in Plasma.
Definition plasma.h:29
Location
The Location enumeration describes where on screen an element, such as an Applet or its managing cont...
Definition plasma.h:81
FormFactor
The FormFactor enumeration describes how a Plasma::Applet should arrange itself.
Definition plasma.h:40
The EdgeEventForwarder class This class forwards edge events to be replayed within the given margin T...
Definition action.h:20
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.