summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2022-09-16 16:14:49 +0200
committerAxel Spoerl <axel.spoerl@qt.io>2022-09-24 01:30:48 +0200
commitd35feca20c02539d04f10c23fc057454cb3fcc12 (patch)
treef6aaf331877207697be38f52c23c2f78e48f9e4b /src/gui/kernel
parentac2154c7e90d68e4477cb383d1090aaa1939efec (diff)
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 <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qguiapplication.cpp16
-rw-r--r--src/gui/kernel/qguiapplication_p.h2
-rw-r--r--src/gui/kernel/qstylehints.cpp51
-rw-r--r--src/gui/kernel/qstylehints.h3
-rw-r--r--src/gui/kernel/qstylehints_p.h53
5 files changed, 106 insertions, 19 deletions
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 <QtGui/qgenericpluginfactory.h>
#include <QtGui/qstylehints.h>
+#include <QtGui/private/qstylehints_p.h>
#include <QtGui/qinputmethod.h>
#include <QtGui/qpixmapcache.h>
#include <qpa/qplatforminputcontext.h>
@@ -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 <qstylehints.h>
+#include "qstylehints_p.h"
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformtheme.h>
#include <private/qguiapplication_p.h>
@@ -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
@@ -140,6 +122,17 @@ int QStyleHints::touchDoubleTapDistance() const
}
/*!
+ \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
\sa mousePressAndHoldInterval()
@@ -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 <qpa/qplatformintegration.h>
+#include <QPalette>
+#include <private/qguiapplication_p.h>
+#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