keyboard: Make auto repeat work
This commit is contained in:
parent
02da3993f2
commit
412267cf9a
|
@ -131,6 +131,14 @@ static qreal qskRowStretch( const QskInputPanel::KeyRow& keyRow )
|
||||||
return stretch;
|
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
|
namespace
|
||||||
{
|
{
|
||||||
struct KeyCounter
|
struct KeyCounter
|
||||||
|
@ -155,6 +163,16 @@ QskKeyButton::QskKeyButton( int keyIndex, QskInputPanel* inputPanel, QQuickItem*
|
||||||
options.setFontSizeMode( QskTextOptions::VerticalFit );
|
options.setFontSizeMode( QskTextOptions::VerticalFit );
|
||||||
setTextOptions( options );
|
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();
|
updateText();
|
||||||
|
|
||||||
connect( this, &QskKeyButton::pressed, this, [ this ]()
|
connect( this, &QskKeyButton::pressed, this, [ this ]()
|
||||||
|
@ -216,7 +234,6 @@ class QskInputPanel::PrivateData
|
||||||
focusKeyIndex( -1 ),
|
focusKeyIndex( -1 ),
|
||||||
selectedGroup( -1 ),
|
selectedGroup( -1 ),
|
||||||
candidateOffset( 0 ),
|
candidateOffset( 0 ),
|
||||||
repeatKeyTimerId( -1 ),
|
|
||||||
buttonsBox( nullptr ),
|
buttonsBox( nullptr ),
|
||||||
isUIInitialized( false )
|
isUIInitialized( false )
|
||||||
{
|
{
|
||||||
|
@ -230,8 +247,6 @@ class QskInputPanel::PrivateData
|
||||||
qint16 selectedGroup;
|
qint16 selectedGroup;
|
||||||
qint32 candidateOffset;
|
qint32 candidateOffset;
|
||||||
|
|
||||||
int repeatKeyTimerId;
|
|
||||||
|
|
||||||
QLocale locale;
|
QLocale locale;
|
||||||
|
|
||||||
QVector< Qt::Key > groups;
|
QVector< Qt::Key > groups;
|
||||||
|
@ -650,39 +665,6 @@ void QskInputPanel::geometryChanged(
|
||||||
Q_EMIT keyboardRectChanged();
|
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 )
|
bool QskInputPanel::eventFilter( QObject* object, QEvent* event )
|
||||||
{
|
{
|
||||||
if( event->type() == QEvent::InputMethod )
|
if( event->type() == QEvent::InputMethod )
|
||||||
|
|
|
@ -123,7 +123,6 @@ public Q_SLOTS:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void geometryChanged( const QRectF&, const QRectF& ) override;
|
virtual void geometryChanged( const QRectF&, const QRectF& ) override;
|
||||||
virtual void timerEvent( QTimerEvent* ) override;
|
|
||||||
virtual bool eventFilter( QObject* object, QEvent* event ) override;
|
virtual bool eventFilter( QObject* object, QEvent* event ) override;
|
||||||
virtual void updateLayout() override;
|
virtual void updateLayout() override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue