aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurugappan Nataraj <murugappan.nataraj@nokia.com>2010-10-11 19:09:46 +0530
committerPekka Vuorela <pekka.ta.vuorela@nokia.com>2010-10-18 16:09:43 +0300
commit2b4ff2998a0ee474dd60377119dc913174b6e791 (patch)
tree5da4e6c3c1d6de5452a72614610616a9f81d8e21
parent3bd08c500526ef8dbd1210bee6828c47fc38bafa (diff)
Changes: Implementation of Set/Get APIs in Rich Text Edit
RevBy : Pekka Vuorela Details: Implemented the set/Get APIs in MRichTextEdit to provide facility to set and get the rich text content.
-rwxr-xr-xsrc/corelib/widgets/mrichtextedit.cpp50
-rw-r--r--src/corelib/widgets/mrichtextedit.h14
-rwxr-xr-xsrc/corelib/widgets/mtextedit.cpp24
-rwxr-xr-xsrc/corelib/widgets/mtextedit_p.h2
4 files changed, 82 insertions, 8 deletions
diff --git a/src/corelib/widgets/mrichtextedit.cpp b/src/corelib/widgets/mrichtextedit.cpp
index 97012b6e..d955f2a2 100755
--- a/src/corelib/widgets/mrichtextedit.cpp
+++ b/src/corelib/widgets/mrichtextedit.cpp
@@ -204,6 +204,56 @@ void MRichTextEdit::cut()
}
+bool MRichTextEdit::setHtml(const QString &text)
+{
+ Q_D(MRichTextEdit);
+
+ int cursorPosBefore = d->cursor()->position();
+ bool wasSelecting = hasSelectedText();
+ bool wasEmpty = (document()->characterCount() == 0);
+
+ // clear the state
+ d->removePreedit();
+ d->preeditStyling.clear();
+ d->cursor()->clearSelection();
+ document()->clear();
+ d->setMode(MTextEditModel::EditModeBasic);
+
+ //set cursor to the start again
+ d->cursor()->movePosition(QTextCursor::Start);
+
+ d->cursor()->insertHtml(text);
+
+ bool accepted = d->validate();
+
+ if (!accepted) {
+ document()->clear();
+ }
+
+ // only avoid signaling if empty before and after
+ if (!((document()->characterCount() == 0) && wasEmpty)) {
+ d->updateMicroFocus();
+ emit textChanged();
+ }
+
+ if (d->cursor()->position() != cursorPosBefore) {
+ emit cursorPositionChanged();
+ }
+
+ if (wasSelecting) {
+ d->sendCopyAvailable(false);
+ }
+
+ return accepted;
+}
+
+
+QString MRichTextEdit::toHtml() const
+{
+ return document()->toHtml();
+}
+
+
void MRichTextEdit::setFontUnderline(bool underline)
{
Q_D(MRichTextEdit);
diff --git a/src/corelib/widgets/mrichtextedit.h b/src/corelib/widgets/mrichtextedit.h
index d1f12d74..2d4506b0 100644
--- a/src/corelib/widgets/mrichtextedit.h
+++ b/src/corelib/widgets/mrichtextedit.h
@@ -59,6 +59,20 @@ public:
/*! \reimp_end */
/*!
+ * \brief Sets html text for this widget. This replaces the existing text.
+ * \param text New html text for this text edit widget.
+ * \return false if \a text is not allowed to be set.
+ * On successful insertion, the cursor is moved to the end of the text
+ */
+ bool setHtml(const QString &text);
+
+ /*!
+ * \brief Returns current text in html format
+ * \return QString containing current widget text in html format
+ */
+ QString toHtml() const;
+
+ /*!
* \brief sets the Underline style and apply the style to the current selection if any
*/
void setFontUnderline(bool underline);
diff --git a/src/corelib/widgets/mtextedit.cpp b/src/corelib/widgets/mtextedit.cpp
index b94897a2..d16e3cce 100755
--- a/src/corelib/widgets/mtextedit.cpp
+++ b/src/corelib/widgets/mtextedit.cpp
@@ -624,6 +624,21 @@ bool MTextEditPrivate::doTextInsert(const QString &text, bool usePreeditStyling)
}
+bool MTextEditPrivate::validate()
+{
+ Q_Q(MTextEdit);
+
+ if (validator == 0) {
+ return true;
+ } else {
+ QString textCopy = q->model()->document()->toPlainText();
+ int cursorCopy = q->model()->cursor()->position();
+ QValidator::State result = validator->validate(textCopy, cursorCopy);
+ return (result != QValidator::Invalid);
+ }
+}
+
+
bool MTextEditPrivate::validateCurrentBlock()
{
if (validator == 0) {
@@ -1773,14 +1788,7 @@ bool MTextEdit::setText(const QString &text)
d->cursor()->insertText(filteredText);
- bool accepted = true;
-
- if (d->validator) {
- QString textCopy = text;
- int cursorPos = text.length();
- QValidator::State result = d->validator->validate(textCopy, cursorPos);
- accepted = (result != QValidator::Invalid);
- }
+ bool accepted = d->validate();
if (!accepted) {
document()->clear();
diff --git a/src/corelib/widgets/mtextedit_p.h b/src/corelib/widgets/mtextedit_p.h
index 276acbbe..b1d13e4b 100755
--- a/src/corelib/widgets/mtextedit_p.h
+++ b/src/corelib/widgets/mtextedit_p.h
@@ -60,6 +60,8 @@ public:
bool validateCurrentBlock();
+ bool validate();
+
bool setCursorPosition(int index);
void setPreeditText(const QString &text,