summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qpainter.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-03-26 12:38:32 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-03-29 12:09:37 (GMT)
commit3cebc02818d2025cda96528bbf289db15ef1bf89 (patch)
treed2d5855823c66ab46028eb53f0a55f6597bf89ee /src/gui/painting/qpainter.cpp
parentd717d2686ecdbeafee1f5cabc6832c8339cfb2b4 (diff)
downloadQt-3cebc02818d2025cda96528bbf289db15ef1bf89.zip
Qt-3cebc02818d2025cda96528bbf289db15ef1bf89.tar.gz
Qt-3cebc02818d2025cda96528bbf289db15ef1bf89.tar.bz2
Change QStaticText::setMaximumSize() to setTextWidth()
To avoid having to precalculate the height of the laid out text, we now only supply a maximum text width to QStaticText. The only usage of the maximum height would be to clip the results, and clipping should be set separately from the QStaticText call, since this has no impact on the layout of the glyphs. The tests have been updated to reflect the change in logic. We also need a consistent way of specifying the position of the text. Before, the position meant "baseline position" for unbroken text and "top left position" for text with a specified layout width. We want to be consistent, and since baseline position makes no sense for multiline text, we standardize on top left position. Task-number: QTBUG-9029 Reviewed-by: Gunnar
Diffstat (limited to 'src/gui/painting/qpainter.cpp')
-rw-r--r--src/gui/painting/qpainter.cpp42
1 files changed, 19 insertions, 23 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index ac5c8b7..7856881 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -5762,19 +5762,24 @@ void QPainterPrivate::drawGlyphs(const quint32 *glyphArray, const QPointF *posit
/*!
- \fn void QPainter::drawStaticText(const QPoint &position, const QStaticText &staticText)
+ \fn void QPainter::drawStaticText(const QPoint &topLeftPosition, const QStaticText &staticText)
\since 4.7
\overload
- Draws the \a staticText at the \a position.
+ Draws the \a staticText at the \a topLeftPosition.
+
+ \note The y-position is used as the top of the font.
+
*/
/*!
- \fn void QPainter::drawStaticText(int x, int y, const QStaticText &staticText)
+ \fn void QPainter::drawStaticText(int left, int top, const QStaticText &staticText)
\since 4.7
\overload
- Draws the \a staticText at coordinates \a x and \a y.
+ Draws the \a staticText at coordinates \a left and \a top.
+
+ \note The y-position is used as the top of the font.
*/
/*!
@@ -5802,7 +5807,7 @@ void QPainter::drawText(const QPointF &p, const QString &str)
/*!
\since 4.7
- Draws the given \a staticText at the given \a position.
+ Draws the given \a staticText at the given \a topLeftPosition.
The text will be drawn using the font and the transformation set on the painter. If the
font and/or transformation set on the painter are different from the ones used to initialize
@@ -5810,15 +5815,17 @@ void QPainter::drawText(const QPointF &p, const QString &str)
QStaticText::prepare() to initialize \a staticText with the font and transformation with which
it will later be drawn.
- If \a position is not the same as when \a staticText was initialized, or when it was last drawn,
- then there will be a slight overhead when translating the text to its new position.
+ If \a topLeftPosition is not the same as when \a staticText was initialized, or when it was
+ last drawn, then there will be a slight overhead when translating the text to its new position.
- \note If the painter's transformation is not affine, then \a staticText will be drawn using regular
- calls to drawText(), losing any potential performance improvement.
+ \note If the painter's transformation is not affine, then \a staticText will be drawn using
+ regular calls to drawText(), losing any potential for performance improvement.
+
+ \note The y-position is used as the top of the font.
\sa QStaticText
*/
-void QPainter::drawStaticText(const QPointF &position, const QStaticText &staticText)
+void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText &staticText)
{
Q_D(QPainter);
if (!d->engine || staticText.text().isEmpty() || pen().style() == Qt::NoPen)
@@ -5830,13 +5837,13 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static
// If we don't have an extended paint engine, or if the painter is projected,
// we go through standard code path
if (d->extended == 0 || !d->state->matrix.isAffine()) {
- staticText_d->paintText(position, this);
+ staticText_d->paintText(topLeftPosition, this);
return;
}
// Don't recalculate entire layout because of translation, rather add the dx and dy
// into the position to move each text item the correct distance.
- QPointF transformedPosition = position * d->state->matrix;
+ QPointF transformedPosition = topLeftPosition * d->state->matrix;
QTransform matrix = d->state->matrix;
// The translation has been applied to transformedPosition. Remove translation
@@ -5863,14 +5870,6 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static
staticTextNeedsReinit = true;
}
- bool restoreWhenFinished = false;
- if (staticText_d->needsClipRect) {
- save();
- setClipRect(QRectF(position, staticText_d->maximumSize));
-
- restoreWhenFinished = true;
- }
-
if (font() != staticText_d->font) {
staticText_d->font = font();
staticTextNeedsReinit = true;
@@ -5910,9 +5909,6 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static
if (currentColor != oldPen.color())
setPen(oldPen);
- if (restoreWhenFinished)
- restore();
-
if (matrix.isTranslating())
d->state->matrix = matrix;
}