aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-11-28 14:03:34 +1000
committerQt by Nokia <qt-info@nokia.com>2011-11-28 09:05:25 +0100
commitd0d12171b06d568bfcc7717471f4af5b877cfc1f (patch)
tree7f12c1e1731089b58ed1c7836b2a9b870d2e9669 /src
parentb4ad46cdce68eda6b0f22affa3ba128cc8426333 (diff)
Add a getFormattedText function to TextEdit.
The same as getText except it include formatting tags if the TextEdit has a rich text format set. Change-Id: I601e8d396254ab6105aa7d105e25b14fcf69c4e5 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/items/qquicktextedit.cpp30
-rw-r--r--src/declarative/items/qquicktextedit_p.h1
2 files changed, 31 insertions, 0 deletions
diff --git a/src/declarative/items/qquicktextedit.cpp b/src/declarative/items/qquicktextedit.cpp
index 1a467c5393..2e799200e6 100644
--- a/src/declarative/items/qquicktextedit.cpp
+++ b/src/declarative/items/qquicktextedit.cpp
@@ -1995,6 +1995,36 @@ QString QQuickTextEdit::getText(int start, int end) const
}
/*!
+ \qmlmethod string QtQuick2::TextEdit::getFormattedText(int start, int end)
+
+ Returns the section of text that is between the \a start and \a end positions.
+
+ The returned text will be formatted according the \l textFormat property.
+*/
+
+QString QQuickTextEdit::getFormattedText(int start, int end) const
+{
+ Q_D(const QQuickTextEdit);
+
+ start = qBound(0, start, d->document->characterCount() - 1);
+ end = qBound(0, end, d->document->characterCount() - 1);
+
+ QTextCursor cursor(d->document);
+ cursor.setPosition(start, QTextCursor::MoveAnchor);
+ cursor.setPosition(end, QTextCursor::KeepAnchor);
+
+ if (d->richText) {
+#ifndef QT_NO_TEXTHTMLPARSER
+ return cursor.selection().toHtml();
+#else
+ return cursor.selection().toPlainText();
+#endif
+ } else {
+ return cursor.selection().toPlainText();
+ }
+}
+
+/*!
\qmlmethod void QtQuick2::TextEdit::insert(int position, string text)
Inserts \a text into the TextEdit at position.
diff --git a/src/declarative/items/qquicktextedit_p.h b/src/declarative/items/qquicktextedit_p.h
index f2bec6ce4f..66b68ffd85 100644
--- a/src/declarative/items/qquicktextedit_p.h
+++ b/src/declarative/items/qquicktextedit_p.h
@@ -218,6 +218,7 @@ public:
bool isInputMethodComposing() const;
Q_INVOKABLE QString getText(int start, int end) const;
+ Q_INVOKABLE QString getFormattedText(int start, int end) const;
Q_SIGNALS:
void textChanged(const QString &);