From ff3e831ac1b71638d366132a9025817769632c02 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 21 Oct 2024 01:58:02 +0400 Subject: [PATCH] Use KDE's icon engine It has KDE color schemes support that prevents dark icons on dark background --- CMakeLists.txt | 1 + src/qt6ct-qtplugin/CMakeLists.txt | 3 ++- src/qt6ct-qtplugin/qt6ctplatformtheme.cpp | 12 ++++++++++++ src/qt6ct-qtplugin/qt6ctplatformtheme.h | 4 +++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e09dc0a..1cc9f61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000 -DUSE_WIDGETS) find_package(Qt6 REQUIRED COMPONENTS BuildInternals Core Widgets OPTIONAL_COMPONENTS QuickControls2 LinguistTools) find_package(KF6Config) find_package(KF6ColorScheme) +find_package(KF6IconThemes) get_target_property(QT_QTPATHS_EXECUTABLE Qt6::qtpaths IMPORTED_LOCATION) diff --git a/src/qt6ct-qtplugin/CMakeLists.txt b/src/qt6ct-qtplugin/CMakeLists.txt index edf7029..6542289 100644 --- a/src/qt6ct-qtplugin/CMakeLists.txt +++ b/src/qt6ct-qtplugin/CMakeLists.txt @@ -9,5 +9,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../) add_library(qt6ct-qtplugin MODULE ${app_SRCS}) set_target_properties(qt6ct-qtplugin PROPERTIES OUTPUT_NAME qt6ct) -target_link_libraries(qt6ct-qtplugin PRIVATE Qt6::Widgets Qt6::GuiPrivate $ qt6ct-common) +target_link_libraries(qt6ct-qtplugin PRIVATE Qt6::Widgets Qt6::GuiPrivate $ $ qt6ct-common) +target_compile_definitions(qt6ct-qtplugin PRIVATE $<$:KF_ICONTHEMES_LIB>) install(TARGETS qt6ct-qtplugin DESTINATION ${PLUGINDIR}/platformthemes) diff --git a/src/qt6ct-qtplugin/qt6ctplatformtheme.cpp b/src/qt6ct-qtplugin/qt6ctplatformtheme.cpp index e03dbbc..c71496b 100644 --- a/src/qt6ct-qtplugin/qt6ctplatformtheme.cpp +++ b/src/qt6ct-qtplugin/qt6ctplatformtheme.cpp @@ -55,6 +55,11 @@ #include #include +#ifdef KF_ICONTHEMES_LIB +#include +#include +#endif + Q_LOGGING_CATEGORY(lqt6ct, "qt6ct", QtWarningMsg) //QT_QPA_PLATFORMTHEME=qt6ct @@ -160,6 +165,13 @@ QIcon Qt6CTPlatformTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::Ic return QIcon::fromTheme(type.iconName()); } +#ifdef KF_ICONTHEMES_LIB +QIconEngine *Qt6CTPlatformTheme::createIconEngine(const QString &iconName) const +{ + return new KIconEngine(iconName, KIconLoader::global()); +} +#endif + void Qt6CTPlatformTheme::applySettings() { if(!QGuiApplication::desktopSettingsAware() || m_isIgnored) diff --git a/src/qt6ct-qtplugin/qt6ctplatformtheme.h b/src/qt6ct-qtplugin/qt6ctplatformtheme.h index 358166d..79db7fa 100644 --- a/src/qt6ct-qtplugin/qt6ctplatformtheme.h +++ b/src/qt6ct-qtplugin/qt6ctplatformtheme.h @@ -62,7 +62,9 @@ class Qt6CTPlatformTheme : public QObject, public QGenericUnixTheme //virtual QPixmap fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &size, // QPlatformTheme::IconOptions iconOptions = 0) const; - //virtual QIconEngine *createIconEngine(const QString &iconName) const; +#ifdef KF_ICONTHEMES_LIB + virtual QIconEngine *createIconEngine(const QString &iconName) const override; +#endif //virtual QList keyBindings(QKeySequence::StandardKey key) const; //virtual QString standardButtonText(int button) const;