diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-07-06 23:38:31 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-07-06 23:38:31 (GMT) |
commit | 36018fb9de1d1943454d518fb4df1f8df41e67b5 (patch) | |
tree | 2a27edc461143a1b48be866f50279c703efb2e03 | |
parent | cc5a322cbfa9ae84a6114ef7c171d7e119e6a86c (diff) | |
download | Qt-36018fb9de1d1943454d518fb4df1f8df41e67b5.zip Qt-36018fb9de1d1943454d518fb4df1f8df41e67b5.tar.gz Qt-36018fb9de1d1943454d518fb4df1f8df41e67b5.tar.bz2 |
Add textFormat property to the Text element.
-rw-r--r-- | src/declarative/fx/qfxtext.cpp | 75 | ||||
-rw-r--r-- | src/declarative/fx/qfxtext.h | 8 | ||||
-rw-r--r-- | src/declarative/fx/qfxtext_p.h | 4 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit.cpp | 2 |
4 files changed, 85 insertions, 4 deletions
diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp index f2519dc..57897ed 100644 --- a/src/declarative/fx/qfxtext.cpp +++ b/src/declarative/fx/qfxtext.cpp @@ -162,7 +162,7 @@ void QFxText::setText(const QString &n) if (d->text == n) return; - d->richText = Qt::mightBeRichText(n); // ### what's the cost? + d->richText = d->format == RichText || (d->format == AutoText && Qt::mightBeRichText(n)); if (d->richText) { if (!d->doc) { @@ -170,7 +170,7 @@ void QFxText::setText(const QString &n) d->control->setTextInteractionFlags(Qt::TextBrowserInteraction); d->doc = d->control->document(); d->doc->setDocumentMargin(0); - } + } d->doc->setHtml(n); } @@ -377,6 +377,77 @@ void QFxText::setWrap(bool w) } /*! + \qmlproperty enumeration Text::textFormat + + The way the text property should be displayed. + + Supported text formats are \c AutoText, \c PlainText and \c RichText. + + The default is AutoText. If the text format is AutoText the text element + will automatically determine whether the text should be treated as + rich text. This determination is made using Qt::mightBeRichText(). + + \table + \row + \o + \qml +VerticalLayout { + TextEdit { + font.size: 24 + text: "<b>Hello</b> <i>World!</i>" + } + TextEdit { + font.size: 24 + textFormat: "RichText" + text: "<b>Hello</b> <i>World!</i>" + } + TextEdit { + font.size: 24 + textFormat: "PlainText" + text: "<b>Hello</b> <i>World!</i>" + } +} + \endqml + \o \image declarative-textformat.png + \endtable +*/ + +QFxText::TextFormat QFxText::textFormat() const +{ + Q_D(const QFxText); + return d->format; +} + +void QFxText::setTextFormat(TextFormat format) +{ + Q_D(QFxText); + if (format == d->format) + return; + bool wasRich = d->richText; + d->richText = format == RichText || (format == AutoText && Qt::mightBeRichText(d->text)); + + if (wasRich && !d->richText) { + //### delete control? (and vice-versa below) + d->imgDirty = true; + d->updateSize(); + update(); + } else if (!wasRich && d->richText) { + if (!d->doc) + { + d->control = new QTextControl(this); + d->control->setTextInteractionFlags(Qt::TextBrowserInteraction); + d->doc = d->control->document(); + d->doc->setDocumentMargin(0); + } + d->doc->setHtml(d->text); + d->imgDirty = true; + d->updateSize(); + update(); + } + d->format = format; +} + +/*! \qmlproperty Qt::TextElideMode Text::elide Set this property to elide parts of the text fit to the Text item's width. diff --git a/src/declarative/fx/qfxtext.h b/src/declarative/fx/qfxtext.h index ee38a94..bd91f0e 100644 --- a/src/declarative/fx/qfxtext.h +++ b/src/declarative/fx/qfxtext.h @@ -58,6 +58,7 @@ class Q_DECLARATIVE_EXPORT QFxText : public QFxItem Q_ENUMS(HAlignment) Q_ENUMS(VAlignment) Q_ENUMS(TextStyle) + Q_ENUMS(TextFormat) Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) Q_PROPERTY(QmlFont *font READ font CONSTANT) @@ -67,6 +68,7 @@ class Q_DECLARATIVE_EXPORT QFxText : public QFxItem Q_PROPERTY(HAlignment hAlign READ hAlign WRITE setHAlign) Q_PROPERTY(VAlignment vAlign READ vAlign WRITE setVAlign) Q_PROPERTY(bool wrap READ wrap WRITE setWrap) + Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) Q_PROPERTY(Qt::TextElideMode elide READ elideMode WRITE setElideMode) Q_PROPERTY(QString activeLink READ activeLink) Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform) @@ -85,6 +87,9 @@ public: Outline, Raised, Sunken }; + enum TextFormat { AutoText, + PlainText, + RichText }; QString text() const; void setText(const QString &); @@ -109,6 +114,9 @@ public: bool wrap() const; void setWrap(bool w); + TextFormat textFormat() const; + void setTextFormat(TextFormat format); + Qt::TextElideMode elideMode() const; void setElideMode(Qt::TextElideMode); diff --git a/src/declarative/fx/qfxtext_p.h b/src/declarative/fx/qfxtext_p.h index c58705c..670b685 100644 --- a/src/declarative/fx/qfxtext_p.h +++ b/src/declarative/fx/qfxtext_p.h @@ -75,7 +75,8 @@ public: QFxTextPrivate() : _font(0), color((QRgb)0), style(QFxText::Normal), imgDirty(true), hAlign(QFxText::AlignLeft), vAlign(QFxText::AlignTop), elideMode(Qt::ElideNone), - dirty(false), wrap(false), smooth(false), richText(false), singleline(false), control(0), doc(0) + dirty(false), wrap(false), smooth(false), richText(false), singleline(false), control(0), doc(0), + format(QFxText::AutoText) { } @@ -132,6 +133,7 @@ public: QTextDocument *doc; QTextLayout layout; QSize cachedLayoutSize; + QFxText::TextFormat format; }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index 3778e9a..7162bdf 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -179,7 +179,7 @@ void QFxTextEdit::setText(const QString &text) Supported text formats are \c AutoText, \c PlainText and \c RichText. The default is AutoText. If the text format is AutoText the text edit - edit will automatically determine whether the text should be treated as + will automatically determine whether the text should be treated as rich text. This determination is made using Qt::mightBeRichText(). \table |