focusPolicy/wheelEnabled moved from QskControl to QskQuickItem

This commit is contained in:
Uwe Rathmann 2024-02-02 09:48:26 +01:00
parent ceae1fef27
commit 9d2414fd89
9 changed files with 84 additions and 84 deletions

View File

@ -49,8 +49,6 @@ static inline bool qskMaybeGesture( QQuickItem* item,
QskControl::QskControl( QQuickItem* parent ) QskControl::QskControl( QQuickItem* parent )
: QskQuickItem( *( new QskControlPrivate() ), parent ) : QskQuickItem( *( new QskControlPrivate() ), parent )
{ {
Inherited::setActiveFocusOnTab( false );
if ( parent ) if ( parent )
{ {
// inheriting attributes from parent // inheriting attributes from parent
@ -91,55 +89,6 @@ bool QskControl::autoLayoutChildren() const
return d_func()->autoLayoutChildren; return d_func()->autoLayoutChildren;
} }
void QskControl::setWheelEnabled( bool on )
{
Q_D( QskControl );
if ( on != d->isWheelEnabled )
{
d->isWheelEnabled = on;
Q_EMIT wheelEnabledChanged();
}
}
bool QskControl::isWheelEnabled() const
{
return d_func()->isWheelEnabled;
}
void QskControl::setFocusPolicy( Qt::FocusPolicy policy )
{
Q_D( QskControl );
if ( policy != d->focusPolicy )
{
d->focusPolicy = ( policy & ~Qt::TabFocus );
const bool tabFocus = policy & Qt::TabFocus;
if ( !tabFocus && window() )
{
// Removing the activeFocusItem from the focus tab chain is not possible
if ( window()->activeFocusItem() == this )
{
if ( auto focusItem = nextItemInFocusChain( true ) )
focusItem->setFocus( true );
}
}
Inherited::setActiveFocusOnTab( tabFocus );
Q_EMIT focusPolicyChanged();
}
}
Qt::FocusPolicy QskControl::focusPolicy() const
{
uint policy = d_func()->focusPolicy;
if ( Inherited::activeFocusOnTab() )
policy |= Qt::TabFocus;
return static_cast< Qt::FocusPolicy >( policy );
}
void QskControl::setBackgroundColor( const QColor& color ) void QskControl::setBackgroundColor( const QColor& color )
{ {
setBackground( QskGradient( color ) ); setBackground( QskGradient( color ) );
@ -857,7 +806,7 @@ bool QskControl::childMouseEventFilter( QQuickItem* child, QEvent* event )
{ {
/* /*
The strategy implemented in many classes of the Qt development is The strategy implemented in many classes of the Qt development is
to analyze the events without blocking the handling of the child. to analyze the events without blocking the handling of the child.
Once a gesture is detected the gesture handling trys to steal the Once a gesture is detected the gesture handling trys to steal the
mouse grab hoping for the child to abort its operation. mouse grab hoping for the child to abort its operation.

View File

@ -32,12 +32,6 @@ class QSK_EXPORT QskControl : public QskQuickItem, public QskSkinnable
Q_PROPERTY( bool autoLayoutChildren READ autoLayoutChildren Q_PROPERTY( bool autoLayoutChildren READ autoLayoutChildren
WRITE setAutoLayoutChildren ) WRITE setAutoLayoutChildren )
Q_PROPERTY( Qt::FocusPolicy focusPolicy READ focusPolicy
WRITE setFocusPolicy NOTIFY focusPolicyChanged )
Q_PROPERTY( bool wheelEnabled READ isWheelEnabled
WRITE setWheelEnabled NOTIFY wheelEnabledChanged )
Q_PROPERTY( bool visibleToLayout READ isVisibleToLayout ) Q_PROPERTY( bool visibleToLayout READ isVisibleToLayout )
Q_PROPERTY( QskMargins margins READ margins Q_PROPERTY( QskMargins margins READ margins
@ -95,12 +89,6 @@ class QSK_EXPORT QskControl : public QskQuickItem, public QskSkinnable
void setAutoLayoutChildren( bool ); void setAutoLayoutChildren( bool );
bool autoLayoutChildren() const; bool autoLayoutChildren() const;
void setWheelEnabled( bool );
bool isWheelEnabled() const;
void setFocusPolicy( Qt::FocusPolicy );
Qt::FocusPolicy focusPolicy() const;
void setSection( QskAspect::Section ); void setSection( QskAspect::Section );
void resetSection(); void resetSection();
QskAspect::Section section() const override final; QskAspect::Section section() const override final;
@ -180,8 +168,6 @@ class QSK_EXPORT QskControl : public QskQuickItem, public QskSkinnable
void marginsChanged( const QMarginsF& ); void marginsChanged( const QMarginsF& );
void focusIndicatorRectChanged(); void focusIndicatorRectChanged();
void localeChanged( const QLocale& ); void localeChanged( const QLocale& );
void focusPolicyChanged();
void wheelEnabledChanged();
public Q_SLOTS: public Q_SLOTS:
void setLocale( const QLocale& ); void setLocale( const QLocale& );
@ -209,7 +195,6 @@ class QSK_EXPORT QskControl : public QskQuickItem, public QskSkinnable
virtual QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const; virtual QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const;
private: private:
void setActiveFocusOnTab( bool ) = delete; // use setFocusPolicy
void updateInputMethod( Qt::InputMethodQueries ) = delete; // use qskUpdateInputMethod void updateInputMethod( Qt::InputMethodQueries ) = delete; // use qskUpdateInputMethod
QSGNode* updateItemPaintNode( QSGNode* ) override final; QSGNode* updateItemPaintNode( QSGNode* ) override final;

View File

@ -150,8 +150,6 @@ QskControlPrivate::QskControlPrivate()
, explicitLocale( false ) , explicitLocale( false )
, explicitSection( false ) , explicitSection( false )
, autoLayoutChildren( false ) , autoLayoutChildren( false )
, focusPolicy( Qt::NoFocus )
, isWheelEnabled( false )
, blockLayoutRequestEvents( true ) , blockLayoutRequestEvents( true )
{ {
} }

View File

@ -59,9 +59,6 @@ class QskControlPrivate : public QskQuickItemPrivate
bool autoLayoutChildren : 1; bool autoLayoutChildren : 1;
uint focusPolicy : 4;
bool isWheelEnabled : 1;
mutable bool blockLayoutRequestEvents : 1; mutable bool blockLayoutRequestEvents : 1;
}; };

View File

@ -171,6 +171,7 @@ QskQuickItem::QskQuickItem( QskQuickItemPrivate& dd, QQuickItem* parent )
: QQuickItem( dd, parent ) : QQuickItem( dd, parent )
{ {
setFlag( QQuickItem::ItemHasContents, true ); setFlag( QQuickItem::ItemHasContents, true );
Inherited::setActiveFocusOnTab( false );
if ( dd.updateFlags & QskQuickItem::DeferredUpdate ) if ( dd.updateFlags & QskQuickItem::DeferredUpdate )
qskFilterWindow( window() ); qskFilterWindow( window() );
@ -349,6 +350,55 @@ bool QskQuickItem::isTabFence() const
return d_func()->isTabFence; return d_func()->isTabFence;
} }
void QskQuickItem::setFocusPolicy( Qt::FocusPolicy policy )
{
Q_D( QskQuickItem );
if ( policy != d->focusPolicy )
{
d->focusPolicy = ( policy & ~Qt::TabFocus );
const bool tabFocus = policy & Qt::TabFocus;
if ( !tabFocus && window() )
{
// Removing the activeFocusItem from the focus tab chain is not possible
if ( window()->activeFocusItem() == this )
{
if ( auto focusItem = nextItemInFocusChain( true ) )
focusItem->setFocus( true );
}
}
Inherited::setActiveFocusOnTab( tabFocus );
Q_EMIT focusPolicyChanged( focusPolicy() );
}
}
Qt::FocusPolicy QskQuickItem::focusPolicy() const
{
uint policy = d_func()->focusPolicy;
if ( Inherited::activeFocusOnTab() )
policy |= Qt::TabFocus;
return static_cast< Qt::FocusPolicy >( policy );
}
void QskQuickItem::setWheelEnabled( bool on )
{
Q_D( QskQuickItem );
if ( on != d->wheelEnabled )
{
d->wheelEnabled = on;
Q_EMIT wheelEnabledChanged( on );
}
}
bool QskQuickItem::isWheelEnabled() const
{
return d_func()->wheelEnabled;
}
void QskQuickItem::setPolishOnResize( bool on ) void QskQuickItem::setPolishOnResize( bool on )
{ {
Q_D( QskQuickItem ); Q_D( QskQuickItem );
@ -937,7 +987,7 @@ QSGNode* QskQuickItem::updatePaintNode( QSGNode* node, UpdatePaintNodeData* data
it has already been allocated. When deleting it we have a dangling pointer. it has already been allocated. When deleting it we have a dangling pointer.
instead of the new one. instead of the new one.
To avoid creashes for the second situation we manually clear d->paintNode. To avoid creashes for the second situation we manually clear d->paintNode.
*/ */
d->paintNode = nullptr; d->paintNode = nullptr;
#endif #endif

View File

@ -26,6 +26,12 @@ class QSK_EXPORT QskQuickItem : public QQuickItem
Q_PROPERTY( bool polishOnResize READ polishOnResize Q_PROPERTY( bool polishOnResize READ polishOnResize
WRITE setPolishOnResize NOTIFY itemFlagsChanged FINAL ) WRITE setPolishOnResize NOTIFY itemFlagsChanged FINAL )
Q_PROPERTY( Qt::FocusPolicy focusPolicy READ focusPolicy
WRITE setFocusPolicy NOTIFY focusPolicyChanged )
Q_PROPERTY( bool wheelEnabled READ isWheelEnabled
WRITE setWheelEnabled NOTIFY wheelEnabledChanged )
Q_PROPERTY( bool visibleToParent READ isVisibleToParent ) Q_PROPERTY( bool visibleToParent READ isVisibleToParent )
Q_PROPERTY( bool hasChildItems READ hasChildItems ) Q_PROPERTY( bool hasChildItems READ hasChildItems )
Q_PROPERTY( bool initiallyPainted READ isInitiallyPainted ) Q_PROPERTY( bool initiallyPainted READ isInitiallyPainted )
@ -75,9 +81,15 @@ class QSK_EXPORT QskQuickItem : public QQuickItem
void setPolishOnResize( bool ); void setPolishOnResize( bool );
bool polishOnResize() const; bool polishOnResize() const;
void setFocusPolicy( Qt::FocusPolicy );
Qt::FocusPolicy focusPolicy() const;
void setTabFence( bool ); void setTabFence( bool );
bool isTabFence() const; bool isTabFence() const;
void setWheelEnabled( bool );
bool isWheelEnabled() const;
void setLayoutMirroring( bool on, bool childrenInherit = false ); void setLayoutMirroring( bool on, bool childrenInherit = false );
void resetLayoutMirroring(); void resetLayoutMirroring();
bool layoutMirroring() const; bool layoutMirroring() const;
@ -85,9 +97,9 @@ class QSK_EXPORT QskQuickItem : public QQuickItem
void resetUpdateFlags(); void resetUpdateFlags();
UpdateFlags updateFlags() const; UpdateFlags updateFlags() const;
Q_INVOKABLE void setUpdateFlag( UpdateFlag, bool on = true ); void setUpdateFlag( UpdateFlag, bool on = true );
Q_INVOKABLE void resetUpdateFlag( UpdateFlag ); void resetUpdateFlag( UpdateFlag );
Q_INVOKABLE bool testUpdateFlag( UpdateFlag ) const; bool testUpdateFlag( UpdateFlag ) const;
void classBegin() override; void classBegin() override;
void componentComplete() override; void componentComplete() override;
@ -100,6 +112,9 @@ class QSK_EXPORT QskQuickItem : public QQuickItem
bool maybeUnresized() const; bool maybeUnresized() const;
Q_SIGNALS: Q_SIGNALS:
void wheelEnabledChanged( bool );
void focusPolicyChanged( Qt::FocusPolicy );
void itemFlagsChanged(); void itemFlagsChanged();
void updateFlagsChanged( UpdateFlags ); void updateFlagsChanged( UpdateFlags );
@ -158,6 +173,7 @@ class QSK_EXPORT QskQuickItem : public QQuickItem
*/ */
void childrenRect() = delete; void childrenRect() = delete;
void setActiveFocusOnTab( bool ) = delete; // use setFocusPolicy
void applyUpdateFlag( UpdateFlag, bool on ); void applyUpdateFlag( UpdateFlag, bool on );
QSGNode* updatePaintNode( QSGNode*, UpdatePaintNodeData* ) override final; QSGNode* updatePaintNode( QSGNode*, UpdatePaintNodeData* ) override final;

View File

@ -21,6 +21,8 @@ QskQuickItemPrivate::QskQuickItemPrivate()
, blockedImplicitSize( true ) , blockedImplicitSize( true )
, clearPreviousNodes( false ) , clearPreviousNodes( false )
, initiallyPainted( false ) , initiallyPainted( false )
, wheelEnabled( false )
, focusPolicy( Qt::NoFocus )
{ {
if ( updateFlags & QskQuickItem::DeferredLayout ) if ( updateFlags & QskQuickItem::DeferredLayout )
{ {

View File

@ -57,6 +57,9 @@ class QskQuickItemPrivate : public QQuickItemPrivate
bool clearPreviousNodes : 1; bool clearPreviousNodes : 1;
bool initiallyPainted : 1; bool initiallyPainted : 1;
bool wheelEnabled : 1;
uint focusPolicy : 4;
}; };
#endif #endif

View File

@ -4,7 +4,7 @@
*****************************************************************************/ *****************************************************************************/
#include "QskSetup.h" #include "QskSetup.h"
#include "QskControl.h" #include "QskQuickItem.h"
#include "QskGraphicProviderMap.h" #include "QskGraphicProviderMap.h"
#include "QskSkinManager.h" #include "QskSkinManager.h"
#include "QskSkin.h" #include "QskSkin.h"
@ -164,7 +164,7 @@ QskGraphicProvider* QskSetup::graphicProvider( const QString& providerId ) const
bool QskSetup::eventFilter( QObject* object, QEvent* event ) bool QskSetup::eventFilter( QObject* object, QEvent* event )
{ {
if ( auto control = qskControlCast( object ) ) if ( auto qskItem = qobject_cast< QskQuickItem* >( object ) )
{ {
/* /*
Qt::FocusPolicy has always been there with widgets, got lost with Qt::FocusPolicy has always been there with widgets, got lost with
@ -186,7 +186,7 @@ bool QskSetup::eventFilter( QObject* object, QEvent* event )
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease: case QEvent::MouseButtonRelease:
{ {
if ( ( control->focusPolicy() & Qt::ClickFocus ) == Qt::ClickFocus ) if ( ( qskItem->focusPolicy() & Qt::ClickFocus ) == Qt::ClickFocus )
{ {
const bool focusOnRelease = const bool focusOnRelease =
QGuiApplication::styleHints()->setFocusOnTouchRelease(); QGuiApplication::styleHints()->setFocusOnTouchRelease();
@ -194,19 +194,19 @@ bool QskSetup::eventFilter( QObject* object, QEvent* event )
if ( focusOnRelease ) if ( focusOnRelease )
{ {
if ( event->type() == QEvent::MouseButtonRelease ) if ( event->type() == QEvent::MouseButtonRelease )
control->forceActiveFocus( Qt::MouseFocusReason ); qskItem->forceActiveFocus( Qt::MouseFocusReason );
} }
else else
{ {
if ( event->type() == QEvent::MouseButtonPress ) if ( event->type() == QEvent::MouseButtonPress )
control->forceActiveFocus( Qt::MouseFocusReason ); qskItem->forceActiveFocus( Qt::MouseFocusReason );
} }
} }
break; break;
} }
case QEvent::Wheel: case QEvent::Wheel:
{ {
if ( !control->isWheelEnabled() ) if ( !qskItem->isWheelEnabled() )
{ {
/* /*
We block further processing of the event. This is in line We block further processing of the event. This is in line
@ -218,8 +218,8 @@ bool QskSetup::eventFilter( QObject* object, QEvent* event )
return true; return true;
} }
if ( ( control->focusPolicy() & Qt::WheelFocus ) == Qt::WheelFocus ) if ( ( qskItem->focusPolicy() & Qt::WheelFocus ) == Qt::WheelFocus )
control->forceActiveFocus( Qt::MouseFocusReason ); qskItem->forceActiveFocus( Qt::MouseFocusReason );
break; break;
} }