Commit a238a5ad authored by Gabriel de Dietrich's avatar Gabriel de Dietrich Committed by The Qt Project
Browse files

MenuBar: Fix mouse interaction


Used the same pattern as earlier with Menu.

Change-Id: Id7a2d791516ba6d827e90c3b3e11f97dd326ccd5
Reviewed-by: default avatarJ-P Nurmi <jpnurmi@digia.com>
parent 658ea072
Branches
Tags
No related merge requests found
Showing with 32 additions and 28 deletions
......@@ -219,7 +219,7 @@ MenuPrivate {
currentItem = column.childAt(pos.x, pos.y)
if (currentItem) {
root.__currentIndex = currentItem.menuItemIndex
if (currentItem.hasSubmenu && !currentItem.menuItem.popupVisible)
if (currentItem.hasSubmenu && !currentItem.menuItem.__popupVisible)
currentItem.showSubMenu(false)
} else {
root.__currentIndex = -1
......
......@@ -140,6 +140,27 @@ MenuBarPrivate {
anchors.fill: parent
hoverEnabled: true
onPositionChanged: updateCurrentItem(mouse)
onPressed: {
menuBarLoader.preselectMenuItem = false
menuBarLoader.openedMenuIndex = currentItem.menuItemIndex
}
property Item currentItem: null
function updateCurrentItem(mouse) {
var pos = mapToItem(row, mouse.x, mouse.y)
if (!currentItem || !currentItem.contains(Qt.point(pos.x - currentItem.x, pos.y - currentItem.y))) {
var newCurrentItem = row.childAt(pos.x, pos.y)
if (!newCurrentItem)
return;
currentItem = newCurrentItem
if (menuBarLoader.openedMenuIndex !== -1) {
menuBarLoader.preselectMenuItem = false
menuBarLoader.openedMenuIndex = currentItem.menuItemIndex
}
}
}
Row {
id: row
......@@ -150,27 +171,10 @@ MenuBarPrivate {
id: menuItemLoader
property var menuItem: modelData
property bool selected: menuItem.__popupVisible || itemMouseArea.pressed || menuBarLoader.openedMenuIndex === index
property bool selected: menuItem.__popupVisible || menuBarLoader.openedMenuIndex === index
sourceComponent: menuBarLoader.menuItemStyle
MouseArea {
id: itemMouseArea
anchors.fill:parent
hoverEnabled: true
onClicked: {
menuBarLoader.preselectMenuItem = false
menuBarLoader.openedMenuIndex = index
}
onPositionChanged: {
if ((pressed || menuMouseArea.pressed || menuBarLoader.openedMenuIndex !== -1)
&& menuBarLoader.openedMenuIndex !== index) {
menuBarLoader.openedMenuIndex = index
menuBarLoader.preselectMenuItem = false
}
}
}
property int menuItemIndex: index
Connections {
target: menuBarLoader
......
......@@ -134,14 +134,14 @@ void QtMenuPopupWindow::mouseReleaseEvent(QMouseEvent *e)
void QtMenuPopupWindow::forwardEventToTransientParent(QMouseEvent *e)
{
QWindow *parentMenuWindow = qobject_cast<QtMenuPopupWindow*>(transientParent());
if (!parentMenuWindow) {
if (m_mouseMoved && e->type() == QEvent::MouseButtonRelease)
dismissMenu();
} else {
QPoint parentPos = parentMenuWindow->mapFromGlobal(mapToGlobal(e->pos()));
if (!qobject_cast<QtMenuPopupWindow*>(transientParent())
&& m_mouseMoved && e->type() == QEvent::MouseButtonRelease) {
// Clicked outside any menu
dismissMenu();
} else if (transientParent()) {
QPoint parentPos = transientParent()->mapFromGlobal(mapToGlobal(e->pos()));
QMouseEvent pe = QMouseEvent(e->type(), parentPos, e->button(), e->buttons(), e->modifiers());
QGuiApplication::sendEvent(parentMenuWindow, &pe);
QGuiApplication::sendEvent(transientParent(), &pe);
}
}
......
......@@ -47,7 +47,7 @@ import QtQuick.Controls.Private 1.0
Style {
property Component frame: StyleItem {
elementType: "menubar"
width: control.width
width: control.__contentItem.width
height: parent ? parent.contentHeight : 0
// + 2 * (pixelMetric("menuvmargin") + pixelMetric("menupanelwidth"))
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment