1
/* This file is part of the KDE project
2
Copyright (c) 2001 Simon Hausmann <hausmann@kde.org>
3
Copyright (C) 2002, 2003 Nicolas GOUTTE <goutte@kde.org>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library 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 GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
23
#include "PictureKey.h"
24
#include "PictureShared.h"
25
#include "PictureBase.h"
34
#include <kio/netaccess.h>
36
uint Picture::uniqueValue = 0;
39
Picture::Picture(void) : m_sharedData(NULL)
41
m_uniqueName = "Pictures" + QString::number(uniqueValue++);
44
Picture::~Picture(void)
49
QString Picture::uniqueName() const
54
Picture::Picture(const Picture &other)
60
void Picture::assignPictureId(uint _id)
63
m_sharedData->assignPictureId(_id);
66
QString Picture::uniquePictureId() const
69
return m_sharedData->uniquePictureId();
74
Picture& Picture::operator=(const Picture & other)
76
//kDebug(30508) <<"Picture::= before";
77
if (other.m_sharedData)
78
other.linkSharedData();
81
m_sharedData = other.m_sharedData;
83
//kDebug(30508) <<"Picture::= after";
87
void Picture::unlinkSharedData(void)
89
if (m_sharedData && m_sharedData->deref())
95
void Picture::linkSharedData(void) const
101
void Picture::createSharedData(void)
104
m_sharedData = new PictureShared();
105
// Do not call m_sharedData->ref()
109
PictureType::Type Picture::getType(void) const
112
return m_sharedData->getType();
113
return PictureType::TypeUnknown;
116
PictureKey Picture::getKey(void) const
121
void Picture::setKey(const PictureKey& key)
127
bool Picture::isNull(void) const
130
return m_sharedData->isNull();
134
void Picture::draw(QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool fastMode)
137
m_sharedData->draw(painter, x, y, width, height, sx, sy, sw, sh, fastMode);
140
kWarning(30508) << "Drawing white rectangle! (Picture::draw)";
142
painter.setBrush(QColor(255, 255, 255));
143
painter.drawRect(x, y, width, height);
148
bool Picture::loadXpm(QIODevice* io)
150
kDebug(30508) << "Picture::loadXpm";
152
kError(30508) << "No QIODevice!" << endl;
156
return m_sharedData->loadXpm(io);
159
bool Picture::save(QIODevice* io) const
164
return m_sharedData->save(io);
168
bool Picture::saveAsBase64(KoXmlWriter& writer) const
171
return m_sharedData->saveAsBase64(writer);
175
void Picture::clear(void)
180
void Picture::clearAndSetMode(const QString& newMode)
183
m_sharedData->clearAndSetMode(newMode);
186
QString Picture::getExtension(void) const
189
return m_sharedData->getExtension();
190
return "null"; // Just a dummy
193
QString Picture::getMimeType(void) const
196
return m_sharedData->getMimeType();
197
return QString(NULL_MIME_TYPE);
200
bool Picture::load(QIODevice* io, const QString& extension)
202
kDebug(30508) << "Picture::load(QIODevice*, const QString&)" << extension;
205
return m_sharedData->load(io, extension);
208
bool Picture::loadFromFile(const QString& fileName)
210
kDebug(30508) << "Picture::loadFromFile" << fileName;
212
return m_sharedData->loadFromFile(fileName);
215
bool Picture::loadFromBase64(const QByteArray& str)
218
return m_sharedData->loadFromBase64(str);
221
QSize Picture::getOriginalSize(void) const
224
return m_sharedData->getOriginalSize();
228
QPixmap Picture::generatePixmap(const QSize& size, bool smoothScale)
231
return m_sharedData->generatePixmap(size, smoothScale);
235
bool Picture::setKeyAndDownloadPicture(const KUrl& url, QWidget *window)
240
if (KIO::NetAccess::download(url, tmpFileName, window)) {
242
key.setKeyFromFile(tmpFileName);
244
result = loadFromFile(tmpFileName);
245
KIO::NetAccess::removeTempFile(tmpFileName);
251
QMimeData* Picture::dragObject(QWidget *dragSource, const char *name)
254
return m_sharedData->dragObject(dragSource, name);
258
QImage Picture::generateImage(const QSize& size)
261
return m_sharedData->generateImage(size);
265
bool Picture::hasAlphaBuffer() const
268
return m_sharedData->hasAlphaBuffer();
272
void Picture::setAlphaBuffer(bool enable)
275
m_sharedData->setAlphaBuffer(enable);
278
QImage Picture::createAlphaMask(Qt::ImageConversionFlags flags) const
281
return m_sharedData->createAlphaMask(flags);
285
void Picture::clearCache(void)
288
m_sharedData->clearCache();