From 700d5f11dab745d920026b781f66b09e60499013 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 18 Jun 2009 18:23:59 +1000 Subject: Expose the row and column of an item as an attached property --- examples/declarative/flowview/flowview.qml | 15 ++++++-- src/declarative/fx/qfxflowview.cpp | 57 ++++++++++++++++++++++++++++++ src/declarative/fx/qfxflowview.h | 3 ++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/examples/declarative/flowview/flowview.qml b/examples/declarative/flowview/flowview.qml index 7a05c9b..4c9aecc 100644 --- a/examples/declarative/flowview/flowview.qml +++ b/examples/declarative/flowview/flowview.qml @@ -60,13 +60,24 @@ Rect { SetProperties { target: MyContent; x: 0; y: 0; } } ] - transitions: Transition { - fromState: "*"; toState: "*"; + transitions: [ + Transition { + fromState: "*"; toState: "InGrid" SequentialAnimation { ParentChangeAction{} + PauseAnimation { duration: 50 * List.FlowView.column } + NumericAnimation { properties: "x,y,rotation"; easing: "easeInOutQuad" } + } + }, + Transition { + fromState: "*"; toState: "InList" + SequentialAnimation { + ParentChangeAction{} + PauseAnimation { duration: 50 * (Grid.FlowView.row * 2 + Grid.FlowView.column) } NumericAnimation { properties: "x,y,rotation"; easing: "easeInOutQuad" } } } + ] } } diff --git a/src/declarative/fx/qfxflowview.cpp b/src/declarative/fx/qfxflowview.cpp index e45f939..e02e186 100644 --- a/src/declarative/fx/qfxflowview.cpp +++ b/src/declarative/fx/qfxflowview.cpp @@ -44,6 +44,27 @@ QT_BEGIN_NAMESPACE +class QFxFlowViewAttached : public QObject +{ +Q_OBJECT +Q_PROPERTY(int row READ row NOTIFY posChanged); +Q_PROPERTY(int column READ column NOTIFY posChanged); +public: + QFxFlowViewAttached(QObject *parent); + + int row() const; + int column() const; + +signals: + void posChanged(); + +private: + friend class QFxFlowView; + int m_row; + int m_column; +}; + + QFxFlowView::QFxFlowView() : m_columns(0), m_model(0), m_vertical(false), m_dragItem(0), m_dragIdx(-1) { @@ -122,16 +143,28 @@ void QFxFlowView::reflow(bool animate) qreal y = 0; qreal maxY = 0; qreal x = 0; + int row = 0; + int column = -1; if (animate) clearTimeLine(); + for (int ii = 0; ii < m_items.count(); ++ii) { if (0 == (ii % m_columns)) { y += maxY; maxY = 0; x = 0; + row = 0; + column++; } QFxItem *item = m_items.at(ii); + QFxFlowViewAttached *att = + (QFxFlowViewAttached *)qmlAttachedPropertiesObject(item); + att->m_row = row; + att->m_column = column; + emit att->posChanged(); + + if (animate) { if (vertical()) moveItem(item, QPointF(y, x)); @@ -153,6 +186,7 @@ void QFxFlowView::reflow(bool animate) x += item->width(); maxY = qMax(maxY, item->height()); } + ++row; } } @@ -297,6 +331,26 @@ void QFxFlowView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } } +QFxFlowViewAttached::QFxFlowViewAttached(QObject *parent) +: QObject(parent), m_row(0), m_column(0) +{ +} + +int QFxFlowViewAttached::row() const +{ + return m_row; +} + +int QFxFlowViewAttached::column() const +{ + return m_column; +} + +QFxFlowViewAttached *QFxFlowView::qmlAttachedProperties(QObject *obj) +{ + return new QFxFlowViewAttached(obj); +} + void QFxFlowView::clearTimeLine() { m_timeline.clear(); @@ -318,6 +372,9 @@ void QFxFlowView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } } } + QML_DEFINE_TYPE(QFxFlowView,FlowView); +#include "qfxflowview.moc" + QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxflowview.h b/src/declarative/fx/qfxflowview.h index a18a4c7..0e7c2d3 100644 --- a/src/declarative/fx/qfxflowview.h +++ b/src/declarative/fx/qfxflowview.h @@ -52,6 +52,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QFxVisualItemModel; class QFxFlowViewValue; +class QFxFlowViewAttached; class Q_DECLARATIVE_EXPORT QFxFlowView : public QFxItem { Q_OBJECT @@ -75,6 +76,8 @@ public: virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + static QFxFlowViewAttached *qmlAttachedProperties(QObject *); + private: QRectF rectForItem(int idx) const; void refresh(); -- cgit v0.12