summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Bodson <yann.bodson@nokia.com>2009-08-10 04:52:04 (GMT)
committerYann Bodson <yann.bodson@nokia.com>2009-08-10 04:52:04 (GMT)
commitede82d1abfeadf81a294bdb91eb932b36c437c03 (patch)
tree3663ce291684c778025d61b721f2a2621bcf9010
parent3ee9db1d892927522832b6bc8e1d806e27015bc4 (diff)
downloadQt-ede82d1abfeadf81a294bdb91eb932b36c437c03.zip
Qt-ede82d1abfeadf81a294bdb91eb932b36c437c03.tar.gz
Qt-ede82d1abfeadf81a294bdb91eb932b36c437c03.tar.bz2
Add a PreserveAspectFill mode (needs a better name)
-rw-r--r--examples/declarative/fillmode/fillmode.qml3
-rw-r--r--src/declarative/fx/qfximage.cpp9
-rw-r--r--src/declarative/fx/qfximage.h2
3 files changed, 13 insertions, 1 deletions
diff --git a/examples/declarative/fillmode/fillmode.qml b/examples/declarative/fillmode/fillmode.qml
index 6bf1c12..d5d6bb5 100644
--- a/examples/declarative/fillmode/fillmode.qml
+++ b/examples/declarative/fillmode/fillmode.qml
@@ -13,6 +13,9 @@ Image {
SetPropertyAction { value: "PreserveAspect" }
SetPropertyAction { target: Label; property: "text"; value: "PreserveAspect" }
PauseAnimation { duration: 1000 }
+ SetPropertyAction { value: "PreserveAspectFill" }
+ SetPropertyAction { target: Label; property: "text"; value: "PreserveAspectFill" }
+ PauseAnimation { duration: 1000 }
SetPropertyAction { value: "Tile" }
SetPropertyAction { target: Label; property: "text"; value: "Tile" }
PauseAnimation { duration: 1000 }
diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp
index 0cb7988..985ddec 100644
--- a/src/declarative/fx/qfximage.cpp
+++ b/src/declarative/fx/qfximage.cpp
@@ -177,6 +177,7 @@ void QFxImage::setPixmap(const QPixmap &pix)
\list
\o Stretch - the image is scaled to fit
\o PreserveAspect - the image is scaled uniformly to fit
+ \o PreserveAspectFill - the image is scaled uniformly to fill
\o Tile - the image is duplicated horizontally and vertically
\o TileVertically - the image is stretched horizontally and tiled vertically
\o TileHorizontally - the image is stretched vertically and tiled horizontally
@@ -309,6 +310,14 @@ void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
widthScale = heightScale;
scale.translate((width() - widthScale * pix.width()) / 2, 0);
}
+ } else if (d->fillMode == PreserveAspectFill) {
+ if (widthScale < heightScale) {
+ widthScale = heightScale;
+ scale.translate((width() - widthScale * pix.width()) / 2, 0);
+ } else if(heightScale < widthScale) {
+ heightScale = widthScale;
+ scale.translate(0, (height() - heightScale * pix.height()) / 2);
+ }
}
scale.scale(widthScale, heightScale);
diff --git a/src/declarative/fx/qfximage.h b/src/declarative/fx/qfximage.h
index 0a9d2df..91b10ef 100644
--- a/src/declarative/fx/qfximage.h
+++ b/src/declarative/fx/qfximage.h
@@ -63,7 +63,7 @@ public:
QFxImage(QFxItem *parent=0);
~QFxImage();
- enum FillMode { Stretch, PreserveAspect, Tile, TileVertically, TileHorizontally };
+ enum FillMode { Stretch, PreserveAspect, PreserveAspectFill, Tile, TileVertically, TileHorizontally };
FillMode fillMode() const;
void setFillMode(FillMode);