koPicture.cc
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 uint KoPicture::uniqueValue = 0;
00034
00035
00036 KoPicture::KoPicture(void) : m_sharedData(NULL)
00037 {
00038 m_uniqueName = "Pictures"+ QString::number(uniqueValue++);
00039 }
00040
00041 KoPicture::~KoPicture(void)
00042 {
00043 unlinkSharedData();
00044 }
00045
00046 QString KoPicture::uniqueName() const
00047 {
00048 return m_uniqueName;
00049 }
00050
00051 KoPicture::KoPicture(const KoPicture &other)
00052 {
00053 m_sharedData=NULL;
00054 (*this)=other;
00055 }
00056
00057 void KoPicture::assignPictureId( uint _id)
00058 {
00059 if ( m_sharedData )
00060 m_sharedData->assignPictureId(_id);
00061 }
00062
00063 QString KoPicture::uniquePictureId() const
00064 {
00065 if ( m_sharedData )
00066 return m_sharedData->uniquePictureId();
00067 else
00068 return QString::null;
00069 }
00070
00071 KoPicture& KoPicture::operator=( const KoPicture &other )
00072 {
00073
00074 if (other.m_sharedData)
00075 other.linkSharedData();
00076 if (m_sharedData)
00077 unlinkSharedData();
00078 m_sharedData=other.m_sharedData;
00079 m_key=other.m_key;
00080
00081 return *this;
00082 }
00083
00084 void KoPicture::unlinkSharedData(void)
00085 {
00086 if (m_sharedData && m_sharedData->deref())
00087 delete m_sharedData;
00088
00089 m_sharedData=NULL;
00090 }
00091
00092 void KoPicture::linkSharedData(void) const
00093 {
00094 if (m_sharedData)
00095 m_sharedData->ref();
00096 }
00097
00098 void KoPicture::createSharedData(void)
00099 {
00100 if (!m_sharedData)
00101 {
00102 m_sharedData=new KoPictureShared();
00103
00104 }
00105 }
00106
00107 KoPictureType::Type KoPicture::getType(void) const
00108 {
00109 if (m_sharedData)
00110 return m_sharedData->getType();
00111 return KoPictureType::TypeUnknown;
00112 }
00113
00114 KoPictureKey KoPicture::getKey(void) const
00115 {
00116 return m_key;
00117 }
00118
00119 void KoPicture::setKey(const KoPictureKey& key)
00120 {
00121 m_key=key;
00122 }
00123
00124
00125 bool KoPicture::isNull(void) const
00126 {
00127 if (m_sharedData)
00128 return m_sharedData->isNull();
00129 return true;
00130 }
00131
00132 void KoPicture::draw(QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool fastMode)
00133 {
00134 if (m_sharedData)
00135 m_sharedData->draw(painter, x, y, width, height, sx, sy, sw, sh, fastMode);
00136 else
00137 {
00138
00139 kdWarning(30003) << "Drawing white rectangle! (KoPicture::draw)" << endl;
00140 painter.save();
00141 painter.setBrush(QColor(255, 255, 255));
00142 painter.drawRect(x,y,width,height);
00143 painter.restore();
00144 }
00145 }
00146
00147 bool KoPicture::loadXpm(QIODevice* io)
00148 {
00149 kdDebug(30003) << "KoPicture::loadXpm" << endl;
00150 if (!io)
00151 {
00152 kdError(30003) << "No QIODevice!" << endl;
00153 return false;
00154 }
00155 createSharedData();
00156 return m_sharedData->loadXpm(io);
00157 }
00158
00159 bool KoPicture::save(QIODevice* io) const
00160 {
00161 if (!io)
00162 return false;
00163 if (m_sharedData)
00164 return m_sharedData->save(io);
00165 return false;
00166 }
00167
00168 bool KoPicture::saveAsKOffice1Dot1(QIODevice* io) const
00169 {
00170 if (!io)
00171 return false;
00172 if (m_sharedData)
00173 return m_sharedData->saveAsKOffice1Dot1(io);
00174 return false;
00175 }
00176
00177
00178 bool KoPicture::saveAsBase64( KoXmlWriter& writer ) const
00179 {
00180 if ( m_sharedData )
00181 return m_sharedData->saveAsBase64( writer );
00182 return false;
00183 }
00184
00185 void KoPicture::clear(void)
00186 {
00187 unlinkSharedData();
00188 }
00189
00190 void KoPicture::clearAndSetMode(const QString& newMode)
00191 {
00192 createSharedData();
00193 m_sharedData->clearAndSetMode(newMode);
00194 }
00195
00196 QString KoPicture::getExtension(void) const
00197 {
00198 if (m_sharedData)
00199 return m_sharedData->getExtension();
00200 return "null";
00201 }
00202
00203 QString KoPicture::getExtensionAsKOffice1Dot1(void) const
00204 {
00205 if (m_sharedData)
00206 return m_sharedData->getExtensionAsKOffice1Dot1();
00207 return "null";
00208 }
00209
00210 QString KoPicture::getMimeType(void) const
00211 {
00212 if (m_sharedData)
00213 return m_sharedData->getMimeType();
00214 return QString(NULL_MIME_TYPE);
00215 }
00216
00217 bool KoPicture::load(QIODevice* io, const QString& extension)
00218 {
00219 kdDebug(30003) << "KoPicture::load(QIODevice*, const QString&) " << extension << endl;
00220 createSharedData();
00221
00222 return m_sharedData->load(io,extension);
00223 }
00224
00225 bool KoPicture::loadFromFile(const QString& fileName)
00226 {
00227 kdDebug(30003) << "KoPicture::loadFromFile " << fileName << endl;
00228 createSharedData();
00229 return m_sharedData->loadFromFile(fileName);
00230 }
00231
00232 bool KoPicture::loadFromBase64( const QCString& str )
00233 {
00234 createSharedData();
00235 return m_sharedData->loadFromBase64( str );
00236 }
00237
00238 QSize KoPicture::getOriginalSize(void) const
00239 {
00240 if (m_sharedData)
00241 return m_sharedData->getOriginalSize();
00242 return QSize(0,0);
00243 }
00244
00245 QPixmap KoPicture::generatePixmap(const QSize& size, bool smoothScale)
00246 {
00247 if (m_sharedData)
00248 return m_sharedData->generatePixmap(size, smoothScale);
00249 return QPixmap();
00250 }
00251
00252 bool KoPicture::isClipartAsKOffice1Dot1(void) const
00253 {
00254 if (m_sharedData)
00255 return m_sharedData->isClipartAsKOffice1Dot1();
00256 return false;
00257 }
00258
00259 bool KoPicture::setKeyAndDownloadPicture(const KURL& url, QWidget *window)
00260 {
00261 bool result=false;
00262
00263 QString tmpFileName;
00264 if ( KIO::NetAccess::download(url, tmpFileName, window) )
00265 {
00266 KoPictureKey key;
00267 key.setKeyFromFile( tmpFileName );
00268 setKey( key );
00269 result=loadFromFile( tmpFileName );
00270 KIO::NetAccess::removeTempFile( tmpFileName );
00271 }
00272
00273 return result;
00274 }
00275
00276 QDragObject* KoPicture::dragObject( QWidget *dragSource, const char *name )
00277 {
00278 if (m_sharedData)
00279 return m_sharedData->dragObject( dragSource, name );
00280 return 0L;
00281 }
00282
00283 QImage KoPicture::generateImage(const QSize& size)
00284 {
00285 if (m_sharedData)
00286 return m_sharedData->generateImage( size );
00287 return QImage();
00288 }
00289
00290 bool KoPicture::hasAlphaBuffer() const
00291 {
00292 if (m_sharedData)
00293 return m_sharedData->hasAlphaBuffer();
00294 return false;
00295 }
00296
00297 void KoPicture::setAlphaBuffer(bool enable)
00298 {
00299 if (m_sharedData)
00300 m_sharedData->setAlphaBuffer(enable);
00301 }
00302
00303 QImage KoPicture::createAlphaMask(int conversion_flags) const
00304 {
00305 if (m_sharedData)
00306 return m_sharedData->createAlphaMask(conversion_flags);
00307 return QImage();
00308 }
00309
00310 void KoPicture::clearCache(void)
00311 {
00312 if (m_sharedData)
00313 m_sharedData->clearCache();
00314 }
This file is part of the documentation for lib Library Version 1.4.2.