include/katie/QtScriptTools/QScriptEngineDebugger
include/katie/QtScriptTools/QtScriptTools
include/katie/QtScriptTools/qscriptenginedebugger.h
-include/katie/QtSvg/QGraphicsSvgItem
-include/katie/QtSvg/QSvgGenerator
-include/katie/QtSvg/QSvgRenderer
-include/katie/QtSvg/QSvgWidget
include/katie/QtSvg/QtSvg
-include/katie/QtSvg/qgraphicssvgitem.h
-include/katie/QtSvg/qsvggenerator.h
include/katie/QtSvg/qsvgrenderer.h
-include/katie/QtSvg/qsvgwidget.h
include/katie/QtTest/QEventSizeOfChecker
include/katie/QtTest/QSignalSpy
include/katie/QtTest/QSpontaneKeyEvent
include/katie/QtScriptTools/QScriptEngineDebugger
include/katie/QtScriptTools/QtScriptTools
include/katie/QtScriptTools/qscriptenginedebugger.h
-include/katie/QtSvg/QGraphicsSvgItem
-include/katie/QtSvg/QSvgGenerator
include/katie/QtSvg/QSvgRenderer
-include/katie/QtSvg/QSvgWidget
include/katie/QtSvg/QtSvg
-include/katie/QtSvg/qgraphicssvgitem.h
-include/katie/QtSvg/qsvggenerator.h
include/katie/QtSvg/qsvgrenderer.h
-include/katie/QtSvg/qsvgwidget.h
include/katie/QtTest/QEventSizeOfChecker
include/katie/QtTest/QSignalSpy
include/katie/QtTest/QSpontaneKeyEvent
include/katie/QtScriptTools/QtScriptTools
include/katie/QtScriptTools/qscriptenginedebugger.h
include/katie/QtSvg/
-include/katie/QtSvg/QGraphicsSvgItem
-include/katie/QtSvg/QSvgGenerator
include/katie/QtSvg/QSvgRenderer
-include/katie/QtSvg/QSvgWidget
include/katie/QtSvg/QtSvg
-include/katie/QtSvg/qgraphicssvgitem.h
-include/katie/QtSvg/qsvggenerator.h
include/katie/QtSvg/qsvgrenderer.h
-include/katie/QtSvg/qsvgwidget.h
include/katie/QtTest/
include/katie/QtTest/QEventSizeOfChecker
include/katie/QtTest/QSignalSpy
"QGraphicsSceneResizeEvent",
"QGraphicsSceneWheelEvent",
"QGraphicsSimpleTextItem",
- "QGraphicsSvgItem",
"QGraphicsTextItem",
"QGraphicsView",
"QGraphicsWidget",
"QStyleOptionViewItemV4",
"QStylePainter",
"QStylePlugin",
- "QSvgGenerator",
"QSvgRenderer",
- "QSvgWidget",
"QSyntaxHighlighter",
"QSystemSemaphore",
"QSystemTrayIcon",
#define QT_NO_STYLE_MOTIF
#define QT_NO_STYLE_PLASTIQUE
#define QT_NO_ACCESSIBILITY
+#define QT_NO_SVGGENERATOR
+#define QT_NO_SVGWIDGET
+#define QT_NO_GRAPHICSSVGITEM
// Not supported, used to bootstrap
#cmakedefine QT_NO_QOBJECT
#cmakedefine QT_NO_FSFILEENGINE
#cmakedefine QT_NO_FTP
#cmakedefine QT_NO_GRAPHICSEFFECT
-#cmakedefine QT_NO_GRAPHICSSVGITEM
#cmakedefine QT_NO_GRAPHICSVIEW
#cmakedefine QT_NO_GROUPBOX
#cmakedefine QT_NO_HTTP
#cmakedefine QT_NO_STYLE_STYLESHEET
#cmakedefine QT_NO_STYLE_WINDOWS
#cmakedefine QT_NO_SVG
-#cmakedefine QT_NO_SVGGENERATOR
#cmakedefine QT_NO_SVGRENDERER
-#cmakedefine QT_NO_SVGWIDGET
#cmakedefine QT_NO_SYNTAXHIGHLIGHTER
#cmakedefine QT_NO_SYSTEMSEMAPHORE
#cmakedefine QT_NO_SYSTEMTRAYICON
# define QT_NO_MENUBAR
#endif
-// QSvgGenerator
-#if !defined(QT_NO_SVGGENERATOR) && defined(QT_NO_SVG)
-# define QT_NO_SVGGENERATOR
-#endif
-
// QSvgRenderer
#if !defined(QT_NO_SVGRENDERER) && defined(QT_NO_SVG)
# define QT_NO_SVGRENDERER
# define QT_NO_STRINGLISTMODEL
#endif
-// QSvgWidget
-#if !defined(QT_NO_SVGWIDGET) && defined(QT_NO_SVGRENDERER)
-# define QT_NO_SVGWIDGET
-#endif
-
// QSyntaxHighlighter
#if !defined(QT_NO_SYNTAXHIGHLIGHTER) && defined(QT_NO_TEXTEDIT)
# define QT_NO_SYNTAXHIGHLIGHTER
# define QT_NO_FSCOMPLETER
#endif
-// QGraphicsSvgItem
-#if !defined(QT_NO_GRAPHICSSVGITEM) && (defined(QT_NO_SVGRENDERER) || defined(QT_NO_GRAPHICSVIEW))
-# define QT_NO_GRAPHICSSVGITEM
-#endif
-
// QComboBox
#if !defined(QT_NO_COMBOBOX) && (defined(QT_NO_LINEEDIT) || defined(QT_NO_STANDARDITEMMODEL) || defined(QT_NO_LISTVIEW))
# define QT_NO_COMBOBOX
\internal
Highlights \a item as selected.
-
- NOTE: This function is a duplicate of qt_graphicsItem_highlightSelected() in
- qgraphicssvgitem.cpp!
*/
static void qt_graphicsItem_highlightSelected(
QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option)
ExtraToolTip,
ExtraCursor,
ExtraCacheData,
- ExtraMaxDeviceCoordCacheSize,
ExtraBoundingRegionGranularity
};
if (widget && !viewRect.intersects(deviceRect))
return;
- // Resort to direct rendering if the device rect exceeds the
- // (optional) maximum bounds. (QGraphicsSvgItem uses this).
- QSize maximumCacheSize =
- itemd->extra(QGraphicsItemPrivate::ExtraMaxDeviceCoordCacheSize).toSize();
- if (!maximumCacheSize.isEmpty()
- && (deviceRect.width() > maximumCacheSize.width()
- || deviceRect.height() > maximumCacheSize.height())) {
- _q_paintItem(static_cast<QGraphicsWidget *>(item), painter, option, widget,
- oldPainterOpacity != newPainterOpacity, painterStateProtection);
- return;
- }
-
// Create or reuse offscreen pixmap, possibly scroll/blit from the old one.
// If the world transform is rotated we always recreate the cache to avoid
// wrong blending.
enum Type {
X11,
PostScript,
- SVG,
Raster,
Pdf,
)
set(SVG_PUBLIC_HEADERS
- QGraphicsSvgItem
- QSvgGenerator
QSvgRenderer
- QSvgWidget
)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/qsvgfont_p.h
${CMAKE_CURRENT_SOURCE_DIR}/qsvgtinydocument_p.h
${CMAKE_CURRENT_SOURCE_DIR}/qsvgrenderer.h
- ${CMAKE_CURRENT_SOURCE_DIR}/qsvgwidget.h
- ${CMAKE_CURRENT_SOURCE_DIR}/qgraphicssvgitem.h
- ${CMAKE_CURRENT_SOURCE_DIR}/qsvggenerator.h
)
set(SVG_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/qsvgfont.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qsvgtinydocument.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qsvgrenderer.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/qsvgwidget.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/qgraphicssvgitem.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/qsvggenerator.cpp
)
katie_generate_misc("${SVG_HEADERS}" QtSvg)
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2016 Ivailo Monev
-**
-** This file is part of the QtSvg module of the Katie Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-**
-** GNU Lesser General Public License Usage
-** 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.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "qgraphicssvgitem.h"
-
-#ifndef QT_NO_GRAPHICSSVGITEM
-
-#include "qpainter.h"
-#include "qstyleoption.h"
-#include "qsvgrenderer.h"
-#include "qdebug.h"
-
-#include "qobject_p.h"
-#include "qgraphicsitem_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QGraphicsSvgItemPrivate : public QGraphicsItemPrivate
-{
-public:
- Q_DECLARE_PUBLIC(QGraphicsSvgItem)
-
- QGraphicsSvgItemPrivate()
- : renderer(0), shared(false)
- {
- }
-
- void init(QGraphicsItem *parent)
- {
- Q_Q(QGraphicsSvgItem);
- q->setParentItem(parent);
- renderer = new QSvgRenderer(q);
- QObject::connect(renderer, SIGNAL(repaintNeeded()),
- q, SLOT(_q_repaintItem()));
- q->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
- q->setMaximumCacheSize(QSize(1024, 768));
- }
-
- void _q_repaintItem()
- {
- q_func()->update();
- }
-
- inline void updateDefaultSize()
- {
- QRectF bounds;
- if (elemId.isEmpty()) {
- bounds = QRectF(QPointF(0, 0), renderer->defaultSize());
- } else {
- bounds = renderer->boundsOnElement(elemId);
- }
- if (boundingRect.size() != bounds.size()) {
- q_func()->prepareGeometryChange();
- boundingRect.setSize(bounds.size());
- }
- }
-
- QSvgRenderer *renderer;
- QRectF boundingRect;
- bool shared;
- QString elemId;
-};
-
-/*!
- \class QGraphicsSvgItem
- \ingroup graphicsview-api
- \brief The QGraphicsSvgItem class is a QGraphicsItem that can be used to render
- the contents of SVG files.
-
- \since 4.2
-
- QGraphicsSvgItem provides a way of rendering SVG files onto QGraphicsView.
- QGraphicsSvgItem can be created by passing the SVG file to be rendered to
- its constructor or by explicit setting a shared QSvgRenderer on it.
-
- Note that setting QSvgRenderer on a QGraphicsSvgItem doesn't make the item take
- ownership of the renderer, therefore if using setSharedRenderer() method one has
- to make sure that the lifetime of the QSvgRenderer object will be at least as long
- as that of the QGraphicsSvgItem.
-
- QGraphicsSvgItem provides a way of rendering only parts of the SVG files via
- the setElementId. If setElementId() method is called, only the SVG element
- (and its children) with the passed id will be renderer. This provides a convenient
- way of selectively rendering large SVG files that contain a number of discrete
- elements. For example the following code renders only jokers from a SVG file
- containing a whole card deck:
-
- \snippet doc/src/snippets/code/src_svg_qgraphicssvgitem.cpp 0
-
- Size of the item can be set via the \l{QRectF::setSize()}
- {setSize()} method of the \l{QGraphicsSvgItem::boundingRect()}
- {bounding rectangle} or via direct manipulation of the items
- transformation matrix.
-
- By default the SVG rendering is cached using QGraphicsItem::DeviceCoordinateCache
- mode to speedup the display of items. Caching can be disabled by passing
- QGraphicsItem::NoCache to the QGraphicsItem::setCacheMode() method.
-
- \sa QSvgWidget, {QtSvg Module}, QGraphicsItem, QGraphicsView
-*/
-
-/*!
- Constructs a new SVG item with the given \a parent.
-*/
-QGraphicsSvgItem::QGraphicsSvgItem(QGraphicsItem *parent)
- : QGraphicsObject(*new QGraphicsSvgItemPrivate(), 0, 0)
-{
- Q_D(QGraphicsSvgItem);
- d->init(parent);
-}
-
-/*!
- Constructs a new item with the given \a parent and loads the contents of the
- SVG file with the specified \a fileName.
-*/
-QGraphicsSvgItem::QGraphicsSvgItem(const QString &fileName, QGraphicsItem *parent)
- : QGraphicsObject(*new QGraphicsSvgItemPrivate(), 0, 0)
-{
- Q_D(QGraphicsSvgItem);
- d->init(parent);
- d->renderer->load(fileName);
- d->updateDefaultSize();
-}
-
-/*!
- Returns the currently use QSvgRenderer.
-*/
-QSvgRenderer *QGraphicsSvgItem::renderer() const
-{
- return d_func()->renderer;
-}
-
-
-/*!
- Returns the bounding rectangle of this item.
-*/
-QRectF QGraphicsSvgItem::boundingRect() const
-{
- Q_D(const QGraphicsSvgItem);
- return d->boundingRect;
-}
-
-/*!
- \internal
-
- Highlights \a item as selected.
-
- NOTE: This function is a duplicate of qt_graphicsItem_highlightSelected() in qgraphicsitem.cpp!
-*/
-static void qt_graphicsItem_highlightSelected(
- QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option)
-{
- const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1));
- if (qFuzzyIsNull(qMax(murect.width(), murect.height())))
- return;
-
- const QRectF mbrect = painter->transform().mapRect(item->boundingRect());
- if (qMin(mbrect.width(), mbrect.height()) < qreal(1.0))
- return;
-
- qreal itemPenWidth;
- switch (item->type()) {
- case QGraphicsEllipseItem::Type:
- itemPenWidth = static_cast<QGraphicsEllipseItem *>(item)->pen().widthF();
- break;
- case QGraphicsPathItem::Type:
- itemPenWidth = static_cast<QGraphicsPathItem *>(item)->pen().widthF();
- break;
- case QGraphicsPolygonItem::Type:
- itemPenWidth = static_cast<QGraphicsPolygonItem *>(item)->pen().widthF();
- break;
- case QGraphicsRectItem::Type:
- itemPenWidth = static_cast<QGraphicsRectItem *>(item)->pen().widthF();
- break;
- case QGraphicsSimpleTextItem::Type:
- itemPenWidth = static_cast<QGraphicsSimpleTextItem *>(item)->pen().widthF();
- break;
- case QGraphicsLineItem::Type:
- itemPenWidth = static_cast<QGraphicsLineItem *>(item)->pen().widthF();
- break;
- default:
- itemPenWidth = 1.0;
- }
- const qreal pad = itemPenWidth / 2;
-
- const qreal penWidth = 0; // cosmetic pen
-
- const QColor fgcolor = option->palette.windowText().color();
- const QColor bgcolor( // ensure good contrast against fgcolor
- fgcolor.red() > 127 ? 0 : 255,
- fgcolor.green() > 127 ? 0 : 255,
- fgcolor.blue() > 127 ? 0 : 255);
-
- painter->setPen(QPen(bgcolor, penWidth, Qt::SolidLine));
- painter->setBrush(Qt::NoBrush);
- painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));
-
- painter->setPen(QPen(option->palette.windowText(), 0, Qt::DashLine));
- painter->setBrush(Qt::NoBrush);
- painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));
-}
-
-/*!
- \reimp
-*/
-void QGraphicsSvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget)
-{
-// Q_UNUSED(option);
- Q_UNUSED(widget);
-
- Q_D(QGraphicsSvgItem);
- if (!d->renderer->isValid())
- return;
-
- if (d->elemId.isEmpty())
- d->renderer->render(painter, d->boundingRect);
- else
- d->renderer->render(painter, d->elemId, d->boundingRect);
-
- if (option->state & QStyle::State_Selected)
- qt_graphicsItem_highlightSelected(this, painter, option);
-}
-
-/*!
- \reimp
-*/
-int QGraphicsSvgItem::type() const
-{
- return Type;
-}
-
-/*!
- \property QGraphicsSvgItem::maximumCacheSize
- \since 4.6
-
- This property holds the maximum size of the device coordinate cache
- for this item.
- */
-
-/*!
- Sets the maximum device coordinate cache size of the item to \a size.
- If the item is cached using QGraphicsItem::DeviceCoordinateCache mode,
- caching is bypassed if the extension of the item in device coordinates
- is larger than \a size.
-
- The cache corresponds to the QPixmap which is used to cache the
- results of the rendering.
- Use QPixmapCache::setCacheLimit() to set limitations on the whole cache
- and use setMaximumCacheSize() when setting cache size for individual
- items.
-
- \sa QGraphicsItem::cacheMode()
-*/
-void QGraphicsSvgItem::setMaximumCacheSize(const QSize &size)
-{
- QGraphicsItem::d_ptr->setExtra(QGraphicsItemPrivate::ExtraMaxDeviceCoordCacheSize, size);
- update();
-}
-
-/*!
- Returns the current maximum size of the device coordinate cache for this item.
- If the item is cached using QGraphicsItem::DeviceCoordinateCache mode,
- caching is bypassed if the extension of the item in device coordinates
- is larger than the maximum size.
-
- The default maximum cache size is 1024x768.
- QPixmapCache::cacheLimit() gives the
- cumulative bounds of the whole cache, whereas maximumCacheSize() refers
- to a maximum cache size for this particular item.
-
- \sa QGraphicsItem::cacheMode()
-*/
-QSize QGraphicsSvgItem::maximumCacheSize() const
-{
- return QGraphicsItem::d_ptr->extra(QGraphicsItemPrivate::ExtraMaxDeviceCoordCacheSize).toSize();
-}
-
-/*!
- \property QGraphicsSvgItem::elementId
- \since 4.6
-
- This property holds the element's XML ID.
- */
-
-/*!
- Sets the XML ID of the element to \a id.
-*/
-void QGraphicsSvgItem::setElementId(const QString &id)
-{
- Q_D(QGraphicsSvgItem);
- d->elemId = id;
- d->updateDefaultSize();
- update();
-}
-
-/*!
- Returns the XML ID the element that is currently
- being rendered. Returns an empty string if the whole
- file is being rendered.
-*/
-QString QGraphicsSvgItem::elementId() const
-{
- Q_D(const QGraphicsSvgItem);
- return d->elemId;
-}
-
-/*!
- Sets \a renderer to be a shared QSvgRenderer on the item. By
- using this method one can share the same QSvgRenderer on a number
- of items. This means that the SVG file will be parsed only once.
- QSvgRenderer passed to this method has to exist for as long as
- this item is used.
-*/
-void QGraphicsSvgItem::setSharedRenderer(QSvgRenderer *renderer)
-{
- Q_D(QGraphicsSvgItem);
- if (!d->shared)
- delete d->renderer;
-
- d->renderer = renderer;
- d->shared = true;
-
- d->updateDefaultSize();
-
- update();
-}
-
-/*!
- \obsolete
-
- Use QGraphicsItem::setCacheMode() instead. Passing true to this function is equivalent
- to QGraphicsItem::setCacheMode(QGraphicsItem::DeviceCoordinateCache).
-*/
-void QGraphicsSvgItem::setCachingEnabled(bool caching)
-{
- setCacheMode(caching ? QGraphicsItem::DeviceCoordinateCache : QGraphicsItem::NoCache);
-}
-
-/*!
- \obsolete
-
- Use QGraphicsItem::cacheMode() instead.
-*/
-bool QGraphicsSvgItem::isCachingEnabled() const
-{
- return cacheMode() != QGraphicsItem::NoCache;
-}
-
-QT_END_NAMESPACE
-
-
-
-#endif // QT_NO_GRAPHICSSVGITEM
-
-#include "moc_qgraphicssvgitem.h"
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2016 Ivailo Monev
-**
-** This file is part of the QtSvg module of the Katie Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-**
-** GNU Lesser General Public License Usage
-** 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.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef QGRAPHICSSVGITEM_H
-#define QGRAPHICSSVGITEM_H
-
-#include <QtGui/qgraphicsitem.h>
-
-#ifndef QT_NO_GRAPHICSSVGITEM
-
-
-QT_BEGIN_NAMESPACE
-
-
-class QSvgRenderer;
-class QGraphicsSvgItemPrivate;
-
-class Q_SVG_EXPORT QGraphicsSvgItem : public QGraphicsObject
-{
- Q_OBJECT
- Q_INTERFACES(QGraphicsItem)
- Q_PROPERTY(QString elementId READ elementId WRITE setElementId)
- Q_PROPERTY(QSize maximumCacheSize READ maximumCacheSize WRITE setMaximumCacheSize)
-
-public:
- QGraphicsSvgItem(QGraphicsItem *parentItem=0);
- QGraphicsSvgItem(const QString &fileName, QGraphicsItem *parentItem=0);
-
- void setSharedRenderer(QSvgRenderer *renderer);
- QSvgRenderer *renderer() const;
-
- void setElementId(const QString &id);
- QString elementId() const;
-
- void setCachingEnabled(bool);
- bool isCachingEnabled() const;
-
- void setMaximumCacheSize(const QSize &size);
- QSize maximumCacheSize() const;
-
- virtual QRectF boundingRect() const;
-
- virtual void paint(QPainter *painter,
- const QStyleOptionGraphicsItem *option,
- QWidget *widget=0);
-
- enum { Type = 13 };
- virtual int type() const;
-
-private:
- Q_DISABLE_COPY(QGraphicsSvgItem)
- Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QGraphicsSvgItem)
-
- Q_PRIVATE_SLOT(d_func(), void _q_repaintItem())
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QT_NO_GRAPHICSSVGITEM
-#endif // QGRAPHICSSVGITEM_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2016 Ivailo Monev
-**
-** This file is part of the QtSvg module of the Katie Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-**
-** GNU Lesser General Public License Usage
-** 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.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qsvggenerator.h"
-
-#ifndef QT_NO_SVGGENERATOR
-
-#include "qpainterpath.h"
-#include "qpaintengine_p.h"
-#include "qtextengine_p.h"
-#include "qdrawhelper_p.h"
-#include "qfile.h"
-#include "qtextcodec.h"
-#include "qtextstream.h"
-#include "qbuffer.h"
-#include "qmath.h"
-#include "qdebug.h"
-
-QT_BEGIN_NAMESPACE
-
-static void translate_color(const QColor &color, QString *color_string,
- QString *opacity_string)
-{
- Q_ASSERT(color_string);
- Q_ASSERT(opacity_string);
-
- *color_string = color.name();
- *opacity_string = QString::number(color.alphaF());
-}
-
-static void translate_dashPattern(const QVector<qreal> &pattern, const qreal& width, QString *pattern_string)
-{
- Q_ASSERT(pattern_string);
-
- // Note that SVG operates in absolute lengths, whereas Qt uses a length/width ratio.
- foreach (qreal entry, pattern) {
- *pattern_string += QString::fromLatin1("%1,").arg(entry * width);
- }
-
- pattern_string->chop(1);
-}
-
-class QSvgPaintEnginePrivate : public QPaintEnginePrivate
-{
-public:
- QSvgPaintEnginePrivate()
- : outputDevice(nullptr),
- resolution(72),
- afterFirstUpdate(false),
- numGradients(0)
- {
- attributes.document_title = QLatin1String("Katie Svg Document");
- attributes.document_description = QLatin1String("Generated with Katie");
- attributes.font_family = QLatin1String("freeserif");
- attributes.font_size = QLatin1String("10pt");
- attributes.font_style = QLatin1String("normal");
- attributes.font_weight = QLatin1String("normal");
- }
-
- QSize size;
- QRectF viewBox;
- QIODevice *outputDevice;
- QTextStream *stream;
- int resolution;
-
- QString header;
- QString defs;
- QString body;
- bool afterFirstUpdate;
-
- QBrush brush;
- QPen pen;
- QMatrix matrix;
- QFont font;
-
- QString generateGradientName() {
- ++numGradients;
- currentGradientName = QString::fromLatin1("gradient%1").arg(numGradients);
- return currentGradientName;
- }
-
- QString currentGradientName;
- int numGradients;
-
- struct _attributes {
- QString document_title;
- QString document_description;
- QString font_weight;
- QString font_size;
- QString font_family;
- QString font_style;
- QString stroke, strokeOpacity;
- QString dashPattern, dashOffset;
- QString fill, fillOpacity;
- } attributes;
-};
-
-static inline QPaintEngine::PaintEngineFeatures svgEngineFeatures()
-{
- return QPaintEngine::PaintEngineFeatures(
- QPaintEngine::AllFeatures
- & ~QPaintEngine::PerspectiveTransform
- & ~QPaintEngine::PorterDuff);
-}
-
-class QSvgPaintEngine : public QPaintEngine
-{
- Q_DECLARE_PRIVATE(QSvgPaintEngine)
-public:
-
- QSvgPaintEngine()
- : QPaintEngine(*new QSvgPaintEnginePrivate,
- svgEngineFeatures())
- {
- }
-
- bool begin(QPaintDevice *device);
- bool end();
-
- void updateState(const QPaintEngineState &state);
- void popGroup();
-
- void drawPath(const QPainterPath &path);
- void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
- void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
- void drawTextItem(const QPointF &pt, const QTextItem &item);
- void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
- Qt::ImageConversionFlags flags = Qt::AutoColor);
-
- QPaintEngine::Type type() const { return QPaintEngine::SVG; }
-
- QSize size() const { return d_func()->size; }
- void setSize(const QSize &size) {
- Q_ASSERT(!isActive());
- d_func()->size = size;
- }
-
- QRectF viewBox() const { return d_func()->viewBox; }
- void setViewBox(const QRectF &viewBox) {
- Q_ASSERT(!isActive());
- d_func()->viewBox = viewBox;
- }
-
- QString documentTitle() const { return d_func()->attributes.document_title; }
- void setDocumentTitle(const QString &title) {
- d_func()->attributes.document_title = title;
- }
-
- QString documentDescription() const { return d_func()->attributes.document_description; }
- void setDocumentDescription(const QString &description) {
- d_func()->attributes.document_description = description;
- }
-
- QIODevice *outputDevice() const { return d_func()->outputDevice; }
- void setOutputDevice(QIODevice *device) {
- Q_ASSERT(!isActive());
- d_func()->outputDevice = device;
- }
-
- int resolution() { return d_func()->resolution; }
- void setResolution(int resolution) {
- Q_ASSERT(!isActive());
- d_func()->resolution = resolution;
- }
- void saveLinearGradientBrush(const QGradient *g)
- {
- QTextStream str(&d_func()->defs, QIODevice::Append);
- const QLinearGradient *grad = static_cast<const QLinearGradient*>(g);
- str << QLatin1String("<linearGradient ");
- saveGradientUnits(str, g);
- if (grad) {
- str << QLatin1String("x1=\"") <<grad->start().x()<< QLatin1String("\" ")
- << QLatin1String("y1=\"") <<grad->start().y()<< QLatin1String("\" ")
- << QLatin1String("x2=\"") <<grad->finalStop().x() << QLatin1String("\" ")
- << QLatin1String("y2=\"") <<grad->finalStop().y() << QLatin1String("\" ");
- }
-
- str << QLatin1String("id=\"") << d_func()->generateGradientName() << QLatin1String("\">\n");
- saveGradientStops(str, g);
- str << QLatin1String("</linearGradient>") <<endl;
- }
- void saveRadialGradientBrush(const QGradient *g)
- {
- QTextStream str(&d_func()->defs, QIODevice::Append);
- const QRadialGradient *grad = static_cast<const QRadialGradient*>(g);
- str << QLatin1String("<radialGradient ");
- saveGradientUnits(str, g);
- if (grad) {
- str << QLatin1String("cx=\"") <<grad->center().x()<< QLatin1String("\" ")
- << QLatin1String("cy=\"") <<grad->center().y()<< QLatin1String("\" ")
- << QLatin1String("r=\"") <<grad->radius() << QLatin1String("\" ")
- << QLatin1String("fx=\"") <<grad->focalPoint().x() << QLatin1String("\" ")
- << QLatin1String("fy=\"") <<grad->focalPoint().y() << QLatin1String("\" ");
- }
- str << QLatin1String("xml:id=\"") <<d_func()->generateGradientName()<< QLatin1String("\">\n");
- saveGradientStops(str, g);
- str << QLatin1String("</radialGradient>") << endl;
- }
-
- void saveGradientStops(QTextStream &str, const QGradient *g) {
- QGradientStops stops = g->stops();
-
- if (g->interpolationMode() == QGradient::ColorInterpolation) {
- bool constantAlpha = true;
- int alpha = stops.at(0).second.alpha();
- for (int i = 1; i < stops.size(); ++i)
- constantAlpha &= (stops.at(i).second.alpha() == alpha);
-
- if (!constantAlpha) {
- const qreal spacing = qreal(0.02);
- QGradientStops newStops;
- QRgb fromColor = PREMUL(stops.at(0).second.rgba());
- QRgb toColor;
- for (int i = 0; i + 1 < stops.size(); ++i) {
- int parts = qCeil((stops.at(i + 1).first - stops.at(i).first) / spacing);
- newStops.append(stops.at(i));
- toColor = PREMUL(stops.at(i + 1).second.rgba());
-
- if (parts > 1) {
- qreal step = (stops.at(i + 1).first - stops.at(i).first) / parts;
- for (int j = 1; j < parts; ++j) {
- QRgb color = INV_PREMUL(INTERPOLATE_PIXEL_256(fromColor, 256 - 256 * j / parts, toColor, 256 * j / parts));
- newStops.append(QGradientStop(stops.at(i).first + j * step, QColor::fromRgba(color)));
- }
- }
- fromColor = toColor;
- }
- newStops.append(stops.back());
- stops = newStops;
- }
- }
-
- foreach(QGradientStop stop, stops) {
- str << QLatin1String(" <stop offset=\"")<< stop.first << QLatin1String("\" ")
- << QLatin1String("stop-color=\"") << stop.second.name() << QLatin1String("\" ")
- << QLatin1String("stop-opacity=\"") << stop.second.alphaF() <<QLatin1String("\" />\n");
- }
- }
-
- void saveGradientUnits(QTextStream &str, const QGradient *gradient)
- {
- str << QLatin1String("gradientUnits=\"");
- if (gradient && gradient->coordinateMode() == QGradient::ObjectBoundingMode)
- str << QLatin1String("objectBoundingBox");
- else
- str << QLatin1String("userSpaceOnUse");
- str << QLatin1String("\" ");
- }
-
- void generateQtDefaults()
- {
- *d_func()->stream << QLatin1String("fill=\"none\" ");
- *d_func()->stream << QLatin1String("stroke=\"black\" ");
- *d_func()->stream << QLatin1String("stroke-width=\"1\" ");
- *d_func()->stream << QLatin1String("fill-rule=\"evenodd\" ");
- *d_func()->stream << QLatin1String("stroke-linecap=\"square\" ");
- *d_func()->stream << QLatin1String("stroke-linejoin=\"bevel\" ");
- *d_func()->stream << QLatin1String(">\n");
- }
- inline QTextStream &stream()
- {
- return *d_func()->stream;
- }
-
-
- void qpenToSvg(const QPen &spen)
- {
- QString width;
-
- d_func()->pen = spen;
-
- switch (spen.style()) {
- case Qt::NoPen:
- stream() << QLatin1String("stroke=\"none\" ");
-
- d_func()->attributes.stroke = QLatin1String("none");
- d_func()->attributes.strokeOpacity = QString();
- return;
- case Qt::SolidLine: {
- QString color, colorOpacity;
-
- translate_color(spen.color(), &color,
- &colorOpacity);
- d_func()->attributes.stroke = color;
- d_func()->attributes.strokeOpacity = colorOpacity;
-
- stream() << QLatin1String("stroke=\"")<<color<< QLatin1String("\" ");
- stream() << QLatin1String("stroke-opacity=\"")<<colorOpacity<< QLatin1String("\" ");
- break;
- }
- case Qt::DashLine:
- case Qt::DotLine:
- case Qt::DashDotLine:
- case Qt::DashDotDotLine:
- case Qt::CustomDashLine: {
- QString color, colorOpacity, dashPattern, dashOffset;
-
- qreal penWidth = spen.width() == 0 ? qreal(1) : spen.widthF();
-
- translate_color(spen.color(), &color, &colorOpacity);
- translate_dashPattern(spen.dashPattern(), penWidth, &dashPattern);
-
- // SVG uses absolute offset
- dashOffset = QString::number(spen.dashOffset() * penWidth);
-
- d_func()->attributes.stroke = color;
- d_func()->attributes.strokeOpacity = colorOpacity;
- d_func()->attributes.dashPattern = dashPattern;
- d_func()->attributes.dashOffset = dashOffset;
-
- stream() << QLatin1String("stroke=\"")<<color<< QLatin1String("\" ");
- stream() << QLatin1String("stroke-opacity=\"")<<colorOpacity<< QLatin1String("\" ");
- stream() << QLatin1String("stroke-dasharray=\"")<<dashPattern<< QLatin1String("\" ");
- stream() << QLatin1String("stroke-dashoffset=\"")<<dashOffset<< QLatin1String("\" ");
- break;
- }
- default:
- qWarning("Unsupported pen style");
- break;
- }
-
- if (spen.widthF() == 0)
- stream() <<"stroke-width=\"1\" ";
- else
- stream() <<"stroke-width=\"" << spen.widthF() << "\" ";
-
- switch (spen.capStyle()) {
- case Qt::FlatCap:
- stream() << "stroke-linecap=\"butt\" ";
- break;
- case Qt::SquareCap:
- stream() << "stroke-linecap=\"square\" ";
- break;
- case Qt::RoundCap:
- stream() << "stroke-linecap=\"round\" ";
- break;
- default:
- qWarning("Unhandled cap style");
- }
- switch (spen.joinStyle()) {
- case Qt::SvgMiterJoin:
- case Qt::MiterJoin:
- stream() << "stroke-linejoin=\"miter\" "
- "stroke-miterlimit=\""<<spen.miterLimit()<<"\" ";
- break;
- case Qt::BevelJoin:
- stream() << "stroke-linejoin=\"bevel\" ";
- break;
- case Qt::RoundJoin:
- stream() << "stroke-linejoin=\"round\" ";
- break;
- default:
- qWarning("Unhandled join style");
- }
- }
- void qbrushToSvg(const QBrush &sbrush)
- {
- d_func()->brush = sbrush;
- switch (sbrush.style()) {
- case Qt::SolidPattern: {
- QString color, colorOpacity;
- translate_color(sbrush.color(), &color, &colorOpacity);
- stream() << "fill=\"" << color << "\" "
- "fill-opacity=\""
- << colorOpacity << "\" ";
- d_func()->attributes.fill = color;
- d_func()->attributes.fillOpacity = colorOpacity;
- break;
- }
- case Qt::LinearGradientPattern:
- saveLinearGradientBrush(sbrush.gradient());
- d_func()->attributes.fill = QString::fromLatin1("url(#%1)").arg(d_func()->currentGradientName);
- d_func()->attributes.fillOpacity = QString();
- stream() << QLatin1String("fill=\"url(#") << d_func()->currentGradientName << QLatin1String(")\" ");
- break;
- case Qt::RadialGradientPattern:
- saveRadialGradientBrush(sbrush.gradient());
- d_func()->attributes.fill = QString::fromLatin1("url(#%1)").arg(d_func()->currentGradientName);
- d_func()->attributes.fillOpacity = QString();
- stream() << QLatin1String("fill=\"url(#") << d_func()->currentGradientName << QLatin1String(")\" ");
- break;
- case Qt::NoBrush:
- stream() << QLatin1String("fill=\"none\" ");
- d_func()->attributes.fill = QLatin1String("none");
- d_func()->attributes.fillOpacity = QString();
- return;
- break;
- default:
- break;
- }
- }
- void qfontToSvg(const QFont &sfont)
- {
- Q_D(QSvgPaintEngine);
-
- d->font = sfont;
-
- if (d->font.pixelSize() == -1)
- d->attributes.font_size = QString::number(d->font.pointSizeF() * d->resolution / 72);
- else
- d->attributes.font_size = QString::number(d->font.pixelSize());
-
- int svgWeight = d->font.weight();
- switch (svgWeight) {
- case QFont::Light:
- svgWeight = 100;
- break;
- case QFont::Normal:
- svgWeight = 400;
- break;
- case QFont::Bold:
- svgWeight = 700;
- break;
- default:
- svgWeight *= 10;
- break;
- }
-
- d->attributes.font_weight = QString::number(svgWeight);
- d->attributes.font_family = d->font.family();
- d->attributes.font_style = d->font.italic() ? QLatin1String("italic") : QLatin1String("normal");
-
- *d->stream << "font-family=\"" << d->attributes.font_family << "\" "
- "font-size=\"" << d->attributes.font_size << "\" "
- "font-weight=\"" << d->attributes.font_weight << "\" "
- "font-style=\"" << d->attributes.font_style << "\" "
- << endl;
- }
-};
-
-class QSvgGeneratorPrivate
-{
-public:
- QSvgPaintEngine *engine;
-
- bool owns_iodevice;
- QString fileName;
-};
-
-/*!
- \class QSvgGenerator
- \ingroup painting
- \since 4.3
- \brief The QSvgGenerator class provides a paint device that is used to create SVG drawings.
- \reentrant
-
- 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}
-*/
-
-/*!
- Constructs a new generator.
-*/
-QSvgGenerator::QSvgGenerator()
- : d_ptr(new QSvgGeneratorPrivate)
-{
- Q_D(QSvgGenerator);
-
- d->engine = new QSvgPaintEngine;
- d->owns_iodevice = false;
-}
-
-/*!
- Destroys the generator.
-*/
-QSvgGenerator::~QSvgGenerator()
-{
- Q_D(QSvgGenerator);
- if (d->owns_iodevice)
- delete d->engine->outputDevice();
- delete d->engine;
- delete d_ptr;
-}
-
-/*!
- \property QSvgGenerator::title
- \brief the title of the generated SVG drawing
- \since 4.5
- \sa description
-*/
-QString QSvgGenerator::title() const
-{
- Q_D(const QSvgGenerator);
-
- return d->engine->documentTitle();
-}
-
-void QSvgGenerator::setTitle(const QString &title)
-{
- Q_D(QSvgGenerator);
-
- d->engine->setDocumentTitle(title);
-}
-
-/*!
- \property QSvgGenerator::description
- \brief the description of the generated SVG drawing
- \since 4.5
- \sa title
-*/
-QString QSvgGenerator::description() const
-{
- Q_D(const QSvgGenerator);
-
- return d->engine->documentDescription();
-}
-
-void QSvgGenerator::setDescription(const QString &description)
-{
- Q_D(QSvgGenerator);
-
- d->engine->setDocumentDescription(description);
-}
-
-/*!
- \property QSvgGenerator::size
- \brief the size of the generated SVG drawing
- \since 4.5
-
- By default this property is set to \c{QSize(-1, -1)}, which
- indicates that the generator should not output the width and
- height attributes of the \c<svg> element.
-
- \note It is not possible to change this property while a
- QPainter is active on the generator.
-
- \sa viewBox, resolution
-*/
-QSize QSvgGenerator::size() const
-{
- Q_D(const QSvgGenerator);
- return d->engine->size();
-}
-
-void QSvgGenerator::setSize(const QSize &size)
-{
- Q_D(QSvgGenerator);
- if (Q_UNLIKELY(d->engine->isActive())) {
- qWarning("QSvgGenerator::setSize(), cannot set size while SVG is being generated");
- return;
- }
- d->engine->setSize(size);
-}
-
-/*!
- \property QSvgGenerator::viewBox
- \brief the viewBox of the generated SVG drawing
- \since 4.5
-
- By default this property is set to \c{QRect(0, 0, -1, -1)}, which
- indicates that the generator should not output the viewBox attribute
- of the \c<svg> element.
-
- \note It is not possible to change this property while a
- QPainter is active on the generator.
-
- \sa viewBox(), size, resolution
-*/
-QRectF QSvgGenerator::viewBoxF() const
-{
- Q_D(const QSvgGenerator);
- return d->engine->viewBox();
-}
-
-/*!
- \since 4.5
-
- Returns viewBoxF().toRect().
-
- \sa viewBoxF()
-*/
-QRect QSvgGenerator::viewBox() const
-{
- Q_D(const QSvgGenerator);
- return d->engine->viewBox().toRect();
-}
-
-void QSvgGenerator::setViewBox(const QRectF &viewBox)
-{
- Q_D(QSvgGenerator);
- if (Q_UNLIKELY(d->engine->isActive())) {
- qWarning("QSvgGenerator::setViewBox(), cannot set viewBox while SVG is being generated");
- return;
- }
- d->engine->setViewBox(viewBox);
-}
-
-void QSvgGenerator::setViewBox(const QRect &viewBox)
-{
- setViewBox(QRectF(viewBox));
-}
-
-/*!
- \property QSvgGenerator::fileName
- \brief the target filename for the generated SVG drawing
- \since 4.5
-
- \sa outputDevice
-*/
-QString QSvgGenerator::fileName() const
-{
- Q_D(const QSvgGenerator);
- return d->fileName;
-}
-
-void QSvgGenerator::setFileName(const QString &fileName)
-{
- Q_D(QSvgGenerator);
- if (Q_UNLIKELY(d->engine->isActive())) {
- qWarning("QSvgGenerator::setFileName(), cannot set file name while SVG is being generated");
- return;
- }
-
- if (d->owns_iodevice)
- delete d->engine->outputDevice();
-
- d->owns_iodevice = true;
-
- d->fileName = fileName;
- QFile *file = new QFile(fileName);
- d->engine->setOutputDevice(file);
-}
-
-/*!
- \property QSvgGenerator::outputDevice
- \brief the output device for the generated SVG drawing
- \since 4.5
-
- If both output device and file name are specified, the output device
- will have precedence.
-
- \sa fileName
-*/
-QIODevice *QSvgGenerator::outputDevice() const
-{
- Q_D(const QSvgGenerator);
- return d->engine->outputDevice();
-}
-
-void QSvgGenerator::setOutputDevice(QIODevice *outputDevice)
-{
- Q_D(QSvgGenerator);
- if (Q_UNLIKELY(d->engine->isActive())) {
- qWarning("QSvgGenerator::setOutputDevice(), cannot set output device while SVG is being generated");
- return;
- }
- d->owns_iodevice = false;
- d->engine->setOutputDevice(outputDevice);
- d->fileName = QString();
-}
-
-/*!
- \property QSvgGenerator::resolution
- \brief the resolution of the generated output
- \since 4.5
-
- The resolution is specified in dots per inch, and is used to
- calculate the physical size of an SVG drawing.
-
- \sa size, viewBox
-*/
-int QSvgGenerator::resolution() const
-{
- Q_D(const QSvgGenerator);
- return d->engine->resolution();
-}
-
-void QSvgGenerator::setResolution(int dpi)
-{
- Q_D(QSvgGenerator);
- d->engine->setResolution(dpi);
-}
-
-/*!
- Returns the paint engine used to render graphics to be converted to SVG
- format information.
-*/
-QPaintEngine *QSvgGenerator::paintEngine() const
-{
- Q_D(const QSvgGenerator);
- return d->engine;
-}
-
-/*!
- \reimp
-*/
-int QSvgGenerator::metric(QPaintDevice::PaintDeviceMetric metric) const
-{
- Q_D(const QSvgGenerator);
- switch (metric) {
- case QPaintDevice::PdmDepth:
- return 32;
- case QPaintDevice::PdmWidth:
- return d->engine->size().width();
- case QPaintDevice::PdmHeight:
- return d->engine->size().height();
- case QPaintDevice::PdmDpiX:
- return d->engine->resolution();
- case QPaintDevice::PdmDpiY:
- return d->engine->resolution();
- case QPaintDevice::PdmHeightMM:
- return qRound(d->engine->size().height() * 25.4 / d->engine->resolution());
- case QPaintDevice::PdmWidthMM:
- return qRound(d->engine->size().width() * 25.4 / d->engine->resolution());
- case QPaintDevice::PdmNumColors:
- return 0xffffffff;
- case QPaintDevice::PdmPhysicalDpiX:
- return d->engine->resolution();
- case QPaintDevice::PdmPhysicalDpiY:
- return d->engine->resolution();
- default:
- qWarning("QSvgGenerator::metric(), unhandled metric %d\n", metric);
- break;
- }
- return 0;
-}
-
-/*****************************************************************************
- * class QSvgPaintEngine
- */
-
-bool QSvgPaintEngine::begin(QPaintDevice *)
-{
- Q_D(QSvgPaintEngine);
- if (Q_UNLIKELY(!d->outputDevice)) {
- qWarning("QSvgPaintEngine::begin(), no output device");
- return false;
- } else if (!d->outputDevice->isOpen()) {
- if (Q_UNLIKELY(!d->outputDevice->open(QIODevice::WriteOnly | QIODevice::Text))) {
- qWarning("QSvgPaintEngine::begin(), could not open output device: '%s'",
- qPrintable(d->outputDevice->errorString()));
- return false;
- }
- } else if (Q_UNLIKELY(!d->outputDevice->isWritable())) {
- qWarning("QSvgPaintEngine::begin(), could not write to read-only output device: '%s'",
- qPrintable(d->outputDevice->errorString()));
- return false;
- }
-
- d->stream = new QTextStream(&d->header);
-
- // stream out the header...
- *d->stream << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" << endl << "<svg";
-
- if (d->size.isValid()) {
- qreal wmm = d->size.width() * 25.4 / d->resolution;
- qreal hmm = d->size.height() * 25.4 / d->resolution;
- *d->stream << " width=\"" << wmm << "mm\" height=\"" << hmm << "mm\"" << endl;
- }
-
- if (d->viewBox.isValid()) {
- *d->stream << " viewBox=\"" << d->viewBox.left() << ' ' << d->viewBox.top();
- *d->stream << ' ' << d->viewBox.width() << ' ' << d->viewBox.height() << '\"' << endl;
- }
-
- *d->stream << " xmlns=\"http://www.w3.org/2000/svg\""
- " xmlns:xlink=\"http://www.w3.org/1999/xlink\" "
- " version=\"1.2\" baseProfile=\"tiny\">" << endl;
-
- if (!d->attributes.document_title.isEmpty()) {
- *d->stream << "<title>" << d->attributes.document_title << "</title>" << endl;
- }
-
- if (!d->attributes.document_description.isEmpty()) {
- *d->stream << "<desc>" << d->attributes.document_description << "</desc>" << endl;
- }
-
- d->stream->setString(&d->defs);
- *d->stream << "<defs>\n";
-
- d->stream->setString(&d->body);
- // Start the initial graphics state...
- *d->stream << "<g ";
- generateQtDefaults();
- *d->stream << endl;
-
- return true;
-}
-
-bool QSvgPaintEngine::end()
-{
- Q_D(QSvgPaintEngine);
-
- d->stream->setString(&d->defs);
- *d->stream << "</defs>\n";
-
- d->stream->setDevice(d->outputDevice);
-#ifndef QT_NO_TEXTCODEC
- d->stream->setCodec(QTextCodec::codecForName("UTF-8"));
-#endif
-
- *d->stream << d->header;
- *d->stream << d->defs;
- *d->stream << d->body;
- if (d->afterFirstUpdate)
- *d->stream << "</g>" << endl; // close the updateState
-
- *d->stream << "</g>" << endl // close the Qt defaults
- << "</svg>" << endl;
-
- delete d->stream;
-
- return true;
-}
-
-void QSvgPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm,
- const QRectF &sr)
-{
- drawImage(r, pm.toImage(), sr);
-}
-
-void QSvgPaintEngine::drawImage(const QRectF &r, const QImage &image,
- const QRectF &sr,
- Qt::ImageConversionFlags flags)
-{
- //Q_D(QSvgPaintEngine);
-
- Q_UNUSED(sr);
- Q_UNUSED(flags);
- stream() << "<image ";
- stream() << "x=\""<<r.x()<<"\" "
- "y=\""<<r.y()<<"\" "
- "width=\""<<r.width()<<"\" "
- "height=\""<<r.height()<<"\" "
- "preserveAspectRatio=\"none\" ";
-
- QByteArray data;
- QBuffer buffer(&data);
- buffer.open(QBuffer::WriteOnly);
- image.save(&buffer, "PNG");
- buffer.close();
- stream() << "xlink:href=\"data:image/png;base64,"
- << data.toBase64()
- <<"\" />\n";
-}
-
-void QSvgPaintEngine::updateState(const QPaintEngineState &state)
-{
- Q_D(QSvgPaintEngine);
- // close old state and start a new one...
- if (d->afterFirstUpdate)
- *d->stream << "</g>\n\n";
-
- *d->stream << "<g ";
-
- qbrushToSvg(state.brush());
-
- qpenToSvg(state.pen());
-
- d->matrix = state.matrix();
- *d->stream << "transform=\"matrix(" << d->matrix.m11() << ','
- << d->matrix.m12() << ','
- << d->matrix.m21() << ',' << d->matrix.m22() << ','
- << d->matrix.dx() << ',' << d->matrix.dy()
- << ")\""
- << endl;
-
- qfontToSvg(state.font());
-
- if (!qFuzzyIsNull(state.opacity() - 1))
- stream() << "opacity=\""<<state.opacity()<<"\" ";
-
- *d->stream << '>' << endl;
-
- d->afterFirstUpdate = true;
-}
-
-void QSvgPaintEngine::drawPath(const QPainterPath &p)
-{
- Q_D(QSvgPaintEngine);
-
- *d->stream << "<path vector-effect=\""
- << (state->pen().isCosmetic() ? "non-scaling-stroke" : "none")
- << "\" fill-rule=\""
- << (p.fillRule() == Qt::OddEvenFill ? "evenodd" : "nonzero")
- << "\" d=\"";
-
- for (int i=0; i<p.elementCount(); ++i) {
- const QPainterPath::Element &e = p.elementAt(i);
- switch (e.type) {
- case QPainterPath::MoveToElement:
- *d->stream << 'M' << e.x << ',' << e.y;
- break;
- case QPainterPath::LineToElement:
- *d->stream << 'L' << e.x << ',' << e.y;
- break;
- case QPainterPath::CurveToElement:
- *d->stream << 'C' << e.x << ',' << e.y;
- ++i;
- while (i < p.elementCount()) {
- const QPainterPath::Element &e = p.elementAt(i);
- if (e.type != QPainterPath::CurveToDataElement) {
- --i;
- break;
- } else
- *d->stream << ' ';
- *d->stream << e.x << ',' << e.y;
- ++i;
- }
- break;
- default:
- break;
- }
- if (i != p.elementCount() - 1) {
- *d->stream << ' ';
- }
- }
-
- *d->stream << "\"/>" << endl;
-}
-
-void QSvgPaintEngine::drawPolygon(const QPointF *points, int pointCount,
- PolygonDrawMode mode)
-{
- Q_ASSERT(pointCount >= 2);
-
- //Q_D(QSvgPaintEngine);
-
- QPainterPath path(points[0]);
- for (int i=1; i<pointCount; ++i)
- path.lineTo(points[i]);
-
- if (mode == PolylineMode) {
- stream() << "<polyline fill=\"none\" vector-effect=\""
- << (state->pen().isCosmetic() ? "non-scaling-stroke" : "none")
- << "\" points=\"";
- for (int i = 0; i < pointCount; ++i) {
- const QPointF &pt = points[i];
- stream() << pt.x() << ',' << pt.y() << ' ';
- }
- stream() << "\" />" <<endl;
- } else {
- path.closeSubpath();
- drawPath(path);
- }
-}
-
-void QSvgPaintEngine::drawTextItem(const QPointF &pt, const QTextItem &textItem)
-{
- Q_D(QSvgPaintEngine);
- if (d->pen.style() == Qt::NoPen)
- return;
-
- *d->stream << "<text "
- "fill=\"" << d->attributes.stroke << "\" "
- "fill-opacity=\"" << d->attributes.strokeOpacity << "\" "
- "stroke=\"none\" "
- "xml:space=\"preserve\" "
- "x=\"" << pt.x() << "\" y=\"" << pt.y() << "\" ";
- qfontToSvg(textItem.font());
- *d->stream << " >"
- << Qt::escape(textItem.text())
- << "</text>"
- << endl;
-}
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_SVGGENERATOR
-
-
-
-#include "moc_qsvggenerator.h"
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2016 Ivailo Monev
-**
-** This file is part of the QtSvg module of the Katie Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-**
-** GNU Lesser General Public License Usage
-** 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.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSVGGENERATOR_H
-#define QSVGGENERATOR_H
-
-#include <QtGui/qpaintdevice.h>
-
-#ifndef QT_NO_SVGGENERATOR
-
-#include <QtCore/qnamespace.h>
-#include <QtCore/qiodevice.h>
-#include <QtCore/qobjectdefs.h>
-#include <QtCore/qrect.h>
-
-
-QT_BEGIN_NAMESPACE
-
-
-class QSvgGeneratorPrivate;
-
-class Q_SVG_EXPORT QSvgGenerator : public QObject, public QPaintDevice
-{
- Q_OBJECT
-
- Q_DECLARE_PRIVATE(QSvgGenerator)
-
- Q_PROPERTY(QSize size READ size WRITE setSize)
- Q_PROPERTY(QRectF viewBox READ viewBoxF WRITE setViewBox)
- Q_PROPERTY(QString title READ title WRITE setTitle)
- Q_PROPERTY(QString description READ description WRITE setDescription)
- Q_PROPERTY(QString fileName READ fileName WRITE setFileName)
- Q_PROPERTY(QIODevice* outputDevice READ outputDevice WRITE setOutputDevice)
- Q_PROPERTY(int resolution READ resolution WRITE setResolution)
-public:
- QSvgGenerator();
- ~QSvgGenerator();
-
- QString title() const;
- void setTitle(const QString &title);
-
- QString description() const;
- void setDescription(const QString &description);
-
- QSize size() const;
- void setSize(const QSize &size);
-
- QRect viewBox() const;
- QRectF viewBoxF() const;
- void setViewBox(const QRect &viewBox);
- void setViewBox(const QRectF &viewBox);
-
- QString fileName() const;
- void setFileName(const QString &fileName);
-
- QIODevice *outputDevice() const;
- void setOutputDevice(QIODevice *outputDevice);
-
- void setResolution(int dpi);
- int resolution() const;
-protected:
- QPaintEngine *paintEngine() const;
- int metric(QPaintDevice::PaintDeviceMetric metric) const;
-
-private:
- QSvgGeneratorPrivate* d_ptr;
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QT_NO_SVGGENERATOR
-#endif // QSVGGENERATOR_H
Finally, the QSvgRenderer class provides the repaintNeeded() signal which is emitted
whenever the rendering of the document needs to be updated.
- \sa QSvgWidget, {QtSvg Module}, {SVG Viewer Example}
+ \sa {QtSvg Module}, {SVG Viewer Example}
*/
class QSvgRendererPrivate : public QObjectPrivate
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2016 Ivailo Monev
-**
-** This file is part of the QtSvg module of the Katie Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-**
-** GNU Lesser General Public License Usage
-** 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.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qsvgwidget.h"
-
-#ifndef QT_NO_SVGWIDGET
-
-#include "qsvgrenderer.h"
-
-#include "qpainter.h"
-#include "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.
- 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}
-*/
-
-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
-
-#include "moc_qsvgwidget.h"
-
-
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2016 Ivailo Monev
-**
-** This file is part of the QtSvg module of the Katie Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-**
-** GNU Lesser General Public License Usage
-** 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.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSVGWIDGET_H
-#define QSVGWIDGET_H
-
-#include <QtGui/qwidget.h>
-
-#ifndef QT_NO_SVGWIDGET
-
-
-QT_BEGIN_NAMESPACE
-
-
-class QSvgWidgetPrivate;
-class QPaintEvent;
-class QSvgRenderer;
-
-class Q_SVG_EXPORT QSvgWidget : public QWidget
-{
- Q_OBJECT
-public:
- QSvgWidget(QWidget *parent = nullptr);
- QSvgWidget(const QString &file, QWidget *parent = nullptr);
- ~QSvgWidget();
-
- QSvgRenderer *renderer() const;
-
- QSize sizeHint() const;
-public Q_SLOTS:
- void load(const QString &file);
- void load(const QByteArray &contents);
-protected:
- void paintEvent(QPaintEvent *event);
-private:
- Q_DISABLE_COPY(QSvgWidget)
- Q_DECLARE_PRIVATE(QSvgWidget)
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QT_NO_SVGWIDGET
-#endif // QSVGWIDGET_H
{ QLatin1String("QGraphicsSceneResizeEvent"), QLatin1String("QtGui/qgraphicssceneevent.h") },
{ QLatin1String("QGraphicsSceneWheelEvent"), QLatin1String("QtGui/qgraphicssceneevent.h") },
{ QLatin1String("QGraphicsSimpleTextItem"), QLatin1String("QtGui/qgraphicsitem.h") },
- { QLatin1String("QGraphicsSvgItem"), QLatin1String("QtSvg/qgraphicssvgitem.h") },
{ QLatin1String("QGraphicsTextItem"), QLatin1String("QtGui/qgraphicsitem.h") },
{ QLatin1String("QGraphicsTransform"), QLatin1String("QtGui/qgraphicstransform.h") },
{ QLatin1String("QGraphicsView"), QLatin1String("QtGui/qgraphicsview.h") },
{ QLatin1String("QStylePainter"), QLatin1String("QtGui/qstylepainter.h") },
{ QLatin1String("QStylePlugin"), QLatin1String("QtGui/qstyleplugin.h") },
{ QLatin1String("QStyledItemDelegate"), QLatin1String("QtGui/qstyleditemdelegate.h") },
- { QLatin1String("QSvgGenerator"), QLatin1String("QtSvg/qsvggenerator.h") },
{ QLatin1String("QSvgRenderer"), QLatin1String("QtSvg/qsvgrenderer.h") },
- { QLatin1String("QSvgWidget"), QLatin1String("QtSvg/qsvgwidget.h") },
{ QLatin1String("QSyntaxHighlighter"), QLatin1String("QtGui/qsyntaxhighlighter.h") },
{ QLatin1String("QSystemSemaphore"), QLatin1String("QtCore/qsystemsemaphore.h") },
{ QLatin1String("QSystemTrayIcon"), QLatin1String("QtGui/qsystemtrayicon.h") },