3 Commits

Author SHA1 Message Date
Aurélie Delhaie
8dd5892327 Add config dialog 2022-11-06 16:06:38 +01:00
Aurélie Delhaie
c00dd40def Add configuration file 2022-11-05 09:58:47 +01:00
Aurélie Delhaie
3626ffa54e Add export, fix scrollbar, fix dialog name 2022-11-04 22:51:12 +01:00
23 changed files with 831 additions and 197 deletions

View File

@@ -4,8 +4,8 @@ greaterThan(QT_MAJOR_VERSION, 5): QT += widgets
CONFIG += c++17
win32:VERSION = 2.0.0.0 # major.minor.patch.build
else:VERSION = 2.0.0 # major.minor.patch
win32:VERSION = 2.1.0.0 # major.minor.patch.build
else:VERSION = 2.1.0 # major.minor.patch
DEFINES += APP_VERSION=\"\\\"$${VERSION}\\\"\"
DEFINES += APP_NAME=\"\\\"WorkPad\\\"\"
@@ -69,29 +69,36 @@ linux-* {
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
src/frames/configdialog.cpp \
src/services/configmanager.cpp \
src/frames/exportdialog.cpp \
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/appconfiguration.cpp \
src/models/note.cpp \
src/models/folder.cpp \
src/services/savemanager.cpp
HEADERS += \
src/frames/configdialog.h \
src/services/configmanager.h \
src/frames/exportdialog.h \
src/frames/renamedialog.h \
src/frames/aboutdialog.h \
src/frames/createdialog.h \
src/frames/mainwindow.h \
src/frames/movedialog.h \
src/models/appconfiguration.h \
src/models/note.h \
src/models/folder.h \
src/services/savemanager.h
FORMS += \
src/frames/configdialog.ui \
src/frames/exportdialog.ui \
src/frames/renamedialog.ui \
src/frames/aboutdialog.ui \
src/frames/createdialog.ui \
src/frames/mainwindow.ui \
src/frames/movedialog.ui

View File

@@ -1,10 +1,10 @@
<RCC>
<qresource prefix="/icon">
<file>resources/outline_delete_forever_black_48dp.png</file>
<file>resources/outline_help_outline_black_48dp.png</file>
<file>resources/outline_save_black_48dp.png</file>
<file>resources/new_file.png</file>
<file>resources/new_folder.png</file>
<file>resources/settings.png</file>
</qresource>
<qresource prefix="/logo">
<file>resources/logo.png</file>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

BIN
resources/settings.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 887 B

View File

@@ -1,16 +0,0 @@
#include "aboutdialog.h"
#include "ui_aboutdialog.h"
AboutDialog::AboutDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AboutDialog)
{
ui->setupUi(this);
ui->appNameLabel->setText(QString("%1 (%2)").arg(APP_NAME, APP_ARCH));
ui->versionLabel->setText(QString("Version %1").arg(APP_VERSION));
}
AboutDialog::~AboutDialog()
{
delete ui;
}

View File

@@ -1,23 +0,0 @@
#ifndef ABOUTDIALOG_H
#define ABOUTDIALOG_H
#include <QDialog>
#include <QSysInfo>
namespace Ui {
class AboutDialog;
}
class AboutDialog : public QDialog
{
Q_OBJECT
public:
explicit AboutDialog(QWidget *parent = nullptr);
~AboutDialog();
private:
Ui::AboutDialog *ui;
};
#endif // ABOUTDIALOG_H

View File

@@ -1,100 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AboutDialog</class>
<widget class="QDialog" name="AboutDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>334</width>
<height>180</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>334</width>
<height>180</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>334</width>
<height>180</height>
</size>
</property>
<property name="windowTitle">
<string>About WorkPad</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>0</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>64</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">image: url(:/logo/resources/logo.png);</string>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="appNameLabel">
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>WorkPad</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="versionLabel">
<property name="text">
<string>Version 1.2.0.0</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Author: Aurélie Delhaie (aureliedelhaie.fr)</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,45 @@
#include "configdialog.h"
#include "ui_configdialog.h"
ConfigDialog::ConfigDialog(AppConfiguration *cfg, QWidget *parent) :
QDialog(parent),
ui(new Ui::ConfigDialog)
{
ui->setupUi(this);
ui->appNameLabel->setText(QString("%1 (%2)").arg(APP_NAME, APP_ARCH));
ui->versionLabel->setText(QString("Version %1").arg(APP_VERSION));
this->cfg = cfg;
applyCfg();
connect(ui->autoSaveEnableCheckbox, &QCheckBox::stateChanged, this, &ConfigDialog::autoSaveEnableChange);
connect(ui->autoSaveDelaySpinbox, &QSpinBox::valueChanged, this, &ConfigDialog::autoSaveDelayChange);
}
ConfigDialog::~ConfigDialog()
{
delete ui;
}
void ConfigDialog::autoSaveEnableChange(int state)
{
if (state == Qt::CheckState::Checked)
{
cfg->setEnableAutoSave(true);
}
else
{
cfg->setEnableAutoSave(false);
}
}
void ConfigDialog::autoSaveDelayChange(int value)
{
cfg->setAutoSaveDelay(value);
}
void ConfigDialog::applyCfg()
{
ui->autoSaveEnableCheckbox->setCheckState(cfg->isEnableAutoSave() ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
ui->autoSaveDelaySpinbox->setValue(cfg->getAutoSaveDelay());
}

31
src/frames/configdialog.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef CONFIGDIALOG_H
#define CONFIGDIALOG_H
#include <QDialog>
#include "../models/appconfiguration.h"
namespace Ui {
class ConfigDialog;
}
class ConfigDialog : public QDialog
{
Q_OBJECT
public:
explicit ConfigDialog(AppConfiguration *cfg, QWidget *parent = nullptr);
~ConfigDialog();
private slots:
void autoSaveEnableChange(int);
void autoSaveDelayChange(int);
private:
Ui::ConfigDialog *ui;
AppConfiguration *cfg;
void applyCfg();
};
#endif // CONFIGDIALOG_H

296
src/frames/configdialog.ui Normal file
View File

@@ -0,0 +1,296 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigDialog</class>
<widget class="QDialog" name="ConfigDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>612</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>612</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>400</width>
<height>612</height>
</size>
</property>
<property name="windowTitle">
<string>Configuration</string>
</property>
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>381</width>
<height>561</height>
</rect>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>General</string>
</attribute>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>361</width>
<height>17</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Auto save</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>51</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Enable</string>
</property>
</widget>
<widget class="QCheckBox" name="autoSaveEnableCheckbox">
<property name="geometry">
<rect>
<x>360</x>
<y>45</y>
<width>31</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>56</x>
<y>56</y>
<width>231</width>
<height>16</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>10</x>
<y>81</y>
<width>71</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Delay (ms.)</string>
</property>
</widget>
<widget class="Line" name="line_2">
<property name="geometry">
<rect>
<x>76</x>
<y>84</y>
<width>211</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QSpinBox" name="autoSaveDelaySpinbox">
<property name="geometry">
<rect>
<x>291</x>
<y>71</y>
<width>81</width>
<height>26</height>
</rect>
</property>
<property name="minimum">
<number>500</number>
</property>
<property name="maximum">
<number>900000000</number>
</property>
<property name="value">
<number>1000</number>
</property>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>About</string>
</attribute>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>7</x>
<y>321</y>
<width>314</width>
<height>26</height>
</rect>
</property>
<property name="text">
<string>Author: Aurélie Delhaie (github.com/mojitaurelie)</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QLabel" name="versionLabel">
<property name="geometry">
<rect>
<x>7</x>
<y>290</y>
<width>314</width>
<height>26</height>
</rect>
</property>
<property name="text">
<string>Version 1.2.0.0</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QLabel" name="appNameLabel">
<property name="geometry">
<rect>
<x>3</x>
<y>229</y>
<width>371</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="text">
<string>WorkPad</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>8</x>
<y>10</y>
<width>360</width>
<height>201</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">image: url(:/logo/resources/logo.png);</string>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>7</x>
<y>353</y>
<width>314</width>
<height>26</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Under MIT license&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="geometry">
<rect>
<x>9</x>
<y>380</y>
<width>361</width>
<height>141</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="plainText">
<string>Copyright 2022 Aurélie Delhaie
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &quot;Software&quot;), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</string>
</property>
</widget>
</widget>
</widget>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>225</x>
<y>578</y>
<width>166</width>
<height>25</height>
</rect>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ConfigDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>307</x>
<y>590</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>305</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,23 @@
#include "exportdialog.h"
#include "ui_exportdialog.h"
ExportDialog::ExportDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ExportDialog)
{
ui->setupUi(this);
}
ExportDialog::~ExportDialog()
{
delete ui;
}
int ExportDialog::getResult()
{
if (ui->markdownButton->isChecked())
{
return MARKDOWN;
}
return PLAIN;
}

26
src/frames/exportdialog.h Normal file
View File

@@ -0,0 +1,26 @@
#ifndef EXPORTDIALOG_H
#define EXPORTDIALOG_H
#include <QDialog>
#define MARKDOWN 1
#define PLAIN 2
namespace Ui {
class ExportDialog;
}
class ExportDialog : public QDialog
{
Q_OBJECT
public:
explicit ExportDialog(QWidget *parent = nullptr);
~ExportDialog();
int getResult();
private:
Ui::ExportDialog *ui;
};
#endif // EXPORTDIALOG_H

109
src/frames/exportdialog.ui Normal file
View File

@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExportDialog</class>
<widget class="QDialog" name="ExportDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>223</width>
<height>138</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>223</width>
<height>138</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>223</width>
<height>138</height>
</size>
</property>
<property name="windowTitle">
<string>Export</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>0</x>
<y>100</y>
<width>211</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QRadioButton" name="markdownButton">
<property name="geometry">
<rect>
<x>30</x>
<y>20</y>
<width>171</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Markdown file</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QRadioButton" name="plainTextRadio">
<property name="geometry">
<rect>
<x>30</x>
<y>60</y>
<width>92</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Text file</string>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ExportDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ExportDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -1,10 +1,11 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "aboutdialog.h"
#include "configdialog.h"
#include "createdialog.h"
#include "movedialog.h"
#include "renamedialog.h"
#include "exportdialog.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
@@ -15,7 +16,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->actionAdd_folder, &QAction::triggered, this, &MainWindow::createFolder);
connect(ui->actionAdd, &QAction::triggered, this, &MainWindow::createNote);
connect(ui->actionSave, &QAction::triggered, this, &MainWindow::save);
connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::showAboutBox);
connect(ui->actionSettings, &QAction::triggered, this, &MainWindow::showSettingsBox);
connect(ui->contentEdit, &QPlainTextEdit::textChanged, this, &MainWindow::markdownContentChanged);
connect(ui->plainTextEdit, &QPlainTextEdit::textChanged, this, &MainWindow::plainContentChanged);
connect(ui->treeWidget, &QTreeWidget::itemSelectionChanged, this, &MainWindow::selectionChanged);
@@ -25,6 +26,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->plainTextEdit->setFont(fixedFont);
ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
this->savemng = new SaveManager();
this->cfgmng = new ConfigManager();
updateListView();
connect(timer, &QTimer::timeout, this, &MainWindow::save);
}
@@ -122,11 +124,12 @@ void MainWindow::save()
this->savemng->flushSave();
}
void MainWindow::showAboutBox()
void MainWindow::showSettingsBox()
{
AboutDialog dialog;
ConfigDialog dialog(cfgmng->getConfiguration(), this);
dialog.setModal(true);
dialog.exec();
cfgmng->writeToDisk();
}
void MainWindow::prepareMenu(const QPoint &pos)
@@ -146,6 +149,9 @@ void MainWindow::prepareMenu(const QPoint &pos)
QAction *moveAction = new QAction(tr("Move to..."), this);
connect(moveAction, &QAction::triggered, this, &MainWindow::moveNote);
menu.addAction(moveAction);
QAction *exportAction = new QAction(tr("Export"), this);
connect(exportAction, &QAction::triggered, this, &MainWindow::exportNote);
menu.addAction(exportAction);
}
menu.exec(ui->treeWidget->mapToGlobal(pos));
}
@@ -156,6 +162,9 @@ void MainWindow::deleteItem()
if (ui->treeWidget->selectedItems().length() == 1) {
QTreeWidgetItem *item = ui->treeWidget->selectedItems()[0];
QString uuid = item->text(COLUMN_UUID);
QMessageBox::StandardButton res = QMessageBox::question(this, tr("Remove"), QString("Do you want to remove '%1'?").arg(item->text(COLUMN_NAME)));
if (res == QMessageBox::Yes)
{
if (item->text(COLUMN_TYPE) == TYPE_NOTE)
{
QString uuidFolder = item->parent()->text(COLUMN_UUID);
@@ -189,6 +198,7 @@ void MainWindow::deleteItem()
updateListView();
}
}
}
void MainWindow::moveNote()
{
@@ -276,6 +286,51 @@ void MainWindow::editName()
}
}
void MainWindow::exportNote()
{
if (ui->treeWidget->selectedItems().length() == 1) {
QTreeWidgetItem *item = ui->treeWidget->selectedItems()[0];
if (item->text(COLUMN_TYPE) == TYPE_NOTE)
{
Note *n = savemng->getNoteByUUID(item->text(COLUMN_UUID));
if (n == nullptr)
{
QMessageBox::critical(this, tr("WorkPad"), "The note is not found", QMessageBox::Ok, QMessageBox::Ok);
return;
}
ExportDialog d(this);
if (d.exec() == QDialog::Accepted)
{
int fileType = d.getResult();
QString filter = "Plain text file (*.txt)";
if (fileType == MARKDOWN)
{
filter = "Markdown file (*.md)";
}
QString fileName = QFileDialog::getSaveFileName(this, tr("Export note"), "", filter);
if (!fileName.isEmpty())
{
if (fileType == MARKDOWN && !fileName.endsWith(".md", Qt::CaseInsensitive))
{
fileName += ".md";
}
else if (fileType == PLAIN && !fileName.endsWith(".txt", Qt::CaseInsensitive))
{
fileName += ".txt";
}
QFile *f = new QFile(fileName);
if (f->open(QIODevice::WriteOnly))
{
f->write(n->getContent().toUtf8());
f->close();
}
delete f;
}
}
}
}
}
void MainWindow::markdownContentChanged()
{
timer->stop();
@@ -286,8 +341,14 @@ void MainWindow::markdownContentChanged()
QString uuid = ui->treeWidget->selectedItems()[0]->text(COLUMN_UUID);
Note *n = savemng->getNoteByUUID(uuid);
if (n != nullptr) {
QScrollBar *scrollbar = ui->markdownViewer->verticalScrollBar();
QString content = ui->contentEdit->toPlainText();
int pos = scrollbar->sliderPosition();
ui->markdownViewer->setMarkdown(content);
scrollbar->setSliderPosition(pos);
ui->markdownViewer2->setMarkdown(content);
ui->plainTextEdit->setPlainText(content);
n->setContent(content);
@@ -296,7 +357,10 @@ void MainWindow::markdownContentChanged()
ui->plainTextEdit->blockSignals(false);
ui->contentEdit->blockSignals(false);
ui->actionSave->setDisabled(false);
timer->start(1000);
if (cfgmng->getConfiguration()->isEnableAutoSave())
{
timer->start(cfgmng->getConfiguration()->getAutoSaveDelay());
}
}
void MainWindow::plainContentChanged()
@@ -319,7 +383,10 @@ void MainWindow::plainContentChanged()
ui->plainTextEdit->blockSignals(false);
ui->contentEdit->blockSignals(false);
ui->actionSave->setDisabled(false);
timer->start(1000);
if (cfgmng->getConfiguration()->isEnableAutoSave())
{
timer->start(cfgmng->getConfiguration()->getAutoSaveDelay());
}
}
void MainWindow::updateListView()

View File

@@ -8,8 +8,11 @@
#include <QTreeWidgetItem>
#include <QMenu>
#include <QPoint>
#include <QFileDialog>
#include <QScrollBar>
#include "../services/savemanager.h"
#include "../services/configmanager.h"
#define COLUMN_NAME 0
#define COLUMN_UUID 1
@@ -37,15 +40,17 @@ private slots:
void save();
void markdownContentChanged();
void plainContentChanged();
void showAboutBox();
void showSettingsBox();
void prepareMenu(const QPoint &pos);
void deleteItem();
void moveNote();
void editName();
void exportNote();
private:
Ui::MainWindow *ui;
SaveManager *savemng;
ConfigManager *cfgmng;
QTimer *timer;
void updateListView();

View File

@@ -56,6 +56,18 @@
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="titleLabel">
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
@@ -72,30 +84,18 @@
<string>Plain text</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<item row="2" column="0">
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="titleLabel">
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Mardown editor</string>
<string>Markdown editor</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
@@ -214,7 +214,7 @@
<addaction name="separator"/>
<addaction name="actionSave"/>
<addaction name="separator"/>
<addaction name="actionAbout"/>
<addaction name="actionSettings"/>
</widget>
<action name="actionAdd">
<property name="enabled">
@@ -249,13 +249,16 @@
<string>Ctrl+S</string>
</property>
</action>
<action name="actionAbout">
<action name="actionSettings">
<property name="icon">
<iconset resource="../../icons.qrc">
<normaloff>:/icon/resources/outline_help_outline_black_48dp.png</normaloff>:/icon/resources/outline_help_outline_black_48dp.png</iconset>
<normaloff>:/icon/resources/settings.png</normaloff>:/icon/resources/settings.png</iconset>
</property>
<property name="text">
<string>About</string>
<string>Settings</string>
</property>
<property name="toolTip">
<string>Settings</string>
</property>
</action>
<action name="actionAdd_folder">

View File

@@ -23,7 +23,7 @@
</size>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Move note</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">

View File

@@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Rename</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">

View File

@@ -0,0 +1,43 @@
#include "appconfiguration.h"
AppConfiguration::AppConfiguration()
{
this->enableAutoSave = true;
this->autoSaveDelay = 1000;
}
AppConfiguration::AppConfiguration(QJsonObject obj)
{
this->enableAutoSave = obj[ENABLEAUTOSAVEKEY].toBool(true);
this->autoSaveDelay = obj[AUTOSAVEDELAY].toInt(1000);
}
QJsonObject AppConfiguration::toJson()
{
QJsonObject obj;
obj[ENABLEAUTOSAVEKEY] = this->enableAutoSave;
obj[AUTOSAVEDELAY] = this->autoSaveDelay;
return obj;
}
bool AppConfiguration::isEnableAutoSave()
{
return enableAutoSave;
}
int AppConfiguration::getAutoSaveDelay()
{
return autoSaveDelay;
}
void AppConfiguration::setEnableAutoSave(bool value)
{
this->enableAutoSave = value;
}
void AppConfiguration::setAutoSaveDelay(int value)
{
this->autoSaveDelay = value;
}

View File

@@ -0,0 +1,27 @@
#ifndef APPCONFIGURATION_H
#define APPCONFIGURATION_H
#define ENABLEAUTOSAVEKEY "enable_auto_save"
#define AUTOSAVEDELAY "auto_save_delay"
#include <QJsonObject>
class AppConfiguration
{
private:
bool enableAutoSave;
int autoSaveDelay;
public:
AppConfiguration();
AppConfiguration(QJsonObject obj);
QJsonObject toJson();
bool isEnableAutoSave();
int getAutoSaveDelay();
void setEnableAutoSave(bool);
void setAutoSaveDelay(int);
};
#endif // APPCONFIGURATION_H

View File

@@ -0,0 +1,62 @@
#include "configmanager.h"
ConfigManager::ConfigManager()
{
load();
}
ConfigManager::~ConfigManager()
{
delete cfg;
}
AppConfiguration *ConfigManager::getConfiguration()
{
return cfg;
}
QString ConfigManager::getSaveFilePath() {
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
if (!QDir(path).exists())
{
QDir().mkpath(path);
}
path += "/data/";
if (!QDir(path).exists())
{
QDir().mkpath(path);
}
path += FILENAME;
return QDir::cleanPath(path);
}
void ConfigManager::load() {
QFile* file = new QFile(getSaveFilePath());
if (!file->open(QIODevice::ReadOnly))
{
delete file;
this->cfg = new AppConfiguration();
writeToDisk();
return;
}
auto json = QString(file->readAll());
file->close();
delete file;
QJsonObject obj = QJsonDocument::fromJson(json.toUtf8()).object();
this->cfg = new AppConfiguration(obj);
return;
}
void ConfigManager::writeToDisk()
{
QJsonDocument doc(cfg->toJson());
QFile *f = new QFile(getSaveFilePath());
if (f->open(QIODevice::WriteOnly))
{
f->write(doc.toJson());
f->close();
}
delete f;
}

View File

@@ -0,0 +1,29 @@
#ifndef CONFIGMANAGER_H
#define CONFIGMANAGER_H
#define FILENAME "config.json"
#include <QJsonDocument>
#include <QJsonObject>
#include <QStandardPaths>
#include <QString>
#include <QDir>
#include "../models/appconfiguration.h"
class ConfigManager
{
private:
QString getSaveFilePath();
void load();
AppConfiguration *cfg;
public:
ConfigManager();
~ConfigManager();
AppConfiguration *getConfiguration();
void writeToDisk();
};
#endif // CONFIGMANAGER_H