86  const QFontDatabase fontDatabase;
 
   87  const QFont::StyleStrategy oldStrategy = mDisplayFont.styleStrategy();
 
   88  mDisplayFont = fontDatabase.font( mDisplayFont.family(), fontStyle, mDisplayFont.pointSize() );
 
   89  mDisplayFont.setStyleStrategy( oldStrategy );
 
   90  mSquareSize = std::max( 34, QFontMetrics( mDisplayFont ).xHeight() * 3 );
 
 
  116  const bool changed = 
character.unicode() != mLastKey;
 
  118  QWidget *widget = parentWidget();
 
  121    QScrollArea *scrollArea = qobject_cast<QScrollArea *>( widget->parent() );
 
  122    if ( scrollArea && mLastKey < 65536 )
 
  124      scrollArea->ensureVisible( 0, mLastKey / mColumns * mSquareSize );
 
 
  146  const QFontMetrics fm( mDisplayFont );
 
  148  if ( event->key() == Qt::Key_Right )
 
  150    int next = std::min( mLastKey + 1, 0xfffc );
 
  151    while ( next < 0xfffc && !fm.inFont( QChar( next ) ) )
 
  157  else if ( event->key() == Qt::Key_Left )
 
  159    int next = mLastKey - 1;
 
  160    while ( next > 0 && !fm.inFont( QChar( next ) ) )
 
  166  else if ( event->key() == Qt::Key_Down )
 
  168    int next = std::min( mLastKey + mColumns, 0xfffc );
 
  169    while ( next < 0xfffc && !fm.inFont( QChar( next ) ) )
 
  171      next = std::min( next + mColumns, 0xfffc );
 
  175  else if ( event->key() == Qt::Key_Up )
 
  177    int next = std::max( 0, mLastKey - mColumns );
 
  178    while ( next > 0 && !fm.inFont( QChar( next ) ) )
 
  180      next = std::max( 0, next - mColumns );
 
  184  else if ( event->key() == Qt::Key_Home )
 
  187    while ( next < 0xfffc && !fm.inFont( QChar( next ) ) )
 
  193  else if ( event->key() == Qt::Key_End )
 
  196    while ( next > 0 && !fm.inFont( QChar( next ) ) )
 
  202  else if ( !event->text().isEmpty() )
 
  204    QChar chr = 
event->text().at( 0 );
 
  205    if ( chr.unicode() != mLastKey )
 
 
  214  const QPoint widgetPosition = mapFromGlobal( event->globalPos() );
 
  215  const uint key = ( widgetPosition.y() / mSquareSize ) * mColumns + widgetPosition.x() / mSquareSize;
 
  217  const QString text = QStringLiteral( 
"<p style=\"text-align: center; font-size: 24pt; font-family: %1\">%2</p><p><table><tr><td>%3</td><td>%2</td></tr><tr><td>%4</td><td>%5</td></tr><tr><td>%6</td><td>0x%7</td></tr></table>" )
 
  218                         .arg( mDisplayFont.family() )
 
  220                         .arg( tr( 
"Character" ), tr( 
"Decimal" ) )
 
  222                         .arg( tr( 
"Hex" ), QString::number( key, 16 ) );
 
  223  QToolTip::showText( event->globalPos(), text, 
this );
 
 
  241  QPainter painter( 
this );
 
  242  painter.setFont( mDisplayFont );
 
  244  const QFontMetrics fontMetrics( mDisplayFont );
 
  246  const QRect redrawRect = 
event->rect();
 
  247  const int beginRow = redrawRect.top() / mSquareSize;
 
  248  const int endRow = redrawRect.bottom() / mSquareSize;
 
  249  const int beginColumn = redrawRect.left() / mSquareSize;
 
  250  const int endColumn = std::min( mColumns - 1, redrawRect.right() / mSquareSize );
 
  252  const QPalette palette = qApp->palette();
 
  253  painter.setPen( QPen( palette.color( QPalette::Mid ) ) );
 
  254  for ( 
int row = beginRow; row <= endRow; ++row )
 
  256    for ( 
int column = beginColumn; column <= endColumn; ++column )
 
  258      const int key = row * mColumns + column;
 
  259      painter.setBrush( fontMetrics.inFont( QChar( key ) ) ? QBrush( palette.color( QPalette::Base ) ) : Qt::NoBrush );
 
  260      painter.drawRect( column * mSquareSize, row * mSquareSize, mSquareSize, mSquareSize );
 
  264  for ( 
int row = beginRow; row <= endRow; ++row )
 
  266    for ( 
int column = beginColumn; column <= endColumn; ++column )
 
  268      const int key = row * mColumns + column;
 
  269      painter.setClipRect( column * mSquareSize, row * mSquareSize, mSquareSize, mSquareSize );
 
  270      painter.setPen( QPen( palette.color( key == mLastKey ? QPalette::HighlightedText : QPalette::WindowText ) ) );
 
  272      if ( key == mLastKey )
 
  273        painter.fillRect( column * mSquareSize + 1, row * mSquareSize + 1, mSquareSize, mSquareSize, QBrush( palette.color( QPalette::Highlight ) ) );
 
  275      if ( fontMetrics.inFont( QChar( key ) ) )
 
  277        painter.drawText( column * mSquareSize + ( mSquareSize / 2 ) - fontMetrics.boundingRect( QChar( key ) ).width() / 2, row * mSquareSize + 4 + fontMetrics.ascent(), QString( QChar( key ) ) );