From d35feca20c02539d04f10c23fc057454cb3fcc12 Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Fri, 16 Sep 2022 16:14:49 +0200 Subject: Propagate appearance property from QPlatformTheme to QStyleHints Implement appearance property, getter and notifier in QStyleHints. Update appearance property in QStyleHints when handling theme change in QGuiApplicationPrivate. Task-number: QTBUG-106381 Change-Id: Idd67ca9df248ec9d9e67c0d48121e8eead11a9e2 Reviewed-by: Volker Hilsheimer --- src/gui/kernel/qguiapplication.cpp | 16 ++++++++++++ src/gui/kernel/qguiapplication_p.h | 2 ++ src/gui/kernel/qstylehints.cpp | 51 ++++++++++++++++++++++-------------- src/gui/kernel/qstylehints.h | 3 +++ src/gui/kernel/qstylehints_p.h | 53 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 106 insertions(+), 19 deletions(-) create mode 100644 src/gui/kernel/qstylehints_p.h (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 7ecdee7f0b..b99b08ca92 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -2553,6 +2554,21 @@ void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate:: const QWindowList windows = tce->window ? QWindowList{tce->window} : window_list; for (auto *window : windows) QGuiApplication::sendSpontaneousEvent(window, &themeChangeEvent); + + QStyleHintsPrivate::get(QGuiApplication::styleHints())->setAppearance(appearance()); +} + +/*! + \internal + \brief QGuiApplicationPrivate::appearance + \return the platform theme's appearance + or Qt::Appearance::Unknown if a platform theme cannot be established + Qt::Appearance. + */ +Qt::Appearance QGuiApplicationPrivate::appearance() +{ + return platformTheme() ? platformTheme()->appearance() + : Qt::Appearance::Unknown; } void QGuiApplicationPrivate::handleThemeChanged() diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 8309e2bfa7..82c9f45ad2 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -313,6 +313,8 @@ private: friend class QDragManager; + static Qt::Appearance appearance(); + static QGuiApplicationPrivate *self; static int m_fakeMouseSourcePointId; #ifdef Q_OS_WIN diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp index 042f793a27..6819aeaf2e 100644 --- a/src/gui/kernel/qstylehints.cpp +++ b/src/gui/kernel/qstylehints.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include +#include "qstylehints_p.h" #include #include #include @@ -43,25 +44,6 @@ static inline QVariant themeableHint(QPlatformTheme::ThemeHint th) return QPlatformTheme::defaultThemeHint(th); } -class QStyleHintsPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QStyleHints) -public: - int m_mouseDoubleClickInterval = -1; - int m_mousePressAndHoldInterval = -1; - int m_startDragDistance = -1; - int m_startDragTime = -1; - int m_keyboardInputInterval = -1; - int m_cursorFlashTime = -1; - int m_tabFocusBehavior = -1; - int m_uiEffects = -1; - int m_showShortcutsInContextMenus = -1; - int m_wheelScrollLines = -1; - int m_mouseQuickSelectionThreshold = -1; - int m_mouseDoubleClickDistance = -1; - int m_touchDoubleTapDistance = -1; -}; - /*! \class QStyleHints \since 5.0 @@ -139,6 +121,17 @@ int QStyleHints::touchDoubleTapDistance() const themeableHint(QPlatformTheme::TouchDoubleTapDistance).toInt(); } +/*! + \property QStyleHints::appearance + \brief the appearance of the platform theme + \sa Qt::Appearance + \since 6.5 +*/ +Qt::Appearance QStyleHints::appearance() const +{ + return d_func()->appearance(); +} + /*! Sets the \a mousePressAndHoldInterval. \internal @@ -583,6 +576,26 @@ int QStyleHints::mouseQuickSelectionThreshold() const return themeableHint(QPlatformTheme::MouseQuickSelectionThreshold, QPlatformIntegration::MouseQuickSelectionThreshold).toInt(); } +/*! + \internal + QStyleHintsPrivate::setAppearance - set a new appearance. + Set \a appearance as the new appearance of the QStyleHints. + The appearanceChanged signal will be emitted if present and new appearance differ. + */ +void QStyleHintsPrivate::setAppearance(Qt::Appearance appearance) +{ + if (m_appearance != appearance) { + m_appearance = appearance; + emit q_func()->appearanceChanged(appearance); + } +} + +QStyleHintsPrivate *QStyleHintsPrivate::get(QStyleHints *q) +{ + Q_ASSERT(q); + return q->d_func(); +} + QT_END_NAMESPACE #include "moc_qstylehints.cpp" diff --git a/src/gui/kernel/qstylehints.h b/src/gui/kernel/qstylehints.h index 8e54a76475..e32d9b5df3 100644 --- a/src/gui/kernel/qstylehints.h +++ b/src/gui/kernel/qstylehints.h @@ -49,6 +49,7 @@ class Q_GUI_EXPORT QStyleHints : public QObject Q_PROPERTY(int mouseDoubleClickDistance READ mouseDoubleClickDistance STORED false CONSTANT FINAL) Q_PROPERTY(int touchDoubleTapDistance READ touchDoubleTapDistance STORED false CONSTANT FINAL) + Q_PROPERTY(Qt::Appearance appearance READ appearance NOTIFY appearanceChanged FINAL) public: void setMouseDoubleClickInterval(int mouseDoubleClickInterval); @@ -85,6 +86,7 @@ public: void setWheelScrollLines(int scrollLines); void setMouseQuickSelectionThreshold(int threshold); int mouseQuickSelectionThreshold() const; + Qt::Appearance appearance() const; Q_SIGNALS: void cursorFlashTimeChanged(int cursorFlashTime); @@ -98,6 +100,7 @@ Q_SIGNALS: void showShortcutsInContextMenusChanged(bool); void wheelScrollLinesChanged(int scrollLines); void mouseQuickSelectionThresholdChanged(int threshold); + void appearanceChanged(Qt::Appearance appearance); private: friend class QGuiApplication; diff --git a/src/gui/kernel/qstylehints_p.h b/src/gui/kernel/qstylehints_p.h new file mode 100644 index 0000000000..4a16fbef01 --- /dev/null +++ b/src/gui/kernel/qstylehints_p.h @@ -0,0 +1,53 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef QSTYLEHINTS_P_H +#define QSTYLEHINTS_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include "qstylehints.h" + +QT_BEGIN_NAMESPACE + +class QStyleHintsPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QStyleHints) +public: + int m_mouseDoubleClickInterval = -1; + int m_mousePressAndHoldInterval = -1; + int m_startDragDistance = -1; + int m_startDragTime = -1; + int m_keyboardInputInterval = -1; + int m_cursorFlashTime = -1; + int m_tabFocusBehavior = -1; + int m_uiEffects = -1; + int m_showShortcutsInContextMenus = -1; + int m_wheelScrollLines = -1; + int m_mouseQuickSelectionThreshold = -1; + int m_mouseDoubleClickDistance = -1; + int m_touchDoubleTapDistance = -1; + + Qt::Appearance appearance() const { return m_appearance; }; + void setAppearance(Qt::Appearance appearance); + static QStyleHintsPrivate *get(QStyleHints *q); + +private: + Qt::Appearance m_appearance = Qt::Appearance::Unknown; +}; + +QT_END_NAMESPACE + +#endif -- cgit v1.2.3