From a9e08c091c822e65ae8453581c6fee4b94001682 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 1 Dec 2009 16:58:52 +0100 Subject: 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. --- src/gui/text/qstatictext.cpp | 23 +++++++++++++++++++++++ src/gui/text/qstatictext.h | 7 ++++++- 2 files changed, 29 insertions(+), 1 deletion(-) 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 #include + +#include #include -#include + 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; -- cgit v0.12