Merge lp:~tpeeters/ubuntu-ui-toolkit/buttonAction into lp:ubuntu-ui-toolkit

Proposed by Tim Peeters
Status: Merged
Approved by: Zsombor Egri
Approved revision: 522
Merged at revision: 518
Proposed branch: lp:~tpeeters/ubuntu-ui-toolkit/buttonAction
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 270 lines (+94/-32)
6 files modified
components.api (+1/-0)
modules/Ubuntu/Components/AbstractButton.qml (+20/-7)
modules/Ubuntu/Components/Button.qml (+20/-9)
modules/Ubuntu/Components/Toolbar.qml (+15/-16)
tests/unit/tst_components/tst_abstractbutton.qml (+16/-0)
tests/unit/tst_components/tst_button.qml (+22/-0)
To merge this branch: bzr merge lp:~tpeeters/ubuntu-ui-toolkit/buttonAction
Reviewer Review Type Date Requested Status
Zsombor Egri Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+165563@code.launchpad.net

Commit message

Add action property to AbstractButton, and use it in the toolbar.

Description of the change

Add action property to AbstractButton, and use it in the toolbar.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Zsombor Egri (zsombi) wrote :

looks cool :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'components.api'
--- components.api 2013-05-22 11:27:49 +0000
+++ components.api 2013-05-28 12:40:33 +0000
@@ -1,5 +1,6 @@
1modules/Ubuntu/Components/AbstractButton.qml1modules/Ubuntu/Components/AbstractButton.qml
2Item2Item
3 property Action action
3 signal clicked()4 signal clicked()
4 signal pressAndHold()5 signal pressAndHold()
5 property bool pressed6 property bool pressed
67
=== modified file 'modules/Ubuntu/Components/AbstractButton.qml'
--- modules/Ubuntu/Components/AbstractButton.qml 2013-04-17 11:06:44 +0000
+++ modules/Ubuntu/Components/AbstractButton.qml 2013-05-28 12:40:33 +0000
@@ -31,35 +31,48 @@
31 id: button31 id: button
3232
33 /*!33 /*!
34 \preliminary34 If an action is specified, the button's clicked signal will trigger the action.
35 Subclasses of AbstractButton can use other properties of action (for example
36 the text and iconSource).
37 */
38 property Action action: null
39
40 visible: action ? action.visible : true
41 enabled: action ? action.enabled : true
42
43 /*!
35 This handler is called when there is a mouse click on the button44 This handler is called when there is a mouse click on the button
36 and the button is not disabled.45 and the button is not disabled. If \l action is defined,
46 the action will be triggered.
37 */47 */
38 signal clicked()48 signal clicked()
3949
50 /*!
51 If \l action was set, action.triggered() is automatically called with
52 the AbstractButton as parameter.
53 */
54 onClicked: if (action) action.triggered(button)
55
40 Keys.onEnterPressed: clicked()56 Keys.onEnterPressed: clicked()
41 Keys.onReturnPressed: clicked()57 Keys.onReturnPressed: clicked()
4258
43 /*!59 /*!
44 \preliminary
45 This handler is called when there is a long press.60 This handler is called when there is a long press.
46 */61 */
47 signal pressAndHold()62 signal pressAndHold()
4863
49 /*!64 /*!
50 \preliminary
51 True if the user presses a mouse button in the button's mouse area.65 True if the user presses a mouse button in the button's mouse area.
52 */66 */
53 property bool pressed: mouseArea.pressed67 property bool pressed: mouseArea.pressed
5468
55 /*!69 /*!
56 \preliminary
57 True if the mouse cursor hovers over the button's mouse area.70 True if the mouse cursor hovers over the button's mouse area.
58 */71 */
59 property bool hovered: __acceptEvents && mouseArea.containsMouse72 property bool hovered: __acceptEvents && mouseArea.containsMouse
6073
6174 /*!
62 /*! \internal75 \internal
63 Disable or enable signal emition by default.76 Disable or enable signal emition by default.
64 Some classes want to emit the signal by themselves (ListItem.Standard)77 Some classes want to emit the signal by themselves (ListItem.Standard)
65 */78 */
6679
=== modified file 'modules/Ubuntu/Components/Button.qml'
--- modules/Ubuntu/Components/Button.qml 2013-05-24 09:12:56 +0000
+++ modules/Ubuntu/Components/Button.qml 2013-05-28 12:40:33 +0000
@@ -49,6 +49,22 @@
49 }49 }
50 }50 }
51 \endqml51 \endqml
52 An \l Action can be used to specify \l clicked(), \l iconSource and \l text. Example:
53 \qml
54 Item {
55 Action {
56 id: action1
57 text: "Click me"
58 onTriggered: print("action!")
59 iconSource: "icon.png"
60 }
61 Button {
62 anchors.centerIn: parent
63 action: action1
64 color: "green"
65 }
66 }
67 \endqml
52*/68*/
53AbstractButton {69AbstractButton {
54 id: button70 id: button
@@ -59,31 +75,26 @@
59 implicitHeight: units.gu(4)75 implicitHeight: units.gu(4)
6076
61 /*!77 /*!
62 \preliminary
63 The foreground color of the button in idle state.78 The foreground color of the button in idle state.
64 */79 */
65 property color color: "transparent"80 property color color: "transparent"
6681
67 /*!82 /*!
68 \preliminary
69 The source URL of the icon to display inside the button.83 The source URL of the icon to display inside the button.
70 Leave this value blank for a text-only button.84 Leave this value blank for a text-only button.
71 \qmlproperty url iconSource85 If \l action is set, the default iconSource is that of the action.
72 */86 */
73 property url iconSource: ""87 property url iconSource: action ? action.iconSource : ""
7488
75 /*!89 /*!
76 \preliminary
77 The text to display in the button. If an icon was defined,90 The text to display in the button. If an icon was defined,
78 the text will be shown next to the icon, otherwise it will91 the text will be shown next to the icon, otherwise it will
79 be centered. Leave blank for an icon-only button.92 be centered. Leave blank for an icon-only button.
80 \qmlproperty string text93 If \l action is set, the default text is that of the action.
81 */94 */
82 property string text95 property string text: action ? action.text : undefined
8396
84 /*!97 /*!
85 \preliminary
86
87 The position of the icon relative to the text. Options98 The position of the icon relative to the text. Options
88 are "left" and "right". The default value is "left".99 are "left" and "right". The default value is "left".
89100
90101
=== modified file 'modules/Ubuntu/Components/Toolbar.qml'
--- modules/Ubuntu/Components/Toolbar.qml 2013-05-02 19:18:09 +0000
+++ modules/Ubuntu/Components/Toolbar.qml 2013-05-28 12:40:33 +0000
@@ -122,15 +122,12 @@
122122
123 Component {123 Component {
124 id: toolButtonComponent124 id: toolButtonComponent
125 Item {125 Button {
126 id: toolButton126 id: toolButton
127 // Disable the mouse area so swipes on the button will not be blocked
128 // from going to the toolbar. The panel will take care calling the button's clicked().
129 __mouseArea.visible: false
127 Theming.ItemStyle.class: "toolbar-button"130 Theming.ItemStyle.class: "toolbar-button"
128 property string text: action && action.text ? action.text : ""
129 property url iconSource: action && action.iconSource ? action.iconSource : ""
130 signal clicked()
131 onClicked: action.triggered(toolButton)
132 enabled: action && action.enabled
133 visible: action && action.visible
134 width: units.gu(5)131 width: units.gu(5)
135 height: toolbar.height132 height: toolbar.height
136 }133 }
@@ -138,22 +135,20 @@
138135
139 Loader {136 Loader {
140 id: backButton137 id: backButton
141 property Action action: toolbar.tools && toolbar.tools.back ? toolbar.tools.back : null138 property Action backAction: toolbar.tools ? toolbar.tools.back : null
142 sourceComponent: action ? action.itemHint ? action.itemHint : toolButtonComponent : null139 sourceComponent: backAction ? backAction.itemHint ? backAction.itemHint : toolButtonComponent : null
143 anchors {140 anchors {
144 left: parent.left141 left: parent.left
145 leftMargin: units.gu(2)142 leftMargin: units.gu(2)
146 verticalCenter: parent.verticalCenter143 verticalCenter: parent.verticalCenter
147 }144 }
148 onStatusChanged: {145 onStatusChanged: {
149 if (item && status == Loader.Ready && action && action.itemHint) {146 if (item && status == Loader.Ready) {
150 if (item.hasOwnProperty("clicked")) item.clicked.connect(backButton.itemTriggered);147 if (item.hasOwnProperty("action")) item.action = backAction;
151 if (item.hasOwnProperty("accepted")) item.accepted.connect(backButton.itemTriggered);
152 if (item.hasOwnProperty("triggered")) item.accepted.connect(backButton.itemTtriggered);
153 }148 }
154 }149 }
155 signal itemTriggered()150 // ensure the item's action is up-to-date (which is not the case without this line):
156 onItemTriggered: action.triggered(item)151 onBackActionChanged: if (item && item.hasOwnProperty("action")) item.action = backAction;
157 }152 }
158153
159 Row {154 Row {
@@ -170,8 +165,12 @@
170 model: internal.visibleTools ? internal.visibleTools.children : 0165 model: internal.visibleTools ? internal.visibleTools.children : 0
171 Loader {166 Loader {
172 sourceComponent: modelData.itemHint ? modelData.itemHint : toolButtonComponent167 sourceComponent: modelData.itemHint ? modelData.itemHint : toolButtonComponent
173 property Action action: modelData
174 anchors.verticalCenter: toolButtonsContainer.verticalCenter168 anchors.verticalCenter: toolButtonsContainer.verticalCenter
169 onStatusChanged: {
170 if (item && status == Loader.Ready) {
171 if (item.hasOwnProperty("action")) item.action = modelData
172 }
173 }
175 }174 }
176 }175 }
177 }176 }
178177
=== modified file 'tests/unit/tst_components/tst_abstractbutton.qml'
--- tests/unit/tst_components/tst_abstractbutton.qml 2012-11-21 21:23:04 +0000
+++ tests/unit/tst_components/tst_abstractbutton.qml 2013-05-28 12:40:33 +0000
@@ -21,6 +21,16 @@
21TestCase {21TestCase {
22 name: "AbstractButtonAPI"22 name: "AbstractButtonAPI"
2323
24 function test_action() {
25 compare(absButton.action, null,"Action is null by default")
26 absButton.action = action1
27 compare(absButton.action, action1, "Action can be set")
28 var numTriggers = action1.triggerCount
29 absButton.clicked()
30 compare(action1.triggerCount, numTriggers+1, "Button clicked triggers action")
31 absButton.action = null
32 }
33
24 function test_hovered() {34 function test_hovered() {
25 compare(absButton.hovered,false,"Hovered is boolean and false by default")35 compare(absButton.hovered,false,"Hovered is boolean and false by default")
26 }36 }
@@ -46,4 +56,10 @@
46 target: parent56 target: parent
47 }57 }
48 }58 }
59
60 Action {
61 id: action1
62 property int triggerCount: 0
63 onTriggered: triggerCount++
64 }
49}65}
5066
=== modified file 'tests/unit/tst_components/tst_button.qml'
--- tests/unit/tst_components/tst_button.qml 2013-05-06 13:11:21 +0000
+++ tests/unit/tst_components/tst_button.qml 2013-05-28 12:40:33 +0000
@@ -28,6 +28,18 @@
28 compare(button.text,newText,"Can set/get text")28 compare(button.text,newText,"Can set/get text")
29 }29 }
3030
31 function test_action() {
32 compare(actionButton.action, null, "Action is null by default")
33 actionButton.action = action1
34 compare(actionButton.action, action1, "action can be set")
35 var newText = "Hello action!"
36 action1.text = newText
37 compare(actionButton.text, newText, "action can be used to define text")
38 var newIcon = "../../../examples/ubuntu-ui-toolkit-gallery/small_avatar.png"
39 action1.iconSource = newIcon
40 compare(actionButton.iconSource, Qt.resolvedUrl(newIcon), "action can be used to define iconSource")
41 }
42
31 function test_iconPosition() {43 function test_iconPosition() {
32 compare(button.iconPosition,"left","The default value for iconPosition is 'left'")44 compare(button.iconPosition,"left","The default value for iconPosition is 'left'")
33 var newIconPosition = "right"45 var newIconPosition = "right"
@@ -73,4 +85,14 @@
73 target: parent85 target: parent
74 }86 }
75 }87 }
88
89 // Use a new button for action tests, because other tests override
90 // the button's default text and iconSource so they are no longer
91 // automatically taken from the action.
92 Button {
93 id: actionButton
94 }
95 Action {
96 id: action1
97 }
76}98}

Subscribers

People subscribed via source and target branches

to status/vote changes: