Add files settings in UI (wip)

This commit is contained in:
Vyn 2024-04-22 15:45:26 +02:00
parent e5328c15d4
commit d8d50582c3
7 changed files with 92 additions and 35 deletions

View file

@ -9,6 +9,7 @@
#include "core/TaskItem.h" #include "core/TaskItem.h"
#include "core/TasksView.h" #include "core/TasksView.h"
#include "core/TodoMd.h" #include "core/TodoMd.h"
#include <exception>
#include <iostream> #include <iostream>
#include <ostream> #include <ostream>
#include <qjsonarray.h> #include <qjsonarray.h>
@ -267,6 +268,28 @@ void Backend::saveTagsColor(QVariant modifiedTags)
saveConfig(); 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() void Backend::saveConfig()
{ {
QJsonObject rootJson; QJsonObject rootJson;

View file

@ -56,6 +56,7 @@ class Backend : public QObject
Q_INVOKABLE void hideCompletedTasks(bool shouldHide); Q_INVOKABLE void hideCompletedTasks(bool shouldHide);
Q_INVOKABLE QString getTagColor(QString tag); Q_INVOKABLE QString getTagColor(QString tag);
Q_INVOKABLE void saveTagsColor(QVariant tags); Q_INVOKABLE void saveTagsColor(QVariant tags);
Q_INVOKABLE void saveFilesPath(QVariant filesPath);
private: private:
void rebuildQMLTasksList(); void rebuildQMLTasksList();

View file

@ -20,9 +20,18 @@ namespace mirai
void Mirai::loadFile(const std::string &path) void Mirai::loadFile(const std::string &path)
{ {
try {
auto tasksFile = TodoMdFormat::readFile(path); auto tasksFile = TodoMdFormat::readFile(path);
files.push_back(std::move(tasksFile)); files.push_back(std::move(tasksFile));
reloadTags(); reloadTags();
} catch (std::exception &e) {
std::cout << "Cannot load file " << path << " : " << e.what() << std::endl;
}
}
void Mirai::unloadAllFiles()
{
files.clear();
} }
void Mirai::save() void Mirai::save()

View file

@ -24,6 +24,7 @@ class Mirai
public: public:
void loadFile(const std::string &path); void loadFile(const std::string &path);
void unloadAllFiles();
void save(); void save();
void addTask(TaskItemData taskItem); void addTask(TaskItemData taskItem);
void addTask(std::string text, std::string date); void addTask(std::string text, std::string date);

View file

@ -127,24 +127,7 @@ Window {
Layout.fillHeight: true 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 { Popup {
id: taskFormPopup id: taskFormPopup

View file

@ -12,11 +12,23 @@ import Mirai
ColumnLayout { ColumnLayout {
RowLayout {
AppText { AppText {
text: "Files" text: "Files"
font.pixelSize: 32 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 } Item { Layout.preferredHeight: 16 }
Repeater { Repeater {
@ -82,7 +94,6 @@ ColumnLayout {
AppText { AppText {
text: modelData.name text: modelData.name
color: { color: {
console.log("ttagg", modelData.name, modelData.color)
return modelData.color return modelData.color
} }
padding: 4 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 { Popup {
parent: Overlay.overlay parent: Overlay.overlay
id: tagsFormPopup id: tagsFormPopup

View file

@ -15,12 +15,11 @@ import Mirai
ColumnLayout { ColumnLayout {
id: form id: form
spacing: 6 spacing: 6
signal confirmed signal confirmed(paths: var)
function reset() { function reset() {
internal.paths = backend.files.map(file => { internal.paths = []
return {path: file.path, name: file.name} internal.paths = backend.files.map(file => file.path)
})
} }
QtObject { QtObject {
@ -32,20 +31,25 @@ ColumnLayout {
model: internal.paths model: internal.paths
ColumnLayout { ColumnLayout {
AppLineEdit { AppLineEdit {
text: modelData.name text: modelData
onTextChanged: {
internal.paths[index] = text
}
}
}
} }
AppLineEdit { AppButton {
text: modelData.path text: "+"
} onClicked: {
internal.paths = [...internal.paths, ""]
} }
} }
AppButton { AppButton {
text: "Save" text: "Save"
onClicked: { onClicked: {
backend. form.confirmed(internal.paths)
form.confirmed()
} }
} }
} }