From a6f818864a59eda7935c08beed87f45f2ffd9e9f Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Fri, 27 Jun 2025 13:46:00 +0200 Subject: [PATCH] Begin move to kde configuration --- CMakeLists.txt | 14 +++-- README.md | 4 +- flake.nix | 1 - src/CMakeLists.txt | 1 + src/contents/ui/AddEditSheet.qml | 91 --------------------------- src/contents/ui/KountdownDelegate.qml | 54 ---------------- src/contents/ui/main.qml | 45 +------------ src/counter.cpp | 18 ++++++ src/counter.h | 22 +++++++ src/main.cpp | 4 +- src/resources.qrc | 2 - 11 files changed, 58 insertions(+), 198 deletions(-) delete mode 100644 src/contents/ui/AddEditSheet.qml delete mode 100644 src/contents/ui/KountdownDelegate.qml create mode 100644 src/counter.cpp create mode 100644 src/counter.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9db8ed7..6370321 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,20 @@ cmake_minimum_required(VERSION 3.16) -project(tutorial_kirigami2) +project(tutorial_kirigami2 VERSION 0.1.0 LANGUAGES CXX) -find_package(ECM REQUIRED NO_MODULE) +set(KF_MIN_VERSION "6.0.0") +set(QT_MIN_VERSION "6.6") + +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}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) -find_package(Qt${QT_MAJOR_VERSION} REQUIRED NO_MODULE COMPONENTS +find_package(Qt6 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Quick Test @@ -17,7 +23,7 @@ find_package(Qt${QT_MAJOR_VERSION} REQUIRED NO_MODULE COMPONENTS Widgets ) -find_package(KF${QT_MAJOR_VERSION} REQUIRED COMPONENTS +find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS Kirigami2 I18n CoreAddons diff --git a/README.md b/README.md index 98b57bd..a6440b3 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ 2. `cmake $cmakeFlags -B build -G Ninja .` 3. `cd build` 3. `ninja` -4. `./src/tutorial_kirigami2` +4. `./bin/tutorial_kirigami2` For use gammaray, you need to disable yama security. @@ -15,5 +15,5 @@ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope Then run with, ``` -gammaray ./src/tutorial_kirigami2 +gammaray ./bin/tutorial_kirigami2 ``` diff --git a/flake.nix b/flake.nix index 4ee6bf7..3facd04 100644 --- a/flake.nix +++ b/flake.nix @@ -43,7 +43,6 @@ dontFixCmake = true; cmakeFlags = [ - "-DQT_MAJOR_VERSION=6" "-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON" "-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo" ]; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6b0f943..4cf2812 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,7 @@ add_executable(tutorial_kirigami2) target_sources(tutorial_kirigami2 PRIVATE main.cpp + counter.cpp resources.qrc ) diff --git a/src/contents/ui/AddEditSheet.qml b/src/contents/ui/AddEditSheet.qml deleted file mode 100644 index 921d46c..0000000 --- a/src/contents/ui/AddEditSheet.qml +++ /dev/null @@ -1,91 +0,0 @@ -import QtQuick -import QtQuick.Controls as Controls -import QtQuick.Layouts -import org.kde.kirigami as Kirigami - -// Overlay sheets appear over a part of the window -Kirigami.OverlaySheet { - id: addEditSheet - - // Sheet mode - property string mode: "add" - - property int index: -1 - property alias name: nameField.text - property alias description: descriptionField.text - property alias kdate: dateField.text - - // Signals can be read and certain actions performed when these happen - signal added(string name, string description, var kdate) - signal edited(int index, string name, string description, var kdate) - signal removed(int index) - - header: Kirigami.Heading { - // i18nc is useful for adding context for translators - text: mode === "add" ? i18nc("@title:window", "Add kountdown") : - i18nc("@title:window", "Edit kountdown") - } - // Form layouts help align and structure a layout with several inputs - Kirigami.FormLayout { - // Textfields let you input text in a thin textbox - Controls.TextField { - id: nameField - // Provides label attached to the textfield - Kirigami.FormData.label: i18nc("@label:textbox", "Name:") - // Placeholder text is visible before you enter anything - placeholderText: i18n("Event name (required)") - // What to do after input is accepted (i.e. pressed enter) - // In this case, it moves the focus to the next field - onAccepted: descriptionField.forceActiveFocus() - } - Controls.TextField { - id: descriptionField - Kirigami.FormData.label: i18nc("@label:textbox", "Description:") - placeholderText: i18n("Optional") - onAccepted: dateField.forceActiveFocus() - } - Controls.TextField { - id: dateField - Kirigami.FormData.label: i18nc("@label:textbox", "Date:") - inputMask: "0000-00-00" - placeholderText: i18n("YYYY-MM-DD") - } - // This is a button. - Controls.Button { - id: deleteButton - Layout.fillWidth: true - text: i18nc("@action:button", "Delete") - visible: mode === "edit" - onClicked: { - addEditSheet.removed(addEditSheet.index) - close(); - } - } - Controls.Button { - id: doneButton - Layout.fillWidth: true - text: i18nc("@action:button", "Done") - // Button is only enabled if the user has entered something into the nameField - enabled: nameField.text.length > 0 - onClicked: { - // Add a listelement to the kountdownModel ListModel - if(mode === "add") { - addEditSheet.added( - nameField.text, - descriptionField.text, - dateField.text - ); - } - else { - addEditSheet.edited( - index, - nameField.text, - descriptionField.text, - dateField.text - ); - } - close(); - } - } - } -} diff --git a/src/contents/ui/KountdownDelegate.qml b/src/contents/ui/KountdownDelegate.qml deleted file mode 100644 index 7634c92..0000000 --- a/src/contents/ui/KountdownDelegate.qml +++ /dev/null @@ -1,54 +0,0 @@ -import QtQuick -import QtQuick.Controls as Controls -import QtQuick.Layouts -import org.kde.kirigami as Kirigami - -Kirigami.AbstractCard { - id: kountdownDelegate - contentItem: Item { - implicitWidth: delegateLayout.implicitWidth - implicitHeight: delegateLayout.implicitHeight - GridLayout { - id: delegateLayout - anchors { - left: parent.left - top: parent.top - right: parent.right - } - rowSpacing: Kirigami.Units.largeSpacing - columnSpacing: Kirigami.Units.largeSpacing - columns: root.wideScreen ? 4 : 2 - - Kirigami.Heading { - Layout.fillHeight: true - level: 1 - text: i18n("%1 days", Math.round((date-Date.now())/86400000)) - } - - ColumnLayout { - Kirigami.Heading { - Layout.fillWidth: true - level: 2 - text: name - } - Kirigami.Separator { - Layout.fillWidth: true - visible: description.length > 0 - } - Controls.Label { - Layout.fillWidth: true - wrapMode: Text.WordWrap - text: description - visible: description.length > 0 - } - } - Controls.Button { - Layout.alignment: Qt.AlignRight - // Column spanning within grid layout (vertically in this case) - Layout.columnSpan: 2 - text: i18n("Edit") - onClicked: openPopulatedSheet("edit", index, name, description, new Date(date).toISOString().slice(0,10)) - } - } - } -} diff --git a/src/contents/ui/main.qml b/src/contents/ui/main.qml index 4258660..874b379 100644 --- a/src/contents/ui/main.qml +++ b/src/contents/ui/main.qml @@ -6,7 +6,7 @@ import org.kde.kirigami as Kirigami Kirigami.ApplicationWindow { id: root - title: i18nc("@title:window", "Hello World") + title: i18nc("@title:window", "My Application") globalDrawer: Kirigami.GlobalDrawer { isMenu: true @@ -20,51 +20,12 @@ Kirigami.ApplicationWindow { ] } - ListModel { - id: kountdownModel - } - - AddEditSheet { - id: addEditSheet - onAdded: kountdownModel.append({ - "name": name, - "description": description, - "date": Date.parse(kdate) - }); - onEdited: kountdownModel.set(index, { - "name": name, - "description": description, - "date": Date.parse(kdate) - }); - onRemoved: kountdownModel.remove(index, 1) - } - - function openPopulatedSheet(mode, index = -1, listName = "", listDesc = "", listDate = "") { - addEditSheet.mode = mode - addEditSheet.index = index; - addEditSheet.name = listName - addEditSheet.description = listDesc - addEditSheet.kdate = listDate - - addEditSheet.open() - } - pageStack.initialPage: Kirigami.ScrollablePage { - title: i18nc("@title", "Kountdown") + title: i18nc("@title", "Main Page") actions: [ - Kirigami.Action { - id: addAction - icon.name: "list-add" - text: i18nc("@action:button", "Add kountdown") - onTriggered:openPopulatedSheet("add") - } ] - Kirigami.CardsListView { - id: cardsView - model: kountdownModel - delegate: KountdownDelegate {} - } + Item {} } } diff --git a/src/counter.cpp b/src/counter.cpp new file mode 100644 index 0000000..b141c7e --- /dev/null +++ b/src/counter.cpp @@ -0,0 +1,18 @@ +#include "counter.h" + +Counter::Counter(QObject *parent) + : QObject(parent) +{ + // Nothing +} + +uint Counter::counter() const +{ + return m_counter; +} + +void Counter::setCounter(const uint counter) +{ + m_counter = counter; + Q_EMIT counterChanged(); +} diff --git a/src/counter.h b/src/counter.h new file mode 100644 index 0000000..d648a54 --- /dev/null +++ b/src/counter.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include + +class Counter: QObject { + Q_OBJECT + Q_PROPERTY(uint counter READ counter WRITE setCounter NOTIFY counterChanged) + QML_ELEMENT +public: + explicit Counter(QObject *parent = nullptr); + + [[nodiscard]] uint counter() const; + void setCounter(const uint counter); + +Q_SIGNALS: + void counterChanged(); + +private: + uint m_counter; +}; diff --git a/src/main.cpp b/src/main.cpp index 28ff074..abec709 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,10 +10,10 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - KLocalizedString::setApplicationDomain("helloworld"); + KLocalizedString::setApplicationDomain("myapplication"); QCoreApplication::setOrganizationName(QStringLiteral("KDE")); QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); - QCoreApplication::setApplicationName(QStringLiteral("Hello World")); + QCoreApplication::setApplicationName(QStringLiteral("My application of test")); QCoreApplication::setApplicationVersion(QStringLiteral("0.1.0")); if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) { diff --git a/src/resources.qrc b/src/resources.qrc index d3ba5a5..b2b45f8 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -1,7 +1,5 @@ contents/ui/main.qml - contents/ui/AddEditSheet.qml - contents/ui/KountdownDelegate.qml