From 412267cf9aebd9c8d5f9cc21a386e710bff59976 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Mon, 26 Mar 2018 10:05:44 +0200 Subject: [PATCH] keyboard: Make auto repeat work --- src/controls/QskInputPanel.cpp | 54 ++++++++++++---------------------- src/controls/QskInputPanel.h | 1 - 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/src/controls/QskInputPanel.cpp b/src/controls/QskInputPanel.cpp index 092ad7e2..241b1373 100644 --- a/src/controls/QskInputPanel.cpp +++ b/src/controls/QskInputPanel.cpp @@ -131,6 +131,14 @@ static qreal qskRowStretch( const QskInputPanel::KeyRow& keyRow ) return stretch; } +static bool qskIsAutorepeat( Qt::Key key ) +{ + return ( key != Qt::Key_Return && key != Qt::Key_Enter + && key != Qt::Key_Shift && key!= Qt::Key_CapsLock + && key != Qt::Key_Mode_switch ); + +} + namespace { struct KeyCounter @@ -155,6 +163,16 @@ QskKeyButton::QskKeyButton( int keyIndex, QskInputPanel* inputPanel, QQuickItem* options.setFontSizeMode( QskTextOptions::VerticalFit ); setTextOptions( options ); + auto keyData = m_inputPanel->keyDataAt( m_keyIndex ); + const auto key = keyData.key & ~KeyStates; + + if ( qskIsAutorepeat( key ) ) + { + setAutoRepeat( true ); + setAutoRepeatDelay( 500 ); + setAutoRepeatInterval( 1000 / QGuiApplication::styleHints()->keyboardAutoRepeatRate() ); + } + updateText(); connect( this, &QskKeyButton::pressed, this, [ this ]() @@ -216,7 +234,6 @@ class QskInputPanel::PrivateData focusKeyIndex( -1 ), selectedGroup( -1 ), candidateOffset( 0 ), - repeatKeyTimerId( -1 ), buttonsBox( nullptr ), isUIInitialized( false ) { @@ -230,8 +247,6 @@ class QskInputPanel::PrivateData qint16 selectedGroup; qint32 candidateOffset; - int repeatKeyTimerId; - QLocale locale; QVector< Qt::Key > groups; @@ -650,39 +665,6 @@ void QskInputPanel::geometryChanged( Q_EMIT keyboardRectChanged(); } -void QskInputPanel::timerEvent( QTimerEvent* e ) -{ - if( e->timerId() == m_data->repeatKeyTimerId ) - { - for( auto it = m_data->activeKeys.begin(); it != m_data->activeKeys.end(); ) - { - if( it->second.count >= 0 && it->second.count++ > 20 ) // ### use platform long-press hint - { - const auto key = keyDataAt( it->second.keyIndex ).key & ~KeyStates; - - if( !key || key == Qt::Key_unknown ) - { - it = m_data->activeKeys.erase( it ); - continue; - } - - if( key == Qt::Key_ApplicationLeft || key == Qt::Key_ApplicationRight ) - { - setCandidateOffset( m_data->candidateOffset - + ( key == Qt::Key_ApplicationLeft ? -1 : 1 ) ); - } - else if( !( key & KeyLocked ) ) // do not repeat locked keys - { - // long press events could be emitted from here - compose( key & ~KeyStates ); - } - } - - ++it; - } - } -} - bool QskInputPanel::eventFilter( QObject* object, QEvent* event ) { if( event->type() == QEvent::InputMethod ) diff --git a/src/controls/QskInputPanel.h b/src/controls/QskInputPanel.h index a514bb1f..4fc648cc 100644 --- a/src/controls/QskInputPanel.h +++ b/src/controls/QskInputPanel.h @@ -123,7 +123,6 @@ public Q_SLOTS: protected: virtual void geometryChanged( const QRectF&, const QRectF& ) override; - virtual void timerEvent( QTimerEvent* ) override; virtual bool eventFilter( QObject* object, QEvent* event ) override; virtual void updateLayout() override;