4 // Stefan Bund <info@j32.de>
7 \brief PDFWidget non-inline non-template implementation */
9 #include "PDFWidget.hh"
10 //#include "PDFWidget.ih"
14 #include <QNetworkRequest>
15 #include <QNetworkReply>
20 //#include "PDFWidget.mpp"
22 ///////////////////////////////cc.p////////////////////////////////////////
24 prefix_ pykit::PDFWidget::PDFWidget(QString const & id, QNetworkAccessManager * manager,
26 : QLabel(parent), id_ (id), manager_ (manager), currentPage_ (0)
29 QWebView * webView (dynamic_cast<QWebView*>(parent));
30 if (webView && !id_.isEmpty())
31 webView->page()->mainFrame()->addToJavaScriptWindowObject(id_,this);
34 prefix_ pykit::PDFWidget::PDFWidget(QString const & id, QString const & document,
35 QNetworkAccessManager * manager, QWidget * parent)
36 : QLabel(parent), id_ (id), manager_ (manager), currentPage_ (0)
39 setFocusPolicy(Qt::WheelFocus);
40 document_.reset(Poppler::Document::load(document));
41 QWebView * webView (dynamic_cast<QWebView*>(parent));
42 if (webView && !id_.isEmpty())
43 webView->page()->mainFrame()->addToJavaScriptWindowObject(id_,this);
47 prefix_ void pykit::PDFWidget::load(QUrl const & url)
49 QNetworkRequest request (url);
50 QNetworkReply * reply (manager_->get(request));
51 connect(reply, SIGNAL(finished()), this, SLOT(netLoadDocument()));
54 prefix_ void pykit::PDFWidget::resizeEvent(QResizeEvent *)
58 QSizeF pageSize (document_->page(currentPage_)->pageSizeF());
59 double n = 72.0 * width() / pageSize.width();
66 prefix_ void pykit::PDFWidget::netLoadDocument()
68 QNetworkReply * reply = static_cast<QNetworkReply*>(sender());
69 if (reply->error() != QNetworkReply::NoError)
71 QByteArray data (reply->read(reply->size()));
72 document_.reset(Poppler::Document::loadFromData(data));
77 prefix_ void pykit::PDFWidget::documentSetup()
81 document_->setRenderHint(Poppler::Document::Antialiasing, true);
82 document_->setRenderHint(Poppler::Document::TextAntialiasing, true);
83 document_->setRenderHint(Poppler::Document::TextHinting, false);
88 prefix_ void pykit::PDFWidget::showPage()
92 QImage image (document_->page(currentPage_)->renderToImage(
93 dpi_, dpi_, 0, 0, width(), height()));
94 setPixmap(QPixmap::fromImage(image));
97 ///////////////////////////////cc.e////////////////////////////////////////
99 //#include "PDFWidget.mpp"
105 // comment-column: 40
106 // c-file-style: "j32"
107 // indent-tabs-mode: nil
108 // ispell-local-dictionary: "american"
109 // compile-command: "make"