Merge lp:~nick-dedekind/ubuntu-ui-toolkit/actionItem-mnemonics into lp:ubuntu-ui-toolkit/staging
- actionItem-mnemonics
- Merge into staging
Proposed by
Nick Dedekind
Status: | Needs review |
---|---|
Proposed branch: | lp:~nick-dedekind/ubuntu-ui-toolkit/actionItem-mnemonics |
Merge into: | lp:ubuntu-ui-toolkit/staging |
Diff against target: |
740 lines (+319/-97) 8 files modified
components.api (+8/-1) src/UbuntuToolkit/ubuntutoolkitmodule.cpp (+2/-0) src/UbuntuToolkit/ucaction.cpp (+1/-77) src/UbuntuToolkit/ucaction_p.h (+2/-1) src/UbuntuToolkit/ucactionitem.cpp (+249/-17) src/UbuntuToolkit/ucactionitem_p.h (+44/-0) src/UbuntuToolkit/ucactionitem_p_p.h (+4/-0) tests/unit/visual/tst_actionitem.11.qml (+9/-1) |
To merge this branch: | bzr merge lp:~nick-dedekind/ubuntu-ui-toolkit/actionItem-mnemonics |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Zsombor Egri | Needs Information | ||
Review via email: mp+313115@code.launchpad.net |
Commit message
Moved Action mnemonic logic to the ActionItem.
Description of the change
Moved Action mnemonic logic to the ActionItem.
Added ActionItem.mnemonic for altering properties of the mnemonic logic.
To post a comment you must log in.
- 1329. By Nick Dedekind
-
removed action check
- 1330. By Nick Dedekind
-
removed extra coment block end
- 1331. By Nick Dedekind
-
Added mnemonic type
Unmerged revisions
- 1331. By Nick Dedekind
-
Added mnemonic type
- 1330. By Nick Dedekind
-
removed extra coment block end
- 1329. By Nick Dedekind
-
removed action check
- 1328. By Nick Dedekind
-
merged with staging
- 1327. By Nick Dedekind
-
merged with trunk
- 1326. By Nick Dedekind
-
added qdoc check
- 1325. By Nick Dedekind
-
fixed 1.3 version of ActionItem
- 1324. By Nick Dedekind
-
merged with staging
- 1323. By Nick Dedekind
-
API fixes
- 1322. By Nick Dedekind
-
Added mnemonic test
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'components.api' | |||
2 | --- components.api 2016-09-17 05:48:25 +0000 | |||
3 | +++ components.api 2016-12-13 14:24:00 +0000 | |||
4 | @@ -45,13 +45,14 @@ | |||
5 | 45 | property bool active | 45 | property bool active |
6 | 46 | function addAction(Action action) | 46 | function addAction(Action action) |
7 | 47 | function removeAction(Action action) | 47 | function removeAction(Action action) |
9 | 48 | Ubuntu.Components.ActionItem 1.0 0.1 UCActionItem: StyledItem | 48 | Ubuntu.Components.ActionItem 1.3 1.0 0.1 UCActionItem: StyledItem |
10 | 49 | property Action action | 49 | property Action action |
11 | 50 | property string iconName | 50 | property string iconName |
12 | 51 | property url iconSource | 51 | property url iconSource |
13 | 52 | signal triggered(var value) | 52 | signal triggered(var value) |
14 | 53 | function trigger(var value) | 53 | function trigger(var value) |
15 | 54 | function trigger() | 54 | function trigger() |
16 | 55 | readonly property ActionMnemonic mnemonic 1.3 | ||
17 | 55 | property string text | 56 | property string text |
18 | 56 | Ubuntu.Components.Styles.ActionItemProperties 1.3: QtObject | 57 | Ubuntu.Components.Styles.ActionItemProperties 1.3: QtObject |
19 | 57 | property color backgroundColor | 58 | property color backgroundColor |
20 | @@ -79,6 +80,10 @@ | |||
21 | 79 | function removeAction(Action action) | 80 | function removeAction(Action action) |
22 | 80 | function addLocalContext(ActionContext context) | 81 | function addLocalContext(ActionContext context) |
23 | 81 | function removeLocalContext(ActionContext context) | 82 | function removeLocalContext(ActionContext context) |
24 | 83 | Ubuntu.Components.ActionMnemonic 1.3: QtObject | ||
25 | 84 | property int modifier | ||
26 | 85 | readonly property StandardKey sequence | ||
27 | 86 | property bool visible | ||
28 | 82 | Ubuntu.Components.Popups.ActionSelectionPopover 1.0 0.1: Popover | 87 | Ubuntu.Components.Popups.ActionSelectionPopover 1.0 0.1: Popover |
29 | 83 | property var actions | 88 | property var actions |
30 | 84 | property Component delegate | 89 | property Component delegate |
31 | @@ -1597,6 +1602,7 @@ | |||
32 | 1597 | signal triggered(var value) | 1602 | signal triggered(var value) |
33 | 1598 | function trigger(var value) | 1603 | function trigger(var value) |
34 | 1599 | function trigger() | 1604 | function trigger() |
35 | 1605 | readonly property ActionMnemonic mnemonic | ||
36 | 1600 | property string text | 1606 | property string text |
37 | 1601 | Ubuntu.Components.ToolbarButton 1.3: StyledItem | 1607 | Ubuntu.Components.ToolbarButton 1.3: StyledItem |
38 | 1602 | property Action action | 1608 | property Action action |
39 | @@ -1605,6 +1611,7 @@ | |||
40 | 1605 | signal triggered(var value) | 1611 | signal triggered(var value) |
41 | 1606 | function trigger(var value) | 1612 | function trigger(var value) |
42 | 1607 | function trigger() | 1613 | function trigger() |
43 | 1614 | readonly property ActionMnemonic mnemonic | ||
44 | 1608 | property string text | 1615 | property string text |
45 | 1609 | Ubuntu.Components.ToolbarItems 1.0 0.1: Item | 1616 | Ubuntu.Components.ToolbarItems 1.0 0.1: Item |
46 | 1610 | property Item back | 1617 | property Item back |
47 | 1611 | 1618 | ||
48 | === modified file 'src/UbuntuToolkit/ubuntutoolkitmodule.cpp' | |||
49 | --- src/UbuntuToolkit/ubuntutoolkitmodule.cpp 2016-09-29 10:19:06 +0000 | |||
50 | +++ src/UbuntuToolkit/ubuntutoolkitmodule.cpp 2016-12-13 14:24:00 +0000 | |||
51 | @@ -398,6 +398,8 @@ | |||
52 | 398 | qmlRegisterType<UCMainViewBase>(uri, 1, 3, "MainViewBase"); | 398 | qmlRegisterType<UCMainViewBase>(uri, 1, 3, "MainViewBase"); |
53 | 399 | qmlRegisterType<ActionList>(uri, 1, 3, "ActionList"); | 399 | qmlRegisterType<ActionList>(uri, 1, 3, "ActionList"); |
54 | 400 | qmlRegisterType<ExclusiveGroup>(uri, 1, 3, "ExclusiveGroup"); | 400 | qmlRegisterType<ExclusiveGroup>(uri, 1, 3, "ExclusiveGroup"); |
55 | 401 | qmlRegisterType<UCActionItem, 1>(uri, 1, 3, "ActionItem"); | ||
56 | 402 | qmlRegisterType<UCActionMnemonic>(); | ||
57 | 401 | } | 403 | } |
58 | 402 | 404 | ||
59 | 403 | void UbuntuToolkitModule::undefineModule() | 405 | void UbuntuToolkitModule::undefineModule() |
60 | 404 | 406 | ||
61 | === modified file 'src/UbuntuToolkit/ucaction.cpp' | |||
62 | --- src/UbuntuToolkit/ucaction.cpp 2016-09-20 08:23:40 +0000 | |||
63 | +++ src/UbuntuToolkit/ucaction.cpp 2016-12-13 14:24:00 +0000 | |||
64 | @@ -138,20 +138,6 @@ | |||
65 | 138 | * | 138 | * |
66 | 139 | * Examples: See \l Page | 139 | * Examples: See \l Page |
67 | 140 | * | 140 | * |
68 | 141 | * \section2 Mnemonics | ||
69 | 142 | * Since Ubuntu.Components 1.3 Action supports mnemonics. Mnemonics are shortcuts | ||
70 | 143 | * defined in the \l text property, prefixed the shortcut letter with \&. For instance | ||
71 | 144 | * \c "\&Call" will bint the \c "Alt-C" shortcut to the action. When a mnemonic | ||
72 | 145 | * is detected on the Action and a keyboard is attached to the device, the \l text | ||
73 | 146 | * property will provide a formatted text having the mnemonic letter underscored. | ||
74 | 147 | * \qml | ||
75 | 148 | * Action { | ||
76 | 149 | * id: call | ||
77 | 150 | * iconName: "call" | ||
78 | 151 | * text: "&Call" | ||
79 | 152 | * } | ||
80 | 153 | * \endqml | ||
81 | 154 | * | ||
82 | 155 | * \section2 Checkable property | 141 | * \section2 Checkable property |
83 | 156 | * Since Ubuntu.Components 1.3 Action supports the checkable/checked properties. | 142 | * Since Ubuntu.Components 1.3 Action supports the checkable/checked properties. |
84 | 157 | * \qml | 143 | * \qml |
85 | @@ -191,40 +177,10 @@ | |||
86 | 191 | /*! | 177 | /*! |
87 | 192 | * \qmlproperty string Action::text | 178 | * \qmlproperty string Action::text |
88 | 193 | * The user visible primary label of the action. | 179 | * The user visible primary label of the action. |
89 | 194 | * | ||
90 | 195 | * Mnemonics are shortcuts prefixed in the text with \&. If the text has multiple | ||
91 | 196 | * occurences of the \& character, the first one will be considered for the shortcut. | ||
92 | 197 | * However \&\& can be used for a single \& in the text, not as a mnemonic. | ||
93 | 198 | * The \& character cannot be used as shortcut. | ||
94 | 199 | */ | 180 | */ |
95 | 200 | QString UCAction::text() | 181 | QString UCAction::text() |
96 | 201 | { | 182 | { |
123 | 202 | QString displayText(m_text); | 183 | return m_text; |
98 | 203 | // if we have a mnemonic, underscore it | ||
99 | 204 | if (!m_mnemonic.isEmpty()) { | ||
100 | 205 | |||
101 | 206 | QString mnemonic = "&" + m_mnemonic.toString().remove(QStringLiteral("Alt+")); | ||
102 | 207 | // patch special cases | ||
103 | 208 | mnemonic.replace(QStringLiteral("Space"), QStringLiteral(" ")); | ||
104 | 209 | int mnemonicIndex = m_text.indexOf(mnemonic); | ||
105 | 210 | if (mnemonicIndex < 0) { | ||
106 | 211 | // try lower case | ||
107 | 212 | mnemonic = mnemonic.toLower(); | ||
108 | 213 | mnemonicIndex = m_text.indexOf(mnemonic); | ||
109 | 214 | } | ||
110 | 215 | ACT_TRACE("MNEM" << mnemonic); | ||
111 | 216 | // FIXME: we need QInputDeviceInfo to detect the keyboard attechment | ||
112 | 217 | // https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1276808 | ||
113 | 218 | if (QuickUtils::instance()->keyboardAttached()) { | ||
114 | 219 | // underscore the character | ||
115 | 220 | displayText.replace(mnemonicIndex, mnemonic.length(), "<u>" + mnemonic[1] + "</u>"); | ||
116 | 221 | } else { | ||
117 | 222 | displayText.remove(mnemonicIndex, 1); | ||
118 | 223 | } | ||
119 | 224 | } | ||
120 | 225 | // Escape ampersands | ||
121 | 226 | displayText.replace(QStringLiteral("&&"), QStringLiteral("&")); | ||
122 | 227 | return displayText; | ||
124 | 228 | } | 184 | } |
125 | 229 | void UCAction::setText(const QString &text) | 185 | void UCAction::setText(const QString &text) |
126 | 230 | { | 186 | { |
127 | @@ -232,7 +188,6 @@ | |||
128 | 232 | return; | 188 | return; |
129 | 233 | } | 189 | } |
130 | 234 | m_text = text; | 190 | m_text = text; |
131 | 235 | setMnemonicFromText(m_text); | ||
132 | 236 | Q_EMIT textChanged(); | 191 | Q_EMIT textChanged(); |
133 | 237 | } | 192 | } |
134 | 238 | void UCAction::resetText() | 193 | void UCAction::resetText() |
135 | @@ -240,25 +195,6 @@ | |||
136 | 240 | setText(QString()); | 195 | setText(QString()); |
137 | 241 | } | 196 | } |
138 | 242 | 197 | ||
139 | 243 | void UCAction::setMnemonicFromText(const QString &text) | ||
140 | 244 | { | ||
141 | 245 | QKeySequence sequence = QKeySequence::mnemonic(text); | ||
142 | 246 | if (sequence == m_mnemonic) { | ||
143 | 247 | return; | ||
144 | 248 | } | ||
145 | 249 | if (!m_mnemonic.isEmpty()) { | ||
146 | 250 | QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(0, this, m_mnemonic); | ||
147 | 251 | } | ||
148 | 252 | |||
149 | 253 | m_mnemonic = sequence; | ||
150 | 254 | |||
151 | 255 | if (!m_mnemonic.isEmpty()) { | ||
152 | 256 | ACT_TRACE("MNEMONIC SET" << m_mnemonic.toString()); | ||
153 | 257 | Qt::ShortcutContext context = Qt::WindowShortcut; | ||
154 | 258 | QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(this, m_mnemonic, context, shortcutContextMatcher); | ||
155 | 259 | } | ||
156 | 260 | } | ||
157 | 261 | |||
158 | 262 | /*! | 198 | /*! |
159 | 263 | * \qmlproperty string Action::keywords | 199 | * \qmlproperty string Action::keywords |
160 | 264 | * Additional user visible keywords for the action. | 200 | * Additional user visible keywords for the action. |
161 | @@ -287,10 +223,6 @@ | |||
162 | 287 | , m_checked(false) | 223 | , m_checked(false) |
163 | 288 | { | 224 | { |
164 | 289 | generateName(); | 225 | generateName(); |
165 | 290 | // FIXME: we need QInputDeviceInfo to detect the keyboard attechment | ||
166 | 291 | // https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1276808 | ||
167 | 292 | connect(QuickUtils::instance(), &QuickUtils::keyboardAttachedChanged, | ||
168 | 293 | this, &UCAction::onKeyboardAttached); | ||
169 | 294 | } | 226 | } |
170 | 295 | 227 | ||
171 | 296 | UCAction::~UCAction() | 228 | UCAction::~UCAction() |
172 | @@ -609,14 +541,6 @@ | |||
173 | 609 | return true; | 541 | return true; |
174 | 610 | } | 542 | } |
175 | 611 | 543 | ||
176 | 612 | // trigger text changes whenever HW keyboad is attached/detached | ||
177 | 613 | void UCAction::onKeyboardAttached() | ||
178 | 614 | { | ||
179 | 615 | if (!m_mnemonic.isEmpty()) { | ||
180 | 616 | Q_EMIT textChanged(); | ||
181 | 617 | } | ||
182 | 618 | } | ||
183 | 619 | |||
184 | 620 | /*! | 544 | /*! |
185 | 621 | * \qmlmethod Action::trigger(var value) | 545 | * \qmlmethod Action::trigger(var value) |
186 | 622 | * Checks the \c value against the action \l parameterType and triggers the action. | 546 | * Checks the \c value against the action \l parameterType and triggers the action. |
187 | 623 | 547 | ||
188 | === modified file 'src/UbuntuToolkit/ucaction_p.h' | |||
189 | --- src/UbuntuToolkit/ucaction_p.h 2016-09-09 17:49:07 +0000 | |||
190 | +++ src/UbuntuToolkit/ucaction_p.h 2016-12-13 14:24:00 +0000 | |||
191 | @@ -32,6 +32,8 @@ | |||
192 | 32 | 32 | ||
193 | 33 | UT_NAMESPACE_BEGIN | 33 | UT_NAMESPACE_BEGIN |
194 | 34 | 34 | ||
195 | 35 | Q_DECLARE_LOGGING_CATEGORY(ucAction) | ||
196 | 36 | |||
197 | 35 | // the function detects whether QML has an overridden trigger() slot available | 37 | // the function detects whether QML has an overridden trigger() slot available |
198 | 36 | // and invokes the one with the appropriate signature | 38 | // and invokes the one with the appropriate signature |
199 | 37 | template<class T> | 39 | template<class T> |
200 | @@ -185,7 +187,6 @@ | |||
201 | 185 | void generateName(); | 187 | void generateName(); |
202 | 186 | void setMnemonicFromText(const QString &text); | 188 | void setMnemonicFromText(const QString &text); |
203 | 187 | bool event(QEvent *event) override; | 189 | bool event(QEvent *event) override; |
204 | 188 | void onKeyboardAttached(); | ||
205 | 189 | }; | 190 | }; |
206 | 190 | 191 | ||
207 | 191 | UT_NAMESPACE_END | 192 | UT_NAMESPACE_END |
208 | 192 | 193 | ||
209 | === modified file 'src/UbuntuToolkit/ucactionitem.cpp' | |||
210 | --- src/UbuntuToolkit/ucactionitem.cpp 2016-09-12 09:03:50 +0000 | |||
211 | +++ src/UbuntuToolkit/ucactionitem.cpp 2016-12-13 14:24:00 +0000 | |||
212 | @@ -15,16 +15,65 @@ | |||
213 | 15 | */ | 15 | */ |
214 | 16 | 16 | ||
215 | 17 | #include "ucactionitem_p_p.h" | 17 | #include "ucactionitem_p_p.h" |
216 | 18 | |||
217 | 19 | #define foreach Q_FOREACH | ||
218 | 20 | #include <QtQml/private/qqmlbinding_p.h> | ||
219 | 21 | #undef foreach | ||
220 | 22 | |||
221 | 23 | #include "ucaction_p.h" | 18 | #include "ucaction_p.h" |
222 | 19 | #include "ucactioncontext_p.h" | ||
223 | 24 | #include "ucstyleditembase_p_p.h" | 20 | #include "ucstyleditembase_p_p.h" |
224 | 21 | #include "quickutils_p.h" | ||
225 | 22 | |||
226 | 23 | #include <QtQuick/qquickwindow.h> | ||
227 | 24 | #include <private/qguiapplication_p.h> | ||
228 | 25 | 25 | ||
229 | 26 | UT_NAMESPACE_BEGIN | 26 | UT_NAMESPACE_BEGIN |
230 | 27 | 27 | ||
231 | 28 | #define ACT_TRACE(params) qCDebug(ucAction) << params | ||
232 | 29 | |||
233 | 30 | bool itemShortcutContextMatcher(QObject* object, Qt::ShortcutContext context) | ||
234 | 31 | { | ||
235 | 32 | UCActionItem* actionItem = static_cast<UCActionItem*>(object); | ||
236 | 33 | UCAction* action = actionItem->action(); | ||
237 | 34 | if (!action || !action->isEnabled()) { | ||
238 | 35 | return false; | ||
239 | 36 | } | ||
240 | 37 | |||
241 | 38 | switch (context) { | ||
242 | 39 | case Qt::ApplicationShortcut: | ||
243 | 40 | return true; | ||
244 | 41 | case Qt::WindowShortcut: { | ||
245 | 42 | QObject* window = actionItem->window(); | ||
246 | 43 | bool activatable = window && window == QGuiApplication::focusWindow(); | ||
247 | 44 | |||
248 | 45 | if (activatable) { | ||
249 | 46 | QQuickItem *pl = actionItem; | ||
250 | 47 | activatable = false; | ||
251 | 48 | while (pl) { | ||
252 | 49 | UCActionContextAttached *attached = static_cast<UCActionContextAttached*>( | ||
253 | 50 | qmlAttachedPropertiesObject<UCActionContext>(pl, false)); | ||
254 | 51 | if (attached) { | ||
255 | 52 | activatable = attached->context()->active(); | ||
256 | 53 | if (!activatable) { | ||
257 | 54 | ACT_TRACE(action << "Inactive context found" << attached->context()); | ||
258 | 55 | break; | ||
259 | 56 | } | ||
260 | 57 | } | ||
261 | 58 | pl = pl->parentItem(); | ||
262 | 59 | } | ||
263 | 60 | if (!activatable) { | ||
264 | 61 | // check if the action is in an active context | ||
265 | 62 | UCActionContext *context = qobject_cast<UCActionContext*>(action->parent()); | ||
266 | 63 | activatable = context && context->active(); | ||
267 | 64 | } | ||
268 | 65 | } | ||
269 | 66 | if (activatable) { | ||
270 | 67 | ACT_TRACE("SELECTED ACTION" << action); | ||
271 | 68 | } | ||
272 | 69 | |||
273 | 70 | return activatable; | ||
274 | 71 | } | ||
275 | 72 | default: break; | ||
276 | 73 | } | ||
277 | 74 | return false; | ||
278 | 75 | } | ||
279 | 76 | |||
280 | 28 | UCActionItemPrivate::UCActionItemPrivate() | 77 | UCActionItemPrivate::UCActionItemPrivate() |
281 | 29 | : action(Q_NULLPTR) | 78 | : action(Q_NULLPTR) |
282 | 30 | , flags(0) | 79 | , flags(0) |
283 | @@ -36,6 +85,9 @@ | |||
284 | 36 | Q_Q(UCActionItem); | 85 | Q_Q(UCActionItem); |
285 | 37 | QObject::connect(q, &UCActionItem::enabledChanged, q, &UCActionItem::enabledChanged2); | 86 | QObject::connect(q, &UCActionItem::enabledChanged, q, &UCActionItem::enabledChanged2); |
286 | 38 | QObject::connect(q, &UCActionItem::visibleChanged, q, &UCActionItem::visibleChanged2); | 87 | QObject::connect(q, &UCActionItem::visibleChanged, q, &UCActionItem::visibleChanged2); |
287 | 88 | |||
288 | 89 | QObject::connect(&mnemonic, SIGNAL(visibleChanged()), q, SLOT(_q_textBinding())); | ||
289 | 90 | QObject::connect(&mnemonic, SIGNAL(modifierChanged()), q, SLOT(_q_updateMnemonic())); | ||
290 | 39 | } | 91 | } |
291 | 40 | 92 | ||
292 | 41 | /*! | 93 | /*! |
293 | @@ -50,6 +102,20 @@ | |||
294 | 50 | * If \l action is set, the values of the other properties will by default | 102 | * If \l action is set, the values of the other properties will by default |
295 | 51 | * be identical to the \l Action's property values. Setting the other properties | 103 | * be identical to the \l Action's property values. Setting the other properties |
296 | 52 | * will override the properties copied from the \l Action. | 104 | * will override the properties copied from the \l Action. |
297 | 105 | * | ||
298 | 106 | * \section2 Mnemonics | ||
299 | 107 | * Since Ubuntu.Components 1.3 ActionItem supports mnemonics. Mnemonics are shortcuts | ||
300 | 108 | * defined in the \l text property, prefixed the shortcut letter with \&. For instance | ||
301 | 109 | * \c "\&Call" will bint the \c "Alt-C" shortcut to the action. When a mnemonic | ||
302 | 110 | * is detected on the ActionItem and a keyboard is attached to the device, the \l text | ||
303 | 111 | * property will provide a formatted text having the mnemonic letter underscored. | ||
304 | 112 | * \qml | ||
305 | 113 | * ActionItem { | ||
306 | 114 | * id: call | ||
307 | 115 | * iconName: "call" | ||
308 | 116 | * text: "&Call" | ||
309 | 117 | * } | ||
310 | 118 | * \endqml | ||
311 | 53 | */ | 119 | */ |
312 | 54 | 120 | ||
313 | 55 | /*! | 121 | /*! |
314 | @@ -60,6 +126,11 @@ | |||
315 | 60 | : UCStyledItemBase(*(new UCActionItemPrivate), parent) | 126 | : UCStyledItemBase(*(new UCActionItemPrivate), parent) |
316 | 61 | { | 127 | { |
317 | 62 | d_func()->init(); | 128 | d_func()->init(); |
318 | 129 | |||
319 | 130 | // FIXME: we need QInputDeviceInfo to detect the keyboard attechment | ||
320 | 131 | // https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1276808 | ||
321 | 132 | connect(QuickUtils::instance(), SIGNAL(keyboardAttachedChanged()), | ||
322 | 133 | this, SLOT(_q_onKeyboardAttached()), Qt::DirectConnection); | ||
323 | 63 | } | 134 | } |
324 | 64 | 135 | ||
325 | 65 | UCActionItem::UCActionItem(UCActionItemPrivate &dd, QQuickItem *parent) | 136 | UCActionItem::UCActionItem(UCActionItemPrivate &dd, QQuickItem *parent) |
326 | @@ -68,6 +139,29 @@ | |||
327 | 68 | d_func()->init(); | 139 | d_func()->init(); |
328 | 69 | } | 140 | } |
329 | 70 | 141 | ||
330 | 142 | bool UCActionItem::event(QEvent *e) | ||
331 | 143 | { | ||
332 | 144 | Q_D(UCActionItem); | ||
333 | 145 | if (e->type() == QEvent::Shortcut) { | ||
334 | 146 | if (!d->action) { | ||
335 | 147 | return false; | ||
336 | 148 | } | ||
337 | 149 | |||
338 | 150 | // when we reach this point, we can be sure the Action is used | ||
339 | 151 | // by a component belonging to an active ActionContext. | ||
340 | 152 | QShortcutEvent *shortcut_event(static_cast<QShortcutEvent*>(e)); | ||
341 | 153 | if (shortcut_event->isAmbiguous()) { | ||
342 | 154 | qmlInfo(this) << "Ambiguous shortcut: " << shortcut_event->key().toString(); | ||
343 | 155 | return false; | ||
344 | 156 | } | ||
345 | 157 | |||
346 | 158 | // do not call trigger() directly but invoke, as it may get overridden in QML | ||
347 | 159 | invokeTrigger<UCAction>(d->action, QVariant()); | ||
348 | 160 | return true; | ||
349 | 161 | } | ||
350 | 162 | return UCStyledItemBase::event(e); | ||
351 | 163 | } | ||
352 | 164 | |||
353 | 71 | bool UCActionItemPrivate::hasBindingOnProperty(const QString &name) | 165 | bool UCActionItemPrivate::hasBindingOnProperty(const QString &name) |
354 | 72 | { | 166 | { |
355 | 73 | Q_Q(UCActionItem); | 167 | Q_Q(UCActionItem); |
356 | @@ -109,6 +203,51 @@ | |||
357 | 109 | invokeTrigger<UCAction>(action, value); | 203 | invokeTrigger<UCAction>(action, value); |
358 | 110 | } | 204 | } |
359 | 111 | 205 | ||
360 | 206 | // update the text property | ||
361 | 207 | void UCActionItemPrivate::_q_textBinding() | ||
362 | 208 | { | ||
363 | 209 | if (flags & CustomText) { | ||
364 | 210 | return; | ||
365 | 211 | } | ||
366 | 212 | _q_updateMnemonic(); | ||
367 | 213 | Q_EMIT q_func()->textChanged(); | ||
368 | 214 | } | ||
369 | 215 | |||
370 | 216 | // trigger text changes whenever HW keyboad is attached/detached | ||
371 | 217 | void UCActionItemPrivate::_q_onKeyboardAttached() | ||
372 | 218 | { | ||
373 | 219 | if (!mnemonic.sequence().isEmpty()) { | ||
374 | 220 | Q_EMIT q_func()->textChanged(); | ||
375 | 221 | } | ||
376 | 222 | } | ||
377 | 223 | |||
378 | 224 | void UCActionItemPrivate::_q_updateMnemonic() | ||
379 | 225 | { | ||
380 | 226 | Q_Q(UCActionItem); | ||
381 | 227 | |||
382 | 228 | const QString displayText = action ? action->text() : QString(); | ||
383 | 229 | |||
384 | 230 | QKeySequence sequence = QKeySequence::mnemonic(displayText); | ||
385 | 231 | if (!sequence.isEmpty()) { | ||
386 | 232 | sequence = sequence[0] & ~Qt::ALT; // QKeySequence::mnemonic adds alt. | ||
387 | 233 | sequence = sequence[0] | mnemonic.modifier(); | ||
388 | 234 | } | ||
389 | 235 | |||
390 | 236 | if (sequence == mnemonic.sequence()) { | ||
391 | 237 | return; | ||
392 | 238 | } | ||
393 | 239 | if (!mnemonic.sequence().isEmpty()) { | ||
394 | 240 | QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(0, q, mnemonic.sequence()); | ||
395 | 241 | } | ||
396 | 242 | |||
397 | 243 | mnemonic.setSequence(sequence); | ||
398 | 244 | |||
399 | 245 | if (!sequence.isEmpty()) { | ||
400 | 246 | Qt::ShortcutContext context = Qt::WindowShortcut; | ||
401 | 247 | QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(q, sequence, context, itemShortcutContextMatcher); | ||
402 | 248 | } | ||
403 | 249 | } | ||
404 | 250 | |||
405 | 112 | // setter called when bindings from QML set the value. Internal functions will | 251 | // setter called when bindings from QML set the value. Internal functions will |
406 | 113 | // all use the setVisible setter, so initialization and (re)parenting related | 252 | // all use the setVisible setter, so initialization and (re)parenting related |
407 | 114 | // visible alteration won't set the custom flag | 253 | // visible alteration won't set the custom flag |
408 | @@ -124,12 +263,15 @@ | |||
409 | 124 | setEnabled(enabled); | 263 | setEnabled(enabled); |
410 | 125 | } | 264 | } |
411 | 126 | 265 | ||
412 | 266 | UCActionMnemonic *UCActionItem::mnemonic() | ||
413 | 267 | { | ||
414 | 268 | Q_D(UCActionItem); | ||
415 | 269 | return &d->mnemonic; | ||
416 | 270 | } | ||
417 | 271 | |||
418 | 127 | void UCActionItemPrivate::updateProperties() | 272 | void UCActionItemPrivate::updateProperties() |
419 | 128 | { | 273 | { |
420 | 129 | Q_Q(UCActionItem); | 274 | Q_Q(UCActionItem); |
421 | 130 | if (!(flags & CustomText)) { | ||
422 | 131 | Q_EMIT q->textChanged(); | ||
423 | 132 | } | ||
424 | 133 | if (!(flags & CustomIconSource)) { | 275 | if (!(flags & CustomIconSource)) { |
425 | 134 | Q_EMIT q->iconSourceChanged(); | 276 | Q_EMIT q->iconSourceChanged(); |
426 | 135 | } | 277 | } |
427 | @@ -154,8 +296,8 @@ | |||
428 | 154 | q, SLOT(_q_enabledBinding()), Qt::DirectConnection); | 296 | q, SLOT(_q_enabledBinding()), Qt::DirectConnection); |
429 | 155 | } | 297 | } |
430 | 156 | if (!(flags & CustomText)) { | 298 | if (!(flags & CustomText)) { |
433 | 157 | QObject::connect(action, &UCAction::textChanged, | 299 | QObject::connect(action, SIGNAL(textChanged()), |
434 | 158 | q, &UCActionItem::textChanged, Qt::DirectConnection); | 300 | q, SLOT(_q_textBinding()), Qt::DirectConnection); |
435 | 159 | } | 301 | } |
436 | 160 | if (!(flags & CustomIconSource)) { | 302 | if (!(flags & CustomIconSource)) { |
437 | 161 | QObject::connect(action, &UCAction::iconSourceChanged, | 303 | QObject::connect(action, &UCAction::iconSourceChanged, |
438 | @@ -178,8 +320,8 @@ | |||
439 | 178 | q, SLOT(_q_enabledBinding())); | 320 | q, SLOT(_q_enabledBinding())); |
440 | 179 | } | 321 | } |
441 | 180 | if (!(flags & CustomText)) { | 322 | if (!(flags & CustomText)) { |
444 | 181 | QObject::disconnect(action, &UCAction::textChanged, | 323 | QObject::disconnect(action, SIGNAL(textChanged()), |
445 | 182 | q, &UCActionItem::textChanged); | 324 | q, SLOT(_q_textBinding())); |
446 | 183 | } | 325 | } |
447 | 184 | if (!(flags & CustomIconSource)) { | 326 | if (!(flags & CustomIconSource)) { |
448 | 185 | QObject::disconnect(action, &UCAction::iconSourceChanged, | 327 | QObject::disconnect(action, &UCAction::iconSourceChanged, |
449 | @@ -189,6 +331,11 @@ | |||
450 | 189 | QObject::disconnect(action, &UCAction::iconNameChanged, | 331 | QObject::disconnect(action, &UCAction::iconNameChanged, |
451 | 190 | q, &UCActionItem::iconNameChanged); | 332 | q, &UCActionItem::iconNameChanged); |
452 | 191 | } | 333 | } |
453 | 334 | |||
454 | 335 | if (!mnemonic.sequence().isEmpty()) { | ||
455 | 336 | QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(0, q, mnemonic.sequence()); | ||
456 | 337 | mnemonic.setSequence(QKeySequence()); | ||
457 | 338 | } | ||
458 | 192 | } | 339 | } |
459 | 193 | } | 340 | } |
460 | 194 | 341 | ||
461 | @@ -220,12 +367,18 @@ | |||
462 | 220 | } | 367 | } |
463 | 221 | d->_q_visibleBinding(); | 368 | d->_q_visibleBinding(); |
464 | 222 | d->_q_enabledBinding(); | 369 | d->_q_enabledBinding(); |
465 | 370 | d->_q_textBinding(); | ||
466 | 223 | d->updateProperties(); | 371 | d->updateProperties(); |
467 | 224 | } | 372 | } |
468 | 225 | 373 | ||
469 | 226 | /*! | 374 | /*! |
470 | 227 | * \qmlproperty string ActionItem::text | 375 | * \qmlproperty string ActionItem::text |
471 | 228 | * The title of the actionItem. Defaults to the \c action.text. | 376 | * The title of the actionItem. Defaults to the \c action.text. |
472 | 377 | * | ||
473 | 378 | * Mnemonics are shortcuts prefixed in the text with \&. If the text has multiple | ||
474 | 379 | * occurences of the \& character, the first one will be considered for the shortcut. | ||
475 | 380 | * However \&\& can be used for a single \& in the text, not as a mnemonic. | ||
476 | 381 | * The \& character cannot be used as shortcut. | ||
477 | 229 | */ | 382 | */ |
478 | 230 | QString UCActionItem::text() | 383 | QString UCActionItem::text() |
479 | 231 | { | 384 | { |
480 | @@ -233,7 +386,40 @@ | |||
481 | 233 | if (d->flags & UCActionItemPrivate::CustomText) { | 386 | if (d->flags & UCActionItemPrivate::CustomText) { |
482 | 234 | return d->text; | 387 | return d->text; |
483 | 235 | } | 388 | } |
485 | 236 | return d->action ? d->action->text() : QString(); | 389 | |
486 | 390 | if (!d->action) { | ||
487 | 391 | return QString(); | ||
488 | 392 | } | ||
489 | 393 | |||
490 | 394 | QString displayText(d->action->text()); | ||
491 | 395 | |||
492 | 396 | // if we have a mnemonic, underscore it | ||
493 | 397 | if (!d->mnemonic.sequence().isEmpty()) { | ||
494 | 398 | const QString modifier = QKeySequence(d->mnemonic.modifier()).toString(); | ||
495 | 399 | |||
496 | 400 | QString mnemonic = "&" + d->mnemonic.sequence().toString().remove(modifier); | ||
497 | 401 | // patch special cases | ||
498 | 402 | mnemonic.replace(QStringLiteral("Space"), QStringLiteral(" ")); | ||
499 | 403 | int mnemonicIndex = displayText.indexOf(mnemonic); | ||
500 | 404 | if (mnemonicIndex < 0) { | ||
501 | 405 | // try lower case | ||
502 | 406 | mnemonic = mnemonic.toLower(); | ||
503 | 407 | mnemonicIndex = displayText.indexOf(mnemonic); | ||
504 | 408 | } | ||
505 | 409 | |||
506 | 410 | // FIXME: we need QInputDeviceInfo to detect the keyboard attechment | ||
507 | 411 | // https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1276808 | ||
508 | 412 | if (d->mnemonic.visible() && QuickUtils::instance()->keyboardAttached()) { | ||
509 | 413 | // underscore the character | ||
510 | 414 | displayText.replace(mnemonicIndex, mnemonic.length(), "<u>" + mnemonic[1] + "</u>"); | ||
511 | 415 | } else { | ||
512 | 416 | displayText.remove(mnemonicIndex, 1); | ||
513 | 417 | } | ||
514 | 418 | } | ||
515 | 419 | |||
516 | 420 | // Escape ampersands | ||
517 | 421 | displayText.replace(QStringLiteral("&&"), QStringLiteral("&")); | ||
518 | 422 | return displayText; | ||
519 | 237 | } | 423 | } |
520 | 238 | void UCActionItem::setText(const QString &text) | 424 | void UCActionItem::setText(const QString &text) |
521 | 239 | { | 425 | { |
522 | @@ -241,8 +427,8 @@ | |||
523 | 241 | 427 | ||
524 | 242 | if (d->action && !(d->flags & UCActionItemPrivate::CustomText)) { | 428 | if (d->action && !(d->flags & UCActionItemPrivate::CustomText)) { |
525 | 243 | // disconnect change signal from Action | 429 | // disconnect change signal from Action |
528 | 244 | disconnect(d->action, &UCAction::textChanged, | 430 | disconnect(d->action, SIGNAL(textChanged()), |
529 | 245 | this, &UCActionItem::textChanged); | 431 | this, SLOT(_q_textBinding())); |
530 | 246 | } | 432 | } |
531 | 247 | d->flags |= UCActionItemPrivate::CustomText; | 433 | d->flags |= UCActionItemPrivate::CustomText; |
532 | 248 | 434 | ||
533 | @@ -259,8 +445,8 @@ | |||
534 | 259 | d->flags &= ~UCActionItemPrivate::CustomText; | 445 | d->flags &= ~UCActionItemPrivate::CustomText; |
535 | 260 | if (d->action) { | 446 | if (d->action) { |
536 | 261 | // re-connect change signal from Action | 447 | // re-connect change signal from Action |
539 | 262 | connect(d->action, &UCAction::textChanged, | 448 | connect(d->action, SIGNAL(textChanged()), |
540 | 263 | this, &UCActionItem::textChanged, Qt::DirectConnection); | 449 | this, SLOT(_q_textBinding()), Qt::DirectConnection); |
541 | 264 | } | 450 | } |
542 | 265 | Q_EMIT textChanged(); | 451 | Q_EMIT textChanged(); |
543 | 266 | } | 452 | } |
544 | @@ -382,6 +568,52 @@ | |||
545 | 382 | } | 568 | } |
546 | 383 | } | 569 | } |
547 | 384 | 570 | ||
548 | 571 | UCActionMnemonic::UCActionMnemonic(QObject *parent) | ||
549 | 572 | : QObject(parent) | ||
550 | 573 | , m_visible(true) | ||
551 | 574 | , m_modifier(Qt::ALT) | ||
552 | 575 | { | ||
553 | 576 | } | ||
554 | 577 | |||
555 | 578 | bool UCActionMnemonic::visible() const | ||
556 | 579 | { | ||
557 | 580 | return m_visible; | ||
558 | 581 | } | ||
559 | 582 | |||
560 | 583 | void UCActionMnemonic::setVisible(bool visible) | ||
561 | 584 | { | ||
562 | 585 | if (visible != m_visible) { | ||
563 | 586 | m_visible = visible; | ||
564 | 587 | Q_EMIT visibleChanged(); | ||
565 | 588 | } | ||
566 | 589 | } | ||
567 | 590 | |||
568 | 591 | int UCActionMnemonic::modifier() const | ||
569 | 592 | { | ||
570 | 593 | return m_modifier; | ||
571 | 594 | } | ||
572 | 595 | |||
573 | 596 | void UCActionMnemonic::setModifier(int modifier) | ||
574 | 597 | { | ||
575 | 598 | if (modifier != m_modifier) { | ||
576 | 599 | m_modifier = modifier; | ||
577 | 600 | Q_EMIT modifierChanged(); | ||
578 | 601 | } | ||
579 | 602 | } | ||
580 | 603 | |||
581 | 604 | const QKeySequence& UCActionMnemonic::sequence() const | ||
582 | 605 | { | ||
583 | 606 | return m_sequence; | ||
584 | 607 | } | ||
585 | 608 | |||
586 | 609 | void UCActionMnemonic::setSequence(const QKeySequence &sequence) | ||
587 | 610 | { | ||
588 | 611 | if (m_sequence != sequence) { | ||
589 | 612 | m_sequence = sequence; | ||
590 | 613 | Q_EMIT sequenceChanged(); | ||
591 | 614 | } | ||
592 | 615 | } | ||
593 | 616 | |||
594 | 385 | UT_NAMESPACE_END | 617 | UT_NAMESPACE_END |
595 | 386 | 618 | ||
596 | 387 | #include "moc_ucactionitem_p.cpp" | 619 | #include "moc_ucactionitem_p.cpp" |
597 | 388 | 620 | ||
598 | === modified file 'src/UbuntuToolkit/ucactionitem_p.h' | |||
599 | --- src/UbuntuToolkit/ucactionitem_p.h 2016-09-09 17:49:07 +0000 | |||
600 | +++ src/UbuntuToolkit/ucactionitem_p.h 2016-12-13 14:24:00 +0000 | |||
601 | @@ -23,6 +23,7 @@ | |||
602 | 23 | 23 | ||
603 | 24 | class UCAction; | 24 | class UCAction; |
604 | 25 | class UCActionItemPrivate; | 25 | class UCActionItemPrivate; |
605 | 26 | class UCActionMnemonic; | ||
606 | 26 | class UBUNTUTOOLKIT_EXPORT UCActionItem : public UCStyledItemBase | 27 | class UBUNTUTOOLKIT_EXPORT UCActionItem : public UCStyledItemBase |
607 | 27 | { | 28 | { |
608 | 28 | Q_OBJECT | 29 | Q_OBJECT |
609 | @@ -35,6 +36,13 @@ | |||
610 | 35 | Q_PROPERTY(QUrl iconSource READ iconSource WRITE setIconSource RESET resetIconSource NOTIFY iconSourceChanged) | 36 | Q_PROPERTY(QUrl iconSource READ iconSource WRITE setIconSource RESET resetIconSource NOTIFY iconSourceChanged) |
611 | 36 | Q_PROPERTY(QString iconName READ iconName WRITE setIconName RESET resetIconName NOTIFY iconNameChanged) | 37 | Q_PROPERTY(QString iconName READ iconName WRITE setIconName RESET resetIconName NOTIFY iconNameChanged) |
612 | 37 | 38 | ||
613 | 39 | // 1.3 | ||
614 | 40 | #ifndef Q_QDOC | ||
615 | 41 | Q_PROPERTY(UT_PREPEND_NAMESPACE(UCActionMnemonic) *mnemonic READ mnemonic CONSTANT FINAL REVISION 1) | ||
616 | 42 | #else | ||
617 | 43 | Q_PROPERTY(UCActionMnemonic *mnemonic READ mnemonic CONSTANT FINAL REVISION 1) | ||
618 | 44 | #endif | ||
619 | 45 | |||
620 | 38 | // overrides | 46 | // overrides |
621 | 39 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled2 NOTIFY enabledChanged2) | 47 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled2 NOTIFY enabledChanged2) |
622 | 40 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible2 NOTIFY visibleChanged2 FINAL) | 48 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible2 NOTIFY visibleChanged2 FINAL) |
623 | @@ -56,6 +64,8 @@ | |||
624 | 56 | void setVisible2(bool visible); | 64 | void setVisible2(bool visible); |
625 | 57 | void setEnabled2(bool enabled); | 65 | void setEnabled2(bool enabled); |
626 | 58 | 66 | ||
627 | 67 | UCActionMnemonic* mnemonic(); | ||
628 | 68 | |||
629 | 59 | Q_SIGNALS: | 69 | Q_SIGNALS: |
630 | 60 | void actionChanged(); | 70 | void actionChanged(); |
631 | 61 | void textChanged(); | 71 | void textChanged(); |
632 | @@ -72,10 +82,44 @@ | |||
633 | 72 | protected: | 82 | protected: |
634 | 73 | UCActionItem(UCActionItemPrivate &, QQuickItem *parent); | 83 | UCActionItem(UCActionItemPrivate &, QQuickItem *parent); |
635 | 74 | 84 | ||
636 | 85 | bool event(QEvent *event) override; | ||
637 | 86 | |||
638 | 75 | Q_DECLARE_PRIVATE(UCActionItem) | 87 | Q_DECLARE_PRIVATE(UCActionItem) |
639 | 76 | Q_PRIVATE_SLOT(d_func(), void _q_visibleBinding()) | 88 | Q_PRIVATE_SLOT(d_func(), void _q_visibleBinding()) |
640 | 77 | Q_PRIVATE_SLOT(d_func(), void _q_enabledBinding()) | 89 | Q_PRIVATE_SLOT(d_func(), void _q_enabledBinding()) |
641 | 78 | Q_PRIVATE_SLOT(d_func(), void _q_invokeActionTrigger(const QVariant &value)) | 90 | Q_PRIVATE_SLOT(d_func(), void _q_invokeActionTrigger(const QVariant &value)) |
642 | 91 | Q_PRIVATE_SLOT(d_func(), void _q_textBinding()) | ||
643 | 92 | Q_PRIVATE_SLOT(d_func(), void _q_onKeyboardAttached()) | ||
644 | 93 | Q_PRIVATE_SLOT(d_func(), void _q_updateMnemonic()) | ||
645 | 94 | }; | ||
646 | 95 | |||
647 | 96 | class UBUNTUTOOLKIT_EXPORT UCActionMnemonic : public QObject | ||
648 | 97 | { | ||
649 | 98 | Q_OBJECT | ||
650 | 99 | Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged) | ||
651 | 100 | Q_PROPERTY(int modifier READ modifier WRITE setModifier NOTIFY modifierChanged) | ||
652 | 101 | Q_PROPERTY(QKeySequence sequence READ sequence NOTIFY sequenceChanged) | ||
653 | 102 | public: | ||
654 | 103 | UCActionMnemonic(QObject* parent = 0); | ||
655 | 104 | |||
656 | 105 | bool visible() const; | ||
657 | 106 | void setVisible(bool visible); | ||
658 | 107 | |||
659 | 108 | int modifier() const; | ||
660 | 109 | void setModifier(int modifier); | ||
661 | 110 | |||
662 | 111 | const QKeySequence& sequence() const; | ||
663 | 112 | void setSequence(const QKeySequence& sequence); | ||
664 | 113 | |||
665 | 114 | Q_SIGNALS: | ||
666 | 115 | void visibleChanged(); | ||
667 | 116 | void modifierChanged(); | ||
668 | 117 | void sequenceChanged(); | ||
669 | 118 | |||
670 | 119 | private: | ||
671 | 120 | bool m_visible; | ||
672 | 121 | int m_modifier; | ||
673 | 122 | QKeySequence m_sequence; | ||
674 | 79 | }; | 123 | }; |
675 | 80 | 124 | ||
676 | 81 | UT_NAMESPACE_END | 125 | UT_NAMESPACE_END |
677 | 82 | 126 | ||
678 | === modified file 'src/UbuntuToolkit/ucactionitem_p_p.h' | |||
679 | --- src/UbuntuToolkit/ucactionitem_p_p.h 2016-09-09 17:49:07 +0000 | |||
680 | +++ src/UbuntuToolkit/ucactionitem_p_p.h 2016-12-13 14:24:00 +0000 | |||
681 | @@ -45,6 +45,9 @@ | |||
682 | 45 | void _q_visibleBinding(); | 45 | void _q_visibleBinding(); |
683 | 46 | void _q_enabledBinding(); | 46 | void _q_enabledBinding(); |
684 | 47 | void _q_invokeActionTrigger(const QVariant &value); | 47 | void _q_invokeActionTrigger(const QVariant &value); |
685 | 48 | void _q_textBinding(); | ||
686 | 49 | void _q_onKeyboardAttached(); | ||
687 | 50 | void _q_updateMnemonic(); | ||
688 | 48 | 51 | ||
689 | 49 | enum { | 52 | enum { |
690 | 50 | CustomText = 0x01, | 53 | CustomText = 0x01, |
691 | @@ -58,6 +61,7 @@ | |||
692 | 58 | QUrl iconSource; | 61 | QUrl iconSource; |
693 | 59 | UCAction *action; | 62 | UCAction *action; |
694 | 60 | quint8 flags; | 63 | quint8 flags; |
695 | 64 | UCActionMnemonic mnemonic; | ||
696 | 61 | }; | 65 | }; |
697 | 62 | 66 | ||
698 | 63 | UT_NAMESPACE_END | 67 | UT_NAMESPACE_END |
699 | 64 | 68 | ||
700 | === modified file 'tests/unit/visual/tst_actionitem.11.qml' | |||
701 | --- tests/unit/visual/tst_actionitem.11.qml 2016-06-15 13:46:51 +0000 | |||
702 | +++ tests/unit/visual/tst_actionitem.11.qml 2016-12-13 14:24:00 +0000 | |||
703 | @@ -16,7 +16,7 @@ | |||
704 | 16 | 16 | ||
705 | 17 | import QtQuick 2.0 | 17 | import QtQuick 2.0 |
706 | 18 | import QtTest 1.0 | 18 | import QtTest 1.0 |
708 | 19 | import Ubuntu.Components 1.1 | 19 | import Ubuntu.Components 1.3 |
709 | 20 | 20 | ||
710 | 21 | Item { | 21 | Item { |
711 | 22 | id: main | 22 | id: main |
712 | @@ -58,6 +58,7 @@ | |||
713 | 58 | Action { | 58 | Action { |
714 | 59 | id: action2 | 59 | id: action2 |
715 | 60 | objectName: "action2" | 60 | objectName: "action2" |
716 | 61 | text: "&mnemonicActionText" | ||
717 | 61 | } | 62 | } |
718 | 62 | 63 | ||
719 | 63 | Loader { | 64 | Loader { |
720 | @@ -86,6 +87,7 @@ | |||
721 | 86 | function cleanup() { | 87 | function cleanup() { |
722 | 87 | loader.sourceComponent = null; | 88 | loader.sourceComponent = null; |
723 | 88 | item1.action = null; | 89 | item1.action = null; |
724 | 90 | item1.text = undefined; | ||
725 | 89 | action1.visible = true; | 91 | action1.visible = true; |
726 | 90 | action1.enabled = true; | 92 | action1.enabled = true; |
727 | 91 | action2.visible = true; | 93 | action2.visible = true; |
728 | @@ -116,6 +118,12 @@ | |||
729 | 116 | compare(item1.text, "", "text can be unset") | 118 | compare(item1.text, "", "text can be unset") |
730 | 117 | } | 119 | } |
731 | 118 | 120 | ||
732 | 121 | function test_action_mnemonic() { | ||
733 | 122 | QuickUtils.keyboardAttached = true; | ||
734 | 123 | item1.action = action2; | ||
735 | 124 | compare(item1.text, "<u>m</u>nemonicActionText", "Text uses action text mnemonics"); | ||
736 | 125 | } | ||
737 | 126 | |||
738 | 119 | // NOTE: This test must be run AFTER test_action(), otherwise setting the action will | 127 | // NOTE: This test must be run AFTER test_action(), otherwise setting the action will |
739 | 120 | // will not update the iconSource | 128 | // will not update the iconSource |
740 | 121 | function test_iconSource() { | 129 | function test_iconSource() { |
Mostly clarification I need. Also few more tests to cover the group properties please.