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" ),
224 QString::number( key, 16 ) );
225 QToolTip::showText( event->globalPos(), text,
this );
243 QPainter painter(
this );
244 painter.setFont( mDisplayFont );
246 const QFontMetrics fontMetrics( mDisplayFont );
248 const QRect redrawRect =
event->rect();
249 const int beginRow = redrawRect.top() / mSquareSize;
250 const int endRow = redrawRect.bottom() / mSquareSize;
251 const int beginColumn = redrawRect.left() / mSquareSize;
252 const int endColumn = std::min( mColumns - 1, redrawRect.right() / mSquareSize );
254 const QPalette palette = qApp->palette();
255 painter.setPen( QPen( palette.color( QPalette::Mid ) ) );
256 for (
int row = beginRow; row <= endRow; ++row )
258 for (
int column = beginColumn; column <= endColumn; ++column )
260 const int key = row * mColumns + column;
261 painter.setBrush( fontMetrics.inFont( QChar( key ) ) ? QBrush( palette.color( QPalette::Base ) ) : Qt::NoBrush );
262 painter.drawRect( column * mSquareSize, row * mSquareSize, mSquareSize, mSquareSize );
266 for (
int row = beginRow; row <= endRow; ++row )
268 for (
int column = beginColumn; column <= endColumn; ++column )
270 const int key = row * mColumns + column;
271 painter.setClipRect( column * mSquareSize, row * mSquareSize, mSquareSize, mSquareSize );
272 painter.setPen( QPen( palette.color( key == mLastKey ? QPalette::HighlightedText : QPalette::WindowText ) ) );
274 if ( key == mLastKey )
275 painter.fillRect( column * mSquareSize + 1, row * mSquareSize + 1, mSquareSize, mSquareSize, QBrush( palette.color( QPalette::Highlight ) ) );
277 if ( fontMetrics.inFont( QChar( key ) ) )
279 painter.drawText( column * mSquareSize + ( mSquareSize / 2 ) - fontMetrics.boundingRect( QChar( key ) ).width() / 2,
280 row * mSquareSize + 4 + fontMetrics.ascent(),
281 QString( QChar( key ) ) );