on xenial help sign in
merge lp:~aacid/unity8/create_less_components
cf2fee6Lukáš Tinkl
qml/ApplicationMenus/MenuBar.qml+13−12
@@ -104,6 +104,11 @@ Item {
104 onModelReset: d.firstInvisibleIndex = undefined
104 onModelReset: d.firstInvisibleIndex = undefined
105 }
105 }
106
106
107+ Component {
108+ id: menuComponent
109+ MenuPopup { }
110+ }
111+
107 Repeater {
112 Repeater {
108 id: rowRepeater
113 id: rowRepeater
109
114
@@ -127,7 +132,14 @@ Item {
127
132
128 function show() {
133 function show() {
129 if (!__popup) {
134 if (!__popup) {
130− __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
135+ __popup = menuComponent.createObject(root,
136+ {
137+ objectName: visualItem.objectName + "-menu",
138+ desiredX: Qt.binding(function() { return visualItem.x - units.gu(1); }),
139+ desiredY: Qt.binding(function() { return root.height; }),
140+ unityMenuModel: Qt.binding(function() { return root.unityMenuModel.submenu(visualItem.__ownIndex); })
141+ });
142+ __popup.reset();
131 __popup.childActivated.connect(dismiss);
143 __popup.childActivated.connect(dismiss);
132 // force the current item to be the newly popped up menu
144 // force the current item to be the newly popped up menu
133 } else {
145 } else {
@@ -170,17 +182,6 @@ Item {
170 onDismissAll: visualItem.dismiss()
182 onDismissAll: visualItem.dismiss()
171 }
183 }
172
184
173− Component {
174− id: menuComponent
175− MenuPopup {
176− desiredX: visualItem.x - units.gu(1)
177− desiredY: parent.height
178− unityMenuModel: root.unityMenuModel.submenu(visualItem.__ownIndex)
179−
180− Component.onCompleted: reset();
181− }
182− }
183−
184 RowLayout {
185 RowLayout {
185 id: column
186 id: column
186 spacing: units.gu(1)
187 spacing: units.gu(1)
qml/ApplicationMenus/MenuItem.qml+6−6
@@ -34,7 +34,7 @@ ActionItem {
34 val += units.gu(1) + title.contentWidth;
34 val += units.gu(1) + title.contentWidth;
35 if (hasSubmenu) {
35 if (hasSubmenu) {
36 val += units.gu(1) + chevronIcon.width;
36 val += units.gu(1) + chevronIcon.width;
37− } else if (shortcut != undefined) {
37+ } else if (menuData && menuData.shortcut != undefined) {
38 val += units.gu(3) + shortcutLabel.contentWidth;
38 val += units.gu(3) + shortcutLabel.contentWidth;
39 }
39 }
40 return val + units.gu(1);
40 return val + units.gu(1);
@@ -49,9 +49,9 @@ ActionItem {
49 enabled: root.enabled
49 enabled: root.enabled
50
50
51 // FIXME - SDK Action:text modifies menu text with html underline for mnemonic
51 // FIXME - SDK Action:text modifies menu text with html underline for mnemonic
52− text: menuData.label.replace("_", "&").replace("<u>", "&").replace("</u>", "")
52+ text: menuData ? menuData.label.replace("_", "&").replace("<u>", "&").replace("</u>", "") : ""
53− checkable: menuData.isCheck || menuData.isRadio
53+ checkable: menuData && (menuData.isCheck || menuData.isRadio)
54− checked: menuData.isToggled
54+ checked: menuData && menuData.isToggled
55 }
55 }
56
56
57 width: {
57 width: {
@@ -127,8 +127,8 @@ ActionItem {
127 color: enabled ? theme.palette.normal.overlaySecondaryText :
127 color: enabled ? theme.palette.normal.overlaySecondaryText :
128 theme.palette.disabled.overlaySecondaryText
128 theme.palette.disabled.overlaySecondaryText
129
129
130− visible: menuData.shortcut != undefined && !root.hasSubmenu && QuickUtils.keyboardAttached
130+ visible: menuData && menuData.shortcut != undefined && !root.hasSubmenu && QuickUtils.keyboardAttached
131− text: menuData.shortcut ? menuData.shortcut : ""
131+ text: menuData && menuData.shortcut ? menuData.shortcut : ""
132 }
132 }
133 }
133 }
134
134
qml/ApplicationMenus/MenuPopup.qml+75−73
@@ -276,6 +276,79 @@ UbuntuShape {
276 }
276 }
277 }
277 }
278
278
279+ Component {
280+ id: separatorComponent
281+ ListItems.ThinDivider {
282+ // Parent will be loader
283+ objectName: parent.objectName + "-separator"
284+ implicitHeight: units.dp(2)
285+ }
286+ }
287+
288+ Component {
289+ id: menuItemComponent
290+ MenuItem {
291+ // Parent will be loader
292+ id: menuItem
293+ menuData: parent.__menuData
294+ objectName: parent.objectName + "-actionItem"
295+
296+ width: MathUtils.clamp(implicitWidth, d.__minimumWidth, d.__maximumWidth)
297+
298+ action.onTriggered: {
299+ submenuHoverTimer.stop();
300+
301+ d.currentItem = parent;
302+
303+ if (hasSubmenu) {
304+ if (!popup) {
305+ var model = root.unityMenuModel.submenu(__ownIndex);
306+ popup = submenuComponent.createObject(focusScope, {
307+ objectName: parent.objectName + "-",
308+ unityMenuModel: model,
309+ substractWidth: true,
310+ desiredX: Qt.binding(function() { return root.width }),
311+ desiredY: Qt.binding(function() {
312+ var dummy = listView.contentY; // force a recalc on contentY change.
313+ return mapToItem(container, 0, y).y;
314+ })
315+ });
316+ popup.retreat.connect(function() {
317+ popup.destroy();
318+ popup = null;
319+ menuItem.forceActiveFocus();
320+ });
321+ popup.childActivated.connect(function() {
322+ popup.destroy();
323+ popup = null;
324+ root.childActivated();
325+ });
326+ } else if (popup) {
327+ popup.visible = true;
328+ }
329+ } else {
330+ root.unityMenuModel.activate(__ownIndex);
331+ root.childActivated();
332+ }
333+ }
334+
335+ Connections {
336+ target: d
337+ onCurrentIndexChanged: {
338+ if (popup && d.currentIndex != __ownIndex) {
339+ popup.visible = false;
340+ }
341+ }
342+ onDismissAll: {
343+ if (popup) {
344+ popup.destroy();
345+ popup = null;
346+ }
347+ }
348+ }
349+ }
350+ }
351+
279 ColumnLayout {
352 ColumnLayout {
280 id: menuColumn
353 id: menuColumn
281 spacing: 0
354 spacing: 0
@@ -289,6 +362,8 @@ UbuntuShape {
289 id: loader
362 id: loader
290 objectName: root.objectName + "-item" + __ownIndex
363 objectName: root.objectName + "-item" + __ownIndex
291
364
365+ property Item popup: null
366+ property var __menuData: model
292 property int __ownIndex: index
367 property int __ownIndex: index
293 property bool __isSeparator: model.isSeparator
368 property bool __isSeparator: model.isSeparator
294
369
@@ -301,80 +376,7 @@ UbuntuShape {
301 return menuItemComponent;
376 return menuItemComponent;
302 }
377 }
303
378
304− property Item popup: null
305−
306 Layout.fillWidth: true
379 Layout.fillWidth: true
307−
308− Component {
309− id: menuItemComponent
310− MenuItem {
311− id: menuItem
312− menuData: model
313− objectName: loader.objectName + "-actionItem"
314−
315− width: MathUtils.clamp(implicitWidth, d.__minimumWidth, d.__maximumWidth)
316−
317− action.onTriggered: {
318− submenuHoverTimer.stop();
319−
320− d.currentItem = loader;
321−
322− if (hasSubmenu) {
323− if (!popup) {
324− var model = root.unityMenuModel.submenu(__ownIndex);
325− popup = submenuComponent.createObject(focusScope, {
326− objectName: loader.objectName + "-",
327− unityMenuModel: model,
328− substractWidth: true,
329− desiredX: Qt.binding(function() { return root.width }),
330− desiredY: Qt.binding(function() {
331− var dummy = listView.contentY; // force a recalc on contentY change.
332− return mapToItem(container, 0, y).y;
333− })
334− });
335− popup.retreat.connect(function() {
336− popup.destroy();
337− popup = null;
338− menuItem.forceActiveFocus();
339− });
340− popup.childActivated.connect(function() {
341− popup.destroy();
342− popup = null;
343− root.childActivated();
344− });
345− } else if (popup) {
346− popup.visible = true;
347− }
348− } else {
349− root.unityMenuModel.activate(__ownIndex);
350− root.childActivated();
351− }
352− }
353−
354− Connections {
355− target: d
356− onCurrentIndexChanged: {
357− if (popup && d.currentIndex != __ownIndex) {
358− popup.visible = false;
359− }
360− }
361− onDismissAll: {
362− if (popup) {
363− popup.destroy();
364− popup = null;
365− }
366− }
367− }
368− }
369− }
370−
371− Component {
372− id: separatorComponent
373− ListItems.ThinDivider {
374− objectName: loader.objectName + "-separator"
375− implicitHeight: units.dp(2)
376− }
377− }
378 }
380 }
379
381
380 }
382 }
tests/qmltests/ApplicationMenus/tst_MenuBar.qml+2−2
@@ -81,10 +81,10 @@ Item {
81 name: "MenuBar"
81 name: "MenuBar"
82 when: windowShown
82 when: windowShown
83
83
84− function cleanup() {
84+ function init() {
85 menuBar.dismiss();
85 menuBar.dismiss();
86 activatedSpy.clear();
86 activatedSpy.clear();
87− menuBackend.modelData = null;
87+ waitForRendering(menuBar);
88 }
88 }
89
89
90 function test_mouseNavigation() {
90 function test_mouseNavigation() {