summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2016-05-28 10:07:34 +0200
committerMontel Laurent <[email protected]>2016-05-28 10:07:34 +0200
commit12d42d7e69fcbae88e38136030d3ffc5287f2862 (patch)
tree4a6108b268deddffdcb6fee048cb7c66b82bfc7c
parent78030d74e7c1427ccb85f56cd9ccefda07ef8187 (diff)
Start to implement print suppor
-rw-r--r--akregator/src/articleviewer-ng/webengine/articleviewerwebengine.cpp78
-rw-r--r--akregator/src/articleviewer-ng/webengine/articleviewerwebengine.h4
-rw-r--r--akregator/src/articleviewerwidget.cpp4
-rw-r--r--akregator/src/frame/mainframe.h2
-rw-r--r--akregator/src/frame/webengine/akrwebengineviewer.cpp2
-rw-r--r--akregator/src/widgets/searchbar.cpp2
6 files changed, 71 insertions, 21 deletions
diff --git a/akregator/src/articleviewer-ng/webengine/articleviewerwebengine.cpp b/akregator/src/articleviewer-ng/webengine/articleviewerwebengine.cpp
index 598c7dd..26e9bb0 100644
--- a/akregator/src/articleviewer-ng/webengine/articleviewerwebengine.cpp
+++ b/akregator/src/articleviewer-ng/webengine/articleviewerwebengine.cpp
@@ -49,6 +49,17 @@
#include <viewerplugintoolmanager.h>
#include <QWebEngineProfile>
#include <QWebEngineDownloadItem>
+#include <QPointer>
+#include <WebEnginePrintMessageBox>
+#include <MimeTreeParser/AttachmentTemporaryFilesDirs>
+
+#include <webengineviewer/config-webengineviewer.h>
+#ifdef WEBENGINEVIEWER_PRINTPREVIEW_SUPPORT
+#include <WebEngineViewer/PrintPreviewDialog>
+#include <WebEngineViewer/PrintWebEngineViewJob>
+#include <WebEngineViewer/PrintConfigureDialog>
+#endif
+
#include <WebEngineViewer/WebHitTestResult>
#include <WebEngineViewer/WebHitTest>
#include <WebEngineViewer/WebEngineScript>
@@ -220,29 +231,68 @@ void ArticleViewerWebEngine::slotShowContextMenu(const QPoint &pos)
void ArticleViewerWebEngine::slotPrintPreview()
{
- //Use printToPdf Qt5.7
-#if 0
- PimCommon::KPimPrintPreviewDialog previewdlg(this);
- connect(&previewdlg, &QPrintPreviewDialog::paintRequested, this, [this](QPrinter * printer) {
- render(printer);
- });
- previewdlg.exec();
+#if 0 //FIXME
+ QPointer<WebEngineViewer::WebEnginePrintMessageBox> dialog = new WebEngineViewer::WebEnginePrintMessageBox(Q_NULLPTR);
+ connect(dialog.data(), &WebEngineViewer::WebEnginePrintMessageBox::openInBrowser, this, &ArticleViewerWebEngine::slotOpenInBrowser);
+ connect(dialog.data(), &WebEngineViewer::WebEnginePrintMessageBox::openPrintPreview, this, &ArticleViewerWebEngine::slotOpenPrintPreviewDialog);
+ dialog->setWebEngineView(this);
+ dialog->exec();
+ delete dialog;
#endif
}
-void ArticleViewerWebEngine::slotPrint()
+void ArticleViewerWebEngine::slotOpenInBrowser(const QString &filename)
{
-#if 0
- QPrinter printer;
-
- QScopedPointer<QPrintDialog> dlg(new QPrintDialog(&printer));
+ MimeTreeParser::AttachmentTemporaryFilesDirs *browserTemporaryFile = new MimeTreeParser::AttachmentTemporaryFilesDirs;
+ browserTemporaryFile->addTempFile(filename);
+ const QUrl url(QUrl::fromLocalFile(filename));
+ KRun::runUrl(url, QStringLiteral("text/html"), this);
+ browserTemporaryFile->removeTempFiles();
+ browserTemporaryFile = Q_NULLPTR;
+}
- if (dlg && dlg->exec() == QDialog::Accepted) {
- render(&printer);
+void ArticleViewerWebEngine::slotOpenPrintPreviewDialog()
+{
+#ifdef WEBENGINEVIEWER_PRINTPREVIEW_SUPPORT
+ QPointer<WebEngineViewer::PrintConfigureDialog> dlg = new WebEngineViewer::PrintConfigureDialog(Q_NULLPTR);
+ if (dlg->exec()) {
+ const QPageLayout pageLayout = dlg->currentPageLayout();
+ WebEngineViewer::PrintWebEngineViewJob *job = new WebEngineViewer::PrintWebEngineViewJob(this);
+ job->setEngineView(this);
+ job->setPageLayout(pageLayout);
+ connect(job, &WebEngineViewer::PrintWebEngineViewJob::failed, this, &ArticleViewerWebEngine::slotPdfFailed);
+ connect(job, &WebEngineViewer::PrintWebEngineViewJob::success, this, &ArticleViewerWebEngine::slotPdfCreated);
+ job->start();
}
+ delete dlg;
+#endif
+}
+
+void ArticleViewerWebEngine::slotPdfCreated(const QString &filename)
+{
+#ifdef WEBENGINEVIEWER_PRINTPREVIEW_SUPPORT
+ WebEngineViewer::PrintPreviewDialog dlg(this);
+ dlg.loadFile(filename, true);
+ dlg.exec();
#endif
}
+void ArticleViewerWebEngine::slotPdfFailed()
+{
+ qCDebug(AKREGATOR_LOG) << "Print to pdf Failed";
+}
+
+void ArticleViewerWebEngine::slotPrint()
+{
+ QPointer<WebEngineViewer::WebEnginePrintMessageBox> dialog = new WebEngineViewer::WebEnginePrintMessageBox(Q_NULLPTR);
+ connect(dialog.data(), &WebEngineViewer::WebEnginePrintMessageBox::openInBrowser, this, &ArticleViewerWebEngine::slotOpenInBrowser);
+ connect(dialog.data(), &WebEngineViewer::WebEnginePrintMessageBox::openPrintPreview, this, &ArticleViewerWebEngine::slotOpenPrintPreviewDialog);
+ dialog->setWebEngineView(this);
+ dialog->exec();
+ delete dialog;
+}
+
+
void ArticleViewerWebEngine::slotCopy()
{
triggerPageAction(QWebEnginePage::Copy);
diff --git a/akregator/src/articleviewer-ng/webengine/articleviewerwebengine.h b/akregator/src/articleviewer-ng/webengine/articleviewerwebengine.h
index 48f811d..fd83ac6 100644
--- a/akregator/src/articleviewer-ng/webengine/articleviewerwebengine.h
+++ b/akregator/src/articleviewer-ng/webengine/articleviewerwebengine.h
@@ -128,6 +128,10 @@ private Q_SLOTS:
void slotWebHitFinished(const WebEngineViewer::WebHitTestResult &result);
void slotActivatePlugin(MessageViewer::ViewerPluginInterface *interface);
void slotWebPageMutedOrAudibleChanged();
+ void slotOpenInBrowser(const QString &filename);
+ void slotOpenPrintPreviewDialog();
+ void slotPdfCreated(const QString &filename);
+ void slotPdfFailed();
protected:
ArticleViewerWebEnginePage *mPageEngine;
diff --git a/akregator/src/articleviewerwidget.cpp b/akregator/src/articleviewerwidget.cpp
index adaa842..1023adc 100644
--- a/akregator/src/articleviewerwidget.cpp
+++ b/akregator/src/articleviewerwidget.cpp
@@ -71,8 +71,6 @@
using namespace Akregator;
using namespace Akregator::Filters;
-using namespace Akregator;
-
ArticleViewerWidget::ArticleViewerWidget(const QString &grantleeDirectory, KActionCollection *ac, QWidget *parent)
: QWidget(parent),
m_imageDir(QUrl::fromLocalFile(QString(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String("/akregator/Media/")))),
@@ -173,7 +171,7 @@ void ArticleViewerWidget::slotShowSummary(TreeNode *node)
m_node = node;
}
- QString summary = m_normalViewFormatter->formatSummary(node);
+ const QString summary = m_normalViewFormatter->formatSummary(node);
m_link.clear();
renderContent(summary);
diff --git a/akregator/src/frame/mainframe.h b/akregator/src/frame/mainframe.h
index 25fe63b..a3ce003 100644
--- a/akregator/src/frame/mainframe.h
+++ b/akregator/src/frame/mainframe.h
@@ -29,7 +29,7 @@ class AKREGATOR_EXPORT MainFrame : public Frame
public:
- MainFrame(QWidget *parent, QWidget *widget);
+ explicit MainFrame(QWidget *parent, QWidget *widget);
virtual ~MainFrame();
QUrl url() const Q_DECL_OVERRIDE;
diff --git a/akregator/src/frame/webengine/akrwebengineviewer.cpp b/akregator/src/frame/webengine/akrwebengineviewer.cpp
index 824e864..dd32c06 100644
--- a/akregator/src/frame/webengine/akrwebengineviewer.cpp
+++ b/akregator/src/frame/webengine/akrwebengineviewer.cpp
@@ -108,10 +108,10 @@ void AkrWebEngineViewer::slotWebHitFinished(const WebEngineViewer::WebHitTestRes
popup.addSeparator();
popup.addActions(viewerPluginActionList(MessageViewer::ViewerPluginInterface::NeedSelection));
}
-#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
popup.addSeparator();
popup.addAction(ActionManager::getInstance()->action(QStringLiteral("viewer_print")));
popup.addAction(ActionManager::getInstance()->action(QStringLiteral("viewer_printpreview")));
+#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
popup.addSeparator();
popup.addAction(pageAction(QWebEnginePage::SavePage));
popup.addSeparator();
diff --git a/akregator/src/widgets/searchbar.cpp b/akregator/src/widgets/searchbar.cpp
index 91a7e09..bfa85d0 100644
--- a/akregator/src/widgets/searchbar.cpp
+++ b/akregator/src/widgets/searchbar.cpp
@@ -43,8 +43,6 @@
using namespace Akregator;
using namespace Akregator::Filters;
-
-using namespace Akregator;
class SearchBar::SearchBarPrivate
{
public: