summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/fx/qfxitem.cpp20
-rw-r--r--src/declarative/fx/qfxitem.h6
-rw-r--r--src/declarative/fx/qfxvisualitemmodel.cpp51
-rw-r--r--src/declarative/fx/qfxvisualitemmodel.h3
4 files changed, 74 insertions, 6 deletions
diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp
index 2ff02f0..806d5c0 100644
--- a/src/declarative/fx/qfxitem.cpp
+++ b/src/declarative/fx/qfxitem.cpp
@@ -1289,8 +1289,10 @@ void QFxItem::setBaselineOffset(qreal offset)
*/
/*!
- Returns a value indicating whether the mouse should
- remain with this item.
+ Returns a value indicating whether mouse input should
+ remain with this item exclusively.
+
+ \sa setKeepMouseGrab
*/
bool QFxItem::keepMouseGrab() const
{
@@ -1301,6 +1303,20 @@ bool QFxItem::keepMouseGrab() const
/*!
The flag indicating whether the mouse should remain
with this item is set to \a keep.
+
+ This is useful for items that wish to grab and keep mouse
+ interaction following a predefined gesture. For example,
+ an item that is interested in horizontal mouse movement
+ may set keepMouseGrab to true once a threshold has been
+ exceeded. Once keepMouseGrab has been set to true, filtering
+ items will not react to mouse events.
+
+ If the item does not indicate that it wishes to retain mouse grab,
+ a filtering item may steal the grab. For example, Flickable may attempt
+ to steal a mouse grab if it detects that the user has begun to
+ move the viewport.
+
+ \sa keepMouseGrab
*/
void QFxItem::setKeepMouseGrab(bool keep)
{
diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h
index 4a26c9b..6563c45 100644
--- a/src/declarative/fx/qfxitem.h
+++ b/src/declarative/fx/qfxitem.h
@@ -163,9 +163,6 @@ public:
QmlList<QGraphicsTransform *> *transform();
- bool keepMouseGrab() const;
- void setKeepMouseGrab(bool);
-
qreal width() const;
void setWidth(qreal);
@@ -185,6 +182,9 @@ public:
void setFocus(bool);
bool hasActiveFocus() const;
+ bool keepMouseGrab() const;
+ void setKeepMouseGrab(bool);
+
Q_SIGNALS:
void xChanged();
void yChanged();
diff --git a/src/declarative/fx/qfxvisualitemmodel.cpp b/src/declarative/fx/qfxvisualitemmodel.cpp
index 6516545..9694b3a 100644
--- a/src/declarative/fx/qfxvisualitemmodel.cpp
+++ b/src/declarative/fx/qfxvisualitemmodel.cpp
@@ -58,6 +58,47 @@ QML_DECLARE_TYPE(QListModelInterface)
QT_BEGIN_NAMESPACE
+class QFxVisualItemModelAttached : public QObject
+{
+ Q_OBJECT
+
+public:
+ QFxVisualItemModelAttached(QObject *parent)
+ : QObject(parent), m_index(0) {}
+ ~QFxVisualItemModelAttached() {
+ attachedProperties.remove(parent());
+ }
+
+ Q_PROPERTY(int index READ index NOTIFY indexChanged)
+ int index() const { return m_index; }
+ void setIndex(int idx) {
+ if (m_index != idx) {
+ m_index = idx;
+ emit indexChanged();
+ }
+ }
+
+ static QFxVisualItemModelAttached *properties(QObject *obj) {
+ QFxVisualItemModelAttached *rv = attachedProperties.value(obj);
+ if (!rv) {
+ rv = new QFxVisualItemModelAttached(obj);
+ attachedProperties.insert(obj, rv);
+ }
+ return rv;
+ }
+
+signals:
+ void indexChanged();
+
+public:
+ int m_index;
+
+ static QHash<QObject*, QFxVisualItemModelAttached*> attachedProperties;
+};
+
+QHash<QObject*, QFxVisualItemModelAttached*> QFxVisualItemModelAttached::attachedProperties;
+
+
class QFxVisualItemModelPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QFxVisualItemModel);
@@ -75,6 +116,8 @@ public:
void itemAppended() {
Q_Q(QFxVisualItemModel);
+ QFxVisualItemModelAttached *attached = QFxVisualItemModelAttached::properties(children.last());
+ attached->setIndex(children.count()-1);
emit q->itemsInserted(children.count()-1, 1);
emit q->countChanged();
}
@@ -88,7 +131,8 @@ public:
\brief The VisualItemModel allows items to be provided to a view.
The children of the VisualItemModel are provided in a model which
- can be used in a view.
+ can be used in a view. An item can determine its index within the
+ model via the VisualItemModel.index attached property.
The example below places three colored rectangles in a ListView.
\code
@@ -177,6 +221,11 @@ void QFxVisualItemModelPrivate::ItemList::append(QFxItem *item)
model->itemAppended();
}
+QFxVisualItemModelAttached *QFxVisualItemModel::qmlAttachedProperties(QObject *obj)
+{
+ return QFxVisualItemModelAttached::properties(obj);
+}
+
class QFxVisualDataModelParts;
class QFxVisualDataModelData;
diff --git a/src/declarative/fx/qfxvisualitemmodel.h b/src/declarative/fx/qfxvisualitemmodel.h
index 6160068..6165746 100644
--- a/src/declarative/fx/qfxvisualitemmodel.h
+++ b/src/declarative/fx/qfxvisualitemmodel.h
@@ -101,6 +101,7 @@ private:
Q_DISABLE_COPY(QFxVisualModel)
};
+class QFxVisualItemModelAttached;
class QFxVisualItemModelPrivate;
class Q_DECLARATIVE_EXPORT QFxVisualItemModel : public QFxVisualModel
{
@@ -125,6 +126,8 @@ public:
QmlList<QFxItem *> *children();
+ static QFxVisualItemModelAttached *qmlAttachedProperties(QObject *obj);
+
private:
Q_DISABLE_COPY(QFxVisualItemModel)
};