commit d661cc7b426671c644935fbd0c0d6df184d2c7fb Author: Aurélie Delhaie Date: Tue Feb 1 19:08:44 2022 +0100 First version diff --git a/Info.plist b/Info.plist new file mode 100755 index 0000000..5c734dc --- /dev/null +++ b/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleExecutable + TaskNote + CFBundleIconFile + + CFBundleIdentifier + com.aureliedelhaie.TaskNote + CFBundlePackageType + APPL + CFBundleSignature + ???? + LSMinimumSystemVersion + 10.14 + NSPrincipalClass + NSApplication + NSSupportsAutomaticGraphicsSwitching + + CFBundleIconFile + icon.icns + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..de8d568 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# TaskNote - 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 diff --git a/TaskNote.pro b/TaskNote.pro new file mode 100755 index 0000000..cf05ddd --- /dev/null +++ b/TaskNote.pro @@ -0,0 +1,77 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++17 + +# remove possible other optimization flags +win32 { + message("Build for Windows") + QMAKE_CXXFLAGS_RELEASE -= -O + QMAKE_CXXFLAGS_RELEASE -= -O1 + QMAKE_CXXFLAGS_RELEASE *= -O2 + equals(QMAKE_TARGET.arch, arm64) { + message("CPU Architecture : aarch64") + # Add specific arm stuff here + } + equals(QMAKE_TARGET.arch, x86_64) { + message("CPU Architecture : x64") + QMAKE_CXXFLAGS_RELEASE += -favor:INTEL64 + } + RC_ICONS = icon.ico + VERSION = 1.1.0.0 + QMAKE_TARGET_COMPANY = "Aurelie Delhaie" + QMAKE_TARGET_PRODUCT = "TaskNote" + QMAKE_TARGET_DESCRIPTION = "TaskNote" +} + +macx { + message("Build for macOS") + ICON = icon.icns + QMAKE_INFO_PLIST = Info.plist + QMAKE_CXXFLAGS_RELEASE -= -O + QMAKE_CXXFLAGS_RELEASE -= -O1 + QMAKE_CXXFLAGS_RELEASE -= -O2 + QMAKE_CXXFLAGS_RELEASE *= -O3 + equals(QMAKE_APPLE_DEVICE_ARCHS, arm64) { + message("CPU Architecture : aarch64") + QMAKE_CXXFLAGS_RELEASE += -mcpu=apple-a14 + } + VERSION = 1.1.0 +} + +linux-g++* { + message("Build for Linux") + QMAKE_CXXFLAGS_RELEASE *= -O3 + QMAKE_CXXFLAGS_RELEASE += -march=skylake + VERSION = 1.1.0 +} + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + src/frames/aboutdialog.cpp \ + src/main.cpp \ + src/frames/mainwindow.cpp \ + src/models/note.cpp \ + src/services/savemanager.cpp + +HEADERS += \ + src/frames/aboutdialog.h \ + src/frames/mainwindow.h \ + src/models/note.h \ + src/services/savemanager.h + +FORMS += \ + src/frames/aboutdialog.ui \ + src/frames/mainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + icons.qrc diff --git a/TaskNote.pro.user b/TaskNote.pro.user new file mode 100755 index 0000000..97c2f07 --- /dev/null +++ b/TaskNote.pro.user @@ -0,0 +1,266 @@ + + + + + + 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 + 1 + 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 + 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 + + + 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-Release/TaskNote.app/Contents/MacOS + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/TaskNote.pro.user.4f8813a b/TaskNote.pro.user.4f8813a new file mode 100755 index 0000000..a9a66a5 --- /dev/null +++ b/TaskNote.pro.user.4f8813a @@ -0,0 +1,267 @@ + + + + + + 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 new file mode 100755 index 0000000..9f73a8a --- /dev/null +++ b/TaskNote.pro.user.6652f76 @@ -0,0 +1,265 @@ + + + + + + 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 new file mode 100755 index 0000000..c88d811 --- /dev/null +++ b/TaskNote.pro.user.f1407b1 @@ -0,0 +1,264 @@ + + + + + + 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/icon.icns b/icon.icns new file mode 100755 index 0000000..39c3b1f Binary files /dev/null and b/icon.icns differ diff --git a/icon.ico b/icon.ico new file mode 100755 index 0000000..f48bc2a Binary files /dev/null and b/icon.ico differ diff --git a/icons.qrc b/icons.qrc new file mode 100755 index 0000000..c5e844d --- /dev/null +++ b/icons.qrc @@ -0,0 +1,11 @@ + + + resources/outline_add_circle_outline_black_18dp.png + resources/outline_delete_forever_black_18dp.png + resources/outline_save_black_18dp.png + resources/outline_help_outline_black_18dp.png + + + resources/logo.png + + diff --git a/resources/logo.png b/resources/logo.png new file mode 100755 index 0000000..e498b55 Binary files /dev/null and b/resources/logo.png differ diff --git a/resources/outline_add_circle_outline_black_18dp.png b/resources/outline_add_circle_outline_black_18dp.png new file mode 100755 index 0000000..59e2fa2 Binary files /dev/null and b/resources/outline_add_circle_outline_black_18dp.png differ diff --git a/resources/outline_delete_forever_black_18dp.png b/resources/outline_delete_forever_black_18dp.png new file mode 100755 index 0000000..c89a0ff Binary files /dev/null and b/resources/outline_delete_forever_black_18dp.png differ diff --git a/resources/outline_help_outline_black_18dp.png b/resources/outline_help_outline_black_18dp.png new file mode 100755 index 0000000..200b15c Binary files /dev/null and b/resources/outline_help_outline_black_18dp.png differ diff --git a/resources/outline_save_black_18dp.png b/resources/outline_save_black_18dp.png new file mode 100755 index 0000000..f6cd4ca Binary files /dev/null and b/resources/outline_save_black_18dp.png differ diff --git a/src/frames/aboutdialog.cpp b/src/frames/aboutdialog.cpp new file mode 100755 index 0000000..13933b3 --- /dev/null +++ b/src/frames/aboutdialog.cpp @@ -0,0 +1,15 @@ +#include "aboutdialog.h" +#include "ui_aboutdialog.h" + +AboutDialog::AboutDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::AboutDialog) +{ + ui->setupUi(this); + ui->appNameLabel->setText(QString("TaskNote (%1)").arg(QSysInfo::currentCpuArchitecture())); +} + +AboutDialog::~AboutDialog() +{ + delete ui; +} diff --git a/src/frames/aboutdialog.h b/src/frames/aboutdialog.h new file mode 100755 index 0000000..a8c5c53 --- /dev/null +++ b/src/frames/aboutdialog.h @@ -0,0 +1,23 @@ +#ifndef ABOUTDIALOG_H +#define ABOUTDIALOG_H + +#include +#include + +namespace Ui { +class AboutDialog; +} + +class AboutDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AboutDialog(QWidget *parent = nullptr); + ~AboutDialog(); + +private: + Ui::AboutDialog *ui; +}; + +#endif // ABOUTDIALOG_H diff --git a/src/frames/aboutdialog.ui b/src/frames/aboutdialog.ui new file mode 100755 index 0000000..9565d03 --- /dev/null +++ b/src/frames/aboutdialog.ui @@ -0,0 +1,97 @@ + + + AboutDialog + + + + 0 + 0 + 334 + 180 + + + + + 334 + 180 + + + + + 334 + 180 + + + + About TaskNote + + + + + + + + + 0 + 64 + + + + + 16777215 + 64 + + + + image: url(:/logo/resources/logo.png); + + + + + + Qt::AlignCenter + + + + + + + + 14 + + + + TaskNote + + + Qt::AlignCenter + + + + + + + Version 1.1.0.0 + + + Qt::AlignCenter + + + + + + + Author: Aurélie Delhaie (aureliedelhaie.fr) + + + Qt::AlignCenter + + + + + + + + + + diff --git a/src/frames/mainwindow.cpp b/src/frames/mainwindow.cpp new file mode 100755 index 0000000..0bdcd15 --- /dev/null +++ b/src/frames/mainwindow.cpp @@ -0,0 +1,133 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); + timer = new QTimer(this); + 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); + const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); + ui->contentEdit->setFont(fixedFont); + this->savemng = new SaveManager(); + updateListView(); + connect(timer, &QTimer::timeout, this, &MainWindow::save); +} + +MainWindow::~MainWindow() +{ + delete timer; + delete savemng; + delete ui; +} + +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) + { + 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->actionRemove->setDisabled(false); + ui->titleEdit->setDisabled(false); + ui->contentEdit->setDisabled(false); + ui->titleEdit->setText(n->getTitle()); + ui->contentEdit->setPlainText(n->getContent()); + ui->markdownViewer->setMarkdown(n->getContent()); +} + +void MainWindow::removeSelected() +{ + if (this->currentIndex > -1) + { + this->savemng->removeNoteByIndex(this->currentIndex); + clearAndDisableFields(); + updateListView(); + } +} + +void MainWindow::save() +{ + 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()); + } + timer->start(1000); +} + +void MainWindow::showAboutBox() +{ + AboutDialog dialog; + dialog.setModal(true); + dialog.exec(); +} + +void MainWindow::contentChanged() +{ + timer->stop(); + if (this->currentIndex > -1) + { + Note *n = this->savemng->getNoteByIndex(this->currentIndex); + n->setContent(ui->contentEdit->toPlainText()); + ui->markdownViewer->setMarkdown(ui->contentEdit->toPlainText()); + } + timer->start(1000); +} + +void MainWindow::updateListView() +{ + ui->noteList->clear(); + foreach (Note *n, savemng->getNotes()) + { + ui->noteList->addItem(n->getTitle()); + } +} + +void MainWindow::clearAndDisableFields() +{ + this->currentIndex = -1; + ui->actionRemove->setDisabled(true); + ui->titleEdit->setDisabled(true); + ui->contentEdit->setDisabled(true); + ui->titleEdit->clear(); + ui->contentEdit->clear(); + ui->markdownViewer->clear(); +} + diff --git a/src/frames/mainwindow.h b/src/frames/mainwindow.h new file mode 100755 index 0000000..644b7a9 --- /dev/null +++ b/src/frames/mainwindow.h @@ -0,0 +1,44 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + + +#include +#include +#include + +#include "../services/savemanager.h" +#include "aboutdialog.h" + + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private slots: + void createNote(); + void selectionChanged(int); + void removeSelected(); + void save(); + void contentChanged(); + void titleChanged(); + void showAboutBox(); + +private: + Ui::MainWindow *ui; + SaveManager *savemng; + QTimer *timer; + + int currentIndex = -1; + + void updateListView(); + void clearAndDisableFields(); +}; +#endif // MAINWINDOW_H diff --git a/src/frames/mainwindow.ui b/src/frames/mainwindow.ui new file mode 100755 index 0000000..49e7fb4 --- /dev/null +++ b/src/frames/mainwindow.ui @@ -0,0 +1,189 @@ + + + MainWindow + + + + 0 + 0 + 1075 + 710 + + + + + 1075 + 710 + + + + TaskNote + + + + + + + + + + 250 + 16777215 + + + + + + + + Qt::Vertical + + + + + + + + + + 16777215 + 13 + + + + Title + + + + + + + false + + + + + + + + + Markdown editor + + + + + + + Viewer + + + + + + + + + + + false + + + + + + + true + + + QTextEdit::AutoAll + + + QTextEdit::WidgetWidth + + + true + + + false + + + Qt::TextSelectableByMouse + + + + + + + + + + + + + + + 16777215 + 33 + + + + toolBar + + + TopToolBarArea + + + false + + + + + + + + + + + + :/icon/resources/outline_add_circle_outline_black_18dp.png:/icon/resources/outline_add_circle_outline_black_18dp.png + + + Add + + + + + false + + + + :/icon/resources/outline_delete_forever_black_18dp.png:/icon/resources/outline_delete_forever_black_18dp.png + + + Remove + + + + + + :/icon/resources/outline_save_black_18dp.png:/icon/resources/outline_save_black_18dp.png + + + Save + + + + + + :/icon/resources/outline_help_outline_black_18dp.png:/icon/resources/outline_help_outline_black_18dp.png + + + About + + + + + + + + diff --git a/src/main.cpp b/src/main.cpp new file mode 100755 index 0000000..8e0d377 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,11 @@ +#include "src/frames/mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/src/models/note.cpp b/src/models/note.cpp new file mode 100755 index 0000000..7200a04 --- /dev/null +++ b/src/models/note.cpp @@ -0,0 +1,45 @@ +#include "note.h" + +Note::Note() +{ + +} + +QJsonObject Note::toJson() +{ + QJsonObject o; + + o["title"] = this->title; + o["content"] = this->content; + + return o; +} + +Note *Note::fromJson(QJsonObject o) +{ + Note *n = new Note(); + n->title = o["title"].toString(); + n->content = o["content"].toString(); + return n; +} + +QString Note::getTitle() +{ + return title; +} + +QString Note::getContent() +{ + return content; +} + +void Note::setTitle(QString value) +{ + this->title = value; +} + +void Note::setContent(QString value) +{ + this->content = value; +} + diff --git a/src/models/note.h b/src/models/note.h new file mode 100755 index 0000000..a22a546 --- /dev/null +++ b/src/models/note.h @@ -0,0 +1,26 @@ +#ifndef NOTE_H +#define NOTE_H + +#include +#include + +class Note +{ +public: + Note(); + + QJsonObject toJson(); + static Note* fromJson(QJsonObject o); + + QString getTitle(); + QString getContent(); + + void setTitle(QString value); + void setContent(QString value); + +private: + QString title; + QString content; +}; + +#endif // NOTE_H diff --git a/src/services/savemanager.cpp b/src/services/savemanager.cpp new file mode 100755 index 0000000..63d7787 --- /dev/null +++ b/src/services/savemanager.cpp @@ -0,0 +1,99 @@ +#include "savemanager.h" + +SaveManager::SaveManager() +{ + openSave(); +} + +SaveManager::~SaveManager() +{ + flushSave(); +} + +void SaveManager::flushSave() +{ + QJsonArray json_notes; + + foreach (Note *n, notes) + { + json_notes.append(n->toJson()); + } + + QJsonObject obj + { + {"notes", json_notes}, + }; + + QJsonDocument doc(obj); + QFile *f = new QFile(getSaveFilePath()); + if (f->open(QIODevice::WriteOnly)) + { + f->write(doc.toJson()); + f->close(); + } + delete f; +} + +QVector SaveManager::getNotes() +{ + return notes; +} + +void SaveManager::addNote(Note *n) +{ + 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())) + { + return nullptr; + } + return this->notes[i]; +} + +QString SaveManager::getSaveFilePath() { + QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + if (!QDir(path).exists()) + { + QDir().mkpath(path); + } + + path += "/data/"; + if (!QDir(path).exists()) + { + QDir().mkpath(path); + } + path += SAVE_FILENAME; + return QDir::cleanPath(path); +} + +void SaveManager::openSave() { + QFile* file = new QFile(getSaveFilePath()); + file->open(QIODevice::ReadOnly); + auto json = QString(file->readAll()); + file->close(); + delete file; + + QJsonObject obj = QJsonDocument::fromJson(json.toUtf8()).object(); + QJsonArray arr = obj["notes"].toArray(); + for (int i = 0; i < arr.size(); i++) + { + this->notes.append(Note::fromJson(arr[i].toObject())); + } +} diff --git a/src/services/savemanager.h b/src/services/savemanager.h new file mode 100755 index 0000000..25eb1e3 --- /dev/null +++ b/src/services/savemanager.h @@ -0,0 +1,35 @@ +#ifndef SAVEMANAGER_H +#define SAVEMANAGER_H + +#define SAVE_FILENAME "data.json" + +#include +#include +#include +#include +#include +#include + +#include "../models/note.h" + +class SaveManager +{ +public: + SaveManager(); + ~SaveManager(); + + void flushSave(); + + QVector getNotes(); + + void addNote(Note *n); + bool removeNoteByIndex(int i); + Note *getNoteByIndex(int i); +private: + QString getSaveFilePath(); + void openSave(); + + QVector notes; +}; + +#endif // SAVEMANAGER_H