Public Member Functions

QwtRichTextEngine Class Reference

A text engine for Qt rich texts. More...

#include <qwt_text_engine.h>

Inheritance diagram for QwtRichTextEngine:
Inheritance graph
[legend]
Collaboration diagram for QwtRichTextEngine:
Collaboration graph
[legend]

List of all members.

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

Detailed Description

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.


Constructor & Destructor Documentation

QwtRichTextEngine::QwtRichTextEngine (  )

Constructor.

Definition at line 277 of file qwt_text_engine.cpp.

{
}

Member Function Documentation

void QwtRichTextEngine::draw ( QPainter *  painter,
const QRect &  rect,
int  flags,
const QString &  text 
) const [virtual]

Draw the text in a clipping rectangle

Parameters:
painterPainter
rectClipping rectangle
flagsBitwise OR of the flags like in for QPainter::drawText
textText 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

Parameters:
fontFont of the text
flagsBitwise OR of the flags used like in QPainter::drawText
textText to be rendered
widthWidth
Returns:
Calculated height

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

Parameters:
textText to be tested
Returns:
QStyleSheet::mightBeRichText(text);

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

Parameters:
leftReturn 0
rightReturn 0
topReturn 0
bottomReturn 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

Parameters:
fontFont of the text
flagsBitwise OR of the flags used like in QPainter::drawText
textText to be rendered
Returns:
Caluclated size

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
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines