Qt 4.8
qsvgwidget.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSvg module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qsvgwidget.h"
43 
44 #ifndef QT_NO_SVGWIDGET
45 
46 #include "qsvgrenderer.h"
47 
48 #include "qpainter.h"
49 #include "private/qwidget_p.h"
50 
52 
86 {
88 public:
90 };
91 
96  : QWidget(*new QSvgWidgetPrivate, parent, 0)
97 {
98  d_func()->renderer = new QSvgRenderer(this);
99  QObject::connect(d_func()->renderer, SIGNAL(repaintNeeded()),
100  this, SLOT(update()));
101 }
102 
108  : QWidget(*new QSvgWidgetPrivate, parent, 0)
109 {
110  d_func()->renderer = new QSvgRenderer(file, this);
111  QObject::connect(d_func()->renderer, SIGNAL(repaintNeeded()),
112  this, SLOT(update()));
113 }
114 
119 {
120 
121 }
122 
127 {
128  Q_D(const QSvgWidget);
129  return d->renderer;
130 }
131 
132 
137 {
138  Q_D(const QSvgWidget);
139  if (d->renderer->isValid())
140  return d->renderer->defaultSize();
141  else
142  return QSize(128, 64);
143 }
144 
145 
150 {
151  Q_D(QSvgWidget);
152  QPainter p(this);
153  d->renderer->render(&p);
154 }
155 
159 void QSvgWidget::load(const QString &file)
160 {
161  Q_D(const QSvgWidget);
162  d->renderer->load(file);
163 }
164 
168 void QSvgWidget::load(const QByteArray &contents)
169 {
170  Q_D(const QSvgWidget);
171  d->renderer->load(contents);
172 }
173 
175 
176 #endif // QT_NO_SVGWIDGET
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define SLOT(a)
Definition: qobjectdefs.h:226
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
QSvgRenderer * renderer() const
Returns the renderer used to display the contents of the widget.
Definition: qsvgwidget.cpp:126
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
#define SIGNAL(a)
Definition: qobjectdefs.h:227
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
The QSvgWidget class provides a widget that is used to display the contents of Scalable Vector Graphi...
Definition: qsvgwidget.h:59
void load(const QString &file)
Loads the contents of the specified SVG file and updates the widget.
Definition: qsvgwidget.cpp:159
void paintEvent(QPaintEvent *event)
Reimplemented Function
Definition: qsvgwidget.cpp:149
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
The QSvgRenderer class is used to draw the contents of SVG files onto paint devices.
Definition: qsvgrenderer.h:64
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QSvgRenderer * renderer
Definition: qsvgwidget.cpp:89
QObject * parent
Definition: qobject.h:92
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QSize sizeHint() const
Reimplemented Function
Definition: qsvgwidget.cpp:136
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
QSvgWidget(QWidget *parent=0)
Constructs a new SVG display widget with the given parent.
Definition: qsvgwidget.cpp:95
~QSvgWidget()
Destroys the widget.
Definition: qsvgwidget.cpp:118