keyboard: Make auto repeat work

This commit is contained in:
Peter Hartmann 2018-03-26 10:05:44 +02:00
parent 02da3993f2
commit 412267cf9a
2 changed files with 18 additions and 37 deletions

View File

@ -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 )

View File

@ -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;