Commit 711be311 authored by Laurent Montel's avatar Laurent Montel 😁

Improve print job support

parent a869f64a
......@@ -19,5 +19,5 @@ ecm_add_test(printpreviewpagewidgettest.cpp ../printpreviewpagewidget.cpp ../pr
ecm_add_test(printwebengineviewjobtest.cpp ../printwebengineviewjob.cpp
TEST_NAME printwebengineviewjobtest
NAME_PREFIX "webengineviewer-print-"
LINK_LIBRARIES Qt5::Test Qt5::Widgets
LINK_LIBRARIES Qt5::Test Qt5::Widgets Qt5::WebEngineWidgets
)
......@@ -16,9 +16,27 @@
*/
#include "printwebengineviewjob.h"
#include <QWebEngineView>
using namespace WebEngineViewer;
template<typename Arg, typename R, typename C>
struct InvokeWrapper {
R *receiver;
void (C::*memberFun)(Arg);
void operator()(Arg result) {
(receiver->*memberFun)(result);
}
};
template<typename Arg, typename R, typename C>
InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFun)(Arg))
{
InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFun};
return wrapper;
}
PrintWebEngineViewJob::PrintWebEngineViewJob(QObject *parent)
: QObject(parent),
mEngineView(Q_NULLPTR)
......@@ -34,8 +52,24 @@ PrintWebEngineViewJob::~PrintWebEngineViewJob()
void PrintWebEngineViewJob::start()
{
if (mEngineView) {
if (!mTemporaryFile.open()) {
Q_EMIT failed();
deleteLater();
} else {
mTemporaryFile.setAutoRemove(false);
#if QT_VERSION >= 0x050700
//Print to pdf
//mEngineView->page()->printToPdf(invoke(this, &PrintWebEngineViewJob::slotHandlePdfPrinted), printer.pageLayout());
#endif
}
} else {
Q_EMIT failed();
deleteLater();
}
}
void PrintWebEngineViewJob::slotHandlePdfPrinted(const QByteArray& result)
{
//TODO
}
......
......@@ -19,6 +19,7 @@
#define PRINTWEBENGINEVIEWJOB_H
#include <QObject>
#include <QTemporaryFile>
class QWebEngineView;
namespace WebEngineViewer
......@@ -35,7 +36,15 @@ public:
QWebEngineView *engineView() const;
void setEngineView(QWebEngineView *engineView);
Q_SIGNALS:
void failed();
void success();
private Q_SLOTS:
void slotHandlePdfPrinted(const QByteArray &result);
private:
QTemporaryFile mTemporaryFile;
QWebEngineView *mEngineView;
};
}
......
......@@ -16,6 +16,7 @@
*/
#include "webengineview.h"
#include "config-webengineviewer.h"
#include <QEvent>
#include <QKeyEvent>
#include <QMouseEvent>
......@@ -179,3 +180,16 @@ qreal WebEngineView::relativePosition() const
{
return d->mSavedRelativePosition;
}
bool WebEngineView::hasPrintPreviewSupport() const
{
#if QT_VERSION < 0x050700
return false;
#endif
#ifdef WEBENGINEVIEWER_PRINTPREVIEW_SUPPORT
return true;
#else
return false;
#endif
}
......@@ -35,6 +35,8 @@ public:
void saveRelativePosition();
qreal relativePosition() const;
bool hasPrintPreviewSupport() const;
protected:
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
QWebEngineView *createWindow(QWebEnginePage::WebWindowType type) Q_DECL_OVERRIDE;
......
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