summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-07-17 06:55:44 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-07-17 06:55:44 (GMT)
commit76002f882a260082ca17b6f82130eb38db89adff (patch)
tree15cbc0f3f3bb2567e993508ff678eb8560740482 /src
parent4937b60008fcb0923f30f976556f427495695a91 (diff)
downloadQt-76002f882a260082ca17b6f82130eb38db89adff.zip
Qt-76002f882a260082ca17b6f82130eb38db89adff.tar.gz
Qt-76002f882a260082ca17b6f82130eb38db89adff.tar.bz2
Add a preserveAspect property to Image
Diffstat (limited to 'src')
-rw-r--r--src/declarative/fx/qfximage.cpp33
-rw-r--r--src/declarative/fx/qfximage.h4
-rw-r--r--src/declarative/fx/qfximage_p.h4
3 files changed, 38 insertions, 3 deletions
diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp
index 148c269..34ff157 100644
--- a/src/declarative/fx/qfximage.cpp
+++ b/src/declarative/fx/qfximage.cpp
@@ -339,9 +339,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);
@@ -486,6 +499,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
diff --git a/src/declarative/fx/qfximage.h b/src/declarative/fx/qfximage.h
index 925a520..bc63d7a 100644
--- a/src/declarative/fx/qfximage.h
+++ b/src/declarative/fx/qfximage.h
@@ -66,6 +66,7 @@ class Q_DECLARATIVE_EXPORT QFxImage : public QFxItem
Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap DESIGNABLE false)
Q_PROPERTY(bool opaque READ isOpaque WRITE setOpaque)
Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform)
+ Q_PROPERTY(bool preserveAspect READ preserveAspect WRITE setPreserveAspect);
public:
QFxImage(QFxItem *parent=0);
~QFxImage();
@@ -88,6 +89,9 @@ public:
Status status() const;
qreal progress() const;
+ bool preserveAspect() const;
+ void setPreserveAspect(bool);
+
QUrl source() const;
virtual void setSource(const QUrl &url);
diff --git a/src/declarative/fx/qfximage_p.h b/src/declarative/fx/qfximage_p.h
index e4a3a90..de7ebe6 100644
--- a/src/declarative/fx/qfximage_p.h
+++ b/src/declarative/fx/qfximage_p.h
@@ -69,7 +69,8 @@ class QFxImagePrivate : public QFxItemPrivate
public:
QFxImagePrivate()
: scaleGrid(0), tiled(false), smooth(false), opaque(false),
- status(QFxImage::Idle), sciReply(0), progress(0.0)
+ preserveAspect(false), status(QFxImage::Idle), sciReply(0),
+ progress(0.0)
{
}
@@ -92,6 +93,7 @@ public:
bool tiled : 1;
bool smooth : 1;
bool opaque : 1;
+ bool preserveAspect : 1;
QFxImage::Status status;
QUrl url;