Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions platformthemeplugin/qdeepintheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,19 +672,67 @@ const QPalette *QDeepinTheme::palette(QPlatformTheme::Palette type) const
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
Qt::ColorScheme QDeepinTheme::colorScheme() const
{
if (m_requestedColorScheme != Qt::ColorScheme::Unknown)
return m_requestedColorScheme;

auto *helper = DGuiApplicationHelper::instance();
if (!helper)
return QGenericUnixTheme::colorScheme();

switch (helper->themeType()) {
case DGuiApplicationHelper::DarkType:
return Qt::ColorScheme::Dark;
case DGuiApplicationHelper::LightType:
return Qt::ColorScheme::Light;
default:
return Qt::ColorScheme::Unknown;
// Check DTK's explicit palette type first. This value may be set by
// setPaletteType() or restored from DConfig persistence across sessions.
if (helper->paletteType() != DGuiApplicationHelper::UnknownType) {
switch (helper->paletteType()) {
case DGuiApplicationHelper::DarkType:
return Qt::ColorScheme::Dark;
case DGuiApplicationHelper::LightType:
return Qt::ColorScheme::Light;
default:
break;
}
}

// Fall back to DPlatformTheme::themeName() for system theme detection,
// consistent with DTK's fetchPalette(). Don't use themeType() here
// because it falls back to palette luminance via toColorType(), and
// during QGuiApplicationPrivate::handleThemeChanged() the palette
// hasn't been updated yet when colorScheme() is called.
DPlatformTheme *theme = helper->applicationTheme();
if (theme) {
const QByteArray themeName = theme->themeName();
if (themeName.endsWith("dark"))
return Qt::ColorScheme::Dark;
}

return Qt::ColorScheme::Light;
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
void QDeepinTheme::requestColorScheme(Qt::ColorScheme scheme)
{
// Don't skip Unknown requests: they need to reset the DTK palette type
// even when m_requestedColorScheme is already Unknown (e.g. DConfig
// persisted a non-Unknown palette type from a previous session).
if (m_requestedColorScheme == scheme && scheme != Qt::ColorScheme::Unknown)
return;
m_requestedColorScheme = scheme;
QPlatformTheme::requestColorScheme(scheme);

if (auto *helper = DGuiApplicationHelper::instance()) {
switch (scheme) {
case Qt::ColorScheme::Dark:
helper->setPaletteType(DGuiApplicationHelper::DarkType);
break;
case Qt::ColorScheme::Light:
helper->setPaletteType(DGuiApplicationHelper::LightType);
break;
case Qt::ColorScheme::Unknown:
helper->setPaletteType(DGuiApplicationHelper::UnknownType);
break;
}
}
}
#endif
#endif

static QFont *createUnresolveFont(const QString &family, qreal pointSize)
Expand Down
6 changes: 6 additions & 0 deletions platformthemeplugin/qdeepintheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class QDeepinTheme : public QGenericUnixTheme
const QPalette *palette(Palette type) const override;
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
Qt::ColorScheme colorScheme() const override;
#endif
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
void requestColorScheme(Qt::ColorScheme scheme) override;
#endif
const QFont *font(Font type) const Q_DECL_OVERRIDE;
DThemeSettings *settings() const;
Expand All @@ -54,6 +57,9 @@ class QDeepinTheme : public QGenericUnixTheme
static bool m_usePlatformNativeDialog;
static QMimeDatabase m_mimeDatabase;
static DThemeSettings *m_settings;
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
Qt::ColorScheme m_requestedColorScheme = Qt::ColorScheme::Unknown;
#endif

friend class QDeepinFileDialogHelper;
friend class QDeepinPlatformMenu;
Expand Down
Loading