From 0ed68f3f58c63bd1496cb268bd83881da180051f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Wed, 21 May 2014 13:57:09 +0200 Subject: Refactor the sloppy submenu logic And enable the style to control the behavior of the sloppy submenus [ChangeLog][QtWidgets][QMenu] QMenu now pick up how "sloppy" submenus behave from the style Task-number: QTBUG-20094 Change-Id: Ib1a9770d9b63028033cc360ae236471449d00267 Reviewed-by: Friedemann Kleint Reviewed-by: Gabriel de Dietrich --- src/widgets/styles/qcommonstyle.cpp | 19 +++++++++++++++++++ src/widgets/styles/qmacstyle_mac.mm | 13 +++++++++++++ src/widgets/styles/qstyle.cpp | 26 ++++++++++++++++++++++++++ src/widgets/styles/qstyle.h | 6 ++++++ src/widgets/styles/qwindowsstyle.cpp | 11 +++++++++++ 5 files changed, 75 insertions(+) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index ce6d3d708f..5f343714a4 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -4927,6 +4927,25 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget ret = true; break; + case SH_Menu_SubMenuUniDirection: + ret = false; + break; + case SH_Menu_SubMenuUniDirectionFailCount: + ret = 1; + break; + case SH_Menu_SubMenuSloppySelectOtherActions: + ret = true; + break; + case SH_Menu_SubMenuSloppyCloseTimeout: + ret = 1000; + break; + case SH_Menu_SubMenuResetWhenReenteringParent: + ret = false; + break; + case SH_Menu_SubMenuDontStartSloppyOnLeave: + ret = false; + break; + case SH_ProgressDialog_TextLabelAlignment: ret = Qt::AlignCenter; break; diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 242a1c1c9e..8b61ca40d7 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -2547,6 +2547,19 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w case SH_Menu_SubMenuPopupDelay: ret = 100; break; + case SH_Menu_SubMenuUniDirection: + ret = true; + break; + case SH_Menu_SubMenuSloppySelectOtherActions: + ret = false; + break; + case SH_Menu_SubMenuResetWhenReenteringParent: + ret = true; + break; + case SH_Menu_SubMenuDontStartSloppyOnLeave: + ret = true; + break; + case SH_ScrollBar_LeftClickAbsolutePosition: { NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; bool result = [defaults boolForKey:@"AppleScrollerPagingBehavior"]; diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index fb5a5c9003..5c292ea85d 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -1711,6 +1711,32 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, other items of the menu. This is supported on most modern desktop platforms. + \value SH_Menu_SubMenuUniDirection Since Qt 5.5. If the cursor has + to move towards the submenu (like it is on OS X), or if the + cursor can move in any direction as long as it reaches the + submenu before the sloppy timeout. + + \value SH_Menu_SubMenuUniDirectionFailCount Since Qt 5.5. When + SH_Menu_SubMenuUniDirection is defined this enum defines the + number of failed mouse moves before the sloppy submenu is + discarded. This can be used to control the "strictness" of the + uni direction algorithm. + + \value SH_Menu_SubMenuSloppySelectOtherActions Since Qt 5.5. Should + other action items be selected when the mouse moves towards a + sloppy submenu. + + \value SH_Menu_SubMenuSloppyCloseTimeout Since Qt 5.5. The timeout + used to close sloppy submenus. + + \value SH_Menu_SubMenuResetWhenReenteringParent Since Qt 5.5. When + entering parent from child submenu, should the sloppy state be + reset, effectively closing the child and making the current + submenu active. + + \value SH_Menu_SubMenuDontStartSloppyOnLeave Since Qt 5.5. Do not + start sloppy timers when the mouse leaves a sub-menu. + \value SH_ScrollView_FrameOnlyAroundContents Whether scrollviews draw their frame only around contents (like Motif), or around contents, scroll bars and corner widgets (like Windows). diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index a2de839404..2ea7bbe2ee 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -708,6 +708,12 @@ public: SH_ComboBox_UseNativePopup, SH_LineEdit_PasswordMaskDelay, SH_TabBar_ChangeCurrentDelay, + SH_Menu_SubMenuUniDirection, + SH_Menu_SubMenuUniDirectionFailCount, + SH_Menu_SubMenuSloppySelectOtherActions, + SH_Menu_SubMenuSloppyCloseTimeout, + SH_Menu_SubMenuResetWhenReenteringParent, + SH_Menu_SubMenuDontStartSloppyOnLeave, // Add new style hint values here SH_CustomBase = 0xf0000000 diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 2f04a20cd0..b26e329628 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -594,6 +594,17 @@ int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWid break; } #endif // Q_OS_WIN && !Q_OS_WINRT + case SH_Menu_SubMenuSloppyCloseTimeout: + case SH_Menu_SubMenuPopupDelay: { +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) + DWORD delay; + if (SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &delay, 0)) + ret = delay; + else +#endif // Q_OS_WIN && !Q_OS_WINCE && !Q_OS_WINRT + ret = 400; + break; + } #ifndef QT_NO_RUBBERBAND case SH_RubberBand_Mask: if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast(opt)) { -- cgit v1.2.3