From d0cea474a6cc45b28114ba158061d42c0cfed484 Mon Sep 17 00:00:00 2001 From: Gerhard Schwanzer Date: Sun, 5 Jul 2026 11:10:44 +0200 Subject: [PATCH] Fix Qt-only build without KF5 The BUILD_WITH_KF5 option was checked with DEFINED, so passing -DBUILD_WITH_KF5=OFF still entered the KF5 setup path. Skip the KF5 setup when disabled and provide small Qt-only replacements for the KDE color widgets used by .ui files in that build mode. Assisted-by: pi coding agent / Mika (OpenAI GPT-5.5) --- CMakeLists.txt | 8 ++++ cmake/fetch_kdeaddons.cmake | 2 +- cmake/qet_compilation_vars.cmake | 9 ++++ sources/ui/nokde/kcolorbutton.cpp | 70 +++++++++++++++++++++++++++++++ sources/ui/nokde/kcolorbutton.h | 48 +++++++++++++++++++++ sources/ui/nokde/kcolorcombo.cpp | 49 ++++++++++++++++++++++ sources/ui/nokde/kcolorcombo.h | 38 +++++++++++++++++ 7 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 sources/ui/nokde/kcolorbutton.cpp create mode 100644 sources/ui/nokde/kcolorbutton.h create mode 100644 sources/ui/nokde/kcolorcombo.cpp create mode 100644 sources/ui/nokde/kcolorcombo.h diff --git a/CMakeLists.txt b/CMakeLists.txt index edec55380..ef2853be1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,6 +148,14 @@ target_include_directories( ${QET_DIR}/sources/svg ) +if(NOT BUILD_WITH_KF5) + target_include_directories( + ${PROJECT_NAME} + PRIVATE + ${QET_DIR}/sources/ui/nokde + ) +endif() + install(TARGETS ${PROJECT_NAME}) if (NOT MINGW) diff --git a/cmake/fetch_kdeaddons.cmake b/cmake/fetch_kdeaddons.cmake index ac5a340f9..0867afec4 100644 --- a/cmake/fetch_kdeaddons.cmake +++ b/cmake/fetch_kdeaddons.cmake @@ -16,7 +16,7 @@ message(" - fetch_kdeaddons") -if(DEFINED BUILD_WITH_KF5) +if(BUILD_WITH_KF5) Include(FetchContent) option(BUILD_KF5 "Build KF5 libraries, use system ones otherwise" YES) diff --git a/cmake/qet_compilation_vars.cmake b/cmake/qet_compilation_vars.cmake index 7e150a6e7..7c905d87b 100644 --- a/cmake/qet_compilation_vars.cmake +++ b/cmake/qet_compilation_vars.cmake @@ -724,6 +724,15 @@ set(QET_SRC_FILES ${QET_DIR}/sources/xml/terminalstriplayoutpatternxml.h ) +if(NOT BUILD_WITH_KF5) + list(APPEND QET_SRC_FILES + ${QET_DIR}/sources/ui/nokde/kcolorbutton.cpp + ${QET_DIR}/sources/ui/nokde/kcolorbutton.h + ${QET_DIR}/sources/ui/nokde/kcolorcombo.cpp + ${QET_DIR}/sources/ui/nokde/kcolorcombo.h + ) +endif() + set(TS_FILES ${QET_DIR}/lang/qet_ar.ts ${QET_DIR}/lang/qet_ca.ts diff --git a/sources/ui/nokde/kcolorbutton.cpp b/sources/ui/nokde/kcolorbutton.cpp new file mode 100644 index 000000000..3436d06f1 --- /dev/null +++ b/sources/ui/nokde/kcolorbutton.cpp @@ -0,0 +1,70 @@ +/* + Copyright 2006-2026 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "kcolorbutton.h" + +#include +#include + +namespace { +QColor fallbackColor() +{ + return QPalette{}.color(QPalette::Button); +} +} + +KColorButton::KColorButton(QWidget *parent) : + QPushButton{parent}, + m_color{fallbackColor()} +{ + connect(this, &QPushButton::clicked, this, &KColorButton::chooseColor); + updateButton(); +} + +QColor KColorButton::color() const +{ + return m_color; +} + +void KColorButton::setColor(const QColor &color) +{ + m_color = color.isValid() ? color : fallbackColor(); + updateButton(); +} + +void KColorButton::chooseColor() +{ + const auto selected = QColorDialog::getColor(m_color, this); + if (!selected.isValid() || selected == m_color) { + return; + } + + m_color = selected; + updateButton(); + emit changed(m_color); +} + +void KColorButton::updateButton() +{ + setText(m_color.name()); + + auto pal = palette(); + pal.setColor(QPalette::Button, m_color); + setAutoFillBackground(true); + setPalette(pal); + update(); +} diff --git a/sources/ui/nokde/kcolorbutton.h b/sources/ui/nokde/kcolorbutton.h new file mode 100644 index 000000000..453ff9530 --- /dev/null +++ b/sources/ui/nokde/kcolorbutton.h @@ -0,0 +1,48 @@ +/* + Copyright 2006-2026 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef QET_KCOLORBUTTON_H +#define QET_KCOLORBUTTON_H + +#include +#include + +class KColorButton : public QPushButton +{ + Q_OBJECT + + public: + explicit KColorButton(QWidget *parent = nullptr); + + QColor color() const; + + public slots: + void setColor(const QColor &color); + + signals: + void changed(const QColor &color); + + private slots: + void chooseColor(); + + private: + void updateButton(); + + QColor m_color; +}; + +#endif // QET_KCOLORBUTTON_H diff --git a/sources/ui/nokde/kcolorcombo.cpp b/sources/ui/nokde/kcolorcombo.cpp new file mode 100644 index 000000000..e90e25d13 --- /dev/null +++ b/sources/ui/nokde/kcolorcombo.cpp @@ -0,0 +1,49 @@ +/* + Copyright 2006-2026 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "kcolorcombo.h" + +#include + +KColorCombo::KColorCombo(QWidget *parent) : + QComboBox{parent} +{ + connect( + this, + QOverload::of(&QComboBox::activated), + this, + [this](int index) { + emit activated(itemData(index).value()); + }); +} + +void KColorCombo::setColors(const QList &colors) +{ + clear(); + for (const auto &color : colors) { + addItem(color.name(), color); + } +} + +QColor KColorCombo::color(int index) const +{ + if (index < 0 || index >= count()) { + return {}; + } + + return itemData(index).value(); +} diff --git a/sources/ui/nokde/kcolorcombo.h b/sources/ui/nokde/kcolorcombo.h new file mode 100644 index 000000000..94d70948f --- /dev/null +++ b/sources/ui/nokde/kcolorcombo.h @@ -0,0 +1,38 @@ +/* + Copyright 2006-2026 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef QET_KCOLORCOMBO_H +#define QET_KCOLORCOMBO_H + +#include +#include + +class KColorCombo : public QComboBox +{ + Q_OBJECT + + public: + explicit KColorCombo(QWidget *parent = nullptr); + + void setColors(const QList &colors); + QColor color(int index) const; + + signals: + void activated(const QColor &color); +}; + +#endif // QET_KCOLORCOMBO_H