summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/fx/qfxtext.cpp75
-rw-r--r--src/declarative/fx/qfxtext.h8
-rw-r--r--src/declarative/fx/qfxtext_p.h4
-rw-r--r--src/declarative/fx/qfxtextedit.cpp23
-rw-r--r--src/declarative/fx/qfxtextedit.h4
5 files changed, 109 insertions, 5 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 7f08fba..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
@@ -410,7 +410,7 @@ void QFxTextEdit::setWrap(bool w)
}
/*!
- \property QFxTextEdit::cursorVisible
+ \qmlproperty TextEdit::cursorVisible
\brief If true the text edit shows a cursor.
This property is set and unset when the text edit gets focus, but it can also
@@ -435,6 +435,25 @@ void QFxTextEdit::setCursorVisible(bool on)
}
/*!
+ \qmlproperty TextEdit::cursorPosition
+ \brief The position of the cursor in the TextEdit.
+*/
+int QFxTextEdit::cursorPosition() const
+{
+ Q_D(const QFxTextEdit);
+ return d->control->textCursor().position();
+}
+
+void QFxTextEdit::setCursorPosition(int pos)
+{
+ Q_D(QFxTextEdit);
+ QTextCursor cursor = d->control->textCursor();
+ if (cursor.position() == pos)
+ return;
+ cursor.setPosition(pos);
+}
+
+/*!
\qmlproperty bool TextEdit::focusOnPress
Whether the TextEdit should gain focus on a mouse press. By default this is
diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h
index 24ba3fe..6988822 100644
--- a/src/declarative/fx/qfxtextedit.h
+++ b/src/declarative/fx/qfxtextedit.h
@@ -77,6 +77,7 @@ class Q_DECLARATIVE_EXPORT QFxTextEdit : public QFxPaintedItem
Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat)
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible)
+ Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition)
Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress)
Q_PROPERTY(bool preserveSelection READ preserveSelection WRITE setPreserveSelection)
Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin)
@@ -129,6 +130,9 @@ public:
bool isCursorVisible() const;
void setCursorVisible(bool on);
+ int cursorPosition() const;
+ void setCursorPosition(int pos);
+
bool focusOnPress() const;
void setFocusOnPress(bool on);