prefix_ pykit::PDFWidget::PDFWidget(QString const & id, QNetworkAccessManager * manager,
QWidget * parent)
- : QLabel(parent), id_ (id), manager_ (manager), currentPage_ (0), dpi_ (96.0), x_ (0), y_ (0)
+ : QLabel(parent), id_ (id), manager_ (manager), currentPage_ (0)
{
QWebView * webView (dynamic_cast<QWebView*>(parent));
prefix_ pykit::PDFWidget::PDFWidget(QString const & id, QString const & document,
QNetworkAccessManager * manager, QWidget * parent)
- : QLabel(parent), id_ (id), manager_ (manager), currentPage_ (0), dpi_ (96.0), x_ (0), y_ (0)
+ : QLabel(parent), id_ (id), manager_ (manager), currentPage_ (0)
{
setFocusPolicy(Qt::WheelFocus);
connect(reply, SIGNAL(finished()), this, SLOT(netLoadDocument()));
}
-prefix_ void pykit::PDFWidget::zoomIn()
-{
- zoomMode_ = Manual;
- double n (dpi_ + ZoomStepDpi);
- if (n > ZoomMaxDpi)
- n = ZoomMaxDpi;
- if (n != dpi_) {
- dpi_ = n;
- showPage();
- }
-}
-
-prefix_ void pykit::PDFWidget::zoomOut()
-{
- zoomMode_ = Manual;
- double n (dpi_ - ZoomStepDpi);
- if (n < ZoomMinDpi)
- n = ZoomMinDpi;
- if (n != dpi_) {
- dpi_ = n;
- showPage();
- }
-}
-
-prefix_ void pykit::PDFWidget::zoomDPI(double dpi)
-{
- zoomMode_ = Manual;
- if (dpi < ZoomMinDpi)
- dpi = ZoomMinDpi;
- if (dpi > ZoomMaxDpi)
- dpi = ZoomMaxDpi;
- if (dpi != dpi_) {
- dpi_ = dpi;
- showPage();
- }
-}
-
-prefix_ int pykit::PDFWidget::zoomWidth(int w)
-{
- zoomMode_ = Width;
- if (! document_)
- return 0;
- if (w == -1)
- w = width();
- QSizeF pageSize (document_->page(currentPage_)->pageSizeF());
- double n = 72.0 * w / pageSize.width();
- if (n > ZoomMaxDpi)
- n = ZoomMaxDpi;
- if (n < ZoomMinDpi)
- n = ZoomMinDpi;
- if (n != dpi_) {
- dpi_ = n;
- showPage();
- }
- return pageSize.height() * dpi_ / 72.0;
-}
-
-prefix_ int pykit::PDFWidget::zoomHeight()
-{
- zoomMode_ = Height;
- if (! document_)
- return 0;
- QSizeF pageSize (document_->page(currentPage_)->pageSizeF());
- double n = 72.0 * height() / pageSize.height();
- if (n > ZoomMaxDpi)
- n = ZoomMaxDpi;
- if (n < ZoomMinDpi)
- n = ZoomMinDpi;
- if (n != dpi_) {
- dpi_ = n;
- showPage();
- }
- return pageSize.width() * dpi_ / 72.0;
-}
-
-prefix_ void pykit::PDFWidget::zoomFit()
+prefix_ void pykit::PDFWidget::resizeEvent(QResizeEvent *)
{
- zoomMode_ = Fit;
if (! document_)
return;
QSizeF pageSize (document_->page(currentPage_)->pageSizeF());
- double xres = 72.0 * width() / pageSize.width();
- double yres = 72.0 * height() / pageSize.height();
- double n = xres < yres ? xres : yres;
- if (n > ZoomMaxDpi)
- n = ZoomMaxDpi;
- if (n < ZoomMinDpi)
- n = ZoomMinDpi;
- if (n != dpi_) {
+ double n = 72.0 * width() / pageSize.width();
+ if (n != dpi_) {
dpi_ = n;
showPage();
}
}
-prefix_ int pykit::PDFWidget::getPDFWidth()
-{
- if (! document_)
- return 0;
- QSizeF pageSize (document_->page(currentPage_)->pageSizeF());
- return pageSize.width() * dpi_ / 72.0;
-}
-
-prefix_ int pykit::PDFWidget::getPDFHeight()
-{
- if (! document_)
- return 0;
- QSizeF pageSize (document_->page(currentPage_)->pageSizeF());
- return pageSize.height() * dpi_ / 72.0;
-}
-
-prefix_ void pykit::PDFWidget::resizeEvent(QResizeEvent *)
-{
- switch (zoomMode_) {
- case Manual:
- break;
- case Width:
- zoomWidth();
- break;
- case Height:
- zoomHeight();
- break;
- case Fit:
- zoomFit();
- break;
- }
- showPage();
-}
-
prefix_ void pykit::PDFWidget::netLoadDocument()
{
QNetworkReply * reply = static_cast<QNetworkReply*>(sender());
document_->setRenderHint(Poppler::Document::Antialiasing, true);
document_->setRenderHint(Poppler::Document::TextAntialiasing, true);
document_->setRenderHint(Poppler::Document::TextHinting, false);
- zoomFit();
+ resizeEvent(0);
showPage();
}
if (! document_)
return;
QImage image (document_->page(currentPage_)->renderToImage(
- dpi_, dpi_, x_, y_, width(), height()));
+ dpi_, dpi_, 0, 0, width(), height()));
setPixmap(QPixmap::fromImage(image));
}