mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-02 09:23:18 +00:00
Add files settings in UI (wip)
This commit is contained in:
parent
e5328c15d4
commit
d8d50582c3
7 changed files with 92 additions and 35 deletions
|
@ -9,6 +9,7 @@
|
|||
#include "core/TaskItem.h"
|
||||
#include "core/TasksView.h"
|
||||
#include "core/TodoMd.h"
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <qjsonarray.h>
|
||||
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue