summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2014-03-18 12:56:10 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-20 11:24:22 +0100
commitb6e15e047d7f981cbd987e60a1adcf62a57010a1 (patch)
tree18b3f90d6a333f7897c8df369b4e51a4a88b63cd
parent020d873a5753c4c147d11ac98682d270554e1d05 (diff)
QMenu: Enable sloppy submenu mouse navigation
Since we're in the 21st century, we set QCommonStyle to return true to the SH_Menu_SloppySubMenus style hint. This unlocks all the logic already available in QMenu. This is a backport of I134c87e348d98d1f46055e0bfef2b4a4a3d2993a from qt/qtbase and includes some previous enhancements. Task-number: QTBUG-20094 [ChangeLog][QtWidgets][QMenu] Enable sloppy submenu mouse navigation Change-Id: If4141a3d849123850e40af92ac5aede9ed767bdf Reviewed-by: J-P Nurmi <jpnurmi@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--src/gui/styles/qcommonstyle.cpp4
-rw-r--r--src/gui/styles/qmacstyle_mac.mm3
-rw-r--r--src/gui/styles/qstyle.cpp6
-rw-r--r--src/gui/widgets/qmenu.cpp10
4 files changed, 16 insertions, 7 deletions
diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp
index 164515250b..c204633608 100644
--- a/src/gui/styles/qcommonstyle.cpp
+++ b/src/gui/styles/qcommonstyle.cpp
@@ -4931,6 +4931,10 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget
ret = 256;
break;
+ case SH_Menu_SloppySubMenus:
+ ret = true;
+ break;
+
case SH_ProgressDialog_TextLabelAlignment:
ret = Qt::AlignCenter;
break;
diff --git a/src/gui/styles/qmacstyle_mac.mm b/src/gui/styles/qmacstyle_mac.mm
index a93d987d50..a575b312d2 100644
--- a/src/gui/styles/qmacstyle_mac.mm
+++ b/src/gui/styles/qmacstyle_mac.mm
@@ -2392,9 +2392,6 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w
ret = QDialogButtons::Reject;
break;
*/
- case SH_Menu_SloppySubMenus:
- ret = true;
- break;
case SH_GroupBox_TextLabelVerticalAlignment:
ret = Qt::AlignTop;
break;
diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp
index 558153fff9..5a86d9b5a3 100644
--- a/src/gui/styles/qstyle.cpp
+++ b/src/gui/styles/qstyle.cpp
@@ -1681,8 +1681,10 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
\value SH_Menu_Scrollable Whether popup menus must support scrolling.
- \value SH_Menu_SloppySubMenus Whether popupmenu's must support
- sloppy submenu; as implemented on Mac OS.
+ \value SH_Menu_SloppySubMenus Whether popup menus must support
+ the user moving the mouse cursor to a submenu while crossing
+ other items of the menu. This is supported on most modern
+ desktop platforms.
\value SH_ScrollView_FrameOnlyAroundContents Whether scrollviews
draw their frame only around contents (like Motif), or around
diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp
index 2a7477adbc..0e4ecde237 100644
--- a/src/gui/widgets/qmenu.cpp
+++ b/src/gui/widgets/qmenu.cpp
@@ -2872,8 +2872,14 @@ void QMenu::mouseMoveEvent(QMouseEvent *e)
d->mouseDown = this;
}
if (d->sloppyRegion.contains(e->pos())) {
- d->sloppyAction = action;
- d->sloppyDelayTimer = startTimer(style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this)*6);
+ if (d->sloppyAction != action && d->sloppyDelayTimer != 0) {
+ killTimer(d->sloppyDelayTimer);
+ d->sloppyDelayTimer = 0;
+ }
+ if (d->sloppyDelayTimer == 0) {
+ d->sloppyAction = action;
+ d->sloppyDelayTimer = startTimer(style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this)*6);
+ }
} else if (action != d->currentAction) {
d->setCurrentAction(action, style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this));
}