File indexing completed on 2025-03-09 04:54:39
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "testmailwebengine.h" 0008 #include "viewer/printmessage.h" 0009 #include "webenginescript.h" 0010 0011 #include <KActionCollection> 0012 #include <QApplication> 0013 #include <QPrintPreviewDialog> 0014 #include <QPrinter> 0015 #include <QPushButton> 0016 #include <QVBoxLayout> 0017 #include <QWebEngineSettings> 0018 0019 #include <MessageViewer/MailWebEngineView> 0020 #include <WebEngineViewer/WebEngineManageScript> 0021 0022 TestMailWebEngine::TestMailWebEngine(QWidget *parent) 0023 : QWidget(parent) 0024 , mZoom(1.0) 0025 { 0026 auto vbox = new QVBoxLayout(this); 0027 mTestWebEngine = new MessageViewer::MailWebEngineView(new KActionCollection(this), this); 0028 connect(mTestWebEngine, &MessageViewer::MailWebEngineView::openUrl, this, &TestMailWebEngine::slotOpenUrl); 0029 // mTestWebEngine->load(QUrl(QStringLiteral("http://www.kde.org"))); 0030 QString str = QStringLiteral( 0031 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " 0032 "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n <style type=\"text/css\">\n " 0033 "/*<![CDATA[*/\n @import \"main.css\";\n /*]]>*/\n\n.links {\n margin: auto;\n}\n\n.links td {\n padding-top: 5px;\n padding-bottom: " 0034 "5px;\n}\n\n </style>\n\n <title>Akregator</title>\n</head>\n\n<body>\n <div id=\"header\"><img " 0035 "src=\"file:///opt/kde5/share/icons/maia/apps/scalable/akregator.svg\" align=\"top\" height=\"128\" width=\"128\" alt=\"akregator\" title=\"\" />\n " 0036 "<div id=\"title\">\n <h1>Akregator</h1>Akregator est un agrégateur de flux pour KDE.\n </div>\n </div>\n\n <div id=\"box\">\n <div " 0037 "id=\"boxInner\">\n\n<div class=\"center\">\n <p>Feed readers provide a convenient way to browse different kinds of content, including news, blogs, " 0038 "and other content from online sites. Instead of checking all your favorite web sites manually for updates, Akregator collects the content for " 0039 "you.</p>\n <p> For more information about using Akregator, check the <a href='http://akregator.kde.org/'>Akregator website</a>. If you do not want " 0040 "to see this page anymore, <a href='config:/disable_introduction'>click here</a>.</p>\n <p>We hope that you will enjoy Akregator.</p>\n <p>Thank " 0041 "you, The Akregator Team </p>\n</div>\n\n </div>\n </div>\n</body>\n</html>\n\n<!-- vim:set sw=2 et nocindent smartindent: -->\n"); 0042 mTestWebEngine->setHtml(str, QUrl(QStringLiteral("file:///"))); 0043 mTestWebEngine->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true); 0044 vbox->addWidget(mTestWebEngine); 0045 auto hButtonBox = new QHBoxLayout; 0046 vbox->addLayout(hButtonBox); 0047 0048 auto scrollUp = new QPushButton(QStringLiteral("scrollUp 10px"), this); 0049 connect(scrollUp, &QPushButton::clicked, this, &TestMailWebEngine::slotScrollUp); 0050 hButtonBox->addWidget(scrollUp); 0051 0052 auto scrollDown = new QPushButton(QStringLiteral("scrollDown 10px"), this); 0053 connect(scrollDown, &QPushButton::clicked, this, &TestMailWebEngine::slotScrollDown); 0054 hButtonBox->addWidget(scrollDown); 0055 0056 hButtonBox = new QHBoxLayout; 0057 vbox->addLayout(hButtonBox); 0058 0059 auto zoomUp = new QPushButton(QStringLiteral("zoom Up"), this); 0060 connect(zoomUp, &QPushButton::clicked, this, &TestMailWebEngine::slotZoomUp); 0061 hButtonBox->addWidget(zoomUp); 0062 0063 auto zoomDown = new QPushButton(QStringLiteral("zoom Down"), this); 0064 connect(zoomDown, &QPushButton::clicked, this, &TestMailWebEngine::slotZoomDown); 0065 hButtonBox->addWidget(zoomDown); 0066 0067 auto printPreview = new QPushButton(QStringLiteral("Print Preview"), this); 0068 connect(printPreview, &QPushButton::clicked, this, &TestMailWebEngine::slotPrintPreview); 0069 hButtonBox->addWidget(printPreview); 0070 } 0071 0072 TestMailWebEngine::~TestMailWebEngine() = default; 0073 0074 void TestMailWebEngine::slotOpenUrl(const QUrl &url) 0075 { 0076 mTestWebEngine->load(url); 0077 } 0078 0079 void TestMailWebEngine::slotScrollDown() 0080 { 0081 mTestWebEngine->page()->runJavaScript(WebEngineViewer::WebEngineScript::scrollDown(10), WebEngineViewer::WebEngineManageScript::scriptWordId()); 0082 } 0083 0084 void TestMailWebEngine::slotScrollUp() 0085 { 0086 mTestWebEngine->page()->runJavaScript(WebEngineViewer::WebEngineScript::scrollUp(10), WebEngineViewer::WebEngineManageScript::scriptWordId()); 0087 } 0088 0089 void TestMailWebEngine::slotZoomDown() 0090 { 0091 mZoom -= 0.2; 0092 mTestWebEngine->setZoomFactor(mZoom); 0093 } 0094 0095 void TestMailWebEngine::slotZoomUp() 0096 { 0097 mZoom += 0.2; 0098 mTestWebEngine->setZoomFactor(mZoom); 0099 } 0100 0101 void TestMailWebEngine::slotPrintPreview() 0102 { 0103 auto printMessage = new MessageViewer::PrintMessage(this); 0104 printMessage->setView(mTestWebEngine); 0105 printMessage->setParentWidget(this); 0106 printMessage->printPreview(); 0107 } 0108 0109 int main(int argc, char *argv[]) 0110 { 0111 QApplication app(argc, argv); 0112 auto testWebEngine = new TestMailWebEngine; 0113 testWebEngine->show(); 0114 const int ret = app.exec(); 0115 return ret; 0116 } 0117 0118 #include "moc_testmailwebengine.cpp"