85 const QFontDatabase fontDatabase;
86 const QFont::StyleStrategy oldStrategy = mDisplayFont.styleStrategy();
87 mDisplayFont = fontDatabase.font( mDisplayFont.family(), fontStyle, mDisplayFont.pointSize() );
88 mDisplayFont.setStyleStrategy( oldStrategy );
89 mSquareSize = std::max( 34, QFontMetrics( mDisplayFont ).xHeight() * 3 );
115 const bool changed =
character.unicode() != mLastKey;
117 QWidget *widget = parentWidget();
120 QScrollArea *scrollArea = qobject_cast< QScrollArea *>( widget->parent() );
121 if ( scrollArea && mLastKey < 65536 )
123 scrollArea->ensureVisible( 0, mLastKey / mColumns * mSquareSize );
145 const QFontMetrics fm( mDisplayFont );
147 if ( event->key() == Qt::Key_Right )
149 int next = std::min( mLastKey + 1, 0xfffc );
150 while ( next < 0xfffc && !fm.inFont( QChar( next ) ) )
156 else if ( event->key() == Qt::Key_Left )
158 int next = mLastKey - 1;
159 while ( next > 0 && !fm.inFont( QChar( next ) ) )
165 else if ( event->key() == Qt::Key_Down )
167 int next = std::min( mLastKey + mColumns, 0xfffc );
168 while ( next < 0xfffc && !fm.inFont( QChar( next ) ) )
170 next = std::min( next + mColumns, 0xfffc );
174 else if ( event->key() == Qt::Key_Up )
176 int next = std::max( 0, mLastKey - mColumns );
177 while ( next > 0 && !fm.inFont( QChar( next ) ) )
179 next = std::max( 0, next - mColumns );
183 else if ( event->key() == Qt::Key_Home )
186 while ( next < 0xfffc && !fm.inFont( QChar( next ) ) )
192 else if ( event->key() == Qt::Key_End )
195 while ( next > 0 && !fm.inFont( QChar( next ) ) )
201 else if ( !event->text().isEmpty() )
203 QChar chr =
event->text().at( 0 );
204 if ( chr.unicode() != mLastKey )
213 const QPoint widgetPosition = mapFromGlobal( event->globalPos() );
214 const uint key = ( widgetPosition.y() / mSquareSize ) * mColumns + widgetPosition.x() / mSquareSize;
216 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>" )
217 .arg( mDisplayFont.family() )
219 .arg( tr(
"Character" ),
223 QString::number( key, 16 ) );
224 QToolTip::showText( event->globalPos(), text,
this );
242 QPainter painter(
this );
243 painter.setFont( mDisplayFont );
245 const QFontMetrics fontMetrics( mDisplayFont );
247 const QRect redrawRect =
event->rect();
248 const int beginRow = redrawRect.top() / mSquareSize;
249 const int endRow = redrawRect.bottom() / mSquareSize;
250 const int beginColumn = redrawRect.left() / mSquareSize;
251 const int endColumn = std::min( mColumns - 1, redrawRect.right() / mSquareSize );
253 const QPalette palette = qApp->palette();
254 painter.setPen( QPen( palette.color( QPalette::Mid ) ) );
255 for (
int row = beginRow; row <= endRow; ++row )
257 for (
int column = beginColumn; column <= endColumn; ++column )
259 const int key = row * mColumns + column;
260 painter.setBrush( fontMetrics.inFont( QChar( key ) ) ? QBrush( palette.color( QPalette::Base ) ) : Qt::NoBrush );
261 painter.drawRect( column * mSquareSize, row * mSquareSize, mSquareSize, mSquareSize );
265 for (
int row = beginRow; row <= endRow; ++row )
267 for (
int column = beginColumn; column <= endColumn; ++column )
269 const int key = row * mColumns + column;
270 painter.setClipRect( column * mSquareSize, row * mSquareSize, mSquareSize, mSquareSize );
271 painter.setPen( QPen( palette.color( key == mLastKey ? QPalette::HighlightedText : QPalette::WindowText ) ) );
273 if ( key == mLastKey )
274 painter.fillRect( column * mSquareSize + 1, row * mSquareSize + 1, mSquareSize, mSquareSize, QBrush( palette.color( QPalette::Highlight ) ) );
276 if ( fontMetrics.inFont( QChar( key ) ) )
278 painter.drawText( column * mSquareSize + ( mSquareSize / 2 ) - fontMetrics.boundingRect( QChar( key ) ).width() / 2,
279 row * mSquareSize + 4 + fontMetrics.ascent(),
280 QString( QChar( key ) ) );