summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/painting/qpainter.cpp2
-rw-r--r--src/gui/text/qstatictext.cpp55
-rw-r--r--src/gui/text/qstatictext.h7
-rw-r--r--src/gui/text/qstatictext_p.h2
4 files changed, 41 insertions, 25 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index 2b5a0c5..e26a24d 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -5736,7 +5736,7 @@ void QPainter::drawText(const QPointF &p, const QString &str)
void QPainter::drawStaticText(const QPointF &position, const QStaticText &staticText)
{
Q_D(QPainter);
- if (!d->engine || staticText.isEmpty() || pen().style() == Qt::NoPen)
+ if (!d->engine || staticText.text().isEmpty() || pen().style() == Qt::NoPen)
return;
QStaticTextPrivate *staticText_d =
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