m (→PopupApplet specific) |
(→Geometry) |
||
| (7 intermediate revisions by 2 users not shown) | |||
| Line 84: | Line 84: | ||
== PopupApplet specific == | == PopupApplet specific == | ||
| − | * QIcon '''popupIcon''': it will be used instead of the applet content when the applet is in a panel | + | * ''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: | + | * ''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 | + | ** ''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'' '''mainText''': the tooltip title |
| − | ** | + | ** ''String'' '''subText''': the tooltip descriptive subtext |
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
| Line 98: | Line 98: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | * bool '''passivePopup''': if true when the popup is opened other windows can gain focus and the popup won't close | + | * ''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 == | == Containment specific == | ||
| − | * '' | + | * ''Array(Object)'' '''applets''': List of all applets in the containment |
| − | * ''drawWallpaper'': | + | * ''bool'' '''drawWallpaper''': Enable/disable the wallpaper painting by the containment |
| − | * ''containmentType'': one of | + | * ''enum'' '''containmentType''': one of |
** ''DesktopContainment'': A desktop containment | ** ''DesktopContainment'': A desktop containment | ||
** ''PanelContainment'': A desktop panel | ** ''PanelContainment'': A desktop panel | ||
| Line 109: | Line 111: | ||
** ''CustomPanelContainment'': A customized desktop panel | ** ''CustomPanelContainment'': A customized desktop panel | ||
| − | * ''screen'': | + | * ''int'' '''screen''': Number of the screen this containment is in |
| − | * ''activityName'': | + | * ''string'' '''activityName''': The name of the activity this containment belongs to. |
| − | * ''activityId'': | + | * ''string'' '''activityId''': The id of the activity this containment belongs to. |
| + | |||
| + | The following API is only available from declarative containments. | ||
| + | * ''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. | ||
= Geometry = | = Geometry = | ||
| Line 122: | Line 128: | ||
Functions: | Functions: | ||
| − | * '''resize(width, height)''' | + | * '''resize(width, height)''' - must not be called on widget creation (that will break external resizing; e.g. user interaction), and should only be called as a last resort during runtime. Almost always content should scale to the size of the plasmoid. |
| − | * '''setMinimumSize(width, height)''' | + | * '''setMinimumSize(width, height)''' - Not to be used from QML, where top level minimumWidth and minimumHeight properties are used instead |
| − | * '''setPreferredSize(width, height)''' | + | * '''setPreferredSize(width, height)''' - Not to be used from QML |
* '''setBackgroundHints(background)''' - use '''NoBackground''' as value if you want to remove the default plasmoid background box. | * '''setBackgroundHints(background)''' - use '''NoBackground''' as value if you want to remove the default plasmoid background box. | ||
* '''popupIcon(QIcon("some icon"))''' - set icon to show when the plasmoid is added to the taskbar. NOTE if the plasmoid is made in QML, you MUST specify a default size for the main Item. This size will be used for the plasmoid when added to the taskbar | * '''popupIcon(QIcon("some icon"))''' - set icon to show when the plasmoid is added to the taskbar. NOTE if the plasmoid is made in QML, you MUST specify a default size for the main Item. This size will be used for the plasmoid when added to the taskbar | ||
| Line 185: | Line 191: | ||
Functions: | Functions: | ||
| − | * '''setAction(String name, String text, String icon, String shortcut)''': adds an item to the context menu with the given text and icon; you need to define '''plasmoid.action_<name>''' function, where <name> is the first argument for setAction call, and this function will be called each time user clicks the item | + | * '''setAction(String name, String text, String icon, String shortcut)''': adds an item to the context menu with the given text and icon; |
| + | In pure JavaScript plasmoids you need to define '''plasmoid.action_<name>''' function, where <name> is the first argument for setAction call, and this function will be called each time user clicks the item. | ||
| + | Similarly in QML plasmoids you must define a function '''action_<name>''' in the root qml item that will handle the action click. | ||
* '''setActionSeparator(String name)''': (API v5) adds a separator item to the context menu | * '''setActionSeparator(String name)''': (API v5) adds a separator item to the context menu | ||
* '''removeAction(String name)''': removes the item with <name> | * '''removeAction(String name)''': removes the item with <name> | ||
Contents |
There is a global object available to the Plasmoid called, appropriately, "plasmoid". It has a number of useful properties (some of which are read only, but many of which are read/write), functions, constant values and callbacks. Each are enumerated below. All of those are valid for both JavaScript and QML bindings.
See the section on Events above.
There are some events that are generated by Plasma for the Plasmoid. These can often be caught by providing a function assigned to a specific name in the plasmoid object. For instance, to get notified of form factor changes, one would provide a formFactorChanged method as follows:
plasmoid.formFactorChanged = function() { print("the form factor has changed to: " + plasmoid.formFactor()) }
The following callbacks are used to notify the Plasmoid of changes in its running environment:
Other callbacks include:
In API v2, all of these callbacks can also be used as events. So, for instance, instead of implementing plasmoid.popupEvent, one could also write:
plasmoid.addEventListener('popupEvent', function(shown) { print('shown? ' + shown) } )
This would also suppress any calls to plasmoid.popupEvent.
Further documentation on these callbacks can be found in the relevant sections below.
A set of read-only properties (and in most cases notification functions) that tell the Plasmoid about its current environment:
A set of read/write properties that allow the Plasmoid to set various visual or functional properties:
var data = new Object data["image"] = "konqueror" data["mainText"] = "ToolTip title" data["subText"] = "ToolTip descriptive sub text" plasmoid.popupIconToolTip = data
The following API is only available from declarative containments.
Read Only Properties:
Functions:
To paint directly on to the canvas, a widget may implement the paintInterface function in the plasmoid object:
plasmoid.paintInterface = function(painter) { /* painting code goes here*/ }
See the Painting section below for information about helpful classes and functions that can be used when implementing a paintInterface function.
Read/Write Properties:
Functions:
Functions:
var path = plasmoid.file("mainscript")
or
var pm = new QPixmap(plasmoid.file("images", "mypixmap.png"))
Configuration values can be defined using KConfig XT XML files in the contents/config/ directory of the Plasmoid's package. The default file that is looked for and used is contents/config/main.xml.
Read-write properties:
Functions:
User customization can be offered by providing a Qt Designer file called contents/ui/config.ui in the Plasmoid's package.
Callbacks:
It's possible to add some items to the popup menu of the Plasmoid.
Functions:
In pure JavaScript plasmoids you need to define plasmoid.action_<name> function, where <name> is the first argument for setAction call, and this function will be called each time user clicks the item. Similarly in QML plasmoids you must define a function action_<name> in the root qml item that will handle the action click.