From b91871a108638a5a136ac2a4310f5a3743320f72 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 29 Jan 2010 13:00:32 +1000 Subject: Add paintedWidth and paintedHeight properties to QmlGraphicsImage. --- src/declarative/graphicsitems/qmlgraphicsimage.cpp | 48 +++++++++++++++++++++- src/declarative/graphicsitems/qmlgraphicsimage_p.h | 9 ++++ .../graphicsitems/qmlgraphicsimage_p_p.h | 4 +- 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); }; -- cgit v0.12 From c1ff07502cde66ccf4c1fc86b3ad2eac66fbea40 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 1 Feb 2010 11:09:25 +1000 Subject: doc --- src/declarative/qml/qmlmoduleplugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qmlmoduleplugin.cpp b/src/declarative/qml/qmlmoduleplugin.cpp index 446c7bc..3346ec7 100644 --- a/src/declarative/qml/qmlmoduleplugin.cpp +++ b/src/declarative/qml/qmlmoduleplugin.cpp @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE The plugin should register QML types with QML_DEFINE_TYPE. - The strings returned by keys() should be the list of URIs of module + The strings returned by keys() should be the list of URIs of modules that the plugin registers. \sa examples/declarative/plugins -- cgit v0.12 From 6e8feab83fa9303b1345f4a27478ba3ee0316e86 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 1 Feb 2010 11:10:31 +1000 Subject: Ensure pixmaps can be retrieved even if they do not fit in the QPixmapCache. Fixes QT-2280 --- src/declarative/util/qmlpixmapcache.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/declarative/util/qmlpixmapcache.cpp b/src/declarative/util/qmlpixmapcache.cpp index 6f36cad..1f68512 100644 --- a/src/declarative/util/qmlpixmapcache.cpp +++ b/src/declarative/util/qmlpixmapcache.cpp @@ -293,7 +293,7 @@ bool QmlPixmapReply::event(QEvent *event) } else { qWarning() << "Error decoding" << d->urlKey; } - QPixmapCache::insert(d->urlKey, d->pixmap); + QPixmapCache::insert(d->urlKey, d->pixmap); // note: may fail (returns false) emit finished(); } return true; @@ -374,8 +374,14 @@ QmlPixmapReply::Status QmlPixmapCache::get(const QUrl& url, QPixmap *pixmap) #endif QString key = url.toString(); + QmlPixmapReplyHash::Iterator iter = qmlActivePixmapReplies.find(key); - if (QPixmapCache::find(key, pixmap)) { + if (iter != qmlActivePixmapReplies.end() && (*iter)->status() == QmlPixmapReply::Ready) { + // Must check this, since QPixmapCache::insert may have failed. + *pixmap = (*iter)->d_func()->pixmap; + status = (*iter)->status(); + (*iter)->release(); + } else if (QPixmapCache::find(key, pixmap)) { if (iter != qmlActivePixmapReplies.end()) { status = (*iter)->status(); (*iter)->release(); -- cgit v0.12 From a6f90ca4d73365d37bdc4eaf8fe15cf55fe1bf83 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 1 Feb 2010 13:23:16 +1000 Subject: Support animating attached properties. Task-number: QTBUG-5580 --- src/declarative/util/qmlanimation.cpp | 2 +- .../auto/declarative/animations/data/attached.qml | 34 ++++++++++++++++++++++ .../auto/declarative/animations/tst_animations.cpp | 12 ++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/animations/data/attached.qml diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index efb4159..63044bc 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -223,7 +223,7 @@ void QmlAbstractAnimationPrivate::commence() QmlMetaProperty QmlAbstractAnimationPrivate::createProperty(QObject *obj, const QString &str, QObject *infoObj) { - QmlMetaProperty prop = QmlMetaProperty::createProperty(obj, str); + QmlMetaProperty prop = QmlMetaProperty::createProperty(obj, str, qmlContext(infoObj)); if (!prop.isValid()) { qmlInfo(infoObj) << QmlAbstractAnimation::tr("Cannot animate non-existant property \"%1\"").arg(str); return QmlMetaProperty(); diff --git a/tests/auto/declarative/animations/data/attached.qml b/tests/auto/declarative/animations/data/attached.qml new file mode 100644 index 0000000..0fb6f8c --- /dev/null +++ b/tests/auto/declarative/animations/data/attached.qml @@ -0,0 +1,34 @@ +import Qt 4.6 + +Rectangle { + width: 180; height: 200; + + Component { + id: delegate + Rectangle { + id: wrapper + width: 180; height: 200 + color: "blue" + + states: State { + name: "otherState" + PropertyChanges { target: wrapper; color: "green" } + } + + transitions: Transition { + PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: true } + ScriptAction { script: console.log(ListView.delayRemove ? "on" : "off") } + } + + Component.onCompleted: { + console.log(ListView.delayRemove ? "on" : "off"); + wrapper.state = "otherState" + } + } + } + + ListView { + model: 1 + delegate: delegate + } +} diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp index 35eae73..7f043ba 100644 --- a/tests/auto/declarative/animations/tst_animations.cpp +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -67,6 +67,7 @@ private slots: void propertiesTransition(); void easingStringConversion(); void invalidDuration(); + void attached(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -563,6 +564,17 @@ void tst_animations::invalidDuration() QCOMPARE(pauseAnimation->duration(), 250); } +void tst_animations::attached() +{ + QmlEngine engine; + + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/attached.qml")); + QTest::ignoreMessage(QtDebugMsg, "off"); + QTest::ignoreMessage(QtDebugMsg, "on"); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); +} + QTEST_MAIN(tst_animations) #include "tst_animations.moc" -- cgit v0.12 From 6c51b1c9e456f39d4e75303fe74d348e7f859e1b Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 1 Feb 2010 15:00:28 +1000 Subject: Don't use statics for type definition, at least for plugin modules. Task-number: QT-2798 --- examples/declarative/plugins/plugin.cpp | 7 ++++++- src/declarative/qml/qmlengine.cpp | 4 +++- src/declarative/qml/qmlmoduleplugin.cpp | 26 ++++++++++++++++++++++++-- src/declarative/qml/qmlmoduleplugin.h | 8 ++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/examples/declarative/plugins/plugin.cpp b/examples/declarative/plugins/plugin.cpp index 9688caf..f4aa36b 100644 --- a/examples/declarative/plugins/plugin.cpp +++ b/examples/declarative/plugins/plugin.cpp @@ -138,7 +138,6 @@ MinuteTimer *Time::timer=0; QML_DECLARE_TYPE(Time); -QML_DEFINE_TYPE(com.nokia.TimeExample,1,0,Time,Time); class QExampleQmlPlugin : public QmlModulePlugin @@ -149,6 +148,12 @@ public: { return QStringList() << QLatin1String("com.nokia.TimeExample"); } + + void defineModule(const QString& uri) + { + Q_ASSERT(uri == QLatin1String("com.nokia.TimeExample")); + qmlRegisterType