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

« back to all changes in this revision

Viewing changes to lib/document/documentloadedimpl.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 2007 Aurélien Gâteau <agateau@kde.org>
37
37
#include "imageutils.h"
38
38
#include "savejob.h"
39
39
 
40
 
namespace Gwenview {
41
 
 
 
40
namespace Gwenview
 
41
{
42
42
 
43
43
struct DocumentLoadedImplPrivate {
44
 
        QByteArray mRawData;
45
 
        bool mQuietInit;
 
44
    QByteArray mRawData;
 
45
    bool mQuietInit;
46
46
};
47
47
 
48
 
 
49
48
DocumentLoadedImpl::DocumentLoadedImpl(Document* document, const QByteArray& rawData, bool quietInit)
50
49
: AbstractDocumentImpl(document)
51
 
, d(new DocumentLoadedImplPrivate) {
52
 
        if (document->keepRawData()) {
53
 
                d->mRawData = rawData;
54
 
        }
55
 
        d->mQuietInit = quietInit;
56
 
}
57
 
 
58
 
 
59
 
DocumentLoadedImpl::~DocumentLoadedImpl() {
60
 
        delete d;
61
 
}
62
 
 
63
 
 
64
 
void DocumentLoadedImpl::init() {
65
 
        if (!d->mQuietInit) {
66
 
                emit imageRectUpdated(document()->image().rect());
67
 
                emit loaded();
68
 
        }
69
 
}
70
 
 
71
 
 
72
 
bool DocumentLoadedImpl::isEditable() const {
73
 
        return true;
74
 
}
75
 
 
76
 
 
77
 
Document::LoadingState DocumentLoadedImpl::loadingState() const {
78
 
        return Document::Loaded;
79
 
}
80
 
 
81
 
 
82
 
bool DocumentLoadedImpl::saveInternal(QIODevice* device, const QByteArray& format) {
83
 
        QImageWriter writer(device, format);
84
 
        bool ok = writer.write(document()->image());
85
 
        if (ok) {
86
 
                setDocumentFormat(format);
87
 
        } else {
88
 
                setDocumentErrorString(writer.errorString());
89
 
        }
90
 
        return ok;
91
 
}
92
 
 
93
 
 
94
 
DocumentJob* DocumentLoadedImpl::save(const KUrl& url, const QByteArray& format) {
95
 
        return new SaveJob(this, url, format);
96
 
}
97
 
 
98
 
 
99
 
AbstractDocumentEditor* DocumentLoadedImpl::editor() {
100
 
        return this;
101
 
}
102
 
 
103
 
 
104
 
void DocumentLoadedImpl::setImage(const QImage& image) {
105
 
        setDocumentImage(image);
106
 
        imageRectUpdated(image.rect());
107
 
}
108
 
 
109
 
 
110
 
void DocumentLoadedImpl::applyTransformation(Orientation orientation) {
111
 
        QImage image = document()->image();
112
 
        QMatrix matrix = ImageUtils::transformMatrix(orientation);
113
 
        image = image.transformed(matrix);
114
 
        setDocumentImage(image);
115
 
        imageRectUpdated(image.rect());
116
 
}
117
 
 
118
 
 
119
 
QByteArray DocumentLoadedImpl::rawData() const {
120
 
        return d->mRawData;
121
 
}
122
 
 
 
50
, d(new DocumentLoadedImplPrivate)
 
51
{
 
52
    if (document->keepRawData()) {
 
53
        d->mRawData = rawData;
 
54
    }
 
55
    d->mQuietInit = quietInit;
 
56
}
 
57
 
 
58
DocumentLoadedImpl::~DocumentLoadedImpl()
 
59
{
 
60
    delete d;
 
61
}
 
62
 
 
63
void DocumentLoadedImpl::init()
 
64
{
 
65
    if (!d->mQuietInit) {
 
66
        emit imageRectUpdated(document()->image().rect());
 
67
        emit loaded();
 
68
    }
 
69
}
 
70
 
 
71
bool DocumentLoadedImpl::isEditable() const
 
72
{
 
73
    return true;
 
74
}
 
75
 
 
76
Document::LoadingState DocumentLoadedImpl::loadingState() const
 
77
{
 
78
    return Document::Loaded;
 
79
}
 
80
 
 
81
bool DocumentLoadedImpl::saveInternal(QIODevice* device, const QByteArray& format)
 
82
{
 
83
    QImageWriter writer(device, format);
 
84
    bool ok = writer.write(document()->image());
 
85
    if (ok) {
 
86
        setDocumentFormat(format);
 
87
    } else {
 
88
        setDocumentErrorString(writer.errorString());
 
89
    }
 
90
    return ok;
 
91
}
 
92
 
 
93
DocumentJob* DocumentLoadedImpl::save(const KUrl& url, const QByteArray& format)
 
94
{
 
95
    return new SaveJob(this, url, format);
 
96
}
 
97
 
 
98
AbstractDocumentEditor* DocumentLoadedImpl::editor()
 
99
{
 
100
    return this;
 
101
}
 
102
 
 
103
void DocumentLoadedImpl::setImage(const QImage& image)
 
104
{
 
105
    setDocumentImage(image);
 
106
    imageRectUpdated(image.rect());
 
107
}
 
108
 
 
109
void DocumentLoadedImpl::applyTransformation(Orientation orientation)
 
110
{
 
111
    QImage image = document()->image();
 
112
    QMatrix matrix = ImageUtils::transformMatrix(orientation);
 
113
    image = image.transformed(matrix);
 
114
    setDocumentImage(image);
 
115
    imageRectUpdated(image.rect());
 
116
}
 
117
 
 
118
QByteArray DocumentLoadedImpl::rawData() const
 
119
{
 
120
    return d->mRawData;
 
121
}
123
122
 
124
123
} // namespace