From b13365187b58ecc2d259589ab523a7d0da84dc83 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Tue, 15 Sep 2009 15:21:33 +0200 Subject: Focus changes to QFxItem and QFxView. Remove QFxItem::activeFocus, make QFxItem::focus behave like QGraphicsItem::focus (same as activeFocus essentially). Introduce QFxItem::wantsFocus to provide the same behavior as QFxItem::focus used to. Also updated the focusScope manual tests to reflect this new behavior. This change is going to break every example that relies on activeFocus. The fix is to replace all references with "focus" instead. All places that bind to "focus" should now bind to "wantsFocus" instead. Reviewed-by: akennedy --- examples/declarative/focusscope/test.qml | 14 +++++------ examples/declarative/focusscope/test2.qml | 10 ++++---- src/declarative/fx/qfxitem.cpp | 42 +++++++++++++------------------ src/declarative/fx/qfxitem.h | 7 +++--- src/declarative/fx/qfxitem_p.h | 7 ++++-- src/declarative/util/qfxview.cpp | 6 +++-- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/examples/declarative/focusscope/test.qml b/examples/declarative/focusscope/test.qml index 22ffc8d..77ffb84 100644 --- a/examples/declarative/focusscope/test.qml +++ b/examples/declarative/focusscope/test.qml @@ -19,21 +19,21 @@ Rectangle { color: "transparent" border.width: 5 - border.color: MyScope.focus?"blue":"black" + border.color: MyScope.wantsFocus?"blue":"black" Rectangle { id: Item1 x: 10; y: 10 width: 100; height: 100; color: "green" border.width: 5 - border.color: focus?"blue":"black" + border.color: wantsFocus?"blue":"black" Keys.onDigit9Pressed: print("Top Left"); KeyNavigation.right: Item2 focus: true Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.activeFocus?"red":"transparent" + color: parent.focus?"red":"transparent" } } @@ -42,13 +42,13 @@ Rectangle { x: 310; y: 10 width: 100; height: 100; color: "green" border.width: 5 - border.color: focus?"blue":"black" + border.color: wantsFocus?"blue":"black" KeyNavigation.left: Item1 Keys.onDigit9Pressed: print("Top Right"); Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.activeFocus?"red":"transparent" + color: parent.focus?"red":"transparent" } } } @@ -62,14 +62,14 @@ Rectangle { x: 10; y: 300 width: 100; height: 100; color: "green" border.width: 5 - border.color: focus?"blue":"black" + border.color: wantsFocus?"blue":"black" Keys.onDigit9Pressed: print("Bottom Left"); KeyNavigation.up: MyScope Rectangle { width: 50; height: 50; anchors.centerIn: parent - color: parent.activeFocus?"red":"transparent" + color: parent.focus?"red":"transparent" } } diff --git a/examples/declarative/focusscope/test2.qml b/examples/declarative/focusscope/test2.qml index 0ac0f5d..5b6971a 100644 --- a/examples/declarative/focusscope/test2.qml +++ b/examples/declarative/focusscope/test2.qml @@ -10,27 +10,27 @@ Rectangle { FocusScope { y: 100 focus: true - Rectangle { width: 50; height: 50; color: parent.focus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } FocusScope { y: 100 focus: true - Rectangle { width: 50; height: 50; color: parent.focus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } FocusScope { y: 100 focus: true - Rectangle { width: 50; height: 50; color: parent.focus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } FocusScope { y: 100 focus: true - Rectangle { width: 50; height: 50; color: parent.focus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } FocusScope { y: 100 focus: true - Rectangle { width: 50; height: 50; color: parent.focus?"red":"blue" } + Rectangle { width: 50; height: 50; color: parent.wantsFocus?"red":"blue" } } } } diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index a2c744e..962fee2 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -2575,7 +2575,7 @@ bool QFxItem::sceneEvent(QEvent *event) if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut) { - activeFocusChanged(hasActiveFocus()); + focusChanged(hasFocus()); } return rv; @@ -2756,39 +2756,33 @@ bool QFxItem::heightValid() const } /*! - \qmlproperty bool Item::focus - This property indicates whether the item has has an active focus request. Set this - property to true to request active focus. -*/ - -bool QFxItem::hasFocus() const -{ - Q_D(const QFxItem); - return d->itemIsFocusedInScope; -} - -void QFxItem::setFocus(bool focus) -{ - if (focus) QGraphicsItem::setFocus(Qt::OtherFocusReason); - else QGraphicsItem::clearFocus(); -} + \qmlproperty bool Item::wantsFocus -void QFxItemPrivate::focusedInScopeChanged() + This property indicates whether the item has has an active focus request. +*/ +bool QFxItem::wantsFocus() const { - Q_Q(QFxItem); - q->focusChanged(q->hasFocus()); + return focusItem() != 0; } /*! - \qmlproperty bool Item::activeFocus - This property indicates whether the item has the active focus. + \qmlproperty bool Item::focus + This property indicates whether the item has keyboard input focus. Set this + property to true to request focus. */ - -bool QFxItem::hasActiveFocus() const +bool QFxItem::hasFocus() const { return QGraphicsItem::hasFocus(); } +void QFxItem::setFocus(bool focus) +{ + if (focus) + QGraphicsItem::setFocus(Qt::OtherFocusReason); + else + QGraphicsItem::clearFocus(); +} + /*! \reimp */ diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index c6a5311..7ec1ab2 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -89,7 +89,7 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserSta Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged) Q_PROPERTY(bool clip READ clip WRITE setClip) // ### move to QGI/QGO, NOTIFY Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL) - Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL) + Q_PROPERTY(bool wantsFocus READ wantsFocus NOTIFY wantsFocusChanged) Q_PROPERTY(QmlList* transform READ transform DESIGNABLE false FINAL) Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin) Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform) @@ -147,9 +147,9 @@ public: QRectF boundingRect() const; virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - virtual bool hasFocus() const; + bool wantsFocus() const; + bool hasFocus() const; void setFocus(bool); - bool hasActiveFocus() const; bool keepMouseGrab() const; void setKeepMouseGrab(bool); @@ -161,6 +161,7 @@ Q_SIGNALS: void baselineOffsetChanged(); void stateChanged(const QString &); void focusChanged(); + void wantsFocusChanged(); void activeFocusChanged(); void parentChanged(); diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h index 054bdc7..b2560ee 100644 --- a/src/declarative/fx/qfxitem_p.h +++ b/src/declarative/fx/qfxitem_p.h @@ -224,8 +224,11 @@ public: q->geometryChanged(QRectF(this->pos.x(), this->pos.y(), width, height), oldGeometry); } - // Inherited from QGraphcisItemPrivate - virtual void focusedInScopeChanged(); + // Reimplemented from QGraphicsItemPrivate + virtual void subFocusItemChange() + { + emit q_func()->wantsFocusChanged(); + } }; QT_END_NAMESPACE diff --git a/src/declarative/util/qfxview.cpp b/src/declarative/util/qfxview.cpp index 2a38cda..19dfe2c 100644 --- a/src/declarative/util/qfxview.cpp +++ b/src/declarative/util/qfxview.cpp @@ -498,9 +498,10 @@ void QFxView::paintEvent(QPaintEvent *event) This virtual function does nothing with the event \a e in this class. */ -void QFxView::focusInEvent(QFocusEvent *) +void QFxView::focusInEvent(QFocusEvent *e) { // Do nothing (do not call QWidget::update()) + QGraphicsView::focusInEvent(e); } @@ -508,9 +509,10 @@ void QFxView::focusInEvent(QFocusEvent *) This virtual function does nothing with the event \a e in this class. */ -void QFxView::focusOutEvent(QFocusEvent *) +void QFxView::focusOutEvent(QFocusEvent *e) { // Do nothing (do not call QWidget::update()) + QGraphicsView::focusOutEvent(e); } QT_END_NAMESPACE -- cgit v0.12