From ce10188aa97cbb8f5945e169a2bca1407f8b825e Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Fri, 30 Jan 2015 11:23:56 +0100 Subject: [PATCH] Expose TabFocusBehavior in QStyleHints TabAllWidgets in QPlatformTheme is replaced by TabFocusBehavior. [ChangeLog][QtGui] Expose TabFocusBehavior in QStyleHints Change-Id: Iafaad7c6a5c6bc888d1e124e6ddcdbdc46f37b1c Reviewed-by: Shawn Rutledge Reviewed-by: Paul Olav Tvete --- src/corelib/global/qnamespace.h | 8 ++++++++ src/corelib/global/qnamespace.qdoc | 13 +++++++++++++ src/gui/kernel/qplatformintegration.cpp | 2 ++ src/gui/kernel/qplatformintegration.h | 3 ++- src/gui/kernel/qplatformtheme.cpp | 9 +++++---- src/gui/kernel/qplatformtheme.h | 5 +++++ src/gui/kernel/qstylehints.cpp | 14 ++++++++++++++ src/gui/kernel/qstylehints.h | 2 ++ src/plugins/platforms/cocoa/qcocoatheme.mm | 5 +++-- 9 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index d839d6ed47..2cde1bae81 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -173,6 +173,13 @@ public: WheelFocus = StrongFocus | 0x4 }; + enum TabFocusBehavior { + NoTabFocus = 0x00, + TabFocusTextControls = 0x01, + TabFocusListControls = 0x02, + TabFocusAllControls = 0xff + }; + enum SortOrder { AscendingOrder, DescendingOrder @@ -1686,6 +1693,7 @@ public: QT_Q_ENUM(TimerType) QT_Q_ENUM(ScrollPhase) QT_Q_ENUM(MouseEventSource) + QT_Q_ENUM(TabFocusBehavior) #endif // Q_DOC } diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 98cc51fc3f..1be83caa06 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -1929,6 +1929,19 @@ */ +/*! + \enum Qt::TabFocusBehavior + \since 5.5 + + This enum type provides different focus behaviors for tab navigation. + + \value NoTabFocus iterate nothing. + \value TabFocusTextControls iterate text controls and widgets. + \value TabFocusListControls iterate list controls and widgets. + \value TabFocusAllControls iterate all controls and widgets. + +*/ + /*! \enum Qt::ShortcutContext diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp index d58e2da3f8..d2db6af52b 100644 --- a/src/gui/kernel/qplatformintegration.cpp +++ b/src/gui/kernel/qplatformintegration.cpp @@ -392,6 +392,8 @@ QVariant QPlatformIntegration::styleHint(StyleHint hint) const return QVariant(false); case MousePressAndHoldInterval: return QPlatformTheme::defaultThemeHint(QPlatformTheme::MousePressAndHoldInterval); + case TabFocusBehavior: + return QPlatformTheme::defaultThemeHint(QPlatformTheme::TabFocusBehavior); } return 0; diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h index b8f92165cf..a0756a4992 100644 --- a/src/gui/kernel/qplatformintegration.h +++ b/src/gui/kernel/qplatformintegration.h @@ -145,7 +145,8 @@ public: PasswordMaskCharacter, SetFocusOnTouchRelease, ShowIsMaximized, - MousePressAndHoldInterval + MousePressAndHoldInterval, + TabFocusBehavior }; virtual QVariant styleHint(StyleHint hint) const; diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 869231d64f..3e48c48c2c 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -132,8 +132,9 @@ QT_BEGIN_NAMESPACE \value SpellCheckUnderlineStyle (int) A QTextCharFormat::UnderlineStyle specifying the underline style used misspelled words when spell checking. - \value TabAllWidgets (bool) Whether tab navigation should go through all the widgets or components, - or just through text boxes and list views. This is mostly a Mac feature. + \value TabFocusBehavior (int) A Qt::TabFocusBehavior specifying + the behavior of focus change when tab key was pressed. + This enum value was added in Qt 5.5. \value DialogSnapToDefaultButton (bool) Whether the mouse should snap to the default button when a dialog becomes visible. @@ -491,8 +492,8 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint) return QVariant(int(0)); case SpellCheckUnderlineStyle: return QVariant(int(QTextCharFormat::SpellCheckUnderline)); - case TabAllWidgets: - return QVariant(true); + case TabFocusBehavior: + return QVariant(int(Qt::TabFocusAllControls)); case IconPixmapSizes: return QVariant::fromValue(QList()); case DialogSnapToDefaultButton: diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index 534ab700ae..69cc2f90af 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -95,7 +95,12 @@ public: KeyboardScheme, UiEffects, SpellCheckUnderlineStyle, +#if QT_VERSION >= QT_VERSION_CHECK(6,0,0) + TabFocusBehavior, +#else TabAllWidgets, + TabFocusBehavior = TabAllWidgets, +#endif IconPixmapSizes, PasswordMaskCharacter, DialogSnapToDefaultButton, diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp index 0d9b886507..a0f98383ff 100644 --- a/src/gui/kernel/qstylehints.cpp +++ b/src/gui/kernel/qstylehints.cpp @@ -358,4 +358,18 @@ bool QStyleHints::setFocusOnTouchRelease() const return hint(QPlatformIntegration::SetFocusOnTouchRelease).toBool(); } +/*! + \property QStyleHints::tabFocusBehavior + \since 5.5 + \brief The focus behavior on press of the tab key. + + \note Do not bind this value in QML because the change notifier + signal is not implemented yet. +*/ + +Qt::TabFocusBehavior QStyleHints::tabFocusBehavior() const +{ + return Qt::TabFocusBehavior(themeableHint(QPlatformTheme::TabFocusBehavior, QPlatformIntegration::TabFocusBehavior).toInt()); +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qstylehints.h b/src/gui/kernel/qstylehints.h index 74447d86fb..5fbc851ee9 100644 --- a/src/gui/kernel/qstylehints.h +++ b/src/gui/kernel/qstylehints.h @@ -60,6 +60,7 @@ class Q_GUI_EXPORT QStyleHints : public QObject Q_PROPERTY(int startDragTime READ startDragTime NOTIFY startDragTimeChanged FINAL) Q_PROPERTY(int startDragVelocity READ startDragVelocity STORED false CONSTANT FINAL) Q_PROPERTY(bool useRtlExtensions READ useRtlExtensions STORED false CONSTANT FINAL) + Q_PROPERTY(Qt::TabFocusBehavior tabFocusBehavior READ tabFocusBehavior STORED false CONSTANT FINAL) public: void setMouseDoubleClickInterval(int mouseDoubleClickInterval); @@ -81,6 +82,7 @@ public: qreal fontSmoothingGamma() const; bool useRtlExtensions() const; bool setFocusOnTouchRelease() const; + Qt::TabFocusBehavior tabFocusBehavior() const; Q_SIGNALS: void cursorFlashTimeChanged(int cursorFlashTime); diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index 744d3f23aa..7b2f1ee3af 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -281,8 +281,9 @@ QVariant QCocoaTheme::themeHint(ThemeHint hint) const return QVariant(QPlatformDialogHelper::MacLayout); case KeyboardScheme: return QVariant(int(MacKeyboardScheme)); - case TabAllWidgets: - return QVariant(bool([[NSApplication sharedApplication] isFullKeyboardAccessEnabled])); + case TabFocusBehavior: + return QVariant([[NSApplication sharedApplication] isFullKeyboardAccessEnabled] ? + int(Qt::TabFocusAllControls) : int(Qt::TabFocusTextControls | Qt::TabFocusListControls)); case IconPixmapSizes: { qreal devicePixelRatio = qGuiApp->devicePixelRatio(); QList sizes;