2
* Copyright (C) 2009, Shawn Rutledge <shawn.t.rutledge@gmail.com>
3
* Copyright (C) 2009, Pino Toscano <pino@kde.org>
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)
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.
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.
20
#include "thumbnails.h"
22
#include <poppler-qt4.h>
24
#include <QtGui/QListWidget>
26
static const int PageRole = Qt::UserRole + 1;
28
ThumbnailsDock::ThumbnailsDock(QWidget *parent)
29
: AbstractInfoDock(parent)
31
m_list = new QListWidget(this);
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*)));
41
ThumbnailsDock::~ThumbnailsDock()
45
void ThumbnailsDock::fillInfo()
47
const int num = document()->numPages();
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()));
64
m_list->setGridSize(maxSize);
65
m_list->setIconSize(maxSize);
69
void ThumbnailsDock::documentClosed()
72
AbstractInfoDock::documentClosed();
75
void ThumbnailsDock::slotItemActivated(QListWidgetItem *item)
81
setPage(item->data(PageRole).toInt());
84
#include "thumbnails.moc"