From 3d92ac2abc1e0cf949b70f74b3235f8417807aba Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Fri, 4 Jul 2025 15:10:47 +0200 Subject: [PATCH] Migrate to KDE configurations Can be not complete: link error --- .vscode/settings.json | 8 ++-- CMakeLists.txt | 44 +++++++++++++++-- README.md | 7 +-- flake.nix | 12 +++-- src/CMakeLists.txt | 29 ++++++++---- src/counter.h | 2 +- src/main.cpp | 55 +++++++++++++++------- src/{contents/ui/main.qml => qml/Main.qml} | 0 src/resources.qrc | 5 -- 9 files changed, 115 insertions(+), 47 deletions(-) rename src/{contents/ui/main.qml => qml/Main.qml} (100%) delete mode 100644 src/resources.qrc diff --git a/.vscode/settings.json b/.vscode/settings.json index 3180563..868bcab 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,10 +1,8 @@ { "cmake.generator": "Ninja", - "cmake.configureSettings": { - "CMAKE_EXPORT_COMPILE_COMMANDS:BOOL": "ON", - "CMAKE_BUILD_TYPE": "RelWithDebInfo", - "QT_MAJOR_VERSION": "6" - }, + "cmake.configureArgs": [ + "${env:cmakeFlags}" + ], "cmake.buildDirectory": "${workspaceFolder}/build", "C_Cpp.intelliSenseEngine": "disabled", } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 6370321..8a704d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,32 @@ cmake_minimum_required(VERSION 3.16) project(tutorial_kirigami2 VERSION 0.1.0 LANGUAGES CXX) -set(KF_MIN_VERSION "6.0.0") -set(QT_MIN_VERSION "6.6") +set(QT_MIN_VERSION 6.6) +set(KF_MIN_VERSION 6.8) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(ECM ${KF_MIN_VERSION} REQUIRED NO_MODULE) -set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH}) +# only enable QML debugging on debug builds +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG ") + +include(FeatureSummary) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) +include(ECMQmlModule) +include(ECMQtDeclareLoggingCategory) +include(ECMDeprecationSettings) +include(ECMAddTests) +include(KDEGitCommitHooks) +include(KDEClangFormat) +include(GenerateExportHeader) +include(ECMGenerateHeaders) +include(ECMSetupVersion) +include(ECMAddQch) find_package(Qt6 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core @@ -24,11 +38,33 @@ find_package(Qt6 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS ) find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS - Kirigami2 + Kirigami I18n + Config CoreAddons + IconThemes + ColorScheme ) +ecm_set_disabled_deprecation_versions(QT ${QT_MIN_VERSION} KF ${KF_MIN_VERSION}) + +ecm_setup_version(${PROJECT_VERSION} + VARIABLE_PREFIX TUTORIAL_KIRIGAMI2 + VERSION_HEADER ${CMAKE_CURRENT_BINARY_DIR}/tutorial-kirigami2-version.h +) + +if(BUILD_TESTING) + add_definitions(-DBUILD_TESTING) + find_package(Qt6 ${QT_MIN_VERSION} REQUIRED COMPONENTS Test) +endif() + add_subdirectory(src) +file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES src/*.cpp src/*.h) +kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) +kde_configure_git_pre_commit_hook(CHECKS CLANG_FORMAT) + +ki18n_install(po) + feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) + diff --git a/README.md b/README.md index a6440b3..7b0e062 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,10 @@ 1. `direnv allow` 2. `cmake $cmakeFlags -B build -G Ninja .` -3. `cd build` -3. `ninja` -4. `./bin/tutorial_kirigami2` +3. `source build/prefix.sh` +4. `cd build` +5. `ninja` +6. `./bin/tutorial_kirigami2` For use gammaray, you need to disable yama security. diff --git a/flake.nix b/flake.nix index 3facd04..a8b7626 100644 --- a/flake.nix +++ b/flake.nix @@ -11,8 +11,7 @@ let pkgs = import nixpkgs { inherit system; }; - kdeDependencies = with pkgs.kdePackages; [ - qtbase + qmlDependencies = with pkgs.kdePackages; [ qtdeclarative kirigami.unwrapped ki18n @@ -21,6 +20,11 @@ sonnet ]; + kdeDependencies = with pkgs.kdePackages; [ + qtbase + extra-cmake-modules + ]; + makeQmlImportPath = pkgs.lib.makeSearchPathOutput "bin" "lib/qt-6/qml"; in { @@ -39,7 +43,7 @@ # For translation generation ruby - ] ++ kdeDependencies; + ] ++ kdeDependencies ++ qmlDependencies; dontFixCmake = true; cmakeFlags = [ @@ -47,7 +51,7 @@ "-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo" ]; - QML2_IMPORT_PATH = makeQmlImportPath kdeDependencies; + QML2_IMPORT_PATH = makeQmlImportPath qmlDependencies; }; }; }); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4cf2812..4dd27e2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,18 +1,31 @@ -add_executable(tutorial_kirigami2) +add_library(tutorial_kirigami2_static STATIC) +ecm_add_qml_module(tutorial_kirigami2_static + URI fr.mrdev023.tutorial_kirigami2 + GENERATE_PLUGIN_SOURCE + QML_FILES + qml/Main.qml -target_sources(tutorial_kirigami2 PRIVATE - main.cpp - counter.cpp - resources.qrc + SOURCES + counter.cpp counter.h ) -target_link_libraries(tutorial_kirigami2 - Qt${QT_MAJOR_VERSION}::Quick - Qt${QT_MAJOR_VERSION}::Qml +target_link_libraries(tutorial_kirigami2_static PUBLIC + Qt${QT_MAJOR_VERSION}::Core Qt${QT_MAJOR_VERSION}::Gui + Qt${QT_MAJOR_VERSION}::Qml + Qt${QT_MAJOR_VERSION}::Quick Qt${QT_MAJOR_VERSION}::QuickControls2 Qt${QT_MAJOR_VERSION}::Widgets KF${QT_MAJOR_VERSION}::I18n + KF${QT_MAJOR_VERSION}::ConfigCore + KF${QT_MAJOR_VERSION}::ConfigGui + KF${QT_MAJOR_VERSION}::CoreAddons + KF${QT_MAJOR_VERSION}::IconThemes + KF${QT_MAJOR_VERSION}::ColorScheme ) +add_executable(tutorial_kirigami2 main.cpp) +target_link_libraries(tutorial_kirigami2 PRIVATE tutorial_kirigami2_static tutorial_kirigami2_staticplugin) + install(TARGETS tutorial_kirigami2 ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) + diff --git a/src/counter.h b/src/counter.h index d648a54..57cddc9 100644 --- a/src/counter.h +++ b/src/counter.h @@ -4,7 +4,7 @@ #include #include -class Counter: QObject { +class Counter: public QObject { Q_OBJECT Q_PROPERTY(uint counter READ counter WRITE setCounter NOTIFY counterChanged) QML_ELEMENT diff --git a/src/main.cpp b/src/main.cpp index abec709..89b5f81 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,33 +1,54 @@ +#include +#include #include +#include #include #include +#include #include #include #include #include #include -#include + +#include "../tutorial-kirigami2-version.h" + +using namespace Qt::Literals::StringLiterals; int main(int argc, char *argv[]) { - QApplication app(argc, argv); - KLocalizedString::setApplicationDomain("myapplication"); - QCoreApplication::setOrganizationName(QStringLiteral("KDE")); - QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); - QCoreApplication::setApplicationName(QStringLiteral("My application of test")); - QCoreApplication::setApplicationVersion(QStringLiteral("0.1.0")); + KIconTheme::initTheme(); + QIcon::setFallbackThemeName(u"breeze"_s); + QApplication app(argc, argv); + // Default to org.kde.desktop style unless the user forces another style + if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) { + QQuickStyle::setStyle(u"org.kde.desktop"_s); + } - if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) { - QQuickStyle::setStyle(QStringLiteral("org.kde.desktop")); - } + KLocalizedString::setApplicationDomain("tutorial_kirigami2"); + QGuiApplication::setWindowIcon(QIcon::fromTheme(u"fr.mrdev023.tutorial_kirigami2"_s)); - QQmlApplicationEngine engine; + KAboutData about(u"tutorial_kirigami2"_s, + i18nc("Application name", "Tutorial Kirigami 2"), + QStringLiteral(TUTORIAL_KIRIGAMI2_VERSION_STRING), + i18n("Note taking application"), + KAboutLicense::MIT, + i18n("© 2025-2025 Florian RICHER")); + about.addAuthor(i18n("Florian RICHER"), + i18n("Maintainer"), + u"florian.richer@protonmail.com"_s, + u"https://invent.kde.org/florianricher"_s, + QUrl(u"https://gravatar.com/avatar/f9c35f242fe79337bf8746ca9fccc189?size=256.png"_s)); + + KAboutData::setApplicationData(about); - engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); - engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + QQmlApplicationEngine engine; + KLocalization::setupLocalizedContext(&engine); - if (engine.rootObjects().isEmpty()) { - return -1; - } + engine.loadFromModule(u"fr.mrdev023.tutorial_kirigami2"_s, u"Main"_s); - return app.exec(); + if (engine.rootObjects().isEmpty()) { + return -1; + } + + return app.exec(); } diff --git a/src/contents/ui/main.qml b/src/qml/Main.qml similarity index 100% rename from src/contents/ui/main.qml rename to src/qml/Main.qml diff --git a/src/resources.qrc b/src/resources.qrc deleted file mode 100644 index b2b45f8..0000000 --- a/src/resources.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - contents/ui/main.qml - -