Ubuntu.Components.Action
Describe an action that can be re-used and shared between different components. More...
Import Statement: | import Ubuntu.Components 1.3 |
- Obsolete members
Properties
- description : string
- enabled : bool
- iconName : string
- iconSource : url
- keywords : string
- name : string
- parameterType : enum
- shortcut : var
- text : string
- visible : bool
Signals
- triggered(var value)
Methods
- trigger(var value)
Detailed Description
Actions can be used to define a specific task to be executed in different contexts using different components. The same action can be assigned to a Button, a Checkbox or even a TextField. The triggered signal is emitted depending on the component. Button and CheckBox for instance emits the signal when clicked, whereas TextField emits the signal when its accepted signal is triggered.
If the parameterType property is set, the Action is said to be parameterised. This means that when it is bound to a menu or button, the action expects a typed input parameter. The type affects the allowed value of the QVariant that must be passed to the trigger and triggered.
Action { id: action parameterType: Action.Integer text: "Int value" onTriggered: { // the value will be undefined console.log("value is", value); } Component.onCompleted: trigger("Hello World!") }
When an Action is assigned to a component, the component takes the values from the action itself. Therefore assigning the action to a Button is enough to set up the label and the icon to be shown by the button.
Action { id: stock iconName: "call" text: "Call" } Button { // this binding will set the Button's text, iconName and // iconSource properties. action: stock }
Actions are used to populate different Popovers like ActionSelectionPopover as well as to define actions for pages, or when defining options in ListItemOptions
.
Examples: See Page
Mnemonics
Since Ubuntu.Components 1.3 Action supports mnemonics. Mnemonics are shortcuts defined in the text property, prefixed the shortcut letter with &. For instance "\&Call"
will bint the "Alt-C"
shortcut to the action. When a mnemonic is detected on the Action and a keyboard is attached to the device, the text property will provide a formatted text having the mnemonic letter underscored.
Action { id: call iconName: "call" text: "&Call" }
Property Documentation
description : string |
User visible secondary description for the action. Description is more verbose than the text and should describe the Action with couple of words.
enabled : bool |
If set to false the action can not be triggered. Components visualizing the action migth either hide the action or make it insensitive. However visibility can be controlled separately using the visible property.
iconName : string |
The icon associated with the action. If both iconName and iconSource are defined, iconName will be ignored by the components.
Note: The complete list of icons available in Ubuntu is not published yet. For now please refer to the folder where the icon theme is installed:
- Ubuntu Touch: /usr/share/icons/suru
iconSource : http://doc.qt.io/qt-5/qml-url.html">url |
This is a URL to any image file. In order to use an icon from the Ubuntu theme, use the iconName property instead.
keywords : string |
Additional user visible keywords for the action. The format of the keywords string is "Keyword 1;Keyword 2;Keyword 3" to allow translators to define different number of keywords per language. The keywords are separated by ; and they may contain spaces.
Action { text: i18n.tr("Crop") description: i18n.tr("Crop the image") keywords: i18n.tr("Trim;Cut") }
name : string |
The name of the action. By default an action gets it's name generated automatically if not overridden with later. If name is set to "" then the action restores it's autogenerated name. The name is not user visible.
parameterType : enum |
Type of the parameter passed to trigger and triggered. Type is an enumeration:
- Action.None: No paramater. (default)
- Action.String: String parameter.
- Action.Integer: Integer parameter.
- Action.Bool: Boolean parameter.
- Action.Real: Single precision floating point parameter.
- Action.Object: The parameter is an object.
Action { id: action parameterType: Action.String onTriggered: { // value arguments now contain strings console.log(value); } Component.onCompleted: action.trigger("Hello World") }
shortcut : http://doc.qt.io/qt-5/qml-var.html">var |
The keyboard shortcut that can be used to trigger the action. StandardKey values such as StandardKey.Copy as well as strings in the form "Ctrl+C" are accepted values.
This QML property was introduced in Qt 1.3.
text : string |
The user visible primary label of the action.
Mnemonics are shortcuts prefixed in the text with &. If the text has multiple occurences of the & character, the first one will be considered for the shortcut. The & character cannot be used as shortcut.
visible : bool |
Specifies whether the action is visible to the user. Defaults to true.
Signal Documentation
triggered(http://doc.qt.io/qt-5/qml-var.html">var value) |
Signal called when the action is triggered. The user visible primary label of the action when emitted by components. Custom implementations must make sure this rule is followed, therefore instead of emitting the signal the trigger function should be called.
Method Documentation
trigger(http://doc.qt.io/qt-5/qml-var.html">var value) |
Checks the value
against the action parameterType and triggers the action. If parameterType is Action.None
, it will trigger as
action.trigger()