Commit 8f7015b4 authored by Laurent Montel's avatar Laurent Montel 😁

Move in toplevel to fix print

parent 36d91c66
......@@ -50,15 +50,6 @@
#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>
......@@ -229,70 +220,6 @@ void ArticleViewerWebEngine::slotShowContextMenu(const QPoint &pos)
displayContextMenu(pos);
}
void ArticleViewerWebEngine::slotPrintPreview()
{
#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::slotOpenInBrowser(const QString &filename)
{
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;
}
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);
......
......@@ -89,8 +89,6 @@ private:
QVariantHash introductionData() const;
public Q_SLOTS:
void slotPrintPreview();
void slotPrint();
void slotCopy();
void slotSaveLinkAs();
void slotCopyLinkAddress();
......@@ -128,10 +126,6 @@ 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;
......
......@@ -16,18 +16,29 @@
*/
#include "articleviewerwebenginewidgetng.h"
#include "akregator_debug.h"
#include <KActionCollection>
#include <KLocalizedString>
#include <QVBoxLayout>
#include <QAction>
#include <viewerplugintoolmanager.h>
#include <KRun>
#include <KPIMTextEdit/kpimtextedit/texttospeechwidget.h>
#include <kpimtextedit/slidecontainer.h>
#include <MimeTreeParser/AttachmentTemporaryFilesDirs>
#include <WebEngineViewer/WebEnginePrintMessageBox>
#include <WebEngineViewer/FindBarWebEngineView>
#include <webengineviewer/config-webengineviewer.h>
#ifdef WEBENGINEVIEWER_PRINTPREVIEW_SUPPORT
#include <WebEngineViewer/PrintPreviewDialog>
#include <WebEngineViewer/PrintWebEngineViewJob>
#include <WebEngineViewer/PrintConfigureDialog>
#endif
using namespace Akregator;
......@@ -108,3 +119,65 @@ void ArticleViewerWebEngineWidgetNg::restoreCurrentPosition()
{
mArticleViewerNg->restoreCurrentPosition();
}
void ArticleViewerWebEngineWidgetNg::slotPrintPreview()
{
QPointer<WebEngineViewer::WebEnginePrintMessageBox> dialog = new WebEngineViewer::WebEnginePrintMessageBox(this);
connect(dialog.data(), &WebEngineViewer::WebEnginePrintMessageBox::openInBrowser, this, &ArticleViewerWebEngineWidgetNg::slotOpenInBrowser);
connect(dialog.data(), &WebEngineViewer::WebEnginePrintMessageBox::openPrintPreview, this, &ArticleViewerWebEngineWidgetNg::slotOpenPrintPreviewDialog);
dialog->setWebEngineView(mArticleViewerNg);
dialog->exec();
delete dialog;
}
void ArticleViewerWebEngineWidgetNg::slotOpenInBrowser(const QString &filename)
{
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;
}
void ArticleViewerWebEngineWidgetNg::slotOpenPrintPreviewDialog()
{
#ifdef WEBENGINEVIEWER_PRINTPREVIEW_SUPPORT
QPointer<WebEngineViewer::PrintConfigureDialog> dlg = new WebEngineViewer::PrintConfigureDialog(this);
if (dlg->exec()) {
const QPageLayout pageLayout = dlg->currentPageLayout();
WebEngineViewer::PrintWebEngineViewJob *job = new WebEngineViewer::PrintWebEngineViewJob(this);
job->setEngineView(mArticleViewerNg);
job->setPageLayout(pageLayout);
connect(job, &WebEngineViewer::PrintWebEngineViewJob::failed, this, &ArticleViewerWebEngineWidgetNg::slotPdfFailed);
connect(job, &WebEngineViewer::PrintWebEngineViewJob::success, this, &ArticleViewerWebEngineWidgetNg::slotPdfCreated);
job->start();
}
delete dlg;
#endif
}
void ArticleViewerWebEngineWidgetNg::slotPdfCreated(const QString &filename)
{
#ifdef WEBENGINEVIEWER_PRINTPREVIEW_SUPPORT
WebEngineViewer::PrintPreviewDialog dlg(this);
dlg.loadFile(filename, true);
dlg.exec();
#endif
}
void ArticleViewerWebEngineWidgetNg::slotPdfFailed()
{
qCDebug(AKREGATOR_LOG) << "Print to pdf Failed";
}
void ArticleViewerWebEngineWidgetNg::slotPrint()
{
QPointer<WebEngineViewer::WebEnginePrintMessageBox> dialog = new WebEngineViewer::WebEnginePrintMessageBox(Q_NULLPTR);
connect(dialog.data(), &WebEngineViewer::WebEnginePrintMessageBox::openInBrowser, this, &ArticleViewerWebEngineWidgetNg::slotOpenInBrowser);
connect(dialog.data(), &WebEngineViewer::WebEnginePrintMessageBox::openPrintPreview, this, &ArticleViewerWebEngineWidgetNg::slotOpenPrintPreviewDialog);
dialog->setWebEngineView(mArticleViewerNg);
dialog->exec();
delete dialog;
}
......@@ -51,6 +51,15 @@ public:
public Q_SLOTS:
void slotSpeakText();
void slotFind();
void slotPrint();
void slotPrintPreview();
private Q_SLOTS:
void slotPdfFailed();
void slotPdfCreated(const QString &filename);
void slotOpenPrintPreviewDialog();
void slotOpenInBrowser(const QString &filename);
private:
void initializeActions(KActionCollection *ac);
void initializeLayout(KActionCollection *ac);
......
......@@ -109,12 +109,12 @@ void ArticleViewerWidget::slotSelectionChanged()
void ArticleViewerWidget::slotPrint()
{
m_articleViewerWidgetNg->articleViewerNg()->slotPrint();
m_articleViewerWidgetNg->slotPrint();
}
void ArticleViewerWidget::slotPrintPreview()
{
m_articleViewerWidgetNg->articleViewerNg()->slotPrintPreview();
m_articleViewerWidgetNg->slotPrintPreview();
}
void ArticleViewerWidget::connectToNode(TreeNode *node)
......
......@@ -118,7 +118,7 @@ void WebEngineFrame::slotPrintInFrame(int frameId)
if (frameId != id()) {
return;
}
mArticleViewerWidgetNg->articleViewerNg()->slotPrint();
mArticleViewerWidgetNg->slotPrint();
}
void WebEngineFrame::slotPrintPreviewInFrame(int frameId)
......@@ -126,7 +126,7 @@ void WebEngineFrame::slotPrintPreviewInFrame(int frameId)
if (frameId != id()) {
return;
}
mArticleViewerWidgetNg->articleViewerNg()->slotPrintPreview();
mArticleViewerWidgetNg->slotPrintPreview();
}
void WebEngineFrame::slotFindTextInFrame(int frameId)
......
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