on xenial help sign in
Better API for indicator menu select activation
commitde24225bd5bfbcb834bd18d33409dda1da37b9a0 authorNick Dedekind <nicholas.dedekind@gmail.com> dateWed 19 Jun 2013, 10:45 (13 years ago) parent1290955
5 files changed+31−22
modules/Unity/Indicators/qml/BasicMenu.qml+4−7 modules/Unity/Indicators/qml/IndicatorPage.qml+5−1 modules/Unity/Indicators/qml/MenuFactory.qml+9−7 modules/Unity/Indicators/qml/messaging/HeroMessage.qml+5−5 modules/Unity/Indicators/qml/messaging/MessageItem.qml+8−2
modules/Unity/Indicators/qml/BasicMenu.qml+4−7
@@ -23,11 +23,14 @@ import Ubuntu.Components.ListItems 0.1 as ListItem
2323ListItem.Standard {
2424 id: _priv
2525
26− property bool listViewIsCurrentItem : false
26+ property bool menuActivated : false
2727 property QtObject menu
2828 property QtObject actionGroup
2929 property alias color: __bg.color
3030
31+ signal activateMenu()
32+ signal deactivateMenu()
33+
3134 showDivider: false
3235 __foregroundColor: "#e8e1d0"
3336
@@ -42,10 +45,4 @@ ListItem.Standard {
4245 color: "#221e1c"
4346 z: -1
4447 }
45−
46− function listViewSelectItem(targetIndex) {
47− if (__menuFactory != undefined) {
48− return __menuFactory.selectItem(targetIndex)
49− }
50− }
5148}
modules/Unity/Indicators/qml/IndicatorPage.qml+5−1
@@ -134,7 +134,11 @@ IndicatorBase {
134134 height: implicitHeight
135135 menu: model
136136
137− onSelectItem: item.ListView.view.currentIndex = targetIndex
137+ Connections {
138+ target : factory
139+ onActivated: item.ListView.view.currentIndex = index
140+ onDeactivated: item.ListView.view.currentIndex = -1
141+ }
138142 }
139143 }
140144 }
modules/Unity/Indicators/qml/MenuFactory.qml+9−7
@@ -33,7 +33,8 @@ Item {
3333
3434 implicitHeight: (__loader.status === Loader.Ready) ? __loader.item.implicitHeight : 0
3535
36− signal selectItem(int targetIndex)
36+ signal activated()
37+ signal deactivated()
3738
3839 property var _map: {
3940 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
@@ -95,12 +96,13 @@ Item {
9596 return undefined;
9697 }
9798
98− onStatusChanged: {
99− if (status == Loader.Ready) {
100− item.listViewIsCurrentItem = Qt.binding(function() { return isCurrentItem; });
101− item.actionGroup = Qt.binding(function() { return __menuFactory.actionGroup; });
102− item.menu = Qt.binding(function() { return __menuFactory.menu; });
103− }
99+ onLoaded: {
100+ item.menuActivated = Qt.binding(function() { return isCurrentItem; });
101+ item.actionGroup = Qt.binding(function() { return __menuFactory.actionGroup; });
102+ item.menu = Qt.binding(function() { return __menuFactory.menu; });
103+
104+ item.activateMenu.connect(function() { __menuFactory.activated(); });
105+ item.deactivateMenu.connect(function() { __menuFactory.deactivated(); });
104106 }
105107 }
106108}
modules/Unity/Indicators/qml/messaging/HeroMessage.qml+5−5
@@ -51,17 +51,17 @@ Indicators.BasicMenu {
5151
5252 onAppIconClicked: {
5353 if (action && action.valid) {
54− listViewSelectItem(-1)
54+ deactivateMenu()
5555 action.activate(true)
5656 }
5757 }
5858 }
5959
6060 onClicked: {
61− if (listViewIsCurrentItem) {
62− listViewSelectItem(-1)
61+ if (menuActivated) {
62+ deactivateMenu()
6363 } else {
64− listViewSelectItem(index)
64+ activateMenu()
6565 }
6666 }
6767
@@ -79,7 +79,7 @@ Indicators.BasicMenu {
7979
8080 states: State {
8181 name: "expanded"
82− when: listViewIsCurrentItem
82+ when: menuActivated
8383
8484 PropertyChanges {
8585 target: __heroMessage
modules/Unity/Indicators/qml/messaging/MessageItem.qml+8−2
@@ -39,8 +39,8 @@ Indicators.BasicMenu {
3939 // property will be propagated to the __contents.item at any time
4040 Binding {
4141 target: __contents.item
42− property: "listViewIsCurrentItem"
43− value: listViewIsCurrentItem
42+ property: "menuActivated"
43+ value: menuActivated
4444 when: (__contents.status == Loader.Ready)
4545 }
4646
@@ -64,6 +64,12 @@ Indicators.BasicMenu {
6464 value: actionsDescription
6565 when: (__contents.status == Loader.Ready)
6666 }
67+
68+ Connections {
69+ target: __contents.item ? __contents.item : null
70+ onActivateMenu: activateMenu()
71+ onDeactivateMenu: deactivateMenu()
72+ }
6773 }
6874
6975