28#include <tdeversion.h>
29#if ! KDE_IS_VERSION( 3,1,90 )
30#include <kdebugclasses.h>
33#include "KoPictureKey.h"
34#include "KoPictureBase.h"
35#include "KoPictureClipart.h"
37KoPictureClipart::KoPictureClipart(
void) : m_clipart(KoPictureType::formatVersionTQPicture)
41KoPictureClipart::~KoPictureClipart(
void)
45KoPictureBase* KoPictureClipart::newCopy(
void)
const
47 return new KoPictureClipart(*
this);
50KoPictureType::Type KoPictureClipart::getType(
void)
const
52 return KoPictureType::TypeClipart;
55bool KoPictureClipart::isNull(
void)
const
57 return m_clipart.isNull();
60void KoPictureClipart::drawTQPicture(TQPicture& clipart, TQPainter& painter,
61 int x,
int y,
int width,
int height,
int sx,
int sy,
int sw,
int sh)
63 kdDebug(30003) <<
"Drawing KoPictureClipart " <<
this << endl;
64 kdDebug(30003) <<
" x=" << x <<
" y=" << y <<
" width=" << width <<
" height=" << height << endl;
65 kdDebug(30003) <<
" sx=" << sx <<
" sy=" << sy <<
" sw=" << sw <<
" sh=" << sh << endl;
68 TQRect br = clipart.boundingRect();
69 kdDebug(30003) <<
" Bounding rect. " << br << endl;
71 painter.translate(x,y);
72 if ( br.width() && br.height() )
73 painter.scale(
double(width)/
double(br.width()),
double(height)/
double(br.height()));
75 kdWarning(30003) <<
"Null bounding rectangle: " << br.width() <<
" x " << br.height() << endl;
76 painter.drawPicture(0,0,clipart);
80void KoPictureClipart::draw(TQPainter& painter,
int x,
int y,
int width,
int height,
int sx,
int sy,
int sw,
int sh,
bool )
82 drawTQPicture(m_clipart, painter, x, y, width, height, sx, sy, sw, sh);
85bool KoPictureClipart::loadData(
const TQByteArray& array,
const TQString& extension)
88 kdDebug(30003) <<
"Trying to load clipart... (Size:" << m_rawData.size() <<
")" << endl;
90 TQBuffer buffer(m_rawData);
91 buffer.open(IO_ReadOnly);
95 if (!m_clipart.load(&buffer,
"svg"))
97 kdWarning(30003) <<
"Loading SVG has failed! (KoPictureClipart::load)" << endl;
103 if (!m_clipart.load(&buffer, NULL))
105 kdWarning(30003) <<
"Loading TQPicture has failed! (KoPictureClipart::load)" << endl;
113bool KoPictureClipart::save(TQIODevice* io)
const
116 TQ_ULONG size=io->writeBlock(m_rawData);
117 return (size==m_rawData.size());
120TQSize KoPictureClipart::getOriginalSize(
void)
const
122 return m_clipart.boundingRect().size();
125TQPixmap KoPictureClipart::generatePixmap(
const TQSize& size,
bool )
128 TQPixmap pixmap(size);
132 p.setBackgroundColor( TQt::white );
133 pixmap.fill( TQt::white );
135 TQRect br = m_clipart.boundingRect();
136 if ( br.width() && br.height() )
137 p.scale( (
double)pixmap.width() / (
double)br.width(), (
double)pixmap.height() / (
double)br.height() );
138 p.drawPicture( m_clipart );
143TQString KoPictureClipart::getMimeType(
const TQString& extension)
const
145 if (extension==
"svg")
146 return "image/svg+xml";
148 return "image/x-vnd.trolltech.qpicture";