From d8d50582c3e7a08e0eed142247805566dc5b012d Mon Sep 17 00:00:00 2001 From: Vyn Date: Mon, 22 Apr 2024 15:45:26 +0200 Subject: [PATCH] Add files settings in UI (wip) --- src/Backend.cpp | 23 +++++++++++++++++++ src/Backend.h | 1 + src/core/Mirai.cpp | 15 ++++++++++--- src/core/Mirai.h | 1 + src/qml/Main.qml | 19 +--------------- src/qml/SideMenu.qml | 44 +++++++++++++++++++++++++++++++++---- src/qml/forms/FilesForm.qml | 24 +++++++++++--------- 7 files changed, 92 insertions(+), 35 deletions(-) diff --git a/src/Backend.cpp b/src/Backend.cpp index 9a9625b..a0fa0a2 100644 --- a/src/Backend.cpp +++ b/src/Backend.cpp @@ -9,6 +9,7 @@ #include "core/TaskItem.h" #include "core/TasksView.h" #include "core/TodoMd.h" +#include #include #include #include @@ -267,6 +268,28 @@ void Backend::saveTagsColor(QVariant modifiedTags) saveConfig(); } +void Backend::saveFilesPath(QVariant modifiedFilesPath) +{ + // TODO: Make something better, rework rebuildQMLTasksList ? + auto paths = modifiedFilesPath.toStringList(); + QMLTags.clear(); + QMLTasks.clear(); + QMLTasksFiles.clear(); + emit tagsChanged(); + emit tasksChanged(); + emit filesChanged(); + mirai.unloadAllFiles(); + for (auto path : paths) { + mirai.loadFile(path.toStdString()); + } + view.update(); + rebuildQMLTasksList(); + emit tagsChanged(); + emit tasksChanged(); + emit filesChanged(); + saveConfig(); +} + void Backend::saveConfig() { QJsonObject rootJson; diff --git a/src/Backend.h b/src/Backend.h index 28a3596..8ff242c 100644 --- a/src/Backend.h +++ b/src/Backend.h @@ -56,6 +56,7 @@ class Backend : public QObject Q_INVOKABLE void hideCompletedTasks(bool shouldHide); Q_INVOKABLE QString getTagColor(QString tag); Q_INVOKABLE void saveTagsColor(QVariant tags); + Q_INVOKABLE void saveFilesPath(QVariant filesPath); private: void rebuildQMLTasksList(); diff --git a/src/core/Mirai.cpp b/src/core/Mirai.cpp index fc3cd7f..440542d 100644 --- a/src/core/Mirai.cpp +++ b/src/core/Mirai.cpp @@ -20,9 +20,18 @@ namespace mirai void Mirai::loadFile(const std::string &path) { - auto tasksFile = TodoMdFormat::readFile(path); - files.push_back(std::move(tasksFile)); - reloadTags(); + try { + auto tasksFile = TodoMdFormat::readFile(path); + files.push_back(std::move(tasksFile)); + reloadTags(); + } catch (std::exception &e) { + std::cout << "Cannot load file " << path << " : " << e.what() << std::endl; + } +} + +void Mirai::unloadAllFiles() +{ + files.clear(); } void Mirai::save() diff --git a/src/core/Mirai.h b/src/core/Mirai.h index a30fd82..a3b9f3d 100644 --- a/src/core/Mirai.h +++ b/src/core/Mirai.h @@ -24,6 +24,7 @@ class Mirai public: void loadFile(const std::string &path); + void unloadAllFiles(); void save(); void addTask(TaskItemData taskItem); void addTask(std::string text, std::string date); diff --git a/src/qml/Main.qml b/src/qml/Main.qml index 7ce93b3..55d69c2 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -127,24 +127,7 @@ Window { Layout.fillHeight: true } - Popup { - id: filesFormPopup - width: parent.width * 0.75 - implicitHeight: filesForm.height + padding * 2 - x: Math.round((parent.width - width) / 2) - y: Math.round((parent.height * 0.4) / 2) - padding: 8 - background: Rectangle { - border.color: colorPalette.selected.modalBorder - border.width: 2 - color: colorPalette.selected.pane - radius: 4 - } - FilesForm { - id: filesForm - width: parent.width - } - } + Popup { id: taskFormPopup diff --git a/src/qml/SideMenu.qml b/src/qml/SideMenu.qml index 23a3066..0d7331a 100644 --- a/src/qml/SideMenu.qml +++ b/src/qml/SideMenu.qml @@ -12,9 +12,21 @@ import Mirai ColumnLayout { - AppText { - text: "Files" - font.pixelSize: 32 + RowLayout { + AppText { + text: "Files" + font.pixelSize: 32 + } + + Item { Layout.fillWidth: true } + AppIcon { + icon.source: "qrc:/qt/qml/Mirai/src/images/settings.png" + icon.color: colorPalette.selected.textPlaceholder + onClicked: { + filesForm.reset(); + filesFormPopup.open(); + } + } } Item { Layout.preferredHeight: 16 } @@ -82,7 +94,6 @@ ColumnLayout { AppText { text: modelData.name color: { - console.log("ttagg", modelData.name, modelData.color) return modelData.color } padding: 4 @@ -117,6 +128,31 @@ ColumnLayout { } } + Popup { + parent: Overlay.overlay + id: filesFormPopup + width: parent.width * 0.75 + implicitHeight: filesForm.height + padding * 2 + x: Math.round((parent.width - width) / 2) + y: Math.round((parent.height * 0.4) / 2) + padding: 8 + background: Rectangle { + border.color: colorPalette.selected.modalBorder + border.width: 2 + color: colorPalette.selected.pane + radius: 4 + } + FilesForm { + id: filesForm + width: parent.width + onConfirmed: (filesPath) => { + filesFormPopup.close() + console.log(filesPath) + backend.saveFilesPath(filesPath) + } + } + } + Popup { parent: Overlay.overlay id: tagsFormPopup diff --git a/src/qml/forms/FilesForm.qml b/src/qml/forms/FilesForm.qml index 8f05d4f..3a20feb 100644 --- a/src/qml/forms/FilesForm.qml +++ b/src/qml/forms/FilesForm.qml @@ -15,12 +15,11 @@ import Mirai ColumnLayout { id: form spacing: 6 - signal confirmed + signal confirmed(paths: var) function reset() { - internal.paths = backend.files.map(file => { - return {path: file.path, name: file.name} - }) + internal.paths = [] + internal.paths = backend.files.map(file => file.path) } QtObject { @@ -32,20 +31,25 @@ ColumnLayout { model: internal.paths ColumnLayout { AppLineEdit { - text: modelData.name + text: modelData + onTextChanged: { + internal.paths[index] = text + } } + } + } - AppLineEdit { - text: modelData.path - } + AppButton { + text: "+" + onClicked: { + internal.paths = [...internal.paths, ""] } } AppButton { text: "Save" onClicked: { - backend. - form.confirmed() + form.confirmed(internal.paths) } } }