summaryrefslogtreecommitdiffstats
path: root/src/svg
diff options
context:
space:
mode:
authoraxis <qt-info@nokia.com>2009-04-24 16:03:55 +0200
committeraxis <qt-info@nokia.com>2009-04-27 09:09:01 +0200
commite74c8dc65e2feffb9a55d00aee5ca634fba41df8 (patch)
tree3a131f9235fb6a455793178d8313655e4fd0036e /src/svg
parent8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76 (diff)
parent211bea9838bcc2acd7f54b65468fe1be2d81b1e0 (diff)
Merge branch '4.5' of git@scm.dev.nokia.troll.no:qt/qt
Configure.exe recompiled with MSVC6. Conflicts: configure.exe examples/network/network.pro src/gui/dialogs/qfiledialog_p.h src/gui/dialogs/qfilesystemmodel_p.h src/gui/kernel/qapplication.cpp tests/auto/_Categories/qmake.txt tests/auto/qfile/test/test.pro tests/auto/qfile/tst_qfile.cpp tests/auto/qlibrary/tst_qlibrary.cpp tests/auto/qline/tst_qline.cpp tests/auto/qstyle/tst_qstyle.cpp tests/auto/qtextstream/tst_qtextstream.cpp tests/auto/qtranslator/qtranslator.pro tests/auto/qwaitcondition/tst_qwaitcondition.cpp translations/qt_ja_JP.ts
Diffstat (limited to 'src/svg')
-rw-r--r--src/svg/qsvggenerator.cpp29
-rw-r--r--src/svg/qsvghandler.cpp18
-rw-r--r--src/svg/qsvgstyle.cpp12
-rw-r--r--src/svg/qsvgstyle_p.h11
-rw-r--r--src/svg/qsvgwidget.cpp16
5 files changed, 56 insertions, 30 deletions
diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp
index f7b2ae8a4b..e822da5f35 100644
--- a/src/svg/qsvggenerator.cpp
+++ b/src/svg/qsvggenerator.cpp
@@ -516,7 +516,34 @@ public:
\brief The QSvgGenerator class provides a paint device that is used to create SVG drawings.
\reentrant
- \sa QSvgRenderer, QSvgWidget
+ This paint device represents a Scalable Vector Graphics (SVG) drawing. Like QPrinter, it is
+ designed as a write-only device that generates output in a specific format.
+
+ To write an SVG file, you first need to configure the output by setting the \l fileName
+ or \l outputDevice properties. It is usually necessary to specify the size of the drawing
+ by setting the \l size property, and in some cases where the drawing will be included in
+ another, the \l viewBox property also needs to be set.
+
+ \snippet examples/painting/svggenerator/window.cpp configure SVG generator
+
+ Other meta-data can be specified by setting the \a title, \a description and \a resolution
+ properties.
+
+ As with other QPaintDevice subclasses, a QPainter object is used to paint onto an instance
+ of this class:
+
+ \snippet examples/painting/svggenerator/window.cpp begin painting
+ \dots
+ \snippet examples/painting/svggenerator/window.cpp end painting
+
+ Painting is performed in the same way as for any other paint device. However,
+ it is necessary to use the QPainter::begin() and \l{QPainter::}{end()} to
+ explicitly begin and end painting on the device.
+
+ The \l{SVG Generator Example} shows how the same painting commands can be used
+ for painting a widget and writing an SVG file.
+
+ \sa QSvgRenderer, QSvgWidget, {About SVG}
*/
/*!
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp
index 56dab5ffcf..433a3adc9b 100644
--- a/src/svg/qsvghandler.cpp
+++ b/src/svg/qsvghandler.cpp
@@ -2587,10 +2587,12 @@ static void parseBaseGradient(QSvgNode *node,
if (prop && prop->type() == QSvgStyleProperty::GRADIENT) {
QSvgGradientStyle *inherited =
static_cast<QSvgGradientStyle*>(prop);
- if (!inherited->stopLink().isEmpty())
+ if (!inherited->stopLink().isEmpty()) {
gradProp->setStopLink(inherited->stopLink(), handler->document());
- else
+ } else {
grad->setStops(inherited->qgradient()->stops());
+ gradProp->setGradientStopsSet(inherited->gradientStopsSet());
+ }
matrix = inherited->qmatrix();
} else {
@@ -2649,7 +2651,6 @@ static QSvgStyleProperty *createLinearGradientNode(QSvgNode *node,
}
QLinearGradient *grad = new QLinearGradient(nx1, ny1, nx2, ny2);
- grad->setColorAt(qQNaN(), QColor());
grad->setInterpolationMode(QGradient::ComponentInterpolation);
QSvgGradientStyle *prop = new QSvgGradientStyle(grad);
parseBaseGradient(node, attributes, prop, handler);
@@ -2783,7 +2784,6 @@ static QSvgStyleProperty *createRadialGradientNode(QSvgNode *node,
nfy = toDouble(fy);
QRadialGradient *grad = new QRadialGradient(ncx, ncy, nr, nfx, nfy);
- grad->setColorAt(qQNaN(), QColor());
grad->setInterpolationMode(QGradient::ComponentInterpolation);
QSvgGradientStyle *prop = new QSvgGradientStyle(grad);
@@ -2929,12 +2929,9 @@ static bool parseStopNode(QSvgStyleProperty *parent,
QGradient *grad = style->qgradient();
offset = qMin(qreal(1), qMax(qreal(0), offset)); // Clamp to range [0, 1]
- QGradientStops stops = grad->stops();
- // Check if the gradient is marked as empty (marked with one single stop at NaN).
- if ((stops.size() == 1) && qIsNaN(stops.at(0).first)) {
- stops.clear();
- grad->setStops(stops);
- } else {
+ QGradientStops stops;
+ if (style->gradientStopsSet()) {
+ stops = grad->stops();
// If the stop offset equals the one previously added, add an epsilon to make it greater.
if (offset <= stops.back().first)
offset = stops.back().first + FLT_EPSILON;
@@ -2950,6 +2947,7 @@ static bool parseStopNode(QSvgStyleProperty *parent,
}
grad->setColorAt(offset, color);
+ style->setGradientStopsSet(true);
if (!colorOK)
style->addResolve(offset);
return true;
diff --git a/src/svg/qsvgstyle.cpp b/src/svg/qsvgstyle.cpp
index 389f68f144..bd0804ca7c 100644
--- a/src/svg/qsvgstyle.cpp
+++ b/src/svg/qsvgstyle.cpp
@@ -231,7 +231,7 @@ void QSvgSolidColorStyle::revert(QPainter *p, QSvgExtraStates &)
}
QSvgGradientStyle::QSvgGradientStyle(QGradient *grad)
- : m_gradient(grad)
+ : m_gradient(grad), m_gradientStopsSet(false)
{
}
@@ -256,14 +256,13 @@ void QSvgGradientStyle::apply(QPainter *p, const QRectF &/*rect*/, QSvgNode *, Q
}
// If the gradient is marked as empty, insert transparent black
- QGradientStops stops = m_gradient->stops();
- if (stops.size() == 1 && qIsNaN(stops.at(0).first))
+ if (!m_gradientStopsSet) {
m_gradient->setStops(QGradientStops() << QGradientStop(0.0, QColor(0, 0, 0, 0)));
-
- QGradient gradient = *m_gradient;
+ m_gradientStopsSet = true;
+ }
QBrush brush;
- brush = QBrush(gradient);
+ brush = QBrush(*m_gradient);
if (!m_matrix.isIdentity())
brush.setMatrix(m_matrix);
@@ -809,6 +808,7 @@ void QSvgGradientStyle::resolveStops()
static_cast<QSvgGradientStyle*>(prop);
st->resolveStops();
m_gradient->setStops(st->qgradient()->stops());
+ m_gradientStopsSet = st->gradientStopsSet();
}
}
m_link = QString();
diff --git a/src/svg/qsvgstyle_p.h b/src/svg/qsvgstyle_p.h
index ff4058b265..058ba3583d 100644
--- a/src/svg/qsvgstyle_p.h
+++ b/src/svg/qsvgstyle_p.h
@@ -376,6 +376,16 @@ public:
}
void addResolve(qreal offset);
+
+ bool gradientStopsSet() const
+ {
+ return m_gradientStopsSet;
+ }
+
+ void setGradientStopsSet(bool set)
+ {
+ m_gradientStopsSet = set;
+ }
private:
QGradient *m_gradient;
QList<qreal> m_resolvePoints;
@@ -386,6 +396,7 @@ private:
QSvgTinyDocument *m_doc;
QString m_link;
+ bool m_gradientStopsSet;
};
class QSvgTransformStyle : public QSvgStyleProperty
diff --git a/src/svg/qsvgwidget.cpp b/src/svg/qsvgwidget.cpp
index a4200ca704..ac8595fbb2 100644
--- a/src/svg/qsvgwidget.cpp
+++ b/src/svg/qsvgwidget.cpp
@@ -83,18 +83,6 @@ class QSvgWidgetPrivate : public QWidgetPrivate
{
Q_DECLARE_PUBLIC(QSvgWidget)
public:
- QSvgWidgetPrivate()
- : QWidgetPrivate()
- {
- Q_Q(QSvgWidget);
- renderer = new QSvgRenderer(q);
- }
- QSvgWidgetPrivate(const QString &file)
- : QWidgetPrivate()
- {
- Q_Q(QSvgWidget);
- renderer = new QSvgRenderer(file, q);
- }
QSvgRenderer *renderer;
};
@@ -104,6 +92,7 @@ public:
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()));
}
@@ -113,8 +102,9 @@ QSvgWidget::QSvgWidget(QWidget *parent)
of the specified \a file.
*/
QSvgWidget::QSvgWidget(const QString &file, QWidget *parent)
- : QWidget(*new QSvgWidgetPrivate(file), parent, 0)
+ : QWidget(*new QSvgWidgetPrivate, parent, 0)
{
+ d_func()->renderer = new QSvgRenderer(file, this);
QObject::connect(d_func()->renderer, SIGNAL(repaintNeeded()),
this, SLOT(update()));
}