Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 061ce03d authored by Laurent Montel's avatar Laurent Montel 😁

Continue to implement it

parent 5fe14fea
......@@ -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);
}
......@@ -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 {};
}
......@@ -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;
......
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
......
......@@ -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;
}
/*
Copyright (C) 2018 Montel Laurent <montel@kde.org>
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
}
/*
Copyright (C) 2018 Montel Laurent <montel@kde.org>
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment