qskTabChainIncrement added

This commit is contained in:
Uwe Rathmann 2018-02-06 14:57:34 +01:00
parent e91a0932e8
commit d32646c67c
3 changed files with 42 additions and 20 deletions

View File

@ -1,5 +1,6 @@
#include "QskEvent.h" #include "QskEvent.h"
#include "QskGesture.h" #include "QskGesture.h"
#include <QKeyEvent>
static void qskRegisterEventTypes() static void qskRegisterEventTypes()
{ {
@ -17,6 +18,27 @@ static void qskRegisterEventTypes()
Q_CONSTRUCTOR_FUNCTION( 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 ): QskEvent::QskEvent( QskEvent::Type type ):
QEvent( static_cast< QEvent::Type >( type ) ) QEvent( static_cast< QEvent::Type >( type ) )
{ {

View File

@ -99,4 +99,6 @@ private:
const State m_state; const State m_state;
}; };
QSK_EXPORT int qskTabChainIncrement( const QEvent* );
#endif #endif

View File

@ -8,6 +8,7 @@
#include "QskAspect.h" #include "QskAspect.h"
#include "QskSetup.h" #include "QskSetup.h"
#include "QskSkin.h" #include "QskSkin.h"
#include "QskEvent.h"
#include <QtMath> #include <QtMath>
#include <QPointer> #include <QPointer>
@ -259,31 +260,28 @@ bool QskWindow::event( QEvent* event )
void QskWindow::keyPressEvent( QKeyEvent* 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
The Qt/Quick implementation for navigating along the situation we also have to include all items being
focus tab chain gives unsufficient results, when the tab fences into consideration.
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 In certain situations Qt/Quick gets even stuck in a non
terminating loop: see Qt-Bug 65943 terminating loop: see Qt-Bug 65943
So we better block the focus navigation and find the So we better block the focus navigation and find the
next focus item on our own. next focus item on our own.
*/ */
ensureFocus( Qt::TabFocusReason ); ensureFocus( Qt::TabFocusReason );
event->accept(); event->accept();
return; return;
}
} }
} }