An error occurred while loading the file. Please try again.
-
Jason McDonald authored
As in the past, to avoid rewriting various autotests that contain line-number information, an extra blank line has been inserted at the end of the license text to ensure that this commit does not change the total number of lines in the license header. Change-Id: Ie14feff161cca83c53750e22a6204d34c3cba52c Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by:
Rohan McGovern <rohan.mcgovern@nokia.com>
990cacfd
import QtQuick 2.0
import "../components/plugin"
MenuBase {
property ListModel model
property string selectedText: itemTextAt(selectedIndex)
property string hoveredText: itemTextAt(hoveredIndex)
// 'centerSelectedText' means that the menu will be positioned
// so that the selected text' top left corner will be at x, y.
property bool centerSelectedText: true
// Show, or hide, the popup by setting the 'visible' property:
visible: false
onMenuClosed: visible = false
onModelChanged: if (Component.status === Component.Ready) rebuildMenu()
Component.onCompleted: rebuildMenu()
onHoveredIndexChanged: {
if (hoveredIndex < menuItems.length)
menuItems[hoveredIndex].emitHovered()
}
onSelectedIndexChanged: {
if (hoveredIndex < menuItems.length)
menuItems[hoveredIndex].emitSelected()
}
onVisibleChanged: {
if (visible) {
var globalPos = parent.mapToItem(null, x, y)
showPopup(globalPos.x, globalPos.y, centerSelectedText ? selectedIndex : 0)
} else {
closePopup()
}
}
function rebuildMenu()
{
clearMenuItems();
for (var i=0; i<menuItems.length; ++i)
addMenuItem(menuItems[i].text)
if (model != undefined) {
for (var j=0; j<model.count; ++j)
addMenuItem(model.get(j).text)
}
}
}