on xenial help sign in
Signal aboutToShow (LP: #1664578)
c196bf9Albert Astals Cid
debian/control+1−1
@@ -28,7 +28,7 @@ Build-Depends: cmake,
28 liblightdm-qt5-3-dev,
28 liblightdm-qt5-3-dev,
29 libpam0g-dev,
29 libpam0g-dev,
30 libpulse-dev,
30 libpulse-dev,
31− libqmenumodel-dev (>= 0.2.11),
31+ libqmenumodel-dev (>= 0.2.12),
32 libqt5svg5-dev,
32 libqt5svg5-dev,
33 libqt5xmlpatterns5-dev,
33 libqt5xmlpatterns5-dev,
34 libsystemsettings-dev,
34 libsystemsettings-dev,
qml/ApplicationMenus/MenuBar.qml+3−1
@@ -136,6 +136,7 @@ Item {
136
136
137 function show() {
137 function show() {
138 if (!__popup) {
138 if (!__popup) {
139+ root.unityMenuModel.aboutToShow(visualItem.__ownIndex);
139 __popup = menuComponent.createObject(root,
140 __popup = menuComponent.createObject(root,
140 {
141 {
141 objectName: visualItem.objectName + "-menu",
142 objectName: visualItem.objectName + "-menu",
@@ -146,7 +147,8 @@ Item {
146 __popup.reset();
147 __popup.reset();
147 __popup.childActivated.connect(dismiss);
148 __popup.childActivated.connect(dismiss);
148 // force the current item to be the newly popped up menu
149 // force the current item to be the newly popped up menu
149− } else {
150+ } else if (!__popup.visible) {
151+ root.unityMenuModel.aboutToShow(visualItem.__ownIndex);
150 __popup.show();
152 __popup.show();
151 }
153 }
152 d.currentItem = visualItem;
154 d.currentItem = visualItem;
qml/ApplicationMenus/MenuPopup.qml+3−1
@@ -302,6 +302,7 @@ UbuntuShape {
302
302
303 if (hasSubmenu) {
303 if (hasSubmenu) {
304 if (!popup) {
304 if (!popup) {
305+ root.unityMenuModel.aboutToShow(__ownIndex);
305 var model = root.unityMenuModel.submenu(__ownIndex);
306 var model = root.unityMenuModel.submenu(__ownIndex);
306 popup = submenuComponent.createObject(focusScope, {
307 popup = submenuComponent.createObject(focusScope, {
307 objectName: parent.objectName + "-",
308 objectName: parent.objectName + "-",
@@ -323,7 +324,8 @@ UbuntuShape {
323 popup = null;
324 popup = null;
324 root.childActivated();
325 root.childActivated();
325 });
326 });
326− } else if (popup) {
327+ } else if (!popup.visible) {
328+ root.unityMenuModel.aboutToShow(__ownIndex);
327 popup.visible = true;
329 popup.visible = true;
328 }
330 }
329 } else {
331 } else {
qml/Panel/Panel.qml+7
@@ -296,6 +296,13 @@ Item {
296 }
296 }
297
297
298 pageDelegate: PanelMenuPage {
298 pageDelegate: PanelMenuPage {
299+ readonly property bool isCurrent: modelIndex == __applicationMenus.currentMenuIndex
300+ onIsCurrentChanged: {
301+ if (isCurrent && menuModel) {
302+ menuModel.aboutToShow(modelIndex);
303+ }
304+ }
305+
299 menuModel: __applicationMenus.model
306 menuModel: __applicationMenus.model
300 submenuIndex: modelIndex
307 submenuIndex: modelIndex
301
308
qml/Panel/PanelMenu.qml+1
@@ -46,6 +46,7 @@ Showable {
46 readonly property bool fullyClosed: unitProgress == 0
46 readonly property bool fullyClosed: unitProgress == 0
47 readonly property alias expanded: bar.expanded
47 readonly property alias expanded: bar.expanded
48 readonly property int barWidth: Math.min(bar.width, bar.implicitWidth)
48 readonly property int barWidth: Math.min(bar.width, bar.implicitWidth)
49+ readonly property alias currentMenuIndex: bar.currentItemIndex
49
50
50 signal showTapped()
51 signal showTapped()
51
52
qml/Panel/PanelMenuPage.qml+1
@@ -192,6 +192,7 @@ PageStack {
192 if (item.hasOwnProperty("clicked")) {
192 if (item.hasOwnProperty("clicked")) {
193 item.clicked.connect(function() {
193 item.clicked.connect(function() {
194 if (model.hasSubmenu) {
194 if (model.hasSubmenu) {
195+ page.menuModel.aboutToShow(modelIndex);
195 root.push(pageComponent, {
196 root.push(pageComponent, {
196 "isSubmenu": true,
197 "isSubmenu": true,
197 "title": model.label.replace(/_|&/, ""),
198 "title": model.label.replace(/_|&/, ""),
tests/mocks/QMenuModel/unitymenumodel.cpp+5
@@ -273,6 +273,11 @@ void UnityMenuModel::activate(int row, const QVariant&)
273 Q_EMIT activated(rd[roleNames()[ActionRole]].toString());
273 Q_EMIT activated(rd[roleNames()[ActionRole]].toString());
274}
274}
275
275
276+void UnityMenuModel::aboutToShow(int index)
277+{
278+ Q_EMIT aboutToShowCalled(index);
279+}
280+
276void UnityMenuModel::changeState(int, const QVariant&)
281void UnityMenuModel::changeState(int, const QVariant&)
277{
282{
278}
283}
tests/mocks/QMenuModel/unitymenumodel.h+2
@@ -73,6 +73,7 @@ public:
73 Q_INVOKABLE QVariant get(int row, const QByteArray &role);
73 Q_INVOKABLE QVariant get(int row, const QByteArray &role);
74
74
75 Q_INVOKABLE void activate(int index, const QVariant& parameter = QVariant());
75 Q_INVOKABLE void activate(int index, const QVariant& parameter = QVariant());
76+ Q_INVOKABLE void aboutToShow(int index);
76 Q_INVOKABLE void changeState(int index, const QVariant& parameter);
77 Q_INVOKABLE void changeState(int index, const QVariant& parameter);
77
78
78 void registerAction(UnityMenuAction* action);
79 void registerAction(UnityMenuAction* action);
@@ -87,6 +88,7 @@ Q_SIGNALS:
87
88
88 // Internal mock usage
89 // Internal mock usage
89 void modelDataChanged();
90 void modelDataChanged();
91+ void aboutToShowCalled(int index);
90
92
91 void activated(const QString& action);
93 void activated(const QString& action);
92
94
tests/qmltests/ApplicationMenus/tst_MenuBar.qml+43
@@ -76,6 +76,12 @@ Item {
76 signalName: "activated"
76 signalName: "activated"
77 }
77 }
78
78
79+ SignalSpy {
80+ id: aboutToShowCalledSpy
81+ target: menuBackend
82+ signalName: "aboutToShowCalled"
83+ }
84+
79 UnityTestCase {
85 UnityTestCase {
80 id: testCase
86 id: testCase
81 name: "MenuBar"
87 name: "MenuBar"
@@ -115,6 +121,43 @@ Item {
115 compare(menuItem0.popupVisible, true, "Popup should be visible");
121 compare(menuItem0.popupVisible, true, "Popup should be visible");
116 }
122 }
117
123
124+ function test_aboutToShow() {
125+ menuBackend.modelData = appMenuData.generateTestData(3,3,0,0, "menu");
126+ wait(50) // wait for row to build
127+ var priv = findInvisibleChild(menuBar, "d");
128+
129+ var menuItem0 = findChild(menuBar, "menuBar-item0");
130+ var menuItem1 = findChild(menuBar, "menuBar-item1");
131+
132+ aboutToShowCalledSpy.clear();
133+ menuItem0.show();
134+ compare(aboutToShowCalledSpy.count, 1);
135+
136+ menuItem0.show();
137+ // It's already shown so nothing happens
138+ compare(aboutToShowCalledSpy.count, 1);
139+
140+ menuItem0.hide();
141+ menuItem0.show();
142+ compare(aboutToShowCalledSpy.count, 2);
143+
144+ menuItem0.dismiss();
145+ menuItem0.show();
146+ compare(aboutToShowCalledSpy.count, 3);
147+
148+ menuItem1.show();
149+ compare(aboutToShowCalledSpy.count, 4);
150+
151+ menuItem0.show();
152+ compare(aboutToShowCalledSpy.count, 5);
153+
154+ compare(aboutToShowCalledSpy.signalArguments[0][0], 0);
155+ compare(aboutToShowCalledSpy.signalArguments[1][0], 0);
156+ compare(aboutToShowCalledSpy.signalArguments[2][0], 0);
157+ compare(aboutToShowCalledSpy.signalArguments[3][0], 1);
158+ compare(aboutToShowCalledSpy.signalArguments[4][0], 0);
159+ }
160+
118 function test_keyboardNavigation_RightKeySelectsNextMenuItem(data) {
161 function test_keyboardNavigation_RightKeySelectsNextMenuItem(data) {
119 menuBackend.modelData = appMenuData.generateTestData(3,3,0,0, "menu");
162 menuBackend.modelData = appMenuData.generateTestData(3,3,0,0, "menu");
120 var priv = findInvisibleChild(menuBar, "d");
163 var priv = findInvisibleChild(menuBar, "d");
tests/qmltests/ApplicationMenus/tst_MenuPopup.qml+34−9
@@ -59,18 +59,13 @@ Item {
59 }}
59 }}
60 ]
60 ]
61 }
61 }
62−
63− Binding {
64− target: activatedSpy
65− property: "target"
66− value: unityMenuModel
67− }
68 }
62 }
69 }
63 }
70
64
71 SignalSpy {
65 SignalSpy {
72− id: activatedSpy
66+ id: aboutToShowCalledSpy
67+ target: loader.item ? loader.item.unityMenuModel : undefined
73− signalName: "activated"
68+ signalName: "aboutToShowCalled"
74 }
69 }
75
70
76 UnityTestCase {
71 UnityTestCase {
@@ -88,7 +83,6 @@ Item {
88 function cleanup() {
83 function cleanup() {
89 menu.reset();
84 menu.reset();
90 wait(100); // let the page dismiss
85 wait(100); // let the page dismiss
91− activatedSpy.clear();
92
86
93 loader.active = false;
87 loader.active = false;
94 tryCompare(loader, "item", null);
88 tryCompare(loader, "item", null);
@@ -194,6 +188,37 @@ Item {
194 compare(priv.currentItem, item0, "CurrentItem should have moved to item 2");
188 compare(priv.currentItem, item0, "CurrentItem should have moved to item 2");
195 }
189 }
196
190
191+ function test_aboutToShow() {
192+ menu.unityMenuModel.modelData = appMenuData.generateTestData(3,3,1,0,"menu",false);
193+
194+ var item0 = findChild(menu, "menu-item0");
195+ var item1 = findChild(menu, "menu-item1");
196+ var item2 = findChild(menu, "menu-item2");
197+
198+ aboutToShowCalledSpy.clear();
199+
200+ mouseMove(item0, item0.width/2, item0.height/2);
201+ tryCompare(aboutToShowCalledSpy, "count", 1);
202+
203+ mouseMove(item1, item0.width/2, item0.height/2);
204+ tryCompare(aboutToShowCalledSpy, "count", 2);
205+
206+ mouseMove(item2, item0.width/2, item0.height/2);
207+ tryCompare(aboutToShowCalledSpy, "count", 3);
208+
209+ mouseMove(item0, item0.width/2, item0.height/2);
210+ tryCompare(aboutToShowCalledSpy, "count", 4);
211+
212+ item0.item.trigger();
213+ // it's already visible
214+ tryCompare(aboutToShowCalledSpy, "count", 4);
215+
216+ compare(aboutToShowCalledSpy.signalArguments[0][0], 0);
217+ compare(aboutToShowCalledSpy.signalArguments[1][0], 1);
218+ compare(aboutToShowCalledSpy.signalArguments[2][0], 2);
219+ compare(aboutToShowCalledSpy.signalArguments[3][0], 0);
220+ }
221+
197 function test_keyboardNavigation_RightKeyEntersSubMenu() {
222 function test_keyboardNavigation_RightKeyEntersSubMenu() {
198 menu.unityMenuModel.modelData = appMenuData.generateTestData(3,3,1,0,"menu",false);
223 menu.unityMenuModel.modelData = appMenuData.generateTestData(3,3,1,0,"menu",false);
199
224
tests/qmltests/Panel/tst_Panel.qml+34
@@ -57,6 +57,11 @@ PanelTest {
57 color: "darkgrey"
57 color: "darkgrey"
58 }
58 }
59
59
60+ SignalSpy {
61+ id: aboutToShowCalledSpy
62+ signalName: "aboutToShowCalled"
63+ }
64+
60 RowLayout {
65 RowLayout {
61 anchors.fill: parent
66 anchors.fill: parent
62 anchors.margins: units.gu(1)
67 anchors.margins: units.gu(1)
@@ -838,5 +843,34 @@ PanelTest {
838 keyClick(Qt.Key_Escape);
843 keyClick(Qt.Key_Escape);
839 tryCompare(panel.indicators, "fullyClosed", true);
844 tryCompare(panel.indicators, "fullyClosed", true);
840 }
845 }
846+
847+ function test_aboutToShowMenu() {
848+ waitForRendering(panel);
849+
850+ aboutToShowCalledSpy.target = panel.applicationMenus.model
851+ aboutToShowCalledSpy.clear();
852+
853+ var indicatorsBar = findChild(panel.applicationMenus, "indicatorsBar");
854+
855+ PanelState.title = "Fake Title"
856+ pullDownApplicationsMenu();
857+ compare(aboutToShowCalledSpy.count, 1);
858+
859+ keyClick(Qt.Key_Right);
860+ tryCompare(indicatorsBar, "currentItemIndex", 1);
861+ compare(aboutToShowCalledSpy.count, 2);
862+
863+ compare(aboutToShowCalledSpy.signalArguments[0][0], 0);
864+ compare(aboutToShowCalledSpy.signalArguments[1][0], 1);
865+
866+ keyClick(Qt.Key_Tab);
867+ keyClick(Qt.Key_Tab);
868+
869+ aboutToShowCalledSpy.target = panel.applicationMenus.model.submenu(1);
870+ aboutToShowCalledSpy.clear();
871+
872+ keyClick(Qt.Key_Enter);
873+ compare(aboutToShowCalledSpy.count, 1);
874+ }
841 }
875 }
842}
876}