Add config dialog

This commit is contained in:
Aurélie Delhaie
2022-11-06 16:06:38 +01:00
parent c00dd40def
commit 8dd5892327
14 changed files with 389 additions and 152 deletions

View File

@@ -69,10 +69,10 @@ linux-* {
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \ SOURCES += \
src/frames/configdialog.cpp \
src/services/configmanager.cpp \ src/services/configmanager.cpp \
src/frames/exportdialog.cpp \ src/frames/exportdialog.cpp \
src/frames/renamedialog.cpp \ src/frames/renamedialog.cpp \
src/frames/aboutdialog.cpp \
src/frames/createdialog.cpp \ src/frames/createdialog.cpp \
src/frames/movedialog.cpp \ src/frames/movedialog.cpp \
src/main.cpp \ src/main.cpp \
@@ -83,10 +83,10 @@ SOURCES += \
src/services/savemanager.cpp src/services/savemanager.cpp
HEADERS += \ HEADERS += \
src/frames/configdialog.h \
src/services/configmanager.h \ src/services/configmanager.h \
src/frames/exportdialog.h \ src/frames/exportdialog.h \
src/frames/renamedialog.h \ src/frames/renamedialog.h \
src/frames/aboutdialog.h \
src/frames/createdialog.h \ src/frames/createdialog.h \
src/frames/mainwindow.h \ src/frames/mainwindow.h \
src/frames/movedialog.h \ src/frames/movedialog.h \
@@ -96,9 +96,9 @@ HEADERS += \
src/services/savemanager.h src/services/savemanager.h
FORMS += \ FORMS += \
src/frames/configdialog.ui \
src/frames/exportdialog.ui \ src/frames/exportdialog.ui \
src/frames/renamedialog.ui \ src/frames/renamedialog.ui \
src/frames/aboutdialog.ui \
src/frames/createdialog.ui \ src/frames/createdialog.ui \
src/frames/mainwindow.ui \ src/frames/mainwindow.ui \
src/frames/movedialog.ui src/frames/movedialog.ui

View File

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

@@ -1,7 +1,7 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "aboutdialog.h" #include "configdialog.h"
#include "createdialog.h" #include "createdialog.h"
#include "movedialog.h" #include "movedialog.h"
#include "renamedialog.h" #include "renamedialog.h"
@@ -16,7 +16,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->actionAdd_folder, &QAction::triggered, this, &MainWindow::createFolder); connect(ui->actionAdd_folder, &QAction::triggered, this, &MainWindow::createFolder);
connect(ui->actionAdd, &QAction::triggered, this, &MainWindow::createNote); connect(ui->actionAdd, &QAction::triggered, this, &MainWindow::createNote);
connect(ui->actionSave, &QAction::triggered, this, &MainWindow::save); 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->contentEdit, &QPlainTextEdit::textChanged, this, &MainWindow::markdownContentChanged);
connect(ui->plainTextEdit, &QPlainTextEdit::textChanged, this, &MainWindow::plainContentChanged); connect(ui->plainTextEdit, &QPlainTextEdit::textChanged, this, &MainWindow::plainContentChanged);
connect(ui->treeWidget, &QTreeWidget::itemSelectionChanged, this, &MainWindow::selectionChanged); connect(ui->treeWidget, &QTreeWidget::itemSelectionChanged, this, &MainWindow::selectionChanged);
@@ -124,11 +124,12 @@ void MainWindow::save()
this->savemng->flushSave(); this->savemng->flushSave();
} }
void MainWindow::showAboutBox() void MainWindow::showSettingsBox()
{ {
AboutDialog dialog(this); ConfigDialog dialog(cfgmng->getConfiguration(), this);
dialog.setModal(true); dialog.setModal(true);
dialog.exec(); dialog.exec();
cfgmng->writeToDisk();
} }
void MainWindow::prepareMenu(const QPoint &pos) void MainWindow::prepareMenu(const QPoint &pos)

View File

@@ -40,7 +40,7 @@ private slots:
void save(); void save();
void markdownContentChanged(); void markdownContentChanged();
void plainContentChanged(); void plainContentChanged();
void showAboutBox(); void showSettingsBox();
void prepareMenu(const QPoint &pos); void prepareMenu(const QPoint &pos);
void deleteItem(); void deleteItem();
void moveNote(); void moveNote();

View File

@@ -214,7 +214,7 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionSave"/> <addaction name="actionSave"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionAbout"/> <addaction name="actionSettings"/>
</widget> </widget>
<action name="actionAdd"> <action name="actionAdd">
<property name="enabled"> <property name="enabled">
@@ -249,13 +249,16 @@
<string>Ctrl+S</string> <string>Ctrl+S</string>
</property> </property>
</action> </action>
<action name="actionAbout"> <action name="actionSettings">
<property name="icon"> <property name="icon">
<iconset resource="../../icons.qrc"> <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>
<property name="text"> <property name="text">
<string>About</string> <string>Settings</string>
</property>
<property name="toolTip">
<string>Settings</string>
</property> </property>
</action> </action>
<action name="actionAdd_folder"> <action name="actionAdd_folder">