From 6d5b9ba008bba20f1c0a1642af5f5b7182f3e890 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 17 Mar 2016 13:36:07 +0100 Subject: 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 --- .../markdowneditor/doc/src/markdowneditor.qdoc | 3 ++- .../webenginewidgets/markdowneditor/mainwindow.cpp | 25 ++++++++++++++-------- .../webenginewidgets/markdowneditor/mainwindow.h | 2 ++ 3 files changed, 20 insertions(+), 10 deletions(-) (limited to 'examples') diff --git a/examples/webenginewidgets/markdowneditor/doc/src/markdowneditor.qdoc b/examples/webenginewidgets/markdowneditor/doc/src/markdowneditor.qdoc index ddea067b7..5a599a1b2 100644 --- a/examples/webenginewidgets/markdowneditor/doc/src/markdowneditor.qdoc +++ b/examples/webenginewidgets/markdowneditor/doc/src/markdowneditor.qdoc @@ -116,7 +116,8 @@ \printto connect The constructor first calls \c setupUi to construct the widgets and menu - actions according to the UI file. It then makes sure our custom + actions according to the UI file. The text editor font is set to one + with a fixed character width. It then makes sure our custom \c PreviewPage is used by the QWebEngineView instance in \c{ui->preview}. \printto ui->preview 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 #include +#include #include #include #include @@ -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() diff --git a/examples/webenginewidgets/markdowneditor/mainwindow.h b/examples/webenginewidgets/markdowneditor/mainwindow.h index 596b5c504..fc04f6beb 100644 --- a/examples/webenginewidgets/markdowneditor/mainwindow.h +++ b/examples/webenginewidgets/markdowneditor/mainwindow.h @@ -59,6 +59,8 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + void openFile(const QString &path); + private slots: void onFileNew(); void onFileOpen(); -- cgit v1.2.3