This repository was archived by the owner on Feb 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
115 lines (95 loc) · 2.94 KB
/
MainWindow.cpp
File metadata and controls
115 lines (95 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "Config.h"
#include <QTimer>
#include <QDebug>
#include <QIcon>
#include <QAction>
#include <QFileDialog>
extern "C" {
#include <mkdio.h>
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->ui->textBrowser_2->setVisible(false);
this->showMaximized();
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateMkd()));
timer->start(500);
this->initToolbar(this->ui->mainToolBar);
}
void MainWindow::initToolbar(QToolBar *toolBar)
{
QAction *refresh = new QAction(QIcon::fromTheme("view-refresh"), tr("&refresh"), this);
QAction *open = new QAction(QIcon::fromTheme("document-open"), tr("&open"), this);
QAction *save = new QAction(QIcon::fromTheme("document-save"), tr("&save"), this);
QAction *newFile = new QAction(QIcon::fromTheme("document-new"), tr("&new"), this);
toolBar->addAction(open);
toolBar->addAction(save);
toolBar->addAction(newFile);
toolBar->addAction(refresh);
connect(open, SIGNAL(triggered()), this, SLOT(openFile()));
connect(save, SIGNAL(triggered()), this, SLOT(saveFile()));
#ifdef DEBUG
QAction *tglDebug = new QAction("debug", this);
toolBar->addAction(tglDebug);
// connect
connect(tglDebug, SIGNAL(triggered()), this, SLOT(on_actionHide_Debug_triggered()));
#endif
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::openFile()
{
QString path = QFileDialog::getOpenFileName(this, "Datei öffnen", QDir::homePath());
if(!(path.isNull() || path.isEmpty())) {
QFile fp(path);
fp.open(QFile::ReadOnly);
this->ui->plainTextEdit->setPlainText(QString::fromLocal8Bit(fp.readAll()));
} else {
qDebug() << path;
}
}
void MainWindow::saveFile()
{
QString path = QFileDialog::getSaveFileName(this, "Datei speichern", QDir::homePath());
if(!(path.isNull() || path.isEmpty())) {
QFile fp(path);
fp.open(QFile::WriteOnly | QFile::Truncate);
QString text = this->ui->plainTextEdit->toPlainText();
fp.write(text.toLocal8Bit());
} else {
qDebug() << path;
}
}
void MainWindow::updateMkd()
{
QString input = this->ui->plainTextEdit->toPlainText();
char *in = strdup(input.toAscii().data());
#ifdef _MKDIO_D
MMIOT *mkd = mkd_string(in, input.length(), MKD_AUTOLINK);
mkd_compile(mkd, MKD_AUTOLINK);
char *out = NULL;
mkd_document(mkd, &out);
this->ui->textBrowser->setHtml(QString::fromLocal8Bit(out));
#endif
this->ui->textBrowser_2->setPlainText(QString::fromAscii(in)); // DEBUG
free(in);
}
void MainWindow::on_actionRefresh_2_triggered()
{
this->updateMkd();
}
void MainWindow::on_pushButton_clicked()
{
this->updateMkd();
}
void MainWindow::on_actionHide_Debug_triggered()
{
this->ui->textBrowser_2->setVisible(!this->ui->textBrowser_2->isVisible());
}