1
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
3
Gwenview: an image viewer
4
Copyright 2010 Aurélien Gâteau <agateau@kde.org>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License
8
as published by the Free Software Foundation; either version 2
9
of the License, or (at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
22
#include "documentinfoprovider.moc"
30
#include <lib/document/documentfactory.h>
31
#include <lib/semanticinfo/sorteddirmodel.h>
36
struct DocumentInfoProviderPrivate {
37
SortedDirModel* mDirModel;
41
DocumentInfoProvider::DocumentInfoProvider(SortedDirModel* model)
42
: AbstractDocumentInfoProvider(model)
43
, d(new DocumentInfoProviderPrivate) {
45
connect(DocumentFactory::instance(), SIGNAL(documentBusyStateChanged(const KUrl&, bool)),
46
SLOT(emitBusyStateChanged(const KUrl&, bool)) );
48
connect(DocumentFactory::instance(), SIGNAL(documentChanged(const KUrl&)),
49
SLOT(emitDocumentChanged(const KUrl&)) );
53
DocumentInfoProvider::~DocumentInfoProvider() {
58
void DocumentInfoProvider::thumbnailForDocument(const KUrl& url, ThumbnailGroup::Enum group, QPixmap* outPix, QSize* outFullSize) const {
60
Q_ASSERT(outFullSize);
62
*outFullSize = QSize();
63
DocumentFactory* factory = DocumentFactory::instance();
64
const int pixelSize = ThumbnailGroup::pixelSize(group);
66
if (!factory->hasUrl(url)) {
70
Document::Ptr doc = factory->load(url);
71
if (doc->loadingState() != Document::Loaded) {
75
QImage image = doc->image();
76
if (image.width() > pixelSize || image.height() > pixelSize) {
77
image = image.scaled(pixelSize, pixelSize, Qt::KeepAspectRatio);
79
*outPix = QPixmap::fromImage(image);
80
*outFullSize = doc->size();
84
bool DocumentInfoProvider::isModified(const KUrl& url) {
85
DocumentFactory* factory = DocumentFactory::instance();
87
if (factory->hasUrl(url)) {
88
Document::Ptr doc = factory->load(url);
89
return doc->loadingState() == Document::Loaded && doc->isModified();
96
bool DocumentInfoProvider::isBusy(const KUrl& url) {
97
DocumentFactory* factory = DocumentFactory::instance();
99
if (factory->hasUrl(url)) {
100
Document::Ptr doc = factory->load(url);
101
return doc->isBusy();
108
void DocumentInfoProvider::emitBusyStateChanged(const KUrl& url, bool busy) {
109
QModelIndex index = d->mDirModel->indexForUrl(url);
110
if (!index.isValid()) {
113
busyStateChanged(index, busy);
117
void DocumentInfoProvider::emitDocumentChanged(const KUrl& url) {
118
QModelIndex index = d->mDirModel->indexForUrl(url);
119
if (!index.isValid()) {
122
documentChanged(index);