summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2016-03-17 13:36:07 +0100
committerKai Koehne <kai.koehne@theqtcompany.com>2016-03-18 14:46:04 +0000
commit6d5b9ba008bba20f1c0a1642af5f5b7182f3e890 (patch)
treee351ef52c3888dca7be3cbe382edc613e4f13e5e /examples
parenta4175559acdef0f22203ce31486df626cee9d6fc (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')
-rw-r--r--examples/webenginewidgets/markdowneditor/doc/src/markdowneditor.qdoc3
-rw-r--r--examples/webenginewidgets/markdowneditor/mainwindow.cpp25
-rw-r--r--examples/webenginewidgets/markdowneditor/mainwindow.h2
3 files changed, 20 insertions, 10 deletions
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 <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()
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();