diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-05 15:16:16 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-05 15:18:04 (GMT) |
commit | 3d89703be18d13cc4a571ce875cff3ec6cca498f (patch) | |
tree | 8226680122ad651ec8eac1d44e2da3193f5f3df9 /src/gui | |
parent | 88b1aa6b3c0e03107db111921ef69de814f1dc06 (diff) | |
download | Qt-3d89703be18d13cc4a571ce875cff3ec6cca498f.zip Qt-3d89703be18d13cc4a571ce875cff3ec6cca498f.tar.gz Qt-3d89703be18d13cc4a571ce875cff3ec6cca498f.tar.bz2 |
Temporarily remove QPainter::drawStaticText() for Qt 4.6.x integration
We can't add new symbols to QPainter for Qt 4.6.x, as we would not be
able to remove them again if we regretted the API. Hence, I've made
removable symbols instead, a private global function and a
drawStaticText() in QPainterPrivate. In order to tie things together,
I needed a static private-getter in QPainterPrivate, and hence it
had to be a friend of QPainter.
Reviewed-by: Trond
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/painting/qpaintbuffer.cpp | 2 | ||||
-rw-r--r-- | src/gui/painting/qpainter.cpp | 87 | ||||
-rw-r--r-- | src/gui/painting/qpainter.h | 16 | ||||
-rw-r--r-- | src/gui/painting/qpainter_p.h | 6 | ||||
-rw-r--r-- | src/gui/text/qstatictext.cpp | 82 | ||||
-rw-r--r-- | src/gui/text/qstatictext_p.h | 2 | ||||
-rw-r--r-- | src/gui/text/qstatictext_p_p.h | 1 |
7 files changed, 91 insertions, 105 deletions
diff --git a/src/gui/painting/qpaintbuffer.cpp b/src/gui/painting/qpaintbuffer.cpp index 632dea7..51eb681 100644 --- a/src/gui/painting/qpaintbuffer.cpp +++ b/src/gui/painting/qpaintbuffer.cpp @@ -1448,7 +1448,7 @@ void QPainterReplayer::process(const QPaintBufferCommand &cmd) QStaticText text(variants.at(0).value<QStaticText>()); painter->setFont(font); - painter->drawStaticText(QPointF(0, 0), text); + qt_draw_static_text(painter, QPointF(0, 0), text); break; } diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 4338a5f..0d47260 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -5707,36 +5707,23 @@ void QPainter::drawText(const QPointF &p, const QString &str) drawText(p, str, 0, 0); } -/*! - \fn void QPainter::drawStaticText(const QPoint &position, const QStaticText &staticText) - - \internal - - \overload -*/ - -/*! - \fn void QPainter::drawStaticText(int x, int y, const QStaticText &staticText) - - \internal - - \overload -*/ - -/*! - Draws the given \a staticText beginning at the given \a position. +QPainterPrivate *QPainterPrivate::get(QPainter *p) +{ + return p->d_ptr.data(); +} - \internal +void qt_draw_static_text(QPainter *p, const QPointF &position, const QStaticText &text) +{ + QPainterPrivate *prv = QPainterPrivate::get(p); + Q_ASSERT(prv != 0); - This function can be used to optimize drawing text if the text and its layout is updated - seldomly. + prv->drawStaticText(position, text); +} - \sa QStaticText -*/ -void QPainter::drawStaticText(const QPointF &position, const QStaticText &staticText) +void QPainterPrivate::drawStaticText(const QPointF &position, const QStaticText &staticText) { - Q_D(QPainter); - if (!d->engine || staticText.isEmpty() || pen().style() == Qt::NoPen) + Q_Q(QPainter); + if (!engine || staticText.isEmpty() || q->pen().style() == Qt::NoPen) return; QStaticTextPrivate *staticText_d = @@ -5744,31 +5731,31 @@ 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()) { + if (extended == 0 || !state->matrix.isAffine()) { if (staticText_d->size.isValid()) - drawText(QRectF(position, staticText_d->size), staticText_d->text); + q->drawText(QRectF(position, staticText_d->size), staticText_d->text); else - drawText(position, staticText_d->text); + q->drawText(position, staticText_d->text); 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; - QTransform matrix = d->state->matrix; + QPointF transformedPosition = position * state->matrix; + QTransform matrix = state->matrix; // The translation has been applied to transformedPosition. Remove translation // component from matrix. - if (d->state->matrix.isTranslating()) { - qreal m11 = d->state->matrix.m11(); - qreal m12 = d->state->matrix.m12(); - qreal m13 = d->state->matrix.m13(); - qreal m21 = d->state->matrix.m21(); - qreal m22 = d->state->matrix.m22(); - qreal m23 = d->state->matrix.m23(); - qreal m33 = d->state->matrix.m33(); - - d->state->matrix.setMatrix(m11, m12, m13, + if (state->matrix.isTranslating()) { + qreal m11 = state->matrix.m11(); + qreal m12 = state->matrix.m12(); + qreal m13 = state->matrix.m13(); + qreal m21 = state->matrix.m21(); + qreal m22 = state->matrix.m22(); + qreal m23 = state->matrix.m23(); + qreal m33 = state->matrix.m33(); + + state->matrix.setMatrix(m11, m12, m13, m21, m22, m23, 0.0, 0.0, m33); } @@ -5776,21 +5763,21 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static // If the transform is not identical to the text transform, // we have to relayout the text (for other transformations than plain translation) bool staticTextNeedsReinit = false; - if (staticText_d->matrix != d->state->matrix) { - staticText_d->matrix = d->state->matrix; + if (staticText_d->matrix != state->matrix) { + staticText_d->matrix = state->matrix; staticTextNeedsReinit = true; } bool restoreWhenFinished = false; if (staticText_d->needsClipRect) { - save(); - setClipRect(QRectF(position, staticText_d->size)); + q->save(); + q->setClipRect(QRectF(position, staticText_d->size)); restoreWhenFinished = true; } - if (font() != staticText_d->font) { - staticText_d->font = font(); + if (q->font() != staticText_d->font) { + staticText_d->font = q->font(); staticTextNeedsReinit = true; } @@ -5817,14 +5804,14 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static for (int i=0; i<staticText_d->itemCount; ++i) { QStaticTextItem *item = staticText_d->items + i; - d->extended->drawStaticTextItem(item); + extended->drawStaticTextItem(item); } if (restoreWhenFinished) - restore(); + q->restore(); if (matrix.isTranslating()) - d->state->matrix = matrix; + state->matrix = matrix; } /*! diff --git a/src/gui/painting/qpainter.h b/src/gui/painting/qpainter.h index 181eba7..088a973 100644 --- a/src/gui/painting/qpainter.h +++ b/src/gui/painting/qpainter.h @@ -78,7 +78,6 @@ class QPolygon; class QTextItem; class QMatrix; class QTransform; -class QStaticText; class QPainterPrivateDeleter; @@ -370,10 +369,6 @@ public: void setLayoutDirection(Qt::LayoutDirection direction); Qt::LayoutDirection layoutDirection() const; - inline void drawStaticText(int x, int y, const QStaticText &staticText); - inline void drawStaticText(const QPoint &p, const QStaticText &staticText); - void drawStaticText(const QPointF &p, const QStaticText &staticText); - void drawText(const QPointF &p, const QString &s); inline void drawText(const QPoint &p, const QString &s); inline void drawText(int x, int y, const QString &s); @@ -527,6 +522,7 @@ private: friend class QRasterPaintEngine; friend class QAlphaPaintEngine; friend class QPreviewPaintEngine; + friend class QPainterPrivate; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QPainter::RenderHints) @@ -911,16 +907,6 @@ inline void QPainter::drawText(const QPoint &p, const QString &s) drawText(QPointF(p), s); } -inline void QPainter::drawStaticText(const QPoint &p, const QStaticText &staticText) -{ - drawStaticText(QPointF(p), staticText); -} - -inline void QPainter::drawStaticText(int x, int y, const QStaticText &staticText) -{ - drawStaticText(QPointF(x, y), staticText); -} - inline void QPainter::drawText(int x, int y, int w, int h, int flags, const QString &str, QRect *br) { drawText(QRect(x, y, w, h), flags, str, br); diff --git a/src/gui/painting/qpainter_p.h b/src/gui/painting/qpainter_p.h index 02a91aa..2979de6 100644 --- a/src/gui/painting/qpainter_p.h +++ b/src/gui/painting/qpainter_p.h @@ -70,6 +70,7 @@ QT_BEGIN_NAMESPACE class QPaintEngine; class QEmulationPaintEngine; class QPaintEngineEx; +class QStaticText; struct QTLWExtra; @@ -229,6 +230,8 @@ public: void drawStretchedGradient(const QPainterPath &path, DrawOperation operation); void drawOpaqueBackground(const QPainterPath &path, DrawOperation operation); + void drawStaticText(const QPointF &position, const QStaticText &staticText); + void updateMatrix(); void updateInvMatrix(); @@ -242,6 +245,8 @@ public: static bool attachPainterPrivate(QPainter *q, QPaintDevice *pdev); void detachPainterPrivate(QPainter *q); + static QPainterPrivate *get(QPainter *p); + QPaintDevice *device; QPaintDevice *original_device; QPaintDevice *helper_device; @@ -252,6 +257,7 @@ public: }; Q_GUI_EXPORT void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation); +Q_GUI_EXPORT void qt_draw_static_text(QPainter *p, const QPointF &position, const QStaticText &text); QString qt_generate_brush_key(const QBrush &brush); diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index 922920e..659324b 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -113,8 +113,8 @@ QT_BEGIN_NAMESPACE /*! Constructs an empty QStaticText */ -QStaticText::QStaticText() - : d_ptr(new QStaticTextPrivate) +QStaticText::QStaticText() + : data(new QStaticTextPrivate) { } @@ -126,11 +126,11 @@ QStaticText::QStaticText() the text will be unbounded. */ QStaticText::QStaticText(const QString &text, const QSizeF &size) - : d_ptr(new QStaticTextPrivate) + : data(new QStaticTextPrivate) { - d_ptr->text = text; - d_ptr->size = size; - d_ptr->init(); + data->text = text; + data->size = size; + data->init(); } /*! @@ -138,26 +138,24 @@ QStaticText::QStaticText(const QString &text, const QSizeF &size) */ QStaticText::QStaticText(const QStaticText &other) { - d_ptr = other.d_ptr; - d_ptr->ref.ref(); + data = other.data; } /*! Destroys the QStaticText. */ QStaticText::~QStaticText() -{ - if (!d_ptr->ref.deref()) - delete d_ptr; +{ + Q_ASSERT(!data || data->ref >= 1); } /*! \internal */ void QStaticText::detach() -{ - if (d_ptr->ref != 1) - qAtomicDetach(d_ptr); +{ + if (data->ref != 1) + data.detach(); } /*! @@ -177,9 +175,9 @@ void QStaticText::detach() */ void QStaticText::prepare(const QTransform &matrix, const QFont &font) { - d_ptr->matrix = matrix; - d_ptr->font = font; - d_ptr->init(); + data->matrix = matrix; + data->font = font; + data->init(); } @@ -187,8 +185,8 @@ void QStaticText::prepare(const QTransform &matrix, const QFont &font) Assigns \a other to this QStaticText. */ QStaticText &QStaticText::operator=(const QStaticText &other) -{ - qAtomicAssign(d_ptr, other.d_ptr); +{ + data = other.data; return *this; } @@ -198,10 +196,10 @@ QStaticText &QStaticText::operator=(const QStaticText &other) */ bool QStaticText::operator==(const QStaticText &other) const { - return (d_ptr == other.d_ptr - || (d_ptr->text == other.d_ptr->text - && d_ptr->font == other.d_ptr->font - && d_ptr->size == other.d_ptr->size)); + return (data == other.data + || (data->text == other.data->text + && data->font == other.data->font + && data->size == other.data->size)); } /*! @@ -223,8 +221,8 @@ bool QStaticText::operator!=(const QStaticText &other) const void QStaticText::setText(const QString &text) { detach(); - d_ptr->text = text; - d_ptr->init(); + data->text = text; + data->init(); } /*! @@ -234,7 +232,7 @@ void QStaticText::setText(const QString &text) */ QString QStaticText::text() const { - return d_ptr->text; + return data->text; } /*! @@ -255,13 +253,13 @@ QString QStaticText::text() const */ void QStaticText::setUseBackendOptimizations(bool on) { - if ((!on && !d_ptr->useBackendOptimizations) - || (on && d_ptr->useBackendOptimizations)) + if ((!on && !data->useBackendOptimizations) + || (on && data->useBackendOptimizations)) return; detach(); - d_ptr->useBackendOptimizations = on; - d_ptr->init(); + data->useBackendOptimizations = on; + data->init(); } /*! @@ -272,7 +270,7 @@ void QStaticText::setUseBackendOptimizations(bool on) */ bool QStaticText::useBackendOptimizations() const { - return d_ptr->useBackendOptimizations; + return data->useBackendOptimizations; } /*! @@ -285,8 +283,8 @@ bool QStaticText::useBackendOptimizations() const void QStaticText::setMaximumSize(const QSizeF &size) { detach(); - d_ptr->size = size; - d_ptr->init(); + data->size = size; + data->init(); } /*! @@ -296,7 +294,7 @@ void QStaticText::setMaximumSize(const QSizeF &size) */ QSizeF QStaticText::maximumSize() const { - return d_ptr->size; + return data->size; } /*! @@ -306,15 +304,24 @@ QSizeF QStaticText::maximumSize() const */ bool QStaticText::isEmpty() const { - return d_ptr->text.isEmpty(); + return data->text.isEmpty(); } QStaticTextPrivate::QStaticTextPrivate() - : items(0), itemCount(0), glyphPool(0), positionPool(0), needsClipRect(false) + : items(0), itemCount(0), glyphPool(0), positionPool(0), needsClipRect(false), + useBackendOptimizations(false) { ref = 1; } +QStaticTextPrivate::QStaticTextPrivate(const QStaticTextPrivate &other) + : text(other.text), font(other.font), size(other.size), matrix(other.matrix), + items(0), itemCount(0), glyphPool(0), positionPool(0), needsClipRect(false), + useBackendOptimizations(false) +{ + ref = 1; +} + QStaticTextPrivate::~QStaticTextPrivate() { delete[] items; @@ -324,10 +331,9 @@ QStaticTextPrivate::~QStaticTextPrivate() QStaticTextPrivate *QStaticTextPrivate::get(const QStaticText *q) { - return q->d_ptr; + return q->data.data(); } - extern int qt_defaultDpiX(); extern int qt_defaultDpiY(); diff --git a/src/gui/text/qstatictext_p.h b/src/gui/text/qstatictext_p.h index b07383e..a19fb6c 100644 --- a/src/gui/text/qstatictext_p.h +++ b/src/gui/text/qstatictext_p.h @@ -96,7 +96,7 @@ public: private: void detach(); - QStaticTextPrivate *d_ptr; + QExplicitlySharedDataPointer<QStaticTextPrivate> data; friend class QStaticTextPrivate; }; diff --git a/src/gui/text/qstatictext_p_p.h b/src/gui/text/qstatictext_p_p.h index bca59e0..72c8439 100644 --- a/src/gui/text/qstatictext_p_p.h +++ b/src/gui/text/qstatictext_p_p.h @@ -110,6 +110,7 @@ class Q_AUTOTEST_EXPORT QStaticTextPrivate { public: QStaticTextPrivate(); + QStaticTextPrivate(const QStaticTextPrivate &other); ~QStaticTextPrivate(); void init(); |