@@ -25,12 +25,13 @@ Item {
2525 id: root
2626 objectName: "menuBar"
2727
28+ // set from outside
2829 property alias unityMenuModel: rowRepeater.model
29−
30− readonly property bool valid: rowRepeater.count > 0
31−
3230 property bool enableKeyFilter: false
31+ property real overflowWidth: width
3332
33+ // read from outside
34+ readonly property bool valid: rowRepeater.count > 0
3435 readonly property bool showRequested: d.longAltPressed || d.currentItem != null
3536
3637 implicitWidth: row.width
@@ -65,168 +66,185 @@ Item {
6566 onPressed: d.dismissAll()
6667 }
6768
68− Item {
69− id: clippingItem
70−
71− height: root.height
72− width: root.width
73− clip: true
74−
75− Row {
76− id: row
77− spacing: units.gu(2)
78− height: parent.height
79−
80− ActionContext {
81− id: menuBarContext
82− objectName: "barContext"
83− active: !d.currentItem && enableKeyFilter
84− }
85−
86− Repeater {
87− id: rowRepeater
88−
89− Item {
90− id: visualItem
91− objectName: root.objectName + "-item" + __ownIndex
69+ Rectangle {
70+ anchors.fill: row
71+ color: Qt.rgba(1,0,0,0.4)
72+ }
9273
93− readonly property int __ownIndex: index
94− property Item __popup: null;
95− property bool popupVisible: __popup && __popup.visible
74+ Row {
75+ id: row
76+ spacing: units.gu(2)
77+ height: parent.height
9678
97− implicitWidth: column.implicitWidth
98− implicitHeight: row.height
99− enabled: model.sensitive
79+ ActionContext {
80+ id: menuBarContext
81+ objectName: "barContext"
82+ active: !d.currentItem && enableKeyFilter
83+ }
10084
101− function show() {
102− if (!__popup) {
103− __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
104− // force the current item to be the newly popped up menu
105− } else {
106− __popup.show();
107− }
108− d.currentItem = visualItem;
85+ Repeater {
86+ id: rowRepeater
87+
88+ Item {
89+ id: visualItem
90+ objectName: root.objectName + "-item" + __ownIndex
91+
92+ readonly property int __ownIndex: index
93+ property Item __popup: null;
94+ property bool popupVisible: __popup && __popup.visible
95+ property bool shouldDisplay: x + width + ((index < rowRepeater.count-1) ? units.gu(1) : 0) <
96+ (root.overflowWidth - (overflowButton.visible ? overflowButton.width : 0))
97+
98+ implicitWidth: column.implicitWidth
99+ implicitHeight: row.height
100+ enabled: model.sensitive && shouldDisplay
101+ opacity: shouldDisplay ? 1 : 0
102+
103+ function show() {
104+ if (!__popup) {
105+ __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
106+ // force the current item to be the newly popped up menu
107+ } else {
108+ __popup.show();
109109 }
110− function hide() {
111− if (__popup) {
112− __popup.hide();
110+ d.currentItem = visualItem;
111+ }
112+ function hide() {
113+ if (__popup) {
114+ __popup.hide();
113115
114− if (d.currentItem === visualItem) {
115− d.currentItem = null;
116− }
116+ if (d.currentItem === visualItem) {
117+ d.currentItem = null;
117118 }
118119 }
119− function dismiss() {
120− if (__popup) {
121− __popup.destroy();
122− __popup = null;
120+ }
121+ function dismiss() {
122+ if (__popup) {
123+ __popup.destroy();
124+ __popup = null;
123125
124− if (d.currentItem === visualItem) {
125− d.currentItem = null;
126− }
126+ if (d.currentItem === visualItem) {
127+ d.currentItem = null;
127128 }
128129 }
130+ }
129131
130− Connections {
131− target: d
132− onDismissAll: visualItem.dismiss()
133− }
132+ Connections {
133+ target: d
134+ onDismissAll: visualItem.dismiss()
135+ }
134136
135− Component {
136− id: menuComponent
137− MenuPopup {
138− x: visualItem.x - units.gu(1)
139− anchors.top: parent.bottom
140− unityMenuModel: root.unityMenuModel.submenu(visualItem.__ownIndex)
137+ Component {
138+ id: menuComponent
139+ MenuPopup {
140+ x: visualItem.x - units.gu(1)
141+ anchors.top: parent.bottom
142+ unityMenuModel: root.unityMenuModel.submenu(visualItem.__ownIndex)
141143
142− Component.onCompleted: reset();
143− }
144+ Component.onCompleted: reset();
144145 }
146+ }
145147
146− RowLayout {
147− id: column
148− spacing: units.gu(1)
149− anchors {
150− centerIn: parent
151− }
148+ RowLayout {
149+ id: column
150+ spacing: units.gu(1)
151+ anchors {
152+ centerIn: parent
153+ }
152154
153− Icon {
154− Layout.preferredWidth: units.gu(2)
155− Layout.preferredHeight: units.gu(2)
156− Layout.alignment: Qt.AlignVCenter
155+ Icon {
156+ Layout.preferredWidth: units.gu(2)
157+ Layout.preferredHeight: units.gu(2)
158+ Layout.alignment: Qt.AlignVCenter
157159
158− visible: model.icon || false
159− source: model.icon || ""
160− }
160+ visible: model.icon || false
161+ source: model.icon || ""
162+ }
161163
162− ActionItem {
163− id: actionItem
164− width: _title.width
165− height: _title.height
164+ ActionItem {
165+ id: actionItem
166+ width: _title.width
167+ height: _title.height
166168
167− action: Action {
168− // FIXME - SDK Action:text modifies menu text with html underline for mnemonic
169− text: model.label.replace("_", "&").replace("<u>", "&").replace("</u>", "")
169+ action: Action {
170+ // FIXME - SDK Action:text modifies menu text with html underline for mnemonic
171+ text: model.label.replace("_", "&").replace("<u>", "&").replace("</u>", "")
170172
171− onTriggered: {
172− visualItem.show();
173− }
173+ onTriggered: {
174+ visualItem.show();
174175 }
176+ }
175177
176− Label {
177− id: _title
178− text: actionItem.text
179− horizontalAlignment: Text.AlignLeft
180− color: enabled ? theme.palette.normal.overlayText : theme.palette.disabled.overlayText
181− }
178+ Label {
179+ id: _title
180+ text: actionItem.text
181+ horizontalAlignment: Text.AlignLeft
182+ color: enabled ? theme.palette.normal.overlayText : theme.palette.disabled.overlayText
182183 }
183184 }
184− } // Item ( delegate )
185− } // Repeater
186− } // Row
185+ }
186+ } // Item ( delegate )
187+ } // Repeater
188+ } // Row
189+
190+ MouseArea {
191+ id: overflowButton
192+ visible: root.implicitWidth > root.width
193+ height: parent.height
194+ width: units.gu(4)
195+ anchors.right: parent.right
196+
197+ Icon {
198+ id: icon
199+ width: units.gu(2)
200+ height: units.gu(2)
201+ anchors.centerIn: parent
202+ color: theme.palette.normal.overlayText
203+ name: "toolkit_chevron-down_2gu"
204+ }
205+ }
187206
188− MouseArea {
189− anchors.fill: parent
190− hoverEnabled: d.currentItem
207+ MouseArea {
208+ anchors.fill: parent
209+ hoverEnabled: d.currentItem
191210
192− onEntered: {
193− if (d.currentItem) {
194− updateCurrentItemFromPosition(Qt.point(mouseX, mouseY))
195− }
211+ onEntered: {
212+ if (d.currentItem) {
213+ updateCurrentItemFromPosition(Qt.point(mouseX, mouseY))
196214 }
197− onPositionChanged: {
198− if (d.currentItem) {
199− updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
200− }
215+ }
216+ onPositionChanged: {
217+ if (d.currentItem) {
218+ updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
201219 }
202− onClicked: updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
220+ }
221+ onClicked: updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
203222
204− function updateCurrentItemFromPosition(point) {
205− var pos = mapToItem(row, point.x, point.y);
223+ function updateCurrentItemFromPosition(point) {
224+ var pos = mapToItem(row, point.x, point.y);
206225
207− if (!d.hoveredItem || !d.currentItem || !d.hoveredItem.contains(Qt.point(pos.x - d.currentItem.x, pos.y - d.currentItem.y))) {
208− d.hoveredItem = row.childAt(pos.x, pos.y);
209− if (!d.hoveredItem || !d.hoveredItem.enabled)
210− return false;
211− if (d.currentItem != d.hoveredItem) {
212− d.currentItem = d.hoveredItem;
213− }
226+ if (!d.hoveredItem || !d.currentItem || !d.hoveredItem.contains(Qt.point(pos.x - d.currentItem.x, pos.y - d.currentItem.y))) {
227+ d.hoveredItem = row.childAt(pos.x, pos.y);
228+ if (!d.hoveredItem || !d.hoveredItem.enabled)
229+ return false;
230+ if (d.currentItem != d.hoveredItem) {
231+ d.currentItem = d.hoveredItem;
214232 }
215− return true;
216233 }
234+ return true;
217235 }
236+ }
218237
219− Rectangle {
220− id: underline
221− anchors {
222− bottom: row.bottom
223− }
224− x: d.currentItem ? row.x + d.currentItem.x - units.gu(1) : 0
225− width: d.currentItem ? d.currentItem.width + units.gu(2) : 0
226− height: units.dp(4)
227− color: theme.palette.normal.activity
228− visible: d.currentItem
238+ Rectangle {
239+ id: underline
240+ anchors {
241+ bottom: row.bottom
229242 }
243+ x: d.currentItem ? row.x + d.currentItem.x - units.gu(1) : 0
244+ width: d.currentItem ? d.currentItem.width + units.gu(2) : 0
245+ height: units.dp(4)
246+ color: theme.palette.normal.activity
247+ visible: d.currentItem
230248 }
231249
232250 MenuNavigator {