27
27
backgroundColor: theme.palette.normal.overlay
29
property alias unityMenuModel: listView.model
31
readonly property real __ajustedMinimumHeight: {
32
if (listView.contentHeight > __minimumHeight) {
35
return Math.max(listView.contentHeight, units.gu(2));
38
readonly property real __minimumWidth: units.gu(20)
39
readonly property real __minimumHeight: units.gu(30)
40
readonly property real __maximumWidth: Screen.width * 0.7
41
readonly property real __maximumHeight: Screen.height * 0.7
29
property alias unityMenuModel: repeater.model
66
implicitWidth: container.width
67
implicitHeight: MathUtils.clamp(listView.contentHeight, __ajustedMinimumHeight, __maximumHeight)
54
implicitWidth: focusScope.width
55
implicitHeight: focusScope.height
74
62
property Item currentItem: null
75
63
property Item hoveredItem: null
76
64
readonly property int currentIndex: currentItem ? currentItem.__ownIndex : -1
66
property real __minimumWidth: units.gu(20)
67
property real __maximumWidth: Screen.width * 0.7
68
property real __minimumHeight: units.gu(2)
69
property real __maximumHeight: Screen.height * 0.7
78
71
signal dismissAll()
80
73
onCurrentItemChanged: {
109
115
objectName: "container"
111
width: listView.contentWidth
112
height: parent.height
117
height: MathUtils.clamp(listView.contentHeight, d.__minimumHeight, d.__maximumHeight)
118
width: menuColumn.width
115
// FIXME use ListView.header - tried but was flaky with positionViewAtIndex.
121
// Header - scroll up
117
Layout.fillWidth: true;
118
Layout.maximumHeight: units.gu(3)
119
Layout.minimumHeight: units.gu(3)
123
Layout.fillWidth: true
120
125
visible: listView.contentHeight > root.height
121
126
enabled: !listView.atYBeginning
124
130
color: enabled ? theme.palette.normal.overlayText :
144
150
anchors.fill: parent
146
var index = listView.indexAt(0, listView.contentY);
147
listView.positionViewAtIndex(index-1, ListView.Beginning);
152
var item = menuColumn.childAt(0, listView.contentY);
154
var previousItem = item;
156
previousItem = repeater.itemAt(previousItem.__ownIndex-1);
158
listView.contentY = 0;
161
} while (previousItem.__isSeparator);
163
listView.contentY = previousItem.y
154
objectName: "listView"
155
174
Layout.fillHeight: true
156
175
Layout.fillWidth: true
157
contentWidth: MathUtils.clamp(contentItem.childrenRect.width,
161
orientation: Qt.Vertical
162
interactive: contentHeight > height
164
highlightFollowsCurrentItem: false
166
highlight: Rectangle {
168
border.width: units.dp(1)
169
border.color: UbuntuColors.orange
172
width: listView.width
173
height: d.currentItem ? d.currentItem.height : 0
174
y: d.currentItem ? d.currentItem.y : 0
175
visible: d.currentItem
178
function itemAt(index) {
179
if (index > count || index < 0) return null;
180
currentIndex = index;
176
contentHeight: menuColumn.height
177
interactive: height < contentHeight
186
anchors.fill: listView
187
181
hoverEnabled: true
188
182
propagateComposedEvents: true // propogate events so we send clicks to children.
189
183
z: 1 // on top so we override any other hovers
221
objectName: root.objectName + "-item" + __ownIndex
223
property int __ownIndex: index
226
enabled: model.isSeparator ? false : model.sensitive
229
if (model.isSeparator) {
230
return separatorComponent;
232
return menuItemComponent;
235
property Item popup: null
238
id: menuItemComponent
242
objectName: loader.objectName + "-actionItem"
244
action.onTriggered: {
245
d.currentItem = loader;
249
var model = root.unityMenuModel.submenu(__ownIndex);
250
popup = submenuComponent.createObject(focusScope, {
251
objectName: loader.objectName + "-",
252
unityMenuModel: model,
253
x: Qt.binding(function() { return root.width }),
254
y: Qt.binding(function() { return loader.y })
257
popup.visible = true;
259
popup.retreat.connect(function() {
262
menuItem.forceActiveFocus();
265
root.unityMenuModel.activate(__ownIndex);
271
onCurrentIndexChanged: {
272
if (popup && d.currentIndex != __ownIndex) {
273
popup.visible = false;
287
id: separatorComponent
288
ListItems.ThinDivider {
289
objectName: loader.objectName + "-separator"
295
// FIXME use ListView.footer - tried but was flaky with positionViewAtIndex.
217
width: MathUtils.clamp(implicitWidth, d.__minimumWidth, d.__maximumWidth)
224
objectName: root.objectName + "-item" + __ownIndex
226
property int __ownIndex: index
227
property bool __isSeparator: model.isSeparator
229
enabled: __isSeparator ? false : model.sensitive
232
if (model.isSeparator) {
233
return separatorComponent;
235
return menuItemComponent;
238
property Item popup: null
240
Layout.fillWidth: true
243
id: menuItemComponent
247
objectName: loader.objectName + "-actionItem"
249
width: MathUtils.clamp(implicitWidth, d.__minimumWidth, d.__maximumWidth)
251
action.onTriggered: {
252
d.currentItem = loader;
256
var model = root.unityMenuModel.submenu(__ownIndex);
257
popup = submenuComponent.createObject(focusScope, {
258
objectName: loader.objectName + "-",
259
unityMenuModel: model,
260
x: Qt.binding(function() { return root.width }),
261
y: Qt.binding(function() {
262
var dummy = listView.contentY; // force a recalc on contentY change.
263
return mapToItem(container, 0, y).y;
267
popup.visible = true;
269
popup.retreat.connect(function() {
272
menuItem.forceActiveFocus();
275
root.unityMenuModel.activate(__ownIndex);
281
onCurrentIndexChanged: {
282
if (popup && d.currentIndex != __ownIndex) {
283
popup.visible = false;
297
id: separatorComponent
298
ListItems.ThinDivider {
299
objectName: loader.objectName + "-separator"
300
implicitHeight: units.dp(2)
311
border.width: units.dp(1)
312
border.color: UbuntuColors.orange
315
width: listView.width
316
height: d.currentItem ? d.currentItem.height : 0
317
y: d.currentItem ? d.currentItem.y : 0
318
visible: d.currentItem
323
// Header - scroll down
297
Layout.fillWidth: true;
298
Layout.maximumHeight: units.gu(3)
299
Layout.minimumHeight: units.gu(3)
325
Layout.fillWidth: true
300
327
visible: listView.contentHeight > root.height
301
328
enabled: !listView.atYEnd
304
332
color: enabled ? theme.palette.normal.overlayText :
324
352
anchors.fill: parent
326
var index = listView.indexAt(0, listView.contentY);
327
listView.positionViewAtIndex(index+1, ListView.Beginning);
354
var item = menuColumn.childAt(0, listView.contentY + listView.height);
358
nextItem = repeater.itemAt(nextItem.__ownIndex+1);
360
listView.contentY = listView.contentHeight - listView.height;
363
} while (nextItem.__isSeparator);
365
listView.contentY = nextItem.y - listView.height