summaryrefslogtreecommitdiff
path: root/qt4
diff options
context:
space:
mode:
authorPino Toscano <pino@kde.org>2009-06-28 19:08:02 +0200
committerPino Toscano <pino@kde.org>2009-06-28 19:08:02 +0200
commita98de97137cb343182bd03c443fc08ff4e0fd9a5 (patch)
tree4deb3f9affe2de86a256633c6cbba26bf4d6390a /qt4
parent40002d2c765398869a3b7d8d92715f0608e39ab3 (diff)
[Qt4 demo] add a zoom combobox
Diffstat (limited to 'qt4')
-rw-r--r--qt4/demos/navigationtoolbar.cpp33
-rw-r--r--qt4/demos/navigationtoolbar.h7
-rw-r--r--qt4/demos/pageview.cpp14
-rw-r--r--qt4/demos/pageview.h6
-rw-r--r--qt4/demos/viewer.cpp2
5 files changed, 57 insertions, 5 deletions
diff --git a/qt4/demos/navigationtoolbar.cpp b/qt4/demos/navigationtoolbar.cpp
index 65a4c544..ce7fb2e2 100644
--- a/qt4/demos/navigationtoolbar.cpp
+++ b/qt4/demos/navigationtoolbar.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, Pino Toscano <pino@kde.org>
+ * Copyright (C) 2008-2009, Pino Toscano <pino@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 3c79de64..3469f01b 100644
--- a/qt4/demos/navigationtoolbar.h
+++ b/qt4/demos/navigationtoolbar.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, Pino Toscano <pino@kde.org>
+ * Copyright (C) 2008-2009, Pino Toscano <pino@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 3420a63f..3c22ab44 100644
--- a/qt4/demos/pageview.cpp
+++ b/qt4/demos/pageview.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, Pino Toscano <pino@kde.org>
+ * Copyright (C) 2008-2009, Pino Toscano <pino@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 abf5a507..018f2460 100644
--- a/qt4/demos/pageview.h
+++ b/qt4/demos/pageview.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, Pino Toscano <pino@kde.org>
+ * Copyright (C) 2008-2009, Pino Toscano <pino@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 8792393d..0201eea3 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);