summaryrefslogtreecommitdiffstats
path: root/src/declarative/fx/qfximage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/fx/qfximage.cpp')
-rw-r--r--src/declarative/fx/qfximage.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp
index f57782c..d19d620 100644
--- a/src/declarative/fx/qfximage.cpp
+++ b/src/declarative/fx/qfximage.cpp
@@ -301,9 +301,22 @@ void QFxImage::paintContents(QPainter &p)
p.restore();
} else if (!d->scaleGrid || d->scaleGrid->isNull()) {
if (width() != pix.width() || height() != pix.height()) {
+ qreal widthScale = width() / qreal(pix.width());
+ qreal heightScale = height() / qreal(pix.height());
+
QTransform scale;
- scale.scale(width() / qreal(pix.width()),
- height() / qreal(pix.height()));
+
+ if (d->preserveAspect) {
+ if (widthScale < heightScale) {
+ heightScale = widthScale;
+ scale.translate(0, (height() - heightScale * pix.height()) / 2);
+ } else if(heightScale < widthScale) {
+ widthScale = heightScale;
+ scale.translate((width() - widthScale * pix.width()) / 2, 0);
+ }
+ }
+
+ scale.scale(widthScale, heightScale);
QTransform old = p.transform();
p.setWorldTransform(scale * old);
p.drawPixmap(0, 0, pix);
@@ -448,6 +461,22 @@ QUrl QFxImage::source() const
return d->url;
}
+bool QFxImage::preserveAspect() const
+{
+ Q_D(const QFxImage);
+ return d->preserveAspect;
+}
+
+void QFxImage::setPreserveAspect(bool p)
+{
+ Q_D(QFxImage);
+
+ if (p == d->preserveAspect)
+ return;
+ d->preserveAspect = p;
+ update();
+}
+
void QFxImage::setSource(const QUrl &url)
{
#ifdef Q_ENABLE_PERFORMANCE_LOG