1 /*
2 * Copyright (C) 2009, Shawn Rutledge <shawn.t.rutledge@gmail.com>
3 * Copyright (C) 2009, Pino Toscano <pino@kde.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #include "thumbnails.h"
21
22 #include <poppler-qt4.h>
23
24 #include <QtGui/QListWidget>
25
26 static const int PageRole = Qt::UserRole + 1;
27
ThumbnailsDock(QWidget * parent)28 ThumbnailsDock::ThumbnailsDock(QWidget *parent)
29 : AbstractInfoDock(parent)
30 {
31 m_list = new QListWidget(this);
32 setWidget(m_list);
33 setWindowTitle(tr("Thumbnails"));
34 m_list->setViewMode(QListView::ListMode);
35 m_list->setMovement(QListView::Static);
36 m_list->setVerticalScrollMode(QListView::ScrollPerPixel);
37 connect(m_list, SIGNAL(itemActivated(QListWidgetItem*)),
38 this, SLOT(slotItemActivated(QListWidgetItem*)));
39 }
40
~ThumbnailsDock()41 ThumbnailsDock::~ThumbnailsDock()
42 {
43 }
44
fillInfo()45 void ThumbnailsDock::fillInfo()
46 {
47 const int num = document()->numPages();
48 QSize maxSize;
49 for (int i = 0; i < num; ++i) {
50 const Poppler::Page *page = document()->page(i);
51 const QImage image = page->thumbnail();
52 if (!image.isNull()) {
53 QListWidgetItem *item = new QListWidgetItem();
54 item->setText(QString::number(i + 1));
55 item->setData(Qt::DecorationRole, QPixmap::fromImage(image));
56 item->setData(PageRole, i);
57 m_list->addItem(item);
58 maxSize.setWidth(qMax(maxSize.width(), image.width()));
59 maxSize.setHeight(qMax(maxSize.height(), image.height()));
60 }
61 delete page;
62 }
63 if (num > 0) {
64 m_list->setGridSize(maxSize);
65 m_list->setIconSize(maxSize);
66 }
67 }
68
documentClosed()69 void ThumbnailsDock::documentClosed()
70 {
71 m_list->clear();
72 AbstractInfoDock::documentClosed();
73 }
74
slotItemActivated(QListWidgetItem * item)75 void ThumbnailsDock::slotItemActivated(QListWidgetItem *item)
76 {
77 if (!item) {
78 return;
79 }
80
81 setPage(item->data(PageRole).toInt());
82 }
83
84 #include "thumbnails.moc"
85