summaryrefslogtreecommitdiffstats
path: root/src/declarative/fx/qfxtextedit.cpp
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-07-08 02:49:52 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-07-08 02:49:52 (GMT)
commit69bf65348194ab339575aa0743832c1960e22962 (patch)
tree5c73baf07402e612331f5f24129f2149b7bb9794 /src/declarative/fx/qfxtextedit.cpp
parent131541866b374b90e04af75ec1382154c78b69b9 (diff)
downloadQt-69bf65348194ab339575aa0743832c1960e22962.zip
Qt-69bf65348194ab339575aa0743832c1960e22962.tar.gz
Qt-69bf65348194ab339575aa0743832c1960e22962.tar.bz2
Add Cursor Delegate to QFxTextEdit
Adds the cursorDelegate property, including docs and autotest. No example is included because we don't really have a text example yet.
Diffstat (limited to 'src/declarative/fx/qfxtextedit.cpp')
-rw-r--r--src/declarative/fx/qfxtextedit.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp
index 7162bdf..bfcc17f 100644
--- a/src/declarative/fx/qfxtextedit.cpp
+++ b/src/declarative/fx/qfxtextedit.cpp
@@ -454,6 +454,66 @@ void QFxTextEdit::setCursorPosition(int pos)
}
/*!
+ \qmlproperty TextEdit::cursorDelegate
+ \brief The delegate for the cursor in the TextEdit.
+
+ If you set a cursorDelegate for a TextEdit, this delegate will be used for
+ drawing the cursor instead of the standard cursor. An instance of the
+ delegate will be created and managed by the text edit when a cursor is
+ needed, and the x and y properties of delegate instance will be set so as
+ to be one pixel before the top left of the current character.
+
+ Note that the root item of the delegate component must be a QFxItem or
+ QFxItem derived item.
+*/
+QmlComponent* QFxTextEdit::cursorDelegate() const
+{
+ Q_D(const QFxTextEdit);
+ return d->cursorComponent;
+}
+
+void QFxTextEdit::setCursorDelegate(QmlComponent* c)
+{
+ Q_D(QFxTextEdit);
+ if(d->cursorComponent){
+ delete d->cursorComponent;
+ if(d->cursor){
+ disconnect(d->control, SIGNAL(cursorPositionChanged()),
+ this, SLOT(moveCursorDelegate()));
+ d->control->setCursorWidth(-1);
+ dirtyCache(cursorRect());
+ delete d->cursor;
+ d->cursor = 0;
+ }
+ }
+ d->cursorComponent = c;
+ if(c && c->isReady()){
+ loadCursorDelegate();
+ }else{
+ connect(c, SIGNAL(statusChanged()),
+ this, SLOT(loadCursorDelegate()));
+ }
+}
+
+void QFxTextEdit::loadCursorDelegate()
+{
+ Q_D(QFxTextEdit);
+ if(d->cursorComponent->isLoading())
+ return;
+ d->cursor = qobject_cast<QFxItem*>(d->cursorComponent->create(qmlContext(this)));
+ if(d->cursor){
+ connect(d->control, SIGNAL(cursorPositionChanged()),
+ this, SLOT(moveCursorDelegate()));
+ d->control->setCursorWidth(0);
+ dirtyCache(cursorRect());
+ d->cursor->setItemParent(this);
+ moveCursorDelegate();
+ }else{
+ qWarning() << "Error loading cursor delegate for TextEdit:" + objectName();
+ }
+}
+
+/*!
\qmlproperty bool TextEdit::focusOnPress
Whether the TextEdit should gain focus on a mouse press. By default this is
@@ -896,6 +956,16 @@ void QFxTextEdit::q_textChanged()
emit textChanged(text());
}
+void QFxTextEdit::moveCursorDelegate()
+{
+ Q_D(QFxTextEdit);
+ if(!d->cursor)
+ return;
+ QRectF cursorRect = d->control->cursorRect();
+ d->cursor->setX(cursorRect.x());
+ d->cursor->setY(cursorRect.y());
+}
+
//### we should perhaps be a bit smarter here -- depending on what has changed, we shouldn't
// need to do all the calculations each time
void QFxTextEdit::updateSize()