diff --git a/src/controls/QskEvent.cpp b/src/controls/QskEvent.cpp index e8ab64c6..a1883b42 100644 --- a/src/controls/QskEvent.cpp +++ b/src/controls/QskEvent.cpp @@ -1,5 +1,6 @@ #include "QskEvent.h" #include "QskGesture.h" +#include static void qskRegisterEventTypes() { @@ -17,6 +18,27 @@ static void qskRegisterEventTypes() Q_CONSTRUCTOR_FUNCTION( qskRegisterEventTypes ) +int qskTabChainIncrement( const QEvent* event ) +{ + if ( event && event->type() == QEvent::KeyPress ) + { + const auto keyEvent = static_cast< const QKeyEvent* >( event ); + if ( !( keyEvent->modifiers() & ( Qt::ControlModifier | Qt::AltModifier ) ) ) + { + switch( keyEvent->key() ) + { + case Qt::Key_Tab: + return 1; + + case Qt::Key_Backtab: + return -1; + } + } + } + + return 0; +} + QskEvent::QskEvent( QskEvent::Type type ): QEvent( static_cast< QEvent::Type >( type ) ) { diff --git a/src/controls/QskEvent.h b/src/controls/QskEvent.h index c7a40e0b..8215828d 100644 --- a/src/controls/QskEvent.h +++ b/src/controls/QskEvent.h @@ -99,4 +99,6 @@ private: const State m_state; }; +QSK_EXPORT int qskTabChainIncrement( const QEvent* ); + #endif diff --git a/src/controls/QskWindow.cpp b/src/controls/QskWindow.cpp index a045dfde..e78043b3 100644 --- a/src/controls/QskWindow.cpp +++ b/src/controls/QskWindow.cpp @@ -8,6 +8,7 @@ #include "QskAspect.h" #include "QskSetup.h" #include "QskSkin.h" +#include "QskEvent.h" #include #include @@ -259,31 +260,28 @@ bool QskWindow::event( QEvent* event ) void QskWindow::keyPressEvent( QKeyEvent* event ) { - if ( !( event->modifiers() & ( Qt::ControlModifier | Qt::AltModifier ) ) ) + if ( qskTabChainIncrement( event ) != 0 ) { - if ( ( event->key() == Qt::Key_Backtab ) || ( event->key() == Qt::Key_Tab ) ) + auto focusItem = activeFocusItem(); + if ( focusItem == nullptr || focusItem == contentItem() ) { - auto focusItem = activeFocusItem(); - if ( focusItem == nullptr || focusItem == contentItem() ) - { - /* - The Qt/Quick implementation for navigating along the - focus tab chain gives unsufficient results, when the - starting point is the root item. In this specific - situation we also have to include all items being - tab fences into consideration. + /* + The Qt/Quick implementation for navigating along the + focus tab chain gives unsufficient results, when the + starting point is the root item. In this specific + situation we also have to include all items being + tab fences into consideration. - In certain situations Qt/Quick gets even stuck in a non - terminating loop: see Qt-Bug 65943 + In certain situations Qt/Quick gets even stuck in a non + terminating loop: see Qt-Bug 65943 - So we better block the focus navigation and find the - next focus item on our own. - */ - ensureFocus( Qt::TabFocusReason ); - event->accept(); + So we better block the focus navigation and find the + next focus item on our own. + */ + ensureFocus( Qt::TabFocusReason ); + event->accept(); - return; - } + return; } }