A text engine for Qt rich texts. More...
#include <qwt_text_engine.h>
Public Member Functions | |
QwtRichTextEngine () | |
Constructor. | |
virtual int | heightForWidth (const QFont &font, int flags, const QString &text, int width) const |
virtual QSize | textSize (const QFont &font, int flags, const QString &text) const |
virtual void | draw (QPainter *painter, const QRect &rect, int flags, const QString &text) const |
virtual bool | mightRender (const QString &) const |
virtual void | textMargins (const QFont &, const QString &, int &left, int &right, int &top, int &bottom) const |
A text engine for Qt rich texts.
QwtRichTextEngine renders Qt rich texts using the classes of the Scribe framework of Qt.
Definition at line 150 of file qwt_text_engine.h.
QwtRichTextEngine::QwtRichTextEngine | ( | ) |
void QwtRichTextEngine::draw | ( | QPainter * | painter, |
const QRect & | rect, | ||
int | flags, | ||
const QString & | text | ||
) | const [virtual] |
Draw the text in a clipping rectangle
painter | Painter |
rect | Clipping rectangle |
flags | Bitwise OR of the flags like in for QPainter::drawText |
text | Text to be rendered |
Implements QwtTextEngine.
Definition at line 387 of file qwt_text_engine.cpp.
References QwtPainter::drawSimpleRichText().
{ QwtRichTextDocument doc(text, flags, painter->font()); QwtPainter::drawSimpleRichText(painter, rect, flags, doc); }
int QwtRichTextEngine::heightForWidth | ( | const QFont & | font, |
int | flags, | ||
const QString & | text, | ||
int | width | ||
) | const [virtual] |
Find the height for a given width
font | Font of the text |
flags | Bitwise OR of the flags used like in QPainter::drawText |
text | Text to be rendered |
width | Width |
Implements QwtTextEngine.
Definition at line 291 of file qwt_text_engine.cpp.
{ QwtRichTextDocument doc(text, flags, font); #if QT_VERSION < 0x040000 doc.setWidth(width); const int h = doc.height(); #else doc.setPageSize(QSize(width, QWIDGETSIZE_MAX)); const int h = qRound(doc.documentLayout()->documentSize().height()); #endif return h; }
bool QwtRichTextEngine::mightRender | ( | const QString & | text ) | const [virtual] |
Test if a string can be rendered by this text engine
text | Text to be tested |
Implements QwtTextEngine.
Definition at line 413 of file qwt_text_engine.cpp.
{ #if QT_VERSION < 0x040000 return QStyleSheet::mightBeRichText(text); #else return Qt::mightBeRichText(text); #endif }
void QwtRichTextEngine::textMargins | ( | const QFont & | , |
const QString & | , | ||
int & | left, | ||
int & | right, | ||
int & | top, | ||
int & | bottom | ||
) | const [virtual] |
Return margins around the texts
left | Return 0 |
right | Return 0 |
top | Return 0 |
bottom | Return 0 |
Implements QwtTextEngine.
Definition at line 430 of file qwt_text_engine.cpp.
{ left = right = top = bottom = 0; }
QSize QwtRichTextEngine::textSize | ( | const QFont & | font, |
int | flags, | ||
const QString & | text | ||
) | const [virtual] |
Returns the size, that is needed to render text
font | Font of the text |
flags | Bitwise OR of the flags used like in QPainter::drawText |
text | Text to be rendered |
Implements QwtTextEngine.
Definition at line 316 of file qwt_text_engine.cpp.
References qwtMax.
{ QwtRichTextDocument doc(text, flags, font); #if QT_VERSION < 0x040000 doc.setWidth(QWIDGETSIZE_MAX); const int w = doc.widthUsed(); const int h = doc.height(); return QSize(w, h); #else // QT_VERSION >= 0x040000 #if QT_VERSION < 0x040200 /* Unfortunately offering the bounding rect calculation in the API of QTextDocument has been forgotten in Qt <= 4.1.x. It is planned to come with Qt 4.2.x. In the meantime we need a hack with a temporary QLabel, to reengineer the internal calculations. */ static int off = 0; static QLabel *label = NULL; if ( label == NULL ) { label = new QLabel; label->hide(); const char *s = "XXXXX"; label->setText(s); int w1 = label->sizeHint().width(); const QFontMetrics fm(label->font()); int w2 = fm.width(s); off = w1 - w2; } label->setFont(doc.defaultFont()); label->setText(text); int w = qwtMax(label->sizeHint().width() - off, 0); doc.setPageSize(QSize(w, QWIDGETSIZE_MAX)); int h = qRound(doc.documentLayout()->documentSize().height()); return QSize(w, h); #else // QT_VERSION >= 0x040200 #if QT_VERSION >= 0x040300 QTextOption option = doc.defaultTextOption(); if ( option.wrapMode() != QTextOption::NoWrap ) { option.setWrapMode(QTextOption::NoWrap); doc.setDefaultTextOption(option); doc.adjustSize(); } #endif return doc.size().toSize(); #endif #endif }