Skip to content

Commit

Permalink
Make dependency qlementine_icons not mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
oclero committed Nov 24, 2024
1 parent 7f487b3 commit e030129
Show file tree
Hide file tree
Showing 31 changed files with 231 additions and 1,154 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ endif()
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Svg)
qt_standard_project_setup()

# include(DeployQt)

# The library.
add_subdirectory(lib)

# Sandbox.
if(${PROJECT_IS_TOP_LEVEL})
# Example apps using the lib.
if(QLEMENTINE_SANDBOX)
add_subdirectory(sandbox)
endif()

if(QLEMENTINE_SHOWCASE)
add_subdirectory(showcase)
endif()
12 changes: 10 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"generator": "Xcode",
"binaryDir": "${sourceDir}/_build",
"cacheVariables": {
"CMAKE_PREFIX_PATH": "/opt/homebrew/opt/qt/lib/cmake/Qt6"
"CMAKE_PREFIX_PATH": "/opt/homebrew/opt/qt/lib/cmake/Qt6",
"QLEMENTINE_SANDBOX": true,
"QLEMENTINE_SHOWCASE": true
},
"condition": {
"type": "equals",
Expand All @@ -28,7 +30,9 @@
"generator": "Visual Studio 17 2022",
"binaryDir": "${sourceDir}/_build",
"cacheVariables": {
"CMAKE_PREFIX_PATH": "C:/Qt/6.8.0/msvc2022_64"
"CMAKE_PREFIX_PATH": "C:/Qt/6.8.0/msvc2022_64",
"QLEMENTINE_SANDBOX": true,
"QLEMENTINE_SHOWCASE": true
},
"condition": {
"type": "equals",
Expand All @@ -42,6 +46,10 @@
"description": "Makefile for Linux",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/_build",
"cacheVariables": {
"QLEMENTINE_SANDBOX": true,
"QLEMENTINE_SHOWCASE": true
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
Expand Down
10 changes: 0 additions & 10 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
set(LIB_TARGET_NAME ${PROJECT_NAME})

# Dependency: qlementine-icons
include(FetchContent)
FetchContent_Declare(qlementine_icons GIT_REPOSITORY "https://github.com/oclero/qlementine-icons.git")
FetchContent_MakeAvailable(qlementine_icons)
set_target_properties(qlementine_icons
PROPERTIES
FOLDER dependencies
)

# Declare files.
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/animation/WidgetAnimator.cpp
Expand Down Expand Up @@ -140,7 +131,6 @@ target_link_libraries(${LIB_TARGET_NAME}
Qt::Core
Qt::Widgets
Qt::Svg
oclero::qlementine_icons
)

set_target_properties(${LIB_TARGET_NAME}
Expand Down
11 changes: 6 additions & 5 deletions lib/include/oclero/qlementine/style/QlementineStyle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ class QlementineStyle : public QCommonStyle {

QIcon makeThemedIcon(
const QString& svgPath, const QSize& size = QSize(16, 16), ColorRole role = ColorRole::Secondary) const;
QIcon makeThemedIcon(
icons::Icons16 id, const QSize& size = QSize(16, 16), ColorRole role = ColorRole::Secondary) const;

QIcon makeThemedIconFromName(
const QString& name, const QSize& size = QSize(16, 16), ColorRole role = ColorRole::Secondary) const;

// Allows to customize quickly the way QlementineStyle gets its icons. SVG paths preferred.
void setIconPathGetter(const std::function<QString(QString)>& func);

public: // QStyle overrides.
void drawPrimitive(
Expand Down Expand Up @@ -289,7 +293,4 @@ class QlementineStyle : public QCommonStyle {
};

QlementineStyle* appStyle();

QIcon makeThemedIcon(icons::Icons16 id, const QSize& size = QSize(16, 16), ColorRole role = ColorRole::Secondary);

} // namespace oclero::qlementine
10 changes: 0 additions & 10 deletions lib/include/oclero/qlementine/utils/IconUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#include <QIcon>
#include <QColor>

#include <oclero/qlementine/icons/Icons12.hpp>
#include <oclero/qlementine/icons/Icons16.hpp>
#include <oclero/qlementine/icons/Icons32.hpp>

namespace oclero::qlementine {
struct IconTheme {
QColor normal;
Expand All @@ -30,10 +26,4 @@ struct IconTheme {
/// Makes an icon from the file located at the path in parameter and colorizes the QPixmaps. Fixes the standard Qt behavior.
[[maybe_unused]] QIcon makeIconFromSvg(
const QString& svgPath, const IconTheme& iconTheme, const QSize& size = QSize(16, 16));

[[maybe_unused]] QIcon makeIconFromSvg(icons::Icons16 id, const QSize& size = QSize(16, 16));

/// Makes an icon from the icon ID in parameter and colorizes the QPixmaps. Fixes the standard Qt behavior.
[[maybe_unused]] QIcon makeIconFromSvg(
icons::Icons16 id, const IconTheme& iconTheme, const QSize& size = QSize(16, 16));
} // namespace oclero::qlementine
52 changes: 28 additions & 24 deletions lib/src/style/EventFilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <oclero/qlementine/utils/MenuUtils.hpp>
#include <oclero/qlementine/utils/WidgetUtils.hpp>

#include <oclero/qlementine/icons/Icons16.hpp>

#include <QMouseEvent>
#include <QWidget>
#include <QLineEdit>
Expand Down Expand Up @@ -502,45 +500,48 @@ class LineEditMenuIconsBehavior : public QObject {
};

static std::vector<QIcon> iconList(IconListMode mode) {
using Icons16 = icons::Icons16;
const auto* qlem = oclero::qlementine::appStyle();
if (!qlem)
return {};

// The order follows the one defined QLineEdit.cpp and QSpinBox.cpp (Qt6).
switch (mode) {
case IconListMode::LineEdit:
return {
QIcon(), // Separator
makeThemedIcon(Icons16::Action_Undo),
makeThemedIcon(Icons16::Action_Redo),
qlem->makeThemedIconFromName("edit-undo"),
qlem->makeThemedIconFromName("edit-redo"),
QIcon(), // Separator
makeThemedIcon(Icons16::Action_Cut),
makeThemedIcon(Icons16::Action_Copy),
makeThemedIcon(Icons16::Action_Paste),
makeThemedIcon(Icons16::Action_Erase),
qlem->makeThemedIconFromName("edit-cut"),
qlem->makeThemedIconFromName("edit-copy"),
qlem->makeThemedIconFromName("edit-paste"),
qlem->makeThemedIconFromName("edit-delete"),
QIcon(), // Separator
makeThemedIcon(Icons16::Action_SelectAll),
qlem->makeThemedIconFromName("edit-select-all"),
};
case IconListMode::ReadOnlyLineEdit:
return {
QIcon(), // Separator
makeThemedIcon(Icons16::Action_Copy),
qlem->makeThemedIconFromName("edit-copy"),
QIcon(), // Separator
makeThemedIcon(Icons16::Action_SelectAll),
qlem->makeThemedIconFromName("edit-select-all"),
};
case IconListMode::SpinBox:
return {
QIcon(), // Separator
makeThemedIcon(Icons16::Action_Undo),
makeThemedIcon(Icons16::Action_Redo),
qlem->makeThemedIconFromName("edit-undo"),
qlem->makeThemedIconFromName("edit-redo"),
QIcon(), // Separator
makeThemedIcon(Icons16::Action_Cut),
makeThemedIcon(Icons16::Action_Copy),
makeThemedIcon(Icons16::Action_Paste),
makeThemedIcon(Icons16::Action_Erase),
qlem->makeThemedIconFromName("edit-cut"),
qlem->makeThemedIconFromName("edit-copy"),
qlem->makeThemedIconFromName("edit-paste"),
qlem->makeThemedIconFromName("edit-delete"),
QIcon(), // Separator
QIcon(), // Separator
makeThemedIcon(Icons16::Action_SelectAll),
qlem->makeThemedIconFromName("edit-select-all"),
QIcon(), // Separator
makeThemedIcon(Icons16::Navigation_ChevronUp),
makeThemedIcon(Icons16::Navigation_ChevronDown),
qlem->makeThemedIconFromName("go-up"),
qlem->makeThemedIconFromName("go-down"),
};
default:
return {};
Expand All @@ -562,12 +563,15 @@ class LineEditMenuIconsBehavior : public QObject {
const auto actions = _menu->findChildren<QAction*>();
if (!actions.empty()) {
const auto icons = iconList(getMode(_menu));
for (auto i = 0; i < static_cast<int>(icons.size()) && i < static_cast<int>(actions.size()); ++i) {
if (auto* action = actions.at(i)) {
action->setIcon(icons.at(i));
if (!icons.empty()) {
for (auto i = 0; i < static_cast<int>(icons.size()) && i < static_cast<int>(actions.size()); ++i) {
if (auto* action = actions.at(i)) {
action->setIcon(icons.at(i));
}
}
}
}
_menu->adjustSize();
}

public:
Expand Down
Loading

0 comments on commit e030129

Please sign in to comment.