diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89f64c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pro.* diff --git a/Info.plist b/Info.plist index 5c734dc..3c47053 100755 --- a/Info.plist +++ b/Info.plist @@ -3,11 +3,11 @@ CFBundleExecutable - TaskNote + WorkPad CFBundleIconFile CFBundleIdentifier - com.aureliedelhaie.TaskNote + com.aureliedelhaie.WorkPad CFBundlePackageType APPL CFBundleSignature diff --git a/README.md b/README.md index de8d568..6dc4dbf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ -# TaskNote - Simple note editor +# WorkPad - Simple note editor Wrote with Qt 6 Open Source : [Download](https://www.qt.io/download-open-source) This is a very simple note editor. The editor has a Markdown text area and a rendering view + +## Prepare to use on linux +You need to install Qt 6 dependencies + +```sh +sudo apt install libqt6widgets6 libqt6gui6 libqt6core5compat6 libqt6core5compat6 libqt6core6 libqt6dbus6 +``` diff --git a/TaskNote.pro.user b/TaskNote.pro.user deleted file mode 100755 index 618b18e..0000000 --- a/TaskNote.pro.user +++ /dev/null @@ -1,263 +0,0 @@ - - - - - - EnvironmentId - {dbe9fba1-e5a9-4d98-85bf-f46da0900eba} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - false - true - false - 0 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - - 0 - true - - true - Builtin.BuildSystem - - true - true - Builtin.DefaultTidyAndClazy - 8 - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop Qt 6.2.3 GCC 64bit - Desktop Qt 6.2.3 GCC 64bit - qt.qt6.623.gcc_64_kit - 0 - 0 - 0 - - 0 - /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Debug - /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Debug - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Release - /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Release - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Profile - /home/aurelie/src/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Profile - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - ProjectExplorer.CustomExecutableRunConfiguration - - false - true - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/TaskNote.pro.user.4f8813a b/TaskNote.pro.user.4f8813a deleted file mode 100755 index a9a66a5..0000000 --- a/TaskNote.pro.user.4f8813a +++ /dev/null @@ -1,267 +0,0 @@ - - - - - - EnvironmentId - {4f8813a6-3af3-4bb9-ae1e-fccaa8f98bf0} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - false - true - false - 0 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - - 0 - true - - -fno-delayed-template-parsing - - true - Builtin.BuildSystem - - true - true - Builtin.DefaultTidyAndClazy - 8 - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop Qt 6.2.3 MSVC2019 64bit - Desktop Qt 6.2.3 MSVC2019 64bit - qt.qt6.623.win64_msvc2019_64_kit - 1 - 0 - 0 - - 0 - D:\build-TaskNote-Desktop_Qt_6_2_3_MSVC2019_64bit-Debug - D:/build-TaskNote-Desktop_Qt_6_2_3_MSVC2019_64bit-Debug - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - D:\build-TaskNote-Desktop_Qt_6_2_3_MSVC2019_64bit-Release - D:/build-TaskNote-Desktop_Qt_6_2_3_MSVC2019_64bit-Release - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - D:\build-TaskNote-Desktop_Qt_6_2_3_MSVC2019_64bit-Profile - D:/build-TaskNote-Desktop_Qt_6_2_3_MSVC2019_64bit-Profile - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:D:/TaskNote/TaskNote.pro - D:/TaskNote/TaskNote.pro - false - true - true - false - true - D:/build-TaskNote-Desktop_Qt_6_2_3_MSVC2019_64bit-Release - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/TaskNote.pro.user.6652f76 b/TaskNote.pro.user.6652f76 deleted file mode 100755 index 9f73a8a..0000000 --- a/TaskNote.pro.user.6652f76 +++ /dev/null @@ -1,265 +0,0 @@ - - - - - - EnvironmentId - {6652f76d-bc53-48e0-b6d8-98a4bb74cdef} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - false - true - false - 0 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - - 0 - true - - true - Builtin.BuildSystem - - true - true - Builtin.DefaultTidyAndClazy - 8 - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop Qt 6.2.3 GCC 64bit - Desktop Qt 6.2.3 GCC 64bit - qt.qt6.623.gcc_64_kit - 1 - 0 - 0 - - 0 - /home/aurelie/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Debug - /home/aurelie/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Debug - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - /home/aurelie/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Release - /home/aurelie/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Release - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - /home/aurelie/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Profile - /home/aurelie/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Profile - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:/home/aurelie/TaskNote/TaskNote.pro - /home/aurelie/TaskNote/TaskNote.pro - false - true - true - false - true - /home/aurelie/build-TaskNote-Desktop_Qt_6_2_3_GCC_64bit-Release - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/TaskNote.pro.user.f1407b1 b/TaskNote.pro.user.f1407b1 deleted file mode 100755 index c88d811..0000000 --- a/TaskNote.pro.user.f1407b1 +++ /dev/null @@ -1,264 +0,0 @@ - - - - - - EnvironmentId - {f1407b1e-b4d5-4aac-ba0d-b38072a0dfb8} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - false - true - false - 0 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - - 0 - true - - true - Builtin.BuildSystem - - true - true - Builtin.DefaultTidyAndClazy - 4 - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Qt 6.2.0 for macOS - Qt 6.2.0 for macOS - qt.qt6.620.clang_64_kit - 0 - 0 - 0 - - 0 - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Debug - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Debug - - - true - QtProjectManager.QMakeBuildStep - false - - arm-darwin-generic-mach_o-64bit - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Release - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Release - - - true - QtProjectManager.QMakeBuildStep - true - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Profile - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Profile - - - true - QtProjectManager.QMakeBuildStep - true - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:/Users/alexis/TaskNote/TaskNote.pro - /Users/alexis/TaskNote/TaskNote.pro - false - true - true - false - true - /Users/alexis/build-TaskNote-Qt_6_2_0_for_macOS-Debug/TaskNote.app/Contents/MacOS - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/TaskNote.pro b/WorkPad.pro similarity index 66% rename from TaskNote.pro rename to WorkPad.pro index 84ea27a..49b04c7 100755 --- a/TaskNote.pro +++ b/WorkPad.pro @@ -1,14 +1,14 @@ QT += core gui -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += widgets CONFIG += c++17 -win32:VERSION = 1.1.2.0 # major.minor.patch.build -else:VERSION = 1.1.2 # major.minor.patch +win32:VERSION = 2.0.0.0 # major.minor.patch.build +else:VERSION = 2.0.0 # major.minor.patch DEFINES += APP_VERSION=\"\\\"$${VERSION}\\\"\" -DEFINES += APP_NAME=\"\\\"TaskNote\\\"\" +DEFINES += APP_NAME=\"\\\"WorkPad\\\"\" # remove possible other optimization flags win32 { @@ -17,7 +17,7 @@ win32 { QMAKE_CXXFLAGS_RELEASE -= -O1 QMAKE_CXXFLAGS_RELEASE *= -O2 DEFINES += APP_OS=\"\\\"Windows\\\"\" - DEFINES += APP_OS_VERSION=\"\\\"$$system(wmic os get version /value)\\\"\" + DEFINES += APP_OS_VERSION=\"\\\"$$system(ver)\\\"\" equals(QMAKE_TARGET.arch, arm64) { message("CPU Architecture : aarch64") DEFINES += APP_ARCH=\"\\\"arm64\\\"\" @@ -29,8 +29,8 @@ win32 { } RC_ICONS = icon.ico QMAKE_TARGET_COMPANY = "Aurelie Delhaie" - QMAKE_TARGET_PRODUCT = "TaskNote" - QMAKE_TARGET_DESCRIPTION = "Simple note-taking workbook" + QMAKE_TARGET_PRODUCT = "WorkPad" + QMAKE_TARGET_DESCRIPTION = "WorkPad" } macx { @@ -47,13 +47,21 @@ macx { DEFINES += APP_ARCH=\"\\\"universal\\\"\" } -linux-g++* { +linux-* { message("Build for Linux") DEFINES += APP_OS=\"\\\"$$system(cat /etc/issue | cut -d\' \' -f1)\\\"\" DEFINES += APP_OS_VERSION=\"\\\"$$system(uname -r)\\\"\" - DEFINES += APP_ARCH=\"\\\"amd64\\\"\" + DEFINES += APP_ARCH=\"\\\"$$system(uname -m)\\\"\" + ARCH = $$system(uname -m) + equals(ARCH, aarch64) { + message("CPU Architecture : aarch64") + QMAKE_CXXFLAGS_RELEASE += -mtune=cortex-a72 + } + equals(ARCH, amd64) { + message("CPU Architecture : amd64") + QMAKE_CXXFLAGS_RELEASE += -march=skylake + } QMAKE_CXXFLAGS_RELEASE *= -O3 - QMAKE_CXXFLAGS_RELEASE += -march=skylake } # You can make your code fail to compile if it uses deprecated APIs. @@ -61,21 +69,32 @@ linux-g++* { #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + src/frames/renamedialog.cpp \ src/frames/aboutdialog.cpp \ + src/frames/createdialog.cpp \ + src/frames/movedialog.cpp \ src/main.cpp \ src/frames/mainwindow.cpp \ src/models/note.cpp \ + src/models/folder.cpp \ src/services/savemanager.cpp HEADERS += \ + src/frames/renamedialog.h \ src/frames/aboutdialog.h \ + src/frames/createdialog.h \ src/frames/mainwindow.h \ + src/frames/movedialog.h \ src/models/note.h \ + src/models/folder.h \ src/services/savemanager.h FORMS += \ + src/frames/renamedialog.ui \ src/frames/aboutdialog.ui \ - src/frames/mainwindow.ui + src/frames/createdialog.ui \ + src/frames/mainwindow.ui \ + src/frames/movedialog.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/icons.qrc b/icons.qrc index a1df688..8bf35f5 100755 --- a/icons.qrc +++ b/icons.qrc @@ -1,12 +1,10 @@ - resources/outline_add_circle_outline_black_48dp.png resources/outline_delete_forever_black_48dp.png resources/outline_help_outline_black_48dp.png - resources/outline_lock_black_48dp.png resources/outline_save_black_48dp.png - resources/outline_shield_black_48dp.png - resources/outline_lock_open_black_48dp.png + resources/new_file.png + resources/new_folder.png resources/logo.png diff --git a/resources/new_file.png b/resources/new_file.png new file mode 100644 index 0000000..86518c4 Binary files /dev/null and b/resources/new_file.png differ diff --git a/resources/new_folder.png b/resources/new_folder.png new file mode 100644 index 0000000..1396389 Binary files /dev/null and b/resources/new_folder.png differ diff --git a/resources/outline_add_circle_outline_black_48dp.png b/resources/outline_add_circle_outline_black_48dp.png deleted file mode 100644 index c6ecf98..0000000 Binary files a/resources/outline_add_circle_outline_black_48dp.png and /dev/null differ diff --git a/resources/outline_lock_black_48dp.png b/resources/outline_lock_black_48dp.png deleted file mode 100644 index 4817e2e..0000000 Binary files a/resources/outline_lock_black_48dp.png and /dev/null differ diff --git a/resources/outline_lock_open_black_48dp.png b/resources/outline_lock_open_black_48dp.png deleted file mode 100644 index 99d1f07..0000000 Binary files a/resources/outline_lock_open_black_48dp.png and /dev/null differ diff --git a/resources/outline_shield_black_48dp.png b/resources/outline_shield_black_48dp.png deleted file mode 100644 index dd9f8f8..0000000 Binary files a/resources/outline_shield_black_48dp.png and /dev/null differ diff --git a/src/frames/aboutdialog.ui b/src/frames/aboutdialog.ui index 3a1b1a9..63debeb 100755 --- a/src/frames/aboutdialog.ui +++ b/src/frames/aboutdialog.ui @@ -23,7 +23,7 @@ - About TaskNote + About WorkPad true @@ -64,7 +64,7 @@ - TaskNote + WorkPad Qt::AlignCenter diff --git a/src/frames/createdialog.cpp b/src/frames/createdialog.cpp new file mode 100644 index 0000000..407ebeb --- /dev/null +++ b/src/frames/createdialog.cpp @@ -0,0 +1,19 @@ +#include "createdialog.h" +#include "ui_createdialog.h" + +CreateDialog::CreateDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::CreateDialog) +{ + ui->setupUi(this); +} + +CreateDialog::~CreateDialog() +{ + delete ui; +} + +QString CreateDialog::getTitle() +{ + return ui->lineEdit->text(); +} diff --git a/src/frames/createdialog.h b/src/frames/createdialog.h new file mode 100644 index 0000000..ebbeaaa --- /dev/null +++ b/src/frames/createdialog.h @@ -0,0 +1,23 @@ +#ifndef CREATEDIALOG_H +#define CREATEDIALOG_H + +#include + +namespace Ui { +class CreateDialog; +} + +class CreateDialog : public QDialog +{ + Q_OBJECT + +public: + explicit CreateDialog(QWidget *parent = nullptr); + ~CreateDialog(); + QString getTitle(); + +private: + Ui::CreateDialog *ui; +}; + +#endif // CREATEDIALOG_H diff --git a/src/frames/createdialog.ui b/src/frames/createdialog.ui new file mode 100644 index 0000000..0b2410d --- /dev/null +++ b/src/frames/createdialog.ui @@ -0,0 +1,111 @@ + + + CreateDialog + + + + 0 + 0 + 400 + 139 + + + + + 400 + 139 + + + + + 400 + 139 + + + + Create + + + + + 10 + 100 + 381 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 10 + 10 + 141 + 41 + + + + + 24 + + + + Create + + + + + + 10 + 60 + 381 + 25 + + + + Title + + + + + + + buttonBox + accepted() + CreateDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + CreateDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/frames/mainwindow.cpp b/src/frames/mainwindow.cpp index d19a04f..3929951 100755 --- a/src/frames/mainwindow.cpp +++ b/src/frames/mainwindow.cpp @@ -1,21 +1,29 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include "aboutdialog.h" +#include "createdialog.h" +#include "movedialog.h" +#include "renamedialog.h" + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); timer = new QTimer(this); + connect(ui->actionAdd_folder, &QAction::triggered, this, &MainWindow::createFolder); connect(ui->actionAdd, &QAction::triggered, this, &MainWindow::createNote); - connect(ui->actionRemove, &QAction::triggered, this, &MainWindow::removeSelected); connect(ui->actionSave, &QAction::triggered, this, &MainWindow::save); connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::showAboutBox); - connect(ui->noteList, &QListWidget::currentRowChanged, this, &MainWindow::selectionChanged); - connect(ui->titleEdit, &QLineEdit::textChanged, this, &MainWindow::titleChanged); - connect(ui->contentEdit, &QPlainTextEdit::textChanged, this, &MainWindow::contentChanged); + connect(ui->contentEdit, &QPlainTextEdit::textChanged, this, &MainWindow::markdownContentChanged); + connect(ui->plainTextEdit, &QPlainTextEdit::textChanged, this, &MainWindow::plainContentChanged); + connect(ui->treeWidget, &QTreeWidget::itemSelectionChanged, this, &MainWindow::selectionChanged); + connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this, &MainWindow::prepareMenu); const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); ui->contentEdit->setFont(fixedFont); + ui->plainTextEdit->setFont(fixedFont); + ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); this->savemng = new SaveManager(); updateListView(); connect(timer, &QTimer::timeout, this, &MainWindow::save); @@ -30,77 +38,90 @@ MainWindow::~MainWindow() void MainWindow::createNote() { - Note *n = new Note(); - n->setTitle("untitled note"); - savemng->addNote(n); - updateListView(); -} - -void MainWindow::selectionChanged(int i) -{ - this->currentIndex = i; - if (i == -1) + if (ui->treeWidget->selectedItems().length() == 1) { - clearAndDisableFields(); - return; - } - Note *n = this->savemng->getNoteByIndex(i); - if (n == nullptr) - { - QMessageBox::critical(this, tr("TaskNote"), "Failed to get this note, the memory pointer is empty", QMessageBox::Ok, QMessageBox::Ok); - clearAndDisableFields(); - return; - } - - ui->contentEdit->blockSignals(true); - ui->titleEdit->blockSignals(true); - - ui->titleEdit->setDisabled(false); - ui->contentEdit->setDisabled(false); - ui->actionRemove->setDisabled(false); - ui->titleEdit->setText(n->getTitle()); - ui->contentEdit->setPlainText(n->getContent()); - ui->markdownViewer->setMarkdown(ui->contentEdit->toPlainText()); - - ui->contentEdit->blockSignals(false); - ui->titleEdit->blockSignals(false); -} - -void MainWindow::removeSelected() -{ - if (this->currentIndex > -1) - { - this->savemng->removeNoteByIndex(this->currentIndex); - clearAndDisableFields(); + CreateDialog dialog(this); + if (dialog.exec() != QDialog::Accepted) { + return; + } + QString title = dialog.getTitle(); + QString uuidFolder = ""; + auto item = ui->treeWidget->selectedItems()[0]; + if (item->text(COLUMN_TYPE) == TYPE_NOTE) + { + uuidFolder = item->parent()->text(COLUMN_UUID); + } + else + { + uuidFolder = item->text(COLUMN_UUID); + } + Note *n = savemng->newNote(uuidFolder, title); updateListView(); + selectTreeItem(n->getUUID()); + } +} + +void MainWindow::createFolder() +{ + CreateDialog dialog; + if (dialog.exec() != QDialog::Accepted) { + return; + } + QString title = dialog.getTitle(); + Folder *f = savemng->newFolder(title); + updateListView(); + selectTreeItem(f->getUUID()); +} + +void MainWindow::selectionChanged() +{ + if (ui->treeWidget->selectedItems().length() == 1) + { + auto item = ui->treeWidget->selectedItems()[0]; + ui->actionAdd->setDisabled(false); + if (item->text(COLUMN_TYPE) == TYPE_NOTE) + { + Note *n = savemng->getNoteByUUID(item->text(COLUMN_UUID)); + if (n == nullptr) + { + QMessageBox::critical(this, tr("WorkPad"), "Failed to get this note, the memory pointer is empty", QMessageBox::Ok, QMessageBox::Ok); + clearAndDisableFields(); + return; + } + ui->plainTextEdit->blockSignals(true); + ui->contentEdit->blockSignals(true); + + this->setWindowTitle(n->getTitle() + " - WorkPad"); + + ui->titleLabel->setText(n->getTitle()); + ui->plainTextEdit->setDisabled(false); + ui->contentEdit->setDisabled(false); + ui->plainTextEdit->setPlainText(n->getContent()); + ui->contentEdit->setPlainText(n->getContent()); + ui->markdownViewer->setMarkdown(ui->contentEdit->toPlainText()); + ui->markdownViewer2->setMarkdown(n->getContent()); + + ui->plainTextEdit->blockSignals(false); + ui->contentEdit->blockSignals(false); + } + else + { + clearAndDisableFields(); + } + } + else + { + clearAndDisableFields(); + ui->actionAdd->setDisabled(true); } } void MainWindow::save() { ui->actionSave->setDisabled(true); - if (this->currentIndex > -1) - { - Note *n = this->savemng->getNoteByIndex(this->currentIndex); - n->setTitle(ui->titleEdit->text()); - n->setContent(ui->contentEdit->toPlainText()); - } this->savemng->flushSave(); } -void MainWindow::titleChanged() -{ - timer->stop(); - if (this->currentIndex > -1) - { - Note *n = this->savemng->getNoteByIndex(this->currentIndex); - n->setTitle(ui->titleEdit->text()); - ui->noteList->item(this->currentIndex)->setText(ui->titleEdit->text()); - } - ui->actionSave->setDisabled(false); - timer->start(1000); -} - void MainWindow::showAboutBox() { AboutDialog dialog; @@ -108,42 +129,261 @@ void MainWindow::showAboutBox() dialog.exec(); } -void MainWindow::contentChanged() +void MainWindow::prepareMenu(const QPoint &pos) +{ + if (ui->treeWidget->selectedItems().length() == 1) { + QTreeWidgetItem *item = ui->treeWidget->selectedItems()[0]; + + QMenu menu(this); + QAction *deleteAction = new QAction(tr("Delete"), this); + connect(deleteAction, &QAction::triggered, this, &MainWindow::deleteItem); + menu.addAction(deleteAction); + QAction *renameAction = new QAction(tr("Rename"), this); + connect(renameAction, &QAction::triggered, this, &MainWindow::editName); + menu.addAction(renameAction); + if (item->text(COLUMN_TYPE) == TYPE_NOTE) + { + QAction *moveAction = new QAction(tr("Move to..."), this); + connect(moveAction, &QAction::triggered, this, &MainWindow::moveNote); + menu.addAction(moveAction); + } + menu.exec(ui->treeWidget->mapToGlobal(pos)); + } +} + +void MainWindow::deleteItem() +{ + if (ui->treeWidget->selectedItems().length() == 1) { + QTreeWidgetItem *item = ui->treeWidget->selectedItems()[0]; + QString uuid = item->text(COLUMN_UUID); + if (item->text(COLUMN_TYPE) == TYPE_NOTE) + { + QString uuidFolder = item->parent()->text(COLUMN_UUID); + Note *n = savemng->getNoteByUUID(uuid); + if (n == nullptr) + { + return; + } + if (!savemng->removeNote(uuidFolder, uuid)) + { + QMessageBox::critical(this, tr("WorkPad"), "Failed to remove this note", QMessageBox::Ok, QMessageBox::Ok); + return; + } + delete n; + } + else + { + Folder *f = savemng->getFolderByUUID(uuid); + if (f == nullptr) + { + return; + } + if (!savemng->removeFolder(uuid)) + { + QMessageBox::critical(this, tr("WorkPad"), "Failed to remove this folder", QMessageBox::Ok, QMessageBox::Ok); + return; + } + delete f; + } + savemng->flushSave(); + updateListView(); + } +} + +void MainWindow::moveNote() +{ + if (ui->treeWidget->selectedItems().length() == 1) { + QTreeWidgetItem *item = ui->treeWidget->selectedItems()[0]; + if (item->text(COLUMN_TYPE) == TYPE_NOTE) + { + QString uuidParent = item->parent()->text(COLUMN_UUID); + MoveDialog dialog(savemng->getFolders(), this); + if (dialog.exec() != QDialog::Accepted) { + return; + } + QString uuidFolder = dialog.getSelectedUUID(); + if (uuidFolder.length() == 0) + { + return; + } + // Check if parent is not the same folder + if (uuidFolder == uuidParent) + { + return; + } + QString uuid = item->text(COLUMN_UUID); + Note *n = savemng->getNoteByUUID(uuid); + if (n == nullptr) + { + return; + } + // Add to new folder + Folder *f = savemng->getFolderByUUID(uuidFolder); + if (f == nullptr) + { + QMessageBox::critical(this, tr("WorkPad"), "The folder is not found", QMessageBox::Ok, QMessageBox::Ok); + return; + } + f->append(n); + // Remove from parent folder + Folder *oldFolder = savemng->getFolderByUUID(uuidParent); + if (oldFolder == nullptr) + { + QMessageBox::critical(this, tr("WorkPad"), "The previous folder is not found, cannot delete the old version of this note", QMessageBox::Ok, QMessageBox::Ok); + return; + } + oldFolder->remove(uuid); + } + savemng->flushSave(); + updateListView(); + } +} + +void MainWindow::editName() +{ + if (ui->treeWidget->selectedItems().length() == 1) { + QTreeWidgetItem *item = ui->treeWidget->selectedItems()[0]; + QString uuid = item->text(COLUMN_UUID); + RenameDialog dialog(item->text(COLUMN_NAME), this); + if (dialog.exec() != QDialog::Accepted) + { + return; + } + QString newName = dialog.getNewName(); + if (item->text(COLUMN_TYPE) == TYPE_NOTE) + { + Note *n = savemng->getNoteByUUID(uuid); + if (n == nullptr) + { + QMessageBox::critical(this, tr("WorkPad"), "The note is not found", QMessageBox::Ok, QMessageBox::Ok); + return; + } + n->setTitle(newName); + } + else + { + Folder *f = savemng->getFolderByUUID(uuid); + if (f == nullptr) + { + QMessageBox::critical(this, tr("WorkPad"), "The folder is not found", QMessageBox::Ok, QMessageBox::Ok); + return; + } + f->setName(newName); + } + savemng->flushSave(); + updateListView(); + selectTreeItem(uuid); + } +} + +void MainWindow::markdownContentChanged() { timer->stop(); - if (this->currentIndex > -1) + ui->plainTextEdit->blockSignals(true); + ui->contentEdit->blockSignals(true); + if (ui->treeWidget->selectedItems().length() == 1) { - Note *n = this->savemng->getNoteByIndex(this->currentIndex); - n->setContent(ui->contentEdit->toPlainText()); - ui->markdownViewer->setMarkdown(ui->contentEdit->toPlainText()); + QString uuid = ui->treeWidget->selectedItems()[0]->text(COLUMN_UUID); + Note *n = savemng->getNoteByUUID(uuid); + if (n != nullptr) { + QString content = ui->contentEdit->toPlainText(); + ui->markdownViewer->setMarkdown(content); + ui->markdownViewer2->setMarkdown(content); + ui->plainTextEdit->setPlainText(content); + n->setContent(content); + } } + ui->plainTextEdit->blockSignals(false); + ui->contentEdit->blockSignals(false); + ui->actionSave->setDisabled(false); + timer->start(1000); +} + +void MainWindow::plainContentChanged() +{ + timer->stop(); + ui->plainTextEdit->blockSignals(true); + ui->contentEdit->blockSignals(true); + if (ui->treeWidget->selectedItems().length() == 1) + { + QString uuid = ui->treeWidget->selectedItems()[0]->text(COLUMN_UUID); + Note *n = savemng->getNoteByUUID(uuid); + if (n != nullptr) { + QString content = ui->plainTextEdit->toPlainText(); + ui->markdownViewer->setMarkdown(content); + ui->markdownViewer2->setMarkdown(content); + ui->contentEdit->setPlainText(content); + n->setContent(content); + } + } + ui->plainTextEdit->blockSignals(false); + ui->contentEdit->blockSignals(false); ui->actionSave->setDisabled(false); timer->start(1000); } void MainWindow::updateListView() { - ui->noteList->clear(); - foreach (Note *n, savemng->getNotes()) + ui->treeWidget->clear(); + foreach (Folder *f, savemng->getFolders()) { - ui->noteList->addItem(n->getTitle()); + QTreeWidgetItem *topLevel = new QTreeWidgetItem(); + topLevel->setText(COLUMN_NAME, f->getName()); + topLevel->setText(COLUMN_UUID, f->getUUID()); + topLevel->setText(COLUMN_TYPE, TYPE_FOLDER); + foreach (Note *n, f->getNotes()) + { + QTreeWidgetItem *children = new QTreeWidgetItem(); + children->setText(COLUMN_NAME, n->getTitle()); + children->setText(COLUMN_UUID, n->getUUID()); + children->setText(COLUMN_TYPE, TYPE_NOTE); + topLevel->addChild(children); + } + ui->treeWidget->addTopLevelItem(topLevel); } } void MainWindow::clearAndDisableFields() { ui->contentEdit->blockSignals(true); - ui->titleEdit->blockSignals(true); + ui->plainTextEdit->blockSignals(true); + - this->currentIndex = -1; - ui->actionRemove->setDisabled(true); - ui->titleEdit->setDisabled(true); ui->contentEdit->setDisabled(true); - ui->titleEdit->clear(); + ui->plainTextEdit->setDisabled(true); + ui->plainTextEdit->clear(); ui->contentEdit->clear(); ui->markdownViewer->clear(); + ui->markdownViewer2->clear(); + ui->titleLabel->setText(""); + this->setWindowTitle("WorkPad"); ui->contentEdit->blockSignals(false); - ui->titleEdit->blockSignals(false); + ui->plainTextEdit->blockSignals(false); +} + +void MainWindow::selectTreeItem(QString uuid) +{ + ui->treeWidget->clearSelection(); + int c = ui->treeWidget->topLevelItemCount(); + int cc = 0; + for (int i = 0; i < c; i++) + { + QTreeWidgetItem *topLevel = ui->treeWidget->topLevelItem(i); + if (topLevel->text(COLUMN_UUID) == uuid) + { + topLevel->setSelected(true); + } + cc = topLevel->childCount(); + for (int y = 0; y < cc; y++) + { + QTreeWidgetItem *child = topLevel->child(y); + if (child->text(COLUMN_UUID) == uuid) + { + child->setSelected(true); + topLevel->setExpanded(true); + } + } + } } diff --git a/src/frames/mainwindow.h b/src/frames/mainwindow.h index 644b7a9..4dd3452 100755 --- a/src/frames/mainwindow.h +++ b/src/frames/mainwindow.h @@ -5,10 +5,18 @@ #include #include #include +#include +#include +#include #include "../services/savemanager.h" -#include "aboutdialog.h" +#define COLUMN_NAME 0 +#define COLUMN_UUID 1 +#define COLUMN_TYPE 2 + +#define TYPE_FOLDER "1" +#define TYPE_NOTE "2" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -24,21 +32,24 @@ public: private slots: void createNote(); - void selectionChanged(int); - void removeSelected(); + void createFolder(); + void selectionChanged(); void save(); - void contentChanged(); - void titleChanged(); + void markdownContentChanged(); + void plainContentChanged(); void showAboutBox(); + void prepareMenu(const QPoint &pos); + void deleteItem(); + void moveNote(); + void editName(); private: Ui::MainWindow *ui; SaveManager *savemng; QTimer *timer; - int currentIndex = -1; - void updateListView(); void clearAndDisableFields(); + void selectTreeItem(QString uuid); }; #endif // MAINWINDOW_H diff --git a/src/frames/mainwindow.ui b/src/frames/mainwindow.ui index 7509c03..610eed9 100755 --- a/src/frames/mainwindow.ui +++ b/src/frames/mainwindow.ui @@ -17,20 +17,34 @@ - TaskNote + WorkPad + + + true - + 250 16777215 + + QAbstractItemView::NoEditTriggers + + + true + + + + Workspace + + @@ -43,83 +57,118 @@ - - - - 16777215 - 13 - + + + QTabWidget::South - - Title + + QTabWidget::Rounded - - - - - - false + + 0 - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - false - - - - false - - - - 200 - 0 - - - - - false - - - - QPlainTextEdit::NoWrap - + + + Plain text + + + + + + false + + + + + + + + 14 + + + + + + + + - - - true - - - - 200 - 0 - - - - QTextEdit::AutoAll - - - QTextEdit::NoWrap - - - true - - - false - - - Qt::TextSelectableByMouse - + + + Mardown editor + + + + + + + + false + + + + 200 + 0 + + + + + false + + + + QPlainTextEdit::NoWrap + + + + + + + true + + + + 200 + 0 + + + + QTextEdit::AutoAll + + + QTextEdit::NoWrap + + + true + + + false + + + Qt::TextSelectableByMouse + + + + + + + + + + Markdown viewer + + + + + + QTextEdit::NoWrap + + + true + + + + @@ -160,32 +209,29 @@ false + - - - - :/icon/resources/outline_add_circle_outline_black_48dp.png:/icon/resources/outline_add_circle_outline_black_48dp.png - - - Add - - - false - :/icon/resources/outline_delete_forever_black_48dp.png:/icon/resources/outline_delete_forever_black_48dp.png + :/icon/resources/new_file.png:/icon/resources/new_file.png - Remove + New note + + + Create a new note + + + Ctrl+N @@ -199,6 +245,9 @@ Save + + Ctrl+S + @@ -209,6 +258,21 @@ About + + + + :/icon/resources/new_folder.png:/icon/resources/new_folder.png + + + New folder + + + Create a new folder + + + Ctrl+F, Ctrl+N + + diff --git a/src/frames/movedialog.cpp b/src/frames/movedialog.cpp new file mode 100644 index 0000000..34c7b40 --- /dev/null +++ b/src/frames/movedialog.cpp @@ -0,0 +1,37 @@ +#include "movedialog.h" +#include "ui_movedialog.h" + +MoveDialog::MoveDialog(QVector folders, QWidget *parent) : + QDialog(parent), + ui(new Ui::MoveDialog) +{ + ui->setupUi(this); + if (folders.length() > 0) + { + this->folders = folders; + foreach (Folder *f, this->folders) + { + ui->comboBox->addItem(f->getName()); + } + ui->comboBox->setCurrentIndex(0); + } + else + { + ui->comboBox->setDisabled(true); + } +} + +MoveDialog::~MoveDialog() +{ + delete ui; +} + +QString MoveDialog::getSelectedUUID() +{ + int i = ui->comboBox->currentIndex(); + if (i == -1) + { + return ""; + } + return folders[i]->getUUID(); +} diff --git a/src/frames/movedialog.h b/src/frames/movedialog.h new file mode 100644 index 0000000..44f3559 --- /dev/null +++ b/src/frames/movedialog.h @@ -0,0 +1,28 @@ +#ifndef MOVEDIALOG_H +#define MOVEDIALOG_H + +#include + +#include "../models/folder.h" + +namespace Ui { +class MoveDialog; +} + +class MoveDialog : public QDialog +{ + Q_OBJECT + +public: + explicit MoveDialog(QVector folders, QWidget *parent = nullptr); + ~MoveDialog(); + + QString getSelectedUUID(); + +private: + Ui::MoveDialog *ui; + + QVector folders; +}; + +#endif // MOVEDIALOG_H diff --git a/src/frames/movedialog.ui b/src/frames/movedialog.ui new file mode 100644 index 0000000..68e1037 --- /dev/null +++ b/src/frames/movedialog.ui @@ -0,0 +1,108 @@ + + + MoveDialog + + + + 0 + 0 + 400 + 142 + + + + + 400 + 142 + + + + + 400 + 142 + + + + Dialog + + + + + 20 + 100 + 361 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 10 + 10 + 141 + 41 + + + + + 24 + + + + Move to + + + + + + 20 + 60 + 361 + 25 + + + + + + + + buttonBox + accepted() + MoveDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + MoveDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/frames/renamedialog.cpp b/src/frames/renamedialog.cpp new file mode 100644 index 0000000..5f9a385 --- /dev/null +++ b/src/frames/renamedialog.cpp @@ -0,0 +1,20 @@ +#include "renamedialog.h" +#include "ui_renamedialog.h" + +RenameDialog::RenameDialog(QString oldName, QWidget *parent) : + QDialog(parent), + ui(new Ui::RenameDialog) +{ + ui->setupUi(this); + ui->lineEdit->setText(oldName); +} + +RenameDialog::~RenameDialog() +{ + delete ui; +} + +QString RenameDialog::getNewName() +{ + return ui->lineEdit->text(); +} diff --git a/src/frames/renamedialog.h b/src/frames/renamedialog.h new file mode 100644 index 0000000..ceb9d27 --- /dev/null +++ b/src/frames/renamedialog.h @@ -0,0 +1,24 @@ +#ifndef RENAMEDIALOG_H +#define RENAMEDIALOG_H + +#include + +namespace Ui { +class RenameDialog; +} + +class RenameDialog : public QDialog +{ + Q_OBJECT + +public: + explicit RenameDialog(QString oldName, QWidget *parent = nullptr); + ~RenameDialog(); + + QString getNewName(); + +private: + Ui::RenameDialog *ui; +}; + +#endif // RENAMEDIALOG_H diff --git a/src/frames/renamedialog.ui b/src/frames/renamedialog.ui new file mode 100644 index 0000000..1f3c2ab --- /dev/null +++ b/src/frames/renamedialog.ui @@ -0,0 +1,96 @@ + + + RenameDialog + + + + 0 + 0 + 400 + 145 + + + + Dialog + + + + + 20 + 100 + 361 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 10 + 10 + 141 + 41 + + + + + 24 + + + + Rename + + + + + + 10 + 60 + 381 + 25 + + + + + + + + buttonBox + accepted() + RenameDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + RenameDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/main.cpp b/src/main.cpp index 8e0d377..57d591c 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,7 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; + w.setWindowState(Qt::WindowState::WindowMaximized); w.show(); return a.exec(); } diff --git a/src/models/folder.cpp b/src/models/folder.cpp new file mode 100644 index 0000000..60bf740 --- /dev/null +++ b/src/models/folder.cpp @@ -0,0 +1,83 @@ +#include "folder.h" + +Folder::Folder(QString name) +{ + QUuid uid = QUuid::createUuid(); + this->uuid = uid.toString(QUuid::StringFormat::WithoutBraces); + this->name = name; +} + +Folder::Folder(QJsonObject obj) +{ + QUuid uid = QUuid::createUuid(); + QString newUuid = uid.toString(QUuid::StringFormat::WithoutBraces); + + this->uuid = obj["uuid"].toString(newUuid); + this->name = obj["name"].toString(""); + foreach (QJsonValue value, obj["notes"].toArray()) { + this->notes.append(new Note(value.toObject())); + } +} + +Folder::~Folder() +{ + foreach (Note *n, notes) + { + delete n; + } +} + +QString Folder::getName() +{ + return name; +} + +void Folder::setName(QString name) +{ + this->name = name; +} + +QString Folder::getUUID() +{ + return uuid; +} + +QVector Folder::getNotes() +{ + return notes; +} + +void Folder::append(Note *n) +{ + notes.append(n); +} + +int Folder::remove(QString uuid) +{ + int res = 0; + int idx = -1; + for (int i = 0; i < notes.length(); i++) + { + if (notes[i]->getUUID() == uuid) + { + idx = i; + res = 1; + } + } + notes.removeAt(idx); + return res; +} + +QJsonObject Folder::toJson() +{ + QJsonObject folder; + QJsonArray arr; + foreach (Note *n, notes) { + arr.append(n->toJson()); + } + folder["name"] = this->name; + folder["uuid"] = this->uuid; + folder["notes"] = arr; + return folder; +} + diff --git a/src/models/folder.h b/src/models/folder.h new file mode 100644 index 0000000..27be495 --- /dev/null +++ b/src/models/folder.h @@ -0,0 +1,33 @@ +#ifndef FOLDER_H +#define FOLDER_H + +#include +#include +#include + +#include "note.h" + + +class Folder +{ +private: + QString uuid; + QString name; + QVector notes; + +public: + Folder(QString name); + Folder(QJsonObject obj); + ~Folder(); + + QString getName(); + void setName(QString name); + QString getUUID(); + QVector getNotes(); + void append(Note *n); + int remove(QString uuid); + + QJsonObject toJson(); +}; + +#endif // FOLDER_H diff --git a/src/models/note.cpp b/src/models/note.cpp index f1f4a32..366566b 100755 --- a/src/models/note.cpp +++ b/src/models/note.cpp @@ -1,9 +1,20 @@ #include "note.h" -Note::Note() +Note::Note(QString name) { QUuid uid = QUuid::createUuid(); this->uuid = uid.toString(QUuid::StringFormat::WithoutBraces); + this->title = name; +} + +Note::Note(QJsonObject obj) +{ + QUuid uid = QUuid::createUuid(); + QString newUuid = uid.toString(QUuid::StringFormat::WithoutBraces); + + this->uuid = obj["uuid"].toString(newUuid); + this->title = obj["title"].toString(""); + this->content = obj["content"].toString(); } QJsonObject Note::toJson() @@ -14,18 +25,7 @@ QJsonObject Note::toJson() o["content"] = this->content; return o; } - -Note *Note::fromJson(QJsonObject o) -{ - Note *n = new Note(); - n->uuid = o["uuid"].toString(n->uuid); - n->title = o["title"].toString(); - n->content = o["content"].toString(); - n->encrypted = o["encrypted"].toBool(false); - return n; -} - -QString Note::getUuid() +QString Note::getUUID() { return uuid; } @@ -37,11 +37,7 @@ QString Note::getTitle() QString Note::getContent() { - if (!this->encrypted) - { - return content; - } - return ""; + return content; } void Note::setTitle(QString value) { @@ -50,7 +46,5 @@ void Note::setTitle(QString value) void Note::setContent(QString value) { - if (!this->encrypted) { this->content = value; - } } diff --git a/src/models/note.h b/src/models/note.h index a0d0659..59b1e53 100755 --- a/src/models/note.h +++ b/src/models/note.h @@ -14,12 +14,13 @@ class Note { public: - Note(); + Note(QString name); + Note(QJsonObject obj); + QJsonObject toJson(); - static Note* fromJson(QJsonObject o); - QString getUuid(); + QString getUUID(); QString getTitle(); QString getContent(); @@ -29,7 +30,6 @@ private: QString uuid; QString title; QString content; - bool encrypted; }; #endif // NOTE_H diff --git a/src/services/savemanager.cpp b/src/services/savemanager.cpp index 27a4884..a209d4d 100755 --- a/src/services/savemanager.cpp +++ b/src/services/savemanager.cpp @@ -3,29 +3,33 @@ SaveManager::SaveManager() { openSave(); + if (oldSaveVersionExist()) + { + migrate(); + } } SaveManager::~SaveManager() { flushSave(); - foreach (Note *n, notes) + foreach (Folder *f, folders) { - delete n; + delete f; } } void SaveManager::flushSave() { - QJsonArray json_notes; + QJsonArray json_folders; - foreach (Note *n, notes) + foreach (Folder *f, folders) { - json_notes.append(n->toJson()); + json_folders.append(f->toJson()); } QJsonObject obj { - {"notes", json_notes}, + {"folders", json_folders}, }; QJsonDocument doc(obj); @@ -38,37 +42,152 @@ void SaveManager::flushSave() delete f; } -QVector SaveManager::getNotes() +QVector SaveManager::getFolders() { - return notes; + return folders; } -void SaveManager::addNote(Note *n) +Note *SaveManager::newNote(QString uuidFolder, QString name) { - this->notes.append(n); - flushSave(); -} - -bool SaveManager::removeNoteByIndex(int i) -{ - if ((i < 0) || (i >= this->notes.length())) - { - return false; - } - Note *n = this->notes[i]; - this->notes.removeAt(i); - delete n; - flushSave(); - return true; -} - -Note *SaveManager::getNoteByIndex(int i) -{ - if ((i < 0) || (i >= this->notes.length())) + Folder *f = getFolderByUUID(uuidFolder); + if (f == nullptr) { return nullptr; } - return this->notes[i]; + if (name.length() == 0) + { + name = ""; + } + Note *n = new Note(name); + f->append(n); + flushSave(); + return n; +} + +Folder *SaveManager::newFolder(QString name) +{ + if (name.length() == 0) + { + name = ""; + } + Folder *f = new Folder(name); + folders.append(f); + flushSave(); + return f; +} + +Folder *SaveManager::getFolderByUUID(QString uuid) +{ + Folder *folder = nullptr; + foreach (Folder *f, folders) + { + if (f->getUUID() == uuid) + { + folder = f; + } + } + return folder; +} + +Note *SaveManager::getNoteByUUID(QString uuid) +{ + Note *note = nullptr; + foreach (Folder *f, folders) + { + foreach (Note *n, f->getNotes()) + { + if (n->getUUID() == uuid) + { + note = n; + } + } + } + return note; +} + +int SaveManager::addNoteToFolder(QString uuidFolder, Note *n) +{ + Folder *f = getFolderByUUID(uuidFolder); + if (f == nullptr) + { + return 0; + } + f->append(n); + return 1; +} + +int SaveManager::removeFolder(QString uuid) +{ + int res = 0; + int idx = -1; + for (int i = 0; i < folders.length(); i++) + { + if (folders[i]->getUUID() == uuid) + { + idx = i; + res = 1; + } + } + folders.removeAt(idx); + return res; +} + +int SaveManager::removeNote(QString uuidFolder, QString uuid) +{ + Folder *f = getFolderByUUID(uuidFolder); + if (f == nullptr) + { + return 0; + } + return f->remove(uuid); +} + +bool SaveManager::oldSaveVersionExist() +{ + QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + path.replace("WorkPad", "TaskNote"); + if (!QDir(path).exists()) + { + return false; + } + path += "/data/"; + if (!QDir(path).exists()) + { + return false; + } + path += OLD_FILENAME; + return QFile::exists(QDir::cleanPath(path)); +} + +void SaveManager::migrate() +{ + QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + path.replace("WorkPad", "TaskNote"); + if (!QDir(path).exists()) + { + return; + } + path += "/data/"; + if (!QDir(path).exists()) + { + return; + } + path = QDir::cleanPath(path + OLD_FILENAME); + QFile* file = new QFile(path); + file->open(QIODevice::ReadOnly); + auto json = QString(file->readAll()); + file->close(); + delete file; + + QJsonObject obj = QJsonDocument::fromJson(json.toUtf8()).object(); + Folder *f = newFolder("Backup from older version"); + QJsonArray arr = obj["notes"].toArray(); + for (int i = 0; i < arr.size(); i++) + { + f->append(new Note(arr[i].toObject())); + } + flushSave(); + QFile::remove(path); } QString SaveManager::getSaveFilePath() { @@ -95,9 +214,9 @@ void SaveManager::openSave() { delete file; QJsonObject obj = QJsonDocument::fromJson(json.toUtf8()).object(); - QJsonArray arr = obj["notes"].toArray(); + QJsonArray arr = obj["folders"].toArray(); for (int i = 0; i < arr.size(); i++) { - this->notes.append(Note::fromJson(arr[i].toObject())); + this->folders.append(new Folder(arr[i].toObject())); } } diff --git a/src/services/savemanager.h b/src/services/savemanager.h index 25eb1e3..bc06968 100755 --- a/src/services/savemanager.h +++ b/src/services/savemanager.h @@ -1,7 +1,8 @@ #ifndef SAVEMANAGER_H #define SAVEMANAGER_H -#define SAVE_FILENAME "data.json" +#define SAVE_FILENAME "workspace.json" +#define OLD_FILENAME "data.json" #include #include @@ -11,6 +12,7 @@ #include #include "../models/note.h" +#include "../models/folder.h" class SaveManager { @@ -20,16 +22,23 @@ public: void flushSave(); - QVector getNotes(); + QVector getFolders(); + + Note *newNote(QString uuidFolder, QString name); + Folder *newFolder(QString name); + Folder *getFolderByUUID(QString uuid); + Note *getNoteByUUID(QString uuid); + int addNoteToFolder(QString uuidFolder, Note *n); + int removeFolder(QString uuid); + int removeNote(QString uuidFolder, QString uuid); - void addNote(Note *n); - bool removeNoteByIndex(int i); - Note *getNoteByIndex(int i); private: QString getSaveFilePath(); void openSave(); + bool oldSaveVersionExist(); + void migrate(); - QVector notes; + QVector folders; }; #endif // SAVEMANAGER_H