F:/KPlato/koffice/libs/kofficecore/KoPictureWmf.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (c) 2001 Simon Hausmann <hausmann@kde.org>
00003    Copyright (c) 2001 David Faure <faure@kde.org>
00004    Copyright (C) 2002 Nicolas GOUTTE <goutte@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include <QBuffer>
00023 #include <QPainter>
00024 #include <q3picture.h>
00025 #include <QPixmap>
00026 
00027 #include <kdebug.h>
00028 #include <kdeversion.h>
00029 
00030 #include <kowmfpaint.h>
00031 #include "KoPictureKey.h"
00032 #include "KoPictureBase.h"
00033 #include "KoPictureWmf.h"
00034 
00035 KoPictureWmf::KoPictureWmf(void) : m_clipart(KoPictureType::formatVersionQPicture)
00036 {
00037 }
00038 
00039 KoPictureWmf::~KoPictureWmf(void)
00040 {
00041 }
00042 
00043 KoPictureBase* KoPictureWmf::newCopy(void) const
00044 {
00045     return new KoPictureWmf(*this);
00046 }
00047 
00048 KoPictureType::Type KoPictureWmf::getType(void) const
00049 {
00050     return KoPictureType::TypeWmf;
00051 }
00052 
00053 bool KoPictureWmf::isNull(void) const
00054 {
00055     return m_clipart.isNull();
00056 }
00057 
00058 void KoPictureWmf::drawQPicture(QPicture& clipart, QPainter& painter,
00059     int x, int y, int width, int height, int sx, int sy, int sw, int sh)
00060 {
00061     kDebug(30003) << "Drawing KoPictureWmf " << this << endl;
00062     kDebug(30003) << "  x=" << x << " y=" << y << " width=" << width << " height=" << height << endl;
00063     kDebug(30003) << "  sx=" << sx << " sy=" << sy << " sw=" << sw << " sh=" << sh << endl;
00064     painter.save();
00065     // Thanks to Harri, Qt3 makes it much easier than Qt2 ;)
00066     QRect br = clipart.boundingRect();
00067     kDebug(30003) << "  Bounding rect. " << br << endl;
00068 
00069     painter.translate(x,y); // Translating must be done before scaling!
00070     if ( br.width() && br.height() )
00071         painter.scale(double(width)/double(br.width()),double(height)/double(br.height()));
00072     else
00073         kWarning(30003) << "Null bounding rectangle: " << br.width() << " x " << br.height() << endl;
00074     painter.drawPicture(0,0,clipart);
00075     painter.restore();
00076 }
00077 
00078 void KoPictureWmf::draw(QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool /*fastMode*/)
00079 {
00080     drawQPicture(m_clipart, painter, x, y, width, height, sx, sy, sw, sh);
00081 }
00082 
00083 bool KoPictureWmf::loadData(const QByteArray& array, const QString& /* extension */)
00084 {
00085     // Second, create the original clipart
00086     kDebug(30003) << "Trying to load clipart... (Size:" << array.size() << ")" << endl;
00087     m_rawData=array;
00088 
00089     KoWmfPaint wmf;
00090     if (!wmf.load(array))
00091     {
00092         kWarning(30003) << "Loading WMF has failed! (KoPictureWmf::load)" << endl;
00093         return false;
00094     }
00095     m_originalSize = wmf.boundingRect().size();
00096     // draw wmf file with relative coordinate
00097     wmf.play(m_clipart, true);
00098 
00099     return true;
00100 }
00101 
00102 bool KoPictureWmf::save(QIODevice* io) const
00103 {
00104     // We save the raw data, as the SVG support in QPicture is poor
00105     qint64 size = io->write( m_rawData ); // WARNING: writeBlock returns Q_LONG but size() Q_ULONG!
00106     return ( size==m_rawData.size() );
00107 }
00108 
00109 QSize KoPictureWmf::getOriginalSize(void) const
00110 {
00111     return m_originalSize;
00112 }
00113 
00114 QPixmap KoPictureWmf::generatePixmap(const QSize& size, bool /*smoothScale*/)
00115 {
00116     // Not sure if it works, but it worked for KoPictureFilePreviewWidget::setClipart
00117     QPixmap pixmap(size);
00118     QPainter p;
00119 
00120     p.begin( &pixmap );
00121     p.setBackground( QBrush( Qt::white ) );
00122     pixmap.fill( Qt::white );
00123 
00124     if ( m_originalSize.width() && m_originalSize.height() )
00125         p.scale( (double)pixmap.width() / (double)m_originalSize.width(), (double)pixmap.height() / (double)m_originalSize.height() );
00126     p.drawPicture( 0, 0, m_clipart );
00127     p.end();
00128     return pixmap;
00129 }
00130 
00131 QString KoPictureWmf::getMimeType(const QString& /* extension */) const
00132 {
00133     return "image/x-wmf";
00134 }

Généré le Wed Nov 22 23:41:03 2006 pour KPlato par  doxygen 1.5.1-p1