From 2d6a97b77b5e2cd6235b24ab56b4b7850a2d0ad3 Mon Sep 17 00:00:00 2001 From: Wang Zichong Date: Mon, 13 Mar 2023 11:02:24 +0800 Subject: [PATCH] chore: option to use KIconThemes instead of Qt5XdgIconLoader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 提供选项,使用 KIconThemes 的 KIconEngine 取代 Qt5XdgIconLoader Log: --- CMakeLists.txt | 6 +++++- src/CMakeLists.txt | 10 ++++++---- src/util/dicontheme.cpp | 25 +++++++++++++++++++------ src/util/util.cmake | 38 +++++++++++++++++++++++--------------- 4 files changed, 53 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae38cceb..d3215cfa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ project(DtkGui set(LIB_NAME dtkgui) include(GNUInstallDirs) +include(FeatureSummary) include(CMakePackageConfigHelpers) list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") set(CMAKE_CXX_STANDARD 11) @@ -19,7 +20,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Set build option -option(DTK_DISABLE_LIBXDG "Disable libxdg" OFF) +option(DTK_DISABLE_ICON_ENGINE_PROXY "Disable icon engine, use QIcon::fromTheme() as possible fallback" OFF) +option(DTK_DISABLE_LIBXDG "If icon engine proxy is used, prefer KIconEngine instead of using libqxdg" OFF) option(DTK_DISABLE_LIBRSVG "Disable librsvg" OFF) option(DTK_DISABLE_EX_IMAGE_FORMAT "Disable libraw and freeimage" OFF) set(BUILD_DOCS ON CACHE BOOL "Generate doxygen-based documentation") @@ -132,3 +134,5 @@ add_subdirectory(examples) if (BUILD_DOCS) add_subdirectory(docs) endif () + +feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 16544781..1bc191a4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,10 +47,12 @@ if(NOT DTK_DISABLE_EX_IMAGE_FORMAT AND EX_IMAGE_FORMAT_LIBS_FOUND) ) endif() -if(NOT DTK_DISABLE_LIBXDG) - target_link_libraries(${LIB_NAME} PRIVATE - Qt5XdgIconLoader - ) +if(NOT DTK_DISABLE_ICON_ENGINE_PROXY) + if(DTK_DISABLE_LIBXDG) + target_link_libraries(${LIB_NAME} PRIVATE KF5::IconThemes) + else() + target_link_libraries(${LIB_NAME} PRIVATE Qt5XdgIconLoader) + endif() endif() set_target_properties(${LIB_NAME} PROPERTIES diff --git a/src/util/dicontheme.cpp b/src/util/dicontheme.cpp index c5c560c9..8109f052 100644 --- a/src/util/dicontheme.cpp +++ b/src/util/dicontheme.cpp @@ -4,8 +4,13 @@ #include "dicontheme.h" #include "private/dbuiltiniconengine_p.h" -#ifndef DTK_DISABLE_LIBXDG -#include "private/xdgiconproxyengine_p.h" +#ifndef DTK_DISABLE_ICON_ENGINE_PROXY + #ifndef DTK_DISABLE_LIBXDG + #include "private/xdgiconproxyengine_p.h" + #else + #include + #include + #endif #endif #include @@ -87,10 +92,14 @@ static inline QIconEngine *createBuiltinIconEngine(const QString &iconName) return new DBuiltinIconEngine(iconName); } -#ifndef DTK_DISABLE_LIBXDG +#ifndef DTK_DISABLE_ICON_ENGINE_PROXY static inline QIconEngine *createXdgProxyIconEngine(const QString &iconName) { +#ifndef DTK_DISABLE_LIBXDG return new XdgIconProxyEngine(new XdgIconLoaderEngine(iconName)); +#else + return new KIconEngine(iconName, KIconLoader::global()); +#endif } #endif @@ -116,7 +125,7 @@ QIcon DIconTheme::findQIcon(const QString &iconName, Options options) } } -#ifdef DTK_DISABLE_LIBXDG +#ifdef DTK_DISABLE_ICON_ENGINE_PROXY if (options.testFlag(DontFallbackToQIconFromTheme)) return QIcon(); return QIcon::fromTheme(iconName); @@ -135,12 +144,16 @@ bool DIconTheme::isBuiltinIcon(const QIcon &icon) bool DIconTheme::isXdgIcon(const QIcon &icon) { -#ifdef DTK_DISABLE_LIBXDG +#ifdef DTK_DISABLE_ICON_ENGINE_PROXY return false; #else if (icon.isNull()) return false; - return typeid(*const_cast(icon).data_ptr()->engine) == typeid(XdgIconProxyEngine); + #ifndef DTK_DISABLE_LIBXDG + return typeid(*const_cast(icon).data_ptr()->engine) == typeid(XdgIconProxyEngine); + #else + return typeid(*const_cast(icon).data_ptr()->engine) == typeid(KIconEngine); + #endif #endif } diff --git a/src/util/util.cmake b/src/util/util.cmake index d1535471..28415cff 100644 --- a/src/util/util.cmake +++ b/src/util/util.cmake @@ -1,20 +1,28 @@ -if(NOT DTK_DISABLE_LIBXDG) - find_package(qt5xdgiconloader) +set(UTIL_PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/private/dbuiltiniconengine_p.h + ${CMAKE_CURRENT_LIST_DIR}/private/dbuiltiniconengine.cpp + ${CMAKE_CURRENT_LIST_DIR}/private/dimagehandlerlibs_p.h +) + +if(NOT DTK_DISABLE_ICON_ENGINE_PROXY) + if(NOT DTK_DISABLE_LIBXDG) + find_package(qt5xdgiconloader REQUIRED) add_definitions(-DXDG_ICON_VERSION_MAR=${qt5xdgiconloader_VERSION_MAJOR}) - set(UTIL_PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/private/xdgiconproxyengine_p.h - ${CMAKE_CURRENT_LIST_DIR}/private/xdgiconproxyengine.cpp - ${CMAKE_CURRENT_LIST_DIR}/private/dbuiltiniconengine_p.h - ${CMAKE_CURRENT_LIST_DIR}/private/dbuiltiniconengine.cpp - ${CMAKE_CURRENT_LIST_DIR}/private/dimagehandlerlibs_p.h - ) -else() - add_definitions(-DDTK_DISABLE_LIBXDG) - set(UTIL_PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/private/dbuiltiniconengine_p.h - ${CMAKE_CURRENT_LIST_DIR}/private/dbuiltiniconengine.cpp - ${CMAKE_CURRENT_LIST_DIR}/private/dimagehandlerlibs_p.h + list(APPEND UTIL_PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/private/xdgiconproxyengine_p.h + ${CMAKE_CURRENT_LIST_DIR}/private/xdgiconproxyengine.cpp ) + else() + find_package(KF5IconThemes REQUIRED) + endif() +endif() + +if(DTK_DISABLE_ICON_ENGINE_PROXY) + add_definitions(-DDTK_DISABLE_ICON_ENGINE_PROXY) +endif() + +if(DTK_DISABLE_LIBXDG) + add_definitions(-DDTK_DISABLE_LIBXDG) endif() if(DTK_DISABLE_EX_IMAGE_FORMAT OR NOT EX_IMAGE_FORMAT_LIBS_FOUND)