30 #include <QMouseEvent>
41 setMouseTracking(
true);
50 return QSize(m_columns * m_squareSize, (65536 / m_columns) * m_squareSize);
60 m_font.setFamily(font.family());
66 QPoint widgetPosition = mapFromGlobal(e->globalPos());
67 uint key = (widgetPosition.y() / m_squareSize) * m_columns + widgetPosition.x() / m_squareSize;
69 QString text = QString::fromLatin1(
"<p>Char: <span style=\"font-size: 28pt; font-family: %1\">").arg(m_font.family())
71 + QString::fromLatin1(
"</span><p>Value: 0x")
72 + QString::number(key, 16);
74 QToolTip::showText(e->globalPos(), text,
this);
79 if(e->button() != Qt::LeftButton)
81 QWidget::mousePressEvent(e);
85 m_currentChar = (e->y() / m_squareSize) * m_columns + e->x() / m_squareSize;
86 #if (QT_VERSION >= 0x050000)
87 if(QChar(m_currentChar).category() != QChar::Other_NotAssigned)
89 if(QChar(m_currentChar).category() != QChar::NoCategory)
91 emit charSelected(m_currentChar);
98 QPainter painter(
this);
99 painter.fillRect(e->rect(), Qt::white);
100 painter.setFont(m_font);
102 QRect redrawRect = e->rect();
103 int beginRow = redrawRect.top() / m_squareSize;
104 int endRow = redrawRect.bottom() / m_squareSize;
105 int beginColumn = redrawRect.left() / m_squareSize;
106 int endColumn = redrawRect.right() / m_squareSize;
108 painter.setPen(Qt::gray);
109 for(
int row = beginRow; row <= endRow; ++row)
110 for(
int column = beginColumn; column <= endColumn; ++column)
111 painter.drawRect(column * m_squareSize, row * m_squareSize, m_squareSize, m_squareSize);
113 painter.setPen(Qt::black);
114 QFontMetrics fontMetrics(m_font);
115 for(
int row = beginRow; row <= endRow; ++row)
117 for(
int column = beginColumn; column <= endColumn; ++column)
119 int key = row * m_columns + column;
120 painter.setClipRect(column * m_squareSize, row * m_squareSize, m_squareSize, m_squareSize);
122 if(key == m_currentChar)
123 painter.fillRect(column * m_squareSize + 1, row * m_squareSize + 1, m_squareSize, m_squareSize, Qt::lightGray);
125 painter.drawText(column * m_squareSize + (m_squareSize / 2) - fontMetrics.width(QChar(key))/2,
126 row * m_squareSize + 4 + fontMetrics.ascent(),
127 QString(QChar(key)));