on xenial help sign in
fixed clipping
0640a93Nick Dedekind
qml/ApplicationMenus/MenuBar.qml+122−114
@@ -64,156 +64,164 @@ Item {
64 onPressed: d.dismissAll()
64 onPressed: d.dismissAll()
65 }
65 }
66
66
67+ Item {
68+ id: clippingItem
69+
70+ height: root.height
71+ width: root.width
72+ clip: true
73+
67− Row {
74+ Row {
68− id: row
75+ id: row
69− height: parent.height
70− spacing: units.gu(2)
76+ spacing: units.gu(2)
71−
77+ height: parent.height
78+
72− ActionContext {
79+ ActionContext {
73− id: menuBarContext
80+ id: menuBarContext
74− objectName: "barContext"
81+ objectName: "barContext"
75− active: !d.currentItem && enableKeyFilter
82+ active: !d.currentItem && enableKeyFilter
76− }
83+ }
77
84
78− Repeater {
85+ Repeater {
79− id: rowRepeater
86+ id: rowRepeater
80
87
81− Item {
88+ Item {
82− id: visualItem
89+ id: visualItem
83− objectName: root.objectName + "-item" + __ownIndex
90+ objectName: root.objectName + "-item" + __ownIndex
84
91
85− readonly property int __ownIndex: index
92+ readonly property int __ownIndex: index
86− property Item __popup: null;
93+ property Item __popup: null;
87− property bool popupVisible: __popup && __popup.visible
94+ property bool popupVisible: __popup && __popup.visible
88
95
89− implicitWidth: column.implicitWidth
96+ implicitWidth: column.implicitWidth
90− implicitHeight: row.height
97+ implicitHeight: row.height
91− enabled: model.sensitive
98+ enabled: model.sensitive
92
99
93− function show() {
100+ function show() {
94− if (!__popup) {
101+ if (!__popup) {
95− __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
102+ __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
96− // force the current item to be the newly popped up menu
103+ // force the current item to be the newly popped up menu
97− } else {
104+ } else {
98− __popup.visible = true;
105+ __popup.visible = true;
106+ }
107+ d.currentItem = visualItem;
99 }
108 }
100− d.currentItem = visualItem;
101− }
102− function hide() {
109+ function hide() {
103− if (__popup) {
110+ if (__popup) {
104− __popup.visible = false;
111+ __popup.visible = false;
105
112
106− if (d.currentItem === visualItem) {
113+ if (d.currentItem === visualItem) {
107− d.currentItem = null;
114+ d.currentItem = null;
115+ }
108 }
116 }
109 }
117 }
110− }
111− function dismiss() {
118+ function dismiss() {
112− if (__popup) {
119+ if (__popup) {
113− __popup.destroy();
120+ __popup.destroy();
114− __popup = null;
121+ __popup = null;
115
122
116− if (d.currentItem === visualItem) {
123+ if (d.currentItem === visualItem) {
117− d.currentItem = null;
124+ d.currentItem = null;
125+ }
118 }
126 }
119 }
127 }
120− }
121
128
122− Connections {
129+ Connections {
123− target: d
130+ target: d
124− onDismissAll: visualItem.dismiss()
131+ onDismissAll: visualItem.dismiss()
125− }
132+ }
126
133
127− Component {
134+ Component {
128− id: menuComponent
135+ id: menuComponent
129− MenuPopup {
136+ MenuPopup {
130− x: visualItem.x - units.gu(1)
137+ x: visualItem.x - units.gu(1)
131− anchors.top: parent.bottom
138+ anchors.top: parent.bottom
132− unityMenuModel: root.unityMenuModel.submenu(visualItem.__ownIndex)
139+ unityMenuModel: root.unityMenuModel.submenu(visualItem.__ownIndex)
133
140
134− Component.onCompleted: reset();
141+ Component.onCompleted: reset();
135− onVisibleChanged: if (visible) { reset(); }
142+ onVisibleChanged: if (visible) { reset(); }
143+ }
136 }
144 }
137− }
138
145
139− RowLayout {
146+ RowLayout {
140− id: column
147+ id: column
141− spacing: units.gu(1)
148+ spacing: units.gu(1)
142− anchors {
149+ anchors {
143− centerIn: parent
150+ centerIn: parent
144− }
151+ }
145
152
146− Icon {
153+ Icon {
147− Layout.preferredWidth: units.gu(2)
154+ Layout.preferredWidth: units.gu(2)
148− Layout.preferredHeight: units.gu(2)
155+ Layout.preferredHeight: units.gu(2)
149− Layout.alignment: Qt.AlignVCenter
156+ Layout.alignment: Qt.AlignVCenter
150
157
151− visible: model.icon || false
158+ visible: model.icon || false
152− source: model.icon || ""
159+ source: model.icon || ""
153− }
160+ }
154
161
155− ActionItem {
162+ ActionItem {
156− id: actionItem
163+ id: actionItem
157− width: _title.width
164+ width: _title.width
158− height: _title.height
165+ height: _title.height
159
166
160− action: Action {
167+ action: Action {
161− // FIXME - SDK Action:text modifies menu text with html underline for mnemonic
168+ // FIXME - SDK Action:text modifies menu text with html underline for mnemonic
162− text: model.label.replace("_", "&").replace("<u>", "&").replace("</u>", "")
169+ text: model.label.replace("_", "&").replace("<u>", "&").replace("</u>", "")
163
170
164− onTriggered: {
171+ onTriggered: {
165− visualItem.show();
172+ visualItem.show();
173+ }
166 }
174 }
167− }
168
175
169− Label {
176+ Label {
170− id: _title
177+ id: _title
171− text: actionItem.text
178+ text: actionItem.text
172− horizontalAlignment: Text.AlignLeft
179+ horizontalAlignment: Text.AlignLeft
173− color: enabled ? "white" : "#5d5d5d"
180+ color: enabled ? "white" : "#5d5d5d"
181+ }
174 }
182 }
175 }
183 }
176− }
177− } // Item ( delegate )
184+ } // Item ( delegate )
178− } // Repeater
185+ } // Repeater
179− } // Row
186+ } // Row
180
187
181− MouseArea {
188+ MouseArea {
182− anchors.fill: parent
189+ anchors.fill: parent
183− hoverEnabled: d.currentItem
190+ hoverEnabled: d.currentItem
184
191
185− onPositionChanged: {
192+ onPositionChanged: {
186− if (d.currentItem) {
193+ if (d.currentItem) {
187− updateCurrentItemFromPosition(mouse)
194+ updateCurrentItemFromPosition(mouse)
195+ }
188 }
196 }
189− }
190− onClicked: updateCurrentItemFromPosition(mouse)
197+ onClicked: updateCurrentItemFromPosition(mouse)
191
198
192− function updateCurrentItemFromPosition(point) {
199+ function updateCurrentItemFromPosition(point) {
193− var pos = mapToItem(row, point.x, point.y);
200+ var pos = mapToItem(row, point.x, point.y);
194
201
195− if (!d.hoveredItem || !d.currentItem || !d.hoveredItem.contains(Qt.point(pos.x - d.currentItem.x, pos.y - d.currentItem.y))) {
202+ if (!d.hoveredItem || !d.currentItem || !d.hoveredItem.contains(Qt.point(pos.x - d.currentItem.x, pos.y - d.currentItem.y))) {
196− d.hoveredItem = row.childAt(pos.x, pos.y);
203+ d.hoveredItem = row.childAt(pos.x, pos.y);
197− if (!d.hoveredItem || !d.hoveredItem.enabled)
204+ if (!d.hoveredItem || !d.hoveredItem.enabled)
198− return false;
205+ return false;
199− if (d.currentItem != d.hoveredItem) {
206+ if (d.currentItem != d.hoveredItem) {
200− d.currentItem = d.hoveredItem;
207+ d.currentItem = d.hoveredItem;
208+ }
201 }
209 }
210+ return true;
202 }
211 }
203− return true;
204 }
212 }
205− }
206
213
207− Rectangle {
214+ Rectangle {
208− id: underline
215+ id: underline
209− anchors {
216+ anchors {
210− bottom: row.bottom
217+ bottom: row.bottom
218+ }
219+ x: d.currentItem ? row.x + d.currentItem.x - units.gu(1) : 0
220+ width: d.currentItem ? d.currentItem.width + units.gu(2) : 0
221+ height: units.dp(4)
222+ color: UbuntuColors.orange
223+ visible: d.currentItem
211 }
224 }
212− x: d.currentItem ? row.x + d.currentItem.x - units.gu(1) : 0
213− width: d.currentItem ? d.currentItem.width + units.gu(2) : 0
214− height: units.dp(4)
215− color: UbuntuColors.orange
216− visible: d.currentItem
217 }
225 }
218
226
219 MenuNavigator {
227 MenuNavigator {