-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
72 lines (64 loc) · 1.96 KB
/
mainwindow.cpp
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
#include <QtCore>
#include <QFile>
#include <QDir>
#include <QFileInfo>
#include <QStandardPaths>
#include <QtWebKitWidgets>
#include <QDebug>
extern "C" {
#include <mkdio.h>
#include <stdio.h>
#include <errno.h>
#include <libgen.h>
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->statusBar->hide();
//コマンドライン引数を取得
QStringList argList = QCoreApplication::arguments();
if (argList.size() == 2) {
//Cのライブラリを用いるのでパスを変換
QString path = argList.at(1);
QByteArray ba = path.toUtf8();
FILE* fp = fopen(ba.data(), "r");
if (fp == NULL) {
perror(ba.data());
}
MMIOT* doc = mkd_in(fp, 0);
mkd_compile(doc, 0);
char* text;
mkd_document(doc, &text);
QString html(text);
//デフォルトのCSSを取得
QString defaultCSS;
defaultCSS = QStandardPaths::locate(QStandardPaths::AppDataLocation, "styles.css");
//HTMLを整形
html = "<html><head>"
"<link href=\"" + defaultCSS + "\" rel=\"stylesheet\"/>"
"<meta charset=\"utf-8\">"
"</head><body>" + html + "</body></html>";
QFileInfo fileinfo(path);
QDir basedir = fileinfo.absoluteDir();
QString basepath = basedir.absolutePath();
QString previewPath = basepath + "/.preview.html";
QFile previewFile(previewPath);
if (!previewFile.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, "Error",
previewFile.errorString());
return;
}
QTextStream previewStream(&previewFile);
previewStream << html;
previewFile.close();
ui->webView->load(QUrl("file://" + previewPath));
}
}
MainWindow::~MainWindow()
{
delete ui;
}