1
/* This file is part of the KDE project
2
Copyright (c) 2001 Simon Hausmann <hausmann@kde.org>
3
Copyright (c) 2001 David Faure <faure@kde.org>
4
Copyright (C) 2002 Nicolas GOUTTE <goutte@kde.org>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
Boston, MA 02111-1307, USA.
28
#include <kdeversion.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"
37
KoPictureClipart::KoPictureClipart(void) : m_clipart(KoPictureType::formatVersionQPicture)
41
KoPictureClipart::~KoPictureClipart(void)
45
KoPictureBase* KoPictureClipart::newCopy(void) const
47
return new KoPictureClipart(*this);
50
KoPictureType::Type KoPictureClipart::getType(void) const
52
return KoPictureType::TypeClipart;
55
bool KoPictureClipart::isNull(void) const
57
return m_clipart.isNull();
60
void KoPictureClipart::drawQPicture(QPicture& clipart, QPainter& 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;
67
// Thanks to Harri, Qt3 makes it much easier than Qt2 ;)
68
QRect br = clipart.boundingRect();
69
kdDebug(30003) << " Bounding rect. " << br << endl;
71
painter.translate(x,y); // Translating must be done before scaling!
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);
80
void KoPictureClipart::draw(QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool /*fastMode*/)
82
drawQPicture(m_clipart, painter, x, y, width, height, sx, sy, sw, sh);
85
bool KoPictureClipart::load(const QByteArray& array, const QString& extension)
87
// Second, create the original clipart
88
kdDebug(30003) << "Trying to load clipart... (Size:" << m_rawData.size() << ")" << endl;
90
QBuffer buffer(m_rawData);
91
buffer.open(IO_ReadWrite);
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 QPicture has failed! (KoPictureClipart::load)" << endl;
113
bool KoPictureClipart::save(QIODevice* io)
115
// We save the raw data, as the SVG supposrt in QPicture is poor
116
Q_ULONG size=io->writeBlock(m_rawData); // WARNING: writeBlock returns Q_LONG but size() Q_ULONG!
117
return (size==m_rawData.size());
120
bool KoPictureClipart::saveAsKOffice1Dot1(QIODevice* io, const QString& extension)
122
QPicture picture(3); //compatibility with QT 2.1 and later (KOffice 1.1.x was with QT 2.3.1 or QT 3.0.x)
125
if (extension=="svg")
127
// SVG: convert it to QPicture
128
QBuffer buffer(m_rawData);
129
buffer.open(IO_ReadWrite);
130
if (picture.load(&buffer,"svg"))
132
result=picture.save(io,NULL);
136
else if (extension=="qpic")
138
// We cannot do much with a QPicture, we cannot convert it to previous formats
143
kdWarning(30003)<< "Unsupported clipart extension " << extension << " (KoPictureClipart::saveAsKOffice1Dot1)" << endl;
144
result=save(io); // Always save something!
150
QSize KoPictureClipart::getOriginalSize(void) const
152
return m_clipart.boundingRect().size();
155
QPixmap KoPictureClipart::generatePixmap(const QSize& size, bool /*smoothScale*/)
157
// Not sure if it works, but it worked for KoPictureFilePreviewWidget::setClipart
158
QPixmap pixmap(size);
162
p.setBackgroundColor( Qt::white );
163
pixmap.fill( Qt::white );
165
QRect br = m_clipart.boundingRect();
166
if ( br.width() && br.height() )
167
p.scale( (double)pixmap.width() / (double)br.width(), (double)pixmap.height() / (double)br.height() );
168
p.drawPicture( m_clipart );
173
bool KoPictureClipart::isClipartAsKOffice1Dot1(void) const
178
QString KoPictureClipart::getMimeType(const QString& extension) const
180
if (extension=="svg")
181
return "image/svg+xml";
183
return "image/x-vnd.trolltech.qpicture";