Prepare for replacing Qt::Appearance with Qt::ColorScheme

Based on discussions in the 6.5 API review, where we concluded that
'appearance' is too general. Instead, we follow the CSS standard
and use the term 'color scheme'.

This patch is a first step, only introducing the new API, so that
submodules can port over. The next step will be to remove the old
API and transition the docs and platform themes.

Pick-to: 6.5
Change-Id: I43cdb6bb1ccb49c535c06b1897821467fd83ca60
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Tor Arne Vestbø 2023-02-09 13:46:06 +01:00
parent 0f50145e43
commit 92f5836fe8
7 changed files with 28 additions and 0 deletions

View File

@ -52,6 +52,12 @@ namespace Qt {
Dark,
};
enum class ColorScheme {
Unknown,
Light,
Dark,
};
enum MouseButton {
NoButton = 0x00000000,
LeftButton = 0x00000001,
@ -1758,6 +1764,7 @@ namespace Qt {
Q_ENUM_NS(CursorShape)
Q_ENUM_NS(GlobalColor)
Q_ENUM_NS(Appearance)
Q_ENUM_NS(ColorScheme)
Q_ENUM_NS(AspectRatioMode)
Q_ENUM_NS(TransformationMode)
Q_FLAG_NS(ImageConversionFlags)

View File

@ -2611,6 +2611,12 @@ Qt::Appearance QGuiApplicationPrivate::appearance()
: Qt::Appearance::Unknown;
}
Qt::ColorScheme QGuiApplicationPrivate::colorScheme()
{
return platformTheme() ? platformTheme()->colorScheme()
: Qt::ColorScheme::Unknown;
}
void QGuiApplicationPrivate::handleThemeChanged()
{
updatePalette();

View File

@ -314,6 +314,7 @@ private:
friend class QDragManager;
static Qt::Appearance appearance();
static Qt::ColorScheme colorScheme();
static QGuiApplicationPrivate *self;
static int m_fakeMouseSourcePointId;

View File

@ -441,6 +441,11 @@ Qt::Appearance QPlatformTheme::appearance() const
return Qt::Appearance::Unknown;
}
Qt::ColorScheme QPlatformTheme::colorScheme() const
{
return Qt::ColorScheme(appearance());
}
const QPalette *QPlatformTheme::palette(Palette type) const
{
Q_D(const QPlatformTheme);

View File

@ -295,6 +295,7 @@ public:
#endif
virtual Qt::Appearance appearance() const;
virtual Qt::ColorScheme colorScheme() const;
virtual const QPalette *palette(Palette type = SystemPalette) const;

View File

@ -133,6 +133,11 @@ Qt::Appearance QStyleHints::appearance() const
return d->appearance();
}
Qt::ColorScheme QStyleHints::colorScheme() const
{
return Qt::ColorScheme(appearance());
}
/*!
Sets the \a mousePressAndHoldInterval.
\internal

View File

@ -53,6 +53,7 @@ class Q_GUI_EXPORT QStyleHints : public QObject
FINAL)
Q_PROPERTY(int touchDoubleTapDistance READ touchDoubleTapDistance STORED false CONSTANT FINAL)
Q_PROPERTY(Qt::Appearance appearance READ appearance NOTIFY appearanceChanged FINAL)
Q_PROPERTY(Qt::ColorScheme colorScheme READ colorScheme NOTIFY colorSchemeChanged FINAL)
public:
void setMouseDoubleClickInterval(int mouseDoubleClickInterval);
@ -94,6 +95,7 @@ public:
void setMouseQuickSelectionThreshold(int threshold);
int mouseQuickSelectionThreshold() const;
Qt::Appearance appearance() const;
Qt::ColorScheme colorScheme() const;
Q_SIGNALS:
void cursorFlashTimeChanged(int cursorFlashTime);
@ -108,6 +110,7 @@ Q_SIGNALS:
void wheelScrollLinesChanged(int scrollLines);
void mouseQuickSelectionThresholdChanged(int threshold);
void appearanceChanged(Qt::Appearance appearance);
void colorSchemeChanged(Qt::ColorScheme colorScheme);
private:
friend class QGuiApplication;