~ubuntu-branches/ubuntu/precise/gwenview/precise-proposed

« back to all changes in this revision

Viewing changes to app/documentinfoprovider.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:54 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20111215141754-z043hyx69dulbggf
Tags: upstream-4.7.90
Import upstream version 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
 
1
// vim: set tabstop=4 shiftwidth=4 expandtab:
2
2
/*
3
3
Gwenview: an image viewer
4
4
Copyright 2010 Aurélien Gâteau <agateau@kde.org>
30
30
#include <lib/document/documentfactory.h>
31
31
#include <lib/semanticinfo/sorteddirmodel.h>
32
32
 
33
 
namespace Gwenview {
34
 
 
 
33
namespace Gwenview
 
34
{
35
35
 
36
36
struct DocumentInfoProviderPrivate {
37
 
        SortedDirModel* mDirModel;
 
37
    SortedDirModel* mDirModel;
38
38
};
39
39
 
40
 
 
41
40
DocumentInfoProvider::DocumentInfoProvider(SortedDirModel* model)
42
41
: AbstractDocumentInfoProvider(model)
43
 
, d(new DocumentInfoProviderPrivate) {
44
 
        d->mDirModel = model;
45
 
        connect(DocumentFactory::instance(), SIGNAL(documentBusyStateChanged(const KUrl&, bool)),
46
 
                SLOT(emitBusyStateChanged(const KUrl&, bool)) );
47
 
 
48
 
        connect(DocumentFactory::instance(), SIGNAL(documentChanged(const KUrl&)),
49
 
                SLOT(emitDocumentChanged(const KUrl&)) );
50
 
}
51
 
 
52
 
 
53
 
DocumentInfoProvider::~DocumentInfoProvider() {
54
 
        delete d;
55
 
}
56
 
 
57
 
 
58
 
void DocumentInfoProvider::thumbnailForDocument(const KUrl& url, ThumbnailGroup::Enum group, QPixmap* outPix, QSize* outFullSize) const {
59
 
        Q_ASSERT(outPix);
60
 
        Q_ASSERT(outFullSize);
61
 
        *outPix = QPixmap();
62
 
        *outFullSize = QSize();
63
 
        DocumentFactory* factory = DocumentFactory::instance();
64
 
        const int pixelSize = ThumbnailGroup::pixelSize(group);
65
 
 
66
 
        if (!factory->hasUrl(url)) {
67
 
                return;
68
 
        }
69
 
 
70
 
        Document::Ptr doc = factory->load(url);
71
 
        if (doc->loadingState() != Document::Loaded) {
72
 
                return;
73
 
        }
74
 
 
75
 
        QImage image = doc->image();
76
 
        if (image.width() > pixelSize || image.height() > pixelSize) {
77
 
                image = image.scaled(pixelSize, pixelSize, Qt::KeepAspectRatio);
78
 
        }
79
 
        *outPix = QPixmap::fromImage(image);
80
 
        *outFullSize = doc->size();
81
 
}
82
 
 
83
 
 
84
 
bool DocumentInfoProvider::isModified(const KUrl& url) {
85
 
        DocumentFactory* factory = DocumentFactory::instance();
86
 
 
87
 
        if (factory->hasUrl(url)) {
88
 
                Document::Ptr doc = factory->load(url);
89
 
                return doc->loadingState() == Document::Loaded && doc->isModified();
90
 
        } else {
91
 
                return false;
92
 
        }
93
 
}
94
 
 
95
 
 
96
 
bool DocumentInfoProvider::isBusy(const KUrl& url) {
97
 
        DocumentFactory* factory = DocumentFactory::instance();
98
 
 
99
 
        if (factory->hasUrl(url)) {
100
 
                Document::Ptr doc = factory->load(url);
101
 
                return doc->isBusy();
102
 
        } else {
103
 
                return false;
104
 
        }
105
 
}
106
 
 
107
 
 
108
 
void DocumentInfoProvider::emitBusyStateChanged(const KUrl& url, bool busy) {
109
 
        QModelIndex index = d->mDirModel->indexForUrl(url);
110
 
        if (!index.isValid()) {
111
 
                return;
112
 
        }
113
 
        busyStateChanged(index, busy);
114
 
}
115
 
 
116
 
 
117
 
void DocumentInfoProvider::emitDocumentChanged(const KUrl& url) {
118
 
        QModelIndex index = d->mDirModel->indexForUrl(url);
119
 
        if (!index.isValid()) {
120
 
                return;
121
 
        }
122
 
        documentChanged(index);
123
 
}
124
 
 
 
42
, d(new DocumentInfoProviderPrivate)
 
43
{
 
44
    d->mDirModel = model;
 
45
    connect(DocumentFactory::instance(), SIGNAL(documentBusyStateChanged(KUrl, bool)),
 
46
            SLOT(emitBusyStateChanged(KUrl, bool)));
 
47
 
 
48
    connect(DocumentFactory::instance(), SIGNAL(documentChanged(KUrl)),
 
49
            SLOT(emitDocumentChanged(KUrl)));
 
50
}
 
51
 
 
52
DocumentInfoProvider::~DocumentInfoProvider()
 
53
{
 
54
    delete d;
 
55
}
 
56
 
 
57
void DocumentInfoProvider::thumbnailForDocument(const KUrl& url, ThumbnailGroup::Enum group, QPixmap* outPix, QSize* outFullSize) const
 
58
{
 
59
    Q_ASSERT(outPix);
 
60
    Q_ASSERT(outFullSize);
 
61
    *outPix = QPixmap();
 
62
    *outFullSize = QSize();
 
63
    DocumentFactory* factory = DocumentFactory::instance();
 
64
    const int pixelSize = ThumbnailGroup::pixelSize(group);
 
65
 
 
66
    if (!factory->hasUrl(url)) {
 
67
        return;
 
68
    }
 
69
 
 
70
    Document::Ptr doc = factory->load(url);
 
71
    if (doc->loadingState() != Document::Loaded) {
 
72
        return;
 
73
    }
 
74
 
 
75
    QImage image = doc->image();
 
76
    if (image.width() > pixelSize || image.height() > pixelSize) {
 
77
        image = image.scaled(pixelSize, pixelSize, Qt::KeepAspectRatio);
 
78
    }
 
79
    *outPix = QPixmap::fromImage(image);
 
80
    *outFullSize = doc->size();
 
81
}
 
82
 
 
83
bool DocumentInfoProvider::isModified(const KUrl& url)
 
84
{
 
85
    DocumentFactory* factory = DocumentFactory::instance();
 
86
 
 
87
    if (factory->hasUrl(url)) {
 
88
        Document::Ptr doc = factory->load(url);
 
89
        return doc->loadingState() == Document::Loaded && doc->isModified();
 
90
    } else {
 
91
        return false;
 
92
    }
 
93
}
 
94
 
 
95
bool DocumentInfoProvider::isBusy(const KUrl& url)
 
96
{
 
97
    DocumentFactory* factory = DocumentFactory::instance();
 
98
 
 
99
    if (factory->hasUrl(url)) {
 
100
        Document::Ptr doc = factory->load(url);
 
101
        return doc->isBusy();
 
102
    } else {
 
103
        return false;
 
104
    }
 
105
}
 
106
 
 
107
void DocumentInfoProvider::emitBusyStateChanged(const KUrl& url, bool busy)
 
108
{
 
109
    QModelIndex index = d->mDirModel->indexForUrl(url);
 
110
    if (!index.isValid()) {
 
111
        return;
 
112
    }
 
113
    busyStateChanged(index, busy);
 
114
}
 
115
 
 
116
void DocumentInfoProvider::emitDocumentChanged(const KUrl& url)
 
117
{
 
118
    QModelIndex index = d->mDirModel->indexForUrl(url);
 
119
    if (!index.isValid()) {
 
120
        return;
 
121
    }
 
122
    documentChanged(index);
 
123
}
125
124
 
126
125
} // namespace