summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsimage.cpp48
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsimage_p.h9
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsimage_p_p.h4
3 files changed, 59 insertions, 2 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsimage.cpp b/src/declarative/graphicsitems/qmlgraphicsimage.cpp
index a777de7..ad43027 100644
--- a/src/declarative/graphicsitems/qmlgraphicsimage.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsimage.cpp
@@ -139,6 +139,12 @@ QmlGraphicsImage::~QmlGraphicsImage()
{
}
+void QmlGraphicsImage::setSource(const QUrl &url)
+{
+ QmlGraphicsImageBase::setSource(url);
+ updatePaintedGeometry();
+}
+
/*!
\qmlproperty QPixmap Image::pixmap
@@ -205,9 +211,22 @@ void QmlGraphicsImage::setFillMode(FillMode mode)
return;
d->fillMode = mode;
update();
+ updatePaintedGeometry();
emit fillModeChanged();
}
+qreal QmlGraphicsImage::paintedWidth() const
+{
+ Q_D(const QmlGraphicsImage);
+ return d->paintedWidth;
+}
+
+qreal QmlGraphicsImage::paintedHeight() const
+{
+ Q_D(const QmlGraphicsImage);
+ return d->paintedHeight;
+}
+
/*!
\qmlproperty enum Image::status
@@ -244,6 +263,33 @@ void QmlGraphicsImage::setFillMode(FillMode mode)
filtering at the beginning of the animation and reenable it at the conclusion.
*/
+void QmlGraphicsImage::updatePaintedGeometry()
+{
+ Q_D(QmlGraphicsImage);
+
+ if (d->fillMode == PreserveAspectFit) {
+ qreal widthScale = width() / qreal(d->pix.width());
+ qreal heightScale = height() / qreal(d->pix.height());
+ if (widthScale <= heightScale) {
+ d->paintedWidth = width();
+ d->paintedHeight = widthScale * qreal(d->pix.height());
+ } else if(heightScale < widthScale) {
+ d->paintedWidth = heightScale * qreal(d->pix.width());
+ d->paintedHeight = height();
+ }
+ } else {
+ d->paintedWidth = width();
+ d->paintedHeight = height();
+ }
+ emit paintedGeometryChanged();
+}
+
+void QmlGraphicsImage::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ QmlGraphicsImageBase::geometryChanged(newGeometry, oldGeometry);
+ updatePaintedGeometry();
+}
+
/*!
\qmlproperty url Image::source
@@ -278,7 +324,7 @@ void QmlGraphicsImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid
QTransform scale;
if (d->fillMode == PreserveAspectFit) {
- if (widthScale < heightScale) {
+ if (widthScale <= heightScale) {
heightScale = widthScale;
scale.translate(0, (height() - heightScale * d->pix.height()) / 2);
} else if(heightScale < widthScale) {
diff --git a/src/declarative/graphicsitems/qmlgraphicsimage_p.h b/src/declarative/graphicsitems/qmlgraphicsimage_p.h
index 2547b78..36066e1 100644
--- a/src/declarative/graphicsitems/qmlgraphicsimage_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsimage_p.h
@@ -59,6 +59,8 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsImage : public QmlGraphicsImageBase
Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap NOTIFY pixmapChanged DESIGNABLE false)
Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
+ Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedGeometryChanged)
+ Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedGeometryChanged)
public:
QmlGraphicsImage(QmlGraphicsItem *parent=0);
@@ -71,13 +73,20 @@ public:
QPixmap pixmap() const;
void setPixmap(const QPixmap &);
+ qreal paintedWidth() const;
+ qreal paintedHeight() const;
+
+ void setSource(const QUrl &url);
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
Q_SIGNALS:
void fillModeChanged();
+ void paintedGeometryChanged();
protected:
QmlGraphicsImage(QmlGraphicsImagePrivate &dd, QmlGraphicsItem *parent);
+ void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
+ void updatePaintedGeometry();
private:
Q_DISABLE_COPY(QmlGraphicsImage)
diff --git a/src/declarative/graphicsitems/qmlgraphicsimage_p_p.h b/src/declarative/graphicsitems/qmlgraphicsimage_p_p.h
index f6b4e51..3a5acca 100644
--- a/src/declarative/graphicsitems/qmlgraphicsimage_p_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsimage_p_p.h
@@ -64,11 +64,13 @@ class QmlGraphicsImagePrivate : public QmlGraphicsImageBasePrivate
public:
QmlGraphicsImagePrivate()
- : fillMode(QmlGraphicsImage::Stretch)
+ : fillMode(QmlGraphicsImage::Stretch), paintedWidth(0), paintedHeight(0)
{
}
QmlGraphicsImage::FillMode fillMode;
+ qreal paintedWidth;
+ qreal paintedHeight;
void setPixmap(const QPixmap &pix);
};