respecting QPlatformTheme::ButtonPressKeys for Qt6

This commit is contained in:
Uwe Rathmann 2023-03-06 10:37:57 +01:00
parent f60fe75de4
commit 04c50fc301

View File

@ -10,9 +10,37 @@
#include <qbasictimer.h>
QSK_QT_PRIVATE_BEGIN
#include <private/qguiapplication_p.h>
QSK_QT_PRIVATE_END
#include <qpa/qplatformtheme.h>
QSK_SYSTEM_STATE( QskAbstractButton, Checked, QskAspect::LastSystemState >> 3 )
QSK_SYSTEM_STATE( QskAbstractButton, Pressed, QskAspect::LastSystemState >> 2 )
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
static inline QList< Qt::Key > qskButtonPressKeys()
{
const auto hint = QGuiApplicationPrivate::platformTheme()->themeHint(
QPlatformTheme::ButtonPressKeys );
return hint.value< QList< Qt::Key > >();
}
#else
static inline QList< Qt::Key > qskButtonPressKeys()
{
static const QList< Qt::Key > keys =
{ Qt::Key_Space, Qt::Key_Enter, Qt::Key_Return, Qt::Key_Select };
return keys;
}
#endif
static QskAbstractButton* qskCheckedSibling( const QskAbstractButton * button )
{
const auto parentItem = button->parentItem();
@ -264,10 +292,7 @@ bool QskAbstractButton::event( QEvent* event )
void QskAbstractButton::keyPressEvent( QKeyEvent* event )
{
switch ( event->key() )
{
case Qt::Key_Select:
case Qt::Key_Space:
if ( qskButtonPressKeys().contains( event->key() ) )
{
if ( !event->isAutoRepeat() )
setPressed( true );
@ -275,27 +300,17 @@ void QskAbstractButton::keyPressEvent( QKeyEvent* event )
// always accepting
return;
}
}
Inherited::keyPressEvent( event );
}
void QskAbstractButton::keyReleaseEvent( QKeyEvent* event )
{
if ( !event->isAutoRepeat() )
{
switch ( event->key() )
{
case Qt::Key_Select:
case Qt::Key_Space:
if ( qskButtonPressKeys().contains( event->key() ) )
{
releaseButton();
return;
}
default:
break;
}
}
Inherited::keyReleaseEvent( event );
}