diff options
author | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2020-01-27 14:22:19 +0100 |
---|---|---|
committer | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2020-01-28 10:21:12 +0100 |
commit | 84bc219fb1e9f586c1f7ac2c10172c4da2605f96 (patch) | |
tree | 99d22acb9c4924fa6cd7e3bad23aed4273321445 /src/svg/qsvgrenderer.cpp | |
parent | 69175cddec56c681b7873d6145cc29e461f1d8b1 (diff) | |
download | qtsvg-84bc219fb1e9f586c1f7ac2c10172c4da2605f96.tar.gz |
Add API to enable opt-in aspect ratio feature in QSvgRenderer
[ChangeLog][QSvgRenderer] Introduced aspect ratio mode property, so
that rendering may be set to preserve the view box aspect ratio.
Task-number: QTBUG-81259
Change-Id: I9802788cdaf2c30974c1ffc34ad5b67cdc74ed57
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/svg/qsvgrenderer.cpp')
-rw-r--r-- | src/svg/qsvgrenderer.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/svg/qsvgrenderer.cpp b/src/svg/qsvgrenderer.cpp index 40ae6ab..0097ec2 100644 --- a/src/svg/qsvgrenderer.cpp +++ b/src/svg/qsvgrenderer.cpp @@ -257,6 +257,41 @@ void QSvgRenderer::setFramesPerSecond(int num) } /*! + \property QSvgRenderer::aspectRatioMode + + \brief how rendering adheres to the SVG view box aspect ratio + + The accepted modes are: + \list + \li Qt::IgnoreAspectRatio (the default): the aspect ratio is ignored and the + rendering is stretched to the target bounds. + \li Qt::KeepAspectRatio: rendering is centered and scaled as large as possible + within the target bounds while preserving aspect ratio. + \endlist + + \since 5.15 +*/ + +Qt::AspectRatioMode QSvgRenderer::aspectRatioMode() const +{ + Q_D(const QSvgRenderer); + if (d->render && d->render->preserveAspectRatio()) + return Qt::KeepAspectRatio; + return Qt::IgnoreAspectRatio; +} + +void QSvgRenderer::setAspectRatioMode(Qt::AspectRatioMode mode) +{ + Q_D(QSvgRenderer); + if (d->render) { + if (mode == Qt::KeepAspectRatio) + d->render->setPreserveAspectRatio(true); + else if (mode == Qt::IgnoreAspectRatio) + d->render->setPreserveAspectRatio(false); + } +} + +/*! \property QSvgRenderer::currentFrame \brief the current frame of the document's animation, or 0 if the document is not animated \internal |