diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-15 14:13:44 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-15 14:13:44 (GMT) |
commit | 3a205ce73d4f87ad499b09cc7a7eb43c61c26cf9 (patch) | |
tree | e067aaf496be3791ecb36407fb5db7a13d93fd73 /src/gui/text | |
parent | 9f387357a7e171636c97a7ef13afca60c01a9e3b (diff) | |
download | Qt-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')
-rw-r--r-- | src/gui/text/qstatictext.cpp | 55 | ||||
-rw-r--r-- | src/gui/text/qstatictext.h | 7 | ||||
-rw-r--r-- | src/gui/text/qstatictext_p.h | 2 |
3 files changed, 40 insertions, 24 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; diff --git a/src/gui/text/qstatictext.h b/src/gui/text/qstatictext.h index 7498ad4..8eeb068 100644 --- a/src/gui/text/qstatictext.h +++ b/src/gui/text/qstatictext.h @@ -65,9 +65,12 @@ public: QStaticText(const QStaticText &other); ~QStaticText(); - void setText(const QString &text, Qt::TextFormat textFormat = Qt::AutoText); + void setText(const QString &text); QString text() const; + void setTextFormat(Qt::TextFormat textFormat); + Qt::TextFormat textFormat() const; + void setMaximumSize(const QSizeF &maximumSize); QSizeF maximumSize() const; @@ -82,8 +85,6 @@ public: bool operator==(const QStaticText &) const; bool operator!=(const QStaticText &) const; - bool isEmpty() const; - private: void detach(); diff --git a/src/gui/text/qstatictext_p.h b/src/gui/text/qstatictext_p.h index 7aee5c4..95bd286 100644 --- a/src/gui/text/qstatictext_p.h +++ b/src/gui/text/qstatictext_p.h @@ -133,7 +133,7 @@ public: char needsClipRect : 1; // 1 byte per text char useBackendOptimizations : 1; - char preferRichText : 1; + char textFormat : 2; // ================ // 171 bytes per text |