30 #include <QtGui/QMouseEvent> 
   31 #include <QtGui/QPainter> 
   32 #include <QtGui/QToolTip> 
   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(QChar(m_currentChar).category() != QChar::NoCategory)
 
   87     emit charSelected(m_currentChar);
 
   94   QPainter painter(
this);
 
   95   painter.fillRect(e->rect(), Qt::white);
 
   96   painter.setFont(m_font);
 
   98   QRect redrawRect = e->rect();
 
   99   int beginRow = redrawRect.top() / m_squareSize;
 
  100   int endRow = redrawRect.bottom() / m_squareSize;
 
  101   int beginColumn = redrawRect.left() / m_squareSize;
 
  102   int endColumn = redrawRect.right() / m_squareSize;
 
  104   painter.setPen(Qt::gray);
 
  105   for(
int row = beginRow; row <= endRow; ++row)
 
  106     for(
int column = beginColumn; column <= endColumn; ++column)
 
  107       painter.drawRect(column * m_squareSize, row * m_squareSize, m_squareSize, m_squareSize);
 
  109   painter.setPen(Qt::black);
 
  110   QFontMetrics fontMetrics(m_font);
 
  111   for(
int row = beginRow; row <= endRow; ++row)
 
  113     for(
int column = beginColumn; column <= endColumn; ++column)
 
  115       int key = row * m_columns + column;
 
  116       painter.setClipRect(column * m_squareSize, row * m_squareSize, m_squareSize, m_squareSize);
 
  118       if(key == m_currentChar)
 
  119         painter.fillRect(column * m_squareSize + 1, row * m_squareSize + 1, m_squareSize, m_squareSize, Qt::lightGray);
 
  121       painter.drawText(column * m_squareSize + (m_squareSize / 2) - fontMetrics.width(QChar(key))/2,
 
  122                        row * m_squareSize + 4 + fontMetrics.ascent(),
 
  123                        QString(QChar(key)));
 
void mouseMoveEvent(QMouseEvent *e)
 
int getCurrentChar() const 
 
void paintEvent(QPaintEvent *e)
 
void updateFont(const QFont &font)
 
~CharMapWidget()
Destructor. 
 
QFont m_font
Current font. 
 
void mousePressEvent(QMouseEvent *e)
 
A widget used to show the set of characters of a specified font. 
 
CharMapWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs the character map widget which is a child of parent, with widget flags set to f...