KDEUI
ksvgrenderer.cpp
Go to the documentation of this file.00001 /* 00002 * This file is part of the KDE project, module kdecore. 00003 * Copyright (C) 2006 Oswald Buddenhagen <ossi@kde.org> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "ksvgrenderer.h" 00022 00023 #include <kfilterdev.h> 00024 00025 #include <QtCore/QBuffer> 00026 #include <QtCore/QFile> 00027 00028 KSvgRenderer::KSvgRenderer(QObject *parent) : QSvgRenderer(parent) 00029 { 00030 } 00031 00032 KSvgRenderer::KSvgRenderer(const QString &filename, QObject *parent) : 00033 QSvgRenderer(parent) 00034 { 00035 load(filename); 00036 } 00037 00038 KSvgRenderer::KSvgRenderer(const QByteArray &contents, QObject *parent) : 00039 QSvgRenderer(parent) 00040 { 00041 load(contents); 00042 } 00043 00044 bool 00045 KSvgRenderer::load(const QString &filename) 00046 { 00047 QFile fi(filename); 00048 if (!fi.open(QIODevice::ReadOnly)) 00049 return false; 00050 return load(fi.readAll()); 00051 } 00052 00053 bool 00054 KSvgRenderer::load(const QByteArray &contents) 00055 { 00056 if (!contents.startsWith("<?xml")) { 00057 QBuffer buf(const_cast<QByteArray *>(&contents)); 00058 QIODevice *flt = KFilterDev::device( 00059 &buf, QString::fromLatin1("application/x-gzip"), false); 00060 if (!flt) 00061 return false; 00062 if (!flt->open(QIODevice::ReadOnly)) { 00063 delete flt; 00064 return false; 00065 } 00066 QByteArray ar = flt->readAll(); 00067 delete flt; 00068 return QSvgRenderer::load(ar); 00069 } 00070 return QSvgRenderer::load(contents); 00071 } 00072 00073 #include "ksvgrenderer.moc"