diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2010-04-21 05:34:51 (GMT) |
---|---|---|
committer | Yann Bodson <yann.bodson@nokia.com> | 2010-04-21 05:40:39 (GMT) |
commit | 62d40d166f77de67072eced7eac4f3c38697af52 (patch) | |
tree | 2e942083882358c4c9365b155881fdcf4bbca046 /src/declarative | |
parent | 5beddba73a7b2890f775d45aeb2f21407f8c3d0d (diff) | |
download | Qt-62d40d166f77de67072eced7eac4f3c38697af52.zip Qt-62d40d166f77de67072eced7eac4f3c38697af52.tar.gz Qt-62d40d166f77de67072eced7eac4f3c38697af52.tar.bz2 |
Add forceFocus method to QDeclarativeItem.
Reviewed-by: Aaron Kennedy
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeitem.cpp | 21 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeitem.h | 1 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index d19967a..bdd24b6 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -1595,10 +1595,10 @@ void QDeclarativeItemPrivate::transform_clear(QDeclarativeListProperty<QGraphics } } -void QDeclarativeItemPrivate::parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e) +void QDeclarativeItemPrivate::parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e) { QDeclarativeItem *item = static_cast<QDeclarativeItem*>(o); - if (e) + if (e) e->connect(&item->d_func()->parentNotifier); *((QDeclarativeItem **)rv) = item->parentItem(); } @@ -2280,6 +2280,23 @@ QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, qreal x, qrea return sv; } +/*! + \qmlmethod Item::forceFocus() + + Force the focus on the item. + This method sets the focus on the item and makes sure that all the focus scopes higher in the object hierarchy are given focus. +*/ +void QDeclarativeItem::forceFocus() +{ + setFocus(true); + QGraphicsItem *parent = parentItem(); + while (parent) { + if (parent->flags() & QGraphicsItem::ItemIsFocusScope) + parent->setFocus(Qt::OtherFocusReason); + parent = parent->parentItem(); + } +} + void QDeclarativeItemPrivate::focusChanged(bool flag) { Q_Q(QDeclarativeItem); diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h index 51889f6..da5a36e 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.h +++ b/src/declarative/graphicsitems/qdeclarativeitem.h @@ -157,6 +157,7 @@ public: Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const; Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const; + Q_INVOKABLE void forceFocus(); QDeclarativeAnchorLine left() const; QDeclarativeAnchorLine right() const; |