#include <characterwidget.h>
Inheritance diagram for CharacterWidget:


Definition at line 36 of file characterwidget.h.
Public Slots | |
| void | updateFont (const QFont &font) |
| void | updateSize (const QString &fontSize) |
| void | updateStyle (const QString &fontStyle) |
| void | updateFontMerging (bool enable) |
Signals | |
| void | characterSelected (const QString &character) |
Public Member Functions | |
| CharacterWidget (QWidget *parent=0) | |
| QSize | sizeHint () const |
Protected Member Functions | |
| void | mouseMoveEvent (QMouseEvent *event) |
| void | mousePressEvent (QMouseEvent *event) |
| void | paintEvent (QPaintEvent *event) |
Private Attributes | |
| QFont | displayFont |
| int | columns |
| int | lastKey |
| int | squareSize |
| CharacterWidget::CharacterWidget | ( | QWidget * | parent = 0 |
) |
Definition at line 28 of file characterwidget.cpp.
References columns, lastKey, QWidget::setMouseTracking(), and squareSize.
00029 : QWidget(parent) 00030 { 00031 squareSize = 24; 00032 columns = 16; 00033 lastKey = -1; 00034 setMouseTracking(true); 00035 }
Here is the call graph for this function:

| QSize CharacterWidget::sizeHint | ( | ) | const [virtual] |
Reimplemented from QWidget.
Definition at line 74 of file characterwidget.cpp.
References columns, and squareSize.
00075 { 00076 return QSize(columns*squareSize, (65536/columns)*squareSize); 00077 }
| void CharacterWidget::updateFont | ( | const QFont & | font | ) | [slot] |
Definition at line 37 of file characterwidget.cpp.
References QWidget::adjustSize(), displayFont, QFont::family(), QWidget::font(), QWidget::QFontMetrics, qMax(), QFont::setFamily(), squareSize, and QWidget::update().
00038 { 00039 displayFont.setFamily(font.family()); 00040 squareSize = qMax(24, QFontMetrics(displayFont).xHeight() * 3); 00041 adjustSize(); 00042 update(); 00043 }
| void CharacterWidget::updateSize | ( | const QString & | fontSize | ) | [slot] |
Definition at line 45 of file characterwidget.cpp.
References QWidget::adjustSize(), displayFont, QWidget::QFontMetrics, qMax(), QFont::setPointSize(), squareSize, QString::toInt(), and QWidget::update().
00046 { 00047 displayFont.setPointSize(fontSize.toInt()); 00048 squareSize = qMax(24, QFontMetrics(displayFont).xHeight() * 3); 00049 adjustSize(); 00050 update(); 00051 }
| void CharacterWidget::updateStyle | ( | const QString & | fontStyle | ) | [slot] |
Definition at line 53 of file characterwidget.cpp.
References QWidget::adjustSize(), displayFont, QFont::family(), QFontDatabase::font(), QFont::pointSize(), QWidget::QFontMetrics, qMax(), QFont::setStyleStrategy(), squareSize, QFont::styleStrategy(), and QWidget::update().
00054 { 00055 QFontDatabase fontDatabase; 00056 const QFont::StyleStrategy oldStrategy = displayFont.styleStrategy(); 00057 displayFont = fontDatabase.font(displayFont.family(), fontStyle, displayFont.pointSize()); 00058 displayFont.setStyleStrategy(oldStrategy); 00059 squareSize = qMax(24, QFontMetrics(displayFont).xHeight() * 3); 00060 adjustSize(); 00061 update(); 00062 }
| void CharacterWidget::updateFontMerging | ( | bool | enable | ) | [slot] |
Definition at line 64 of file characterwidget.cpp.
References QWidget::adjustSize(), displayFont, QFont::NoFontMerging, QFont::PreferDefault, QFont::setStyleStrategy(), and QWidget::update().
00065 { 00066 if (enable) 00067 displayFont.setStyleStrategy(QFont::PreferDefault); 00068 else 00069 displayFont.setStyleStrategy(QFont::NoFontMerging); 00070 adjustSize(); 00071 update(); 00072 }
| void CharacterWidget::characterSelected | ( | const QString & | character | ) | [signal] |
Referenced by mousePressEvent().
| void CharacterWidget::mouseMoveEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events for the widget.
If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.
QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.
Reimplemented from QWidget.
Definition at line 79 of file characterwidget.cpp.
References QString::arg(), columns, displayFont, QWidget::event(), QFont::family(), QString::fromLatin1(), key, QWidget::mapFromGlobal(), QString::number(), QToolTip::showText(), squareSize, QPoint::x(), and QPoint::y().
00080 { 00081 QPoint widgetPosition = mapFromGlobal(event->globalPos()); 00082 uint key = (widgetPosition.y()/squareSize)*columns + widgetPosition.x()/squareSize; 00083 00084 QString text = QString::fromLatin1("<p>Character: <span style=\"font-size: 24pt; font-family: %1\">").arg(displayFont.family()) 00085 + QChar(key) 00086 + QString::fromLatin1("</span><p>Value: 0x") 00087 + QString::number(key, 16); 00088 QToolTip::showText(event->globalPos(), text, this); 00089 }
Here is the call graph for this function:

| void CharacterWidget::mousePressEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events for the widget.
If you create new widgets in the mousePressEvent() the mouseReleaseEvent() may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.
The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.
Reimplemented from QWidget.
Definition at line 91 of file characterwidget.cpp.
References QUnicodeTables::category(), characterSelected(), columns, emit, QWidget::event(), lastKey, Qt::LeftButton, QWidget::mousePressEvent(), QChar::NoCategory, squareSize, and QWidget::update().
00092 { 00093 if (event->button() == Qt::LeftButton) { 00094 lastKey = (event->y()/squareSize)*columns + event->x()/squareSize; 00095 if (QChar(lastKey).category() != QChar::NoCategory) 00096 emit characterSelected(QString(QChar(lastKey))); 00097 update(); 00098 } 00099 else 00100 QWidget::mousePressEvent(event); 00101 }
Here is the call graph for this function:

| void CharacterWidget::paintEvent | ( | QPaintEvent * | event | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.
The background can be set using setBackgroundRole() and setPalette().
From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.
Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:
...
extern void qt_x11_set_global_double_buffer(bool);
qt_x11_set_global_double_buffer(false);
...
Reimplemented from QWidget.
Definition at line 103 of file characterwidget.cpp.
References QFontMetrics::ascent(), Qt::black, QRect::bottom(), columns, displayFont, QPainter::drawRect(), QPainter::drawText(), QWidget::event(), QPainter::fillRect(), QWidget::fontMetrics(), Qt::gray, key, lastKey, QRect::left(), Qt::red, QRect::right(), row, QPainter::setClipRect(), QPainter::setFont(), QPainter::setPen(), squareSize, QRect::top(), Qt::white, and QFontMetrics::width().
00104 { 00105 QPainter painter(this); 00106 painter.fillRect(event->rect(), QBrush(Qt::white)); 00107 painter.setFont(displayFont); 00108 00109 QRect redrawRect = event->rect(); 00110 int beginRow = redrawRect.top()/squareSize; 00111 int endRow = redrawRect.bottom()/squareSize; 00112 int beginColumn = redrawRect.left()/squareSize; 00113 int endColumn = redrawRect.right()/squareSize; 00114 00115 painter.setPen(QPen(Qt::gray)); 00116 for (int row = beginRow; row <= endRow; ++row) { 00117 for (int column = beginColumn; column <= endColumn; ++column) { 00118 painter.drawRect(column*squareSize, row*squareSize, squareSize, squareSize); 00119 } 00120 } 00121 00122 QFontMetrics fontMetrics(displayFont); 00123 painter.setPen(QPen(Qt::black)); 00124 for (int row = beginRow; row <= endRow; ++row) { 00125 00126 for (int column = beginColumn; column <= endColumn; ++column) { 00127 00128 int key = row*columns + column; 00129 painter.setClipRect(column*squareSize, row*squareSize, squareSize, squareSize); 00130 00131 if (key == lastKey) 00132 painter.fillRect(column*squareSize + 1, row*squareSize + 1, squareSize, squareSize, QBrush(Qt::red)); 00133 00134 painter.drawText(column*squareSize + (squareSize / 2) - fontMetrics.width(QChar(key))/2, 00135 row*squareSize + 4 + fontMetrics.ascent(), 00136 QString(QChar(key))); 00137 } 00138 } 00139 }
Here is the call graph for this function:

QFont CharacterWidget::displayFont [private] |
Definition at line 59 of file characterwidget.h.
Referenced by mouseMoveEvent(), paintEvent(), updateFont(), updateFontMerging(), updateSize(), and updateStyle().
int CharacterWidget::columns [private] |
Definition at line 60 of file characterwidget.h.
Referenced by CharacterWidget(), mouseMoveEvent(), mousePressEvent(), paintEvent(), and sizeHint().
int CharacterWidget::lastKey [private] |
Definition at line 61 of file characterwidget.h.
Referenced by CharacterWidget(), mousePressEvent(), and paintEvent().
int CharacterWidget::squareSize [private] |
Definition at line 62 of file characterwidget.h.
Referenced by CharacterWidget(), mouseMoveEvent(), mousePressEvent(), paintEvent(), sizeHint(), updateFont(), updateSize(), and updateStyle().
1.5.1