lib
KoPicture.cpp00001
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::saveAsBase64( KoXmlWriter& writer ) const
00169 {
00170 if ( m_sharedData )
00171 return m_sharedData->saveAsBase64( writer );
00172 return false;
00173 }
00174
00175 void KoPicture::clear(void)
00176 {
00177 unlinkSharedData();
00178 }
00179
00180 void KoPicture::clearAndSetMode(const QString& newMode)
00181 {
00182 createSharedData();
00183 m_sharedData->clearAndSetMode(newMode);
00184 }
00185
00186 QString KoPicture::getExtension(void) const
00187 {
00188 if (m_sharedData)
00189 return m_sharedData->getExtension();
00190 return "null";
00191 }
00192
00193 QString KoPicture::getMimeType(void) const
00194 {
00195 if (m_sharedData)
00196 return m_sharedData->getMimeType();
00197 return QString(NULL_MIME_TYPE);
00198 }
00199
00200 bool KoPicture::load(QIODevice* io, const QString& extension)
00201 {
00202 kdDebug(30003) << "KoPicture::load(QIODevice*, const QString&) " << extension << endl;
00203 createSharedData();
00204
00205 return m_sharedData->load(io,extension);
00206 }
00207
00208 bool KoPicture::loadFromFile(const QString& fileName)
00209 {
00210 kdDebug(30003) << "KoPicture::loadFromFile " << fileName << endl;
00211 createSharedData();
00212 return m_sharedData->loadFromFile(fileName);
00213 }
00214
00215 bool KoPicture::loadFromBase64( const QCString& str )
00216 {
00217 createSharedData();
00218 return m_sharedData->loadFromBase64( str );
00219 }
00220
00221 QSize KoPicture::getOriginalSize(void) const
00222 {
00223 if (m_sharedData)
00224 return m_sharedData->getOriginalSize();
00225 return QSize(0,0);
00226 }
00227
00228 QPixmap KoPicture::generatePixmap(const QSize& size, bool smoothScale)
00229 {
00230 if (m_sharedData)
00231 return m_sharedData->generatePixmap(size, smoothScale);
00232 return QPixmap();
00233 }
00234
00235 bool KoPicture::setKeyAndDownloadPicture(const KURL& url, QWidget *window)
00236 {
00237 bool result=false;
00238
00239 QString tmpFileName;
00240 if ( KIO::NetAccess::download(url, tmpFileName, window) )
00241 {
00242 KoPictureKey key;
00243 key.setKeyFromFile( tmpFileName );
00244 setKey( key );
00245 result=loadFromFile( tmpFileName );
00246 KIO::NetAccess::removeTempFile( tmpFileName );
00247 }
00248
00249 return result;
00250 }
00251
00252 QDragObject* KoPicture::dragObject( QWidget *dragSource, const char *name )
00253 {
00254 if (m_sharedData)
00255 return m_sharedData->dragObject( dragSource, name );
00256 return 0L;
00257 }
00258
00259 QImage KoPicture::generateImage(const QSize& size)
00260 {
00261 if (m_sharedData)
00262 return m_sharedData->generateImage( size );
00263 return QImage();
00264 }
00265
00266 bool KoPicture::hasAlphaBuffer() const
00267 {
00268 if (m_sharedData)
00269 return m_sharedData->hasAlphaBuffer();
00270 return false;
00271 }
00272
00273 void KoPicture::setAlphaBuffer(bool enable)
00274 {
00275 if (m_sharedData)
00276 m_sharedData->setAlphaBuffer(enable);
00277 }
00278
00279 QImage KoPicture::createAlphaMask(int conversion_flags) const
00280 {
00281 if (m_sharedData)
00282 return m_sharedData->createAlphaMask(conversion_flags);
00283 return QImage();
00284 }
00285
00286 void KoPicture::clearCache(void)
00287 {
00288 if (m_sharedData)
00289 m_sharedData->clearCache();
00290 }
|