summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2010-02-16 13:19:18 (GMT)
committerJason McDonald <jason.mcdonald@nokia.com>2010-02-16 13:19:18 (GMT)
commit1f2ca350bc963a2d3b5e3a5de095f6f2d269ea00 (patch)
treeee4464abd73fe51143aa40a1cceed3ed20102d33 /src/gui/text
parent5998a03ffbf0257f8cf86d732f06475da875047d (diff)
parente4e92b74980c4f601d080e1e072b556b7318c915 (diff)
downloadQt-1f2ca350bc963a2d3b5e3a5de095f6f2d269ea00.zip
Qt-1f2ca350bc963a2d3b5e3a5de095f6f2d269ea00.tar.gz
Qt-1f2ca350bc963a2d3b5e3a5de095f6f2d269ea00.tar.bz2
Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-2
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qstatictext.cpp75
-rw-r--r--src/gui/text/qstatictext.h9
2 files changed, 50 insertions, 34 deletions
diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp
index 1ff3b24..623ee54 100644
--- a/src/gui/text/qstatictext.cpp
+++ b/src/gui/text/qstatictext.cpp
@@ -50,7 +50,6 @@ QT_BEGIN_NAMESPACE
/*!
\class QStaticText
- \internal
\brief The QStaticText class enables optimized drawing of text when the text and its layout
is updated rarely.
\since 4.7
@@ -63,11 +62,13 @@ QT_BEGIN_NAMESPACE
more efficiently than by using QPainter::drawText() in which the layout information is
recalculated with every call.
- The class primarily provides an optimization for cases where text and the transformations on
- the painter are static over several paint events. If the text or its layout is changed
- regularly, QPainter::drawText() is the more efficient alternative. Translating the painter
- will not cause the layout of the text to be recalculated, but will cause a very small
- performance impact on drawStaticText(). Altering any other parts of the painter's
+ The class primarily provides an optimization for cases where the text, its font and the
+ transformations on the painter are static over several paint events. If the text or its layout
+ is changed for every iteration, QPainter::drawText() is the more efficient alternative, since
+ the static text's layout would have to be recalculated to take the new state into consideration.
+
+ Translating the painter will not cause the layout of the text to be recalculated, but will cause
+ a very small performance impact on drawStaticText(). Altering any other parts of the painter's
transformation or the painter's font will cause the layout of the static text to be
recalculated. This should be avoided as often as possible to maximize the performance
benefit of using QStaticText.
@@ -107,10 +108,29 @@ QT_BEGIN_NAMESPACE
passed to QPainter::drawStaticText() and can change from call to call with a minimal impact
on performance.
+ QStaticText will attempt to guess the format of the input text using Qt::mightBeRichText().
+ To force QStaticText to display its contents as either plain text or rich text, use the
+ function QStaticText::setTextFormat() and pass in, respectively, Qt::PlainText and
+ Qt::RichText.
+
\sa QPainter::drawText(), QPainter::drawStaticText(), QTextLayout, QTextDocument
*/
/*!
+ \enum QStaticText::PerformanceHint
+
+ This enum the different performance hints that can be set on the QStaticText. These hints
+ can be used to indicate that the QStaticText should use additional caches, if possible,
+ to improve performance at the expense of memory. In particular, setting the performance hint
+ AggressiveCaching on the QStaticText will improve performance when using the OpenGL graphics
+ system or when drawing to a QGLWidget.
+
+ \value ModerateCaching Do basic caching for high performance at a low memory cost.
+ \value AggressiveCaching Use additional caching when available. This may improve performance
+ at a higher memory cost.
+*/
+
+/*!
Constructs an empty QStaticText
*/
QStaticText::QStaticText()
@@ -119,11 +139,9 @@ QStaticText::QStaticText()
}
/*!
- \fn QStaticText::QStaticText(const QString &text, const QFont &font, const QSizeF &maximumSize)
+ Constructs a QStaticText object with the given \a text and bounded by the given \a size.
- Constructs a QStaticText object with the given \a text which is to be rendered in the given
- \a font and bounded by the given \a maximumSize. If an invalid size is passed for \a maximumSize
- the text will be unbounded.
+ If an invalid size is passed for \a size the text will be unbounded.
*/
QStaticText::QStaticText(const QString &text, const QSizeF &size)
: data(new QStaticTextPrivate)
@@ -264,49 +282,42 @@ QString QStaticText::text() const
}
/*!
- Sets whether the QStaticText object should use optimizations specific to the paint engine
- backend if they are available. If \a on is set to true, backend optimizations will be turned
- on, otherwise they will be turned off. The default value is false.
-
- If backend optimizations are on, the paint engine used to draw the static text is allowed to
- store data in the object which will assist it in future calls to drawStaticText. In particular,
- when using the opengl graphics system, or when painting on a QGLWidget, turning this flag on will
- improve performance, but increase the memory footprint of the QStaticText object.
+ Sets the performance hint of the QStaticText. This hint can be used to customize how much
+ caching is done internally to improve performance.
- The default value is false.
+ The default is QStaticText::ModerateCaching.
\note This function will cause the layout of the text to be recalculated.
- \sa useBackendOptimizations()
+ \sa performanceHint()
*/
-void QStaticText::setUseBackendOptimizations(bool on)
+void QStaticText::setPerformanceHint(PerformanceHint performanceHint)
{
- if ((!on && !data->useBackendOptimizations)
- || (on && data->useBackendOptimizations))
+ if ((performanceHint == ModerateCaching && !data->useBackendOptimizations)
+ || (performanceHint == AggressiveCaching && data->useBackendOptimizations)) {
return;
-
+ }
detach();
- data->useBackendOptimizations = on;
+ data->useBackendOptimizations = (performanceHint == AggressiveCaching);
data->init();
}
/*!
- Returns whether the QStaticText object should use optimizations specific to the paint engine
- backend when possible. By default this setting is false.
+ Returns which performance hint is set for the QStaticText.
- \sa setUseBackendOptimizations()
+ \sa setPerformanceHint()
*/
-bool QStaticText::useBackendOptimizations() const
+QStaticText::PerformanceHint QStaticText::performanceHint() const
{
- return data->useBackendOptimizations;
+ return data->useBackendOptimizations ? AggressiveCaching : ModerateCaching;
}
/*!
- Sets the maximum size of the QStaticText to \a maximumSize.
+ Sets the maximum size of the QStaticText to \a size.
\note This function will cause the layout of the text to be recalculated.
- \sa maximumSize()
+ \sa maximumSize(), size()
*/
void QStaticText::setMaximumSize(const QSizeF &size)
{
diff --git a/src/gui/text/qstatictext.h b/src/gui/text/qstatictext.h
index a1c1bf5..1e59944 100644
--- a/src/gui/text/qstatictext.h
+++ b/src/gui/text/qstatictext.h
@@ -60,6 +60,11 @@ class QStaticTextPrivate;
class Q_GUI_EXPORT QStaticText
{
public:
+ enum PerformanceHint {
+ ModerateCaching,
+ AggressiveCaching
+ };
+
QStaticText();
QStaticText(const QString &text, const QSizeF &maximumSize = QSizeF());
QStaticText(const QStaticText &other);
@@ -78,8 +83,8 @@ public:
void prepare(const QTransform &matrix, const QFont &font);
- void setUseBackendOptimizations(bool on);
- bool useBackendOptimizations() const;
+ void setPerformanceHint(PerformanceHint performanceHint);
+ PerformanceHint performanceHint() const;
QStaticText &operator=(const QStaticText &);
bool operator==(const QStaticText &) const;