File indexing completed on 2024-09-08 06:40:02
0001 /* 0002 SPDX-FileCopyrightText: 2021 Friedrich W. H. Kossebau <kossebau@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include <KTextToHTML> 0008 0009 #include <QApplication> 0010 #include <QHBoxLayout> 0011 #include <QMainWindow> 0012 #include <QTextBrowser> 0013 #include <QTimer> 0014 0015 int main(int argc, char **argv) 0016 { 0017 QApplication app(argc, argv); 0018 0019 auto *window = new QMainWindow; 0020 0021 auto *mainWidget = new QWidget; 0022 window->setCentralWidget(mainWidget); 0023 0024 auto *layout = new QHBoxLayout; 0025 mainWidget->setLayout(layout); 0026 0027 auto *plaintextEditor = new QTextEdit; 0028 plaintextEditor->setAcceptRichText(false); 0029 layout->addWidget(plaintextEditor); 0030 0031 auto *htmlView = new QTextBrowser; 0032 layout->addWidget(htmlView); 0033 0034 auto *updateTimer = new QTimer(&app); 0035 updateTimer->setSingleShot(true); 0036 updateTimer->setInterval(1000); 0037 QObject::connect(updateTimer, &QTimer::timeout, plaintextEditor, [plaintextEditor, htmlView]() { 0038 const QString html = KTextToHTML::convertToHtml(plaintextEditor->toPlainText(), KTextToHTML::Options()); 0039 htmlView->setHtml(html); 0040 }); 0041 0042 QObject::connect(plaintextEditor, &QTextEdit::textChanged, updateTimer, qOverload<>(&QTimer::start)); 0043 0044 window->show(); 0045 0046 return app.exec(); 0047 }