Merge lp:~zsombi/ubuntu-ui-toolkit/cppActionItem into lp:ubuntu-ui-toolkit/staging

Proposed by Zsombor Egri
Status: Merged
Approved by: Zsombor Egri
Approved revision: 1619
Merged at revision: 1612
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/cppActionItem
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 874 lines (+420/-225)
16 files modified
components.api (+6/-10)
src/Ubuntu/Components/1.2/ActionItem.qml (+0/-96)
src/Ubuntu/Components/1.2/TextField.qml (+1/-1)
src/Ubuntu/Components/1.2/TextInputPopover.qml (+1/-0)
src/Ubuntu/Components/1.2/ToolbarButton.qml (+1/-0)
src/Ubuntu/Components/1.3/ActionItem.qml (+0/-96)
src/Ubuntu/Components/1.3/TextField.qml (+1/-1)
src/Ubuntu/Components/ComponentModule.pro (+0/-2)
src/Ubuntu/Components/plugin/plugin.cpp (+2/-0)
src/Ubuntu/Components/plugin/plugin.pri (+4/-2)
src/Ubuntu/Components/plugin/ucaction.cpp (+2/-3)
src/Ubuntu/Components/plugin/ucaction.h (+7/-6)
src/Ubuntu/Components/plugin/ucactionitem.cpp (+305/-0)
src/Ubuntu/Components/plugin/ucactionitem.h (+77/-0)
src/Ubuntu/Components/qmldir (+0/-3)
tests/unit/tst_components/tst_actionitem.qml (+13/-5)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/cppActionItem
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Zsombor Egri Approve
Cris Dywan Approve
Review via email: mp+268348@code.launchpad.net

Commit message

ActionItem moved to C++.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

Looks pretty good to me and seems as closely ported as possible.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Zsombor Egri (zsombi) wrote :

The component is flaky, the ActionSelectionPopover is not showing random actions, common text input tests fail on popover. Needs a bit more love.

review: Needs Fixing
1617. By Zsombor Egri

fixing text, iconName getters to return proper values when not having custom values

1618. By Zsombor Egri

update visible and enabled when action changes, connect text, iconSource and iconName property change signals to action to keep the value changes in sync

1619. By Zsombor Egri

random icon and text disappearance in Popups caused by a stupid mistake - unititialized member

Revision history for this message
Zsombor Egri (zsombi) wrote :

Good to go now, all the needed functionality is there.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'components.api'
--- components.api 2015-08-12 15:22:59 +0000
+++ components.api 2015-08-19 06:57:12 +0000
@@ -43,14 +43,8 @@
43 property string iconName43 property string iconName
44 property url iconSource44 property url iconSource
45 signal triggered(var value)45 signal triggered(var value)
46 function var trigger(var value)46 function trigger(var value)
47 property string text47 function trigger()
48Ubuntu.Components.ActionItem 1.3: StyledItem
49 property Action action
50 property string iconName
51 property url iconSource
52 signal triggered(var value)
53 function var trigger(var value)
54 property string text48 property string text
55Ubuntu.Components.ActionList 1.0 0.1: QtObject49Ubuntu.Components.ActionList 1.0 0.1: QtObject
56 readonly property Action actions50 readonly property Action actions
@@ -1232,14 +1226,16 @@
1232 property string iconName1226 property string iconName
1233 property url iconSource1227 property url iconSource
1234 signal triggered(var value)1228 signal triggered(var value)
1235 function var trigger(var value)1229 function trigger(var value)
1230 function trigger()
1236 property string text1231 property string text
1237Ubuntu.Components.ToolbarButton 1.3: StyledItem1232Ubuntu.Components.ToolbarButton 1.3: StyledItem
1238 property Action action1233 property Action action
1239 property string iconName1234 property string iconName
1240 property url iconSource1235 property url iconSource
1241 signal triggered(var value)1236 signal triggered(var value)
1242 function var trigger(var value)1237 function trigger(var value)
1238 function trigger()
1243 property string text1239 property string text
1244Ubuntu.Components.ToolbarItems 1.0 0.1: Item1240Ubuntu.Components.ToolbarItems 1.0 0.1: Item
1245 property Item back1241 property Item back
12461242
=== removed file 'src/Ubuntu/Components/1.2/ActionItem.qml'
--- src/Ubuntu/Components/1.2/ActionItem.qml 2015-04-30 08:32:44 +0000
+++ src/Ubuntu/Components/1.2/ActionItem.qml 1970-01-01 00:00:00 +0000
@@ -1,96 +0,0 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
16
17import QtQuick 2.4
18import Ubuntu.Components 1.2
19
20/*!
21 \qmlabstract ActionItem
22 \inqmlmodule Ubuntu.Components 1.1
23 \ingroup ubuntu
24 \brief A visual representation of an Action. The API of ActionItem is a
25 copy of the API of \l Action, with additional properties to define
26 visual aspects of the ActionItem.
27
28 If \l action is set, the values of the other properties will by default
29 be identical to the \l Action's property values. Setting the other properties
30 will override the properties copied from the \l Action.
31
32 See \l ToolbarItems for examples of how to use \l ToolbarButton or other ActionItems
33 in a toolbar.
34*/
35StyledItem {
36 id: actionItem
37
38 /*!
39 The \l Action associated with this ActionItem. If action is set,
40 the values of the Action properties are copied to the values of
41 the ActionItem properties.
42 */
43 property Action action: null
44
45 visible: action ? action.visible : true
46 enabled: action ? action.enabled : true
47
48 /*!
49 The title of the actionItem.
50 Default value: action.text
51 */
52 property string text: action ? action.text : ""
53
54 /*!
55 The image associated with the actionItem.
56 Default value: action.iconSource.
57
58 This is the URL of any image file
59 If both iconSource and iconName are defined, iconName will be ignored.
60 */
61 property url iconSource: action ? action.iconSource : (iconName ? "image://theme/" + iconName : "")
62
63 /*!
64 The icon associated with the actionItem in the suru icon theme.
65 Default value: action.iconName.
66
67 \note The complete list of icons available in Ubuntu is not published yet.
68 For now please refer to the folders where the icon themes are installed:
69 \list
70 \li Ubuntu Touch: \l file:/usr/share/icons/suru
71 \li Ubuntu Desktop: \l file:/usr/share/icons/ubuntu-mono-dark
72 \endlist
73 These 2 separate icon themes will be merged soon.
74
75 If both iconSource and iconName are defined, iconName will be ignored.
76 */
77 property string iconName: action ? action.iconName : ""
78
79 /*!
80 Called when the actionItem is triggered.
81 */
82 signal triggered(var value)
83
84 /*!
85 If \l action is set, this will trigger it.
86 */
87 onTriggered: if (action) action.trigger(value)
88
89 /*!
90 Trigger this action item if it is enabled.
91 */
92 function trigger(value) {
93 var passingValue = value ? value : null
94 if (actionItem.enabled) actionItem.triggered(passingValue);
95 }
96}
970
=== modified file 'src/Ubuntu/Components/1.2/TextField.qml'
--- src/Ubuntu/Components/1.2/TextField.qml 2015-05-01 19:38:57 +0000
+++ src/Ubuntu/Components/1.2/TextField.qml 2015-08-19 06:57:12 +0000
@@ -99,7 +99,7 @@
99 \note During text selection all interactive parent Flickables are turned off.99 \note During text selection all interactive parent Flickables are turned off.
100*/100*/
101101
102ActionItem {102Ubuntu.ActionItem {
103 id: control103 id: control
104104
105 implicitWidth: units.gu(25)105 implicitWidth: units.gu(25)
106106
=== modified file 'src/Ubuntu/Components/1.2/TextInputPopover.qml'
--- src/Ubuntu/Components/1.2/TextInputPopover.qml 2015-07-02 23:33:22 +0000
+++ src/Ubuntu/Components/1.2/TextInputPopover.qml 2015-08-19 06:57:12 +0000
@@ -88,6 +88,7 @@
88 action.text so we can get the proper button by text, action being not88 action.text so we can get the proper button by text, action being not
89 accessible. https://bugs.launchpad.net/autopilot/+bug/133459989 accessible. https://bugs.launchpad.net/autopilot/+bug/1334599
90 */90 */
91 // FIXME: AbstractButton has text property, which is getting the action.text, so no need to override!
91 property string text: action.text92 property string text: action.text
92 width: Math.max(units.gu(5), implicitWidth) + units.gu(2)93 width: Math.max(units.gu(5), implicitWidth) + units.gu(2)
93 height: units.gu(6)94 height: units.gu(6)
9495
=== modified file 'src/Ubuntu/Components/1.2/ToolbarButton.qml'
--- src/Ubuntu/Components/1.2/ToolbarButton.qml 2015-04-30 08:32:44 +0000
+++ src/Ubuntu/Components/1.2/ToolbarButton.qml 2015-08-19 06:57:12 +0000
@@ -15,6 +15,7 @@
15 */15 */
1616
17import QtQuick 2.417import QtQuick 2.4
18import Ubuntu.Components 1.2
1819
19/*!20/*!
20 \qmltype ToolbarButton21 \qmltype ToolbarButton
2122
=== removed file 'src/Ubuntu/Components/1.3/ActionItem.qml'
--- src/Ubuntu/Components/1.3/ActionItem.qml 2015-04-25 08:54:58 +0000
+++ src/Ubuntu/Components/1.3/ActionItem.qml 1970-01-01 00:00:00 +0000
@@ -1,96 +0,0 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
16
17import QtQuick 2.4
18import Ubuntu.Components 1.3
19
20/*!
21 \qmlabstract ActionItem
22 \inqmlmodule Ubuntu.Components 1.1
23 \ingroup ubuntu
24 \brief A visual representation of an Action. The API of ActionItem is a
25 copy of the API of \l Action, with additional properties to define
26 visual aspects of the ActionItem.
27
28 If \l action is set, the values of the other properties will by default
29 be identical to the \l Action's property values. Setting the other properties
30 will override the properties copied from the \l Action.
31
32 See \l ToolbarItems for examples of how to use \l ToolbarButton or other ActionItems
33 in a toolbar.
34*/
35StyledItem {
36 id: actionItem
37
38 /*!
39 The \l Action associated with this ActionItem. If action is set,
40 the values of the Action properties are copied to the values of
41 the ActionItem properties.
42 */
43 property Action action: null
44
45 visible: action ? action.visible : true
46 enabled: action ? action.enabled : true
47
48 /*!
49 The title of the actionItem.
50 Default value: action.text
51 */
52 property string text: action ? action.text : ""
53
54 /*!
55 The image associated with the actionItem.
56 Default value: action.iconSource.
57
58 This is the URL of any image file
59 If both iconSource and iconName are defined, iconName will be ignored.
60 */
61 property url iconSource: action ? action.iconSource : (iconName ? "image://theme/" + iconName : "")
62
63 /*!
64 The icon associated with the actionItem in the suru icon theme.
65 Default value: action.iconName.
66
67 \note The complete list of icons available in Ubuntu is not published yet.
68 For now please refer to the folders where the icon themes are installed:
69 \list
70 \li Ubuntu Touch: \l file:/usr/share/icons/suru
71 \li Ubuntu Desktop: \l file:/usr/share/icons/ubuntu-mono-dark
72 \endlist
73 These 2 separate icon themes will be merged soon.
74
75 If both iconSource and iconName are defined, iconName will be ignored.
76 */
77 property string iconName: action ? action.iconName : ""
78
79 /*!
80 Called when the actionItem is triggered.
81 */
82 signal triggered(var value)
83
84 /*!
85 If \l action is set, this will trigger it.
86 */
87 onTriggered: if (action) action.trigger(value)
88
89 /*!
90 Trigger this action item if it is enabled.
91 */
92 function trigger(value) {
93 var passingValue = value ? value : null
94 if (actionItem.enabled) actionItem.triggered(passingValue);
95 }
96}
970
=== modified file 'src/Ubuntu/Components/1.3/TextField.qml'
--- src/Ubuntu/Components/1.3/TextField.qml 2015-08-11 17:15:59 +0000
+++ src/Ubuntu/Components/1.3/TextField.qml 2015-08-19 06:57:12 +0000
@@ -99,7 +99,7 @@
99 \note During text selection all interactive parent Flickables are turned off.99 \note During text selection all interactive parent Flickables are turned off.
100*/100*/
101101
102ActionItem {102Ubuntu.ActionItem {
103 id: control103 id: control
104104
105 implicitWidth: units.gu(25)105 implicitWidth: units.gu(25)
106106
=== modified file 'src/Ubuntu/Components/ComponentModule.pro'
--- src/Ubuntu/Components/ComponentModule.pro 2015-08-10 14:10:51 +0000
+++ src/Ubuntu/Components/ComponentModule.pro 2015-08-19 06:57:12 +0000
@@ -25,7 +25,6 @@
2525
26#1.226#1.2
27QML_FILES += 1.2/AbstractButton.qml \27QML_FILES += 1.2/AbstractButton.qml \
28 1.2/ActionItem.qml \
29 1.2/ActionList.qml \28 1.2/ActionList.qml \
30 1.2/ActivityIndicator.qml \29 1.2/ActivityIndicator.qml \
31 1.2/AnimatedItem.qml \30 1.2/AnimatedItem.qml \
@@ -83,7 +82,6 @@
83#1.382#1.3
84QML_FILES += 1.3/AbstractButton.qml \83QML_FILES += 1.3/AbstractButton.qml \
85 1.3/ActionBar.qml \84 1.3/ActionBar.qml \
86 1.3/ActionItem.qml \
87 1.3/ActionList.qml \85 1.3/ActionList.qml \
88 1.3/ActivityIndicator.qml \86 1.3/ActivityIndicator.qml \
89 1.3/AdaptivePageLayout.qml \87 1.3/AdaptivePageLayout.qml \
9088
=== modified file 'src/Ubuntu/Components/plugin/plugin.cpp'
--- src/Ubuntu/Components/plugin/plugin.cpp 2015-08-12 09:54:40 +0000
+++ src/Ubuntu/Components/plugin/plugin.cpp 2015-08-19 06:57:12 +0000
@@ -62,6 +62,7 @@
62#include "uclistitemstyle.h"62#include "uclistitemstyle.h"
63#include "ucserviceproperties.h"63#include "ucserviceproperties.h"
64#include "ucnamespace.h"64#include "ucnamespace.h"
65#include "ucactionitem.h"
6566
66#include <sys/types.h>67#include <sys/types.h>
67#include <unistd.h>68#include <unistd.h>
@@ -174,6 +175,7 @@
174 qmlRegisterSingletonType<UCUriHandler>(uri, major, minor, "UriHandler", registerUriHandler);175 qmlRegisterSingletonType<UCUriHandler>(uri, major, minor, "UriHandler", registerUriHandler);
175 qmlRegisterType<UCMouse>(uri, major, minor, "Mouse");176 qmlRegisterType<UCMouse>(uri, major, minor, "Mouse");
176 qmlRegisterType<UCInverseMouse>(uri, major, minor, "InverseMouse");177 qmlRegisterType<UCInverseMouse>(uri, major, minor, "InverseMouse");
178 qmlRegisterType<UCActionItem>(uri, major, minor, "ActionItem");
177}179}
178180
179void UbuntuComponentsPlugin::registerTypes(const char *uri)181void UbuntuComponentsPlugin::registerTypes(const char *uri)
180182
=== modified file 'src/Ubuntu/Components/plugin/plugin.pri'
--- src/Ubuntu/Components/plugin/plugin.pri 2015-08-12 09:54:40 +0000
+++ src/Ubuntu/Components/plugin/plugin.pri 2015-08-19 06:57:12 +0000
@@ -80,7 +80,8 @@
80 $$PWD/ucstylehints.h \80 $$PWD/ucstylehints.h \
81 $$PWD/livetimer.h \81 $$PWD/livetimer.h \
82 $$PWD/livetimer_p.h \82 $$PWD/livetimer_p.h \
83 $$PWD/timeutils_p.h83 $$PWD/timeutils_p.h \
84 $$PWD/ucactionitem.h
8485
85SOURCES += $$PWD/plugin.cpp \86SOURCES += $$PWD/plugin.cpp \
86 $$PWD/uctheme.cpp \87 $$PWD/uctheme.cpp \
@@ -132,7 +133,8 @@
132 $$PWD/ucdefaulttheme.cpp \133 $$PWD/ucdefaulttheme.cpp \
133 $$PWD/ucstylehints.cpp \134 $$PWD/ucstylehints.cpp \
134 $$PWD/livetimer.cpp \135 $$PWD/livetimer.cpp \
135 $$PWD/livetimer_p.cpp136 $$PWD/livetimer_p.cpp \
137 $$PWD/ucactionitem.cpp
136138
137# adapters139# adapters
138SOURCES += $$PWD/adapters/alarmsadapter_organizer.cpp140SOURCES += $$PWD/adapters/alarmsadapter_organizer.cpp
139141
=== modified file 'src/Ubuntu/Components/plugin/ucaction.cpp'
--- src/Ubuntu/Components/plugin/ucaction.cpp 2015-07-03 19:16:56 +0000
+++ src/Ubuntu/Components/plugin/ucaction.cpp 2015-08-19 06:57:12 +0000
@@ -150,13 +150,12 @@
150150
151UCAction::UCAction(QObject *parent)151UCAction::UCAction(QObject *parent)
152 : QObject(parent)152 : QObject(parent)
153 , m_itemHint(Q_NULLPTR)
154 , m_parameterType(None)
153 , m_factoryIconSource(true)155 , m_factoryIconSource(true)
154 , m_enabled(true)156 , m_enabled(true)
155 , m_visible(true)157 , m_visible(true)
156 , m_published(false)158 , m_published(false)
157 , m_itemHint(0)
158 , m_parameterType(None)
159 , m_shortcut(0)
160{159{
161 generateName();160 generateName();
162}161}
163162
=== modified file 'src/Ubuntu/Components/plugin/ucaction.h'
--- src/Ubuntu/Components/plugin/ucaction.h 2015-07-07 13:57:50 +0000
+++ src/Ubuntu/Components/plugin/ucaction.h 2015-08-19 06:57:12 +0000
@@ -77,21 +77,22 @@
77 void trigger(const QVariant &value = QVariant());77 void trigger(const QVariant &value = QVariant());
7878
79private:79private:
80 bool m_factoryIconSource:1;
81 bool m_enabled:1;
82 bool m_visible:1;
83 bool m_published:1;
84 QQmlComponent *m_itemHint;
85 QString m_name;80 QString m_name;
86 QString m_text;81 QString m_text;
87 QString m_iconName;82 QString m_iconName;
88 QUrl m_iconSource;83 QUrl m_iconSource;
89 QString m_description;84 QString m_description;
90 QString m_keywords;85 QString m_keywords;
86 QVariant m_shortcut;
87 QQmlComponent *m_itemHint;
91 Type m_parameterType;88 Type m_parameterType;
92 QVariant m_shortcut;89 bool m_factoryIconSource:1;
90 bool m_enabled:1;
91 bool m_visible:1;
92 bool m_published:1;
9393
94 friend class UCActionContext;94 friend class UCActionContext;
95 friend class UCActionItem;
95 friend class UCListItemPrivate;96 friend class UCListItemPrivate;
96 friend class UCListItemAttached;97 friend class UCListItemAttached;
97 friend class UCListItemActionsPrivate;98 friend class UCListItemActionsPrivate;
9899
=== added file 'src/Ubuntu/Components/plugin/ucactionitem.cpp'
--- src/Ubuntu/Components/plugin/ucactionitem.cpp 1970-01-01 00:00:00 +0000
+++ src/Ubuntu/Components/plugin/ucactionitem.cpp 2015-08-19 06:57:12 +0000
@@ -0,0 +1,305 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
16
17#include "ucactionitem.h"
18#include "ucaction.h"
19
20/*!
21 * \qmltype ActionItem
22 * \instantiates UCActionItem
23 * \inqmlmodule Ubuntu.Components 1.1
24 * \ingroup ubuntu
25 * \brief A visual representation of an Action. The API of ActionItem is a
26 * copy of the API of \l Action, with additional properties to define
27 * visual aspects of the ActionItem.
28 *
29 * If \l action is set, the values of the other properties will by default
30 * be identical to the \l Action's property values. Setting the other properties
31 * will override the properties copied from the \l Action.
32 */
33
34/*!
35 * \qmlsignal ActionItem::triggered(var value)
36 * Called when the actionItem is triggered.
37 */
38UCActionItem::UCActionItem(QQuickItem *parent)
39 : UCStyledItemBase(parent)
40 , m_action(Q_NULLPTR)
41 , m_flags(0)
42{
43 connect(this, &UCActionItem::visibleChanged, this, &UCActionItem::_q_visibleChanged);
44 connect(this, &UCActionItem::enabledChanged, this, &UCActionItem::_q_enabledChanged);
45}
46
47void UCActionItem::_q_visibleChanged()
48{
49 m_flags |= CustomVisible;
50 disconnect(this, &UCActionItem::visibleChanged, this, &UCActionItem::_q_visibleChanged);
51}
52
53void UCActionItem::_q_enabledChanged()
54{
55 m_flags |= CustomEnabled;
56 disconnect(this, &UCActionItem::enabledChanged, this, &UCActionItem::_q_enabledChanged);
57}
58
59// update visible property
60void UCActionItem::_q_updateVisible()
61{
62 bool visible = m_action ? m_action->m_visible : true;
63 setVisible(visible);
64 // reset flag and reconnect signal handler disconnected by the
65 m_flags &= ~CustomVisible;
66 if (m_action) {
67 connect(this, &UCActionItem::visibleChanged, this, &UCActionItem::_q_visibleChanged);
68 }
69}
70
71// update enabled property
72void UCActionItem::_q_updateEnabled()
73{
74 bool enabled = m_action ? m_action->m_enabled : true;
75 setEnabled(enabled);
76 // reset flag and reconnect signal handler disconnected by the
77 m_flags &= ~CustomEnabled;
78 if (m_action) {
79 connect(this, &UCActionItem::enabledChanged, this, &UCActionItem::_q_enabledChanged);
80 }
81}
82
83void UCActionItem::updateProperties()
84{
85 if (!(m_flags & CustomText)) {
86 Q_EMIT textChanged();
87 }
88 if (!(m_flags & CustomIconSource)) {
89 Q_EMIT iconSourceChanged();
90 }
91 if (!(m_flags & CustomIconName)) {
92 Q_EMIT iconNameChanged();
93 }
94}
95
96void UCActionItem::attachAction(bool attach)
97{
98 if (attach) {
99 connect(this, &UCActionItem::triggered,
100 m_action, &UCAction::triggered, Qt::DirectConnection);
101 connect(m_action, &UCAction::visibleChanged,
102 this, &UCActionItem::_q_updateVisible, Qt::DirectConnection);
103 connect(m_action, &UCAction::enabledChanged,
104 this, &UCActionItem::_q_updateEnabled, Qt::DirectConnection);
105 if (!(m_flags & CustomText)) {
106 connect(m_action, &UCAction::textChanged,
107 this, &UCActionItem::textChanged, Qt::DirectConnection);
108 }
109 if (!(m_flags & CustomIconSource)) {
110 connect(m_action, &UCAction::iconSourceChanged,
111 this, &UCActionItem::iconSourceChanged, Qt::DirectConnection);
112 }
113 if (!(m_flags & CustomIconName)) {
114 connect(m_action, &UCAction::iconNameChanged,
115 this, &UCActionItem::iconNameChanged, Qt::DirectConnection);
116 }
117 } else {
118 disconnect(this, &UCActionItem::triggered,
119 m_action, &UCAction::triggered);
120 disconnect(m_action, &UCAction::visibleChanged,
121 this, &UCActionItem::_q_updateVisible);
122 disconnect(m_action, &UCAction::enabledChanged,
123 this, &UCActionItem::_q_updateEnabled);
124 if (!(m_flags & CustomText)) {
125 disconnect(m_action, &UCAction::textChanged,
126 this, &UCActionItem::textChanged);
127 }
128 if (!(m_flags & CustomIconSource)) {
129 disconnect(m_action, &UCAction::iconSourceChanged,
130 this, &UCActionItem::iconSourceChanged);
131 }
132 if (!(m_flags & CustomIconName)) {
133 disconnect(m_action, &UCAction::iconNameChanged,
134 this, &UCActionItem::iconNameChanged);
135 }
136 }
137}
138
139/*!
140 * \qmlproperty Action ActionItem::action
141 * The \l Action associated with this ActionItem. If action is set, the values
142 * of the \l Action properties are copied to the values of the ActionItem
143 * properties, unless those were previously overridden.
144 */
145void UCActionItem::setAction(UCAction *action)
146{
147 if (m_action == action) {
148 return;
149 }
150 if (m_action) {
151 attachAction(false);
152 }
153 m_action = action;
154 Q_EMIT actionChanged();
155
156 if (m_action) {
157 attachAction(true);
158 }
159 _q_updateVisible();
160 _q_updateEnabled();
161 updateProperties();
162}
163
164/*!
165 * \qmlproperty string ActionItem::text
166 * The title of the actionItem. Defaults to the \c action.text.
167 */
168QString UCActionItem::text()
169{
170 if (m_flags & CustomText) {
171 return m_text;
172 }
173 return m_action ? m_action->m_text : QString();
174}
175void UCActionItem::setText(const QString &text)
176{
177 if (m_text == text) {
178 return;
179 }
180 m_text = text;
181 if (m_action && !(m_flags & CustomText)) {
182 // disconnect change signal from Action
183 disconnect(m_action, &UCAction::textChanged,
184 this, &UCActionItem::textChanged);
185 }
186 m_flags |= CustomText;
187 Q_EMIT textChanged();
188}
189void UCActionItem::resetText()
190{
191 m_text.clear();
192 m_flags &= ~CustomText;
193 if (m_action) {
194 // re-connect change signal from Action
195 connect(m_action, &UCAction::textChanged,
196 this, &UCActionItem::textChanged, Qt::DirectConnection);
197 }
198 Q_EMIT textChanged();
199}
200
201/*!
202 * \qmlproperty url ActionItem::iconSource
203 * The image associated with the ActionItem. Defaults to \c action.iconSource.
204 *
205 * This is the URL of any image file. If both iconSource and \l iconName are defined,
206 * \l iconName will be ignored.
207 */
208QUrl UCActionItem::iconSource()
209{
210 if (m_flags & CustomIconSource) {
211 return m_iconSource;
212 }
213 if (m_action) {
214 return m_action->m_iconSource;
215 }
216 return !iconName().isEmpty() ? QUrl(QString("image://theme/%1").arg(iconName())) : QUrl();
217}
218void UCActionItem::setIconSource(const QUrl &iconSource)
219{
220 if (m_iconSource == iconSource) {
221 return;
222 }
223 m_iconSource = iconSource;
224 if (m_action && !(m_flags & CustomIconSource)) {
225 // disconnect change signal from Action
226 disconnect(m_action, &UCAction::iconSourceChanged,
227 this, &UCActionItem::iconSourceChanged);
228 }
229 m_flags |= CustomIconSource;
230 Q_EMIT iconSourceChanged();
231}
232void UCActionItem::resetIconSource()
233{
234 m_iconSource.clear();
235 m_flags &= ~CustomIconSource;
236 if (m_action) {
237 // re-connect change signal from Action
238 connect(m_action, &UCAction::iconSourceChanged,
239 this, &UCActionItem::iconSourceChanged, Qt::DirectConnection);
240 }
241 Q_EMIT iconSourceChanged();
242}
243
244/*!
245 * \qmlproperty string ActionItem::iconName
246 * The icon associated with the actionItem in the suru icon theme. Defaults to
247 * \c action.iconName.
248 *
249 * \note The complete list of icons available in Ubuntu is not published yet.
250 * For now please refer to the folders where the icon themes are installed:
251 * \list
252 * \li Ubuntu Touch: \l file:/usr/share/icons/suru
253 * \li Ubuntu Desktop: \l file:/usr/share/icons/ubuntu-mono-dark
254 * \endlist
255 * These 2 separate icon themes will be merged soon.
256 *
257 * If both \l iconSource and iconName are defined, iconName will be ignored.
258 */
259QString UCActionItem::iconName()
260{
261 if (m_flags & CustomIconName) {
262 return m_iconName;
263 }
264 return m_action ? m_action->m_iconName : QString();
265}
266void UCActionItem::setIconName(const QString &iconName)
267{
268 if (m_iconName == iconName) {
269 return;
270 }
271 m_iconName = iconName;
272 if (m_action && !(m_flags & CustomIconName)) {
273 // disconnect change signal from Action
274 disconnect(m_action, &UCAction::iconNameChanged,
275 this, &UCActionItem::iconNameChanged);
276 }
277 m_flags |= CustomIconName;
278 Q_EMIT iconNameChanged();
279 // also sync iconSource if that is not a custom one or taken from action
280 if (!m_action || (m_flags & CustomIconSource)) {
281 Q_EMIT iconSourceChanged();
282 }
283}
284void UCActionItem::resetIconName()
285{
286 m_iconName.clear();
287 m_flags &= ~CustomIconName;
288 if (m_action) {
289 // re-connect change signal from Action
290 connect(m_action, &UCAction::iconNameChanged,
291 this, &UCActionItem::iconNameChanged, Qt::DirectConnection);
292 }
293 Q_EMIT iconNameChanged();
294}
295
296/*!
297 * \qmlmethod void ActionItem::trigger(var value)
298 * Trigger this action item if it is enabled.
299 */
300void UCActionItem::trigger(const QVariant &value)
301{
302 if (isEnabled()) {
303 Q_EMIT triggered(value);
304 }
305}
0306
=== added file 'src/Ubuntu/Components/plugin/ucactionitem.h'
--- src/Ubuntu/Components/plugin/ucactionitem.h 1970-01-01 00:00:00 +0000
+++ src/Ubuntu/Components/plugin/ucactionitem.h 2015-08-19 06:57:12 +0000
@@ -0,0 +1,77 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
16#ifndef UCACTIONITEM_H
17#define UCACTIONITEM_H
18
19#include "ucstyleditembase.h"
20
21class UCAction;
22class UCActionItem : public UCStyledItemBase
23{
24 Q_OBJECT
25 Q_PROPERTY(UCAction *action MEMBER m_action WRITE setAction NOTIFY actionChanged FINAL)
26 Q_PROPERTY(QString text READ text WRITE setText RESET resetText NOTIFY textChanged)
27 Q_PROPERTY(QUrl iconSource READ iconSource WRITE setIconSource RESET resetIconSource NOTIFY iconSourceChanged)
28 Q_PROPERTY(QString iconName READ iconName WRITE setIconName RESET resetIconName NOTIFY iconNameChanged)
29public:
30 explicit UCActionItem(QQuickItem *parent = 0);
31
32 void setAction(UCAction *action);
33 QString text();
34 void setText(const QString &text);
35 void resetText();
36 QUrl iconSource();
37 void setIconSource(const QUrl &iconSource);
38 void resetIconSource();
39 QString iconName();
40 void setIconName(const QString &iconName);
41 void resetIconName();
42
43Q_SIGNALS:
44 void actionChanged();
45 void textChanged();
46 void iconSourceChanged();
47 void iconNameChanged();
48 void triggered(const QVariant &value);
49
50public Q_SLOTS:
51 void trigger(const QVariant &value = QVariant());
52
53protected Q_SLOTS:
54 void _q_visibleChanged();
55 void _q_enabledChanged();
56 void _q_updateVisible();
57 void _q_updateEnabled();
58
59protected:
60 enum {
61 CustomText = 0x01,
62 CustomIconSource = 0x02,
63 CustomIconName = 0x04,
64 CustomVisible = 0x40,
65 CustomEnabled = 0x80
66 };
67 QString m_text;
68 QString m_iconName;
69 QUrl m_iconSource;
70 UCAction *m_action;
71 quint8 m_flags;
72
73 void updateProperties();
74 void attachAction(bool attach);
75};
76
77#endif // UCACTIONITEM_H
078
=== modified file 'src/Ubuntu/Components/qmldir'
--- src/Ubuntu/Components/qmldir 2015-08-10 14:27:35 +0000
+++ src/Ubuntu/Components/qmldir 2015-08-19 06:57:12 +0000
@@ -1,6 +1,5 @@
1module Ubuntu.Components1module Ubuntu.Components
2plugin UbuntuComponents2plugin UbuntuComponents
3ActionItem 0.1 1.2/ActionItem.qml
4ActionList 0.1 1.2/ActionList.qml3ActionList 0.1 1.2/ActionList.qml
5ToolbarItems 0.1 1.2/ToolbarItems.qml4ToolbarItems 0.1 1.2/ToolbarItems.qml
6ToolbarButton 0.1 1.2/ToolbarButton.qml5ToolbarButton 0.1 1.2/ToolbarButton.qml
@@ -44,7 +43,6 @@
44DateUtils 0.1 1.2/dateUtils.js43DateUtils 0.1 1.2/dateUtils.js
4544
46#version 1.045#version 1.0
47ActionItem 1.0 1.2/ActionItem.qml
48ActionList 1.0 1.2/ActionList.qml46ActionList 1.0 1.2/ActionList.qml
49ToolbarItems 1.0 1.2/ToolbarItems.qml47ToolbarItems 1.0 1.2/ToolbarItems.qml
50ToolbarButton 1.0 1.2/ToolbarButton.qml48ToolbarButton 1.0 1.2/ToolbarButton.qml
@@ -105,7 +103,6 @@
105#################################################103#################################################
106#version 1.3104#version 1.3
107ActionBar 1.3 1.3/ActionBar.qml105ActionBar 1.3 1.3/ActionBar.qml
108ActionItem 1.3 1.3/ActionItem.qml
109ActionList 1.3 1.3/ActionList.qml106ActionList 1.3 1.3/ActionList.qml
110AdaptivePageLayout 1.3 1.3/AdaptivePageLayout.qml107AdaptivePageLayout 1.3 1.3/AdaptivePageLayout.qml
111PageColumnsLayout 1.3 1.3/PageColumnsLayout.qml108PageColumnsLayout 1.3 1.3/PageColumnsLayout.qml
112109
=== modified file 'tests/unit/tst_components/tst_actionitem.qml'
--- tests/unit/tst_components/tst_actionitem.qml 2015-03-03 13:20:06 +0000
+++ tests/unit/tst_components/tst_actionitem.qml 2015-08-19 06:57:12 +0000
@@ -21,10 +21,22 @@
21TestCase {21TestCase {
22 name: "ActionItemAPI"22 name: "ActionItemAPI"
2323
24 SignalSpy {
25 id: triggerSpy
26 target: action1
27 signalName: "triggered"
28 }
29
24 function initTestCase() {30 function initTestCase() {
25 compare(item1.action, null, "action is null by default")31 compare(item1.action, null, "action is null by default")
26 compare(item1.text, "", "text is empty string set by default")32 compare(item1.text, "", "text is empty string set by default")
27 compare(item1.iconSource, "", "iconSource is empty string by default")33 compare(item1.iconSource, "", "iconSource is empty string by default")
34 compare(item1.iconName, "", "iconSource is empty string by default")
35 }
36
37 function cleanup() {
38 item1.action = null;
39 triggerSpy.clear();
28 }40 }
2941
30 function test_action() {42 function test_action() {
@@ -33,10 +45,8 @@
33 compare(item1.action, action1, "Action can be set")45 compare(item1.action, action1, "Action can be set")
34 compare(item1.text, action1.text, "text is automatically set to action text")46 compare(item1.text, action1.text, "text is automatically set to action text")
35 compare(item1.iconSource, action1.iconSource, "iconSource is automatically set to action iconSource")47 compare(item1.iconSource, action1.iconSource, "iconSource is automatically set to action iconSource")
36 var numTriggers = action1.triggerCount
37 item1.triggered(null)48 item1.triggered(null)
38 compare(action1.triggerCount, numTriggers+1, "ActionItem triggered() triggers action")49 triggerSpy.wait(400);
39 item1.action = null
40 }50 }
4151
42 // NOTE: This test must be run AFTER test_action(), otherwise setting the action will52 // NOTE: This test must be run AFTER test_action(), otherwise setting the action will
@@ -89,7 +99,5 @@
89 id: action199 id: action1
90 text: "actionText"100 text: "actionText"
91 iconSource: "imageURL"101 iconSource: "imageURL"
92 property int triggerCount: 0
93 onTriggered: triggerCount++
94 }102 }
95}103}

Subscribers

People subscribed via source and target branches