diff options
-rw-r--r-- | examples/declarative/snow/ImageBatch.qml | 79 | ||||
-rw-r--r-- | examples/declarative/snow/Loading.qml | 6 | ||||
-rw-r--r-- | examples/declarative/snow/create.js | 13 | ||||
-rw-r--r-- | examples/declarative/snow/snow.qml | 72 | ||||
-rw-r--r-- | src/declarative/extra/qmlxmllistmodel.cpp | 1 | ||||
-rw-r--r-- | src/declarative/extra/qmlxmllistmodel.h | 2 | ||||
-rw-r--r-- | src/declarative/fx/qfximage.cpp | 33 | ||||
-rw-r--r-- | src/declarative/fx/qfximage.h | 5 | ||||
-rw-r--r-- | src/declarative/fx/qfximage_p.h | 4 | ||||
-rw-r--r-- | src/declarative/qml/qmlcompiler.cpp | 5 |
10 files changed, 216 insertions, 4 deletions
diff --git a/examples/declarative/snow/ImageBatch.qml b/examples/declarative/snow/ImageBatch.qml new file mode 100644 index 0000000..f7ae8b1 --- /dev/null +++ b/examples/declarative/snow/ImageBatch.qml @@ -0,0 +1,79 @@ +GridView { + id: MyGrid + property int offset: 0 + property var ref + property bool isSelected: ref.selectedItemColumn >= offset && ref.selectedItemColumn < offset + 5 + + currentIndex: (ref.selectedItemColumn - offset) + ref.selectedItemRow * 5 + + property int imageWidth: ref.imageWidth + property int imageHeight: ref.imageHeight + + width: 5 * imageWidth + height: 4 * imageHeight + cellWidth: imageWidth + cellHeight: imageHeight + + states: State { + name: "selected"; when: MyGrid.isSelected + SetProperties { target: MyGrid; z: 150 } + } + transitions: Transition { + SequentialAnimation { + PauseAnimation { duration: 150 } + SetPropertyAction { properties: "z" } + } + } + model: XmlListModel { + property string tags : "" + source: "http://api.flickr.com/services/feeds/photos_public.gne?"+(tags ? "tags="+tags+"&" : "")+"format=rss2" + query: "/rss/channel/item" + namespaceDeclarations: "declare namespace media=\"http://search.yahoo.com/mrss/\";" + + XmlRole { name: "title"; query: "title/string()" } + XmlRole { name: "imagePath"; query: "media:thumbnail/@url/string()" } + XmlRole { name: "url"; query: "media:content/@url/string()" } + XmlRole { name: "description"; query: "description/string()" } + XmlRole { name: "tags"; query: "media:category/string()" } + XmlRole { name: "photoWidth"; query: "media:content/@width/string()" } + XmlRole { name: "photoHeight"; query: "media:content/@height/string()" } + XmlRole { name: "photoType"; query: "media:content/@type/string()" } + XmlRole { name: "photoAuthor"; query: "author/string()" } + XmlRole { name: "photoDate"; query: "pubDate/string()" } + } + + Item { + id: Root + property bool isSelected: GridView.isCurrentItem && MyGrid.isSelected + transformOrigin: "Center" + width: MyGrid.imageWidth; height: MyGrid.imageHeight; + + Image { id: Image; source: url; preserveAspect: true; smooth: true; anchors.fill: parent; + opacity: (status == 0)?1:0; opacity: Behavior { NumberAnimation { properties: "opacity" } } } + Loading { anchors.centeredIn: parent; visible: Image.status } + + states: State { + name: "selected" + when: Root.isSelected + SetProperties { target: Root; scale: 3; z: 100 } + } + transitions: [ + Transition { + toState: "selected" + SequentialAnimation { + PauseAnimation { duration: 150 } + SetPropertyAction { properties: "z" } + NumberAnimation { properties: "scale"; duration: 150; } + } + }, + Transition { + fromState: "selected" + SequentialAnimation { + NumberAnimation { properties: "scale"; duration: 150 } + SetPropertyAction { properties: "z" } + } + } + ] + } +} + diff --git a/examples/declarative/snow/Loading.qml b/examples/declarative/snow/Loading.qml new file mode 100644 index 0000000..0a8a51a --- /dev/null +++ b/examples/declarative/snow/Loading.qml @@ -0,0 +1,6 @@ +Image { + id: Loading; source: "pics/loading.png"; transformOrigin: "Center" + rotation: NumberAnimation { + id: "RotationAnimation"; from: 0; to: 360; running: Loading.visible == true; repeat: true; duration: 900 + } +} diff --git a/examples/declarative/snow/create.js b/examples/declarative/snow/create.js new file mode 100644 index 0000000..51f870d --- /dev/null +++ b/examples/declarative/snow/create.js @@ -0,0 +1,13 @@ +var myComponent = null; + +function createNewBlock() { + if (myComponent == null) + myComponent = createComponent("ImageBatch.qml"); + + var obj = myComponent.createObject(); + obj.parent = MyLayout; + obj.offset = maximumColumn + 1; + obj.ref = ImagePanel; + maximumColumn += 5; +} + diff --git a/examples/declarative/snow/snow.qml b/examples/declarative/snow/snow.qml new file mode 100644 index 0000000..b73c2d2 --- /dev/null +++ b/examples/declarative/snow/snow.qml @@ -0,0 +1,72 @@ +Rect { + id: ImagePanel + width: 1024 + height: 768 + color: "black" + + property int maximumColumn: 4 + property int selectedItemRow: 0 + property int selectedItemColumn: 0 + + Script { source: "create.js" } + + onSelectedItemColumnChanged: if (selectedItemColumn == maximumColumn) createNewBlock(); + + property int imageWidth: 200 + property int imageHeight: 200 + + property int selectedX: selectedItemColumn * imageWidth + property int selectedY: selectedItemRow * imageHeight + + Item { + anchors.centeredIn: parent + HorizontalLayout { + id: MyLayout + property real targetX: -(selectedX + imageWidth / 2) + + property real targetDeform: 0 + property bool slowDeform: true + + property real deform + deform: Follow { source: MyLayout.targetDeform; velocity: MyLayout.slowDeform?0.1:2 } + + onDeformChanged: if(deform == targetDeform) { slowDeform = true; targetDeform = 0; } + + ImageBatch { offset: 0; ref: ImagePanel } + + x: Follow { source: MyLayout.targetX; velocity: 1000 } + y: Follow { source: -(selectedY + imageHeight / 2); velocity: 500 } + } + + transform: Rotation3D { + axis { startX: 0; startY: 0; endX: 0; endY: 1 } + angle: MyLayout.deform * 100 + } + + } + + Script { + function leftPressed() { + if (selectedItemColumn <= 0) return; + selectedItemColumn -= 1; + MyLayout.slowDeform = false; + MyLayout.targetDeform = Math.max(Math.min(MyLayout.deform - 0.1, -0.1), -0.4); + } + function rightPressed() { + selectedItemColumn += 1; + MyLayout.slowDeform = false; + MyLayout.targetDeform = Math.min(Math.max(MyLayout.deform + 0.1, 0.1), 0.4); + } + } + KeyActions { + focus: true + leftArrow: "leftPressed()" + rightArrow: "rightPressed()" + upArrow: "if (selectedItemRow > 0) selectedItemRow = selectedItemRow - 1" + downArrow: "if (selectedItemRow < 3) selectedItemRow = selectedItemRow + 1" + } + + Text { + text: MyLayout.deform + } +} diff --git a/src/declarative/extra/qmlxmllistmodel.cpp b/src/declarative/extra/qmlxmllistmodel.cpp index e154268..7f0029d 100644 --- a/src/declarative/extra/qmlxmllistmodel.cpp +++ b/src/declarative/extra/qmlxmllistmodel.cpp @@ -645,6 +645,7 @@ void QmlXmlListModel::queryCompleted(int id, int size) if (size > 0) { d->data = d->qmlXmlQuery.modelData(); emit itemsInserted(0, d->size); + emit countChanged(); } } diff --git a/src/declarative/extra/qmlxmllistmodel.h b/src/declarative/extra/qmlxmllistmodel.h index d9871ab..3b6ffb4 100644 --- a/src/declarative/extra/qmlxmllistmodel.h +++ b/src/declarative/extra/qmlxmllistmodel.h @@ -98,6 +98,7 @@ class Q_DECLARATIVE_EXPORT QmlXmlListModel : public QListModelInterface, public Q_PROPERTY(QString query READ query WRITE setQuery) Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations) Q_PROPERTY(QmlList<XmlListModelRole *> *roles READ roleObjects) + Q_PROPERTY(int count READ count NOTIFY countChanged) Q_CLASSINFO("DefaultProperty", "roles") public: @@ -130,6 +131,7 @@ public: signals: void statusChanged(Status); void progressChanged(qreal progress); + void countChanged(); public Q_SLOTS: void reload(); diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index f57782c..d19d620 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -301,9 +301,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); @@ -448,6 +461,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 378c20d..7b3445c 100644 --- a/src/declarative/fx/qfximage.h +++ b/src/declarative/fx/qfximage.h @@ -65,7 +65,7 @@ class Q_DECLARATIVE_EXPORT QFxImage : public QFxItem Q_PROPERTY(bool tile READ isTiled WRITE setTiled) Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap DESIGNABLE false) Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform) - + Q_PROPERTY(bool preserveAspect READ preserveAspect WRITE setPreserveAspect); public: QFxImage(QFxItem *parent=0); ~QFxImage(); @@ -85,6 +85,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; diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 220c464..138be29 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -903,6 +903,11 @@ void QmlCompiler::genComponent(QmlParser::Object *obj) genObject(root); + QmlInstruction def; + init.line = 0; + def.type = QmlInstruction::SetDefault; + output->bytecode << def; + output->bytecode[count - 1].createComponent.count = output->bytecode.count() - count; |