add thread, export to pdf, new css
This commit is contained in:
@@ -7,7 +7,7 @@ CONFIG += c++17
|
||||
win32:VERSION = 3.0.0.0 # major.minor.patch.build
|
||||
else:VERSION = 3.0.0 # major.minor.patch
|
||||
|
||||
DEFINES += APP_VERSION=\"\\\"$${VERSION}-rc1\\\"\"
|
||||
DEFINES += APP_VERSION=\"\\\"$${VERSION}-rc2\\\"\"
|
||||
DEFINES += APP_NAME=\"\\\"WorkPad\\\"\"
|
||||
|
||||
# remove possible other optimization flags
|
||||
@@ -111,4 +111,5 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||
!isEmpty(target.path): INSTALLS += target
|
||||
|
||||
RESOURCES += \
|
||||
icons.qrc
|
||||
icons.qrc \
|
||||
static.qrc
|
||||
|
||||
1105
resources/style.css
Normal file
1105
resources/style.css
Normal file
File diff suppressed because it is too large
Load Diff
@@ -19,5 +19,9 @@ int ExportDialog::getResult()
|
||||
{
|
||||
return MARKDOWN;
|
||||
}
|
||||
else if (ui->pdfRadio->isChecked())
|
||||
{
|
||||
return PDF;
|
||||
}
|
||||
return PLAIN;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#define MARKDOWN 1
|
||||
#define PLAIN 2
|
||||
#define PDF 3
|
||||
|
||||
namespace Ui {
|
||||
class ExportDialog;
|
||||
|
||||
@@ -35,10 +35,10 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QRadioButton" name="markdownButton">
|
||||
@@ -61,7 +61,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>60</y>
|
||||
<y>40</y>
|
||||
<width>92</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
@@ -70,6 +70,19 @@
|
||||
<string>Text file</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QRadioButton" name="pdfRadio">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>60</y>
|
||||
<width>92</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PDF file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
||||
@@ -7,14 +7,22 @@
|
||||
#include "renamedialog.h"
|
||||
#include "exportdialog.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
timer = new QTimer(this);
|
||||
updateViewThread = nullptr;
|
||||
parser = std::make_shared<maddy::Parser>();
|
||||
|
||||
// open stylesheet resource
|
||||
QFile f(":/css/resources/style.css");
|
||||
f.open(QFile::OpenModeFlag::ReadOnly);
|
||||
style = f.readAll();
|
||||
f.close();
|
||||
|
||||
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);
|
||||
@@ -32,10 +40,39 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
this->cfgmng = new ConfigManager();
|
||||
updateListView();
|
||||
connect(timer, &QTimer::timeout, this, &MainWindow::save);
|
||||
|
||||
// start render thread
|
||||
threaddone = new bool(false);
|
||||
queue = new QVector<QString>;
|
||||
queueMutex = new QMutex();
|
||||
updateViewThread = new std::thread([this](){
|
||||
while (!*threaddone) {
|
||||
queueMutex->lock();
|
||||
if (queue->count() == 0) {
|
||||
queueMutex->unlock();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
continue;
|
||||
}
|
||||
QString content = (*queue)[0];
|
||||
queue->pop_front();
|
||||
queueMutex->unlock();
|
||||
std::stringstream markdownInput(content.toStdString());
|
||||
QString htmlOutput = "<html><body class='markdown-body'>";
|
||||
htmlOutput += QString::fromStdString(parser->Parse(markdownInput));
|
||||
htmlOutput += "</body><style>" + style + "</style></html>";
|
||||
emit updateViewers(htmlOutput);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
*threaddone = true;
|
||||
updateViewThread->join();
|
||||
delete queue;
|
||||
delete queueMutex;
|
||||
delete threaddone;
|
||||
delete updateViewThread;
|
||||
delete timer;
|
||||
delete savemng;
|
||||
delete ui;
|
||||
@@ -309,6 +346,10 @@ void MainWindow::exportNote()
|
||||
{
|
||||
filter = "Markdown file (*.md)";
|
||||
}
|
||||
else if (fileType == PDF)
|
||||
{
|
||||
filter = "PDF file (*.pdf)";
|
||||
}
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export note"), "", filter);
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
@@ -320,13 +361,27 @@ void MainWindow::exportNote()
|
||||
{
|
||||
fileName += ".txt";
|
||||
}
|
||||
QFile *f = new QFile(fileName);
|
||||
if (f->open(QIODevice::WriteOnly))
|
||||
else if (fileType == PDF && !fileName.endsWith(".pdf", Qt::CaseInsensitive))
|
||||
{
|
||||
f->write(n->getContent().toUtf8());
|
||||
f->close();
|
||||
fileName += ".pdf";
|
||||
}
|
||||
delete f;
|
||||
|
||||
if (fileType == PDF)
|
||||
{
|
||||
ui->webEngineViewer->printToPdf(fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
QFile *f = new QFile(fileName);
|
||||
if (f->open(QIODevice::WriteOnly))
|
||||
{
|
||||
|
||||
f->write(n->getContent().toUtf8());
|
||||
f->close();
|
||||
}
|
||||
delete f;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -413,19 +468,12 @@ void MainWindow::updateListView()
|
||||
|
||||
void MainWindow::updateHTMLView()
|
||||
{
|
||||
if (threadLock.tryLock()) {
|
||||
updateViewThread = new std::thread([this](){
|
||||
QString content = ui->plainTextEdit->toPlainText();
|
||||
std::stringstream markdownInput(content.toStdString());
|
||||
QString htmlOutput = QString::fromStdString(parser->Parse(markdownInput));
|
||||
emit updateViewers(htmlOutput);
|
||||
threadLock.unlock();
|
||||
});
|
||||
} else {
|
||||
QTimer::singleShot(200, [this]() {
|
||||
updateHTMLView();
|
||||
});
|
||||
queueMutex->lock();
|
||||
if (queue->count() > 4) {
|
||||
queue->pop_front();
|
||||
}
|
||||
queue->append(ui->plainTextEdit->toPlainText());
|
||||
queueMutex->unlock();
|
||||
}
|
||||
|
||||
void MainWindow::clearAndDisableFields()
|
||||
|
||||
@@ -61,9 +61,15 @@ private:
|
||||
SaveManager *savemng;
|
||||
ConfigManager *cfgmng;
|
||||
QTimer *timer;
|
||||
std::thread *updateViewThread;
|
||||
std::shared_ptr<maddy::Parser> parser;
|
||||
QMutex threadLock;
|
||||
|
||||
QString style;
|
||||
|
||||
//shared between threads
|
||||
QVector<QString>* queue;
|
||||
QMutex* queueMutex;
|
||||
bool* threaddone;
|
||||
std::thread *updateViewThread;
|
||||
|
||||
void updateListView();
|
||||
void clearAndDisableFields();
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
<enum>QTabWidget::TabShape::Rounded</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
|
||||
5
static.qrc
Normal file
5
static.qrc
Normal file
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/css">
|
||||
<file>resources/style.css</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
Reference in New Issue
Block a user