diff options
author | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-05-19 14:48:16 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-01-14 12:45:26 (GMT) |
commit | 26372057d92564da9baf6d17c685fd1b22ff4b8a (patch) | |
tree | 000c726950e7251a706ff294a211c886cd8731ec /src/gui/text/qstatictext.cpp | |
parent | 5d0f93a3d6d3d99d86d181ee3cc559a6782be4ee (diff) | |
download | Qt-26372057d92564da9baf6d17c685fd1b22ff4b8a.zip Qt-26372057d92564da9baf6d17c685fd1b22ff4b8a.tar.gz Qt-26372057d92564da9baf6d17c685fd1b22ff4b8a.tar.bz2 |
Simplify QStaticText
Not much to gain by going directly to the QTextEngine, and the code
is a lot simpler if we just use the QTextLayout instead.
Diffstat (limited to 'src/gui/text/qstatictext.cpp')
-rw-r--r-- | src/gui/text/qstatictext.cpp | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index 90b1145..bb83fd1 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -51,6 +51,11 @@ QStaticText::QStaticText(const QString &text, const QFont &font) d->init(text, font); } +QStaticTextPrivate::QStaticTextPrivate() + : textLayout(0) +{ +} + QStaticTextPrivate *QStaticTextPrivate::get(const QStaticText *q) { return q->d_ptr; @@ -58,34 +63,21 @@ QStaticTextPrivate *QStaticTextPrivate::get(const QStaticText *q) void QStaticTextPrivate::init(const QString &text, const QFont &font) { - engine.text = text; - engine.fnt = font; - - /*engine.option.setTextDirection(d->state->layoutDirection); - if (tf & (Qt::TextForceLeftToRight|Qt::TextForceRightToLeft)) { - engine.ignoreBidi = true; - engine.option.setTextDirection((tf & Qt::TextForceLeftToRight) ? Qt::LeftToRight : Qt::RightToLeft); - }*/ + Q_ASSERT(textLayout == 0); + textLayout = new QTextLayout(text, font); + textLayout->setCacheEnabled(true); - engine.itemize(); - QScriptLine line; - line.length = text.length(); - engine.shapeLine(line); + QFontMetrics fontMetrics(font); - int nItems = engine.layoutData->items.size(); - visualOrder = QVarLengthArray<int>(nItems); - QVarLengthArray<uchar> levels(nItems); - for (int i = 0; i < nItems; ++i) - levels[i] = engine.layoutData->items[i].analysis.bidiLevel; - QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data()); + textLayout->beginLayout(); + int h = fontMetrics.ascent(); + QTextLine line; + if ((line = textLayout->createLine()).isValid()) { + line.setLineWidth(fontMetrics.width(text)); + line.setPosition(QPointF(0, h)); + h += line.height(); + } - /*if (justificationPadding > 0) { - engine.option.setAlignment(Qt::AlignJustify); - engine.forceJustification = true; - // this works because justify() is only interested in the difference between width and textWidth - line.width = justificationPadding; - engine.justify(line); - }*/ } QT_END_NAMESPACE |