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., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA.
22
#include "PictureClipart.h"
31
#include "PictureKey.h"
32
#include "PictureBase.h"
35
PictureClipart::PictureClipart(void) : m_clipart(PictureType::formatVersionQPicture)
39
PictureClipart::~PictureClipart(void)
43
PictureBase* PictureClipart::newCopy(void) const
45
return new PictureClipart(*this);
48
PictureType::Type PictureClipart::getType(void) const
50
return PictureType::TypeClipart;
53
bool PictureClipart::isNull(void) const
55
return m_clipart.isNull();
58
void PictureClipart::drawQPicture(QPicture& clipart, QPainter& painter,
59
int x, int y, int width, int height, int sx, int sy, int sw, int sh)
61
kDebug(30508) << "Drawing PictureClipart" << this;
62
kDebug(30508) << " x=" << x << " y=" << y << " width=" << width << " height=" << height;
63
kDebug(30508) << " sx=" << sx << " sy=" << sy << " sw=" << sw << " sh=" << sh;
65
// Thanks to Harri, Qt3 makes it much easier than Qt2 ;)
66
QRect br = clipart.boundingRect();
67
kDebug(30508) << " Bounding rect." << br;
69
painter.translate(x, y); // Translating must be done before scaling!
70
if (br.width() && br.height())
71
painter.scale(qreal(width) / qreal(br.width()), qreal(height) / qreal(br.height()));
73
kWarning(30508) << "Null bounding rectangle: " << br.width() << " x " << br.height();
74
painter.drawPicture(0, 0, clipart);
78
void PictureClipart::draw(QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool /*fastMode*/)
80
drawQPicture(m_clipart, painter, x, y, width, height, sx, sy, sw, sh);
83
bool PictureClipart::loadData(const QByteArray& array, const QString& extension)
85
// Second, create the original clipart
86
kDebug(30508) << "Trying to load clipart... (Size:" << m_rawData.size() << ")";
88
QBuffer buffer(&m_rawData);
89
buffer.open(QIODevice::ReadOnly);
91
if (extension == "svg") {
92
if (!m_clipart.load(&buffer, "svg")) {
93
kWarning(30508) << "Loading SVG has failed! (PictureClipart::load)";
97
if (!m_clipart.load(&buffer, NULL)) {
98
kWarning(30508) << "Loading QPicture has failed! (PictureClipart::load)";
106
bool PictureClipart::save(QIODevice* io) const
108
// We save the raw data, as the SVG supposrt in QPicture is poor
109
qint64 size = io->write(m_rawData); // WARNING: writeBlock returns Q_LONG but size() Q_ULONG!
110
return (size == m_rawData.size());
113
QSize PictureClipart::getOriginalSize(void) const
115
return m_clipart.boundingRect().size();
118
QPixmap PictureClipart::generatePixmap(const QSize& size, bool /*smoothScale*/)
120
// Not sure if it works, but it worked for PictureFilePreviewWidget::setClipart
121
QPixmap pixmap(size);
125
p.setBackground(QBrush(Qt::white));
126
pixmap.fill(Qt::white);
128
QRect br = m_clipart.boundingRect();
129
if (br.width() && br.height())
130
p.scale((qreal)pixmap.width() / (qreal)br.width(), (qreal)pixmap.height() / (qreal)br.height());
131
p.drawPicture(0, 0, m_clipart);
136
QString PictureClipart::getMimeType(const QString& extension) const
138
if (extension == "svg")
139
return "image/svg+xml";
141
return "image/x-vnd.trolltech.qpicture";