respecting QPlatformTheme::ButtonPressKeys for Qt6
This commit is contained in:
parent
f60fe75de4
commit
04c50fc301
@ -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,17 +292,13 @@ bool QskAbstractButton::event( QEvent* event )
|
||||
|
||||
void QskAbstractButton::keyPressEvent( QKeyEvent* event )
|
||||
{
|
||||
switch ( event->key() )
|
||||
if ( qskButtonPressKeys().contains( event->key() ) )
|
||||
{
|
||||
case Qt::Key_Select:
|
||||
case Qt::Key_Space:
|
||||
{
|
||||
if ( !event->isAutoRepeat() )
|
||||
setPressed( true );
|
||||
if ( !event->isAutoRepeat() )
|
||||
setPressed( true );
|
||||
|
||||
// always accepting
|
||||
return;
|
||||
}
|
||||
// always accepting
|
||||
return;
|
||||
}
|
||||
|
||||
Inherited::keyPressEvent( event );
|
||||
@ -282,19 +306,10 @@ void QskAbstractButton::keyPressEvent( QKeyEvent* event )
|
||||
|
||||
void QskAbstractButton::keyReleaseEvent( QKeyEvent* event )
|
||||
{
|
||||
if ( !event->isAutoRepeat() )
|
||||
if ( qskButtonPressKeys().contains( event->key() ) )
|
||||
{
|
||||
switch ( event->key() )
|
||||
{
|
||||
case Qt::Key_Select:
|
||||
case Qt::Key_Space:
|
||||
{
|
||||
releaseButton();
|
||||
return;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
releaseButton();
|
||||
return;
|
||||
}
|
||||
|
||||
Inherited::keyReleaseEvent( event );
|
||||
|
Loading…
x
Reference in New Issue
Block a user