29#include "KoPictureKey.h"
30#include "KoPictureBase.h"
31#include "KoPictureClipart.h"
33KoPictureClipart::KoPictureClipart(
void) : m_clipart(KoPictureType::formatVersionTQPicture)
37KoPictureClipart::~KoPictureClipart(
void)
41KoPictureBase* KoPictureClipart::newCopy(
void)
const
43 return new KoPictureClipart(*
this);
46KoPictureType::Type KoPictureClipart::getType(
void)
const
48 return KoPictureType::TypeClipart;
51bool KoPictureClipart::isNull(
void)
const
53 return m_clipart.isNull();
56void KoPictureClipart::drawTQPicture(TQPicture& clipart, TQPainter& painter,
57 int x,
int y,
int width,
int height,
int sx,
int sy,
int sw,
int sh)
59 kdDebug(30003) <<
"Drawing KoPictureClipart " <<
this << endl;
60 kdDebug(30003) <<
" x=" << x <<
" y=" << y <<
" width=" << width <<
" height=" << height << endl;
61 kdDebug(30003) <<
" sx=" << sx <<
" sy=" << sy <<
" sw=" << sw <<
" sh=" << sh << endl;
64 TQRect br = clipart.boundingRect();
65 kdDebug(30003) <<
" Bounding rect. " << br << endl;
67 painter.translate(x,y);
68 if ( br.width() && br.height() )
69 painter.scale(
double(width)/
double(br.width()),
double(height)/
double(br.height()));
71 kdWarning(30003) <<
"Null bounding rectangle: " << br.width() <<
" x " << br.height() << endl;
72 painter.drawPicture(0,0,clipart);
76void KoPictureClipart::draw(TQPainter& painter,
int x,
int y,
int width,
int height,
int sx,
int sy,
int sw,
int sh,
bool )
78 drawTQPicture(m_clipart, painter, x, y, width, height, sx, sy, sw, sh);
81bool KoPictureClipart::loadData(
const TQByteArray& array,
const TQString& extension)
84 kdDebug(30003) <<
"Trying to load clipart... (Size:" << m_rawData.size() <<
")" << endl;
86 TQBuffer buffer(m_rawData);
87 buffer.open(IO_ReadOnly);
91 if (!m_clipart.load(&buffer,
"svg"))
93 kdWarning(30003) <<
"Loading SVG has failed! (KoPictureClipart::load)" << endl;
99 if (!m_clipart.load(&buffer, NULL))
101 kdWarning(30003) <<
"Loading TQPicture has failed! (KoPictureClipart::load)" << endl;
109bool KoPictureClipart::save(TQIODevice* io)
const
112 TQ_ULONG size=io->writeBlock(m_rawData);
113 return (size==m_rawData.size());
116TQSize KoPictureClipart::getOriginalSize(
void)
const
118 return m_clipart.boundingRect().size();
121TQPixmap KoPictureClipart::generatePixmap(
const TQSize& size,
bool )
124 TQPixmap pixmap(size);
128 p.setBackgroundColor( TQt::white );
129 pixmap.fill( TQt::white );
131 TQRect br = m_clipart.boundingRect();
132 if ( br.width() && br.height() )
133 p.scale( (
double)pixmap.width() / (
double)br.width(), (
double)pixmap.height() / (
double)br.height() );
134 p.drawPicture( m_clipart );
139TQString KoPictureClipart::getMimeType(
const TQString& extension)
const
141 if (extension==
"svg")
142 return "image/svg+xml";
144 return "image/x-vnd.trolltech.qpicture";