From 2cdabf34d682b8bde04ba191bc00d585084b70e4 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Fri, 19 Jan 2018 10:15:29 +0100 Subject: [PATCH] QskControl::focusIndicatorRect introduced --- examples/sliders/Slider.cpp | 7 +++++++ examples/sliders/Slider.h | 2 ++ src/controls/QskControl.cpp | 5 +++++ src/controls/QskControl.h | 2 ++ src/controls/QskFocusIndicator.cpp | 31 ++++++++++++++++++++++++++++-- 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/examples/sliders/Slider.cpp b/examples/sliders/Slider.cpp index 1ff46f97..01abbfb1 100644 --- a/examples/sliders/Slider.cpp +++ b/examples/sliders/Slider.cpp @@ -43,6 +43,9 @@ Slider::Slider( QQuickItem* parentItem ): skinlet->setOwnedBySkinnable( true ); setSkinlet( skinlet ); + + connect( this, &QskRangeControl::valueChanged, + this, &QskControl::focusIndicatorRectChanged ); } QSizeF Slider::contentsSizeHint() const @@ -51,3 +54,7 @@ QSizeF Slider::contentsSizeHint() const return Inherited::contentsSizeHint() + QSizeF( 0, extra ); } +QRectF Slider::focusIndicatorRect() const +{ + return subControlRect( QskSlider::Handle ); +} diff --git a/examples/sliders/Slider.h b/examples/sliders/Slider.h index 2f5ecb98..856ec3dd 100644 --- a/examples/sliders/Slider.h +++ b/examples/sliders/Slider.h @@ -16,6 +16,8 @@ public: QSK_SUBCONTROLS( Scale, Decoration ) Slider( QQuickItem* parent = nullptr ); + + virtual QRectF focusIndicatorRect() const override; virtual QSizeF contentsSizeHint() const override; }; diff --git a/src/controls/QskControl.cpp b/src/controls/QskControl.cpp index 1c65a02c..a8a2e29f 100644 --- a/src/controls/QskControl.cpp +++ b/src/controls/QskControl.cpp @@ -1454,6 +1454,11 @@ QRectF QskControl::gestureRect() const return boundingRect(); } +QRectF QskControl::focusIndicatorRect() const +{ + return boundingRect(); +} + void QskControl::updateLayout() { } diff --git a/src/controls/QskControl.h b/src/controls/QskControl.h index 4799e178..f78bcbf1 100644 --- a/src/controls/QskControl.h +++ b/src/controls/QskControl.h @@ -107,6 +107,7 @@ public: virtual QRectF layoutRect() const; virtual QRectF gestureRect() const; + virtual QRectF focusIndicatorRect() const; void setAutoFillBackground( bool ); bool autoFillBackground() const; @@ -163,6 +164,7 @@ public: Q_SIGNALS: void backgroundChanged(); void marginsChanged(); + void focusIndicatorRectChanged(); void localeChanged( const QLocale& ); void controlFlagsChanged(); void focusPolicyChanged(); diff --git a/src/controls/QskFocusIndicator.cpp b/src/controls/QskFocusIndicator.cpp index 5ac19f2d..536b6055 100644 --- a/src/controls/QskFocusIndicator.cpp +++ b/src/controls/QskFocusIndicator.cpp @@ -19,8 +19,32 @@ static void qskSetupGeometryConnections( QObject::connect( sender, SIGNAL( yChanged() ), receiver, method ); QObject::connect( sender, SIGNAL( widthChanged() ), receiver, method ); QObject::connect( sender, SIGNAL( heightChanged() ), receiver, method ); + + bool hasIndicatorSignal = ( qobject_cast< const QskControl* >( sender ) != nullptr ); + if ( !hasIndicatorSignal ) + { + const auto mo = sender->metaObject(); + hasIndicatorSignal = ( mo->indexOfSignal( "focusIndicatorRectChanged()" ) >= 0 ); + } + + if ( hasIndicatorSignal ) + { + QObject::connect( sender, SIGNAL( focusIndicatorRectChanged() ), receiver, method ); + } } +static inline QRectF qskFocusIndicatorRect( const QQuickItem* item ) +{ + if ( auto control = qobject_cast< const QskControl* >( item ) ) + return control->focusIndicatorRect(); + + const QVariant v = item->property( "focusIndicatorRect" ); + if ( v.canConvert( QMetaType::QRectF ) ) + return v.toRectF(); + + return item->boundingRect(); +} + QskFocusIndicator::QskFocusIndicator( QQuickItem* parent ): Inherited( parent ) // parentItem() might change, but parent() stays { @@ -120,7 +144,10 @@ QRectF QskFocusIndicator::focusRect() const { const QQuickItem* focusItem = window()->activeFocusItem(); if ( focusItem && ( focusItem != window()->contentItem() ) ) - return parentItem()->mapRectFromItem( focusItem, focusItem->boundingRect() ); + { + const auto rect = qskFocusIndicatorRect( focusItem ); + return parentItem()->mapRectFromItem( focusItem, rect ); + } } return QRectF(); @@ -133,7 +160,7 @@ void QskFocusIndicator::resetConnections() QQuickItem* item = parentItem(); if ( item ) { - qskSetupGeometryConnections( item, this, SLOT(updateFocusFrame()) ); + qskSetupGeometryConnections( item, this, SLOT( updateFocusFrame() ) ); } }