diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-05-21 01:45:41 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-05-21 01:45:41 (GMT) |
commit | 942ea5202d4a329376c27015b07406c2018437ff (patch) | |
tree | b8bd7f482458b2f65b5d8df63a0a2cb2825c1955 /src | |
parent | f6b9e75f3f7fd7bdef3855dd07ffdc9fa10b2dae (diff) | |
download | Qt-942ea5202d4a329376c27015b07406c2018437ff.zip Qt-942ea5202d4a329376c27015b07406c2018437ff.tar.gz Qt-942ea5202d4a329376c27015b07406c2018437ff.tar.bz2 |
Add a preserveSelection property to TextEdit.
This property will allow us to get line edit-like behavior, where the
selection is removed when the item loses focus.
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/fx/qfxtextedit.cpp | 22 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit.h | 4 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit_p.h | 3 |
3 files changed, 28 insertions, 1 deletions
diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index b2da051..f59e0ae 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -427,6 +427,8 @@ void QFxTextEdit::setCursorVisible(bool on) return; d->cursorVisible = on; QFocusEvent focusEvent(on ? QEvent::FocusIn : QEvent::FocusOut); + if (!on && !d->preserveSelection) + d->control->setCursorIsFocusIndicator(true); d->control->processEvent(&focusEvent, QPointF(0, 0)); } @@ -450,6 +452,26 @@ void QFxTextEdit::setFocusOnPress(bool on) d->focusOnPress = on; } +/*! + \qmlproperty bool TextEdit::preserveSelection + + Whether the TextEdit should keep the selection visible when it loses focus to another + item in the scene. By default this is set to true; +*/ +bool QFxTextEdit::preserveSelection() const +{ + Q_D(const QFxTextEdit); + return d->preserveSelection; +} + +void QFxTextEdit::setPreserveSelection(bool on) +{ + Q_D(QFxTextEdit); + if (d->preserveSelection == on) + return; + d->preserveSelection = on; +} + void QFxTextEdit::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h index d195a80..1456cd8 100644 --- a/src/declarative/fx/qfxtextedit.h +++ b/src/declarative/fx/qfxtextedit.h @@ -78,6 +78,7 @@ class Q_DECLARATIVE_EXPORT QFxTextEdit : public QFxPaintedItem Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) + Q_PROPERTY(bool preserveSelection READ preserveSelection WRITE setPreserveSelection) Q_CLASSINFO("DefaultProperty", "text") public: @@ -131,6 +132,9 @@ public: bool focusOnPress() const; void setFocusOnPress(bool on); + bool preserveSelection() const; + void setPreserveSelection(bool on); + virtual void dump(int depth); virtual QString propertyInfo() const; diff --git a/src/declarative/fx/qfxtextedit_p.h b/src/declarative/fx/qfxtextedit_p.h index a9b7237..78b0018 100644 --- a/src/declarative/fx/qfxtextedit_p.h +++ b/src/declarative/fx/qfxtextedit_p.h @@ -69,7 +69,7 @@ class QFxTextEditPrivate : public QFxPaintedItemPrivate public: QFxTextEditPrivate() : font(0), color("black"), imgDirty(true), hAlign(QFxTextEdit::AlignLeft), vAlign(QFxTextEdit::AlignTop), - dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(false), + dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(false), preserveSelection(true), format(QFxTextEdit::AutoText), document(0) { } @@ -98,6 +98,7 @@ public: bool richText; bool cursorVisible; bool focusOnPress; + bool preserveSelection; QFxTextEdit::TextFormat format; QTextDocument *document; QTextControl *control; |