From 4fddc4db24895990e0c1a891064e1e1de4404799 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Fri, 2 Feb 2024 12:38:03 +0100 Subject: [PATCH] code moved from QskSetup to QskQuickItem --- src/controls/QskQuickItem.cpp | 44 ++++++++++++++++++- src/controls/QskSetup.cpp | 79 ----------------------------------- src/controls/QskSetup.h | 2 - 3 files changed, 43 insertions(+), 82 deletions(-) diff --git a/src/controls/QskQuickItem.cpp b/src/controls/QskQuickItem.cpp index 0ca67380..53ca1f74 100644 --- a/src/controls/QskQuickItem.cpp +++ b/src/controls/QskQuickItem.cpp @@ -352,6 +352,12 @@ bool QskQuickItem::isTabFence() const void QskQuickItem::setFocusPolicy( Qt::FocusPolicy policy ) { + /* + Qt::FocusPolicy has always been there with widgets, got lost with + Qt/Quick and has been reintroduced with Qt/Quick Controls 2 ( QC2 ). + Unfortunately this was done by adding code on top instead of fixing + the foundation. + */ Q_D( QskQuickItem ); if ( policy != d->focusPolicy ) { @@ -361,7 +367,7 @@ void QskQuickItem::setFocusPolicy( Qt::FocusPolicy policy ) if ( !tabFocus && window() ) { - // Removing the activeFocusItem from the focus tab chain is not possible + // removing the activeFocusItem from the focus tab chain is not possible if ( window()->activeFocusItem() == this ) { if ( auto focusItem = nextItemInFocusChain( true ) ) @@ -713,6 +719,42 @@ bool QskQuickItem::event( QEvent* event ) return true; } + break; + } + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + { + if ( ( focusPolicy() & Qt::ClickFocus ) == Qt::ClickFocus ) + { + if ( QGuiApplication::styleHints()->setFocusOnTouchRelease() ) + { + if ( event->type() == QEvent::MouseButtonRelease ) + forceActiveFocus( Qt::MouseFocusReason ); + } + else + { + if ( event->type() == QEvent::MouseButtonPress ) + forceActiveFocus( Qt::MouseFocusReason ); + } + } + break; + } + case QEvent::Wheel: + { + if ( !isWheelEnabled() ) + { + /* + We block further processing of the event. This is in line + with not receiving any mouse event that have not been + explicitly enabled with setAcceptedMouseButtons(). + */ + event->ignore(); + return true; + } + + if ( ( focusPolicy() & Qt::WheelFocus ) == Qt::WheelFocus ) + forceActiveFocus( Qt::MouseFocusReason ); + break; } } diff --git a/src/controls/QskSetup.cpp b/src/controls/QskSetup.cpp index b910cf81..f70c657f 100644 --- a/src/controls/QskSetup.cpp +++ b/src/controls/QskSetup.cpp @@ -4,14 +4,10 @@ *****************************************************************************/ #include "QskSetup.h" -#include "QskQuickItem.h" #include "QskGraphicProviderMap.h" #include "QskSkinManager.h" #include "QskSkin.h" -#include -#include - QskSetup* QskSetup::s_instance = nullptr; static inline bool qskHasEnvironment( const char* env ) @@ -62,13 +58,7 @@ static void qskApplicationHook() qAddPostRoutine( QskSetup::cleanup ); } -static void qskApplicationFilter() -{ - QCoreApplication::instance()->installEventFilter( QskSetup::instance() ); -} - Q_CONSTRUCTOR_FUNCTION( qskApplicationHook ) -Q_COREAPP_STARTUP_FUNCTION( qskApplicationFilter ) class QskSetup::PrivateData { @@ -162,73 +152,4 @@ QskGraphicProvider* QskSetup::graphicProvider( const QString& providerId ) const return m_data->graphicProviders.provider( providerId ); } -bool QskSetup::eventFilter( QObject* object, QEvent* event ) -{ - if ( auto qskItem = qobject_cast< QskQuickItem* >( object ) ) - { - /* - Qt::FocusPolicy has always been there with widgets, got lost with - Qt/Quick and has been reintroduced with Qt/Quick Controls 2 ( QC2 ). - Unfortunately this was done once more by adding code on top instead - of fixing the foundation. - - But we also don't want to have how it is done in QC2 by adding - the focus management in the event handler of the base class. - This implementation reverts the expected default behaviour of when - events are accepted/ignored + is an error prone nightmare, when it - comes to overloading event handlers missing to call the base class. - - That's why we prefer to do the focus management outside of the - event handlers. - */ - switch ( event->type() ) - { - case QEvent::MouseButtonPress: - case QEvent::MouseButtonRelease: - { - if ( ( qskItem->focusPolicy() & Qt::ClickFocus ) == Qt::ClickFocus ) - { - const bool focusOnRelease = - QGuiApplication::styleHints()->setFocusOnTouchRelease(); - - if ( focusOnRelease ) - { - if ( event->type() == QEvent::MouseButtonRelease ) - qskItem->forceActiveFocus( Qt::MouseFocusReason ); - } - else - { - if ( event->type() == QEvent::MouseButtonPress ) - qskItem->forceActiveFocus( Qt::MouseFocusReason ); - } - } - break; - } - case QEvent::Wheel: - { - if ( !qskItem->isWheelEnabled() ) - { - /* - We block further processing of the event. This is in line - with not receiving any mouse event that have not been - explicitly enabled with setAcceptedMouseButtons(). - - */ - event->ignore(); - return true; - } - - if ( ( qskItem->focusPolicy() & Qt::WheelFocus ) == Qt::WheelFocus ) - qskItem->forceActiveFocus( Qt::MouseFocusReason ); - - break; - } - default: - break; - } - } - - return false; -} - #include "moc_QskSetup.cpp" diff --git a/src/controls/QskSetup.h b/src/controls/QskSetup.h index d541a614..85d3a5af 100644 --- a/src/controls/QskSetup.h +++ b/src/controls/QskSetup.h @@ -50,8 +50,6 @@ class QSK_EXPORT QskSetup : public QObject QskSetup(); ~QskSetup() override; - bool eventFilter( QObject*, QEvent* ) override final; - static QskSetup* s_instance; class PrivateData;