00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include <qpainter.h>
00022
#include <qfile.h>
00023
00024
#include <kdebug.h>
00025
#include <kurl.h>
00026
#include <kio/netaccess.h>
00027
00028
#include "koPictureKey.h"
00029
#include "koPictureBase.h"
00030
#include "koPictureShared.h"
00031
#include "koPicture.h"
00032
00033 KoPicture::KoPicture(
void) : m_sharedData(NULL)
00034 {
00035 }
00036
00037 KoPicture::~KoPicture(
void)
00038 {
00039 unlinkSharedData();
00040 }
00041
00042 KoPicture::KoPicture(
const KoPicture &other)
00043 {
00044 m_sharedData=NULL;
00045 (*this)=other;
00046 }
00047
00048 KoPicture&
KoPicture::operator=(
const KoPicture &other )
00049 {
00050
00051
if (other.
m_sharedData)
00052 other.
linkSharedData();
00053
if (m_sharedData)
00054 unlinkSharedData();
00055 m_sharedData=other.
m_sharedData;
00056 m_key=other.
m_key;
00057
00058
return *
this;
00059 }
00060
00061
void KoPicture::unlinkSharedData(
void)
00062 {
00063
if (m_sharedData && m_sharedData->deref())
00064
delete m_sharedData;
00065
00066 m_sharedData=NULL;
00067 }
00068
00069
void KoPicture::linkSharedData(
void)
const
00070
{
00071
if (m_sharedData)
00072 m_sharedData->ref();
00073 }
00074
00075
void KoPicture::createSharedData(
void)
00076 {
00077
if (!m_sharedData)
00078 {
00079 m_sharedData=
new KoPictureShared();
00080
00081 }
00082 }
00083
00084 KoPictureType::Type KoPicture::getType(
void)
const
00085
{
00086
if (m_sharedData)
00087
return m_sharedData->getType();
00088
return KoPictureType::TypeUnknown;
00089 }
00090
00091 KoPictureKey KoPicture::getKey(
void)
const
00092
{
00093
return m_key;
00094 }
00095
00096 void KoPicture::setKey(
const KoPictureKey& key)
00097 {
00098 m_key=key;
00099 }
00100
00101 bool KoPicture::isNull(
void)
const
00102
{
00103
if (m_sharedData)
00104
return m_sharedData->isNull();
00105
return true;
00106 }
00107
00108 void KoPicture::draw(
QPainter& painter,
int x,
int y,
int width,
int height,
int sx,
int sy,
int sw,
int sh,
bool fastMode)
00109 {
00110
if (m_sharedData)
00111 m_sharedData->draw(painter, x, y, width, height, sx, sy, sw, sh, fastMode);
00112
else
00113 {
00114
00115 kdWarning(30003) <<
"Drawing white rectangle! (KoPicture::draw)" << endl;
00116 painter.save();
00117 painter.setBrush(
QColor(255, 255, 255));
00118 painter.drawRect(x,y,width,height);
00119 painter.restore();
00120 }
00121 }
00122
00123 bool KoPicture::loadXpm(
QIODevice* io)
00124 {
00125 kdDebug(30003) <<
"KoPicture::loadXpm" << endl;
00126
if (!io)
00127 {
00128 kdError(30003) <<
"No QIODevice!" << endl;
00129
return false;
00130 }
00131 createSharedData();
00132
return m_sharedData->loadXpm(io);
00133 }
00134
00135 bool KoPicture::save(
QIODevice* io)
00136 {
00137
if (!io)
00138
return false;
00139
if (m_sharedData)
00140
return m_sharedData->save(io);
00141
return false;
00142 }
00143
00144 bool KoPicture::saveAsKOffice1Dot1(
QIODevice* io)
00145 {
00146
if (!io)
00147
return false;
00148
if (m_sharedData)
00149
return m_sharedData->saveAsKOffice1Dot1(io);
00150
return false;
00151 }
00152
00153 void KoPicture::clear(
void)
00154 {
00155 unlinkSharedData();
00156 }
00157
00158 void KoPicture::clearAndSetMode(
const QString& newMode)
00159 {
00160 createSharedData();
00161 m_sharedData->clearAndSetMode(newMode);
00162 }
00163
00164 QString KoPicture::getExtension(
void)
const
00165
{
00166
if (m_sharedData)
00167
return m_sharedData->getExtension();
00168
return "null";
00169 }
00170
00171
QString KoPicture::getExtensionAsKOffice1Dot1(
void)
const
00172
{
00173
if (m_sharedData)
00174
return m_sharedData->getExtensionAsKOffice1Dot1();
00175
return "null";
00176 }
00177
00178 QString KoPicture::getMimeType(
void)
const
00179
{
00180
if (m_sharedData)
00181
return m_sharedData->getMimeType();
00182
return QString(NULL_MIME_TYPE);
00183 }
00184
00185
bool KoPicture::load(
QIODevice* io,
const QString& extension)
00186 {
00187 kdDebug(30003) <<
"KoPicture::load(QIODevice*, const QString&) " << extension << endl;
00188 createSharedData();
00189
00190
return m_sharedData->load(io,extension);
00191 }
00192
00193 bool KoPicture::loadFromFile(
const QString& fileName)
00194 {
00195 kdDebug(30003) <<
"KoPicture::loadFromFile " << fileName << endl;
00196 createSharedData();
00197
return m_sharedData->loadFromFile(fileName);
00198 }
00199
00200 QSize KoPicture::getOriginalSize(
void)
const
00201
{
00202
if (m_sharedData)
00203
return m_sharedData->getOriginalSize();
00204
return QSize(0,0);
00205 }
00206
00207 QPixmap KoPicture::generatePixmap(
const QSize& size,
bool smoothScale)
00208 {
00209
if (m_sharedData)
00210
return m_sharedData->generatePixmap(size, smoothScale);
00211
return QPixmap();
00212 }
00213
00214 bool KoPicture::isClipartAsKOffice1Dot1(
void)
const
00215
{
00216
if (m_sharedData)
00217
return m_sharedData->isClipartAsKOffice1Dot1();
00218
return false;
00219 }
00220
00221 bool KoPicture::setKeyAndDownloadPicture(
const KURL& url)
00222 {
00223
bool result=
false;
00224
00225
QString tmpFileName;
00226
if ( KIO::NetAccess::download(url, tmpFileName) )
00227 {
00228
KoPictureKey key;
00229 key.
setKeyFromFile( tmpFileName );
00230
setKey( key );
00231 result=
loadFromFile( tmpFileName );
00232 KIO::NetAccess::removeTempFile( tmpFileName );
00233 }
00234
00235
return result;
00236 }
00237
00238 QDragObject*
KoPicture::dragObject(
QWidget *dragSource,
const char *name )
00239 {
00240
if (m_sharedData)
00241
return m_sharedData->dragObject( dragSource, name );
00242
return 0L;
00243 }
00244
00245 QImage KoPicture::generateImage(
const QSize& size)
00246 {
00247
if (m_sharedData)
00248
return m_sharedData->generateImage( size );
00249
return QImage();
00250 }
00251
00252 bool KoPicture::hasAlphaBuffer()
const
00253
{
00254
if (m_sharedData)
00255
return m_sharedData->hasAlphaBuffer();
00256
return false;
00257 }
00258
00259 void KoPicture::setAlphaBuffer(
bool enable)
00260 {
00261
if (m_sharedData)
00262 m_sharedData->setAlphaBuffer(enable);
00263 }
00264
00265 QImage KoPicture::createAlphaMask(
int conversion_flags)
const
00266
{
00267
if (m_sharedData)
00268
return m_sharedData->createAlphaMask(conversion_flags);
00269
return QImage();
00270 }
00271
00272 void KoPicture::clearCache(
void)
00273 {
00274
if (m_sharedData)
00275 m_sharedData->clearCache();
00276 }
00277