diff options
author | Pino Toscano <pino@kde.org> | 2009-06-03 01:24:21 +0200 |
---|---|---|
committer | Pino Toscano <pino@kde.org> | 2009-06-03 01:24:21 +0200 |
commit | f69a4fe47d3478cccbc03e4ac0929c7eada681c0 (patch) | |
tree | 0bc9c301316e651203af0ef63f1e5901888fdff7 /qt4/demos | |
parent | 2f24ac0f4bbd6de1c9f137110b3ac2bd3b23b0b9 (diff) |
[Qt4 demo] Add a thumbnail dock widget
Useful to show the embedded page thumbnails in the document, if any.
Based on a patch by Shawn Rutledge <shawn.t.rutledge@gmail.com>, reworked by me to be a QListWidget showing the page items at their full size.
Diffstat (limited to 'qt4/demos')
-rw-r--r-- | qt4/demos/CMakeLists.txt | 1 | ||||
-rw-r--r-- | qt4/demos/thumbnails.cpp | 84 | ||||
-rw-r--r-- | qt4/demos/thumbnails.h | 51 | ||||
-rw-r--r-- | qt4/demos/viewer.cpp | 11 |
4 files changed, 146 insertions, 1 deletions
diff --git a/qt4/demos/CMakeLists.txt b/qt4/demos/CMakeLists.txt index 59b3f610..76accf81 100644 --- a/qt4/demos/CMakeLists.txt +++ b/qt4/demos/CMakeLists.txt @@ -19,6 +19,7 @@ set(poppler_qt4viewer_SRCS optcontent.cpp pageview.cpp permissions.cpp + thumbnails.cpp toc.cpp viewer.cpp ) diff --git a/qt4/demos/thumbnails.cpp b/qt4/demos/thumbnails.cpp new file mode 100644 index 00000000..ba82c2da --- /dev/null +++ b/qt4/demos/thumbnails.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2009, Shawn Rutledge <shawn.t.rutledge@gmail.com> + * Copyright (C) 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 + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "thumbnails.h" + +#include <poppler-qt4.h> + +#include <QtGui/QListWidget> + +static const int PageRole = Qt::UserRole + 1; + +ThumbnailsDock::ThumbnailsDock(QWidget *parent) + : AbstractInfoDock(parent) +{ + m_list = new QListWidget(this); + setWidget(m_list); + setWindowTitle(tr("Thumbnails")); + m_list->setViewMode(QListView::ListMode); + m_list->setMovement(QListView::Static); + m_list->setVerticalScrollMode(QListView::ScrollPerPixel); + connect(m_list, SIGNAL(itemActivated(QListWidgetItem*)), + this, SLOT(slotItemActivated(QListWidgetItem*))); +} + +ThumbnailsDock::~ThumbnailsDock() +{ +} + +void ThumbnailsDock::fillInfo() +{ + const int num = document()->numPages(); + QSize maxSize; + for (int i = 0; i < num; ++i) { + const Poppler::Page *page = document()->page(i); + const QImage image = page->thumbnail(); + if (!image.isNull()) { + QListWidgetItem *item = new QListWidgetItem(); + item->setText(QString::number(i + 1)); + item->setData(Qt::DecorationRole, QPixmap::fromImage(image)); + item->setData(PageRole, i); + m_list->addItem(item); + maxSize.setWidth(qMax(maxSize.width(), image.width())); + maxSize.setHeight(qMax(maxSize.height(), image.height())); + } + delete page; + } + if (num > 0) { + m_list->setGridSize(maxSize); + m_list->setIconSize(maxSize); + } +} + +void ThumbnailsDock::documentClosed() +{ + m_list->clear(); + AbstractInfoDock::documentClosed(); +} + +void ThumbnailsDock::slotItemActivated(QListWidgetItem *item) +{ + if (!item) { + return; + } + + emit pageClicked(item->data(PageRole).toInt()); +} + +#include "thumbnails.moc" diff --git a/qt4/demos/thumbnails.h b/qt4/demos/thumbnails.h new file mode 100644 index 00000000..e426b124 --- /dev/null +++ b/qt4/demos/thumbnails.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2009, Shawn Rutledge <shawn.t.rutledge@gmail.com> + * Copyright (C) 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 + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef THUMBNAILS_H +#define THUMBNAILS_H + +#include "abstractinfodock.h" + +class QListWidget; +class QListWidgetItem; + +class ThumbnailsDock : public AbstractInfoDock +{ + Q_OBJECT + +public: + ThumbnailsDock(QWidget *parent = 0); + ~ThumbnailsDock(); + + /*virtual*/ void documentClosed(); + +Q_SIGNALS: + void pageClicked(int page); + +protected: + /*virtual*/ void fillInfo(); + +private Q_SLOTS: + void slotItemActivated(QListWidgetItem *item); + +private: + QListWidget *m_list; +}; + +#endif diff --git a/qt4/demos/viewer.cpp b/qt4/demos/viewer.cpp index 61cea0ae..c85e0796 100644 --- a/qt4/demos/viewer.cpp +++ b/qt4/demos/viewer.cpp @@ -1,6 +1,7 @@ /* - * Copyright (C) 2008, Pino Toscano <pino@kde.org> + * Copyright (C) 2008-2009, Pino Toscano <pino@kde.org> * Copyright (C) 2008, Albert Astals Cid <aacid@kde.org> + * Copyright (C) 2009, Shawn Rutledge <shawn.t.rutledge@gmail.com> * * 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 @@ -27,6 +28,7 @@ #include "optcontent.h" #include "pageview.h" #include "permissions.h" +#include "thumbnails.h" #include "toc.h" #include <poppler-qt4.h> @@ -117,6 +119,13 @@ PdfViewer::PdfViewer() viewMenu->addAction(permissionsDock->toggleViewAction()); m_observers.append(permissionsDock); + ThumbnailsDock *thumbnailsDock = new ThumbnailsDock(this); + addDockWidget(Qt::LeftDockWidgetArea, thumbnailsDock); + thumbnailsDock->hide(); + viewMenu->addAction(thumbnailsDock->toggleViewAction()); + m_observers.append(thumbnailsDock); + connect(thumbnailsDock, SIGNAL(pageClicked(int)), view, SLOT(setPage(int))); + EmbeddedFilesDock *embfilesDock = new EmbeddedFilesDock(this); addDockWidget(Qt::BottomDockWidgetArea, embfilesDock); embfilesDock->hide(); |