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::load(
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_ReadWrite);
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)
00114 {
00115
00116 Q_ULONG size=io->writeBlock(m_rawData);
00117
return (size==m_rawData.size());
00118 }
00119
00120
bool KoPictureClipart::saveAsKOffice1Dot1(
QIODevice* io,
const QString& extension)
00121 {
00122
QPicture picture(3);
00123
00124
bool result=
false;
00125
if (extension==
"svg")
00126 {
00127
00128
QBuffer buffer(m_rawData);
00129 buffer.open(IO_ReadWrite);
00130
if (picture.load(&buffer,
"svg"))
00131 {
00132 result=picture.save(io,NULL);
00133 }
00134 buffer.close();
00135 }
00136
else if (extension==
"qpic")
00137 {
00138
00139 result=
save(io);
00140 }
00141
else
00142 {
00143 kdWarning(30003)<<
"Unsupported clipart extension " << extension <<
" (KoPictureClipart::saveAsKOffice1Dot1)" << endl;
00144 result=
save(io);
00145 }
00146
00147
return result;
00148 }
00149
00150
QSize KoPictureClipart::getOriginalSize(
void)
const
00151
{
00152
return m_clipart.boundingRect().size();
00153 }
00154
00155
QPixmap KoPictureClipart::generatePixmap(
const QSize& size,
bool )
00156 {
00157
00158
QPixmap pixmap(size);
00159
QPainter p;
00160
00161 p.begin( &pixmap );
00162 p.setBackgroundColor( Qt::white );
00163 pixmap.fill( Qt::white );
00164
00165
QRect br = m_clipart.boundingRect();
00166
if ( br.width() && br.height() )
00167 p.
scale( (
double)pixmap.width() / (
double)br.width(), (
double)pixmap.height() / (
double)br.height() );
00168 p.drawPicture( m_clipart );
00169 p.end();
00170
return pixmap;
00171 }
00172
00173
bool KoPictureClipart::isClipartAsKOffice1Dot1(
void)
const
00174
{
00175
return true;
00176 }
00177
00178
QString KoPictureClipart::getMimeType(
const QString& extension)
const
00179
{
00180
if (extension==
"svg")
00181
return "image/svg+xml";
00182
else
00183
return "image/x-vnd.trolltech.qpicture";
00184 }
00185