From 4417f485dbaac79412d43ec403e56e7e2067e5ac Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 7 Aug 2009 13:15:50 +0200 Subject: Respect font settings of QStaticText and clip to maximum size drawText() that renders into a QRect will clip the text (unless otherwise set by the text flags passed to the function.) In drawStaticText() we should do the same for identical behavior. We also need to respect the font set on the QStaticText object. --- src/gui/painting/qpainter.cpp | 21 ++++++++++++++++++++- src/gui/text/qstatictext.cpp | 2 ++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 1057893..83f66e2 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -5728,11 +5728,30 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static if (!d->engine || staticText.isEmpty() || pen().style() == Qt::NoPen) return; - const QStaticTextPrivate *staticText_d = QStaticTextPrivate::get(&staticText); + const QStaticTextPrivate *staticText_d = QStaticTextPrivate::get(&staticText); + bool restoreWhenFinished = false; + + if (staticText_d->size.isValid()) { + setClipRect(QRectF(position, staticText_d->size)); + + save(); + restoreWhenFinished = true; + } + + if (font() != staticText_d->font) { + setFont(staticText_d->font); + + save(); + restoreWhenFinished = true; + } + for (int i=0; iitemCount; ++i) { const QTextItemInt &gf = staticText_d->items[i]; d->engine->drawTextItem(staticText_d->itemPositions[i] + position, gf); } + + if (restoreWhenFinished) + restore(); } /*! diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index 5a8fd9b..70e1c47 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -455,6 +455,7 @@ void QStaticTextPrivate::init() DrawTextItemDevice counterDevice; { QPainter painter(&counterDevice); + painter.setFont(font); if (size.isValid()) painter.drawText(QRectF(QPointF(0, 0), size), text); @@ -475,6 +476,7 @@ void QStaticTextPrivate::init() glyphLayoutMemory, logClusterMemory); { QPainter painter(&recorderDevice); + painter.setFont(font); if (size.isValid()) painter.drawText(QRectF(QPointF(0, 0), size), text); -- cgit v0.12