diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2009-12-01 15:58:52 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-01-14 13:07:02 (GMT) |
commit | a9e08c091c822e65ae8453581c6fee4b94001682 (patch) | |
tree | b70020d3bf195989a730e668a315543d3ed18aa1 /src | |
parent | 378c08e56110b2a57c0112e5bfb189e28cc8e88f (diff) | |
download | Qt-a9e08c091c822e65ae8453581c6fee4b94001682.zip Qt-a9e08c091c822e65ae8453581c6fee4b94001682.tar.gz Qt-a9e08c091c822e65ae8453581c6fee4b94001682.tar.bz2 |
Add prepare() function to QStaticText
Allow the QStaticText layout to be completely defined prior to painting
by introducing a function for setting the font and transform on the
object ahead of using it with a QPainter.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qstatictext.cpp | 23 | ||||
-rw-r--r-- | src/gui/text/qstatictext.h | 7 |
2 files changed, 29 insertions, 1 deletions
diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index 56950ed..9a0ddca 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -152,6 +152,29 @@ void QStaticText::detach() } /*! + Prepares the QStaticText object for being painted with the given \a matrix and the given + \a font to avoid overhead when the actual drawStaticText() call is made. + + When drawStaticText() is called, the layout of the QStaticText will be recalculated if the + painter's font or matrix is different from the one used for the currently cached layout. By + default, QStaticText will use a default constructed QFont and an identity matrix to create + its layout. + + To avoid the overhead of creating the layout the first time you draw the QStaticText with + a painter whose matrix or font are different from the defaults, you can use the prepare() + function and pass in the matrix and font you expect to use when drawing the text. + + \sa QPainter::setFont(), QPainter::setMatrix() +*/ +void QStaticText::prepare(const QTransform &matrix, const QFont &font) +{ + d_ptr->matrix = matrix; + d_ptr->font = font; + d_ptr->init(); +} + + +/*! Assigns \a other to this QStaticText. */ QStaticText &QStaticText::operator=(const QStaticText &other) diff --git a/src/gui/text/qstatictext.h b/src/gui/text/qstatictext.h index c7b5429..e507d82 100644 --- a/src/gui/text/qstatictext.h +++ b/src/gui/text/qstatictext.h @@ -42,9 +42,12 @@ #ifndef QSTATICTEXT_H #define QSTATICTEXT_H +#include <QtCore/qsize.h> #include <QtCore/qstring.h> + +#include <QtGui/qtransform.h> #include <QtGui/qfont.h> -#include <QtCore/qsize.h> + QT_BEGIN_HEADER @@ -67,6 +70,8 @@ public: void setMaximumSize(const QSizeF &maximumSize); QSizeF maximumSize() const; + void prepare(const QTransform &matrix, const QFont &font); + QStaticText &operator=(const QStaticText &); bool operator==(const QStaticText &) const; bool operator!=(const QStaticText &) const; |