@@ -16,16 +16,48 @@
17import QtQuick 2.4
17import QtQuick 2.4
18import QtQuick.Layouts 1.1
18import QtQuick.Layouts 1.1
19−import QtQuick.Window 2.2
20import Ubuntu.Components 1.3
19import Ubuntu.Components 1.3
21import Ubuntu.Components.ListItems 1.3 as ListItems
20import Ubuntu.Components.ListItems 1.3 as ListItems
22import "../Components"
21import "../Components"
24UbuntuShape {
24UbuntuShape {
26 objectName: "menu"
26 objectName: "menu"
27 backgroundColor: theme.palette.normal.overlay
27 backgroundColor: theme.palette.normal.overlay
29+ // true for submenus that need to show on the other side of their parent
30+ // if they don't fit when growing right
31+ property bool substractWidth: false
33+ property real desiredX
35+ var dummy = visible; // force recalc when shown/hidden
36+ var parentTopLeft = parent.mapToItem(null, 0, 0);
37+ var farX = ApplicationMenusLimits.screenWidth;
38+ if (parentTopLeft.x + width + desiredX <= farX) {
41+ if (substractWidth) {
44+ return farX - parentTopLeft.x - width;
49+ property real desiredY
51+ var dummy = visible; // force recalc when shown/hidden
52+ var parentTopLeft = parent.mapToItem(null, 0, 0);
53+ var bottomY = ApplicationMenusLimits.screenHeight;
54+ if (parentTopLeft.y + height + desiredY <= bottomY) {
57+ return bottomY - parentTopLeft.y - height;
29 property alias unityMenuModel: repeater.model
61 property alias unityMenuModel: repeater.model
31 function show() {
63 function show() {
@@ -64,9 +96,9 @@ UbuntuShape {
64 readonly property int currentIndex: currentItem ? currentItem.__ownIndex : -1
96 readonly property int currentIndex: currentItem ? currentItem.__ownIndex : -1
66 property real __minimumWidth: units.gu(20)
98 property real __minimumWidth: units.gu(20)
67− property real __maximumWidth: Screen.width * 0.7
99+ property real __maximumWidth: ApplicationMenusLimits.screenWidth * 0.7
68 property real __minimumHeight: units.gu(2)
100 property real __minimumHeight: units.gu(2)
69− property real __maximumHeight: Screen.height * 0.7
101+ property real __maximumHeight: ApplicationMenusLimits.screenHeight * 0.7
71 signal dismissAll()
103 signal dismissAll()
@@ -257,8 +289,9 @@ UbuntuShape {
257 popup = submenuComponent.createObject(focusScope, {
289 popup = submenuComponent.createObject(focusScope, {
258 objectName: loader.objectName + "-",
290 objectName: loader.objectName + "-",
259 unityMenuModel: model,
291 unityMenuModel: model,
292+ substractWidth: true,
260− x: Qt.binding(function() { return root.width }),
293+ desiredX: Qt.binding(function() { return root.width }),
261− y: Qt.binding(function() {
294+ desiredY: Qt.binding(function() {
262 var dummy = listView.contentY; // force a recalc on contentY change.
295 var dummy = listView.contentY; // force a recalc on contentY change.
263 return mapToItem(container, 0, y).y;
296 return mapToItem(container, 0, y).y;
@@ -375,19 +408,18 @@ UbuntuShape {
375 id: submenuLoader
408 id: submenuLoader
376 source: "MenuPopup.qml"
409 source: "MenuPopup.qml"
411+ property real desiredX
412+ property real desiredY
413+ property bool substractWidth
378 property var unityMenuModel: null
414 property var unityMenuModel: null
379 signal retreat()
415 signal retreat()
381− Binding {
417+ onLoaded: {
383− property: "unityMenuModel"
384− value: submenuLoader.unityMenuModel
418+ item.unityMenuModel = Qt.binding(function() { return submenuLoader.unityMenuModel; });
389− property: "objectName"
390− value: submenuLoader.objectName + "menu"
419+ item.objectName = Qt.binding(function() { return submenuLoader.objectName + "menu"; });
420+ item.desiredX = Qt.binding(function() { return submenuLoader.desiredX; });
421+ item.desiredY = Qt.binding(function() { return submenuLoader.desiredY; });
422+ item.substractWidth = Qt.binding(function() { return submenuLoader.substractWidth; });
393 Keys.onLeftPressed: retreat()
425 Keys.onLeftPressed: retreat()