diff options
Diffstat (limited to 'src/gui/platform')
-rw-r--r-- | src/gui/platform/darwin/qapplekeymapper.mm | 32 | ||||
-rw-r--r-- | src/gui/platform/darwin/qmetallayer.mm | 73 | ||||
-rw-r--r-- | src/gui/platform/darwin/qmetallayer_p.h | 41 | ||||
-rw-r--r-- | src/gui/platform/ios/qiosnativeinterface.cpp | 26 | ||||
-rw-r--r-- | src/gui/platform/unix/qgenericunixthemes.cpp | 291 |
5 files changed, 387 insertions, 76 deletions
diff --git a/src/gui/platform/darwin/qapplekeymapper.mm b/src/gui/platform/darwin/qapplekeymapper.mm index b8ff5c9d6d..9166d8baba 100644 --- a/src/gui/platform/darwin/qapplekeymapper.mm +++ b/src/gui/platform/darwin/qapplekeymapper.mm @@ -455,23 +455,21 @@ const QAppleKeyMapper::KeyMap &QAppleKeyMapper::keyMapForKey(VirtualKeyCode virt if (err == noErr && actualStringLength) carbonUnicodeKey = QChar(unicodeString[0]); - if (@available(macOS 10.15, *)) { - if (canMapCocoaEvent) { - // Until we've verified that the Cocoa API works as expected - // we first run the event through the Carbon APIs and then - // compare the results to Cocoa. - auto cocoaModifiers = toCocoaModifiers(qtModifiers); - auto *charactersWithModifiers = [NSApp.currentEvent charactersByApplyingModifiers:cocoaModifiers]; - - QChar cocoaUnicodeKey; - if (charactersWithModifiers.length > 0) - cocoaUnicodeKey = QChar([charactersWithModifiers characterAtIndex:0]); - - if (cocoaUnicodeKey != carbonUnicodeKey) { - qCWarning(lcQpaKeyMapper) << "Mismatch between Cocoa" << cocoaUnicodeKey - << "and Carbon" << carbonUnicodeKey << "for virtual key" << virtualKey - << "with" << qtModifiers; - } + if (canMapCocoaEvent) { + // Until we've verified that the Cocoa API works as expected + // we first run the event through the Carbon APIs and then + // compare the results to Cocoa. + auto cocoaModifiers = toCocoaModifiers(qtModifiers); + auto *charactersWithModifiers = [NSApp.currentEvent charactersByApplyingModifiers:cocoaModifiers]; + + QChar cocoaUnicodeKey; + if (charactersWithModifiers.length > 0) + cocoaUnicodeKey = QChar([charactersWithModifiers characterAtIndex:0]); + + if (cocoaUnicodeKey != carbonUnicodeKey) { + qCWarning(lcQpaKeyMapper) << "Mismatch between Cocoa" << cocoaUnicodeKey + << "and Carbon" << carbonUnicodeKey << "for virtual key" << virtualKey + << "with" << qtModifiers; } } diff --git a/src/gui/platform/darwin/qmetallayer.mm b/src/gui/platform/darwin/qmetallayer.mm new file mode 100644 index 0000000000..e8a27a7b06 --- /dev/null +++ b/src/gui/platform/darwin/qmetallayer.mm @@ -0,0 +1,73 @@ +// Copyright (C) 2024 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 + +#include "qmetallayer_p.h" + +#include <QtCore/qreadwritelock.h> +#include <QtCore/qrect.h> + +using namespace std::chrono_literals; + +QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(lcMetalLayer, "qt.gui.metal") +QT_END_NAMESPACE + +QT_USE_NAMESPACE + +@implementation QMetalLayer +{ + std::unique_ptr<QReadWriteLock> m_displayLock; +} + +- (instancetype)init +{ + if ((self = [super init])) { + m_displayLock.reset(new QReadWriteLock(QReadWriteLock::Recursive)); + self.mainThreadPresentation = nil; + } + + return self; +} + +- (QReadWriteLock &)displayLock +{ + return *m_displayLock.get(); +} + +- (void)setNeedsDisplay +{ + [self setNeedsDisplayInRect:CGRectInfinite]; +} + +- (void)setNeedsDisplayInRect:(CGRect)rect +{ + if (!self.needsDisplay) { + // We lock for writing here, blocking in case a secondary thread is in + // the middle of presenting to the layer, as we want the main thread's + // display to happen after the secondary thread finishes presenting. + qCDebug(lcMetalLayer) << "Locking" << self << "for writing" + << "due to needing display in rect" << QRectF::fromCGRect(rect); + + // For added safety, we use a 5 second timeout, and try to fail + // gracefully by not marking the layer as needing display, as + // doing so would lead us to unlock and unheld lock in displayLayer. + if (!self.displayLock.tryLockForWrite(5s)) { + qCWarning(lcMetalLayer) << "Timed out waiting for display lock"; + return; + } + } + + [super setNeedsDisplayInRect:rect]; +} + +- (id<CAMetalDrawable>)nextDrawable +{ + // Drop the presentation block early, so that if the main thread for + // some reason doesn't handle the presentation, the block won't hold on + // to a drawable unnecessarily. + self.mainThreadPresentation = nil; + return [super nextDrawable]; +} + + +@end diff --git a/src/gui/platform/darwin/qmetallayer_p.h b/src/gui/platform/darwin/qmetallayer_p.h new file mode 100644 index 0000000000..81f8760ec2 --- /dev/null +++ b/src/gui/platform/darwin/qmetallayer_p.h @@ -0,0 +1,41 @@ +// Copyright (C) 2024 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 QMETALLAYER_P_H +#define QMETALLAYER_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 <QtGui/qtguiglobal.h> + +#include <QtCore/qreadwritelock.h> +#include <QtCore/qloggingcategory.h> +#include <QtCore/private/qcore_mac_p.h> + +#include <QuartzCore/CAMetalLayer.h> + +QT_BEGIN_NAMESPACE +class QReadWriteLock; + +QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY(lcMetalLayer, Q_GUI_EXPORT) + +QT_END_NAMESPACE + +#if defined(__OBJC__) +Q_GUI_EXPORT +#endif +QT_DECLARE_NAMESPACED_OBJC_INTERFACE(QMetalLayer, CAMetalLayer +@property (nonatomic, readonly) QT_PREPEND_NAMESPACE(QReadWriteLock) &displayLock; +@property (atomic, copy) void (^mainThreadPresentation)(); +) + +#endif // QMETALLAYER_P_H diff --git a/src/gui/platform/ios/qiosnativeinterface.cpp b/src/gui/platform/ios/qiosnativeinterface.cpp new file mode 100644 index 0000000000..c942709e33 --- /dev/null +++ b/src/gui/platform/ios/qiosnativeinterface.cpp @@ -0,0 +1,26 @@ +// Copyright (C) 2024 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 + +#include <QtGui/private/qguiapplication_p.h> + +QT_BEGIN_NAMESPACE + +using namespace QNativeInterface::Private; + +#if defined(Q_OS_VISIONOS) + +/*! + \class QNativeInterface::QVisionOSApplication + \since 6.8 + \internal + \preliminary + \brief Native interface to QGuiApplication, to be retrieved from QPlatformIntegration. + \inmodule QtGui + \ingroup native-interfaces +*/ + +QT_DEFINE_NATIVE_INTERFACE(QVisionOSApplication); + +#endif // Q_OS_VISIONOS + +QT_END_NAMESPACE diff --git a/src/gui/platform/unix/qgenericunixthemes.cpp b/src/gui/platform/unix/qgenericunixthemes.cpp index fc4b2296d2..8a7f7cd6f7 100644 --- a/src/gui/platform/unix/qgenericunixthemes.cpp +++ b/src/gui/platform/unix/qgenericunixthemes.cpp @@ -78,17 +78,14 @@ static const char defaultFixedFontNameC[] = "monospace"; enum { defaultSystemFontSize = 9 }; #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) -static bool isDBusTrayAvailable() { - static bool dbusTrayAvailable = false; - static bool dbusTrayAvailableKnown = false; - if (!dbusTrayAvailableKnown) { - QDBusMenuConnection conn; - if (conn.isWatcherRegistered()) - dbusTrayAvailable = true; - dbusTrayAvailableKnown = true; - qCDebug(qLcTray) << "D-Bus tray available:" << dbusTrayAvailable; - } - return dbusTrayAvailable; +static bool shouldUseDBusTray() { + // There's no other tray implementation to fallback to on non-X11 + // and QDBusTrayIcon can register the icon on the fly after creation + if (QGuiApplication::platformName() != "xcb"_L1) + return true; + const bool result = QDBusMenuConnection().isWatcherRegistered(); + qCDebug(qLcTray) << "D-Bus tray available:" << result; + return result; } #endif @@ -476,7 +473,7 @@ QPlatformMenuBar *QGenericUnixTheme::createPlatformMenuBar() const #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) QPlatformSystemTrayIcon *QGenericUnixTheme::createPlatformSystemTrayIcon() const { - if (isDBusTrayAvailable()) + if (shouldUseDBusTray()) return new QDBusTrayIcon(); return nullptr; } @@ -541,6 +538,48 @@ class QKdeThemePrivate : public QPlatformThemePrivate { public: + enum class KdeSettingType { + Root, + KDE, + Icons, + ToolBarIcons, + ToolBarStyle, + Fonts, + Colors, + }; + + enum class KdeSetting { + WidgetStyle, + ColorScheme, + SingleClick, + ShowIconsOnPushButtons, + IconTheme, + ToolBarIconSize, + ToolButtonStyle, + WheelScrollLines, + DoubleClickInterval, + StartDragDistance, + StartDragTime, + CursorBlinkRate, + Font, + Fixed, + MenuFont, + ToolBarFont, + ButtonBackground, + WindowBackground, + ViewForeground, + WindowForeground, + ViewBackground, + SelectionBackground, + SelectionForeground, + ViewBackgroundAlternate, + ButtonForeground, + ViewForegroundLink, + ViewForegroundVisited, + TooltipBackground, + TooltipForeground, + }; + QKdeThemePrivate(const QStringList &kdeDirs, int kdeVersion); static QString kdeGlobals(const QString &kdeDir, int kdeVersion) @@ -551,7 +590,9 @@ public: } void refresh(); - static QVariant readKdeSetting(const QString &key, const QStringList &kdeDirs, int kdeVersion, QHash<QString, QSettings*> &kdeSettings); + static QVariant readKdeSetting(KdeSetting s, const QStringList &kdeDirs, int kdeVersion, QHash<QString, QSettings*> &settings); + QVariant readKdeSetting(KdeSetting s) const; + void clearKdeSettings() const; static void readKdeSystemPalette(const QStringList &kdeDirs, int kdeVersion, QHash<QString, QSettings*> &kdeSettings, QPalette *pal); static QFont *kdeFont(const QVariant &fontValue); static QStringList kdeIconThemeSearchPaths(const QStringList &kdeDirs); @@ -575,8 +616,9 @@ public: Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown; void updateColorScheme(const QString &themeName); -#ifndef QT_NO_DBUS private: + mutable QHash<QString, QSettings *> kdeSettings; +#ifndef QT_NO_DBUS std::unique_ptr<QGenericUnixThemeDBusListener> dbus; bool initDbus(); void settingChangedHandler(QGenericUnixThemeDBusListener::Provider provider, @@ -632,9 +674,136 @@ QKdeThemePrivate::QKdeThemePrivate(const QStringList &kdeDirs, int kdeVersion) #endif // QT_NO_DBUS } +static constexpr QLatin1StringView settingsPrefix(QKdeThemePrivate::KdeSettingType type) +{ + switch (type) { + case QKdeThemePrivate::KdeSettingType::Root: + return QLatin1StringView(); + case QKdeThemePrivate::KdeSettingType::KDE: + return QLatin1StringView("KDE/"); + case QKdeThemePrivate::KdeSettingType::Fonts: + return QLatin1StringView(); + case QKdeThemePrivate::KdeSettingType::Colors: + return QLatin1StringView("Colors:"); + case QKdeThemePrivate::KdeSettingType::Icons: + return QLatin1StringView("Icons/"); + case QKdeThemePrivate::KdeSettingType::ToolBarIcons: + return QLatin1StringView("ToolbarIcons/"); + case QKdeThemePrivate::KdeSettingType::ToolBarStyle: + return QLatin1StringView("Toolbar style/"); + } + Q_UNREACHABLE_RETURN(QLatin1StringView()); +} + +static constexpr QKdeThemePrivate::KdeSettingType settingsType(QKdeThemePrivate::KdeSetting setting) +{ +#define CASE(s, type) case QKdeThemePrivate::KdeSetting::s:\ + return QKdeThemePrivate::KdeSettingType::type + + switch (setting) { + CASE(WidgetStyle, Root); + CASE(ColorScheme, Root); + CASE(SingleClick, KDE); + CASE(ShowIconsOnPushButtons, KDE); + CASE(IconTheme, Icons); + CASE(ToolBarIconSize, ToolBarIcons); + CASE(ToolButtonStyle, ToolBarStyle); + CASE(WheelScrollLines, KDE); + CASE(DoubleClickInterval, KDE); + CASE(StartDragDistance, KDE); + CASE(StartDragTime, KDE); + CASE(CursorBlinkRate, KDE); + CASE(Font, Root); + CASE(Fixed, Root); + CASE(MenuFont, Root); + CASE(ToolBarFont, Root); + CASE(ButtonBackground, Colors); + CASE(WindowBackground, Colors); + CASE(ViewForeground, Colors); + CASE(WindowForeground, Colors); + CASE(ViewBackground, Colors); + CASE(SelectionBackground, Colors); + CASE(SelectionForeground, Colors); + CASE(ViewBackgroundAlternate, Colors); + CASE(ButtonForeground, Colors); + CASE(ViewForegroundLink, Colors); + CASE(ViewForegroundVisited, Colors); + CASE(TooltipBackground, Colors); + CASE(TooltipForeground, Colors); + }; + Q_UNREACHABLE_RETURN(QKdeThemePrivate::KdeSettingType::Root); +} +#undef CASE + +static constexpr QLatin1StringView settingsKey(QKdeThemePrivate::KdeSetting setting) +{ + switch (setting) { + case QKdeThemePrivate::KdeSetting::WidgetStyle: + return QLatin1StringView("widgetStyle"); + case QKdeThemePrivate::KdeSetting::ColorScheme: + return QLatin1StringView("ColorScheme"); + case QKdeThemePrivate::KdeSetting::SingleClick: + return QLatin1StringView("SingleClick"); + case QKdeThemePrivate::KdeSetting::ShowIconsOnPushButtons: + return QLatin1StringView("ShowIconsOnPushButtons"); + case QKdeThemePrivate::KdeSetting::IconTheme: + return QLatin1StringView("Theme"); + case QKdeThemePrivate::KdeSetting::ToolBarIconSize: + return QLatin1StringView("Size"); + case QKdeThemePrivate::KdeSetting::ToolButtonStyle: + return QLatin1StringView("ToolButtonStyle"); + case QKdeThemePrivate::KdeSetting::WheelScrollLines: + return QLatin1StringView("WheelScrollLines"); + case QKdeThemePrivate::KdeSetting::DoubleClickInterval: + return QLatin1StringView("DoubleClickInterval"); + case QKdeThemePrivate::KdeSetting::StartDragDistance: + return QLatin1StringView("StartDragDist"); + case QKdeThemePrivate::KdeSetting::StartDragTime: + return QLatin1StringView("StartDragTime"); + case QKdeThemePrivate::KdeSetting::CursorBlinkRate: + return QLatin1StringView("CursorBlinkRate"); + case QKdeThemePrivate::KdeSetting::Font: + return QLatin1StringView("font"); + case QKdeThemePrivate::KdeSetting::Fixed: + return QLatin1StringView("fixed"); + case QKdeThemePrivate::KdeSetting::MenuFont: + return QLatin1StringView("menuFont"); + case QKdeThemePrivate::KdeSetting::ToolBarFont: + return QLatin1StringView("toolBarFont"); + case QKdeThemePrivate::KdeSetting::ButtonBackground: + return QLatin1StringView("Button/BackgroundNormal"); + case QKdeThemePrivate::KdeSetting::WindowBackground: + return QLatin1StringView("Window/BackgroundNormal"); + case QKdeThemePrivate::KdeSetting::ViewForeground: + return QLatin1StringView("View/ForegroundNormal"); + case QKdeThemePrivate::KdeSetting::WindowForeground: + return QLatin1StringView("Window/ForegroundNormal"); + case QKdeThemePrivate::KdeSetting::ViewBackground: + return QLatin1StringView("View/BackgroundNormal"); + case QKdeThemePrivate::KdeSetting::SelectionBackground: + return QLatin1StringView("Selection/BackgroundNormal"); + case QKdeThemePrivate::KdeSetting::SelectionForeground: + return QLatin1StringView("Selection/ForegroundNormal"); + case QKdeThemePrivate::KdeSetting::ViewBackgroundAlternate: + return QLatin1StringView("View/BackgroundAlternate"); + case QKdeThemePrivate::KdeSetting::ButtonForeground: + return QLatin1StringView("Button/ForegroundNormal"); + case QKdeThemePrivate::KdeSetting::ViewForegroundLink: + return QLatin1StringView("View/ForegroundLink"); + case QKdeThemePrivate::KdeSetting::ViewForegroundVisited: + return QLatin1StringView("View/ForegroundVisited"); + case QKdeThemePrivate::KdeSetting::TooltipBackground: + return QLatin1StringView("Tooltip/BackgroundNormal"); + case QKdeThemePrivate::KdeSetting::TooltipForeground: + return QLatin1StringView("Tooltip/ForegroundNormal"); + }; + Q_UNREACHABLE_RETURN(QLatin1StringView()); +} + void QKdeThemePrivate::refresh() { resources.clear(); + clearKdeSettings(); toolButtonStyle = Qt::ToolButtonTextBesideIcon; toolBarIconSize = 0; @@ -647,45 +816,39 @@ void QKdeThemePrivate::refresh() else iconFallbackThemeName = iconThemeName = QStringLiteral("oxygen"); - QHash<QString, QSettings*> kdeSettings; - QPalette systemPalette = QPalette(); readKdeSystemPalette(kdeDirs, kdeVersion, kdeSettings, &systemPalette); resources.palettes[QPlatformTheme::SystemPalette] = new QPalette(systemPalette); //## TODO tooltip color - const QVariant styleValue = readKdeSetting(QStringLiteral("widgetStyle"), kdeDirs, kdeVersion, kdeSettings); + const QVariant styleValue = readKdeSetting(KdeSetting::WidgetStyle); if (styleValue.isValid()) { const QString style = styleValue.toString(); if (style != styleNames.front()) styleNames.push_front(style); } - const QVariant colorScheme = readKdeSetting(QStringLiteral("ColorScheme"), kdeDirs, - kdeVersion, kdeSettings); + const QVariant colorScheme = readKdeSetting(KdeSetting::ColorScheme); - if (colorScheme.isValid()) - updateColorScheme(colorScheme.toString()); - else - m_colorScheme = Qt::ColorScheme::Unknown; + updateColorScheme(colorScheme.toString()); - const QVariant singleClickValue = readKdeSetting(QStringLiteral("KDE/SingleClick"), kdeDirs, kdeVersion, kdeSettings); + const QVariant singleClickValue = readKdeSetting(KdeSetting::SingleClick); if (singleClickValue.isValid()) singleClick = singleClickValue.toBool(); - const QVariant showIconsOnPushButtonsValue = readKdeSetting(QStringLiteral("KDE/ShowIconsOnPushButtons"), kdeDirs, kdeVersion, kdeSettings); + const QVariant showIconsOnPushButtonsValue = readKdeSetting(KdeSetting::ShowIconsOnPushButtons); if (showIconsOnPushButtonsValue.isValid()) showIconsOnPushButtons = showIconsOnPushButtonsValue.toBool(); - const QVariant themeValue = readKdeSetting(QStringLiteral("Icons/Theme"), kdeDirs, kdeVersion, kdeSettings); + const QVariant themeValue = readKdeSetting(KdeSetting::IconTheme); if (themeValue.isValid()) iconThemeName = themeValue.toString(); - const QVariant toolBarIconSizeValue = readKdeSetting(QStringLiteral("ToolbarIcons/Size"), kdeDirs, kdeVersion, kdeSettings); + const QVariant toolBarIconSizeValue = readKdeSetting(KdeSetting::ToolBarIconSize); if (toolBarIconSizeValue.isValid()) toolBarIconSize = toolBarIconSizeValue.toInt(); - const QVariant toolbarStyleValue = readKdeSetting(QStringLiteral("Toolbar style/ToolButtonStyle"), kdeDirs, kdeVersion, kdeSettings); + const QVariant toolbarStyleValue = readKdeSetting(KdeSetting::ToolButtonStyle); if (toolbarStyleValue.isValid()) { const QString toolBarStyle = toolbarStyleValue.toString(); if (toolBarStyle == "TextBesideIcon"_L1) @@ -696,35 +859,35 @@ void QKdeThemePrivate::refresh() toolButtonStyle = Qt::ToolButtonTextUnderIcon; } - const QVariant wheelScrollLinesValue = readKdeSetting(QStringLiteral("KDE/WheelScrollLines"), kdeDirs, kdeVersion, kdeSettings); + const QVariant wheelScrollLinesValue = readKdeSetting(KdeSetting::WheelScrollLines); if (wheelScrollLinesValue.isValid()) wheelScrollLines = wheelScrollLinesValue.toInt(); - const QVariant doubleClickIntervalValue = readKdeSetting(QStringLiteral("KDE/DoubleClickInterval"), kdeDirs, kdeVersion, kdeSettings); + const QVariant doubleClickIntervalValue = readKdeSetting(KdeSetting::DoubleClickInterval); if (doubleClickIntervalValue.isValid()) doubleClickInterval = doubleClickIntervalValue.toInt(); - const QVariant startDragDistValue = readKdeSetting(QStringLiteral("KDE/StartDragDist"), kdeDirs, kdeVersion, kdeSettings); + const QVariant startDragDistValue = readKdeSetting(KdeSetting::StartDragDistance); if (startDragDistValue.isValid()) startDragDist = startDragDistValue.toInt(); - const QVariant startDragTimeValue = readKdeSetting(QStringLiteral("KDE/StartDragTime"), kdeDirs, kdeVersion, kdeSettings); + const QVariant startDragTimeValue = readKdeSetting(KdeSetting::StartDragTime); if (startDragTimeValue.isValid()) startDragTime = startDragTimeValue.toInt(); - const QVariant cursorBlinkRateValue = readKdeSetting(QStringLiteral("KDE/CursorBlinkRate"), kdeDirs, kdeVersion, kdeSettings); + const QVariant cursorBlinkRateValue = readKdeSetting(KdeSetting::CursorBlinkRate); if (cursorBlinkRateValue.isValid()) { cursorBlinkRate = cursorBlinkRateValue.toInt(); cursorBlinkRate = cursorBlinkRate > 0 ? qBound(200, cursorBlinkRate, 2000) : 0; } // Read system font, ignore 'smallestReadableFont' - if (QFont *systemFont = kdeFont(readKdeSetting(QStringLiteral("font"), kdeDirs, kdeVersion, kdeSettings))) + if (QFont *systemFont = kdeFont(readKdeSetting(KdeSetting::Font))) resources.fonts[QPlatformTheme::SystemFont] = systemFont; else resources.fonts[QPlatformTheme::SystemFont] = new QFont(QLatin1StringView(defaultSystemFontNameC), defaultSystemFontSize); - if (QFont *fixedFont = kdeFont(readKdeSetting(QStringLiteral("fixed"), kdeDirs, kdeVersion, kdeSettings))) { + if (QFont *fixedFont = kdeFont(readKdeSetting(KdeSetting::Fixed))) { resources.fonts[QPlatformTheme::FixedFont] = fixedFont; } else { fixedFont = new QFont(QLatin1StringView(defaultFixedFontNameC), defaultSystemFontSize); @@ -732,12 +895,12 @@ void QKdeThemePrivate::refresh() resources.fonts[QPlatformTheme::FixedFont] = fixedFont; } - if (QFont *menuFont = kdeFont(readKdeSetting(QStringLiteral("menuFont"), kdeDirs, kdeVersion, kdeSettings))) { + if (QFont *menuFont = kdeFont(readKdeSetting(KdeSetting::MenuFont))) { resources.fonts[QPlatformTheme::MenuFont] = menuFont; resources.fonts[QPlatformTheme::MenuBarFont] = new QFont(*menuFont); } - if (QFont *toolBarFont = kdeFont(readKdeSetting(QStringLiteral("toolBarFont"), kdeDirs, kdeVersion, kdeSettings))) + if (QFont *toolBarFont = kdeFont(readKdeSetting(KdeSetting::ToolBarFont))) resources.fonts[QPlatformTheme::ToolButtonFont] = toolBarFont; QWindowSystemInterface::handleThemeChange(); @@ -747,7 +910,7 @@ void QKdeThemePrivate::refresh() qDeleteAll(kdeSettings); } -QVariant QKdeThemePrivate::readKdeSetting(const QString &key, const QStringList &kdeDirs, int kdeVersion, QHash<QString, QSettings*> &kdeSettings) +QVariant QKdeThemePrivate::readKdeSetting(KdeSetting s, const QStringList &kdeDirs, int kdeVersion, QHash<QString, QSettings*> &kdeSettings) { for (const QString &kdeDir : kdeDirs) { QSettings *settings = kdeSettings.value(kdeDir); @@ -759,6 +922,7 @@ QVariant QKdeThemePrivate::readKdeSetting(const QString &key, const QStringList } } if (settings) { + const QString key = settingsPrefix(settingsType(s)) + settingsKey(s); const QVariant value = settings->value(key); if (value.isValid()) return value; @@ -767,6 +931,16 @@ QVariant QKdeThemePrivate::readKdeSetting(const QString &key, const QStringList return QVariant(); } +QVariant QKdeThemePrivate::readKdeSetting(KdeSetting s) const +{ + return readKdeSetting(s, kdeDirs, kdeVersion, kdeSettings); +} + +void QKdeThemePrivate::clearKdeSettings() const +{ + kdeSettings.clear(); +} + // Reads the color from the KDE configuration, and store it in the // palette with the given color role if found. static inline bool kdeColor(QPalette *pal, QPalette::ColorRole role, const QVariant &value) @@ -782,7 +956,7 @@ static inline bool kdeColor(QPalette *pal, QPalette::ColorRole role, const QVari void QKdeThemePrivate::readKdeSystemPalette(const QStringList &kdeDirs, int kdeVersion, QHash<QString, QSettings*> &kdeSettings, QPalette *pal) { - if (!kdeColor(pal, QPalette::Button, readKdeSetting(QStringLiteral("Colors:Button/BackgroundNormal"), kdeDirs, kdeVersion, kdeSettings))) { + if (!kdeColor(pal, QPalette::Button, readKdeSetting(KdeSetting::ButtonBackground, kdeDirs, kdeVersion, kdeSettings))) { // kcolorscheme.cpp: SetDefaultColors const QColor defaultWindowBackground(214, 210, 208); const QColor defaultButtonBackground(223, 220, 217); @@ -790,18 +964,18 @@ void QKdeThemePrivate::readKdeSystemPalette(const QStringList &kdeDirs, int kdeV return; } - kdeColor(pal, QPalette::Window, readKdeSetting(QStringLiteral("Colors:Window/BackgroundNormal"), kdeDirs, kdeVersion, kdeSettings)); - kdeColor(pal, QPalette::Text, readKdeSetting(QStringLiteral("Colors:View/ForegroundNormal"), kdeDirs, kdeVersion, kdeSettings)); - kdeColor(pal, QPalette::WindowText, readKdeSetting(QStringLiteral("Colors:Window/ForegroundNormal"), kdeDirs, kdeVersion, kdeSettings)); - kdeColor(pal, QPalette::Base, readKdeSetting(QStringLiteral("Colors:View/BackgroundNormal"), kdeDirs, kdeVersion, kdeSettings)); - kdeColor(pal, QPalette::Highlight, readKdeSetting(QStringLiteral("Colors:Selection/BackgroundNormal"), kdeDirs, kdeVersion, kdeSettings)); - kdeColor(pal, QPalette::HighlightedText, readKdeSetting(QStringLiteral("Colors:Selection/ForegroundNormal"), kdeDirs, kdeVersion, kdeSettings)); - kdeColor(pal, QPalette::AlternateBase, readKdeSetting(QStringLiteral("Colors:View/BackgroundAlternate"), kdeDirs, kdeVersion, kdeSettings)); - kdeColor(pal, QPalette::ButtonText, readKdeSetting(QStringLiteral("Colors:Button/ForegroundNormal"), kdeDirs, kdeVersion, kdeSettings)); - kdeColor(pal, QPalette::Link, readKdeSetting(QStringLiteral("Colors:View/ForegroundLink"), kdeDirs, kdeVersion, kdeSettings)); - kdeColor(pal, QPalette::LinkVisited, readKdeSetting(QStringLiteral("Colors:View/ForegroundVisited"), kdeDirs, kdeVersion, kdeSettings)); - kdeColor(pal, QPalette::ToolTipBase, readKdeSetting(QStringLiteral("Colors:Tooltip/BackgroundNormal"), kdeDirs, kdeVersion, kdeSettings)); - kdeColor(pal, QPalette::ToolTipText, readKdeSetting(QStringLiteral("Colors:Tooltip/ForegroundNormal"), kdeDirs, kdeVersion, kdeSettings)); + kdeColor(pal, QPalette::Window, readKdeSetting(KdeSetting::WindowBackground, kdeDirs, kdeVersion, kdeSettings)); + kdeColor(pal, QPalette::Text, readKdeSetting(KdeSetting::ViewForeground, kdeDirs, kdeVersion, kdeSettings)); + kdeColor(pal, QPalette::WindowText, readKdeSetting(KdeSetting::WindowForeground, kdeDirs, kdeVersion, kdeSettings)); + kdeColor(pal, QPalette::Base, readKdeSetting(KdeSetting::ViewBackground, kdeDirs, kdeVersion, kdeSettings)); + kdeColor(pal, QPalette::Highlight, readKdeSetting(KdeSetting::SelectionBackground, kdeDirs, kdeVersion, kdeSettings)); + kdeColor(pal, QPalette::HighlightedText, readKdeSetting(KdeSetting::SelectionForeground, kdeDirs, kdeVersion, kdeSettings)); + kdeColor(pal, QPalette::AlternateBase, readKdeSetting(KdeSetting::ViewBackgroundAlternate, kdeDirs, kdeVersion, kdeSettings)); + kdeColor(pal, QPalette::ButtonText, readKdeSetting(KdeSetting::ButtonForeground, kdeDirs, kdeVersion, kdeSettings)); + kdeColor(pal, QPalette::Link, readKdeSetting(KdeSetting::ViewForegroundLink, kdeDirs, kdeVersion, kdeSettings)); + kdeColor(pal, QPalette::LinkVisited, readKdeSetting(KdeSetting::ViewForegroundVisited, kdeDirs, kdeVersion, kdeSettings)); + kdeColor(pal, QPalette::ToolTipBase, readKdeSetting(KdeSetting::TooltipBackground, kdeDirs, kdeVersion, kdeSettings)); + kdeColor(pal, QPalette::ToolTipText, readKdeSetting(KdeSetting::TooltipForeground, kdeDirs, kdeVersion, kdeSettings)); // The above code sets _all_ color roles to "normal" colors. In KDE, the disabled // color roles are calculated by applying various effects described in kdeglobals. @@ -957,13 +1131,13 @@ Qt::ColorScheme QKdeTheme::colorScheme() const /*! \internal - \brief QKdeTheme::updateColorScheme - guess and set appearance for unix themes. - KDE themes do not have an appearance property. - The key words "dark" or "light" should be part of the theme name. + \brief QKdeTheme::updateColorScheme - guess and set a color scheme for unix themes. + KDE themes do not have a color scheme property. + The key words "dark" or "light" are usually part of the theme name. This is, however, not a mandatory convention. - If \param themeName contains a key word, the respective appearance is set. - If it doesn't, the appearance is heuristically determined by comparing text and base color + If \param themeName contains a valid key word, the respective color scheme is set. + If it doesn't, the color scheme is heuristically determined by comparing text and base color of the system palette. */ void QKdeThemePrivate::updateColorScheme(const QString &themeName) @@ -991,7 +1165,6 @@ void QKdeThemePrivate::updateColorScheme(const QString &themeName) m_colorScheme = Qt::ColorScheme::Unknown; } - const QPalette *QKdeTheme::palette(Palette type) const { Q_D(const QKdeTheme); @@ -1071,7 +1244,7 @@ QPlatformMenuBar *QKdeTheme::createPlatformMenuBar() const #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) QPlatformSystemTrayIcon *QKdeTheme::createPlatformSystemTrayIcon() const { - if (isDBusTrayAvailable()) + if (shouldUseDBusTray()) return new QDBusTrayIcon(); return nullptr; } @@ -1266,7 +1439,7 @@ Qt::ColorScheme QGnomeTheme::colorScheme() const #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) QPlatformSystemTrayIcon *QGnomeTheme::createPlatformSystemTrayIcon() const { - if (isDBusTrayAvailable()) + if (shouldUseDBusTray()) return new QDBusTrayIcon(); return nullptr; } |