Commit d8ad851d authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add test apps for testing html from grantlee

parent eb7fddf2
Pipeline #20994 passed with stage
in 6 minutes and 22 seconds
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_BINARY_DIR}/../src)
#####
add_executable(inserthtmldialog_demo inserthtmldialog_demo.cpp)
set(inserthtmldialog_demo_LIBS KF5PimTextEdit Qt5::Widgets KF5::SyntaxHighlighting)
target_link_libraries(inserthtmldialog_demo ${inserthtmldialog_demo_LIBS})
#####
set(slidecontainer_gui_SRCS slidecontainer_gui.cpp)
add_executable(slidecontainer_gui ${slidecontainer_gui_SRCS})
target_link_libraries(slidecontainer_gui
......@@ -13,7 +13,11 @@ target_link_libraries(slidecontainer_gui
KF5PimTextEdit
)
#####
add_executable(showemoticonunicodetab_gui showemoticonunicodetab_gui.cpp)
set(showemoticonunicodetab_gui_LIBS KF5PimTextEdit Qt5::Widgets)
target_link_libraries(showemoticonunicodetab_gui ${showemoticonunicodetab_gui_LIBS})
#####
add_executable(testgeneratehtmlbuildergui_gui testgeneratehtmlbuildergui.cpp)
set(testgeneratehtmlbuildergui_gui_LIBS KF5PimTextEdit Qt5::Widgets )
target_link_libraries(testgeneratehtmlbuildergui_gui ${testgeneratehtmlbuildergui_gui_LIBS})
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "testgeneratehtmlbuildergui.h"
#include <QVBoxLayout>
#include <QApplication>
#include <QLabel>
#include <QTextEdit>
#include <QPushButton>
#include <KPIMTextEdit/TextHTMLBuilder>
#include <KPIMTextEdit/MarkupDirector>
TestGenerateHTMLBuilderGui::TestGenerateHTMLBuilderGui(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QLabel *lab = new QLabel(QStringLiteral("html text"), this);
mainLayout->addWidget(lab);
QTextEdit *htmlEdit = new QTextEdit(this);
htmlEdit->setAcceptRichText(false);
mainLayout->addWidget(htmlEdit);
QPushButton *generateHtmlFromQTextEditButton = new QPushButton(QStringLiteral("Generate HTML"), this);
mainLayout->addWidget(generateHtmlFromQTextEditButton);
lab = new QLabel(QStringLiteral("Generate Html"), this);
mainLayout->addWidget(lab);
QTextEdit *generatedHtml = new QTextEdit(this);
generatedHtml->setAcceptRichText(false);
generatedHtml->setReadOnly(true);
mainLayout->addWidget(generatedHtml);
lab = new QLabel(QStringLiteral("HTML from QTextEdit"), this);
mainLayout->addWidget(lab);
QTextEdit *generatedHtmlFromTextEdit = new QTextEdit(this);
generatedHtmlFromTextEdit->setAcceptRichText(false);
generatedHtmlFromTextEdit->setReadOnly(true);
mainLayout->addWidget(generatedHtmlFromTextEdit);
lab = new QLabel(QStringLiteral("HTML from Grantlee"), this);
mainLayout->addWidget(lab);
QTextEdit *generatedHtmlFromGrantlee = new QTextEdit(this);
generatedHtmlFromGrantlee->setAcceptRichText(false);
generatedHtmlFromGrantlee->setReadOnly(true);
mainLayout->addWidget(generatedHtmlFromGrantlee);
lab = new QLabel(QStringLiteral("HTML from Grantlee to TextEdit"), this);
mainLayout->addWidget(lab);
QTextEdit *generatedHtmlFromGrantleeToTextEdit = new QTextEdit(this);
generatedHtmlFromGrantleeToTextEdit->setAcceptRichText(false);
generatedHtmlFromGrantleeToTextEdit->setReadOnly(true);
mainLayout->addWidget(generatedHtmlFromGrantleeToTextEdit);
connect(generateHtmlFromQTextEditButton, &QPushButton::clicked, [=]{
generatedHtml->setHtml(htmlEdit->toPlainText());
generatedHtmlFromTextEdit->setPlainText(generatedHtml->document()->toHtml());
auto hb = new KPIMTextEdit::TextHTMLBuilder();
auto md = new KPIMTextEdit::MarkupDirector(hb);
md->processDocument(generatedHtml->document());
auto result = hb->getResult();
delete md;
delete hb;
generatedHtmlFromGrantlee->setPlainText(result);
generatedHtmlFromGrantleeToTextEdit->setHtml(result);
});
}
TestGenerateHTMLBuilderGui::~TestGenerateHTMLBuilderGui()
{
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
TestGenerateHTMLBuilderGui window;
window.show();
return app.exec();
}
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef TESTGENERATEHTMLBUILDERGUI_H
#define TESTGENERATEHTMLBUILDERGUI_H
#include <QWidget>
class TestGenerateHTMLBuilderGui : public QWidget
{
Q_OBJECT
public:
explicit TestGenerateHTMLBuilderGui(QWidget *parent = nullptr);
~TestGenerateHTMLBuilderGui();
};
#endif // TESTGENERATEHTMLBUILDERGUI_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