Plasma::Containment Class

The base class for plugins that provide backgrounds and applet grouping containers. More...

Header: #include <Plasma/Containment>
CMake: find_package(Plasma REQUIRED)
target_link_libraries(mytarget PRIVATE Plasma::Plasma)
Inherits: Plasma::Applet

Public Types

enum Type { NoContainment, Desktop, Panel, Custom, CustomPanel, CustomEmbedded }

Properties

Public Functions

(since 5.86) Containment(QObject *parentObject, const KPluginMetaData &data, const QVariantList &args)
QString activity() const
QString activityName() const
void addApplet(Plasma::Applet *applet, const QRectF &geometryHint = QRectF())
QList<Plasma::Applet *> applets() const
QRectF availableRelativeScreenRect() const
QList<QRectF> availableRelativeScreenRegion() const
(since 5.0) QHash<QString, Plasma::ContainmentActions *> &containmentActions()
Plasma::Containment::Type containmentType() const
Plasma::Corona *corona() const
Plasma::Applet *createApplet(const QString &name, const QVariantList &args = QVariantList(), const QRectF &geometryHint = QRectF(-1, -1, 0, 0))
bool isUiReady() const
(since 4.5) int lastScreen() const
int screen() const
QRectF screenGeometry() const
void setActivity(const QString &activityId)
(since 4.4) void setContainmentActions(const QString &trigger, const QString &pluginName)
void setWallpaperPlugin(const QString &pluginName)
QString wallpaperPlugin() const

Public Slots

(since 5.77) void setContainmentDisplayHints(Plasma::Types::ContainmentDisplayHints hints)
void setFormFactor(Plasma::Types::FormFactor formFactor)
void setLocation(Plasma::Types::Location location)

Signals

void activityChanged(const QString &activity)
void activityNameChanged(const QString &name)
void appletAboutToBeAdded(Plasma::Applet *applet, const QRectF &geometryHint)
void appletAboutToBeRemoved(Plasma::Applet *applet)
void appletAdded(Plasma::Applet *applet, const QRectF &geometryHint)
void appletAlternativesRequested(Plasma::Applet *applet)
(since 5.16) void appletCreated(Plasma::Applet *applet, const QRectF &geometryHint)
void appletRemoved(Plasma::Applet *applet)
void appletsChanged()
void availableRelativeScreenRectChanged(const QRectF &rect)
void availableRelativeScreenRegionChanged(const QList<QRectF> &region)
void configureRequested(Plasma::Applet *applet)
void containmentDisplayHintsChanged(Plasma::Types::ContainmentDisplayHints hints)
void containmentTypeChanged()
(since 5.0) void formFactorChanged(Plasma::Types::FormFactor formFactor)
(since 5.0) void locationChanged(Plasma::Types::Location location)
void screenChanged(int newScreen)
void screenGeometryChanged(const QRectF &rect)
void showAddWidgetsInterface(const QPointF &pos)
void uiReadyChanged(bool uiReady)
void wallpaperGraphicsObjectChanged()
void wallpaperPluginChanged()

Protected Functions

virtual void restoreContents(KConfigGroup &group)
virtual void saveContents(KConfigGroup &group) const

Detailed Description

Containment objects provide the means to group applets into functional sets. They also provide the following:

  • creation of focusing event
  • drawing of the background image (which can be interactive)
  • form factors (e.g. panel, desktop, full screen, etc)
  • applet layout management

Since containment is actually just a Plasma::Applet, all the techniques used for writing the visual presentation of Applets is applicable to Containtments. Containments are differentiated from Applets by being marked with the ServiceType of Plasma/Containment. Plugins registered with both the Applet and the Containment ServiceTypes can be loaded for us in either situation.

See techbase.kde.org for a tutorial on writing Containments using this class.

Member Type Documentation

enum Containment::Type

This enumeration describes the type of the Containment. DesktopContainments represent main containments that will own a screen in a mutually exclusive fashion, while PanelContainments are accessories which can be present multiple per screen.

This value is specified in the "X-Plasma-ContainmentType" JSON-metadata value of containments.

ConstantValueDescription
Plasma::Containment::NoContainment-1 
Plasma::Containment::Desktop0A desktop containment
Plasma::Containment::Panel1A desktop panel
Plasma::Containment::Custom127A containment that is neither a desktop nor a panel but something application specific
Plasma::Containment::CustomPanel128A customized desktop panel. "CustomPanel" in metadata
Plasma::Containment::CustomEmbedded129A customized containment embedded in another applet

Property Documentation

[read-only] activity : const QString

Activity UID of this containment

Access functions:

QString activity() const

Notifier signal:

void activityChanged(const QString &activity)

[read-only] activityName : const QString

Activity name of this containment

Access functions:

QString activityName() const

Notifier signal:

void activityNameChanged(const QString &name)

[read-only] applets : QList<Plasma::Applet *> const

List of applets this containment has: the containments

Access functions:

QList<Plasma::Applet *> applets() const

Notifier signal:

[read-only] availableScreenRect : const QRectF

screen area free of panels: the coordinates are relative to the containment, it's independent from the screen position For more precise available geometry use availableScreenRegion()

Access functions:

Notifier signal:

void availableRelativeScreenRectChanged(const QRectF &rect)

containmentDisplayHints : Plasma::Types::ContainmentDisplayHints

Access functions:

Plasma::Types::ContainmentDisplayHints containmentDisplayHints() const
void setContainmentDisplayHints(Plasma::Types::ContainmentDisplayHints hints)

Notifier signal:

void containmentDisplayHintsChanged(Plasma::Types::ContainmentDisplayHints hints)

[read-only] containmentType : const Plasma::Containment::Type

Type of this containment

Access functions:

Plasma::Containment::Type containmentType() const

Notifier signal:

[read-only] corona : Plasma::Corona* const

The corona for this contaiment

Access functions:

Plasma::Corona *corona() const

[read-only] isUiReady : const bool

Access functions:

bool isUiReady() const

Notifier signal:

void uiReadyChanged(bool uiReady)

[read-only] screen : const int

The screen number this containment is serving as the desktop for, or -1 if none

Access functions:

int screen() const

Notifier signal:

void screenChanged(int newScreen)

[read-only] screenGeometry : const QRectF

Provides access to the geometry of the applet is in. Can be useful to figure out what's the absolute position of the applet.

Access functions:

QRectF screenGeometry() const

Notifier signal:

void screenGeometryChanged(const QRectF &rect)

wallpaperGraphicsObject : QObject* const

Notifier signal:

wallpaperPlugin : QString

Access functions:

QString wallpaperPlugin() const
void setWallpaperPlugin(const QString &pluginName)

Notifier signal:

Member Function Documentation

[explicit, since 5.86] Containment::Containment(QObject *parentObject, const KPluginMetaData &data, const QVariantList &args)

This constructor can be used with the KCoreAddons plugin loading system. The argument list is expected to have contain the KPackage of the applet, the meta data file path (for compatibility) and an applet ID which must be a base 10 number.

parent a QObject parent; you probably want to pass in 0

data KPluginMetaData used to create this plugin

args a list of strings containing the applet id

This function was introduced in 5.86.

QString Containment::activity() const

Returns the current activity id associated with this containment

Note: Getter function for property activity.

See also setActivity().

[signal] void Containment::activityChanged(const QString &activity)

Emitted when the activity id has changed

Note: Notifier signal for property activity.

QString Containment::activityName() const

Returns Activity name corresponding to the activity UID

Note: Getter function for property activityName.

[signal] void Containment::activityNameChanged(const QString &name)

Emitted when the activity name has changed

Note: Notifier signal for property activityName.

[invokable] void Containment::addApplet(Plasma::Applet *applet, const QRectF &geometryHint = QRectF())

Add an existing applet to this Containment

applet the applet that should be added geometryHint an hint to pass to the GUI on the location and size we prefer for the newly created applet; the gui might choose whether to respect or not this hint

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

[signal] void Containment::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 applet before the handlers of appletAdded are executed. Useful for instance to prepare the GUI for the applet

applet the applet that is about to be added

geometryHint an hint to pass to the GUI on the location and size we prefer for the newly created applet; the gui might choose whether to respect or not this hint

[signal] void Containment::appletAboutToBeRemoved(Plasma::Applet *applet)

This signal is emitted right before appletRemoved, it can be used to do a preliminary setup on the applet before the handlers of appletRemoved are executed. Useful for instance to prepare or teardown the GUI for the applet

[signal] void Containment::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 situations:

  • The user created the applet
  • The applet was moved in from another containment
  • The applet got restored at startup

applet the applet that has been added

geometryHint an hint to pass to the GUI on the location and size we prefer for the newly created applet; the gui might choose whether to respect or not this hint

[signal] void Containment::appletAlternativesRequested(Plasma::Applet *applet)

Emitted when the user wants to chose an alternative for this applet or containment.

[signal, since 5.16] void Containment::appletCreated(Plasma::Applet *applet, const QRectF &geometryHint)

This signal is emitted when a new applet is created by the containment. Compared to appletAdded, this gets emitted only when the user explicitly creates a new applet, either via the widget explorer or the scripting environment.

This function was introduced in 5.16.

See also appletAdded.

[signal] void Containment::appletRemoved(Plasma::Applet *applet)

This signal is emitted when an applet is destroyed

QList<Plasma::Applet *> Containment::applets() const

Returns the applets currently in this Containment

Note: Getter function for property applets.

[signal] void Containment::appletsChanged()

Emitted when the list of applets has changed, either added or removed

Note: Notifier signal for property applets.

QRectF Containment::availableRelativeScreenRect() const

Returns The available screen rect (excluding panels) for the screen this containment is associated to, empty rectangle if the containment is not active in a screen

Note: Getter function for property availableScreenRect.

[signal] void Containment::availableRelativeScreenRectChanged(const QRectF &rect)

Emitted when the available screen rectangle has changed

Note: Notifier signal for property availableScreenRect.

QList<QRectF> Containment::availableRelativeScreenRegion() const

Returns The available region of this screen, panels excluded. It's a list of rectangles

Note: Getter function for property availableScreenRegion.

[signal] void Containment::availableRelativeScreenRegionChanged(const QList<QRectF> &region)

Emitted when the available screen rectangle has changed

Note: Notifier signal for property availableScreenRegion.

[signal] void Containment::configureRequested(Plasma::Applet *applet)

Emitted when the user wants to configure/change the containment, or an applet inside it.

[since 5.0] QHash<QString, Plasma::ContainmentActions *> &Containment::containmentActions()

Returns all the loaded containment action plugins, indexed by trigger name

This function was introduced in 5.0.

See also setContainmentActions().

[signal] void Containment::containmentDisplayHintsChanged(Plasma::Types::ContainmentDisplayHints hints)

Emitted when the containment disaplay hints change

Note: Notifier signal for property containmentDisplayHints.

Plasma::Containment::Type Containment::containmentType() const

Returns the type of containment

Note: Getter function for property containmentType.

[signal] void Containment::containmentTypeChanged()

emitted when the containment type changed

Note: Notifier signal for property containmentType.

Plasma::Corona *Containment::corona() const

Returns the Corona (if any) that this Containment is hosted by

Note: Getter function for property corona.

Plasma::Applet *Containment::createApplet(const QString &name, const QVariantList &args = QVariantList(), const QRectF &geometryHint = QRectF(-1, -1, 0, 0))

Adds an applet to this Containment

name the plugin name for the applet, as given by KPluginInfo::pluginName()

args argument list to pass to the plasmoid

geometryHint an hint to pass to the GUI on the location and size we prefer for the newly created applet; the gui might choose whether to respect or not this hint. The default position is (-1, -1) and the default size is (0, 0).

Returns a pointer to the applet on success, or 0 on failure

[signal, since 5.0] void Containment::formFactorChanged(Plasma::Types::FormFactor formFactor)

Emitted when the formFactor has changed

This function was introduced in 5.0.

bool Containment::isUiReady() const

Returns true when the ui of this containment is fully loaded, as well the ui of every applet in it

Note: Getter function for property isUiReady.

[since 4.5] int Containment::lastScreen() const

Returns the last screen number this containment had only returns -1 if it's never ever been on a screen

This function was introduced in 4.5.

[signal, since 5.0] void Containment::locationChanged(Plasma::Types::Location location)

Emitted when the location has changed

This function was introduced in 5.0.

[virtual protected] void Containment::restoreContents(KConfigGroup &group)

Called when the contents of the containment should be loaded. By default this loads all previously saved Applets

group the KConfigGroup to save settings under

[virtual protected] void Containment::saveContents(KConfigGroup &group) const

Called when the contents of the containment should be saved. By default this saves all loaded Applets

group the KConfigGroup to save settings under

int Containment::screen() const

Returns the screen number this containment is serving as the desktop for or -1 if none

Note: Getter function for property screen.

[signal] void Containment::screenChanged(int newScreen)

This signal indicates that a containment has been associated (or dissociated) with a physical screen.

newScreen the screen it is now associated with

Note: Notifier signal for property screen.

QRectF Containment::screenGeometry() const

Returns The geometry of the screen this containment is associated to

Note: Getter function for property screenGeometry.

[signal] void Containment::screenGeometryChanged(const QRectF &rect)

Emitted when the screen geometry has changed

Note: Notifier signal for property screenGeometry.

void Containment::setActivity(const QString &activityId)

Sets the current activity by id

activityId the id of the activity

See also activity().

[since 4.4] void Containment::setContainmentActions(const QString &trigger, const QString &pluginName)

Sets a containmentactions plugin.

trigger the mouse button (and optional modifier) to associate the plugin with

pluginName the name of the plugin to attempt to load. blank = set no plugin.

This function was introduced in 4.4.

See also containmentActions().

[slot, since 5.77] void Containment::setContainmentDisplayHints(Plasma::Types::ContainmentDisplayHints hints)

Set Display hints that come from the containment that suggest the applet how to look and behave.

hints the new hints, as bitwise OR

Note: Setter function for property containmentDisplayHints.

This function was introduced in 5.77.

[slot] void Containment::setFormFactor(Plasma::Types::FormFactor formFactor)

Sets the form factor for this Containment. This may cause changes in both the arrangement of Applets as well as the display choices of individual Applets.

[slot] void Containment::setLocation(Plasma::Types::Location location)

Informs the Corona as to what position it is in. This is informational only, as the Corona doesn't change its actual location. This is, however, passed on to Applets that may be managed by this Corona.

location the new location of this Corona

void Containment::setWallpaperPlugin(const QString &pluginName)

Sets wallpaper plugin.

pluginName the name of the wallpaper to attempt to load

Note: Setter function for property wallpaperPlugin.

See also wallpaperPlugin().

[signal] void Containment::showAddWidgetsInterface(const QPointF &pos)

Emitted when the containment requests an add widgets dialog is shown. Usually only used for desktop containments.

pos where in the containment this request was made from, or an invalid position (QPointF()) is not location specific

[signal] void Containment::uiReadyChanged(bool uiReady)

Emitted when the ui has been fully loaded and is fully working

uiReady true when the ui of the containment is ready, as well the ui of each applet in it

Note: Notifier signal for property isUiReady.

[signal] void Containment::wallpaperGraphicsObjectChanged()

Emitted when the root wallpaper item has changed

Note: Notifier signal for property wallpaperGraphicsObject.

QString Containment::wallpaperPlugin() const

Return wallpaper plugin.

Note: Getter function for property wallpaperPlugin.

See also setWallpaperPlugin().

[signal] void Containment::wallpaperPluginChanged()

Emitted when the wallpaper plugin is changed

Note: Notifier signal for property wallpaperPlugin.