Skip to content

Commit

Permalink
chore: option to use KIconThemes instead of Qt5XdgIconLoader
Browse files Browse the repository at this point in the history
提供选项,使用 KIconThemes 的 KIconEngine 取代 Qt5XdgIconLoader

Log:
  • Loading branch information
BLumia committed Mar 13, 2023
1 parent 2e966e9 commit 2d6a97b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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)
10 changes: 6 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 19 additions & 6 deletions src/util/dicontheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <KIconEngine>
#include <KIconLoader>
#endif
#endif

#include <DStandardPaths>
Expand Down Expand Up @@ -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

Expand All @@ -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);
Expand All @@ -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<QIcon&>(icon).data_ptr()->engine) == typeid(XdgIconProxyEngine);
#ifndef DTK_DISABLE_LIBXDG
return typeid(*const_cast<QIcon&>(icon).data_ptr()->engine) == typeid(XdgIconProxyEngine);
#else
return typeid(*const_cast<QIcon&>(icon).data_ptr()->engine) == typeid(KIconEngine);
#endif
#endif
}

Expand Down
38 changes: 23 additions & 15 deletions src/util/util.cmake
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 2d6a97b

Please sign in to comment.