summaryrefslogtreecommitdiffstats
path: root/src/controls/Menu.qml
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2013-03-20 15:22:08 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-20 17:16:42 +0100
commitbdc872955933aaf93cdd434cc17cc29630600b88 (patch)
treea5c40c6bb82a30f7e1c31dde8ce3ec33ac61ee1a /src/controls/Menu.qml
parent8d5e9969b54f80e646cc2b9fcc92e1f36da6d128 (diff)
Menu: Update API, auto-tests
Add 'type' property to QtMenuBase (not exposed to QML explicitly, but is the base class for all things menu). Useful to inspect menu items after creation, for instance. Also, Menu gets addSeparator() and addMenu() functions. Since the Iterator type has been merged to QML, tst_menu now uses it. Change-Id: I4a2f43ecce6671885e523d720e4e1315eca8616e Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/controls/Menu.qml')
-rw-r--r--src/controls/Menu.qml28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/controls/Menu.qml b/src/controls/Menu.qml
index 9ee03e46f..6ac930ef2 100644
--- a/src/controls/Menu.qml
+++ b/src/controls/Menu.qml
@@ -103,6 +103,20 @@ import "Styles/Settings.js" as Settings
MenuPrivate {
id: root
+ /*!
+ Adds a submenu to the menu. Returns the newly created \l Menu.
+ */
+ function addMenu(title) {
+ if (!__selfComponent)
+ __selfComponent = Qt.createComponent("Menu.qml", root)
+ var submenu = __selfComponent.createObject(__selfComponent, { "title": title })
+ root.insertItem(items.length, submenu)
+ return submenu
+ }
+
+ /*! internal */
+ property Component __selfComponent: null
+
/*! \internal */
property Component style: Qt.createComponent(Settings.THEME_PATH + "/MenuStyle.qml", root)
@@ -183,7 +197,7 @@ MenuPrivate {
Keys.onRightPressed: {
var item = itemsRepeater.itemAt(root.__currentIndex)
- if (item && item.hasSubmenu) {
+ if (item && item.isSubmenu) {
item.showSubMenu(true)
item.menuItem.__currentIndex = 0
}
@@ -197,7 +211,7 @@ MenuPrivate {
var item = itemsRepeater.itemAt(root.__currentIndex)
if (item && !item.isSeparator) {
root.__dismissMenu()
- if (!item.hasSubmenu)
+ if (!item.isSubmenu)
item.menuItem.trigger()
}
}
@@ -229,12 +243,12 @@ MenuPrivate {
function updateCurrentItem(mouse) {
var pos = mapToItem(column, mouse.x, mouse.y)
if (!currentItem || !currentItem.contains(Qt.point(pos.x - currentItem.x, pos.y - currentItem.y))) {
- if (currentItem && !pressed && currentItem.hasSubmenu)
+ if (currentItem && !pressed && currentItem.isSubmenu)
currentItem.closeSubMenu()
currentItem = column.childAt(pos.x, pos.y)
if (currentItem) {
root.__currentIndex = currentItem.menuItemIndex
- if (currentItem.hasSubmenu && !currentItem.menuItem.__popupVisible)
+ if (currentItem.isSubmenu && !currentItem.menuItem.__popupVisible)
currentItem.showSubMenu(false)
} else {
root.__currentIndex = -1
@@ -255,10 +269,10 @@ MenuPrivate {
id: menuItemLoader
property var menuItem: modelData
- property bool isSeparator: menuItem ? !menuItem.hasOwnProperty("enabled") : true
- property bool hasSubmenu: menuItem ? !!menuItem["items"] : false
+ readonly property bool isSeparator: !!menuItem && menuItem.type === MenuItemType.Separator
+ readonly property bool isSubmenu: !!menuItem && menuItem.type === MenuItemType.Menu
property bool selected: !isSeparator && root.__currentIndex === index
- property string text: hasSubmenu ? menuItem.title : !isSeparator ? menuItem.text : ""
+ property string text: isSubmenu ? menuItem.title : !isSeparator ? menuItem.text : ""
property int menuItemIndex: index