Commit 12d42d7e authored by Laurent Montel's avatar Laurent Montel 😁

Start to implement print suppor

parent 78030d74
......@@ -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);
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -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();
......
......@@ -43,8 +43,6 @@
using namespace Akregator;
using namespace Akregator::Filters;
using namespace Akregator;
class SearchBar::SearchBarPrivate
{
public:
......
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