print functionality
Stefan Bund [Tue, 25 Jan 2011 09:58:14 +0000 (10:58 +0100)]
Viewer.cc
Viewer.hh

index 7c726c9..56708ee 100644 (file)
--- a/Viewer.cc
+++ b/Viewer.cc
@@ -16,6 +16,8 @@
 #ifdef POPPLER
 #include "PDFWidget.hh"
 #endif
+#include <QPrinter>
+#include <QPrintDialog>
 
 //#include "Viewer.mpp"
 #define prefix_
@@ -100,9 +102,19 @@ prefix_ pykit::Viewer::Viewer(QUrl const & url, Publisher * publisher, QWidget *
 #ifdef POPPLER
     page()->setPluginFactory(new PDFWebPluginFactory (page()->networkAccessManager(), this));
 #endif
+    connect(page(), SIGNAL(printRequested(QWebFrame*)), this, SLOT(printRequested()));
     load(url);
 }
 
+prefix_ void pykit::Viewer::printRequested()
+{
+    QPrinter printer;
+    QPrintDialog printDialog(&printer, this);
+    if (printDialog.exec() == QPrintDialog::Accepted) {
+        print(&printer);
+    }
+}
+
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 //#include "Viewer.mpp"
index 21ba371..3634e25 100644 (file)
--- a/Viewer.hh
+++ b/Viewer.hh
@@ -26,6 +26,9 @@ namespace pykit {
         Q_OBJECT;
     public:
         Viewer(QUrl const & url, Publisher * publisher, QWidget * parent = 0);
+
+    private slots:
+        void printRequested();
     };
 
 }