Merge lp:~nick-dedekind/ubuntu-ui-toolkit/menus into lp:ubuntu-ui-toolkit
- menus
- Merge into trunk
Status: | Superseded |
---|---|
Proposed branch: | lp:~nick-dedekind/ubuntu-ui-toolkit/menus |
Merge into: | lp:ubuntu-ui-toolkit |
Prerequisite: | lp:~nick-dedekind/ubuntu-ui-toolkit/actionItem-mnemonics |
Diff against target: |
2175 lines (+1727/-152) 19 files modified
components.api (+27/-6) src/Ubuntu/Components/1.2/ActionList.qml (+0/-47) src/Ubuntu/Components/1.3/ActionList.qml (+0/-47) src/Ubuntu/Components/ComponentModule.pro (+0/-2) src/Ubuntu/Components/plugin/plugin.cpp (+10/-0) src/Ubuntu/Components/plugin/plugin.pri (+13/-3) src/Ubuntu/Components/plugin/ucaction.cpp (+103/-37) src/Ubuntu/Components/plugin/ucaction.h (+27/-7) src/Ubuntu/Components/plugin/ucactionlist.cpp (+104/-0) src/Ubuntu/Components/plugin/ucactionlist.h (+53/-0) src/Ubuntu/Components/plugin/ucexclusivegroup.cpp (+106/-0) src/Ubuntu/Components/plugin/ucexclusivegroup.h (+53/-0) src/Ubuntu/Components/plugin/ucmenu.cpp (+613/-0) src/Ubuntu/Components/plugin/ucmenu.h (+108/-0) src/Ubuntu/Components/plugin/ucmenu_p.h (+83/-0) src/Ubuntu/Components/plugin/ucmenubar.cpp (+299/-0) src/Ubuntu/Components/plugin/ucmenubar.h (+60/-0) src/Ubuntu/Components/plugin/ucmenubar_p.h (+68/-0) src/Ubuntu/Components/qmldir (+0/-3) |
To merge this branch: | bzr merge lp:~nick-dedekind/ubuntu-ui-toolkit/menus |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu SDK team | Pending | ||
Review via email: mp+295432@code.launchpad.net |
This proposal has been superseded by a proposal from 2016-06-07.
Commit message
API for MenuBar, Menus, MenuItem & MenuSeparator
Description of the change
- 1323. By Timo Jyrinki
-
Rebuild for arm64 gles switch.
- 1324. By Timo Jyrinki
-
no "-gles" in changelog package name
- 1325. By Albert Astals Cid
-
OTA12-2016-05-20
- 1326. By CI Train Bot Account
-
Releasing 1.3.1984+
16.10.20160527. 2 - 1327. By Zoltan Balogh
-
OTA12-2016-06-01
- 1328. By CI Train Bot Account
-
Releasing 1.3.1988+
16.10.20160601 - 1329. By CI Train Bot Account
-
Resync trunk.
- 1330. By Nick Dedekind
-
merged actionList
- 1331. By Nick Dedekind
-
members accessors to functions
- 1332. By Nick Dedekind
-
Menu API
- 1333. By Nick Dedekind
-
merged with actionList
- 1334. By Nick Dedekind
-
new components.api
- 1335. By Nick Dedekind
-
fix platform abstraction
- 1336. By Nick Dedekind
-
better dynamicness
- 1337. By Nick Dedekind
-
updated api
- 1338. By Nick Dedekind
-
removed debug
- 1339. By Nick Dedekind
-
removed attached properties
- 1340. By Nick Dedekind
-
better removal
- 1341. By Nick Dedekind
-
activate state
- 1342. By Nick Dedekind
-
enable fix
- 1343. By Nick Dedekind
-
added MenuGroup::at
- 1344. By Nick Dedekind
-
simplified insert
- 1345. By Nick Dedekind
-
Added menu unit tests
- 1346. By Nick Dedekind
-
updated menu tests
- 1347. By Nick Dedekind
-
updated menu tests
- 1348. By Nick Dedekind
-
updated menu tests
- 1349. By Nick Dedekind
-
removed distfile from pro
- 1350. By Nick Dedekind
-
merged exclusiveGroup
- 1351. By Nick Dedekind
-
merged with staging
- 1352. By Nick Dedekind
-
merged parent
- 1353. By Nick Dedekind
-
fixed namespace
- 1354. By Nick Dedekind
-
merged with trunk
- 1355. By Nick Dedekind
-
removed uc prefix
- 1356. By Nick Dedekind
-
moved menus to Labs
- 1357. By Nick Dedekind
-
merged parent
- 1358. By Nick Dedekind
-
merged staging
- 1359. By Nick Dedekind
-
fixed broken build
Unmerged revisions
- 1359. By Nick Dedekind
-
fixed broken build
Preview Diff
1 | === modified file 'components.api' | |||
2 | --- components.api 2016-05-20 17:33:56 +0000 | |||
3 | +++ components.api 2016-06-07 14:25:30 +0000 | |||
4 | @@ -12,6 +12,7 @@ | |||
5 | 12 | Ubuntu.Components.Action 1.3 1.0 0.1 UCAction: QtObject | 12 | Ubuntu.Components.Action 1.3 1.0 0.1 UCAction: QtObject |
6 | 13 | property string description | 13 | property string description |
7 | 14 | property bool enabled | 14 | property bool enabled |
8 | 15 | property ExclusiveGroup exclusiveGroup 1.3 | ||
9 | 15 | property string iconName | 16 | property string iconName |
10 | 16 | property url iconSource | 17 | property url iconSource |
11 | 17 | property Component itemHint | 18 | property Component itemHint |
12 | @@ -19,9 +20,11 @@ | |||
13 | 19 | signal triggered(var value) | 20 | signal triggered(var value) |
14 | 20 | function trigger(var value) | 21 | function trigger(var value) |
15 | 21 | function trigger() | 22 | function trigger() |
16 | 23 | function setState(var ) | ||
17 | 22 | property string name | 24 | property string name |
18 | 23 | property Type parameterType | 25 | property Type parameterType |
19 | 24 | property var shortcut 1.3 | 26 | property var shortcut 1.3 |
20 | 27 | property var state 1.3 | ||
21 | 25 | property string text | 28 | property string text |
22 | 26 | property bool visible | 29 | property bool visible |
23 | 27 | Ubuntu.Components.Action.Type: Enum | 30 | Ubuntu.Components.Action.Type: Enum |
24 | @@ -54,12 +57,12 @@ | |||
25 | 54 | function trigger(var value) | 57 | function trigger(var value) |
26 | 55 | function trigger() | 58 | function trigger() |
27 | 56 | property string text | 59 | property string text |
34 | 57 | Ubuntu.Components.ActionList 1.0 0.1: QtObject | 60 | Ubuntu.Components.ActionList 1.0 0.1 UCActionList: QtObject |
35 | 58 | property list<Action> actions | 61 | default property list<Action> actions |
36 | 59 | default property list<Action> children | 62 | signal added(Action action) |
37 | 60 | Ubuntu.Components.ActionList 1.3: QtObject | 63 | signal removed(Action action) |
38 | 61 | property list<Action> actions | 64 | function addAction(Action action) |
39 | 62 | default property list<Action> children | 65 | function removeAction(Action action) |
40 | 63 | Ubuntu.Components.ActionManager 1.0 0.1 UCActionManager: QtObject | 66 | Ubuntu.Components.ActionManager 1.0 0.1 UCActionManager: QtObject |
41 | 64 | default property list<Action> actions | 67 | default property list<Action> actions |
42 | 65 | readonly property ActionContext globalContext | 68 | readonly property ActionContext globalContext |
43 | @@ -456,6 +459,8 @@ | |||
44 | 456 | property bool showDivider | 459 | property bool showDivider |
45 | 457 | readonly property string swipingState | 460 | readonly property string swipingState |
46 | 458 | readonly property bool waitingConfirmationForRemoval | 461 | readonly property bool waitingConfirmationForRemoval |
47 | 462 | Ubuntu.Components.ExclusiveGroup 1.3 UCExclusiveGroup: ActionList | ||
48 | 463 | readonly property Action selected | ||
49 | 459 | Ubuntu.Components.ListItems.Expandable 1.0 0.1: Empty | 464 | Ubuntu.Components.ListItems.Expandable 1.0 0.1: Empty |
50 | 460 | property bool collapseOnClick | 465 | property bool collapseOnClick |
51 | 461 | property double collapsedHeight | 466 | property double collapsedHeight |
52 | @@ -656,6 +661,22 @@ | |||
53 | 656 | function double lerp(double delta, double from, double to) | 661 | function double lerp(double delta, double from, double to) |
54 | 657 | function double projectValue(double x, double xmin, double xmax, double ymin, double ymax) | 662 | function double projectValue(double x, double xmin, double xmax, double ymin, double ymax) |
55 | 658 | function double clampAndProject(double x, double xmin, double xmax, double ymin, double ymax) | 663 | function double clampAndProject(double x, double xmin, double xmax, double ymin, double ymax) |
56 | 664 | Ubuntu.Components.Menu 1.3 UCMenu: Action | ||
57 | 665 | default property list<QtObject> data | ||
58 | 666 | function show(Qt.point pt) | ||
59 | 667 | function dismiss() | ||
60 | 668 | function appendObject(QtObject obj) | ||
61 | 669 | function insertObject(int index, QtObject obj) | ||
62 | 670 | function removeObject(QtObject obj) | ||
63 | 671 | Ubuntu.Components.MenuBar 1.3 UCMenuBar: QtObject | ||
64 | 672 | default property list<Menu> menus | ||
65 | 673 | function appendMenu(Menu menu) | ||
66 | 674 | function insertMenu(int index, Menu menu) | ||
67 | 675 | function removeMenu(Menu menu) | ||
68 | 676 | Ubuntu.Components.MenuGroup 1.3 UCMenuGroup: ActionList | ||
69 | 677 | Ubuntu.Components.Menus 1.3: QtObject | ||
70 | 678 | readonly property MenuBar menuBar | ||
71 | 679 | readonly property Menu parentMenu | ||
72 | 659 | Ubuntu.Components.MimeData 1.0 0.1 QQuickMimeData: QtObject | 680 | Ubuntu.Components.MimeData 1.0 0.1 QQuickMimeData: QtObject |
73 | 660 | property color color | 681 | property color color |
74 | 661 | property var data | 682 | property var data |
75 | 662 | 683 | ||
76 | === removed file 'src/Ubuntu/Components/1.2/ActionList.qml' | |||
77 | --- src/Ubuntu/Components/1.2/ActionList.qml 2016-05-25 12:48:10 +0000 | |||
78 | +++ src/Ubuntu/Components/1.2/ActionList.qml 1970-01-01 00:00:00 +0000 | |||
79 | @@ -1,47 +0,0 @@ | |||
80 | 1 | /* | ||
81 | 2 | * Copyright 2012 Canonical Ltd. | ||
82 | 3 | * | ||
83 | 4 | * This program is free software; you can redistribute it and/or modify | ||
84 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
85 | 6 | * the Free Software Foundation; version 3. | ||
86 | 7 | * | ||
87 | 8 | * This program is distributed in the hope that it will be useful, | ||
88 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
89 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
90 | 11 | * GNU Lesser General Public License for more details. | ||
91 | 12 | * | ||
92 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
93 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
94 | 15 | */ | ||
95 | 16 | |||
96 | 17 | import QtQuick 2.4 | ||
97 | 18 | import Ubuntu.Components 1.2 | ||
98 | 19 | |||
99 | 20 | /*! | ||
100 | 21 | \qmltype ActionList | ||
101 | 22 | \inqmlmodule Ubuntu.Components | ||
102 | 23 | \ingroup ubuntu | ||
103 | 24 | \brief List of \l Action items | ||
104 | 25 | */ | ||
105 | 26 | |||
106 | 27 | QtObject { | ||
107 | 28 | id: list | ||
108 | 29 | // internal objects using nested elements, | ||
109 | 30 | // which isn't allowed by QtObject; this fix makes this possible | ||
110 | 31 | /*! | ||
111 | 32 | Default property to allow adding of children. | ||
112 | 33 | \qmlproperty list<Action> children | ||
113 | 34 | \default | ||
114 | 35 | */ | ||
115 | 36 | default property alias children: list.actions | ||
116 | 37 | |||
117 | 38 | /*! | ||
118 | 39 | List of already defined actions when not defining them as children of the ActionList. | ||
119 | 40 | Note that when you set this property, the children of the ActionList will be ignored, | ||
120 | 41 | so do not set the list and define children. | ||
121 | 42 | |||
122 | 43 | The advantage of setting actions over using the children is that the same | ||
123 | 44 | \l Action items can be used in several sets of actions. | ||
124 | 45 | */ | ||
125 | 46 | property list<Action> actions | ||
126 | 47 | } | ||
127 | 48 | 0 | ||
128 | === removed file 'src/Ubuntu/Components/1.3/ActionList.qml' | |||
129 | --- src/Ubuntu/Components/1.3/ActionList.qml 2016-05-25 12:48:10 +0000 | |||
130 | +++ src/Ubuntu/Components/1.3/ActionList.qml 1970-01-01 00:00:00 +0000 | |||
131 | @@ -1,47 +0,0 @@ | |||
132 | 1 | /* | ||
133 | 2 | * Copyright 2012 Canonical Ltd. | ||
134 | 3 | * | ||
135 | 4 | * This program is free software; you can redistribute it and/or modify | ||
136 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
137 | 6 | * the Free Software Foundation; version 3. | ||
138 | 7 | * | ||
139 | 8 | * This program is distributed in the hope that it will be useful, | ||
140 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
141 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
142 | 11 | * GNU Lesser General Public License for more details. | ||
143 | 12 | * | ||
144 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
145 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
146 | 15 | */ | ||
147 | 16 | |||
148 | 17 | import QtQuick 2.4 | ||
149 | 18 | import Ubuntu.Components 1.3 | ||
150 | 19 | |||
151 | 20 | /*! | ||
152 | 21 | \qmltype ActionList | ||
153 | 22 | \inqmlmodule Ubuntu.Components | ||
154 | 23 | \ingroup ubuntu | ||
155 | 24 | \brief List of \l Action items | ||
156 | 25 | */ | ||
157 | 26 | |||
158 | 27 | QtObject { | ||
159 | 28 | id: list | ||
160 | 29 | // internal objects using nested elements, | ||
161 | 30 | // which isn't allowed by QtObject; this fix makes this possible | ||
162 | 31 | /*! | ||
163 | 32 | Default property to allow adding of children. | ||
164 | 33 | \qmlproperty list<Action> children | ||
165 | 34 | \default | ||
166 | 35 | */ | ||
167 | 36 | default property alias children: list.actions | ||
168 | 37 | |||
169 | 38 | /*! | ||
170 | 39 | List of already defined actions when not defining them as children of the ActionList. | ||
171 | 40 | Note that when you set this property, the children of the ActionList will be ignored, | ||
172 | 41 | so do not set the list and define children. | ||
173 | 42 | |||
174 | 43 | The advantage of setting actions over using the children is that the same | ||
175 | 44 | \l Action items can be used in several sets of actions. | ||
176 | 45 | */ | ||
177 | 46 | property list<Action> actions | ||
178 | 47 | } | ||
179 | 48 | 0 | ||
180 | === modified file 'src/Ubuntu/Components/ComponentModule.pro' | |||
181 | --- src/Ubuntu/Components/ComponentModule.pro 2016-02-16 11:39:32 +0000 | |||
182 | +++ src/Ubuntu/Components/ComponentModule.pro 2016-06-07 14:25:30 +0000 | |||
183 | @@ -25,7 +25,6 @@ | |||
184 | 25 | 25 | ||
185 | 26 | #1.2 | 26 | #1.2 |
186 | 27 | QML_FILES += 1.2/AbstractButton.qml \ | 27 | QML_FILES += 1.2/AbstractButton.qml \ |
187 | 28 | 1.2/ActionList.qml \ | ||
188 | 29 | 1.2/ActivityIndicator.qml \ | 28 | 1.2/ActivityIndicator.qml \ |
189 | 30 | 1.2/AnimatedItem.qml \ | 29 | 1.2/AnimatedItem.qml \ |
190 | 31 | 1.2/AppHeader.qml \ | 30 | 1.2/AppHeader.qml \ |
191 | @@ -78,7 +77,6 @@ | |||
192 | 78 | 77 | ||
193 | 79 | #1.3 | 78 | #1.3 |
194 | 80 | QML_FILES += 1.3/ActionBar.qml \ | 79 | QML_FILES += 1.3/ActionBar.qml \ |
195 | 81 | 1.3/ActionList.qml \ | ||
196 | 82 | 1.3/ActivityIndicator.qml \ | 80 | 1.3/ActivityIndicator.qml \ |
197 | 83 | 1.3/AdaptivePageLayout.qml \ | 81 | 1.3/AdaptivePageLayout.qml \ |
198 | 84 | 1.3/AnimatedItem.qml \ | 82 | 1.3/AnimatedItem.qml \ |
199 | 85 | 83 | ||
200 | === modified file 'src/Ubuntu/Components/plugin/plugin.cpp' | |||
201 | --- src/Ubuntu/Components/plugin/plugin.cpp 2016-04-20 15:00:27 +0000 | |||
202 | +++ src/Ubuntu/Components/plugin/plugin.cpp 2016-06-07 14:25:30 +0000 | |||
203 | @@ -78,9 +78,13 @@ | |||
204 | 78 | #include "ucpagetreenode.h" | 78 | #include "ucpagetreenode.h" |
205 | 79 | #include "ucmainviewbase.h" | 79 | #include "ucmainviewbase.h" |
206 | 80 | #include "ucperformancemonitor.h" | 80 | #include "ucperformancemonitor.h" |
207 | 81 | #include "ucmenu.h" | ||
208 | 82 | #include "ucmenubar.h" | ||
209 | 81 | #include "privates/frame.h" | 83 | #include "privates/frame.h" |
210 | 82 | #include "privates/ucpagewrapper.h" | 84 | #include "privates/ucpagewrapper.h" |
211 | 83 | #include "privates/appheaderbase.h" | 85 | #include "privates/appheaderbase.h" |
212 | 86 | #include "ucactionlist.h" | ||
213 | 87 | #include "ucexclusivegroup.h" | ||
214 | 84 | 88 | ||
215 | 85 | // From UbuntuGestures | 89 | // From UbuntuGestures |
216 | 86 | #include "private/ucswipearea_p.h" | 90 | #include "private/ucswipearea_p.h" |
217 | @@ -173,6 +177,7 @@ | |||
218 | 173 | qmlRegisterSimpleSingletonType<UCHaptics>(uri, major, minor, "Haptics"); | 177 | qmlRegisterSimpleSingletonType<UCHaptics>(uri, major, minor, "Haptics"); |
219 | 174 | qmlRegisterSimpleSingletonType<UCMathUtils>(uri, major, minor, "MathUtils"); | 178 | qmlRegisterSimpleSingletonType<UCMathUtils>(uri, major, minor, "MathUtils"); |
220 | 175 | qmlRegisterSimpleSingletonType<UbuntuToolkit::ColorUtils>(uri, major, minor, "ColorUtils"); | 179 | qmlRegisterSimpleSingletonType<UbuntuToolkit::ColorUtils>(uri, major, minor, "ColorUtils"); |
221 | 180 | qmlRegisterType<UCActionList>(uri, major, minor, "ActionList"); | ||
222 | 176 | } | 181 | } |
223 | 177 | 182 | ||
224 | 178 | void UbuntuComponentsPlugin::registerTypes(const char *uri) | 183 | void UbuntuComponentsPlugin::registerTypes(const char *uri) |
225 | @@ -235,6 +240,11 @@ | |||
226 | 235 | qmlRegisterType<UCPageTreeNode>(uri, 1, 3, "PageTreeNode"); | 240 | qmlRegisterType<UCPageTreeNode>(uri, 1, 3, "PageTreeNode"); |
227 | 236 | qmlRegisterType<UCPopupContext>(uri, 1, 3, "PopupContext"); | 241 | qmlRegisterType<UCPopupContext>(uri, 1, 3, "PopupContext"); |
228 | 237 | qmlRegisterType<UCMainViewBase>(uri, 1, 3, "MainViewBase"); | 242 | qmlRegisterType<UCMainViewBase>(uri, 1, 3, "MainViewBase"); |
229 | 243 | qmlRegisterType<UCMenu>(uri, 1, 3, "Menu"); | ||
230 | 244 | qmlRegisterType<UCMenuBar>(uri, 1, 3, "MenuBar"); | ||
231 | 245 | qmlRegisterUncreatableType<UCMenuAttached>(uri, 1, 3, "Menus", "Not instantiable"); | ||
232 | 246 | qmlRegisterType<UCMenuGroup>(uri, 1, 3, "MenuGroup"); | ||
233 | 247 | qmlRegisterType<UCExclusiveGroup>(uri, 1, 3, "ExclusiveGroup"); | ||
234 | 238 | } | 248 | } |
235 | 239 | 249 | ||
236 | 240 | void UbuntuComponentsPlugin::initializeContextProperties(QQmlEngine *engine) | 250 | void UbuntuComponentsPlugin::initializeContextProperties(QQmlEngine *engine) |
237 | 241 | 251 | ||
238 | === modified file 'src/Ubuntu/Components/plugin/plugin.pri' | |||
239 | --- src/Ubuntu/Components/plugin/plugin.pri 2016-04-01 05:30:24 +0000 | |||
240 | +++ src/Ubuntu/Components/plugin/plugin.pri 2016-06-07 14:25:30 +0000 | |||
241 | @@ -3,7 +3,7 @@ | |||
242 | 3 | PKGCONFIG += gio-2.0 dbus-1 libnih-dbus | 3 | PKGCONFIG += gio-2.0 dbus-1 libnih-dbus |
243 | 4 | } | 4 | } |
244 | 5 | 5 | ||
246 | 6 | QT *= core-private qml qml-private quick quick-private gui-private dbus svg UbuntuGestures UbuntuGestures_private UbuntuToolkit | 6 | QT *= core-private qml qml-private quick quick-private gui-private dbus svg platformsupport-private UbuntuGestures UbuntuGestures_private UbuntuToolkit |
247 | 7 | 7 | ||
248 | 8 | equals(QT_MAJOR_VERSION, 5):lessThan(QT_MINOR_VERSION, 2) { | 8 | equals(QT_MAJOR_VERSION, 5):lessThan(QT_MINOR_VERSION, 2) { |
249 | 9 | QT += v8-private | 9 | QT += v8-private |
250 | @@ -117,7 +117,13 @@ | |||
251 | 117 | $$PWD/privates/ucpagewrapperincubator_p.h \ | 117 | $$PWD/privates/ucpagewrapperincubator_p.h \ |
252 | 118 | $$PWD/privates/appheaderbase.h \ | 118 | $$PWD/privates/appheaderbase.h \ |
253 | 119 | $$PWD/label_p.h \ | 119 | $$PWD/label_p.h \ |
255 | 120 | $$PWD/ucbottomedgeregion_p.h | 120 | $$PWD/ucbottomedgeregion_p.h \ |
256 | 121 | $$PWD/ucactionlist.h \ | ||
257 | 122 | $$PWD/ucmenu.h \ | ||
258 | 123 | $$PWD/ucmenu_p.h \ | ||
259 | 124 | $$PWD/ucmenubar.h \ | ||
260 | 125 | $$PWD/ucmenubar_p.h \ | ||
261 | 126 | $$PWD/ucexclusivegroup.h | ||
262 | 121 | 127 | ||
263 | 122 | SOURCES += $$PWD/plugin.cpp \ | 128 | SOURCES += $$PWD/plugin.cpp \ |
264 | 123 | $$PWD/uctheme.cpp \ | 129 | $$PWD/uctheme.cpp \ |
265 | @@ -194,7 +200,11 @@ | |||
266 | 194 | $$PWD/privates/frame.cpp \ | 200 | $$PWD/privates/frame.cpp \ |
267 | 195 | $$PWD/privates/ucpagewrapper.cpp \ | 201 | $$PWD/privates/ucpagewrapper.cpp \ |
268 | 196 | $$PWD/privates/ucpagewrapperincubator.cpp \ | 202 | $$PWD/privates/ucpagewrapperincubator.cpp \ |
270 | 197 | $$PWD/privates/appheaderbase.cpp | 203 | $$PWD/privates/appheaderbase.cpp \ |
271 | 204 | $$PWD/ucactionlist.cpp \ | ||
272 | 205 | $$PWD/ucmenu.cpp \ | ||
273 | 206 | $$PWD/ucmenubar.cpp \ | ||
274 | 207 | $$PWD/ucexclusivegroup.cpp | ||
275 | 198 | 208 | ||
276 | 199 | # adapters | 209 | # adapters |
277 | 200 | SOURCES += $$PWD/adapters/alarmsadapter_organizer.cpp | 210 | SOURCES += $$PWD/adapters/alarmsadapter_organizer.cpp |
278 | 201 | 211 | ||
279 | === modified file 'src/Ubuntu/Components/plugin/ucaction.cpp' | |||
280 | --- src/Ubuntu/Components/plugin/ucaction.cpp 2016-05-25 12:48:10 +0000 | |||
281 | +++ src/Ubuntu/Components/plugin/ucaction.cpp 2016-06-07 14:25:30 +0000 | |||
282 | @@ -17,6 +17,7 @@ | |||
283 | 17 | #include "ucaction.h" | 17 | #include "ucaction.h" |
284 | 18 | #include "quickutils.h" | 18 | #include "quickutils.h" |
285 | 19 | #include "ucactioncontext.h" | 19 | #include "ucactioncontext.h" |
286 | 20 | #include "ucexclusivegroup.h" | ||
287 | 20 | 21 | ||
288 | 21 | #include <QtDebug> | 22 | #include <QtDebug> |
289 | 22 | #include <QtQml/QQmlInfo> | 23 | #include <QtQml/QQmlInfo> |
290 | @@ -248,43 +249,6 @@ | |||
291 | 248 | * \endqml | 249 | * \endqml |
292 | 249 | */ | 250 | */ |
293 | 250 | 251 | ||
294 | 251 | /*! | ||
295 | 252 | * \qmlproperty enum Action::parameterType | ||
296 | 253 | * Type of the parameter passed to \l trigger and \l triggered. | ||
297 | 254 | * Type is an enumeration: | ||
298 | 255 | * \list | ||
299 | 256 | * \li \b Action.None: No paramater. (default) | ||
300 | 257 | * \li \b Action.String: String parameter. | ||
301 | 258 | * \li \b Action.Integer: Integer parameter. | ||
302 | 259 | * \li \b Action.Bool: Boolean parameter. | ||
303 | 260 | * \li \b Action.Real: Single precision floating point parameter. | ||
304 | 261 | * \li \b Action.Object: The parameter is an object. | ||
305 | 262 | * \endlist | ||
306 | 263 | * \qml | ||
307 | 264 | * Action { | ||
308 | 265 | * id: action | ||
309 | 266 | * parameterType: Action.String | ||
310 | 267 | * onTriggered: { | ||
311 | 268 | * // value arguments now contain strings | ||
312 | 269 | * console.log(value); | ||
313 | 270 | * } | ||
314 | 271 | * Component.onCompleted: action.trigger("Hello World") | ||
315 | 272 | * } | ||
316 | 273 | * \endqml | ||
317 | 274 | */ | ||
318 | 275 | |||
319 | 276 | /*! | ||
320 | 277 | * \qmlproperty bool Action::enabled | ||
321 | 278 | * If set to false the action can not be triggered. Components visualizing the | ||
322 | 279 | * action migth either hide the action or make it insensitive. However visibility | ||
323 | 280 | * can be controlled separately using the \l visible property. | ||
324 | 281 | */ | ||
325 | 282 | |||
326 | 283 | /*! | ||
327 | 284 | * \qmlproperty bool Action::visible | ||
328 | 285 | * Specifies whether the action is visible to the user. Defaults to true. | ||
329 | 286 | */ | ||
330 | 287 | |||
331 | 288 | UCAction::UCAction(QObject *parent) | 252 | UCAction::UCAction(QObject *parent) |
332 | 289 | : QObject(parent) | 253 | : QObject(parent) |
333 | 290 | , m_itemHint(Q_NULLPTR) | 254 | , m_itemHint(Q_NULLPTR) |
334 | @@ -293,12 +257,15 @@ | |||
335 | 293 | , m_enabled(true) | 257 | , m_enabled(true) |
336 | 294 | , m_visible(true) | 258 | , m_visible(true) |
337 | 295 | , m_published(false) | 259 | , m_published(false) |
338 | 260 | , m_exclusiveGroup(Q_NULLPTR) | ||
339 | 296 | { | 261 | { |
340 | 297 | generateName(); | 262 | generateName(); |
341 | 298 | // FIXME: we need QInputDeviceInfo to detect the keyboard attechment | 263 | // FIXME: we need QInputDeviceInfo to detect the keyboard attechment |
342 | 299 | // https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1276808 | 264 | // https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1276808 |
343 | 300 | connect(QuickUtils::instance(), &QuickUtils::keyboardAttachedChanged, | 265 | connect(QuickUtils::instance(), &QuickUtils::keyboardAttachedChanged, |
344 | 301 | this, &UCAction::onKeyboardAttached); | 266 | this, &UCAction::onKeyboardAttached); |
345 | 267 | |||
346 | 268 | connect(this, &UCAction::triggered, this, &UCAction::setState); | ||
347 | 302 | } | 269 | } |
348 | 303 | 270 | ||
349 | 304 | UCAction::~UCAction() | 271 | UCAction::~UCAction() |
350 | @@ -434,6 +401,100 @@ | |||
351 | 434 | Q_EMIT shortcutChanged(); | 401 | Q_EMIT shortcutChanged(); |
352 | 435 | } | 402 | } |
353 | 436 | 403 | ||
354 | 404 | /*! | ||
355 | 405 | * \qmlproperty bool Action::visible | ||
356 | 406 | * Specifies whether the action is visible to the user. Defaults to true. | ||
357 | 407 | */ | ||
358 | 408 | void UCAction::setVisible(bool visible) | ||
359 | 409 | { | ||
360 | 410 | if (m_visible == visible) { | ||
361 | 411 | return; | ||
362 | 412 | } | ||
363 | 413 | m_visible = visible; | ||
364 | 414 | Q_EMIT visibleChanged(); | ||
365 | 415 | } | ||
366 | 416 | |||
367 | 417 | /*! | ||
368 | 418 | * \qmlproperty bool Action::enabled | ||
369 | 419 | * If set to false the action can not be triggered. Components visualizing the | ||
370 | 420 | * action migth either hide the action or make it insensitive. However visibility | ||
371 | 421 | * can be controlled separately using the \l visible property. | ||
372 | 422 | */ | ||
373 | 423 | void UCAction::setEnabled(bool enabled) | ||
374 | 424 | { | ||
375 | 425 | if (m_enabled == enabled) { | ||
376 | 426 | return; | ||
377 | 427 | } | ||
378 | 428 | m_enabled = enabled; | ||
379 | 429 | Q_EMIT enabledChanged(); | ||
380 | 430 | |||
381 | 431 | } | ||
382 | 432 | |||
383 | 433 | /*! | ||
384 | 434 | * \qmlproperty enum Action::parameterType | ||
385 | 435 | * Type of the parameter passed to \l trigger and \l triggered. | ||
386 | 436 | * Type is an enumeration: | ||
387 | 437 | * \list | ||
388 | 438 | * \li \b Action.None: No paramater. (default) | ||
389 | 439 | * \li \b Action.String: String parameter. | ||
390 | 440 | * \li \b Action.Integer: Integer parameter. | ||
391 | 441 | * \li \b Action.Bool: Boolean parameter. | ||
392 | 442 | * \li \b Action.Real: Single precision floating point parameter. | ||
393 | 443 | * \li \b Action.Object: The parameter is an object. | ||
394 | 444 | * \endlist | ||
395 | 445 | * \qml | ||
396 | 446 | * Action { | ||
397 | 447 | * id: action | ||
398 | 448 | * parameterType: Action.String | ||
399 | 449 | * onTriggered: { | ||
400 | 450 | * // value arguments now contain strings | ||
401 | 451 | * console.log(value); | ||
402 | 452 | * } | ||
403 | 453 | * Component.onCompleted: action.trigger("Hello World") | ||
404 | 454 | * } | ||
405 | 455 | * \endqml | ||
406 | 456 | */ | ||
407 | 457 | void UCAction::setParameterType(UCAction::Type type) | ||
408 | 458 | { | ||
409 | 459 | if (m_parameterType == type) { | ||
410 | 460 | return; | ||
411 | 461 | } | ||
412 | 462 | m_parameterType = type; | ||
413 | 463 | Q_EMIT parameterTypeChanged(); | ||
414 | 464 | } | ||
415 | 465 | |||
416 | 466 | void UCAction::setState(const QVariant &state) | ||
417 | 467 | { | ||
418 | 468 | if (m_state == state) { | ||
419 | 469 | return; | ||
420 | 470 | } | ||
421 | 471 | m_state = state; | ||
422 | 472 | Q_EMIT stateChanged(); | ||
423 | 473 | } | ||
424 | 474 | |||
425 | 475 | UCExclusiveGroup *UCAction::exclusiveGroup() const | ||
426 | 476 | { | ||
427 | 477 | return m_exclusiveGroup; | ||
428 | 478 | } | ||
429 | 479 | |||
430 | 480 | void UCAction::setExclusiveGroup(UCExclusiveGroup *exclusiveGroup) | ||
431 | 481 | { | ||
432 | 482 | if (m_exclusiveGroup == exclusiveGroup) { | ||
433 | 483 | return; | ||
434 | 484 | } | ||
435 | 485 | |||
436 | 486 | if (m_exclusiveGroup) { | ||
437 | 487 | m_exclusiveGroup->removeAction(this); | ||
438 | 488 | } | ||
439 | 489 | |||
440 | 490 | m_exclusiveGroup = exclusiveGroup; | ||
441 | 491 | |||
442 | 492 | if (m_exclusiveGroup) { | ||
443 | 493 | m_exclusiveGroup->addAction(this); | ||
444 | 494 | } | ||
445 | 495 | Q_EMIT exclusiveGroupChanged(); | ||
446 | 496 | } | ||
447 | 497 | |||
448 | 437 | bool UCAction::event(QEvent *event) | 498 | bool UCAction::event(QEvent *event) |
449 | 438 | { | 499 | { |
450 | 439 | if (event->type() != QEvent::Shortcut) | 500 | if (event->type() != QEvent::Shortcut) |
451 | @@ -473,6 +534,11 @@ | |||
452 | 473 | if (!m_enabled) { | 534 | if (!m_enabled) { |
453 | 474 | return; | 535 | return; |
454 | 475 | } | 536 | } |
455 | 537 | |||
456 | 538 | if (m_exclusiveGroup && !m_exclusiveGroup->checkValidTrigger(this, value)) { | ||
457 | 539 | return; | ||
458 | 540 | } | ||
459 | 541 | |||
460 | 476 | if (!isValidType(value.type())) { | 542 | if (!isValidType(value.type())) { |
461 | 477 | Q_EMIT triggered(QVariant()); | 543 | Q_EMIT triggered(QVariant()); |
462 | 478 | } else { | 544 | } else { |
463 | 479 | 545 | ||
464 | === modified file 'src/Ubuntu/Components/plugin/ucaction.h' | |||
465 | --- src/Ubuntu/Components/plugin/ucaction.h 2016-04-28 11:19:46 +0000 | |||
466 | +++ src/Ubuntu/Components/plugin/ucaction.h 2016-06-07 14:25:30 +0000 | |||
467 | @@ -49,7 +49,7 @@ | |||
468 | 49 | 49 | ||
469 | 50 | class QQmlComponent; | 50 | class QQmlComponent; |
470 | 51 | class QQuickItem; | 51 | class QQuickItem; |
472 | 52 | class UCActionAttached; | 52 | class UCExclusiveGroup; |
473 | 53 | class UCAction : public QObject | 53 | class UCAction : public QObject |
474 | 54 | { | 54 | { |
475 | 55 | Q_OBJECT | 55 | Q_OBJECT |
476 | @@ -58,19 +58,21 @@ | |||
477 | 58 | Q_ENUMS(Type) | 58 | Q_ENUMS(Type) |
478 | 59 | Q_PROPERTY(QString name MEMBER m_name WRITE setName NOTIFY nameChanged) | 59 | Q_PROPERTY(QString name MEMBER m_name WRITE setName NOTIFY nameChanged) |
479 | 60 | Q_PROPERTY(QString text READ text WRITE setText RESET resetText NOTIFY textChanged) | 60 | Q_PROPERTY(QString text READ text WRITE setText RESET resetText NOTIFY textChanged) |
481 | 61 | Q_PROPERTY(QString iconName MEMBER m_iconName WRITE setIconName NOTIFY iconNameChanged) | 61 | Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged) |
482 | 62 | Q_PROPERTY(QString description MEMBER m_description NOTIFY descriptionChanged) | 62 | Q_PROPERTY(QString description MEMBER m_description NOTIFY descriptionChanged) |
483 | 63 | Q_PROPERTY(QString keywords MEMBER m_keywords NOTIFY keywordsChanged) | 63 | Q_PROPERTY(QString keywords MEMBER m_keywords NOTIFY keywordsChanged) |
486 | 64 | Q_PROPERTY(bool enabled MEMBER m_enabled NOTIFY enabledChanged) | 64 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) |
487 | 65 | Q_PROPERTY(Type parameterType MEMBER m_parameterType NOTIFY parameterTypeChanged) | 65 | Q_PROPERTY(Type parameterType READ parameterType WRITE setParameterType NOTIFY parameterTypeChanged) |
488 | 66 | Q_PROPERTY(QVariant state READ state WRITE setState NOTIFY stateChanged REVISION 1) | ||
489 | 67 | Q_PROPERTY(UCExclusiveGroup* exclusiveGroup READ exclusiveGroup WRITE setExclusiveGroup NOTIFY exclusiveGroupChanged REVISION 1) | ||
490 | 66 | 68 | ||
491 | 67 | // Toolkit Actions API | 69 | // Toolkit Actions API |
494 | 68 | Q_PROPERTY(QUrl iconSource MEMBER m_iconSource WRITE setIconSource NOTIFY iconSourceChanged) | 70 | Q_PROPERTY(QUrl iconSource READ iconSource WRITE setIconSource NOTIFY iconSourceChanged) |
495 | 69 | Q_PROPERTY(bool visible MEMBER m_visible NOTIFY visibleChanged) | 71 | Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged) |
496 | 70 | Q_PROPERTY(QQmlComponent *itemHint MEMBER m_itemHint WRITE setItemHint) | 72 | Q_PROPERTY(QQmlComponent *itemHint MEMBER m_itemHint WRITE setItemHint) |
497 | 71 | 73 | ||
498 | 72 | // QtQuickControls.Action | 74 | // QtQuickControls.Action |
500 | 73 | Q_PROPERTY(QVariant shortcut MEMBER m_shortcut WRITE setShortcut RESET resetShortcut NOTIFY shortcutChanged REVISION 1) | 75 | Q_PROPERTY(QVariant shortcut READ shortcut WRITE setShortcut RESET resetShortcut NOTIFY shortcutChanged REVISION 1) |
501 | 74 | public: | 76 | public: |
502 | 75 | enum Type { | 77 | enum Type { |
503 | 76 | None, | 78 | None, |
504 | @@ -104,11 +106,24 @@ | |||
505 | 104 | QString text(); | 106 | QString text(); |
506 | 105 | void setText(const QString &text); | 107 | void setText(const QString &text); |
507 | 106 | void resetText(); | 108 | void resetText(); |
508 | 109 | QString iconName() const { return m_iconName; } | ||
509 | 107 | void setIconName(const QString &name); | 110 | void setIconName(const QString &name); |
510 | 111 | QUrl iconSource() const { return m_iconSource; } | ||
511 | 108 | void setIconSource(const QUrl &url); | 112 | void setIconSource(const QUrl &url); |
512 | 109 | void setItemHint(QQmlComponent *); | 113 | void setItemHint(QQmlComponent *); |
513 | 114 | QVariant shortcut() const { return m_shortcut; } | ||
514 | 110 | void setShortcut(const QVariant&); | 115 | void setShortcut(const QVariant&); |
515 | 111 | void resetShortcut(); | 116 | void resetShortcut(); |
516 | 117 | bool visible() const { return m_visible; } | ||
517 | 118 | void setVisible(bool visible); | ||
518 | 119 | void setEnabled(bool enabled); | ||
519 | 120 | |||
520 | 121 | void setParameterType(Type type); | ||
521 | 122 | Type parameterType() const { return m_parameterType; } | ||
522 | 123 | QVariant state() const { return m_state; } | ||
523 | 124 | |||
524 | 125 | UCExclusiveGroup *exclusiveGroup() const; | ||
525 | 126 | void setExclusiveGroup(UCExclusiveGroup *exclusiveGroup); | ||
526 | 112 | 127 | ||
527 | 113 | Q_SIGNALS: | 128 | Q_SIGNALS: |
528 | 114 | void nameChanged(); | 129 | void nameChanged(); |
529 | @@ -121,10 +136,13 @@ | |||
530 | 121 | void iconSourceChanged(); | 136 | void iconSourceChanged(); |
531 | 122 | void visibleChanged(); | 137 | void visibleChanged(); |
532 | 123 | void shortcutChanged(); | 138 | void shortcutChanged(); |
533 | 139 | void stateChanged(); | ||
534 | 140 | void exclusiveGroupChanged(); | ||
535 | 124 | void triggered(const QVariant &value); | 141 | void triggered(const QVariant &value); |
536 | 125 | 142 | ||
537 | 126 | public Q_SLOTS: | 143 | public Q_SLOTS: |
538 | 127 | void trigger(const QVariant &value = QVariant()); | 144 | void trigger(const QVariant &value = QVariant()); |
539 | 145 | void setState(const QVariant&); | ||
540 | 128 | 146 | ||
541 | 129 | private: | 147 | private: |
542 | 130 | QPODVector<QQuickItem*, 4> m_owningItems; | 148 | QPODVector<QQuickItem*, 4> m_owningItems; |
543 | @@ -142,6 +160,8 @@ | |||
544 | 142 | bool m_enabled:1; | 160 | bool m_enabled:1; |
545 | 143 | bool m_visible:1; | 161 | bool m_visible:1; |
546 | 144 | bool m_published:1; | 162 | bool m_published:1; |
547 | 163 | UCExclusiveGroup *m_exclusiveGroup; | ||
548 | 164 | QVariant m_state; | ||
549 | 145 | 165 | ||
550 | 146 | friend class UCActionContext; | 166 | friend class UCActionContext; |
551 | 147 | friend class UCActionItem; | 167 | friend class UCActionItem; |
552 | 148 | 168 | ||
553 | === added file 'src/Ubuntu/Components/plugin/ucactionlist.cpp' | |||
554 | --- src/Ubuntu/Components/plugin/ucactionlist.cpp 1970-01-01 00:00:00 +0000 | |||
555 | +++ src/Ubuntu/Components/plugin/ucactionlist.cpp 2016-06-07 14:25:30 +0000 | |||
556 | @@ -0,0 +1,104 @@ | |||
557 | 1 | /* | ||
558 | 2 | * Copyright 2016 Canonical Ltd. | ||
559 | 3 | * | ||
560 | 4 | * This program is free software; you can redistribute it and/or modify | ||
561 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
562 | 6 | * the Free Software Foundation; version 3. | ||
563 | 7 | * | ||
564 | 8 | * This program is distributed in the hope that it will be useful, | ||
565 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
566 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
567 | 11 | * GNU Lesser General Public License for more details. | ||
568 | 12 | * | ||
569 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
570 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
571 | 15 | */ | ||
572 | 16 | |||
573 | 17 | #include "ucactionlist.h" | ||
574 | 18 | #include "ucaction.h" | ||
575 | 19 | |||
576 | 20 | /*! | ||
577 | 21 | * \qmltype ActionList | ||
578 | 22 | * \inqmlmodule Ubuntu.Components | ||
579 | 23 | * \ingroup ubuntu | ||
580 | 24 | * \brief List of \l Action items | ||
581 | 25 | */ | ||
582 | 26 | UCActionList::UCActionList(QObject *parent) | ||
583 | 27 | : QObject(parent) | ||
584 | 28 | { | ||
585 | 29 | } | ||
586 | 30 | |||
587 | 31 | /*! | ||
588 | 32 | * \qmlmethod ActionList::addAction(Action action) | ||
589 | 33 | * \deprecated | ||
590 | 34 | * Adds an Action to the context programatically. | ||
591 | 35 | */ | ||
592 | 36 | void UCActionList::addAction(UCAction *action) | ||
593 | 37 | { | ||
594 | 38 | if (m_actions.contains(action)) { | ||
595 | 39 | return; | ||
596 | 40 | } | ||
597 | 41 | m_actions.append(action); | ||
598 | 42 | Q_EMIT added(action); | ||
599 | 43 | } | ||
600 | 44 | |||
601 | 45 | /*! | ||
602 | 46 | * \qmlmethod ActionList::removeAction(Action action) | ||
603 | 47 | * \deprecated | ||
604 | 48 | * Removes an action from the context programatically. | ||
605 | 49 | */ | ||
606 | 50 | void UCActionList::removeAction(UCAction *action) | ||
607 | 51 | { | ||
608 | 52 | if (!action) { | ||
609 | 53 | return; | ||
610 | 54 | } | ||
611 | 55 | if (m_actions.removeOne(action)) { | ||
612 | 56 | Q_EMIT removed(action); | ||
613 | 57 | } | ||
614 | 58 | } | ||
615 | 59 | |||
616 | 60 | /*! | ||
617 | 61 | |||
618 | 62 | * \qmlproperty list<Action> ActionContext::actions | ||
619 | 63 | * \default | ||
620 | 64 | * List of Actions in this ActionContext | ||
621 | 65 | * Note that when you set this property, the children of the ActionList will be ignored, | ||
622 | 66 | * so do not set the list and define children. | ||
623 | 67 | * | ||
624 | 68 | * The advantage of setting actions over using the children is that the same | ||
625 | 69 | * \l Action items can be used in several sets of actions. | ||
626 | 70 | */ | ||
627 | 71 | QQmlListProperty<UCAction> UCActionList::actions() | ||
628 | 72 | { | ||
629 | 73 | return QQmlListProperty<UCAction>(this, 0, UCActionList::append, UCActionList::count, 0, UCActionList::clear); | ||
630 | 74 | } | ||
631 | 75 | |||
632 | 76 | const QList<UCAction*> &UCActionList::list() const | ||
633 | 77 | { | ||
634 | 78 | return m_actions; | ||
635 | 79 | } | ||
636 | 80 | |||
637 | 81 | void UCActionList::append(QQmlListProperty<UCAction> *list, UCAction *action) | ||
638 | 82 | { | ||
639 | 83 | UCActionList *actionList = qobject_cast<UCActionList*>(list->object); | ||
640 | 84 | if (actionList) { | ||
641 | 85 | actionList->addAction(action); | ||
642 | 86 | } | ||
643 | 87 | } | ||
644 | 88 | |||
645 | 89 | void UCActionList::clear(QQmlListProperty<UCAction> *list) | ||
646 | 90 | { | ||
647 | 91 | UCActionList *actionList = qobject_cast<UCActionList*>(list->object); | ||
648 | 92 | if (actionList) { | ||
649 | 93 | actionList->m_actions.clear(); | ||
650 | 94 | } | ||
651 | 95 | } | ||
652 | 96 | |||
653 | 97 | int UCActionList::count(QQmlListProperty<UCAction> *list) | ||
654 | 98 | { | ||
655 | 99 | UCActionList *actionList = qobject_cast<UCActionList*>(list->object); | ||
656 | 100 | if (actionList) { | ||
657 | 101 | return actionList->m_actions.count(); | ||
658 | 102 | } | ||
659 | 103 | return 0; | ||
660 | 104 | } | ||
661 | 0 | 105 | ||
662 | === added file 'src/Ubuntu/Components/plugin/ucactionlist.h' | |||
663 | --- src/Ubuntu/Components/plugin/ucactionlist.h 1970-01-01 00:00:00 +0000 | |||
664 | +++ src/Ubuntu/Components/plugin/ucactionlist.h 2016-06-07 14:25:30 +0000 | |||
665 | @@ -0,0 +1,53 @@ | |||
666 | 1 | /* | ||
667 | 2 | * Copyright 2016 Canonical Ltd. | ||
668 | 3 | * | ||
669 | 4 | * This program is free software; you can redistribute it and/or modify | ||
670 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
671 | 6 | * the Free Software Foundation; version 3. | ||
672 | 7 | * | ||
673 | 8 | * This program is distributed in the hope that it will be useful, | ||
674 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
675 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
676 | 11 | * GNU Lesser General Public License for more details. | ||
677 | 12 | * | ||
678 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
679 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
680 | 15 | */ | ||
681 | 16 | |||
682 | 17 | #ifndef UCACTIONLIST_H | ||
683 | 18 | #define UCACTIONLIST_H | ||
684 | 19 | |||
685 | 20 | #include <QObject> | ||
686 | 21 | #include <QtQml/QQmlListProperty> | ||
687 | 22 | |||
688 | 23 | class UCAction; | ||
689 | 24 | |||
690 | 25 | class UCActionList : public QObject | ||
691 | 26 | { | ||
692 | 27 | Q_OBJECT | ||
693 | 28 | Q_PROPERTY(QQmlListProperty<UCAction> actions READ actions) | ||
694 | 29 | Q_CLASSINFO("DefaultProperty", "actions") | ||
695 | 30 | public: | ||
696 | 31 | explicit UCActionList(QObject *parent = 0); | ||
697 | 32 | |||
698 | 33 | QQmlListProperty<UCAction> actions(); | ||
699 | 34 | |||
700 | 35 | const QList<UCAction*> &list() const; | ||
701 | 36 | |||
702 | 37 | public Q_SLOTS: | ||
703 | 38 | void addAction(UCAction *action); | ||
704 | 39 | void removeAction(UCAction *action); | ||
705 | 40 | |||
706 | 41 | Q_SIGNALS: | ||
707 | 42 | void added(UCAction *action); | ||
708 | 43 | void removed(UCAction *action); | ||
709 | 44 | |||
710 | 45 | protected: | ||
711 | 46 | QList<UCAction*> m_actions; | ||
712 | 47 | |||
713 | 48 | static void append(QQmlListProperty<UCAction> *list, UCAction *action); | ||
714 | 49 | static void clear(QQmlListProperty<UCAction> *list); | ||
715 | 50 | static int count(QQmlListProperty<UCAction> *list); | ||
716 | 51 | }; | ||
717 | 52 | |||
718 | 53 | #endif // UCACTIONLIST_H | ||
719 | 0 | 54 | ||
720 | === added file 'src/Ubuntu/Components/plugin/ucexclusivegroup.cpp' | |||
721 | --- src/Ubuntu/Components/plugin/ucexclusivegroup.cpp 1970-01-01 00:00:00 +0000 | |||
722 | +++ src/Ubuntu/Components/plugin/ucexclusivegroup.cpp 2016-06-07 14:25:30 +0000 | |||
723 | @@ -0,0 +1,106 @@ | |||
724 | 1 | /* | ||
725 | 2 | * Copyright 2016 Canonical Ltd. | ||
726 | 3 | * | ||
727 | 4 | * This program is free software; you can redistribute it and/or modify | ||
728 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
729 | 6 | * the Free Software Foundation; version 3. | ||
730 | 7 | * | ||
731 | 8 | * This program is distributed in the hope that it will be useful, | ||
732 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
733 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
734 | 11 | * GNU Lesser General Public License for more details. | ||
735 | 12 | * | ||
736 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
737 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
738 | 15 | * | ||
739 | 16 | */ | ||
740 | 17 | |||
741 | 18 | #include "ucexclusivegroup.h" | ||
742 | 19 | #include "ucaction.h" | ||
743 | 20 | |||
744 | 21 | UCExclusiveGroup::UCExclusiveGroup(QObject *parent) | ||
745 | 22 | : UCActionList(parent) | ||
746 | 23 | , m_entranceGuard(false) | ||
747 | 24 | { | ||
748 | 25 | connect(this, &UCActionList::added, this, &UCExclusiveGroup::onActionAdded); | ||
749 | 26 | connect(this, &UCActionList::removed, this, &UCExclusiveGroup::onActionRemoved); | ||
750 | 27 | } | ||
751 | 28 | |||
752 | 29 | void UCExclusiveGroup::onActionAdded(UCAction *action) | ||
753 | 30 | { | ||
754 | 31 | action->setExclusiveGroup(this); | ||
755 | 32 | connect(action, &UCAction::stateChanged, this, [this, action]() { stateChanged(action); }); | ||
756 | 33 | } | ||
757 | 34 | |||
758 | 35 | void UCExclusiveGroup::onActionRemoved(UCAction *action) | ||
759 | 36 | { | ||
760 | 37 | action->setExclusiveGroup(nullptr); | ||
761 | 38 | disconnect(action, &UCAction::stateChanged, this, 0); | ||
762 | 39 | } | ||
763 | 40 | |||
764 | 41 | void UCExclusiveGroup::stateChanged(UCAction* action) | ||
765 | 42 | { | ||
766 | 43 | if (m_entranceGuard) return; | ||
767 | 44 | m_entranceGuard = true; | ||
768 | 45 | |||
769 | 46 | if (action->state().type() != QVariant::Bool) { | ||
770 | 47 | m_entranceGuard = false; | ||
771 | 48 | return; | ||
772 | 49 | } | ||
773 | 50 | |||
774 | 51 | Q_FOREACH(UCAction* fromList, list()) { | ||
775 | 52 | if (fromList->parameterType() != UCAction::Bool) { | ||
776 | 53 | continue; | ||
777 | 54 | } | ||
778 | 55 | |||
779 | 56 | if (fromList != action && fromList->state().toBool() == true) { | ||
780 | 57 | fromList->trigger(false); | ||
781 | 58 | } | ||
782 | 59 | } | ||
783 | 60 | |||
784 | 61 | if (action->state().toBool() == true) { | ||
785 | 62 | setSelected(action); | ||
786 | 63 | } else { | ||
787 | 64 | setSelected(nullptr); | ||
788 | 65 | } | ||
789 | 66 | |||
790 | 67 | m_entranceGuard = false; | ||
791 | 68 | } | ||
792 | 69 | |||
793 | 70 | void UCExclusiveGroup::setSelected(UCAction *action) | ||
794 | 71 | { | ||
795 | 72 | if (m_selected != action) { | ||
796 | 73 | if (action) { | ||
797 | 74 | m_selected = action; | ||
798 | 75 | } else { | ||
799 | 76 | m_selected.clear(); | ||
800 | 77 | } | ||
801 | 78 | Q_EMIT selectedChanged(); | ||
802 | 79 | } | ||
803 | 80 | } | ||
804 | 81 | |||
805 | 82 | UCAction *UCExclusiveGroup::selected() const | ||
806 | 83 | { | ||
807 | 84 | return m_selected; | ||
808 | 85 | } | ||
809 | 86 | |||
810 | 87 | bool UCExclusiveGroup::checkValidTrigger(UCAction *action, const QVariant &value) | ||
811 | 88 | { | ||
812 | 89 | // deselect others. | ||
813 | 90 | if (value.type() == QVariant::Bool && value.toBool() == false) { | ||
814 | 91 | |||
815 | 92 | int trueCount = 0; | ||
816 | 93 | Q_FOREACH(UCAction* fromList, list()) { | ||
817 | 94 | if (fromList->parameterType() != UCAction::Bool || | ||
818 | 95 | action == fromList) { | ||
819 | 96 | continue; | ||
820 | 97 | } | ||
821 | 98 | trueCount += fromList->state().toBool(); | ||
822 | 99 | } | ||
823 | 100 | |||
824 | 101 | if (trueCount == 0) { | ||
825 | 102 | return false; | ||
826 | 103 | } | ||
827 | 104 | } | ||
828 | 105 | return true; | ||
829 | 106 | } | ||
830 | 0 | 107 | ||
831 | === added file 'src/Ubuntu/Components/plugin/ucexclusivegroup.h' | |||
832 | --- src/Ubuntu/Components/plugin/ucexclusivegroup.h 1970-01-01 00:00:00 +0000 | |||
833 | +++ src/Ubuntu/Components/plugin/ucexclusivegroup.h 2016-06-07 14:25:30 +0000 | |||
834 | @@ -0,0 +1,53 @@ | |||
835 | 1 | /* | ||
836 | 2 | * Copyright 2016 Canonical Ltd. | ||
837 | 3 | * | ||
838 | 4 | * This program is free software; you can redistribute it and/or modify | ||
839 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
840 | 6 | * the Free Software Foundation; version 3. | ||
841 | 7 | * | ||
842 | 8 | * This program is distributed in the hope that it will be useful, | ||
843 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
844 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
845 | 11 | * GNU Lesser General Public License for more details. | ||
846 | 12 | * | ||
847 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
848 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
849 | 15 | * | ||
850 | 16 | */ | ||
851 | 17 | |||
852 | 18 | #ifndef UCEXCLUSIVEGROUP_H | ||
853 | 19 | #define UCEXCLUSIVEGROUP_H | ||
854 | 20 | |||
855 | 21 | #include "ucactionlist.h" | ||
856 | 22 | #include "ucaction.h" | ||
857 | 23 | #include <QQmlParserStatus> | ||
858 | 24 | |||
859 | 25 | class UCExclusiveGroup : public UCActionList | ||
860 | 26 | { | ||
861 | 27 | Q_OBJECT | ||
862 | 28 | Q_PROPERTY(UCAction* selected READ selected NOTIFY selectedChanged) | ||
863 | 29 | |||
864 | 30 | public: | ||
865 | 31 | explicit UCExclusiveGroup(QObject *parent = 0); | ||
866 | 32 | |||
867 | 33 | UCAction* selected() const; | ||
868 | 34 | |||
869 | 35 | bool checkValidTrigger(UCAction* action, const QVariant& value); | ||
870 | 36 | |||
871 | 37 | Q_SIGNALS: | ||
872 | 38 | void selectedChanged(); | ||
873 | 39 | |||
874 | 40 | |||
875 | 41 | protected Q_SLOTS: | ||
876 | 42 | void onActionAdded(UCAction* action); | ||
877 | 43 | void onActionRemoved(UCAction* action); | ||
878 | 44 | |||
879 | 45 | private: | ||
880 | 46 | void stateChanged(UCAction* action); | ||
881 | 47 | void setSelected(UCAction* action); | ||
882 | 48 | |||
883 | 49 | QPointer<UCAction> m_selected; | ||
884 | 50 | bool m_entranceGuard; | ||
885 | 51 | }; | ||
886 | 52 | |||
887 | 53 | #endif // UCEXCLUSIVEGROUP_H | ||
888 | 0 | 54 | ||
889 | === added file 'src/Ubuntu/Components/plugin/ucmenu.cpp' | |||
890 | --- src/Ubuntu/Components/plugin/ucmenu.cpp 1970-01-01 00:00:00 +0000 | |||
891 | +++ src/Ubuntu/Components/plugin/ucmenu.cpp 2016-06-07 14:25:30 +0000 | |||
892 | @@ -0,0 +1,613 @@ | |||
893 | 1 | /* | ||
894 | 2 | * Copyright 2016 Canonical Ltd. | ||
895 | 3 | * | ||
896 | 4 | * This program is free software; you can redistribute it and/or modify | ||
897 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
898 | 6 | * the Free Software Foundation; version 3. | ||
899 | 7 | * | ||
900 | 8 | * This program is distributed in the hope that it will be useful, | ||
901 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
902 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
903 | 11 | * GNU Lesser General Public License for more details. | ||
904 | 12 | * | ||
905 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
906 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
907 | 15 | */ | ||
908 | 16 | |||
909 | 17 | #include "ucmenu.h" | ||
910 | 18 | #include "ucmenu_p.h" | ||
911 | 19 | #include "ucmenubar.h" | ||
912 | 20 | #include "ucaction.h" | ||
913 | 21 | #include "ucactionlist.h" | ||
914 | 22 | |||
915 | 23 | // Qt | ||
916 | 24 | #include <QtGui/qpa/qplatformtheme.h> | ||
917 | 25 | #include <QtGui/qpa/qplatformmenu.h> | ||
918 | 26 | #include <QQuickItem> | ||
919 | 27 | #include <private/qguiapplication_p.h> | ||
920 | 28 | #include <private/qquickitem_p.h> | ||
921 | 29 | #include <QPointer> | ||
922 | 30 | |||
923 | 31 | |||
924 | 32 | Q_LOGGING_CATEGORY(ucMenu, "ubuntu.components.Menu", QtMsgType::QtWarningMsg) | ||
925 | 33 | |||
926 | 34 | namespace { | ||
927 | 35 | |||
928 | 36 | QWindow* findWindowForObject(QObject* object) | ||
929 | 37 | { | ||
930 | 38 | QObject* window = object; | ||
931 | 39 | while (window && !window->isWindowType()) { | ||
932 | 40 | window = window->parent(); | ||
933 | 41 | if (QQuickItem* item = qobject_cast<QQuickItem*>(window)) { | ||
934 | 42 | window = item->window(); | ||
935 | 43 | } | ||
936 | 44 | } | ||
937 | 45 | return qobject_cast<QWindow*>(window); | ||
938 | 46 | } | ||
939 | 47 | |||
940 | 48 | } | ||
941 | 49 | |||
942 | 50 | UCMenuPrivate::UCMenuPrivate(UCMenu *qq) | ||
943 | 51 | : q_ptr(qq) | ||
944 | 52 | , m_platformMenu(QGuiApplicationPrivate::platformTheme()->createPlatformMenu()) | ||
945 | 53 | { | ||
946 | 54 | } | ||
947 | 55 | |||
948 | 56 | UCMenuPrivate::~UCMenuPrivate() | ||
949 | 57 | { | ||
950 | 58 | delete m_platformMenu; | ||
951 | 59 | } | ||
952 | 60 | |||
953 | 61 | void UCMenuPrivate::insertObject(int index, QObject *o) | ||
954 | 62 | { | ||
955 | 63 | Q_Q(UCMenu); | ||
956 | 64 | if (!o) return; | ||
957 | 65 | qCInfo(ucMenu).nospace() << "UCMenu::insertObject(index="<< index << ", object=" << o << ")"; | ||
958 | 66 | |||
959 | 67 | // If the menus contains lists, we need to alter the insertion index to account for them. | ||
960 | 68 | int actualIndex = 0; | ||
961 | 69 | for (int i = 0; i < index && i < m_data.count(); i++) { | ||
962 | 70 | QObject* data = m_data[i]; | ||
963 | 71 | auto list = qobject_cast<UCActionList*>(data); | ||
964 | 72 | actualIndex += list ? list->list().count() : 1; | ||
965 | 73 | |||
966 | 74 | // menu group adds a separator item. | ||
967 | 75 | if (qobject_cast<UCMenuGroup*>(data)) { | ||
968 | 76 | actualIndex++; | ||
969 | 77 | } | ||
970 | 78 | } | ||
971 | 79 | |||
972 | 80 | QVector<QObject*>::iterator position = m_data.count() > index ? m_data.begin() + index : m_data.end(); | ||
973 | 81 | m_data.insert(position, o); | ||
974 | 82 | |||
975 | 83 | QObjectList objects; | ||
976 | 84 | if (UCActionList* actionList = qobject_cast<UCActionList*>(o)) { | ||
977 | 85 | Q_FOREACH(UCAction* action, actionList->list()) { | ||
978 | 86 | qCInfo(ucMenu).nospace() << " UCMenu::insertObject(actionList=" << actionList << ", action=" << action << ")"; | ||
979 | 87 | objects << action; | ||
980 | 88 | } | ||
981 | 89 | // menu group adds a separator item; so add self as well. | ||
982 | 90 | if (qobject_cast<UCMenuGroup*>(actionList)) { | ||
983 | 91 | objects << o; | ||
984 | 92 | } | ||
985 | 93 | } else { | ||
986 | 94 | objects << o; | ||
987 | 95 | } | ||
988 | 96 | |||
989 | 97 | Q_FOREACH(QObject* object, objects) { | ||
990 | 98 | |||
991 | 99 | UCMenuAttached *attached = qobject_cast<UCMenuAttached*>(qmlAttachedPropertiesObject<UCMenuAttached>(object)); | ||
992 | 100 | if (attached) { | ||
993 | 101 | attached->setParentObject(q); | ||
994 | 102 | } | ||
995 | 103 | |||
996 | 104 | // add to platform | ||
997 | 105 | if (m_platformMenu) { | ||
998 | 106 | auto platformWrapper = new PlatformItemWrapper(object, q); | ||
999 | 107 | platformWrapper->insert(actualIndex++); | ||
1000 | 108 | m_platformItems[object] = platformWrapper; | ||
1001 | 109 | |||
1002 | 110 | QObject::connect(object, &QObject::destroyed, q, [platformWrapper]() { | ||
1003 | 111 | platformWrapper->remove(); | ||
1004 | 112 | }); | ||
1005 | 113 | } | ||
1006 | 114 | } | ||
1007 | 115 | } | ||
1008 | 116 | |||
1009 | 117 | void UCMenuPrivate::removeObject(QObject *o) | ||
1010 | 118 | { | ||
1011 | 119 | Q_Q(UCMenu); | ||
1012 | 120 | m_data.removeOne(o); | ||
1013 | 121 | qCInfo(ucMenu).nospace() << "UCMenu::insertObject(" << o << ")"; | ||
1014 | 122 | |||
1015 | 123 | QObjectList objects; | ||
1016 | 124 | if (UCActionList* actionList = qobject_cast<UCActionList*>(o)) { | ||
1017 | 125 | Q_FOREACH(UCAction* action, actionList->list()) { | ||
1018 | 126 | objects << action; | ||
1019 | 127 | } | ||
1020 | 128 | if (qobject_cast<UCMenuGroup*>(actionList)) { | ||
1021 | 129 | objects << o; | ||
1022 | 130 | } | ||
1023 | 131 | } else { | ||
1024 | 132 | objects << o; | ||
1025 | 133 | } | ||
1026 | 134 | |||
1027 | 135 | Q_FOREACH(QObject* object, objects) { | ||
1028 | 136 | // remove from platform. | ||
1029 | 137 | if (m_platformMenu && m_platformItems.contains(object)) { | ||
1030 | 138 | m_platformItems[object]->remove(); | ||
1031 | 139 | m_platformItems.remove(object); | ||
1032 | 140 | } | ||
1033 | 141 | } | ||
1034 | 142 | } | ||
1035 | 143 | |||
1036 | 144 | void UCMenuPrivate::_q_updateEnabled() | ||
1037 | 145 | { | ||
1038 | 146 | Q_Q(UCMenu); | ||
1039 | 147 | |||
1040 | 148 | bool isEnabled = q->isEnabled(); | ||
1041 | 149 | if (m_platformMenu) { m_platformMenu->setEnabled(isEnabled); } | ||
1042 | 150 | } | ||
1043 | 151 | |||
1044 | 152 | void UCMenuPrivate::_q_updateText() | ||
1045 | 153 | { | ||
1046 | 154 | Q_Q(UCMenu); | ||
1047 | 155 | |||
1048 | 156 | QString text = q->text(); | ||
1049 | 157 | if (m_platformMenu) { m_platformMenu->setText(text); } | ||
1050 | 158 | } | ||
1051 | 159 | |||
1052 | 160 | void UCMenuPrivate::_q_updateIcon() | ||
1053 | 161 | { | ||
1054 | 162 | Q_Q(UCMenu); | ||
1055 | 163 | |||
1056 | 164 | QIcon icon; | ||
1057 | 165 | if (!q->iconSource().isEmpty()) { | ||
1058 | 166 | icon = QIcon(q->iconSource().path()); | ||
1059 | 167 | } else if (!q->iconName().isEmpty()) { | ||
1060 | 168 | icon = QIcon::fromTheme(q->iconName()); | ||
1061 | 169 | } | ||
1062 | 170 | |||
1063 | 171 | if (m_platformMenu) { m_platformMenu->setIcon(icon); } | ||
1064 | 172 | } | ||
1065 | 173 | |||
1066 | 174 | void UCMenuPrivate::_q_updateVisible() | ||
1067 | 175 | { | ||
1068 | 176 | Q_Q(UCMenu); | ||
1069 | 177 | |||
1070 | 178 | bool visible = q->visible(); | ||
1071 | 179 | if (m_platformMenu) { m_platformMenu->setVisible(visible); } | ||
1072 | 180 | } | ||
1073 | 181 | |||
1074 | 182 | void UCMenuPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o) | ||
1075 | 183 | { | ||
1076 | 184 | UCMenu *q = qobject_cast<UCMenu *>(prop->object); | ||
1077 | 185 | q->appendObject(o); | ||
1078 | 186 | } | ||
1079 | 187 | |||
1080 | 188 | int UCMenuPrivate::data_count(QQmlListProperty<QObject> *prop) | ||
1081 | 189 | { | ||
1082 | 190 | UCMenuPrivate *p = static_cast<UCMenuPrivate *>(prop->data); | ||
1083 | 191 | return p->m_data.count(); | ||
1084 | 192 | } | ||
1085 | 193 | |||
1086 | 194 | QObject *UCMenuPrivate::data_at(QQmlListProperty<QObject> *prop, int index) | ||
1087 | 195 | { | ||
1088 | 196 | UCMenuPrivate *p = static_cast<UCMenuPrivate *>(prop->data); | ||
1089 | 197 | return p->m_data.value(index); | ||
1090 | 198 | } | ||
1091 | 199 | |||
1092 | 200 | void UCMenuPrivate::data_clear(QQmlListProperty<QObject> *prop) | ||
1093 | 201 | { | ||
1094 | 202 | UCMenuPrivate *p = static_cast<UCMenuPrivate *>(prop->data); | ||
1095 | 203 | p->m_data.clear(); | ||
1096 | 204 | } | ||
1097 | 205 | |||
1098 | 206 | /*! | ||
1099 | 207 | * \qmltype Menu | ||
1100 | 208 | * \instantiates UCMenu | ||
1101 | 209 | * \inqmlmodule Ubuntu.Components | ||
1102 | 210 | * \ingroup ubuntu | ||
1103 | 211 | * \brief Menu defines a context menu or submenu structure of a MenuBar | ||
1104 | 212 | * | ||
1105 | 213 | * Example usage: | ||
1106 | 214 | * \qml | ||
1107 | 215 | * import QtQuick 2.4 | ||
1108 | 216 | * import Ubuntu.Components 1.3 | ||
1109 | 217 | * Menu { | ||
1110 | 218 | * text: "&File" | ||
1111 | 219 | * | ||
1112 | 220 | * MenuGroup { | ||
1113 | 221 | * Action { | ||
1114 | 222 | * text: "&New" | ||
1115 | 223 | * shortcut: "Ctrl+N" | ||
1116 | 224 | * } | ||
1117 | 225 | * | ||
1118 | 226 | * Action { | ||
1119 | 227 | * text: "&Open" | ||
1120 | 228 | * shortcut: "Ctrl+O" | ||
1121 | 229 | * } | ||
1122 | 230 | * } | ||
1123 | 231 | * | ||
1124 | 232 | * Menu { | ||
1125 | 233 | * text: "Recent Files" | ||
1126 | 234 | * | ||
1127 | 235 | * ActionList { | ||
1128 | 236 | * Action { text: "1.txt" } | ||
1129 | 237 | * Action { text: "2.txt" } | ||
1130 | 238 | * Action { text: "3.txt" } | ||
1131 | 239 | * } | ||
1132 | 240 | * } | ||
1133 | 241 | * | ||
1134 | 242 | * Action { | ||
1135 | 243 | * action: Action { | ||
1136 | 244 | * text: "E&xit" | ||
1137 | 245 | * shortcut: "Ctrl+X" | ||
1138 | 246 | * } | ||
1139 | 247 | * } | ||
1140 | 248 | * } | ||
1141 | 249 | * \endqml | ||
1142 | 250 | */ | ||
1143 | 251 | UCMenu::UCMenu(QObject *parent) | ||
1144 | 252 | : UCAction(parent) | ||
1145 | 253 | , d_ptr(new UCMenuPrivate(this)) | ||
1146 | 254 | { | ||
1147 | 255 | Q_D(UCMenu); | ||
1148 | 256 | |||
1149 | 257 | connect(this, SIGNAL(enabledChanged()), this, SLOT(_q_updateEnabled())); | ||
1150 | 258 | connect(this, SIGNAL(textChanged()), this, SLOT(_q_updateText())); | ||
1151 | 259 | connect(this, SIGNAL(iconNameChanged()), this, SLOT(_q_updateIcon())); | ||
1152 | 260 | connect(this, SIGNAL(iconSourceChanged()), this, SLOT(_q_updateIcon())); | ||
1153 | 261 | connect(this, SIGNAL(visibleChanged()), this, SLOT(_q_updateVisible())); | ||
1154 | 262 | } | ||
1155 | 263 | |||
1156 | 264 | UCMenu::~UCMenu() | ||
1157 | 265 | { | ||
1158 | 266 | } | ||
1159 | 267 | |||
1160 | 268 | /*! | ||
1161 | 269 | * \qmlproperty list<Object> Menu::data | ||
1162 | 270 | * \default | ||
1163 | 271 | * List of objects representing menu items within the menu. | ||
1164 | 272 | * | ||
1165 | 273 | * Currently supports Menu, MenuItem, MenuSeparator & Item objects. | ||
1166 | 274 | * \note Item object which do not support platformItem will not be exported for native menus. | ||
1167 | 275 | */ | ||
1168 | 276 | QQmlListProperty<QObject> UCMenu::data() | ||
1169 | 277 | { | ||
1170 | 278 | Q_D(UCMenu); | ||
1171 | 279 | return QQmlListProperty<QObject>(this, d, | ||
1172 | 280 | &UCMenuPrivate::data_append, | ||
1173 | 281 | &UCMenuPrivate::data_count, | ||
1174 | 282 | &UCMenuPrivate::data_at, | ||
1175 | 283 | &UCMenuPrivate::data_clear); | ||
1176 | 284 | } | ||
1177 | 285 | |||
1178 | 286 | /*! | ||
1179 | 287 | * \qmlmethod Menu::appendObject(object o) | ||
1180 | 288 | * Add a object tto the menu | ||
1181 | 289 | */ | ||
1182 | 290 | void UCMenu::appendObject(QObject *o) | ||
1183 | 291 | { | ||
1184 | 292 | Q_D(UCMenu); | ||
1185 | 293 | |||
1186 | 294 | insertObject(d->m_data.count(), o); | ||
1187 | 295 | } | ||
1188 | 296 | |||
1189 | 297 | /*! | ||
1190 | 298 | * \qmlmethod Menu::insertObject(int index, object o) | ||
1191 | 299 | * Inserts an item at the index in the menu. | ||
1192 | 300 | * | ||
1193 | 301 | * Currently supports Menu, MenuItem, MenuSeparator & Item objects. | ||
1194 | 302 | * \note Item object which do not support platformItem will not be exported for native menus. | ||
1195 | 303 | */ | ||
1196 | 304 | void UCMenu::insertObject(int index, QObject *o) | ||
1197 | 305 | { | ||
1198 | 306 | Q_D(UCMenu); | ||
1199 | 307 | d->insertObject(index, o); | ||
1200 | 308 | } | ||
1201 | 309 | |||
1202 | 310 | /*! | ||
1203 | 311 | * \qmlmethod Menu::removeObject(object o) | ||
1204 | 312 | * Removes the item from the menu. | ||
1205 | 313 | */ | ||
1206 | 314 | void UCMenu::removeObject(QObject *o) | ||
1207 | 315 | { | ||
1208 | 316 | Q_D(UCMenu); | ||
1209 | 317 | qCInfo(ucMenu) << "UCMenu::removeObject" << o; | ||
1210 | 318 | |||
1211 | 319 | d->removeObject(o); | ||
1212 | 320 | } | ||
1213 | 321 | |||
1214 | 322 | QPlatformMenu* UCMenu::platformMenu() const | ||
1215 | 323 | { | ||
1216 | 324 | Q_D(const UCMenu); | ||
1217 | 325 | return d->m_platformMenu; | ||
1218 | 326 | } | ||
1219 | 327 | |||
1220 | 328 | /*! | ||
1221 | 329 | * \qmlmethod Menu::show(point point) | ||
1222 | 330 | * Show the menu popup at the given point | ||
1223 | 331 | */ | ||
1224 | 332 | void UCMenu::show(const QPoint &point) | ||
1225 | 333 | { | ||
1226 | 334 | Q_D(UCMenu); | ||
1227 | 335 | qCInfo(ucMenu, "UCMenu::popup(%s, point(%d,%d))", qPrintable(text()), point.x(), point.y()); | ||
1228 | 336 | |||
1229 | 337 | if (d->m_platformMenu) { | ||
1230 | 338 | d->m_platformMenu->showPopup(findWindowForObject(this), QRect(point, QSize()), nullptr); | ||
1231 | 339 | } | ||
1232 | 340 | } | ||
1233 | 341 | |||
1234 | 342 | /*! | ||
1235 | 343 | * \qmlmethod Menu::dismiss() | ||
1236 | 344 | * Dismiss and destroy the menu popup. | ||
1237 | 345 | */ | ||
1238 | 346 | void UCMenu::dismiss() | ||
1239 | 347 | { | ||
1240 | 348 | Q_D(UCMenu); | ||
1241 | 349 | qCInfo(ucMenu, "UCMenu::dismiss(%s)", qPrintable(text())); | ||
1242 | 350 | |||
1243 | 351 | if (d->m_platformMenu) { | ||
1244 | 352 | d->m_platformMenu->dismiss(); | ||
1245 | 353 | } | ||
1246 | 354 | } | ||
1247 | 355 | |||
1248 | 356 | /*! | ||
1249 | 357 | * \qmltype Menus | ||
1250 | 358 | * \instantiates UCMenuAttached | ||
1251 | 359 | * \inqmlmodule Ubuntu.Components 1.3 | ||
1252 | 360 | * \ingroup ubuntu | ||
1253 | 361 | * \since Ubuntu.Components 1.3 | ||
1254 | 362 | * \brief A set of properties attached to the Menu. | ||
1255 | 363 | * | ||
1256 | 364 | */ | ||
1257 | 365 | UCMenuAttached::UCMenuAttached(QObject *parent) | ||
1258 | 366 | : QObject(parent) | ||
1259 | 367 | , m_parentObject(nullptr) | ||
1260 | 368 | { | ||
1261 | 369 | } | ||
1262 | 370 | |||
1263 | 371 | UCMenuAttached *UCMenuAttached::qmlAttachedProperties(QObject *o) | ||
1264 | 372 | { | ||
1265 | 373 | return new UCMenuAttached(o); | ||
1266 | 374 | } | ||
1267 | 375 | |||
1268 | 376 | void UCMenuAttached::setParentObject(QObject *o) | ||
1269 | 377 | { | ||
1270 | 378 | if (m_parentObject != o) { | ||
1271 | 379 | UCMenu* oldMenu = parentMenu(); | ||
1272 | 380 | UCMenuBar* oldBar = menuBar(); | ||
1273 | 381 | |||
1274 | 382 | m_parentObject = o; | ||
1275 | 383 | |||
1276 | 384 | if (oldMenu != parentMenu()) Q_EMIT parentMenuChanged(); | ||
1277 | 385 | if (oldBar != menuBar()) Q_EMIT menuBarChanged(); | ||
1278 | 386 | } | ||
1279 | 387 | } | ||
1280 | 388 | |||
1281 | 389 | /*! | ||
1282 | 390 | * \qmlattachedproperty bool Menus::parentMenu | ||
1283 | 391 | * The property returns the parent Menu of the object, or null if there is none. | ||
1284 | 392 | */ | ||
1285 | 393 | UCMenu *UCMenuAttached::parentMenu() const | ||
1286 | 394 | { | ||
1287 | 395 | return qobject_cast<UCMenu*>(m_parentObject); | ||
1288 | 396 | } | ||
1289 | 397 | |||
1290 | 398 | /*! | ||
1291 | 399 | * \qmlattachedproperty bool Menus::menuBar | ||
1292 | 400 | * The property returns the parent MenuBar of the object, or null if there is none. | ||
1293 | 401 | */ | ||
1294 | 402 | UCMenuBar *UCMenuAttached::menuBar() const | ||
1295 | 403 | { | ||
1296 | 404 | return qobject_cast<UCMenuBar*>(m_parentObject); | ||
1297 | 405 | } | ||
1298 | 406 | |||
1299 | 407 | |||
1300 | 408 | PlatformItemWrapper::PlatformItemWrapper(QObject *target, UCMenu* menu) | ||
1301 | 409 | : QObject(menu) | ||
1302 | 410 | , m_target(target) | ||
1303 | 411 | , m_menu(menu) | ||
1304 | 412 | , m_platformItem(menu->platformMenu() ? menu->platformMenu()->createMenuItem() : Q_NULLPTR) | ||
1305 | 413 | { | ||
1306 | 414 | connect(m_target, &QObject::destroyed, this, &QObject::deleteLater); | ||
1307 | 415 | |||
1308 | 416 | if (UCMenu* menu = qobject_cast<UCMenu*>(m_target)) { | ||
1309 | 417 | if (m_platformItem) { | ||
1310 | 418 | m_platformItem->setMenu(menu->platformMenu()); | ||
1311 | 419 | } | ||
1312 | 420 | |||
1313 | 421 | connect(menu, &UCMenu::visibleChanged, this, &PlatformItemWrapper::updateVisible); | ||
1314 | 422 | connect(menu, &UCMenu::textChanged, this, &PlatformItemWrapper::updateText); | ||
1315 | 423 | connect(menu, &UCMenu::enabledChanged, this, &PlatformItemWrapper::updateEnabled); | ||
1316 | 424 | connect(menu, &UCMenu::iconSourceChanged, this, &PlatformItemWrapper::updateIcon); | ||
1317 | 425 | connect(menu, &UCMenu::iconNameChanged, this, &PlatformItemWrapper::updateIcon); | ||
1318 | 426 | |||
1319 | 427 | } else if (UCAction* action = qobject_cast<UCAction*>(m_target)) { | ||
1320 | 428 | |||
1321 | 429 | connect(action, &UCAction::visibleChanged, this, &PlatformItemWrapper::updateVisible); | ||
1322 | 430 | connect(action, &UCAction::textChanged, this, &PlatformItemWrapper::updateText); | ||
1323 | 431 | connect(action, &UCAction::enabledChanged, this, &PlatformItemWrapper::updateEnabled); | ||
1324 | 432 | connect(action, &UCAction::iconSourceChanged, this, &PlatformItemWrapper::updateIcon); | ||
1325 | 433 | connect(action, &UCAction::iconNameChanged, this, &PlatformItemWrapper::updateIcon); | ||
1326 | 434 | connect(action, &UCAction::shortcutChanged, this, &PlatformItemWrapper::updateShortcut); | ||
1327 | 435 | connect(action, &UCAction::parameterTypeChanged, this, &PlatformItemWrapper::updateCheck); | ||
1328 | 436 | connect(action, &UCAction::stateChanged, this, &PlatformItemWrapper::updateCheck); | ||
1329 | 437 | |||
1330 | 438 | if (m_platformItem) { | ||
1331 | 439 | connect(m_platformItem, SIGNAL(activated()), action, SLOT(trigger())); | ||
1332 | 440 | } | ||
1333 | 441 | |||
1334 | 442 | } else if (qobject_cast<UCActionList*>(m_target)) { | ||
1335 | 443 | if (m_platformItem) { | ||
1336 | 444 | m_platformItem->setIsSeparator(true); | ||
1337 | 445 | } | ||
1338 | 446 | } | ||
1339 | 447 | |||
1340 | 448 | syncPlatformItem(); | ||
1341 | 449 | } | ||
1342 | 450 | |||
1343 | 451 | void PlatformItemWrapper::insert(int index) | ||
1344 | 452 | { | ||
1345 | 453 | auto platformMenu = m_menu->platformMenu(); | ||
1346 | 454 | if (!platformMenu) return; | ||
1347 | 455 | if (!m_platformItem) return; | ||
1348 | 456 | |||
1349 | 457 | QPlatformMenuItem* before = platformMenu->menuItemAt(index); | ||
1350 | 458 | platformMenu->insertMenuItem(m_platformItem, before); | ||
1351 | 459 | } | ||
1352 | 460 | |||
1353 | 461 | void PlatformItemWrapper::remove() | ||
1354 | 462 | { | ||
1355 | 463 | auto platformMenu = m_menu->platformMenu(); | ||
1356 | 464 | if (!platformMenu) return; | ||
1357 | 465 | if (!m_platformItem) return; | ||
1358 | 466 | |||
1359 | 467 | platformMenu->removeMenuItem(m_platformItem); | ||
1360 | 468 | } | ||
1361 | 469 | |||
1362 | 470 | void PlatformItemWrapper::updateVisible() | ||
1363 | 471 | { | ||
1364 | 472 | if (!m_platformItem) return; | ||
1365 | 473 | |||
1366 | 474 | if (UCMenu* menu = qobject_cast<UCMenu*>(m_target)) { | ||
1367 | 475 | m_platformItem->setVisible(menu->visible()); | ||
1368 | 476 | if (menu->platformMenu()) menu->platformMenu()->setVisible(menu->visible()); | ||
1369 | 477 | } else if (UCAction* action = qobject_cast<UCAction*>(m_target)) { | ||
1370 | 478 | m_platformItem->setVisible(action->visible()); | ||
1371 | 479 | } | ||
1372 | 480 | } | ||
1373 | 481 | |||
1374 | 482 | void PlatformItemWrapper::updateEnabled() | ||
1375 | 483 | { | ||
1376 | 484 | if (!m_platformItem) return; | ||
1377 | 485 | |||
1378 | 486 | if (UCMenu* menu = qobject_cast<UCMenu*>(m_target)) { | ||
1379 | 487 | m_platformItem->setEnabled(menu->isEnabled()); | ||
1380 | 488 | if (menu->platformMenu()) menu->platformMenu()->setEnabled(menu->isEnabled()); | ||
1381 | 489 | } else if (UCAction* action = qobject_cast<UCAction*>(m_target)) { | ||
1382 | 490 | m_platformItem->setText(action->text()); | ||
1383 | 491 | } | ||
1384 | 492 | } | ||
1385 | 493 | |||
1386 | 494 | void PlatformItemWrapper::updateText() | ||
1387 | 495 | { | ||
1388 | 496 | if (!m_platformItem) return; | ||
1389 | 497 | |||
1390 | 498 | if (UCMenu* menu = qobject_cast<UCMenu*>(m_target)) { | ||
1391 | 499 | m_platformItem->setText(menu->text()); | ||
1392 | 500 | if (menu->platformMenu()) menu->platformMenu()->setText(menu->text()); | ||
1393 | 501 | } else if (UCAction* action = qobject_cast<UCAction*>(m_target)) { | ||
1394 | 502 | m_platformItem->setText(action->text()); | ||
1395 | 503 | } | ||
1396 | 504 | } | ||
1397 | 505 | |||
1398 | 506 | void PlatformItemWrapper::updateIcon() | ||
1399 | 507 | { | ||
1400 | 508 | if (!m_platformItem) return; | ||
1401 | 509 | |||
1402 | 510 | QIcon icon; | ||
1403 | 511 | if (UCMenu* menu = qobject_cast<UCMenu*>(m_target)) { | ||
1404 | 512 | |||
1405 | 513 | if (!menu->iconSource().isEmpty()) { | ||
1406 | 514 | icon = QIcon(menu->iconSource().path()); | ||
1407 | 515 | } else if (!menu->iconName().isEmpty()) { | ||
1408 | 516 | icon = QIcon::fromTheme(menu->iconName()); | ||
1409 | 517 | } | ||
1410 | 518 | if (menu->platformMenu()) menu->platformMenu()->setIcon(icon); | ||
1411 | 519 | |||
1412 | 520 | } else if (UCAction* action = qobject_cast<UCAction*>(m_target)) { | ||
1413 | 521 | |||
1414 | 522 | if (!action->iconSource().isEmpty()) { | ||
1415 | 523 | icon = QIcon(action->iconSource().path()); | ||
1416 | 524 | } else if (!action->iconName().isEmpty()) { | ||
1417 | 525 | icon = QIcon::fromTheme(action->iconName()); | ||
1418 | 526 | } | ||
1419 | 527 | } | ||
1420 | 528 | m_platformItem->setIcon(icon); | ||
1421 | 529 | } | ||
1422 | 530 | |||
1423 | 531 | |||
1424 | 532 | inline QKeySequence sequenceFromVariant(const QVariant& variant) | ||
1425 | 533 | { | ||
1426 | 534 | if (variant.type() == QVariant::Int) { | ||
1427 | 535 | return static_cast<QKeySequence::StandardKey>(variant.toInt()); | ||
1428 | 536 | } | ||
1429 | 537 | if (variant.type() == QVariant::String) { | ||
1430 | 538 | return QKeySequence::fromString(variant.toString()); | ||
1431 | 539 | } | ||
1432 | 540 | return QKeySequence(); | ||
1433 | 541 | } | ||
1434 | 542 | |||
1435 | 543 | void PlatformItemWrapper::updateShortcut() | ||
1436 | 544 | { | ||
1437 | 545 | if (!m_platformItem) return; | ||
1438 | 546 | |||
1439 | 547 | if (UCAction* action = qobject_cast<UCAction*>(m_target)) { | ||
1440 | 548 | m_platformItem->setShortcut(sequenceFromVariant(action->shortcut())); | ||
1441 | 549 | } | ||
1442 | 550 | } | ||
1443 | 551 | |||
1444 | 552 | void PlatformItemWrapper::updateCheck() | ||
1445 | 553 | { | ||
1446 | 554 | if (!m_platformItem) return; | ||
1447 | 555 | |||
1448 | 556 | if (UCAction* action = qobject_cast<UCAction*>(m_target)) { | ||
1449 | 557 | bool checkable = action->parameterType() == UCAction::Bool; | ||
1450 | 558 | m_platformItem->setCheckable(checkable); | ||
1451 | 559 | m_platformItem->setChecked(checkable && action->state().toBool()); | ||
1452 | 560 | } | ||
1453 | 561 | } | ||
1454 | 562 | |||
1455 | 563 | void PlatformItemWrapper::syncPlatformItem() | ||
1456 | 564 | { | ||
1457 | 565 | updateVisible(); | ||
1458 | 566 | updateEnabled(); | ||
1459 | 567 | updateText(); | ||
1460 | 568 | updateIcon(); | ||
1461 | 569 | updateShortcut(); | ||
1462 | 570 | updateCheck(); | ||
1463 | 571 | |||
1464 | 572 | if (m_menu->platformMenu() && m_platformItem) { | ||
1465 | 573 | m_menu->platformMenu()->syncMenuItem(m_platformItem); | ||
1466 | 574 | } | ||
1467 | 575 | } | ||
1468 | 576 | |||
1469 | 577 | |||
1470 | 578 | /*! | ||
1471 | 579 | * \qmltype MenuGroup | ||
1472 | 580 | * \inqmlmodule Ubuntu.Components | ||
1473 | 581 | * \ingroup ubuntu | ||
1474 | 582 | * \brief List of \l Action items for a menu which adds a separator between logical groups of menus. | ||
1475 | 583 | * | ||
1476 | 584 | * Example usage: | ||
1477 | 585 | * \qml | ||
1478 | 586 | * import QtQuick 2.4 | ||
1479 | 587 | * import Ubuntu.Components 1.3 | ||
1480 | 588 | * Menu { | ||
1481 | 589 | * text: "Edit" | ||
1482 | 590 | * | ||
1483 | 591 | * MenuGroup { | ||
1484 | 592 | * Action { text: "Undo" } | ||
1485 | 593 | * Action { text: "Redo" } | ||
1486 | 594 | * } | ||
1487 | 595 | * | ||
1488 | 596 | * MenuGroup { | ||
1489 | 597 | * Action { text: "Cut" } | ||
1490 | 598 | * Action { text: "Copy" } | ||
1491 | 599 | * Action { text: "Paste" } | ||
1492 | 600 | * } | ||
1493 | 601 | * | ||
1494 | 602 | * MenuGroup { | ||
1495 | 603 | * Action { text: "Select All" } | ||
1496 | 604 | * } | ||
1497 | 605 | * } | ||
1498 | 606 | * \endqml | ||
1499 | 607 | */ | ||
1500 | 608 | UCMenuGroup::UCMenuGroup(QObject *parent) | ||
1501 | 609 | : UCActionList(parent) | ||
1502 | 610 | { | ||
1503 | 611 | } | ||
1504 | 612 | |||
1505 | 613 | #include "moc_ucmenu.cpp" | ||
1506 | 0 | 614 | ||
1507 | === added file 'src/Ubuntu/Components/plugin/ucmenu.h' | |||
1508 | --- src/Ubuntu/Components/plugin/ucmenu.h 1970-01-01 00:00:00 +0000 | |||
1509 | +++ src/Ubuntu/Components/plugin/ucmenu.h 2016-06-07 14:25:30 +0000 | |||
1510 | @@ -0,0 +1,108 @@ | |||
1511 | 1 | /* | ||
1512 | 2 | * Copyright 2016 Canonical Ltd. | ||
1513 | 3 | * | ||
1514 | 4 | * This program is free software; you can redistribute it and/or modify | ||
1515 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
1516 | 6 | * the Free Software Foundation; version 3. | ||
1517 | 7 | * | ||
1518 | 8 | * This program is distributed in the hope that it will be useful, | ||
1519 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1520 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1521 | 11 | * GNU Lesser General Public License for more details. | ||
1522 | 12 | * | ||
1523 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1524 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1525 | 15 | * | ||
1526 | 16 | */ | ||
1527 | 17 | |||
1528 | 18 | #ifndef UCMENU_H | ||
1529 | 19 | #define UCMENU_H | ||
1530 | 20 | |||
1531 | 21 | #include <QQmlListProperty> | ||
1532 | 22 | #include <QUrl> | ||
1533 | 23 | #include <QLoggingCategory> | ||
1534 | 24 | #include <QPointer> | ||
1535 | 25 | #include <qqml.h> | ||
1536 | 26 | #include <QtQml/qqml.h> | ||
1537 | 27 | #include <private/qquickitemchangelistener_p.h> | ||
1538 | 28 | |||
1539 | 29 | #include "ucaction.h" | ||
1540 | 30 | #include "ucactionlist.h" | ||
1541 | 31 | |||
1542 | 32 | Q_DECLARE_LOGGING_CATEGORY(ucMenu); | ||
1543 | 33 | |||
1544 | 34 | class QPlatformMenu; | ||
1545 | 35 | class QPlatformMenuItem; | ||
1546 | 36 | class QQuickItem; | ||
1547 | 37 | class UCMenuPrivate; | ||
1548 | 38 | class UCMenuAttached; | ||
1549 | 39 | class UCMenuBar; | ||
1550 | 40 | class UCAction; | ||
1551 | 41 | |||
1552 | 42 | class UCMenu : public UCAction | ||
1553 | 43 | { | ||
1554 | 44 | Q_OBJECT | ||
1555 | 45 | |||
1556 | 46 | Q_PROPERTY(QQmlListProperty<QObject> data READ data FINAL) | ||
1557 | 47 | Q_CLASSINFO("DefaultProperty", "data") | ||
1558 | 48 | |||
1559 | 49 | public: | ||
1560 | 50 | explicit UCMenu(QObject *parent = 0); | ||
1561 | 51 | ~UCMenu(); | ||
1562 | 52 | |||
1563 | 53 | QQmlListProperty<QObject> data(); | ||
1564 | 54 | |||
1565 | 55 | Q_INVOKABLE void appendObject(QObject* obj); | ||
1566 | 56 | Q_INVOKABLE void insertObject(int index, QObject* obj); | ||
1567 | 57 | Q_INVOKABLE void removeObject(QObject* obj); | ||
1568 | 58 | |||
1569 | 59 | QPlatformMenu *platformMenu() const; | ||
1570 | 60 | |||
1571 | 61 | public Q_SLOTS: | ||
1572 | 62 | void show(const QPoint& pt); | ||
1573 | 63 | void dismiss(); | ||
1574 | 64 | |||
1575 | 65 | private: | ||
1576 | 66 | Q_DISABLE_COPY(UCMenu) | ||
1577 | 67 | Q_DECLARE_PRIVATE(UCMenu) | ||
1578 | 68 | QScopedPointer<UCMenuPrivate> d_ptr; | ||
1579 | 69 | |||
1580 | 70 | Q_PRIVATE_SLOT(d_func(), void _q_updateEnabled()) | ||
1581 | 71 | Q_PRIVATE_SLOT(d_func(), void _q_updateText()) | ||
1582 | 72 | Q_PRIVATE_SLOT(d_func(), void _q_updateIcon()) | ||
1583 | 73 | Q_PRIVATE_SLOT(d_func(), void _q_updateVisible()) | ||
1584 | 74 | }; | ||
1585 | 75 | |||
1586 | 76 | class UCMenuAttached : public QObject | ||
1587 | 77 | { | ||
1588 | 78 | Q_OBJECT | ||
1589 | 79 | Q_PROPERTY(UCMenu* parentMenu READ parentMenu NOTIFY parentMenuChanged) | ||
1590 | 80 | Q_PROPERTY(UCMenuBar* menuBar READ menuBar NOTIFY parentMenuChanged) | ||
1591 | 81 | public: | ||
1592 | 82 | explicit UCMenuAttached(QObject *parent); | ||
1593 | 83 | |||
1594 | 84 | static UCMenuAttached *qmlAttachedProperties(QObject *); | ||
1595 | 85 | |||
1596 | 86 | void setParentObject(QObject* o); | ||
1597 | 87 | |||
1598 | 88 | UCMenu *parentMenu() const; | ||
1599 | 89 | UCMenuBar *menuBar() const; | ||
1600 | 90 | |||
1601 | 91 | Q_SIGNALS: | ||
1602 | 92 | void parentMenuChanged(); | ||
1603 | 93 | void menuBarChanged(); | ||
1604 | 94 | |||
1605 | 95 | private: | ||
1606 | 96 | QPointer<QObject> m_parentObject; | ||
1607 | 97 | }; | ||
1608 | 98 | QML_DECLARE_TYPEINFO(UCMenuAttached, QML_HAS_ATTACHED_PROPERTIES) | ||
1609 | 99 | |||
1610 | 100 | |||
1611 | 101 | class UCMenuGroup : public UCActionList | ||
1612 | 102 | { | ||
1613 | 103 | Q_OBJECT | ||
1614 | 104 | public: | ||
1615 | 105 | explicit UCMenuGroup(QObject *parent = 0); | ||
1616 | 106 | }; | ||
1617 | 107 | |||
1618 | 108 | #endif // UCMENU_H | ||
1619 | 0 | 109 | ||
1620 | === added file 'src/Ubuntu/Components/plugin/ucmenu_p.h' | |||
1621 | --- src/Ubuntu/Components/plugin/ucmenu_p.h 1970-01-01 00:00:00 +0000 | |||
1622 | +++ src/Ubuntu/Components/plugin/ucmenu_p.h 2016-06-07 14:25:30 +0000 | |||
1623 | @@ -0,0 +1,83 @@ | |||
1624 | 1 | /* | ||
1625 | 2 | * Copyright 2016 Canonical Ltd. | ||
1626 | 3 | * | ||
1627 | 4 | * This program is free software; you can redistribute it and/or modify | ||
1628 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
1629 | 6 | * the Free Software Foundation; version 3. | ||
1630 | 7 | * | ||
1631 | 8 | * This program is distributed in the hope that it will be useful, | ||
1632 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1633 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1634 | 11 | * GNU Lesser General Public License for more details. | ||
1635 | 12 | * | ||
1636 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1637 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1638 | 15 | * | ||
1639 | 16 | */ | ||
1640 | 17 | |||
1641 | 18 | #ifndef UCMENU_P | ||
1642 | 19 | #define UCMENU_P | ||
1643 | 20 | |||
1644 | 21 | #include <private/qquickitemchangelistener_p.h> | ||
1645 | 22 | #include "ucmenu.h" | ||
1646 | 23 | |||
1647 | 24 | class QObject; | ||
1648 | 25 | class UCAction; | ||
1649 | 26 | class QQmlComponent; | ||
1650 | 27 | class UCMenu; | ||
1651 | 28 | class PlatformItemWrapper; | ||
1652 | 29 | |||
1653 | 30 | class UCMenuPrivate | ||
1654 | 31 | { | ||
1655 | 32 | Q_DECLARE_PUBLIC(UCMenu) | ||
1656 | 33 | public: | ||
1657 | 34 | UCMenuPrivate(UCMenu *qq); | ||
1658 | 35 | virtual ~UCMenuPrivate(); | ||
1659 | 36 | |||
1660 | 37 | void insertObject(int index, QObject *obj); | ||
1661 | 38 | void removeObject(QObject *obj); | ||
1662 | 39 | |||
1663 | 40 | void _q_updateEnabled(); | ||
1664 | 41 | void _q_updateText(); | ||
1665 | 42 | void _q_updateIcon(); | ||
1666 | 43 | void _q_updateVisible(); | ||
1667 | 44 | |||
1668 | 45 | static void data_append(QQmlListProperty<QObject> *prop, QObject *o); | ||
1669 | 46 | static int data_count(QQmlListProperty<QObject> *prop); | ||
1670 | 47 | static QObject *data_at(QQmlListProperty<QObject> *prop, int index); | ||
1671 | 48 | static void data_clear(QQmlListProperty<QObject> *prop); | ||
1672 | 49 | |||
1673 | 50 | UCMenu* q_ptr; | ||
1674 | 51 | QPlatformMenu* m_platformMenu; | ||
1675 | 52 | UCAction* m_action; | ||
1676 | 53 | |||
1677 | 54 | QHash<QObject*, PlatformItemWrapper*> m_platformItems; | ||
1678 | 55 | QVector<QObject*> m_data; | ||
1679 | 56 | }; | ||
1680 | 57 | |||
1681 | 58 | class PlatformItemWrapper : public QObject | ||
1682 | 59 | { | ||
1683 | 60 | Q_OBJECT | ||
1684 | 61 | public: | ||
1685 | 62 | PlatformItemWrapper(QObject *target, UCMenu* menu); | ||
1686 | 63 | |||
1687 | 64 | void insert(int index); | ||
1688 | 65 | void remove(); | ||
1689 | 66 | |||
1690 | 67 | public Q_SLOTS: | ||
1691 | 68 | void updateVisible(); | ||
1692 | 69 | void updateEnabled(); | ||
1693 | 70 | void updateText(); | ||
1694 | 71 | void updateIcon(); | ||
1695 | 72 | void updateShortcut(); | ||
1696 | 73 | void updateCheck(); | ||
1697 | 74 | |||
1698 | 75 | private: | ||
1699 | 76 | void syncPlatformItem(); | ||
1700 | 77 | |||
1701 | 78 | QObject* m_target; | ||
1702 | 79 | UCMenu* m_menu; | ||
1703 | 80 | QPlatformMenuItem* m_platformItem; | ||
1704 | 81 | }; | ||
1705 | 82 | |||
1706 | 83 | #endif // UCMENU_P | ||
1707 | 0 | 84 | ||
1708 | === added file 'src/Ubuntu/Components/plugin/ucmenubar.cpp' | |||
1709 | --- src/Ubuntu/Components/plugin/ucmenubar.cpp 1970-01-01 00:00:00 +0000 | |||
1710 | +++ src/Ubuntu/Components/plugin/ucmenubar.cpp 2016-06-07 14:25:30 +0000 | |||
1711 | @@ -0,0 +1,299 @@ | |||
1712 | 1 | /* | ||
1713 | 2 | * Copyright 2016 Canonical Ltd. | ||
1714 | 3 | * | ||
1715 | 4 | * This program is free software; you can redistribute it and/or modify | ||
1716 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
1717 | 6 | * the Free Software Foundation; version 3. | ||
1718 | 7 | * | ||
1719 | 8 | * This program is distributed in the hope that it will be useful, | ||
1720 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1721 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1722 | 11 | * GNU Lesser General Public License for more details. | ||
1723 | 12 | * | ||
1724 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
1725 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1726 | 15 | * | ||
1727 | 16 | */ | ||
1728 | 17 | |||
1729 | 18 | #include "ucmenubar.h" | ||
1730 | 19 | #include "ucmenubar_p.h" | ||
1731 | 20 | |||
1732 | 21 | // Qt | ||
1733 | 22 | #include <QQuickItem> | ||
1734 | 23 | #include <QQuickWindow> | ||
1735 | 24 | #include <private/qguiapplication_p.h> | ||
1736 | 25 | #include <QtGui/qpa/qplatformtheme.h> | ||
1737 | 26 | #include <QtGui/qpa/qplatformmenu.h> | ||
1738 | 27 | |||
1739 | 28 | UCMenuBarPrivate::UCMenuBarPrivate(UCMenuBar *qq) | ||
1740 | 29 | : q_ptr(qq) | ||
1741 | 30 | { | ||
1742 | 31 | m_platformBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar(); | ||
1743 | 32 | } | ||
1744 | 33 | |||
1745 | 34 | void UCMenuBarPrivate::insertMenu(int index, UCMenu* menu) | ||
1746 | 35 | { | ||
1747 | 36 | Q_Q(UCMenuBar); | ||
1748 | 37 | UCMenu* prevMenu = m_menus.count() > index ? m_menus[index] : nullptr; | ||
1749 | 38 | |||
1750 | 39 | m_menus.insert(index, menu); | ||
1751 | 40 | |||
1752 | 41 | UCMenuAttached *attached = qobject_cast<UCMenuAttached*>(qmlAttachedPropertiesObject<UCMenuAttached>(menu)); | ||
1753 | 42 | if (attached) { | ||
1754 | 43 | attached->setParentObject(q); | ||
1755 | 44 | } | ||
1756 | 45 | |||
1757 | 46 | if (m_platformBar && menu->platformMenu()) { | ||
1758 | 47 | m_platformBar->insertMenu(menu->platformMenu(), prevMenu ? prevMenu->platformMenu() : nullptr); | ||
1759 | 48 | } | ||
1760 | 49 | } | ||
1761 | 50 | |||
1762 | 51 | void UCMenuBarPrivate::menu_append(QQmlListProperty<UCMenu> *prop, UCMenu *o) | ||
1763 | 52 | { | ||
1764 | 53 | UCMenuBarPrivate *q = static_cast<UCMenuBarPrivate *>(prop->data); | ||
1765 | 54 | // menubar is the menus parent | ||
1766 | 55 | o->setParent(prop->object); | ||
1767 | 56 | q->insertMenu(q->m_menus.count(), o); | ||
1768 | 57 | } | ||
1769 | 58 | |||
1770 | 59 | int UCMenuBarPrivate::menu_count(QQmlListProperty<UCMenu> *prop) | ||
1771 | 60 | { | ||
1772 | 61 | UCMenuBarPrivate *p = static_cast<UCMenuBarPrivate *>(prop->data); | ||
1773 | 62 | return p->m_menus.count(); | ||
1774 | 63 | } | ||
1775 | 64 | |||
1776 | 65 | UCMenu *UCMenuBarPrivate::menu_at(QQmlListProperty<UCMenu> *prop, int index) | ||
1777 | 66 | { | ||
1778 | 67 | UCMenuBarPrivate *p = static_cast<UCMenuBarPrivate *>(prop->data); | ||
1779 | 68 | return p->m_menus.value(index); | ||
1780 | 69 | } | ||
1781 | 70 | |||
1782 | 71 | void UCMenuBarPrivate::menu_clear(QQmlListProperty<UCMenu> *prop) | ||
1783 | 72 | { | ||
1784 | 73 | UCMenuBarPrivate *p = static_cast<UCMenuBarPrivate *>(prop->data); | ||
1785 | 74 | p->m_menus.clear(); | ||
1786 | 75 | } | ||
1787 | 76 | |||
1788 | 77 | /*! | ||
1789 | 78 | * \qmltype MenuBar | ||
1790 | 79 | * \instantiates UCMenuBar | ||
1791 | 80 | * \inqmlmodule Ubuntu.Components 1.3 | ||
1792 | 81 | * \ingroup ubuntu | ||
1793 | 82 | * \brief MenuBar defines an application menu bar structure | ||
1794 | 83 | * | ||
1795 | 84 | * Example usage: | ||
1796 | 85 | * \qml | ||
1797 | 86 | * import QtQuick 2.4 | ||
1798 | 87 | * import Ubuntu.Components 1.3 | ||
1799 | 88 | * MainView { | ||
1800 | 89 | * MenuBar { | ||
1801 | 90 | * Menu { | ||
1802 | 91 | * text: "_File" | ||
1803 | 92 | * | ||
1804 | 93 | * MenuItem { | ||
1805 | 94 | * text: "_New" | ||
1806 | 95 | * shortcut: "Ctrl+N" | ||
1807 | 96 | * } | ||
1808 | 97 | * | ||
1809 | 98 | * MenuItem { | ||
1810 | 99 | * text: "_Open" | ||
1811 | 100 | * shortcut: "Ctrl+O" | ||
1812 | 101 | * } | ||
1813 | 102 | * | ||
1814 | 103 | * MenuSeparator {} | ||
1815 | 104 | * | ||
1816 | 105 | * MenuItem { | ||
1817 | 106 | * action: exitAction | ||
1818 | 107 | * } | ||
1819 | 108 | * } | ||
1820 | 109 | * | ||
1821 | 110 | * Menu { | ||
1822 | 111 | * text: "_Edit" | ||
1823 | 112 | * | ||
1824 | 113 | * MenuItem { | ||
1825 | 114 | * text: "_Undo" | ||
1826 | 115 | * iconSource: "image://theme/undo" | ||
1827 | 116 | * } | ||
1828 | 117 | * } | ||
1829 | 118 | * Menu { | ||
1830 | 119 | * text: "_Window" | ||
1831 | 120 | * | ||
1832 | 121 | * MenuItem { | ||
1833 | 122 | * text: "Fullscreen" | ||
1834 | 123 | * checkable: true | ||
1835 | 124 | * checked: false | ||
1836 | 125 | * } | ||
1837 | 126 | * } | ||
1838 | 127 | * } | ||
1839 | 128 | * Action { | ||
1840 | 129 | * id: boundAction | ||
1841 | 130 | * text: "E_xit" | ||
1842 | 131 | * onTriggered: { | ||
1843 | 132 | * Qt.quit(); | ||
1844 | 133 | * } | ||
1845 | 134 | * } | ||
1846 | 135 | * } | ||
1847 | 136 | * \endqml | ||
1848 | 137 | */ | ||
1849 | 138 | UCMenuBar::UCMenuBar(QObject *parent) | ||
1850 | 139 | : QObject(parent) | ||
1851 | 140 | , d_ptr(new UCMenuBarPrivate(this)) | ||
1852 | 141 | { | ||
1853 | 142 | } | ||
1854 | 143 | |||
1855 | 144 | UCMenuBar::~UCMenuBar() | ||
1856 | 145 | { | ||
1857 | 146 | } | ||
1858 | 147 | |||
1859 | 148 | /*! | ||
1860 | 149 | * \qmlmethod void MenuBar::appendMenu(Menu menu) | ||
1861 | 150 | * Append a Menu to the MenuBar | ||
1862 | 151 | */ | ||
1863 | 152 | void UCMenuBar::appendMenu(UCMenu *menu) | ||
1864 | 153 | { | ||
1865 | 154 | Q_D(UCMenuBar); | ||
1866 | 155 | insertMenu(d->m_menus.count(), menu); | ||
1867 | 156 | } | ||
1868 | 157 | |||
1869 | 158 | /*! | ||
1870 | 159 | * \qmlmethod void MenuBar::insertMenu(int index, Menu menu) | ||
1871 | 160 | * Insert a Menu to the MenuBar at the specified position | ||
1872 | 161 | */ | ||
1873 | 162 | void UCMenuBar::insertMenu(int index, UCMenu *menu) | ||
1874 | 163 | { | ||
1875 | 164 | Q_D(UCMenuBar); | ||
1876 | 165 | if (!menu) return; | ||
1877 | 166 | |||
1878 | 167 | d->insertMenu(index, menu); | ||
1879 | 168 | Q_EMIT menusChanged(); | ||
1880 | 169 | } | ||
1881 | 170 | |||
1882 | 171 | /*! | ||
1883 | 172 | * \qmlmethod void MenuBar::removeMenu(Menu menu) | ||
1884 | 173 | * Remove a Menu from the MenuBar | ||
1885 | 174 | */ | ||
1886 | 175 | void UCMenuBar::removeMenu(UCMenu *menu) | ||
1887 | 176 | { | ||
1888 | 177 | Q_D(UCMenuBar); | ||
1889 | 178 | if (!menu) return; | ||
1890 | 179 | |||
1891 | 180 | if (d->m_menus.removeOne(menu)) { | ||
1892 | 181 | Q_EMIT menusChanged(); | ||
1893 | 182 | } | ||
1894 | 183 | } | ||
1895 | 184 | /*! | ||
1896 | 185 | * \qmlproperty list<Menu> MenuBar::menus | ||
1897 | 186 | * \default | ||
1898 | 187 | * List of Menus in this MenuBar. | ||
1899 | 188 | */ | ||
1900 | 189 | QQmlListProperty<UCMenu> UCMenuBar::menus() | ||
1901 | 190 | { | ||
1902 | 191 | Q_D(UCMenuBar); | ||
1903 | 192 | return QQmlListProperty<UCMenu>(this, d, | ||
1904 | 193 | &UCMenuBarPrivate::menu_append, | ||
1905 | 194 | &UCMenuBarPrivate::menu_count, | ||
1906 | 195 | &UCMenuBarPrivate::menu_at, | ||
1907 | 196 | &UCMenuBarPrivate::menu_clear); | ||
1908 | 197 | } | ||
1909 | 198 | |||
1910 | 199 | QPlatformMenuBar *UCMenuBar::platformMenuBar() const | ||
1911 | 200 | { | ||
1912 | 201 | Q_D(const UCMenuBar); | ||
1913 | 202 | return d->m_platformBar; | ||
1914 | 203 | } | ||
1915 | 204 | |||
1916 | 205 | void UCMenuBar::classBegin() | ||
1917 | 206 | { | ||
1918 | 207 | } | ||
1919 | 208 | |||
1920 | 209 | void UCMenuBar::componentComplete() | ||
1921 | 210 | { | ||
1922 | 211 | Q_D(UCMenuBar); | ||
1923 | 212 | |||
1924 | 213 | auto parentItem = qobject_cast<QQuickItem*>(parent()); | ||
1925 | 214 | if (parentItem && d->m_platformBar) { | ||
1926 | 215 | d->m_platformBar->handleReparent(parentItem->window()); | ||
1927 | 216 | } | ||
1928 | 217 | } | ||
1929 | 218 | |||
1930 | 219 | PlatformMenuWrapper::PlatformMenuWrapper(UCMenu *target, UCMenuBar* bar) | ||
1931 | 220 | : QObject(bar) | ||
1932 | 221 | , m_bar(bar) | ||
1933 | 222 | , m_target(target) | ||
1934 | 223 | , m_platformItem(target->platformMenu() ? target->platformMenu()->createMenuItem() : Q_NULLPTR) | ||
1935 | 224 | { | ||
1936 | 225 | connect(m_target, &QObject::destroyed, this, &QObject::deleteLater); | ||
1937 | 226 | |||
1938 | 227 | connect(m_target, &UCMenu::visibleChanged, this, &PlatformMenuWrapper::updateVisible); | ||
1939 | 228 | connect(m_target, &UCMenu::textChanged, this, &PlatformMenuWrapper::updateText); | ||
1940 | 229 | connect(m_target, &UCMenu::enabledChanged, this, &PlatformMenuWrapper::updateEnabled); | ||
1941 | 230 | connect(m_target, &UCMenu::iconSourceChanged, this, &PlatformMenuWrapper::updateIcon); | ||
1942 | 231 | connect(m_target, &UCMenu::iconNameChanged, this, &PlatformMenuWrapper::updateIcon); | ||
1943 | 232 | |||
1944 | 233 | if (m_platformItem) { | ||
1945 | 234 | m_platformItem->setMenu(target->platformMenu()); | ||
1946 | 235 | } | ||
1947 | 236 | syncPlatformItem(); | ||
1948 | 237 | } | ||
1949 | 238 | |||
1950 | 239 | void PlatformMenuWrapper::insert(int index) | ||
1951 | 240 | { | ||
1952 | 241 | Q_UNUSED(index); | ||
1953 | 242 | |||
1954 | 243 | auto platformBar = m_bar->platformMenuBar(); | ||
1955 | 244 | if (!platformBar) return; | ||
1956 | 245 | auto platformMenu = m_target->platformMenu(); | ||
1957 | 246 | if (!platformMenu) return; | ||
1958 | 247 | |||
1959 | 248 | platformBar->insertMenu(platformMenu, Q_NULLPTR); | ||
1960 | 249 | } | ||
1961 | 250 | |||
1962 | 251 | void PlatformMenuWrapper::remove() | ||
1963 | 252 | { | ||
1964 | 253 | auto platformBar = m_bar->platformMenuBar(); | ||
1965 | 254 | if (!platformBar) return; | ||
1966 | 255 | auto platformMenu = m_target->platformMenu(); | ||
1967 | 256 | if (!platformMenu) return; | ||
1968 | 257 | |||
1969 | 258 | platformBar->removeMenu(platformMenu); | ||
1970 | 259 | } | ||
1971 | 260 | |||
1972 | 261 | void PlatformMenuWrapper::updateVisible() | ||
1973 | 262 | { | ||
1974 | 263 | if (m_platformItem) m_platformItem->setVisible(m_target->visible()); | ||
1975 | 264 | if (m_target->platformMenu()) m_target->platformMenu()->setVisible(m_target->visible()); | ||
1976 | 265 | } | ||
1977 | 266 | |||
1978 | 267 | void PlatformMenuWrapper::updateEnabled() | ||
1979 | 268 | { | ||
1980 | 269 | if (!m_platformItem) m_platformItem->setEnabled(m_target->isEnabled()); | ||
1981 | 270 | if (m_target->platformMenu()) m_target->platformMenu()->setEnabled(m_target->isEnabled()); | ||
1982 | 271 | } | ||
1983 | 272 | |||
1984 | 273 | void PlatformMenuWrapper::updateText() | ||
1985 | 274 | { | ||
1986 | 275 | if (!m_platformItem) m_platformItem->setText(m_target->text()); | ||
1987 | 276 | if (m_target->platformMenu()) m_target->platformMenu()->setText(m_target->text()); | ||
1988 | 277 | } | ||
1989 | 278 | |||
1990 | 279 | void PlatformMenuWrapper::updateIcon() | ||
1991 | 280 | { | ||
1992 | 281 | QIcon icon; | ||
1993 | 282 | if (!m_target->iconSource().isEmpty()) { | ||
1994 | 283 | icon = QIcon(m_target->iconSource().path()); | ||
1995 | 284 | } else if (!m_target->iconName().isEmpty()) { | ||
1996 | 285 | icon = QIcon::fromTheme(m_target->iconName()); | ||
1997 | 286 | } | ||
1998 | 287 | if (m_target->platformMenu()) m_target->platformMenu()->setIcon(icon); | ||
1999 | 288 | if (!m_platformItem) m_platformItem->setIcon(icon); | ||
2000 | 289 | } | ||
2001 | 290 | |||
2002 | 291 | void PlatformMenuWrapper::syncPlatformItem() | ||
2003 | 292 | { | ||
2004 | 293 | updateVisible(); | ||
2005 | 294 | updateEnabled(); | ||
2006 | 295 | updateText(); | ||
2007 | 296 | updateIcon(); | ||
2008 | 297 | } | ||
2009 | 298 | |||
2010 | 299 | #include "moc_ucmenubar.cpp" | ||
2011 | 0 | 300 | ||
2012 | === added file 'src/Ubuntu/Components/plugin/ucmenubar.h' | |||
2013 | --- src/Ubuntu/Components/plugin/ucmenubar.h 1970-01-01 00:00:00 +0000 | |||
2014 | +++ src/Ubuntu/Components/plugin/ucmenubar.h 2016-06-07 14:25:30 +0000 | |||
2015 | @@ -0,0 +1,60 @@ | |||
2016 | 1 | /* | ||
2017 | 2 | * Copyright 2016 Canonical Ltd. | ||
2018 | 3 | * | ||
2019 | 4 | * This program is free software; you can redistribute it and/or modify | ||
2020 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
2021 | 6 | * the Free Software Foundation; version 3. | ||
2022 | 7 | * | ||
2023 | 8 | * This program is distributed in the hope that it will be useful, | ||
2024 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2025 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2026 | 11 | * GNU Lesser General Public License for more details. | ||
2027 | 12 | * | ||
2028 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
2029 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2030 | 15 | * | ||
2031 | 16 | */ | ||
2032 | 17 | |||
2033 | 18 | #ifndef UCMENUBAR_H | ||
2034 | 19 | #define UCMENUBAR_H | ||
2035 | 20 | |||
2036 | 21 | #include "ucmenu.h" | ||
2037 | 22 | |||
2038 | 23 | #include <QQmlParserStatus> | ||
2039 | 24 | |||
2040 | 25 | class UCMenuBarPrivate; | ||
2041 | 26 | class QPlatformMenuBar; | ||
2042 | 27 | |||
2043 | 28 | class UCMenuBar : public QObject, public QQmlParserStatus | ||
2044 | 29 | { | ||
2045 | 30 | Q_OBJECT | ||
2046 | 31 | Q_INTERFACES(QQmlParserStatus) | ||
2047 | 32 | |||
2048 | 33 | Q_PROPERTY(QQmlListProperty<UCMenu> menus READ menus NOTIFY menusChanged FINAL) | ||
2049 | 34 | Q_CLASSINFO("DefaultProperty", "menus") | ||
2050 | 35 | |||
2051 | 36 | public: | ||
2052 | 37 | explicit UCMenuBar(QObject *parent = 0); | ||
2053 | 38 | ~UCMenuBar(); | ||
2054 | 39 | |||
2055 | 40 | Q_INVOKABLE void appendMenu(UCMenu *menu); | ||
2056 | 41 | Q_INVOKABLE void insertMenu(int index, UCMenu *menu); | ||
2057 | 42 | Q_INVOKABLE void removeMenu(UCMenu *menu); | ||
2058 | 43 | |||
2059 | 44 | QQmlListProperty<UCMenu> menus(); | ||
2060 | 45 | |||
2061 | 46 | QPlatformMenuBar *platformMenuBar() const; | ||
2062 | 47 | |||
2063 | 48 | void classBegin() Q_DECL_OVERRIDE; | ||
2064 | 49 | void componentComplete() Q_DECL_OVERRIDE; | ||
2065 | 50 | |||
2066 | 51 | Q_SIGNALS: | ||
2067 | 52 | void menusChanged(); | ||
2068 | 53 | |||
2069 | 54 | private: | ||
2070 | 55 | Q_DISABLE_COPY(UCMenuBar) | ||
2071 | 56 | Q_DECLARE_PRIVATE(UCMenuBar) | ||
2072 | 57 | QScopedPointer<UCMenuBarPrivate> d_ptr; | ||
2073 | 58 | }; | ||
2074 | 59 | |||
2075 | 60 | #endif // UCMENUBAR_H | ||
2076 | 0 | 61 | ||
2077 | === added file 'src/Ubuntu/Components/plugin/ucmenubar_p.h' | |||
2078 | --- src/Ubuntu/Components/plugin/ucmenubar_p.h 1970-01-01 00:00:00 +0000 | |||
2079 | +++ src/Ubuntu/Components/plugin/ucmenubar_p.h 2016-06-07 14:25:30 +0000 | |||
2080 | @@ -0,0 +1,68 @@ | |||
2081 | 1 | /* | ||
2082 | 2 | * Copyright 2016 Canonical Ltd. | ||
2083 | 3 | * | ||
2084 | 4 | * This program is free software; you can redistribute it and/or modify | ||
2085 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
2086 | 6 | * the Free Software Foundation; version 3. | ||
2087 | 7 | * | ||
2088 | 8 | * This program is distributed in the hope that it will be useful, | ||
2089 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2090 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2091 | 11 | * GNU Lesser General Public License for more details. | ||
2092 | 12 | * | ||
2093 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
2094 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2095 | 15 | * | ||
2096 | 16 | */ | ||
2097 | 17 | |||
2098 | 18 | #ifndef UCMENUBAR_P | ||
2099 | 19 | #define UCMENUBAR_P | ||
2100 | 20 | |||
2101 | 21 | #include "ucmenubar.h" | ||
2102 | 22 | |||
2103 | 23 | class QPlatformMenuBar; | ||
2104 | 24 | |||
2105 | 25 | class UCMenuBarPrivate : public QQuickItemChangeListener | ||
2106 | 26 | { | ||
2107 | 27 | Q_DECLARE_PUBLIC(UCMenuBar) | ||
2108 | 28 | public: | ||
2109 | 29 | UCMenuBarPrivate(UCMenuBar *qq); | ||
2110 | 30 | |||
2111 | 31 | void insertMenu(int index, UCMenu *menu); | ||
2112 | 32 | |||
2113 | 33 | static void menu_append(QQmlListProperty<UCMenu> *prop, UCMenu *o); | ||
2114 | 34 | static int menu_count(QQmlListProperty<UCMenu> *prop); | ||
2115 | 35 | static UCMenu *menu_at(QQmlListProperty<UCMenu> *prop, int index); | ||
2116 | 36 | static void menu_clear(QQmlListProperty<UCMenu> *prop); | ||
2117 | 37 | |||
2118 | 38 | UCMenuBar* q_ptr; | ||
2119 | 39 | QPlatformMenuBar* m_platformBar; | ||
2120 | 40 | QVector<UCMenu*> m_menus; | ||
2121 | 41 | }; | ||
2122 | 42 | |||
2123 | 43 | class PlatformMenuWrapper : public QObject | ||
2124 | 44 | { | ||
2125 | 45 | Q_OBJECT | ||
2126 | 46 | public: | ||
2127 | 47 | PlatformMenuWrapper(UCMenu *target, UCMenuBar *bar); | ||
2128 | 48 | |||
2129 | 49 | void insert(int index); | ||
2130 | 50 | void remove(); | ||
2131 | 51 | |||
2132 | 52 | public Q_SLOTS: | ||
2133 | 53 | void updateVisible(); | ||
2134 | 54 | void updateEnabled(); | ||
2135 | 55 | void updateText(); | ||
2136 | 56 | void updateIcon(); | ||
2137 | 57 | void updateShortcut(); | ||
2138 | 58 | |||
2139 | 59 | private: | ||
2140 | 60 | void syncPlatformItem(); | ||
2141 | 61 | |||
2142 | 62 | UCMenuBar* m_bar; | ||
2143 | 63 | UCMenu* m_target; | ||
2144 | 64 | QPlatformMenuItem* m_platformItem; | ||
2145 | 65 | }; | ||
2146 | 66 | |||
2147 | 67 | #endif // UCMENUBAR_P | ||
2148 | 68 | |||
2149 | 0 | 69 | ||
2150 | === modified file 'src/Ubuntu/Components/qmldir' | |||
2151 | --- src/Ubuntu/Components/qmldir 2016-02-16 11:39:32 +0000 | |||
2152 | +++ src/Ubuntu/Components/qmldir 2016-06-07 14:25:30 +0000 | |||
2153 | @@ -1,6 +1,5 @@ | |||
2154 | 1 | module Ubuntu.Components | 1 | module Ubuntu.Components |
2155 | 2 | plugin UbuntuComponents | 2 | plugin UbuntuComponents |
2156 | 3 | ActionList 0.1 1.2/ActionList.qml | ||
2157 | 4 | ToolbarItems 0.1 1.2/ToolbarItems.qml | 3 | ToolbarItems 0.1 1.2/ToolbarItems.qml |
2158 | 5 | ToolbarButton 0.1 1.2/ToolbarButton.qml | 4 | ToolbarButton 0.1 1.2/ToolbarButton.qml |
2159 | 6 | MainView 0.1 1.2/MainView.qml | 5 | MainView 0.1 1.2/MainView.qml |
2160 | @@ -40,7 +39,6 @@ | |||
2161 | 40 | DateUtils 0.1 1.2/dateUtils.js | 39 | DateUtils 0.1 1.2/dateUtils.js |
2162 | 41 | 40 | ||
2163 | 42 | #version 1.0 | 41 | #version 1.0 |
2164 | 43 | ActionList 1.0 1.2/ActionList.qml | ||
2165 | 44 | ToolbarItems 1.0 1.2/ToolbarItems.qml | 42 | ToolbarItems 1.0 1.2/ToolbarItems.qml |
2166 | 45 | ToolbarButton 1.0 1.2/ToolbarButton.qml | 43 | ToolbarButton 1.0 1.2/ToolbarButton.qml |
2167 | 46 | MainView 1.0 1.2/MainView.qml | 44 | MainView 1.0 1.2/MainView.qml |
2168 | @@ -95,7 +93,6 @@ | |||
2169 | 95 | ################################################# | 93 | ################################################# |
2170 | 96 | #version 1.3 | 94 | #version 1.3 |
2171 | 97 | ActionBar 1.3 1.3/ActionBar.qml | 95 | ActionBar 1.3 1.3/ActionBar.qml |
2172 | 98 | ActionList 1.3 1.3/ActionList.qml | ||
2173 | 99 | AdaptivePageLayout 1.3 1.3/AdaptivePageLayout.qml | 96 | AdaptivePageLayout 1.3 1.3/AdaptivePageLayout.qml |
2174 | 100 | PageColumnsLayout 1.3 1.3/PageColumnsLayout.qml | 97 | PageColumnsLayout 1.3 1.3/PageColumnsLayout.qml |
2175 | 101 | PageColumn 1.3 1.3/PageColumn.qml | 98 | PageColumn 1.3 1.3/PageColumn.qml |