[poppler] qt4/demos

Pino Toscano pino at kemper.freedesktop.org
Sun Jun 28 10:11:32 PDT 2009


 qt4/demos/navigationtoolbar.cpp |   33 ++++++++++++++++++++++++++++++++-
 qt4/demos/navigationtoolbar.h   |    7 ++++++-
 qt4/demos/pageview.cpp          |   14 ++++++++++++--
 qt4/demos/pageview.h            |    6 +++++-
 qt4/demos/viewer.cpp            |    2 ++
 5 files changed, 57 insertions(+), 5 deletions(-)

New commits:
commit a98de97137cb343182bd03c443fc08ff4e0fd9a5
Author: Pino Toscano <pino at kde.org>
Date:   Sun Jun 28 19:08:02 2009 +0200

    [Qt4 demo] add a zoom combobox

diff --git a/qt4/demos/navigationtoolbar.cpp b/qt4/demos/navigationtoolbar.cpp
index 65a4c54..ce7fb2e 100644
--- a/qt4/demos/navigationtoolbar.cpp
+++ b/qt4/demos/navigationtoolbar.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2008-2009, Pino Toscano <pino at kde.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -34,6 +34,26 @@ NavigationToolBar::NavigationToolBar(QWidget *parent)
     m_nextAct = addAction(tr("Next"), this, SLOT(slotGoNext()));
     m_lastAct = addAction(tr("Last"), this, SLOT(slotGoLast()));
 
+    addSeparator();
+
+    m_zoomCombo = new QComboBox(this);
+    m_zoomCombo->setEditable(true);
+    m_zoomCombo->addItem(tr("10%"));
+    m_zoomCombo->addItem(tr("25%"));
+    m_zoomCombo->addItem(tr("33%"));
+    m_zoomCombo->addItem(tr("50%"));
+    m_zoomCombo->addItem(tr("66%"));
+    m_zoomCombo->addItem(tr("75%"));
+    m_zoomCombo->addItem(tr("100%"));
+    m_zoomCombo->addItem(tr("125%"));
+    m_zoomCombo->addItem(tr("150%"));
+    m_zoomCombo->addItem(tr("200%"));
+    m_zoomCombo->addItem(tr("300%"));
+    m_zoomCombo->addItem(tr("400%"));
+    m_zoomCombo->setCurrentIndex(6); // "100%"
+    connect(m_zoomCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotZoomComboChanged(QString)));
+    addWidget(m_zoomCombo);
+
     documentClosed();
 }
 
@@ -95,4 +115,15 @@ void NavigationToolBar::slotComboActivated(int index)
     setPage(index);
 }
 
+void NavigationToolBar::slotZoomComboChanged(const QString &_text)
+{
+    QString text = _text;
+    text.remove(QLatin1Char('%'));
+    bool ok = false;
+    int value = text.toInt(&ok);
+    if (ok && value >= 10) {
+        emit zoomChanged(qreal(value) / 100);
+    }
+}
+
 #include "navigationtoolbar.moc"
diff --git a/qt4/demos/navigationtoolbar.h b/qt4/demos/navigationtoolbar.h
index 3c79de6..3469f01 100644
--- a/qt4/demos/navigationtoolbar.h
+++ b/qt4/demos/navigationtoolbar.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2008-2009, Pino Toscano <pino at kde.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -38,12 +38,16 @@ public:
     /*virtual*/ void documentClosed();
     /*virtual*/ void pageChanged(int page);
 
+Q_SIGNALS:
+    void zoomChanged(qreal value);
+
 private Q_SLOTS:
     void slotGoFirst();
     void slotGoPrev();
     void slotGoNext();
     void slotGoLast();
     void slotComboActivated(int index);
+    void slotZoomComboChanged(const QString &text);
 
 private:
     QAction *m_firstAct;
@@ -51,6 +55,7 @@ private:
     QComboBox *m_pageCombo;
     QAction *m_nextAct;
     QAction *m_lastAct;
+    QComboBox *m_zoomCombo;
 };
 
 #endif
diff --git a/qt4/demos/pageview.cpp b/qt4/demos/pageview.cpp
index 3420a63..3c22ab4 100644
--- a/qt4/demos/pageview.cpp
+++ b/qt4/demos/pageview.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2008-2009, Pino Toscano <pino at kde.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@
 
 PageView::PageView(QWidget *parent)
     : QScrollArea(parent)
+    , m_zoom(1.0)
 {
     m_imageLabel = new QLabel(this);
     m_imageLabel->resize(0, 0);
@@ -49,7 +50,10 @@ void PageView::documentClosed()
 void PageView::pageChanged(int page)
 {
     Poppler::Page *popplerPage = document()->page(page);
-    QImage image = popplerPage->renderToImage();
+    QSize pageSize = popplerPage->pageSize();
+    pageSize *= m_zoom;
+    const double res = 72.0 * m_zoom;
+    QImage image = popplerPage->renderToImage(res, res, 0, 0, pageSize.width(), pageSize.height());
     if (!image.isNull()) {
         m_imageLabel->resize(image.size());
         m_imageLabel->setPixmap(QPixmap::fromImage(image));
@@ -60,4 +64,10 @@ void PageView::pageChanged(int page)
     delete popplerPage;
 }
 
+void PageView::slotZoomChanged(qreal value)
+{
+    m_zoom = value;
+    reloadPage();
+}
+
 #include "pageview.moc"
diff --git a/qt4/demos/pageview.h b/qt4/demos/pageview.h
index abf5a50..018f246 100644
--- a/qt4/demos/pageview.h
+++ b/qt4/demos/pageview.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2008-2009, Pino Toscano <pino at kde.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -37,8 +37,12 @@ public:
     /*virtual*/ void documentClosed();
     /*virtual*/ void pageChanged(int page);
 
+private Q_SLOTS:
+    void slotZoomChanged(qreal value);
+
 private:
     QLabel *m_imageLabel;
+    qreal m_zoom;
 };
 
 #endif
diff --git a/qt4/demos/viewer.cpp b/qt4/demos/viewer.cpp
index 8792393..0201eea 100644
--- a/qt4/demos/viewer.cpp
+++ b/qt4/demos/viewer.cpp
@@ -147,6 +147,8 @@ PdfViewer::PdfViewer()
         obs->m_viewer = this;
     }
 
+    connect(navbar, SIGNAL(zoomChanged(qreal)), view, SLOT(slotZoomChanged(qreal)));
+
     // activate AA by default
     m_settingsTextAAAct->setChecked(true);
     m_settingsGfxAAAct->setChecked(true);


More information about the poppler mailing list