46 #include <QFontDatabase>    47 #include <QMouseEvent>    48 #include <QPaintEvent>    59   setMouseTracking( 
true );
    64   mDisplayFont.setFamily( font.family() );
    65   mSquareSize = std::max( 24, QFontMetrics( mDisplayFont ).xHeight() * 3 );
    72   mDisplayFont.setPointSizeF( fontSize );
    73   mSquareSize = std::max( 24, QFontMetrics( mDisplayFont ).xHeight() * 3 );
    80   QFontDatabase fontDatabase;
    81   const QFont::StyleStrategy oldStrategy = mDisplayFont.styleStrategy();
    82   mDisplayFont = fontDatabase.font( mDisplayFont.family(), fontStyle, mDisplayFont.pointSize() );
    83   mDisplayFont.setStyleStrategy( oldStrategy );
    84   mSquareSize = std::max( 24, QFontMetrics( mDisplayFont ).xHeight() * 3 );
    92     mDisplayFont.setStyleStrategy( QFont::PreferDefault );
    94     mDisplayFont.setStyleStrategy( QFont::NoFontMerging );
   101   if ( mColumns == columns || columns < 1 )
   110   mLastKey = character.unicode();
   116   return QSize( mColumns * mSquareSize, ( 65536 / mColumns ) * mSquareSize );
   121   QPoint widgetPosition = mapFromGlobal( event->globalPos() );
   122   uint key = ( widgetPosition.y() / mSquareSize ) * mColumns + widgetPosition.x() / mSquareSize;
   124   QString text = tr( 
"<p>Character: <span style=\"font-size: 24pt; font-family: %1\">%2</span><p>Value: 0x%3" )
   125                  .arg( mDisplayFont.family() )
   128   QToolTip::showText( event->globalPos(), text, this );
   133   if ( event->button() == Qt::LeftButton )
   135     mLastKey = ( 
event->y() / mSquareSize ) * mColumns + event->x() / mSquareSize;
   136     if ( QChar( mLastKey ).category() != QChar::Other_NotAssigned )
   141     QWidget::mousePressEvent( event );
   146   QPainter painter( 
this );
   147   painter.fillRect( event->rect(), QBrush( Qt::white ) );
   148   painter.setFont( mDisplayFont );
   150   QRect redrawRect = 
event->rect();
   151   int beginRow = redrawRect.top() / mSquareSize;
   152   int endRow = redrawRect.bottom() / mSquareSize;
   153   int beginColumn = redrawRect.left() / mSquareSize;
   154   int endColumn = redrawRect.right() / mSquareSize;
   156   painter.setPen( QPen( Qt::gray ) );
   157   for ( 
int row = beginRow; row <= endRow; ++row )
   159     for ( 
int column = beginColumn; column <= endColumn; ++column )
   161       painter.drawRect( column * mSquareSize, row * mSquareSize, mSquareSize, mSquareSize );
   165   QFontMetrics fontMetrics( mDisplayFont );
   166   painter.setPen( QPen( Qt::black ) );
   167   for ( 
int row = beginRow; row <= endRow; ++row )
   170     for ( 
int column = beginColumn; column <= endColumn; ++column )
   173       int key = row * mColumns + column;
   174       painter.setClipRect( column * mSquareSize, row * mSquareSize, mSquareSize, mSquareSize );
   176       if ( key == mLastKey )
   177         painter.fillRect( column * mSquareSize + 1, row * mSquareSize + 1, mSquareSize, mSquareSize, QBrush( Qt::red ) );
   179       painter.drawText( column * mSquareSize + ( mSquareSize / 2 ) - fontMetrics.width( QChar( key ) ) / 2,
   180                         row * mSquareSize + 4 + fontMetrics.ascent(),
   181                         QString( QChar( key ) ) );