summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qstatictext.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-15 14:13:44 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-15 14:13:44 (GMT)
commit3a205ce73d4f87ad499b09cc7a7eb43c61c26cf9 (patch)
treee067aaf496be3791ecb36407fb5db7a13d93fd73 /src/gui/text/qstatictext.cpp
parent9f387357a7e171636c97a7ef13afca60c01a9e3b (diff)
downloadQt-3a205ce73d4f87ad499b09cc7a7eb43c61c26cf9.zip
Qt-3a205ce73d4f87ad499b09cc7a7eb43c61c26cf9.tar.gz
Qt-3a205ce73d4f87ad499b09cc7a7eb43c61c26cf9.tar.bz2
Separate out textFormat property from setText() function and remove
isEmpty() function in QStaticText To make the return value of text() more intuitively clearer, and to make the API more readable, I've separated out the text format into a separate property. The isEmpty() function seemed out-of-place in the API, as suggested by reviews, so it has been removed.
Diffstat (limited to 'src/gui/text/qstatictext.cpp')
-rw-r--r--src/gui/text/qstatictext.cpp55
1 files changed, 35 insertions, 20 deletions
diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp
index 2fe23e5..6cf7022 100644
--- a/src/gui/text/qstatictext.cpp
+++ b/src/gui/text/qstatictext.cpp
@@ -212,26 +212,48 @@ bool QStaticText::operator!=(const QStaticText &other) const
}
/*!
- Sets the text of the QStaticText to \a text. If \a textFormat is set to Qt::AutoText
- (the default), the format of the text will try to be determined using the function
- Qt::mightBeRichText(). If the text format is Qt::PlainText, then the text will be displayed
- as is, whereas it will be interpreted as HTML if the format is Qt::RichText. HTML tags
- that alter the font of the text, its color, or its layout are supported by QStaticText.
+ Sets the text of the QStaticText to \a text.
\note This function will cause the layout of the text to be recalculated.
\sa text()
*/
-void QStaticText::setText(const QString &text, Qt::TextFormat textFormat)
+void QStaticText::setText(const QString &text)
{
detach();
data->text = text;
- data->preferRichText = (textFormat == Qt::RichText
- || (textFormat == Qt::AutoText && Qt::mightBeRichText(text)));
data->init();
}
/*!
+ Sets the text format of the QStaticText to \a textFormat. If \a textFormat is set to
+ Qt::AutoText (the default), the format of the text will try to be determined using the
+ function Qt::mightBeRichText(). If the text format is Qt::PlainText, then the text will be
+ displayed as is, whereas it will be interpreted as HTML if the format is Qt::RichText. HTML tags
+ that alter the font of the text, its color, or its layout are supported by QStaticText.
+
+ \note This function will cause the layout of the text to be recalculated.
+
+ \sa textFormat(), setText(), text()
+*/
+void QStaticText::setTextFormat(Qt::TextFormat textFormat)
+{
+ detach();
+ data->textFormat = textFormat;
+ data->init();
+}
+
+/*!
+ Returns the text format of the QStaticText.
+
+ \sa setTextFormat(), setText(), text()
+*/
+Qt::TextFormat QStaticText::textFormat() const
+{
+ return Qt::TextFormat(data->textFormat);
+}
+
+/*!
Returns the text of the QStaticText.
\sa setText()
@@ -313,19 +335,9 @@ QSizeF QStaticText::size() const
return data->actualSize;
}
-/*!
- Returns true if the text of the QStaticText is empty, and false if not.
-
- \sa text()
-*/
-bool QStaticText::isEmpty() const
-{
- return data->text.isEmpty();
-}
-
QStaticTextPrivate::QStaticTextPrivate()
: items(0), itemCount(0), glyphPool(0), positionPool(0), needsClipRect(false),
- useBackendOptimizations(false)
+ useBackendOptimizations(false), textFormat(Qt::AutoText)
{
ref = 1;
}
@@ -333,7 +345,7 @@ QStaticTextPrivate::QStaticTextPrivate()
QStaticTextPrivate::QStaticTextPrivate(const QStaticTextPrivate &other)
: text(other.text), font(other.font), maximumSize(other.maximumSize), matrix(other.matrix),
items(0), itemCount(0), glyphPool(0), positionPool(0), needsClipRect(false),
- useBackendOptimizations(false)
+ useBackendOptimizations(false), textFormat(other.textFormat)
{
ref = 1;
}
@@ -509,6 +521,9 @@ namespace {
void QStaticTextPrivate::paintText(QPainter *p)
{
+ bool preferRichText = textFormat == Qt::RichText
+ || (textFormat == Qt::AutoText && Qt::mightBeRichText(text));
+
if (!preferRichText) {
if (maximumSize.isValid()) {
QRectF boundingRect;