Changeset View
Changeset View
Standalone View
Standalone View
lib/document/jpegdocumentloadedimpl.cpp
Context not available. | |||||
28 | // KDE | 28 | // KDE | ||
---|---|---|---|---|---|
29 | 29 | | |||
30 | // Local | 30 | // Local | ||
31 | #include "jpegcontent.h" | 31 | #include "exiv2imageloader.h" | ||
32 | 32 | | |||
33 | namespace Gwenview | 33 | namespace Gwenview | ||
34 | { | 34 | { | ||
35 | 35 | | |||
36 | struct JpegDocumentLoadedImplPrivate | 36 | struct JpegDocumentLoadedImplPrivate | ||
37 | { | 37 | { | ||
38 | JpegContent* mJpegContent; | 38 | std::unique_ptr<Exiv2ImageLoader> mExivContent; | ||
39 | }; | 39 | }; | ||
40 | 40 | | |||
41 | JpegDocumentLoadedImpl::JpegDocumentLoadedImpl(Document* doc, JpegContent* jpegContent) | 41 | JpegDocumentLoadedImpl::JpegDocumentLoadedImpl(Document* doc, std::unique_ptr<Exiv2ImageLoader>&& exivContent) | ||
42 | : DocumentLoadedImpl(doc, QByteArray() /* rawData */) | 42 | : DocumentLoadedImpl(doc, QByteArray() /* rawData */) | ||
43 | , d(new JpegDocumentLoadedImplPrivate) | 43 | , d(new JpegDocumentLoadedImplPrivate) | ||
44 | { | 44 | { | ||
45 | Q_ASSERT(jpegContent); | 45 | Q_ASSERT(exivContent); | ||
46 | d->mJpegContent = jpegContent; | 46 | d->mExivContent = std::move(exivContent); | ||
47 | } | 47 | } | ||
48 | 48 | | |||
49 | JpegDocumentLoadedImpl::~JpegDocumentLoadedImpl() | 49 | JpegDocumentLoadedImpl::~JpegDocumentLoadedImpl() | ||
50 | { | 50 | { | ||
51 | delete d->mJpegContent; | | |||
52 | delete d; | 51 | delete d; | ||
53 | } | 52 | } | ||
54 | 53 | | |||
55 | bool JpegDocumentLoadedImpl::saveInternal(QIODevice* device, const QByteArray& format) | 54 | bool JpegDocumentLoadedImpl::saveInternal(QIODevice* device, const QByteArray& format) | ||
56 | { | 55 | { | ||
57 | if (format == "jpeg") { | 56 | bool ok = d->mExivContent->save(device); | ||
58 | if (!d->mJpegContent->thumbnail().isNull()) { | 57 | if (ok) { | ||
59 | QImage thumbnail = document()->image().scaled(128, 128, Qt::KeepAspectRatio); | 58 | setDocumentFormat(format); | ||
60 | d->mJpegContent->setThumbnail(thumbnail); | | |||
61 | } | | |||
62 | | ||||
63 | bool ok = d->mJpegContent->save(device); | | |||
64 | if (!ok) { | | |||
65 | setDocumentErrorString(d->mJpegContent->errorString()); | | |||
66 | } | | |||
67 | return ok; | | |||
68 | } else { | 59 | } else { | ||
69 | return DocumentLoadedImpl::saveInternal(device, format); | 60 | setDocumentErrorString(d->mExivContent->errorMessage()); | ||
70 | } | 61 | } | ||
62 | return ok; | ||||
71 | } | 63 | } | ||
72 | 64 | | |||
73 | void JpegDocumentLoadedImpl::setImage(const QImage& image) | 65 | void JpegDocumentLoadedImpl::setImage(const QImage& image) | ||
74 | { | 66 | { | ||
75 | d->mJpegContent->setImage(image); | 67 | d->mExivContent->setImage(image); | ||
76 | DocumentLoadedImpl::setImage(image); | 68 | DocumentLoadedImpl::setImage(image); | ||
77 | } | 69 | } | ||
78 | 70 | | |||
Context not available. | |||||
81 | DocumentLoadedImpl::applyTransformation(orientation); | 73 | DocumentLoadedImpl::applyTransformation(orientation); | ||
82 | 74 | | |||
83 | // Apply Exif transformation first to normalize image | 75 | // Apply Exif transformation first to normalize image | ||
84 | d->mJpegContent->transform(d->mJpegContent->orientation()); | 76 | d->mExivContent->transform(d->mExivContent->orientation()); | ||
85 | d->mJpegContent->resetOrientation(); | 77 | d->mExivContent->resetOrientation(); | ||
86 | 78 | | |||
87 | d->mJpegContent->transform(orientation); | 79 | d->mExivContent->transform(orientation); | ||
88 | } | | |||
89 | | ||||
90 | QByteArray JpegDocumentLoadedImpl::rawData() const | | |||
91 | { | | |||
92 | return d->mJpegContent->rawData(); | | |||
93 | } | 80 | } | ||
94 | 81 | | |||
95 | } // namespace | 82 | } // namespace | ||
Context not available. |