From ede82d1abfeadf81a294bdb91eb932b36c437c03 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 10 Aug 2009 14:52:04 +1000 Subject: Add a PreserveAspectFill mode (needs a better name) --- examples/declarative/fillmode/fillmode.qml | 3 +++ src/declarative/fx/qfximage.cpp | 9 +++++++++ src/declarative/fx/qfximage.h | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) 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); -- cgit v0.12