diff options
author | Kai Koehne <kai.koehne@theqtcompany.com> | 2016-03-17 13:36:07 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2016-03-18 14:46:04 +0000 |
commit | 6d5b9ba008bba20f1c0a1642af5f5b7182f3e890 (patch) | |
tree | e351ef52c3888dca7be3cbe382edc613e4f13e5e /examples/webenginewidgets/markdowneditor/mainwindow.cpp | |
parent | a4175559acdef0f22203ce31486df626cee9d6fc (diff) |
Make MarkDownEditor example more usable
- Use a fixed width font for the editor.
- Accept .md file as command line argument.
Change-Id: I97e3bb930569240e195ecc21ed4ce3d9acd3ff66
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Diffstat (limited to 'examples/webenginewidgets/markdowneditor/mainwindow.cpp')
-rw-r--r-- | examples/webenginewidgets/markdowneditor/mainwindow.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/examples/webenginewidgets/markdowneditor/mainwindow.cpp b/examples/webenginewidgets/markdowneditor/mainwindow.cpp index 352b7944a..3c6705686 100644 --- a/examples/webenginewidgets/markdowneditor/mainwindow.cpp +++ b/examples/webenginewidgets/markdowneditor/mainwindow.cpp @@ -43,6 +43,7 @@ #include <QFile> #include <QFileDialog> +#include <QFontDatabase> #include <QMessageBox> #include <QTextStream> #include <QWebChannel> @@ -52,6 +53,7 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { ui->setupUi(this); + ui->editor->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); PreviewPage *page = new PreviewPage(this); ui->preview->setPage(page); @@ -84,6 +86,19 @@ MainWindow::~MainWindow() delete ui; } +void MainWindow::openFile(const QString &path) +{ + QFile f(path); + if (!f.open(QIODevice::ReadOnly)) { + QMessageBox::warning(this, windowTitle(), + tr("Could not open file %1: %2").arg( + QDir::toNativeSeparators(path), f.errorString())); + return; + } + m_filePath = path; + ui->editor->setPlainText(f.readAll()); +} + bool MainWindow::isModified() const { return ui->editor->document()->isModified(); @@ -117,15 +132,7 @@ void MainWindow::onFileOpen() if (path.isEmpty()) return; - QFile f(path); - if (!f.open(QIODevice::ReadOnly)) { - QMessageBox::warning(this, windowTitle(), - tr("Could not open file %1: %2").arg( - QDir::toNativeSeparators(path), f.errorString())); - return; - } - m_filePath = path; - ui->editor->setPlainText(f.readAll()); + openFile(path); } void MainWindow::onFileSave() |