(→Context menu) |
(→Geometry) |
||
| (15 intermediate revisions by 3 users not shown) | |||
| Line 66: | Line 66: | ||
A set of read/write properties that allow the Plasmoid to set various visual or functional 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 [[# | + | * ''AspectRatioMode'' '''aspectRatioMode''': defines how to treat the aspect ratio of a Plasmoid when resizing it. See the [[http://lxr.kde.org/source/kde/kde-runtime/plasma/scriptengines/javascript/plasmoid/appletinterface.h#120|AspectRatioMode]] documentation for values and their meaning. |
* ''BackgroundHints'' '''backgroundHints''': defines how the background of the widget is rendered. See the [[#BackgroundHints|BackgroundHints]] documentation for values and their meaning. | * ''BackgroundHints'' '''backgroundHints''': defines how the background of the widget is rendered. See the [[#BackgroundHints|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 | * ''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. It may be: | ||
| + | ** ''Fixed'': The QWidget::sizeHint() is the only acceptable alternative, so the widget can never grow or shrink (e.g. the vertical direction of a push button). | ||
| + | ** ''Minimum'': The sizeHint() is minimal, and sufficient. The widget can be expanded, but there is no advantage to it being larger (e.g. the horizontal direction of a push button). It cannot be smaller than the size provided by sizeHint(). | ||
| + | ** ''Maximum'': The sizeHint() is a maximum. The widget can be shrunk any amount without detriment if other widgets need the space (e.g. a separator line). It cannot be larger than the size provided by sizeHint(). | ||
| + | ** ''Preferred'': The sizeHint() is best, but the widget can be shrunk and still be useful. The widget can be expanded, but there is no advantage to it being larger than sizeHint() (the default QWidget policy). | ||
| + | ** ''Expanding'': The sizeHint() is a sensible size, but the widget can be shrunk and still be useful. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a horizontal slider). | ||
| + | ** ''MinimumExpanding'': The sizeHint() is minimal, and sufficient. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a horizontal slider). | ||
| + | ** ''Ignored'': The sizeHint() is ignored. The widget will get as much space as possible. | ||
| + | |||
| + | * ''SizePolicy'' '''verticalSizePolicy''': behaviour of the plasmoid in a vertical layout such as a panel. | ||
| + | |||
| + | == 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. | ||
| + | |||
| + | 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 81: | 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 144: | 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.