00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qbuffer.h>
00023 #include <qpainter.h>
00024 #include <qpicture.h>
00025 #include <qpixmap.h>
00026
00027 #include <kdebug.h>
00028 #include <kdeversion.h>
00029 #if ! KDE_IS_VERSION( 3,1,90 )
00030 #include <kdebugclasses.h>
00031 #endif
00032
00033 #include "KoPictureKey.h"
00034 #include "KoPictureBase.h"
00035 #include "KoPictureClipart.h"
00036
00037 KoPictureClipart::KoPictureClipart(void) : m_clipart(KoPictureType::formatVersionQPicture)
00038 {
00039 }
00040
00041 KoPictureClipart::~KoPictureClipart(void)
00042 {
00043 }
00044
00045 KoPictureBase* KoPictureClipart::newCopy(void) const
00046 {
00047 return new KoPictureClipart(*this);
00048 }
00049
00050 KoPictureType::Type KoPictureClipart::getType(void) const
00051 {
00052 return KoPictureType::TypeClipart;
00053 }
00054
00055 bool KoPictureClipart::isNull(void) const
00056 {
00057 return m_clipart.isNull();
00058 }
00059
00060 void KoPictureClipart::drawQPicture(QPicture& clipart, QPainter& painter,
00061 int x, int y, int width, int height, int sx, int sy, int sw, int sh)
00062 {
00063 kdDebug(30003) << "Drawing KoPictureClipart " << this << endl;
00064 kdDebug(30003) << " x=" << x << " y=" << y << " width=" << width << " height=" << height << endl;
00065 kdDebug(30003) << " sx=" << sx << " sy=" << sy << " sw=" << sw << " sh=" << sh << endl;
00066 painter.save();
00067
00068 QRect br = clipart.boundingRect();
00069 kdDebug(30003) << " Bounding rect. " << br << endl;
00070
00071 painter.translate(x,y);
00072 if ( br.width() && br.height() )
00073 painter.scale(double(width)/double(br.width()),double(height)/double(br.height()));
00074 else
00075 kdWarning(30003) << "Null bounding rectangle: " << br.width() << " x " << br.height() << endl;
00076 painter.drawPicture(0,0,clipart);
00077 painter.restore();
00078 }
00079
00080 void KoPictureClipart::draw(QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool )
00081 {
00082 drawQPicture(m_clipart, painter, x, y, width, height, sx, sy, sw, sh);
00083 }
00084
00085 bool KoPictureClipart::loadData(const QByteArray& array, const QString& extension)
00086 {
00087
00088 kdDebug(30003) << "Trying to load clipart... (Size:" << m_rawData.size() << ")" << endl;
00089 m_rawData=array;
00090 QBuffer buffer(m_rawData);
00091 buffer.open(IO_ReadOnly);
00092 bool check = true;
00093 if (extension=="svg")
00094 {
00095 if (!m_clipart.load(&buffer, "svg"))
00096 {
00097 kdWarning(30003) << "Loading SVG has failed! (KoPictureClipart::load)" << endl;
00098 check = false;
00099 }
00100 }
00101 else
00102 {
00103 if (!m_clipart.load(&buffer, NULL))
00104 {
00105 kdWarning(30003) << "Loading QPicture has failed! (KoPictureClipart::load)" << endl;
00106 check = false;
00107 }
00108 }
00109 buffer.close();
00110 return check;
00111 }
00112
00113 bool KoPictureClipart::save(QIODevice* io) const
00114 {
00115
00116 Q_ULONG size=io->writeBlock(m_rawData);
00117 return (size==m_rawData.size());
00118 }
00119
00120 QSize KoPictureClipart::getOriginalSize(void) const
00121 {
00122 return m_clipart.boundingRect().size();
00123 }
00124
00125 QPixmap KoPictureClipart::generatePixmap(const QSize& size, bool )
00126 {
00127
00128 QPixmap pixmap(size);
00129 QPainter p;
00130
00131 p.begin( &pixmap );
00132 p.setBackgroundColor( Qt::white );
00133 pixmap.fill( Qt::white );
00134
00135 QRect br = m_clipart.boundingRect();
00136 if ( br.width() && br.height() )
00137 p.scale( (double)pixmap.width() / (double)br.width(), (double)pixmap.height() / (double)br.height() );
00138 p.drawPicture( m_clipart );
00139 p.end();
00140 return pixmap;
00141 }
00142
00143 QString KoPictureClipart::getMimeType(const QString& extension) const
00144 {
00145 if (extension=="svg")
00146 return "image/svg+xml";
00147 else
00148 return "image/x-vnd.trolltech.qpicture";
00149 }
00150