* '''property Component compactRepresentation''': if the plasmoid is a popupapplet, the component in compactRepresentation will be used instead of the icon and will always be collapsed, regardless if it's in a panel or not.

* '''property Component compactRepresentation''': if the plasmoid is a popupapplet, the component in compactRepresentation will be used instead of the icon and will always be collapsed, regardless if it's in a panel or not.

+

+

= The Global Plasmoid Object =

+

+

As in the [http://techbase.kde.org/Development/Tutorials/Plasma/JavaScript/API#The_Global_plasmoid_Object JavaScript API], there is a global ''plasmoid'' object. However, its API is a little different, largely because QML directly provides access to many functions and events that the global plasmoid object provides in the JavaScript API. There are differences in event reporting, in particular.

+

+

== Environment ==

+

+

A set of read-only properties (and in most cases notification functions) that tell the Plasmoid about its current environment:

+

+

* ''FormFactor'' '''formFactor''': See the [http://api.kde.org/4.10-api/kdelibs-apidocs/plasma/html/namespacePlasma.html#ad4a234ba4043af84f610c376159a862a FormFactor] documentation for values and their meaning. When the form factor changes, the plasmoid.formFactorChanged signal is emitted.

+

+

* ''Location'' '''location''': See the [http://api.kde.org/4.10-api/kdelibs-apidocs/plasma/html/namespacePlasma.html#a2e56eee20e28bd3df07081e9ac7cf72b Location] documentation for values and their meaning. When the location changes, the plasmoid.locationChanged signal is emitted.

+

+

* ''boolean'' '''immutable''': this property is set to true when the Plasmoid is set to not be movable or otherwise changeable, and false otherwise. Configuration is still usually allowed in this state. When the immutability changes, the plasmoid.immutableChanged signal is emitted.

+

+

* ''string'' '''currentActivity''': the current contextual activity name. When the current activity changes, the plasmoid.contextChanged signal is emitted.

+

+

* ''boolean'' '''shouldConserveResources''': true if the plasmoid should not be doing anything that would create too much draw on power, e.g. when on a device with low battery power it may be a good idea not to run a computationally expensive but optional animation

+

+

* ''boolean'' '''userConfiguring''': true if the user configuration interface is currently being displayed.

+

+

== Properties ==

+

+

A set of read/write properties that allow the Plasmoid to set various visual or functional properties:

+

+

* ''AspectRatioMode'' '''aspectRatioMode''': defines how to treat the aspect ratio of a Plasmoid when resizing it. See the [http://api.kde.org/4.10-api/kdelibs-apidocs/plasma/html/namespacePlasma.html#a19549b928c541b25f018703effeea236 AspectRatioMode] documentation for values and their meaning.

+

+

* ''BackgroundHints'' '''backgroundHints''': defines how the background of the widget is rendered. See the [http://api.kde.org/4.10-api/kdelibs-apidocs/plasma/html/classPlasma_1_1Applet.html#a0d91e3f0a945121e5cd399c6850e8754 BackgroundHints] documentation for values and their meaning.

+

+

* ''boolean'' '''busy''': set to true when the Plasmoid is currently processing or waiting for data and the user interface should be blocked while doing so; will generally show a full-Plasmoid animated overlay to denote business

+

+

* ''SizePolicy'' '''horizontalSizePolicy''': behaviour of the plasmoid in an horizontal layout such as a panel. See the [http://techbase.kde.org/Development/Tutorials/Plasma/JavaScript/API-PlasmoidObject#Properties JavaScript API documentation] for more information.

+

+

* ''SizePolicy'' '''verticalSizePolicy''': behaviour of the plasmoid in a vertical layout such as a panel.

+

+

* ''ItemStatus'' '''status''': See [http://api.kde.org/4.10-api/kdelibs-apidocs/plasma/html/namespacePlasma.html#a4d967711130487b1070311626ad285cb ItemStatus documentation] for values and their meaning. The plasmoid.statusChanged signal is emitted when the status changes.

+

+

=== PopupApplet specific ===

+

* ''QIcon'' '''popupIcon''': it will be used instead of the applet content when the applet is in a panel

+

* ''Object'' '''popupIconToolTip''': it contains the icon, mainText and subtext for the tooltip the applet will have when collapsed in an icon, properties:

+

** ''variant'' '''image''': the icon, it may be an icon name, an image path, a QIcon, QImage or a QPixmap

+

** ''String'' '''mainText''': the tooltip title

+

** ''String'' '''subText''': the tooltip descriptive subtext

+

+

<syntaxhighlight lang="javascript">

+

var data = new Object

+

data["image"] = "konqueror"

+

data["mainText"] = "ToolTip title"

+

data["subText"] = "ToolTip descriptive sub text"

+

plasmoid.popupIconToolTip = data

+

</syntaxhighlight>

+

+

* ''bool'' '''passivePopup''': if true when the popup is opened other windows can gain focus and the popup won't close

+

+

* ''bool'' '''popupShowing''': true when the popupapplet is iconified and its popup is open

+

+

=== Containment specific ===

+

* ''Array(Object)'' '''applets''': List of all applets in the containment

+

* ''bool'' '''drawWallpaper''': Enable/disable the wallpaper painting by the containment

+

* ''enum'' '''containmentType''': one of

+

** ''DesktopContainment'': A desktop containment

+

** ''PanelContainment'': A desktop panel

+

** ''CustomContainment'': A containment that is neither a desktop nor a panel but something application specific

+

** ''CustomPanelContainment'': A customized desktop panel

+

+

* ''int'' '''screen''': Number of the screen this containment is in

+

* ''string'' '''activityName''': The name of the activity this containment belongs to.

+

* ''string'' '''activityId''': The id of the activity this containment belongs to.

+

+

* ''ToolBox'' '''toolBox()''': The toolbox of the Containment. The ToolBox is rendered as a separate item on the scene and provides access to the following properties:

+

** ''Array(QAction)'' '''actions''': A list of actions provided by the Containment.

+

+

+

== Events ==

+

+

Note that many of the events of the JavaScript API are signals in the declarative API (eg: formFactorChanged). These should be connected to in the usual way, for example:

+

<syntaxhighlight lang="javascript">

+

plasmoid.formFactorChanged.connect(function() { ... });

+

</syntaxhighlight>

+

<br>

+

However, some notifications are still delivered by events, which should be connected to using ''addEventListener'':

* String '''sourceFilter''': it's a regular expression. If the DataSource is connected to more than one source, only inserts data from sources matching this filter expression in the model. To, for example, have a source watch all sources beginning with say "name:", the required regexp would be sourceFilter: "name:.*"

* String '''sourceFilter''': it's a regular expression. If the DataSource is connected to more than one source, only inserts data from sources matching this filter expression in the model. To, for example, have a source watch all sources beginning with say "name:", the required regexp would be sourceFilter: "name:.*"

−

* String '''keyRoleFilter''': it's a regular expression. Only data with keys that match this filter expression will be inserted in the model

+

* String '''keyRoleFilter''': it's a regular expression. Only data with keys that match this filter expression will be inserted in the model. If you need all data inserted in the mode, you must explicitly request it using the regular expression ".*"

* int '''count''' (read only): how many items are in the model

* int '''count''' (read only): how many items are in the model

Line 182:

Line 318:

* String '''sortRole'''

* String '''sortRole'''

* Qt::SortOrder '''sortOrder'''

* Qt::SortOrder '''sortOrder'''

+

* Qt::CaseSensitivity '''sortCaseSensitivity'''

* int '''count''' (read only)

* int '''count''' (read only)

Line 257:

Line 394:

* Font '''desktopFont''' (read only)

* Font '''desktopFont''' (read only)

* Font '''smallestFont''' (read only)

* Font '''smallestFont''' (read only)

+

* int '''smallIconSize''' (read only)

+

* int '''smallMediumIconSize''' (read only)

+

* int '''mediumIconSize''' (read only)

+

* int '''largeIconSize''' (read only)

+

* int '''hugeIconSize''' (read only)

+

* int '''enormousIconSize''' (read only)

+

* int '''defaultIconSize''' (read only)

Each Font element has the following properties:

Each Font element has the following properties:

Line 271:

Line 415:

* real '''wordSpacing''' (read only)

* real '''wordSpacing''' (read only)

* size '''mSize''' the size, width and height of an uppercase "M" in this font (read only)

* size '''mSize''' the size, width and height of an uppercase "M" in this font (read only)

+

+

Theme is also used to control icon sizes, with the property '''iconSizes'''. it is an Object, that has the following properties:

+

* int '''desktop''': size of icons suited for the workspace

+

* int '''toolbar''': icons to be put in a ToolBar component

+

* int '''small''': smallest size for still "readable" icons

+

* int '''dialog''': icons to be put in popup dialogs

=== Svg ===

=== Svg ===

Line 442:

Line 592:

== Containments ==

== Containments ==

−

A Plasma Containment manages the position and manipulation of Plasmoids.

+

A Plasma Containment manages the position and manipulation of Plasmoids. The declarative containment is responsible for layout of applets and can provide custom applet handles. The containment should listen to the plasmoid.immutability property. In order to lay out applets in your containment, you can use the AppletContainer class to access geometry information of applets.

+

Actions such as configure and close are available through plasmoid.actions.

+

You can access the plasmoid global property from containments in the same way as from declarative and javascript plasmoids. If the plasmoid is a Containment, you can get a list of actions for it. If you want to provide background rendering in your Containment yourself, read the applet.backgroundHints property and after that set applet.backgroundHints to 0 to tell the Applet that is should not render the background.

+

=== AppletContainer ===

=== AppletContainer ===

The AppletContainer class provides access to the geometry and status of Plasmoids in this Containment.

The AppletContainer class provides access to the geometry and status of Plasmoids in this Containment.

Properties:

Properties:

+

* ''Item'' '''applet''': The applet item, this property allows you to track destruction of the actual applet and update your layout.

+

** ''int'' '''backgroundHints''': Should the Applet be rendered on top of a background frame? 0 for no background, 1 for default background, 2 for translucent background

* ''int'' '''minimumWidth''': The minimum width of the applet

* ''int'' '''minimumWidth''': The minimum width of the applet

* ''int'' '''minimumHeight''': The minimum height of the applet

* ''int'' '''minimumHeight''': The minimum height of the applet

Line 468:

Line 623:

AppletContainer is only available for Plasma/Containment packages, and only if they are loaded as containment. AppletContainer is new in 4.10.

AppletContainer is only available for Plasma/Containment packages, and only if they are loaded as containment. AppletContainer is new in 4.10.

−

== ToolBox ==

+

=== ToolBox ===

The ToolBox is only available through the plasmoid object, through plasmoid.toolBox(). The ToolBox is rendered as a separate item on top of the scene covering the entire containment. It is loaded from the "org.kde.toolbox" Plasma Package, if the package is not found, no ToolBox will be loaded.

The ToolBox is only available through the plasmoid object, through plasmoid.toolBox(). The ToolBox is rendered as a separate item on top of the scene covering the entire containment. It is loaded from the "org.kde.toolbox" Plasma Package, if the package is not found, no ToolBox will be loaded.

The ToolBox provides a listmodel of actions that can be rendered using Repeaters or ListViews. The ''actions'' list property contains actions from the Corona and Containments. Examples for these actions are showing the add widget or activities interface, lock and unlock. The actions in the list change dynamically whenever the widgets are locked or unlocked.

The ToolBox provides a listmodel of actions that can be rendered using Repeaters or ListViews. The ''actions'' list property contains actions from the Corona and Containments. Examples for these actions are showing the add widget or activities interface, lock and unlock. The actions in the list change dynamically whenever the widgets are locked or unlocked.

Line 483:

Line 638:

import org.kde.plasma.containments 0.1 as PlasmaContainments

import org.kde.plasma.containments 0.1 as PlasmaContainments

</syntaxhighlight>

</syntaxhighlight>

+

ToolBox is only available for Containments and new in 4.10.

ToolBox is only available for Containments and new in 4.10.

Line 527:

Line 683:

* QPixmapItem.Tile: the image is duplicated horizontally and vertically

* QPixmapItem.Tile: the image is duplicated horizontally and vertically

* QPixmapItem.TileVertically: the image is stretched horizontally and tiled vertically

* QPixmapItem.TileVertically: the image is stretched horizontally and tiled vertically

Introduction to the Plasmoid QML Declarative API

This document provides an overview/reference of the Declarative QML API for Plasmoids. It isn't a full binding to all of Qt or KDE's libraries, but a focused set of bindings designed to make writing Plasmoids fast and easy, while remaining powerful.

The API in this documentation covers the API of the Plasma specific QML components, so only the Declarative part of the API.

The QML ScriptEngine is based upon the Plasma JavaScript engine, making the API of the JavaScript part identical to the one of the JavaScript plasmoids engine.
The most important API for using graphical widgets is the Plasma QtComponents API

What Is a Declarative Plasmoid?

To denote that this Plasmoid is a Declarative widget, ensure that in the metadata.desktop file there is this line:

X-Plasma-API=declarativeappletscript

What follows is a description of the Plasma declarative classes instantiable from QML.

fetching data from the plasmoid package

If you have a file in your plasmoid package under contents, let's say an image, you can access it with the plasmapackage url protocol:

Image {
source:"plasmapackage:/images/foo.png"}

The above code will load in the Image component the file foo.png located in contents/images of your plasmoid package.

import"plasmapackage:/code/foo.js"as Foo

Similarly, the above code will import a javascript file from the folder contents/code of your plasmoid package.

Properties exported from the main QML item

The root qml item can export some properties to influence its behavior:

property Component compactRepresentation: if the plasmoid is a popupapplet, the component in compactRepresentation will be used instead of the icon and will always be collapsed, regardless if it's in a panel or not.

The Global Plasmoid Object

As in the JavaScript API, there is a global plasmoid object. However, its API is a little different, largely because QML directly provides access to many functions and events that the global plasmoid object provides in the JavaScript API. There are differences in event reporting, in particular.

Environment

A set of read-only properties (and in most cases notification functions) that tell the Plasmoid about its current environment:

FormFactorformFactor: See the FormFactor documentation for values and their meaning. When the form factor changes, the plasmoid.formFactorChanged signal is emitted.

Locationlocation: See the Location documentation for values and their meaning. When the location changes, the plasmoid.locationChanged signal is emitted.

booleanimmutable: this property is set to true when the Plasmoid is set to not be movable or otherwise changeable, and false otherwise. Configuration is still usually allowed in this state. When the immutability changes, the plasmoid.immutableChanged signal is emitted.

stringcurrentActivity: the current contextual activity name. When the current activity changes, the plasmoid.contextChanged signal is emitted.

booleanshouldConserveResources: true if the plasmoid should not be doing anything that would create too much draw on power, e.g. when on a device with low battery power it may be a good idea not to run a computationally expensive but optional animation

booleanuserConfiguring: true if the user configuration interface is currently being displayed.

Properties

A set of read/write properties that allow the Plasmoid to set various visual or functional properties:

AspectRatioModeaspectRatioMode: defines how to treat the aspect ratio of a Plasmoid when resizing it. See the AspectRatioMode documentation for values and their meaning.

BackgroundHintsbackgroundHints: defines how the background of the widget is rendered. See the BackgroundHints documentation for values and their meaning.

booleanbusy: set to true when the Plasmoid is currently processing or waiting for data and the user interface should be blocked while doing so; will generally show a full-Plasmoid animated overlay to denote business

SizePolicyhorizontalSizePolicy: behaviour of the plasmoid in an horizontal layout such as a panel. See the JavaScript API documentation for more information.

SizePolicyverticalSizePolicy: behaviour of the plasmoid in a vertical layout such as a panel.

ItemStatusstatus: See ItemStatus documentation for values and their meaning. The plasmoid.statusChanged signal is emitted when the status changes.

PopupApplet specific

QIconpopupIcon: it will be used instead of the applet content when the applet is in a panel

ObjectpopupIconToolTip: it contains the icon, mainText and subtext for the tooltip the applet will have when collapsed in an icon, properties:

variantimage: the icon, it may be an icon name, an image path, a QIcon, QImage or a QPixmap

Properties

bool valid (read only): true when the DataSource is successfully connected to a data engine

int interval: interval of polling of the dataengine, if 0 (default value, so no need to specify if you don't need it) no polling will be executed

string engine: the plugin name of the dataengine to load, e.g. "nowplaying", etc.

Array(string) connectedSources: all the sources of the dataengine we are connected to (and whose data will appear in the data property)

Array(string) sources (read only): all the sources available from the dataengine

variant map data (read only): It's the most important property, it's a map of all the data available from the dataengine: its structure will be as follows:

each key of the map will be a source name, in connectedSources

each value will be a variant hash, so an hash with strings as keys and any variant as value

example: dataSource.data["Local"]["Time"] indicates the Time key of the dataengine source called "Local"

string sourceFilter it's a regular expression. If the DataSource is connected to more than one source, only inserts data from sources matching this filter expression in the model. If we want to have a source watch all sources beginning with say "name:", the required regexp would be sourceFilter: "name:.*"

Signals

It has the following signals:

Note that javascript/qml applies the 'on' prefix to signals. So the actual signal name in C++ which is e.g. newData(...) becomes onNewData(...).

onNewData(String sourceName, Plasma::DataEngine::Data data) the local vairables are named to sourceName and data

onSourceAdded(String source)

onSourceRemoved(String source)

onSourceConnected(String source)

onSourceDisconnected(String source)

onIntervalChanged()

onEngineChanged()

onDataChanged()

onConnectedSourcesChanged()

onSourcesChanged()

You normaly wants to use onNewData (that is the aquivalent to dataUpdated in other languages). Here is sample with the time dataengine:

Service

Due to their imperative nature, Plasma Services are not instantiated as QML classes, but rather created out of a DataSource with the method serviceForSource and used in the JavaScript portions of the QML files.
This following example is a simplified version from the Now Playing QML widget in the kdeexamples git repository:

Here dataSource is the id of a DataSource object, and activeSource is a source contained in one of its connectedSources.
The service provides an operation called "seek", with a parameter called "seconds", that can be written on it as a property of a JavaScript object.

ServiceJob

It is necessary to monitor the result of a Service operation, it's possible to connect to the finished signal provided by the job return paramenter of the startOperationCall service method.
The finished signal has the same job as parameter, from which is possible to check the variant result property, to check the result.

DataModel

Some data engines return as their data something that can be interpreted as a list of items, rather than simple key/value pairs.
QML provides some item views such as ListView, GridView and Repeater.
The DataModel QML object can provide, based on a DataSource a model suitable for those QML item views.

It has the following properties:

DataSource dataSource: the id of an existing (and connected) DataSource

String sourceFilter: it's a regular expression. If the DataSource is connected to more than one source, only inserts data from sources matching this filter expression in the model. To, for example, have a source watch all sources beginning with say "name:", the required regexp would be sourceFilter: "name:.*"

String keyRoleFilter: it's a regular expression. Only data with keys that match this filter expression will be inserted in the model. If you need all data inserted in the mode, you must explicitly request it using the regular expression ".*"

In the example, microblogSource is the id of a DataSource, and inserts in the model only entries that have a number as the key name (matched with [\\d]*, in this case tweets ids)

Each item in the model will have the form of a variant hash: all the keys of the hash will be registered as model role names, in the example, "title" is a role of the model containing a string (also reachable with model["title"]).

A special reserved role will always be present: "DataEngineSource": it will contain the name of the data engine source that gave origin to this item. Therefore, if you want merely the string of the current source that the model is at...do model["DataEngineSource"].

SortFilterModel

SortFilterModel is a proxy model for easy sorting and/or filtering of the items in a DataModel (or any other QAbstractItemModel subclass that has been registered in QML with setContextProperty from a C++ application)
Properties:

Popup Applet

So you want your QML applet to be a popup applet, like the device notifier (an icon in the panel shows and expands the applet)?

Why, that's easy.

To change your plasmoid from being a regular boring one, in your metadata.desktop, simply change this following line:

ServiceTypes=Plasma/Applet

To:

ServiceTypes=Plasma/Applet,Plasma/PopupApplet

Then in the main QML item's Component.onCompleted, do:

plasmoid.popupIcon="konqueror"

If you want to use other elements instead of an icon when collapsed in a panel, use the compactRepresentation property in the root Item.

Plasma Themes

Theme

This class instantiable from QML provides access to the Plasma Theme colors and other facilities such as fonts.
From KDE 4.8 a Theme instance is always present given the org.kde.plasma.core plugin was imported, is not necessary to create it by hand.
It has the following properties:

Svg

String imagePath can be anything in the desktoptheme/ folder. For more information on what is available, see Plasma Theme Elements. Make sure to strip the final extension from this string, so you should for example use "dialogs/background" to get the standard background.

bool usingRenderingCache

Methods:

QPixmap pixmap(QString elementID)

void resize(qreal width, qreal height)

void resize(): resets the image to its default dimension

QSize elementSize(QString elementId)

QRectF elementRect(QString elementId)

bool hasElement(QString elementId)

bool isValid(): true if valid svg file

FrameSvg

Declaring a FrameSvg element instantiates a Plasma FrameSvg instance. This class doesn't draw anything. For drawing, FrameSvgItem is used.
This is to be used when you need informations about the framesvg, such as hasElementPrefix().

Properties:

All properties from Svg

EnabledBorders enabledBorders: flag combination of:

NoBorder

TopBorder

BottomBorder

LeftBorder

RightBorder

Methods:

All methods from Svg

void setImagePath(QString path)

void resizeFrame(QSize size)

QSize frameSize()

qreal marginSize(Plasma::MarginEdge edge)

void getMargins(qreal left, qreal top, qreal right, qreal bottom): parameters are output, they get set with the margins from the FrameSvg

QRectF contentsRect(): the rectangle of the center element, taking the margins into account.

QPoint popupPosition(Item item, Qt::Alignment alignment=Qt::AlignLeft): the suggested position for the Dialog if it has to be correctly placed as popup of the QML item passed as parameter.

void setAttribute(Qt::WindowAttribute attribute, bool on): set an attribute for the dialog window

Margins

Properties:

real left (read only)

real top (read only)

real right (read only)

real bottom (read only)

ToolTip

Declaring a ToolTip instance makes it possible to use Plasma tooltips with any QML item.

Properties:

Item target: the QML item we want to show a tooltip of

String mainText

String subText

String image: freedesktop compliant icon name as image of the tooltip

Containments

A Plasma Containment manages the position and manipulation of Plasmoids. The declarative containment is responsible for layout of applets and can provide custom applet handles. The containment should listen to the plasmoid.immutability property. In order to lay out applets in your containment, you can use the AppletContainer class to access geometry information of applets.
Actions such as configure and close are available through plasmoid.actions.
You can access the plasmoid global property from containments in the same way as from declarative and javascript plasmoids. If the plasmoid is a Containment, you can get a list of actions for it. If you want to provide background rendering in your Containment yourself, read the applet.backgroundHints property and after that set applet.backgroundHints to 0 to tell the Applet that is should not render the background.

AppletContainer

The AppletContainer class provides access to the geometry and status of Plasmoids in this Containment.
Properties:

Itemapplet: The applet item, this property allows you to track destruction of the actual applet and update your layout.

intbackgroundHints: Should the Applet be rendered on top of a background frame? 0 for no background, 1 for default background, 2 for translucent background

intminimumWidth: The minimum width of the applet

intminimumHeight: The minimum height of the applet

intmaximumWidth: The maximum width of the applet

intmaximumHeight: The maximum height of the applet

intpreferredWidth: The preferred height of the applet

intpreferredHeight: The preferred height of the applet

enumstatus: The status of the applet, one in the enum

UnknownStatus: The status is unknown

PassiveStatus: The applet is passive

ActiveStatus: The applet is active

NeedsAttentionStatus: The applet asks for attention

AcceptingInputStatus: The applet is accepting input

They can be imported in your code with:

import org.kde.plasma.containments0.1as PlasmaContainments

AppletContainer is only available for Plasma/Containment packages, and only if they are loaded as containment. AppletContainer is new in 4.10.

ToolBox

The ToolBox is only available through the plasmoid object, through plasmoid.toolBox(). The ToolBox is rendered as a separate item on top of the scene covering the entire containment. It is loaded from the "org.kde.toolbox" Plasma Package, if the package is not found, no ToolBox will be loaded.
The ToolBox provides a listmodel of actions that can be rendered using Repeaters or ListViews. The actions list property contains actions from the Corona and Containments. Examples for these actions are showing the add widget or activities interface, lock and unlock. The actions in the list change dynamically whenever the widgets are locked or unlocked.
Actions such as lock screen and leave can be implemented using the powermanagement dataengine's services for these functions.

ToolBox provides access to the following properties:

Array(QAction)actions: A list of actions provided by the Containment. These actions' most interesting properties are: