summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-02 21:37:24 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-02 21:37:24 (GMT)
commit45e588ed7198a4e26924eaca25a968bde4d461cd (patch)
tree060b49d59497a67bd08f2a6e93d6cadd6e353901
parent6abc5ebb6b1611fd61de5480d5738a4c4751e49b (diff)
Add support for printing based on qt5.8
-rw-r--r--messageviewer/src/viewer/viewer_p.cpp43
-rw-r--r--messageviewer/src/viewer/viewer_p.h3
2 files changed, 43 insertions, 3 deletions
diff --git a/messageviewer/src/viewer/viewer_p.cpp b/messageviewer/src/viewer/viewer_p.cpp
index 998b175..9a285db 100644
--- a/messageviewer/src/viewer/viewer_p.cpp
+++ b/messageviewer/src/viewer/viewer_p.cpp
@@ -159,6 +159,22 @@ using namespace MessageCore;
static QAtomicInt _k_attributeInitialized;
+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;
+}
+
ViewerPrivate::ViewerPrivate(Viewer *aParent, QWidget *mainWindow,
KActionCollection *actionCollection)
: QObject(aParent),
@@ -204,7 +220,8 @@ ViewerPrivate::ViewerPrivate(Viewer *aParent, QWidget *mainWindow,
mHeaderStylePlugin(Q_NULLPTR),
mHeaderStyleMenuManager(Q_NULLPTR),
mViewerPluginToolManager(Q_NULLPTR),
- mZoomActionMenu(Q_NULLPTR)
+ mZoomActionMenu(Q_NULLPTR),
+ mCurrentPrinter(Q_NULLPTR)
{
mMimePartTree = 0;
if (!mainWindow) {
@@ -2244,11 +2261,31 @@ void ViewerPrivate::slotPrintMessage()
return;
}
#ifdef WEBENGINEVIEWER_PRINT_SUPPORT
- //TODO
-#endif
+ if (mCurrentPrinter)
+ return;
+ mCurrentPrinter = new QPrinter();
+ QPointer<QPrintDialog> dialog = new QPrintDialog(mCurrentPrinter, mMainWindow);
+ dialog->setWindowTitle(i18n("Print Document"));
+ if (dialog->exec() != QDialog::Accepted) {
+ slotHandlePagePrinted(false);
+ delete dialog;
+ return;
+ }
+ delete dialog;
+ mViewer->page()->print(mCurrentPrinter, invoke(this, &ViewerPrivate::slotHandlePagePrinted));
+#else
slotPrintPreview();
+#endif
}
+void ViewerPrivate::slotHandlePagePrinted(bool result)
+{
+ Q_UNUSED(result);
+ delete mCurrentPrinter;
+ mCurrentPrinter = Q_NULLPTR;
+}
+
+
void ViewerPrivate::slotSetEncoding()
{
if (mSelectEncodingAction) {
diff --git a/messageviewer/src/viewer/viewer_p.h b/messageviewer/src/viewer/viewer_p.h
index a8074a7..f3af63c 100644
--- a/messageviewer/src/viewer/viewer_p.h
+++ b/messageviewer/src/viewer/viewer_p.h
@@ -53,6 +53,7 @@ class KActionMenu;
class QPoint;
class QSplitter;
class QModelIndex;
+class QPrinter;
namespace KPIMTextEdit
{
@@ -463,6 +464,7 @@ private Q_SLOTS:
void slotOpenInBrowser();
void slotExportHtmlPageFailed();
void slotExportHtmlPageSuccess(const QString &filename);
+ void slotHandlePagePrinted(bool result);
public Q_SLOTS:
/** An URL has been activate with a click. */
void slotUrlOpen(const QUrl &url = QUrl());
@@ -671,6 +673,7 @@ public:
MessageViewer::HeaderStyleMenuManager *mHeaderStyleMenuManager;
MessageViewer::ViewerPluginToolManager *mViewerPluginToolManager;
WebEngineViewer::ZoomActionMenu *mZoomActionMenu;
+ QPrinter *mCurrentPrinter;
};
}