46 #include <QFontDatabase> 47 #include <QMouseEvent> 48 #include <QPaintEvent> 71 squareSize = qMax( 24,
QFontMetrics( displayFont ).xHeight() * 3 );
81 squareSize = qMax( 24,
QFontMetrics( displayFont ).xHeight() * 3 );
90 const QFont::StyleStrategy oldStrategy = displayFont.
styleStrategy();
91 displayFont = fontDatabase.
font( displayFont.
family(), fontStyle, displayFont.
pointSize() );
93 squareSize = qMax( 24,
QFontMetrics( displayFont ).xHeight() * 3 );
110 if ( columns == cols || cols < 1 )
126 return QSize( columns*squareSize, ( 65536 / columns )*squareSize );
134 uint key = ( widgetPosition.
y() / squareSize ) * columns + widgetPosition.
x() / squareSize;
136 QString text =
tr(
"<p>Character: <span style=\"font-size: 24pt; font-family: %1\">%2</span><p>Value: 0x%3" )
147 if ( event->
button() == Qt::LeftButton )
149 lastKey = (
event->y() / squareSize ) * columns + event->
x() / squareSize;
150 if (
QChar( lastKey ).category() != QChar::Other_NotAssigned )
164 painter.
setFont( displayFont );
169 int beginRow = redrawRect.
top() / squareSize;
170 int endRow = redrawRect.
bottom() / squareSize;
171 int beginColumn = redrawRect.
left() / squareSize;
172 int endColumn = redrawRect.
right() / squareSize;
177 for (
int row = beginRow; row <= endRow; ++row )
179 for (
int column = beginColumn; column <= endColumn; ++column )
181 painter.
drawRect( column*squareSize, row*squareSize, squareSize, squareSize );
190 for (
int row = beginRow; row <= endRow; ++row )
193 for (
int column = beginColumn; column <= endColumn; ++column )
196 int key = row * columns + column;
197 painter.
setClipRect( column*squareSize, row*squareSize, squareSize, squareSize );
199 if ( key == lastKey )
200 painter.
fillRect( column*squareSize + 1, row*squareSize + 1, squareSize, squareSize,
QBrush( Qt::red ) );
202 painter.
drawText( column*squareSize + ( squareSize / 2 ) - fontMetrics.
width(
QChar( key ) ) / 2,
203 row*squareSize + 4 + fontMetrics.
ascent(),
void fillRect(const QRectF &rectangle, const QBrush &brush)
StyleStrategy styleStrategy() const
void showText(const QPoint &pos, const QString &text, QWidget *w)
QString tr(const char *sourceText, const char *disambiguation, int n)
const QRect & rect() const
void drawRect(const QRectF &rectangle)
void setFont(const QFont &font)
const QPoint & globalPos() const
void setPen(const QColor &color)
void setStyleStrategy(StyleStrategy s)
void drawText(const QPointF &position, const QString &text)
int width(const QString &text, int len) const
void setPointSizeF(qreal pointSize)
void setClipRect(const QRectF &rectangle, Qt::ClipOperation operation)
void setFamily(const QString &family)
QFont font(const QString &family, const QString &style, int pointSize) const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void rect(int *x, int *y, int *width, int *height) const