Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow navigation of character widget with arrow cursor keys
  • Loading branch information
nyalldawson committed May 2, 2019
1 parent bd13c36 commit 30f1c97
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/gui/symbology/characterwidget.cpp
Expand Up @@ -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 )
Expand Down

0 comments on commit 30f1c97

Please sign in to comment.