Add export, fix scrollbar, fix dialog name

This commit is contained in:
Aurélie Delhaie
2022-11-04 22:51:12 +01:00
parent 7b17dfb044
commit 3626ffa54e
9 changed files with 267 additions and 44 deletions

View File

@@ -4,8 +4,8 @@ greaterThan(QT_MAJOR_VERSION, 5): QT += widgets
CONFIG += c++17 CONFIG += c++17
win32:VERSION = 2.0.0.0 # major.minor.patch.build win32:VERSION = 2.1.0.0 # major.minor.patch.build
else:VERSION = 2.0.0 # major.minor.patch else:VERSION = 2.1.0 # major.minor.patch
DEFINES += APP_VERSION=\"\\\"$${VERSION}\\\"\" DEFINES += APP_VERSION=\"\\\"$${VERSION}\\\"\"
DEFINES += APP_NAME=\"\\\"WorkPad\\\"\" DEFINES += APP_NAME=\"\\\"WorkPad\\\"\"
@@ -69,6 +69,7 @@ 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/exportdialog.cpp \
src/frames/renamedialog.cpp \ src/frames/renamedialog.cpp \
src/frames/aboutdialog.cpp \ src/frames/aboutdialog.cpp \
src/frames/createdialog.cpp \ src/frames/createdialog.cpp \
@@ -80,6 +81,7 @@ SOURCES += \
src/services/savemanager.cpp src/services/savemanager.cpp
HEADERS += \ HEADERS += \
src/frames/exportdialog.h \
src/frames/renamedialog.h \ src/frames/renamedialog.h \
src/frames/aboutdialog.h \ src/frames/aboutdialog.h \
src/frames/createdialog.h \ src/frames/createdialog.h \
@@ -90,6 +92,7 @@ HEADERS += \
src/services/savemanager.h src/services/savemanager.h
FORMS += \ FORMS += \
src/frames/exportdialog.ui \
src/frames/renamedialog.ui \ src/frames/renamedialog.ui \
src/frames/aboutdialog.ui \ src/frames/aboutdialog.ui \
src/frames/createdialog.ui \ src/frames/createdialog.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

@@ -5,6 +5,7 @@
#include "createdialog.h" #include "createdialog.h"
#include "movedialog.h" #include "movedialog.h"
#include "renamedialog.h" #include "renamedialog.h"
#include "exportdialog.h"
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
@@ -124,7 +125,7 @@ void MainWindow::save()
void MainWindow::showAboutBox() void MainWindow::showAboutBox()
{ {
AboutDialog dialog; AboutDialog dialog(this);
dialog.setModal(true); dialog.setModal(true);
dialog.exec(); dialog.exec();
} }
@@ -146,6 +147,9 @@ void MainWindow::prepareMenu(const QPoint &pos)
QAction *moveAction = new QAction(tr("Move to..."), this); QAction *moveAction = new QAction(tr("Move to..."), this);
connect(moveAction, &QAction::triggered, this, &MainWindow::moveNote); connect(moveAction, &QAction::triggered, this, &MainWindow::moveNote);
menu.addAction(moveAction); 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)); menu.exec(ui->treeWidget->mapToGlobal(pos));
} }
@@ -156,37 +160,41 @@ void MainWindow::deleteItem()
if (ui->treeWidget->selectedItems().length() == 1) { if (ui->treeWidget->selectedItems().length() == 1) {
QTreeWidgetItem *item = ui->treeWidget->selectedItems()[0]; QTreeWidgetItem *item = ui->treeWidget->selectedItems()[0];
QString uuid = item->text(COLUMN_UUID); QString uuid = item->text(COLUMN_UUID);
if (item->text(COLUMN_TYPE) == TYPE_NOTE) QMessageBox::StandardButton res = QMessageBox::question(this, tr("Remove"), QString("Do you want to remove '%1'?").arg(item->text(COLUMN_NAME)));
if (res == QMessageBox::Yes)
{ {
QString uuidFolder = item->parent()->text(COLUMN_UUID); if (item->text(COLUMN_TYPE) == TYPE_NOTE)
Note *n = savemng->getNoteByUUID(uuid);
if (n == nullptr)
{ {
return; 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;
} }
if (!savemng->removeNote(uuidFolder, uuid)) else
{ {
QMessageBox::critical(this, tr("WorkPad"), "Failed to remove this note", QMessageBox::Ok, QMessageBox::Ok); Folder *f = savemng->getFolderByUUID(uuid);
return; 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;
} }
delete n; savemng->flushSave();
updateListView();
} }
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();
} }
} }
@@ -276,6 +284,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() void MainWindow::markdownContentChanged()
{ {
timer->stop(); timer->stop();
@@ -286,8 +339,14 @@ void MainWindow::markdownContentChanged()
QString uuid = ui->treeWidget->selectedItems()[0]->text(COLUMN_UUID); QString uuid = ui->treeWidget->selectedItems()[0]->text(COLUMN_UUID);
Note *n = savemng->getNoteByUUID(uuid); Note *n = savemng->getNoteByUUID(uuid);
if (n != nullptr) { if (n != nullptr) {
QScrollBar *scrollbar = ui->markdownViewer->verticalScrollBar();
QString content = ui->contentEdit->toPlainText(); QString content = ui->contentEdit->toPlainText();
int pos = scrollbar->sliderPosition();
ui->markdownViewer->setMarkdown(content); ui->markdownViewer->setMarkdown(content);
scrollbar->setSliderPosition(pos);
ui->markdownViewer2->setMarkdown(content); ui->markdownViewer2->setMarkdown(content);
ui->plainTextEdit->setPlainText(content); ui->plainTextEdit->setPlainText(content);
n->setContent(content); n->setContent(content);

View File

@@ -8,6 +8,8 @@
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include <QMenu> #include <QMenu>
#include <QPoint> #include <QPoint>
#include <QFileDialog>
#include <QScrollBar>
#include "../services/savemanager.h" #include "../services/savemanager.h"
@@ -42,6 +44,7 @@ private slots:
void deleteItem(); void deleteItem();
void moveNote(); void moveNote();
void editName(); void editName();
void exportNote();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;

View File

@@ -56,6 +56,18 @@
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout"> <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> <item>
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="tabPosition"> <property name="tabPosition">
@@ -72,30 +84,18 @@
<string>Plain text</string> <string>Plain text</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0"> <item row="2" column="0">
<widget class="QPlainTextEdit" name="plainTextEdit"> <widget class="QPlainTextEdit" name="plainTextEdit">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
<string>Mardown editor</string> <string>Markdown editor</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0"> <item row="0" column="0">

View File

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

View File

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