Files
tdesktop/Telegram/ThirdParty/kcoreaddons/tests/ktexttohtmltest.cpp
allhaileris afb81b8278
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
init
2026-02-16 15:50:16 +03:00

48 lines
1.2 KiB
C++

/*
SPDX-FileCopyrightText: 2021 Friedrich W. H. Kossebau <kossebau@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <KTextToHTML>
#include <QApplication>
#include <QHBoxLayout>
#include <QMainWindow>
#include <QTextBrowser>
#include <QTimer>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
auto *window = new QMainWindow;
auto *mainWidget = new QWidget;
window->setCentralWidget(mainWidget);
auto *layout = new QHBoxLayout;
mainWidget->setLayout(layout);
auto *plaintextEditor = new QTextEdit;
plaintextEditor->setAcceptRichText(false);
layout->addWidget(plaintextEditor);
auto *htmlView = new QTextBrowser;
layout->addWidget(htmlView);
auto *updateTimer = new QTimer(&app);
updateTimer->setSingleShot(true);
updateTimer->setInterval(1000);
QObject::connect(updateTimer, &QTimer::timeout, plaintextEditor, [plaintextEditor, htmlView]() {
const QString html = KTextToHTML::convertToHtml(plaintextEditor->toPlainText(), KTextToHTML::Options());
htmlView->setHtml(html);
});
QObject::connect(plaintextEditor, &QTextEdit::textChanged, updateTimer, qOverload<>(&QTimer::start));
window->show();
return app.exec();
}