diff options
author | Qt by Nokia <qt-info@nokia.com> | 2011-04-27 12:05:43 +0200 |
---|---|---|
committer | axis <qt-info@nokia.com> | 2011-04-27 12:05:43 +0200 |
commit | 983a4b61f1da719dac647a7190533d1edf2b2159 (patch) | |
tree | 3b52101d36c2b432540c20e0e188f62197c42c59 /src/svg/qsvgwidget.cpp | |
download | qtsvg-983a4b61f1da719dac647a7190533d1edf2b2159.tar.gz |
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you
want to look at revision history older than this, please refer to the
Qt Git wiki for how to use Git history grafting. At the time of
writing, this wiki is located here:
http://qt.gitorious.org/qt/pages/GitIntroductionWithQt
If you have already performed the grafting and you don't see any
history beyond this commit, try running "git log" with the "--follow"
argument.
Branched from the monolithic repo, Qt master branch, at commit
896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'src/svg/qsvgwidget.cpp')
-rw-r--r-- | src/svg/qsvgwidget.cpp | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/src/svg/qsvgwidget.cpp b/src/svg/qsvgwidget.cpp new file mode 100644 index 0000000..d43db92 --- /dev/null +++ b/src/svg/qsvgwidget.cpp @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSvg module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsvgwidget.h" + +#ifndef QT_NO_SVGWIDGET + +#include "qsvgrenderer.h" + +#include "qpainter.h" +#include "private/qwidget_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QSvgWidget + \ingroup painting + + \brief The QSvgWidget class provides a widget that is used to display the contents of + Scalable Vector Graphics (SVG) files. + \since 4.1 + + This class enables developers to display SVG drawings alongside standard widgets, and + is used in much the same way as QLabel is used for displaying text and bitmap images. + + Since QSvgWidget is a subclass of QWidget, SVG drawings are rendered using the properties + of the display. More control can be exercised over the rendering process with the + QSvgRenderer class, as this can be used to paint onto other paint devices, such as QImage + and QGLWidget. The renderer used by the widget can be obtained with the renderer() + function. + + Each QSvgWidget can be constructed with the file name of a SVG file, or they can be + constructed without a specific file to render and one can be supplied later. The load() + functions provide two different ways to load an SVG file: they accept either the file name + of an SVG file or a QByteArray containing the serialized XML representation of an SVG file. + + By default, the widget provides a size hint to reflect the size of the drawing that it + displays. If no data has been loaded, the widget provides the default QWidget size hint. + Subclass this class and reimplement sizeHint() if you need to customize this behavior. + + \sa QSvgRenderer, {QtSvg Module}, QPicture +*/ + +class QSvgWidgetPrivate : public QWidgetPrivate +{ + Q_DECLARE_PUBLIC(QSvgWidget) +public: + QSvgRenderer *renderer; +}; + +/*! + Constructs a new SVG display widget with the given \a parent. +*/ +QSvgWidget::QSvgWidget(QWidget *parent) + : QWidget(*new QSvgWidgetPrivate, parent, 0) +{ + d_func()->renderer = new QSvgRenderer(this); + QObject::connect(d_func()->renderer, SIGNAL(repaintNeeded()), + this, SLOT(update())); +} + +/*! + Constructs a new SVG display widget with the given \a parent and loads the contents + of the specified \a file. +*/ +QSvgWidget::QSvgWidget(const QString &file, QWidget *parent) + : QWidget(*new QSvgWidgetPrivate, parent, 0) +{ + d_func()->renderer = new QSvgRenderer(file, this); + QObject::connect(d_func()->renderer, SIGNAL(repaintNeeded()), + this, SLOT(update())); +} + +/*! + Destroys the widget. +*/ +QSvgWidget::~QSvgWidget() +{ + +} + +/*! + Returns the renderer used to display the contents of the widget. +*/ +QSvgRenderer * QSvgWidget::renderer() const +{ + Q_D(const QSvgWidget); + return d->renderer; +} + + +/*! + \reimp +*/ +QSize QSvgWidget::sizeHint() const +{ + Q_D(const QSvgWidget); + if (d->renderer->isValid()) + return d->renderer->defaultSize(); + else + return QSize(128, 64); +} + + +/*! + \reimp +*/ +void QSvgWidget::paintEvent(QPaintEvent *) +{ + Q_D(QSvgWidget); + QPainter p(this); + d->renderer->render(&p); +} + +/*! + Loads the contents of the specified SVG \a file and updates the widget. +*/ +void QSvgWidget::load(const QString &file) +{ + Q_D(const QSvgWidget); + d->renderer->load(file); +} + +/*! + Loads the specified SVG format \a contents and updates the widget. +*/ +void QSvgWidget::load(const QByteArray &contents) +{ + Q_D(const QSvgWidget); + d->renderer->load(contents); +} + +QT_END_NAMESPACE + +#endif // QT_NO_SVGWIDGET |