2 * Copyright 2013 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
23 \qmltype MenuActionBinding
24 \inqmlmodule Indicators 0.1
25 \brief Helper class to connect a qmenumodel action state with a qml components property
33 actionGroup: menuItem.actionGroup
34 action: "/ubuntu/sound/volume"
46 The component which will have the property changed by action
48 property QtObject target: null
52 The property name of \l target component which will be linked with action state
54 property string property
58 Use this to enable or disable the action state propagation to component property.
60 property bool active: true
62 Component.onCompleted: connectViewChanges()
63 onTargetChanged: connectViewChanges()
64 onPropertyChanged: connectViewChanges()
68 property var currentTarget: undefined
69 property string currentSignal
74 target: menuAction.target
75 property: menuAction.property
76 value: menuAction.state
77 when: menuAction.actionObject && menuAction.active
80 // TODO - re-evaluate in c++
81 function connectViewChanges() {
82 if (d.currentTarget != undefined && d.currentSignal !== "") {
83 if (d.currentTarget[d.currentSignal] !== undefined) {
84 d.currentTarget[d.currentSignal].disconnect(onViewValueChanged);
88 d.currentTarget = null;
91 var signal = "on%1Changed".arg(property.charAt(0).toUpperCase() + property.slice(1));
92 if (target[signal] !== undefined) {
93 target[signal].connect(onViewValueChanged);
94 d.currentTarget = target;
95 d.currentSignal = signal;
100 function onViewValueChanged() {
102 var propertyValue = target[property];
103 actionObject.updateState(propertyValue);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list