From ee143fe27dfe2824dae5d8cbc1d1b799506e0f69 Mon Sep 17 00:00:00 2001 From: Maximilian Goldstein Date: Thu, 17 Feb 2022 18:46:30 +0100 Subject: qquickapplication: Add styleHints property Implements a styleHints property to QQuickApplication for accessing QStyleHints so it can be utilized in a way that's compatible with tooling and compilers. [ChangeLog][QtQuick][New Feature] Qt.styleHints should now be accessed as a property of QQuickApplication via Application.styleHints Fixes: QTBUG-100993 Change-Id: I377c59072678a67d20f519cb5d329863111f295b Reviewed-by: Fabian Kosmale Reviewed-by: Andrei Golubev Reviewed-by: Shawn Rutledge Reviewed-by: Mitch Curtis --- src/qml/qml/qqmlbuiltinfunctions.cpp | 24 ++++-------------------- src/quick/util/qquickapplication.cpp | 31 +++++++++++++++++++++++++++++++ src/quick/util/qquickapplication_p.h | 3 +++ src/quick/util/qquickforeignutils_p.h | 8 ++++++++ 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/qml/qml/qqmlbuiltinfunctions.cpp b/src/qml/qml/qqmlbuiltinfunctions.cpp index 9213bd7c2d..565e0a085d 100644 --- a/src/qml/qml/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/qqmlbuiltinfunctions.cpp @@ -262,28 +262,12 @@ The following functions are also on the Qt object. \since 5.5 The \c styleHints object provides platform-specific style hints and settings. - See the QStyleHints documentation for further details. + See the \l QStyleHints documentation for further details. - \note The \c styleHints object is only available when using the Qt Quick module. - - The following example uses the \c styleHints object to determine whether an - item should gain focus on mouse press or touch release: - \code - import QtQuick 2.4 + You should access StyleHints via \l Application::styleHints instead. + See \l StyleHints for more details. - MouseArea { - id: button - - onPressed: { - if (!Qt.styleHints.setFocusOnTouchRelease) - button.forceActiveFocus() - } - onReleased: { - if (Qt.styleHints.setFocusOnTouchRelease) - button.forceActiveFocus() - } - } - \endcode + \note The \c styleHints object is only available when using the Qt Quick module. */ /*! diff --git a/src/quick/util/qquickapplication.cpp b/src/quick/util/qquickapplication.cpp index 0ed3990738..e850249b65 100644 --- a/src/quick/util/qquickapplication.cpp +++ b/src/quick/util/qquickapplication.cpp @@ -209,6 +209,32 @@ QT_BEGIN_NAMESPACE This property can be written to in order to set the organization domain. */ +/*! + \qmlproperty StyleHints Application::styleHints + + The \c styleHints property provides platform-specific style hints and settings. + See the \l QStyleHints documentation for further details. + + The following example uses \c styleHints to determine whether an + item should gain focus on mouse press or touch release: + \code + import QtQuick + + MouseArea { + id: button + + onPressed: { + if (!Application.styleHints.setFocusOnTouchRelease) + button.forceActiveFocus() + } + onReleased: { + if (Application.styleHints.setFocusOnTouchRelease) + button.forceActiveFocus() + } + } + \endcode + */ + /*! \qmlsignal Application::aboutToQuit() @@ -273,6 +299,11 @@ QString QQuickApplication::displayName() const return QGuiApplication::applicationDisplayName(); } +QStyleHints *QQuickApplication::styleHints() +{ + return QGuiApplication::styleHints(); +} + void QQuickApplication::setDisplayName(const QString &displayName) { return QGuiApplication::setApplicationDisplayName(displayName); diff --git a/src/quick/util/qquickapplication_p.h b/src/quick/util/qquickapplication_p.h index dd67b4b11d..d8f4b3a6ee 100644 --- a/src/quick/util/qquickapplication_p.h +++ b/src/quick/util/qquickapplication_p.h @@ -58,6 +58,7 @@ #include #include +#include #include @@ -73,6 +74,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickApplication : public QQmlApplication Q_PROPERTY(QFont font READ font CONSTANT) Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged) Q_PROPERTY(QQmlListProperty screens READ screens NOTIFY screensChanged) + Q_PROPERTY(QStyleHints *styleHints READ styleHints CONSTANT) QML_NAMED_ELEMENT(Application) QML_SINGLETON @@ -89,6 +91,7 @@ public: QQmlListProperty screens(); QString displayName() const; void setDisplayName(const QString &displayName); + QStyleHints *styleHints(); Q_SIGNALS: void activeChanged(); diff --git a/src/quick/util/qquickforeignutils_p.h b/src/quick/util/qquickforeignutils_p.h index 038d5fd30e..0f7869531f 100644 --- a/src/quick/util/qquickforeignutils_p.h +++ b/src/quick/util/qquickforeignutils_p.h @@ -67,6 +67,14 @@ QT_BEGIN_NAMESPACE +struct QStyleHintsForeign +{ + Q_GADGET + QML_FOREIGN(QStyleHints) + QML_ANONYMOUS + QML_ADDED_IN_VERSION(6, 4) +}; + #if QT_CONFIG(validator) struct QValidatorForeign { -- cgit v1.2.3