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 <q3picture.h>
00025 #include <QPixmap>
00026
00027 #include <kdebug.h>
00028 #include <kdeversion.h>
00029
00030 #include <kowmfpaint.h>
00031 #include "KoPictureKey.h"
00032 #include "KoPictureBase.h"
00033 #include "KoPictureWmf.h"
00034
00035 KoPictureWmf::KoPictureWmf(void) : m_clipart(KoPictureType::formatVersionQPicture)
00036 {
00037 }
00038
00039 KoPictureWmf::~KoPictureWmf(void)
00040 {
00041 }
00042
00043 KoPictureBase* KoPictureWmf::newCopy(void) const
00044 {
00045 return new KoPictureWmf(*this);
00046 }
00047
00048 KoPictureType::Type KoPictureWmf::getType(void) const
00049 {
00050 return KoPictureType::TypeWmf;
00051 }
00052
00053 bool KoPictureWmf::isNull(void) const
00054 {
00055 return m_clipart.isNull();
00056 }
00057
00058 void KoPictureWmf::drawQPicture(QPicture& clipart, QPainter& painter,
00059 int x, int y, int width, int height, int sx, int sy, int sw, int sh)
00060 {
00061 kDebug(30003) << "Drawing KoPictureWmf " << this << endl;
00062 kDebug(30003) << " x=" << x << " y=" << y << " width=" << width << " height=" << height << endl;
00063 kDebug(30003) << " sx=" << sx << " sy=" << sy << " sw=" << sw << " sh=" << sh << endl;
00064 painter.save();
00065
00066 QRect br = clipart.boundingRect();
00067 kDebug(30003) << " Bounding rect. " << br << endl;
00068
00069 painter.translate(x,y);
00070 if ( br.width() && br.height() )
00071 painter.scale(double(width)/double(br.width()),double(height)/double(br.height()));
00072 else
00073 kWarning(30003) << "Null bounding rectangle: " << br.width() << " x " << br.height() << endl;
00074 painter.drawPicture(0,0,clipart);
00075 painter.restore();
00076 }
00077
00078 void KoPictureWmf::draw(QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool )
00079 {
00080 drawQPicture(m_clipart, painter, x, y, width, height, sx, sy, sw, sh);
00081 }
00082
00083 bool KoPictureWmf::loadData(const QByteArray& array, const QString& )
00084 {
00085
00086 kDebug(30003) << "Trying to load clipart... (Size:" << array.size() << ")" << endl;
00087 m_rawData=array;
00088
00089 KoWmfPaint wmf;
00090 if (!wmf.load(array))
00091 {
00092 kWarning(30003) << "Loading WMF has failed! (KoPictureWmf::load)" << endl;
00093 return false;
00094 }
00095 m_originalSize = wmf.boundingRect().size();
00096
00097 wmf.play(m_clipart, true);
00098
00099 return true;
00100 }
00101
00102 bool KoPictureWmf::save(QIODevice* io) const
00103 {
00104
00105 qint64 size = io->write( m_rawData );
00106 return ( size==m_rawData.size() );
00107 }
00108
00109 QSize KoPictureWmf::getOriginalSize(void) const
00110 {
00111 return m_originalSize;
00112 }
00113
00114 QPixmap KoPictureWmf::generatePixmap(const QSize& size, bool )
00115 {
00116
00117 QPixmap pixmap(size);
00118 QPainter p;
00119
00120 p.begin( &pixmap );
00121 p.setBackground( QBrush( Qt::white ) );
00122 pixmap.fill( Qt::white );
00123
00124 if ( m_originalSize.width() && m_originalSize.height() )
00125 p.scale( (double)pixmap.width() / (double)m_originalSize.width(), (double)pixmap.height() / (double)m_originalSize.height() );
00126 p.drawPicture( 0, 0, m_clipart );
00127 p.end();
00128 return pixmap;
00129 }
00130
00131 QString KoPictureWmf::getMimeType(const QString& ) const
00132 {
00133 return "image/x-wmf";
00134 }