summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Montel <[email protected]>2018-03-05 23:08:57 +0100
committerLaurent Montel <[email protected]>2018-03-05 23:08:57 +0100
commit061ce03da806c00487d3667b298ebf5d9db7f6f7 (patch)
treeaf1adcffe7a37ebf0b2dc7b43271889fe2732d4e
parent5fe14fea0259c189693c2f709c6e0697eec809b6 (diff)
Continue to implement it
-rw-r--r--kmail/editorconvertertextplugins/markdown/autotests/markdownpreviewwidgettest.cpp10
-rw-r--r--kmail/editorconvertertextplugins/markdown/markdownpreviewwidget.cpp18
-rw-r--r--kmail/editorconvertertextplugins/markdown/markdownpreviewwidget.h6
-rw-r--r--kmail/editorconvertertextplugins/markdown/tests/CMakeLists.txt2
-rw-r--r--kmail/editorconvertertextplugins/markdown/tests/main.cpp4
-rw-r--r--kmail/editorconvertertextplugins/markdown/tests/markdowndemowidget.cpp46
-rw-r--r--kmail/editorconvertertextplugins/markdown/tests/markdowndemowidget.h39
7 files changed, 120 insertions, 5 deletions
diff --git a/kmail/editorconvertertextplugins/markdown/autotests/markdownpreviewwidgettest.cpp b/kmail/editorconvertertextplugins/markdown/autotests/markdownpreviewwidgettest.cpp
index 0fc4c46..615ff3d 100644
--- a/kmail/editorconvertertextplugins/markdown/autotests/markdownpreviewwidgettest.cpp
+++ b/kmail/editorconvertertextplugins/markdown/autotests/markdownpreviewwidgettest.cpp
@@ -19,8 +19,10 @@
#include "markdownpreviewwidgettest.h"
#include "markdownpreviewwidget.h"
+#include "markdowndocument.h"
#include <QHBoxLayout>
#include <QTest>
+#include <QWebChannel>
#include <QWebEngineView>
QTEST_MAIN(MarkdownPreviewWidgetTest)
@@ -40,4 +42,12 @@ void MarkdownPreviewWidgetTest::shouldHaveDefaultValue()
QWebEngineView *mWebView = w.findChild<QWebEngineView *>(QStringLiteral("webengine"));
QVERIFY(mWebView);
QCOMPARE(mWebView->contextMenuPolicy(), Qt::NoContextMenu);
+
+
+ MarkdownDocument *mDocument = w.findChild<MarkdownDocument *>(QStringLiteral("document"));
+ QVERIFY(mDocument);
+ QVERIFY(mDocument->text().isEmpty());
+
+ QWebChannel *channel = w.findChild<QWebChannel *>(QStringLiteral("webchannel"));
+ QVERIFY(channel);
}
diff --git a/kmail/editorconvertertextplugins/markdown/markdownpreviewwidget.cpp b/kmail/editorconvertertextplugins/markdown/markdownpreviewwidget.cpp
index 05aa41a..9e077f9 100644
--- a/kmail/editorconvertertextplugins/markdown/markdownpreviewwidget.cpp
+++ b/kmail/editorconvertertextplugins/markdown/markdownpreviewwidget.cpp
@@ -27,9 +27,10 @@ MarkdownPreviewWidget::MarkdownPreviewWidget(QWidget *parent)
: QWidget(parent)
{
mDocument = new MarkdownDocument(this);
+ mDocument->setObjectName(QStringLiteral("document"));
+
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->setObjectName(QStringLiteral("mainLayout"));
-
mainLayout->setMargin(0);
mWebView = new QWebEngineView(this);
@@ -38,12 +39,23 @@ MarkdownPreviewWidget::MarkdownPreviewWidget(QWidget *parent)
mWebView->setContextMenuPolicy(Qt::NoContextMenu);
QWebChannel *channel = new QWebChannel(this);
+ channel->setObjectName(QStringLiteral("webchannel"));
channel->registerObject(QStringLiteral("content"), mDocument);
- mWebView->page()->setWebChannel(channel);
-
+ mWebView->page()->setWebChannel(channel);
}
MarkdownPreviewWidget::~MarkdownPreviewWidget()
{
}
+
+void MarkdownPreviewWidget::slotUpdatePreview(const QString &text)
+{
+ mDocument->setText(text);
+}
+
+QString MarkdownPreviewWidget::saveHtml() const
+{
+ //TODO
+ return {};
+}
diff --git a/kmail/editorconvertertextplugins/markdown/markdownpreviewwidget.h b/kmail/editorconvertertextplugins/markdown/markdownpreviewwidget.h
index 3653988..02530cb 100644
--- a/kmail/editorconvertertextplugins/markdown/markdownpreviewwidget.h
+++ b/kmail/editorconvertertextplugins/markdown/markdownpreviewwidget.h
@@ -29,6 +29,12 @@ class MarkdownPreviewWidget : public QWidget
public:
explicit MarkdownPreviewWidget(QWidget *parent = nullptr);
~MarkdownPreviewWidget();
+
+ QString saveHtml() const;
+
+public Q_SLOTS:
+ void slotUpdatePreview(const QString &text);
+
private:
MarkdownDocument *mDocument = nullptr;
QWebEngineView *mWebView = nullptr;
diff --git a/kmail/editorconvertertextplugins/markdown/tests/CMakeLists.txt b/kmail/editorconvertertextplugins/markdown/tests/CMakeLists.txt
index 973c699..444f2a9 100644
--- a/kmail/editorconvertertextplugins/markdown/tests/CMakeLists.txt
+++ b/kmail/editorconvertertextplugins/markdown/tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-set(markdown_gui_SRCS main.cpp)
+set(markdown_gui_SRCS main.cpp markdowndemowidget.cpp ../markdownpreviewwidget.cpp ../markdowndocument.cpp)
add_executable(markdown_gui ${markdown_gui_SRCS})
target_link_libraries(markdown_gui
KF5::MessageComposer KF5::I18n KF5::XmlGui Qt5::WebEngineWidgets
diff --git a/kmail/editorconvertertextplugins/markdown/tests/main.cpp b/kmail/editorconvertertextplugins/markdown/tests/main.cpp
index 9025bb4..b338041 100644
--- a/kmail/editorconvertertextplugins/markdown/tests/main.cpp
+++ b/kmail/editorconvertertextplugins/markdown/tests/main.cpp
@@ -20,13 +20,15 @@
#include <QApplication>
#include <QCommandLineParser>
#include <QStandardPaths>
+#include "markdowndemowidget.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QStandardPaths::setTestModeEnabled(true);
- //TODO
+ MarkdownDemoWidget w;
+ w.show();
app.exec();
return 0;
}
diff --git a/kmail/editorconvertertextplugins/markdown/tests/markdowndemowidget.cpp b/kmail/editorconvertertextplugins/markdown/tests/markdowndemowidget.cpp
new file mode 100644
index 0000000..1b91f3f
--- /dev/null
+++ b/kmail/editorconvertertextplugins/markdown/tests/markdowndemowidget.cpp
@@ -0,0 +1,46 @@
+/*
+ Copyright (C) 2018 Montel Laurent <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "markdowndemowidget.h"
+#include "../markdownpreviewwidget.h"
+#include <QTextEdit>
+#include <QHBoxLayout>
+#include <QPushButton>
+
+MarkdownDemoWidget::MarkdownDemoWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ QVBoxLayout *vboxLayout = new QVBoxLayout(this);
+ QHBoxLayout *mainLayout = new QHBoxLayout;
+ vboxLayout->addLayout(mainLayout);
+ mEdit = new QTextEdit(this);
+ mainLayout->addWidget(mEdit);
+ mPreview = new MarkdownPreviewWidget(this);
+ mainLayout->addWidget(mPreview);
+ connect(mEdit, &QTextEdit::textChanged,
+ [this]() { mPreview->slotUpdatePreview(mEdit->toPlainText()); });
+ QPushButton *saveHtml = new QPushButton(QStringLiteral("Save Html"), this);
+ connect(saveHtml, &QPushButton::clicked, this, &MarkdownDemoWidget::slotSaveHtml);
+ vboxLayout->addWidget(saveHtml);
+}
+
+void MarkdownDemoWidget::slotSaveHtml()
+{
+ //TODO
+}
diff --git a/kmail/editorconvertertextplugins/markdown/tests/markdowndemowidget.h b/kmail/editorconvertertextplugins/markdown/tests/markdowndemowidget.h
new file mode 100644
index 0000000..e589bff
--- /dev/null
+++ b/kmail/editorconvertertextplugins/markdown/tests/markdowndemowidget.h
@@ -0,0 +1,39 @@
+/*
+ Copyright (C) 2018 Montel Laurent <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef MARKDOWNDEMOWIDGET_H
+#define MARKDOWNDEMOWIDGET_H
+
+#include <QWidget>
+class QTextEdit;
+class MarkdownPreviewWidget;
+class MarkdownDemoWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit MarkdownDemoWidget(QWidget *parent = nullptr);
+ ~MarkdownDemoWidget() = default;
+
+private:
+ void slotSaveHtml();
+ QTextEdit *mEdit = nullptr;
+ MarkdownPreviewWidget *mPreview = nullptr;
+};
+
+#endif // MARKDOWNDEMOWIDGET_H