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