lib Library API Documentation

koPicture.cc

00001 /* This file is part of the KDE project
00002    Copyright (c) 2001 Simon Hausmann <hausmann@kde.org>
00003    Copyright (C) 2002, 2003 Nicolas GOUTTE <goutte@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
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     //kdDebug(30003) << "KoPicture::= before" << endl;
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     //kdDebug(30003) << "KoPicture::= after" << endl;
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         // Do not call m_sharedData->ref()
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         // Draw a white box
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"; // Just a dummy
00201 }
00202 
00203 QString KoPicture::getExtensionAsKOffice1Dot1(void) const
00204 {
00205     if (m_sharedData)
00206         return m_sharedData->getExtensionAsKOffice1Dot1();
00207     return "null"; // Just a dummy
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 }
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:40:04 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003