1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Fix printing to printer other than PDF printer

BUG: 497051
FIXED-IN: 24.12

Chery picked from: eaa8070235

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2024-12-04 21:34:31 +01:00
parent 80a925140d
commit cbf47b0625
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
2 changed files with 18 additions and 8 deletions

View File

@ -67,6 +67,7 @@ WebView::WebView(QWidget* parent)
connect(this, &QWebEngineView::iconChanged, this, &WebView::slotIconChanged); connect(this, &QWebEngineView::iconChanged, this, &WebView::slotIconChanged);
connect(this, &QWebEngineView::urlChanged, this, &WebView::slotUrlChanged); connect(this, &QWebEngineView::urlChanged, this, &WebView::slotUrlChanged);
connect(this, &QWebEngineView::titleChanged, this, &WebView::slotTitleChanged); connect(this, &QWebEngineView::titleChanged, this, &WebView::slotTitleChanged);
connect(this, &QWebEngineView::printFinished, this, &WebView::slotPrintFinished);
m_currentZoomLevel = zoomLevels().indexOf(100); m_currentZoomLevel = zoomLevels().indexOf(100);
@ -386,11 +387,11 @@ void WebView::printPage()
{ {
Q_ASSERT(m_page); Q_ASSERT(m_page);
auto *printer = new QPrinter(); m_printer = new QPrinter();
printer->setCreator(tr("Falkon %1 (%2)").arg(QString::fromLatin1(Qz::VERSION), QString::fromLatin1(Qz::WWWADDRESS))); m_printer->setCreator(tr("Falkon %1 (%2)").arg(QString::fromLatin1(Qz::VERSION), QString::fromLatin1(Qz::WWWADDRESS)));
printer->setDocName(QzTools::filterCharsFromFilename(title())); m_printer->setDocName(QzTools::filterCharsFromFilename(title()));
auto *dialog = new QPrintDialog(printer, this); auto *dialog = new QPrintDialog(m_printer, this);
dialog->setOptions(QAbstractPrintDialog::PrintToFile | QAbstractPrintDialog::PrintShowPageSize); dialog->setOptions(QAbstractPrintDialog::PrintToFile | QAbstractPrintDialog::PrintShowPageSize);
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
dialog->setOption(QAbstractPrintDialog::PrintPageRange); dialog->setOption(QAbstractPrintDialog::PrintPageRange);
@ -402,14 +403,19 @@ void WebView::printPage()
m_page->printToPdf(dialog->printer()->outputFileName(), dialog->printer()->pageLayout()); m_page->printToPdf(dialog->printer()->outputFileName(), dialog->printer()->pageLayout());
delete dialog; delete dialog;
} else { } else {
connect(this, &QWebEngineView::printFinished, this, [&dialog](bool success) { print(m_printer);
Q_UNUSED(success);
delete dialog; delete dialog;
});
} }
} }
} }
void WebView::slotPrintFinished(bool success)
{
Q_UNUSED(success);
delete m_printer;
m_printer = nullptr;
}
void WebView::slotLoadStarted() void WebView::slotLoadStarted()
{ {
m_progress = 0; m_progress = 0;

View File

@ -25,6 +25,7 @@
#include "loadrequest.h" #include "loadrequest.h"
#include "wheelhelper.h" #include "wheelhelper.h"
class QPrinter;
class WebPage; class WebPage;
class LoadRequest; class LoadRequest;
class WebHitTestResult; class WebHitTestResult;
@ -118,6 +119,7 @@ protected Q_SLOTS:
void slotIconChanged(); void slotIconChanged();
void slotUrlChanged(const QUrl &url); void slotUrlChanged(const QUrl &url);
void slotTitleChanged(const QString &title); void slotTitleChanged(const QString &title);
void slotPrintFinished(bool success);
// Context menu slots // Context menu slots
void openUrlInNewWindow(); void openUrlInNewWindow();
@ -193,6 +195,8 @@ private:
WheelHelper m_wheelHelper; WheelHelper m_wheelHelper;
static bool s_forceContextMenuOnMouseRelease; static bool s_forceContextMenuOnMouseRelease;
QPrinter* m_printer;
}; };
#endif // WEBVIEW_H #endif // WEBVIEW_H