Allow navigation of character widget with arrow cursor keys

This commit is contained in:
Nyall Dawson 2019-05-02 08:52:23 +10:00
parent bd13c36061
commit 30f1c97341

View File

@ -139,7 +139,45 @@ QSize CharacterWidget::sizeHint() const
void CharacterWidget::keyPressEvent( QKeyEvent *event )
{
if ( !event->text().isEmpty() )
QFontMetrics fm( mDisplayFont );
if ( event->key() == Qt::Key_Right )
{
int next = std::min( mLastKey + 1, 0xfffc );
while ( next < 0xfffc && !fm.inFont( QChar( next ) ) )
{
next++;
}
setCharacter( QChar( next ) );
}
else if ( event->key() == Qt::Key_Left )
{
int next = mLastKey - 1;
while ( next > 0 && !fm.inFont( QChar( next ) ) )
{
next--;
}
setCharacter( QChar( next ) );
}
else if ( event->key() == Qt::Key_Down )
{
int next = std::min( mLastKey + mColumns, 0xfffc );
while ( next < 0xfffc && !fm.inFont( QChar( next ) ) )
{
next = std::min( next + mColumns, 0xfffc );
}
setCharacter( QChar( next ) );
}
else if ( event->key() == Qt::Key_Up )
{
int next = std::max( 0, mLastKey - mColumns );
while ( next > 0 && !fm.inFont( QChar( next ) ) )
{
next = std::max( 0, next - mColumns );
}
setCharacter( QChar( next ) );
}
else if ( !event->text().isEmpty() )
{
QChar chr = event->text().at( 0 );
if ( chr.unicode() != mLastKey )