aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/items/items.pri2
-rw-r--r--src/quick/items/qquicktextedit.cpp63
-rw-r--r--src/quick/items/qquicktextedit_p.h4
-rw-r--r--src/quick/items/qquicktextedit_p_p.h14
-rw-r--r--src/quick/items/qquicktextinput.cpp79
-rw-r--r--src/quick/items/qquicktextinput_p.h2
-rw-r--r--src/quick/items/qquicktextinput_p_p.h9
-rw-r--r--src/quick/items/qquicktextutil.cpp81
-rw-r--r--src/quick/items/qquicktextutil_p.h126
-rw-r--r--tests/auto/quick/qquicktextedit/data/http/cursorHttpTest.qml4
-rw-r--r--tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail1.qml3
-rw-r--r--tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail2.qml3
-rw-r--r--tests/auto/quick/qquicktextedit/data/http/cursorHttpTestPass.qml2
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp7
-rw-r--r--tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp9
15 files changed, 291 insertions, 117 deletions
diff --git a/src/quick/items/items.pri b/src/quick/items/items.pri
index b8b4e1104c..4f22b32837 100644
--- a/src/quick/items/items.pri
+++ b/src/quick/items/items.pri
@@ -23,6 +23,7 @@ HEADERS += \
$$PWD/qquicktextcontrol_p_p.h \
$$PWD/qquicktextedit_p.h \
$$PWD/qquicktextedit_p_p.h \
+ $$PWD/qquicktextutil_p.h \
$$PWD/qquickimagebase_p.h \
$$PWD/qquickimagebase_p_p.h \
$$PWD/qquickimage_p.h \
@@ -91,6 +92,7 @@ SOURCES += \
$$PWD/qquicktextinput.cpp \
$$PWD/qquicktextcontrol.cpp \
$$PWD/qquicktextedit.cpp \
+ $$PWD/qquicktextutil.cpp \
$$PWD/qquickimagebase.cpp \
$$PWD/qquickimage.cpp \
$$PWD/qquickborderimage.cpp \
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp
index de0cf7ccee..cfb07f019b 100644
--- a/src/quick/items/qquicktextedit.cpp
+++ b/src/quick/items/qquicktextedit.cpp
@@ -46,6 +46,7 @@
#include "qquickevents_p_p.h"
#include "qquickcanvas.h"
#include "qquicktextnode_p.h"
+#include "qquicktextutil_p.h"
#include <QtQuick/qsgsimplerectnode.h>
#include <QtQml/qqmlinfo.h>
@@ -60,6 +61,7 @@
#include <private/qtextengine_p.h>
#include <private/qsgadaptationlayer_p.h>
+
QT_BEGIN_NAMESPACE
/*!
@@ -360,8 +362,8 @@ void QQuickTextEdit::setFont(const QFont &font)
if (oldFont != d->font) {
d->document->setDefaultFont(d->font);
- if (d->cursor) {
- d->cursor->setHeight(QFontMetrics(d->font).height());
+ if (d->cursorItem) {
+ d->cursorItem->setHeight(QFontMetrics(d->font).height());
moveCursorDelegate();
}
updateSize();
@@ -890,6 +892,8 @@ void QQuickTextEdit::setCursorVisible(bool on)
if (d->cursorVisible == on)
return;
d->cursorVisible = on;
+ if (on && isComponentComplete())
+ QQuickTextUtil::createCursor(d);
if (!on && !d->persistentSelection)
d->control->setCursorIsFocusIndicator(true);
d->control->setCursorVisible(on);
@@ -941,45 +945,14 @@ QQmlComponent* QQuickTextEdit::cursorDelegate() const
void QQuickTextEdit::setCursorDelegate(QQmlComponent* c)
{
Q_D(QQuickTextEdit);
- if (d->cursorComponent) {
- if (d->cursor) {
- d->control->setCursorWidth(-1);
- updateCursor();
- delete d->cursor;
- d->cursor = 0;
- }
- }
- d->cursorComponent = c;
- if (c && c->isReady()) {
- loadCursorDelegate();
- } else {
- if (c)
- connect(c, SIGNAL(statusChanged()),
- this, SLOT(loadCursorDelegate()));
- }
-
- emit cursorDelegateChanged();
+ QQuickTextUtil::setCursorDelegate(d, c);
}
-void QQuickTextEdit::loadCursorDelegate()
+void QQuickTextEdit::createCursor()
{
Q_D(QQuickTextEdit);
- if (d->cursorComponent->isLoading() || !isComponentComplete())
- return;
- QQmlContext *creationContext = d->cursorComponent->creationContext();
- QObject *object = d->cursorComponent->create(creationContext ? creationContext : qmlContext(this));
- d->cursor = qobject_cast<QQuickItem*>(object);
- if (d->cursor) {
- d->control->setCursorWidth(0);
- updateCursor();
- QQml_setParent_noEvent(d->cursor, this);
- d->cursor->setParentItem(this);
- d->cursor->setHeight(QFontMetrics(d->font).height());
- moveCursorDelegate();
- }else{
- delete object;
- qmlInfo(this) << "Error loading cursor delegate.";
- }
+ d->cursorPending = true;
+ QQuickTextUtil::createCursor(d);
}
/*!
@@ -1187,8 +1160,8 @@ void QQuickTextEdit::componentComplete()
updateSize();
d->dirty = false;
}
- if (d->cursorComponent && d->cursorComponent->isReady())
- loadCursorDelegate();
+ if (d->cursorComponent && isCursorVisible())
+ QQuickTextUtil::createCursor(d);
}
/*!
\qmlproperty bool QtQuick2::TextEdit::selectByMouse
@@ -1818,11 +1791,11 @@ void QQuickTextEdit::moveCursorDelegate()
d->determineHorizontalAlignment();
updateInputMethod();
emit cursorRectangleChanged();
- if (!d->cursor)
+ if (!d->cursorItem)
return;
QRectF cursorRect = cursorRectangle();
- d->cursor->setX(cursorRect.x());
- d->cursor->setY(cursorRect.y());
+ d->cursorItem->setX(cursorRect.x());
+ d->cursorItem->setY(cursorRect.y());
}
void QQuickTextEdit::updateSelectionMarkers()
@@ -1843,7 +1816,7 @@ QRectF QQuickTextEdit::boundingRect() const
Q_D(const QQuickTextEdit);
QRectF r(0, -d->yoff, d->contentSize.width(), d->contentSize.height());
int cursorWidth = 1;
- if (d->cursor)
+ if (d->cursorItem)
cursorWidth = 0;
else if (!d->document->isEmpty())
cursorWidth += 3;// ### Need a better way of accounting for space between char and cursor
@@ -1885,8 +1858,8 @@ QRectF QQuickTextEdit::clipRect() const
Q_D(const QQuickTextEdit);
QRectF r = QQuickImplicitSizeItem::clipRect();
int cursorWidth = 1;
- if (d->cursor)
- cursorWidth = d->cursor->width();
+ if (d->cursorItem)
+ cursorWidth = d->cursorItem->width();
if (!d->document->isEmpty())
cursorWidth += 3;// ### Need a better way of accounting for space between char and cursor
diff --git a/src/quick/items/qquicktextedit_p.h b/src/quick/items/qquicktextedit_p.h
index 9f904cae67..48954cc7d6 100644
--- a/src/quick/items/qquicktextedit_p.h
+++ b/src/quick/items/qquicktextedit_p.h
@@ -290,7 +290,7 @@ private Q_SLOTS:
void q_textChanged();
void updateSelectionMarkers();
void moveCursorDelegate();
- void loadCursorDelegate();
+ void createCursor();
void q_canPasteChanged();
void updateDocument();
void updateCursor();
@@ -320,6 +320,8 @@ protected:
QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData);
+ friend class QQuickTextUtil;
+
private:
Q_DISABLE_COPY(QQuickTextEdit)
Q_DECLARE_PRIVATE(QQuickTextEdit)
diff --git a/src/quick/items/qquicktextedit_p_p.h b/src/quick/items/qquicktextedit_p_p.h
index e556367bcf..1fb82110ea 100644
--- a/src/quick/items/qquicktextedit_p_p.h
+++ b/src/quick/items/qquicktextedit_p_p.h
@@ -55,6 +55,7 @@
#include "qquicktextedit_p.h"
#include "qquickimplicitsizeitem_p_p.h"
+#include "qquicktextcontrol_p.h"
#include <QtQml/qqml.h>
@@ -64,19 +65,21 @@ class QQuickTextDocumentWithImageResources;
class QQuickTextControl;
class QQuickTextEditPrivate : public QQuickImplicitSizeItemPrivate
{
+public:
Q_DECLARE_PUBLIC(QQuickTextEdit)
-public:
+ typedef QQuickTextEdit Public;
+
QQuickTextEditPrivate()
: color(QRgb(0xFF000000)), selectionColor(QRgb(0xFF000080)), selectedTextColor(QRgb(0xFFFFFFFF))
- , textMargin(0.0), yoff(0), font(sourceFont), cursorComponent(0), cursor(0), document(0), control(0)
+ , textMargin(0.0), yoff(0), font(sourceFont), cursorComponent(0), cursorItem(0), document(0), control(0)
, lastSelectionStart(0), lastSelectionEnd(0), lineCount(0)
, hAlign(QQuickTextEdit::AlignLeft), vAlign(QQuickTextEdit::AlignTop)
, format(QQuickTextEdit::PlainText), wrapMode(QQuickTextEdit::NoWrap)
, contentDirection(Qt::LayoutDirectionAuto)
, mouseSelectionMode(QQuickTextEdit::SelectCharacters), inputMethodHints(Qt::ImhNone)
, updateType(UpdatePaintNode)
- , documentDirty(true), dirty(false), richText(false), cursorVisible(false)
+ , documentDirty(true), dirty(false), richText(false), cursorVisible(false), cursorPending(false)
, focusOnPress(true), persistentSelection(false), requireImplicitWidth(false)
, selectByMouse(false), canPaste(false), canPasteValid(false), hAlignImplicit(true)
, textCached(false), inLayout(false)
@@ -96,6 +99,8 @@ public:
qreal getImplicitWidth() const;
Qt::LayoutDirection textDirection(const QString &text) const;
+ void setNativeCursorEnabled(bool enabled) { control->setCursorWidth(enabled ? 1 : 0); }
+
QColor color;
QColor selectionColor;
QColor selectedTextColor;
@@ -111,7 +116,7 @@ public:
QFont font;
QQmlComponent* cursorComponent;
- QQuickItem* cursor;
+ QQuickItem* cursorItem;
QQuickTextDocumentWithImageResources *document;
QQuickTextControl *control;
@@ -138,6 +143,7 @@ public:
bool dirty : 1;
bool richText : 1;
bool cursorVisible : 1;
+ bool cursorPending : 1;
bool focusOnPress : 1;
bool persistentSelection : 1;
bool requireImplicitWidth:1;
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp
index e2199347e7..3e92568db3 100644
--- a/src/quick/items/qquicktextinput.cpp
+++ b/src/quick/items/qquicktextinput.cpp
@@ -42,9 +42,11 @@
#include "qquicktextinput_p.h"
#include "qquicktextinput_p_p.h"
#include "qquickcanvas.h"
+#include "qquicktextutil_p.h"
#include <private/qqmlglobal_p.h>
+
#include <QtCore/qcoreapplication.h>
#include <QtQml/qqmlinfo.h>
#include <QtGui/qevent.h>
@@ -102,8 +104,8 @@ void QQuickTextInput::componentComplete()
d->checkIsValid();
d->updateLayout();
updateCursorRectangle();
- if (d->cursorComponent && d->cursorComponent->isReady())
- createCursor();
+ if (d->cursorComponent && isCursorVisible())
+ QQuickTextUtil::createCursor(d);
}
/*!
@@ -669,9 +671,13 @@ void QQuickTextInput::setCursorVisible(bool on)
if (d->cursorVisible == on)
return;
d->cursorVisible = on;
- d->setCursorBlinkPeriod(on ? qApp->styleHints()->cursorFlashTime() : 0);
- d->updateType = QQuickTextInputPrivate::UpdatePaintNode;
- update();
+ if (on && isComponentComplete())
+ QQuickTextUtil::createCursor(d);
+ if (!d->cursorItem) {
+ d->setCursorBlinkPeriod(on ? qApp->styleHints()->cursorFlashTime() : 0);
+ d->updateType = QQuickTextInputPrivate::UpdatePaintNode;
+ update();
+ }
emit cursorVisibleChanged(d->cursorVisible);
}
@@ -1247,65 +1253,14 @@ QQmlComponent* QQuickTextInput::cursorDelegate() const
void QQuickTextInput::setCursorDelegate(QQmlComponent* c)
{
Q_D(QQuickTextInput);
- if (d->cursorComponent == c)
- return;
-
- d->cursorComponent = c;
- if (!c) {
- //note that the components are owned by something else
- delete d->cursorItem;
- d->cursorItem = 0;
- } else {
- d->startCreatingCursor();
- }
-
- emit cursorDelegateChanged();
-}
-
-void QQuickTextInputPrivate::startCreatingCursor()
-{
- Q_Q(QQuickTextInput);
- if (cursorComponent->isReady()) {
- q->createCursor();
- } else if (cursorComponent->isLoading()) {
- q->connect(cursorComponent, SIGNAL(statusChanged(int)),
- q, SLOT(createCursor()));
- } else { // isError
- qmlInfo(q, cursorComponent->errors()) << QQuickTextInput::tr("Could not load cursor delegate");
- }
+ QQuickTextUtil::setCursorDelegate(d, c);
}
void QQuickTextInput::createCursor()
{
Q_D(QQuickTextInput);
- if (!isComponentComplete())
- return;
-
- if (d->cursorComponent->isError()) {
- qmlInfo(this, d->cursorComponent->errors()) << tr("Could not load cursor delegate");
- return;
- }
-
- if (!d->cursorComponent->isReady())
- return;
-
- if (d->cursorItem)
- delete d->cursorItem;
- QQmlContext *creationContext = d->cursorComponent->creationContext();
- QObject *object = d->cursorComponent->create(creationContext ? creationContext : qmlContext(this));
- d->cursorItem = qobject_cast<QQuickItem*>(object);
- if (!d->cursorItem) {
- delete object;
- qmlInfo(this, d->cursorComponent->errors()) << tr("Could not instantiate cursor delegate");
- return;
- }
-
- QRectF r = cursorRectangle();
-
- QQml_setParent_noEvent(d->cursorItem, this);
- d->cursorItem->setParentItem(this);
- d->cursorItem->setPos(r.topLeft());
- d->cursorItem->setHeight(r.height());
+ d->cursorPending = true;
+ QQuickTextUtil::createCursor(d);
}
/*!
@@ -3189,10 +3144,9 @@ void QQuickTextInputPrivate::processInputMethodEvent(QInputMethodEvent *event)
m_textLayout.setPreeditArea(m_cursor, event->preeditString());
#endif //QT_NO_IM
const int oldPreeditCursor = m_preeditCursor;
- const bool oldCursorVisible = cursorVisible;
m_preeditCursor = event->preeditString().length();
hasImState = !event->preeditString().isEmpty();
- cursorVisible = true;
+ bool cursorVisible = true;
QList<QTextLayout::FormatRange> formats;
for (int i = 0; i < event->attributes().size(); ++i) {
const QInputMethodEvent::Attribute &a = event->attributes().at(i);
@@ -3224,8 +3178,7 @@ void QQuickTextInputPrivate::processInputMethodEvent(QInputMethodEvent *event)
if (isGettingInput)
finishChange(priorState);
- if (cursorVisible != oldCursorVisible)
- emit q->cursorVisibleChanged(cursorVisible);
+ q->setCursorVisible(cursorVisible);
if (selectionChange) {
emit q->selectionChanged();
diff --git a/src/quick/items/qquicktextinput_p.h b/src/quick/items/qquicktextinput_p.h
index 9a3be0f116..a7b07898e8 100644
--- a/src/quick/items/qquicktextinput_p.h
+++ b/src/quick/items/qquicktextinput_p.h
@@ -344,6 +344,8 @@ private Q_SLOTS:
void triggerPreprocess();
private:
+ friend class QQuickTextUtil;
+
Q_DECLARE_PRIVATE(QQuickTextInput)
};
diff --git a/src/quick/items/qquicktextinput_p_p.h b/src/quick/items/qquicktextinput_p_p.h
index 34aa0726d3..2648af160d 100644
--- a/src/quick/items/qquicktextinput_p_p.h
+++ b/src/quick/items/qquicktextinput_p_p.h
@@ -74,8 +74,11 @@ class QQuickTextNode;
class Q_AUTOTEST_EXPORT QQuickTextInputPrivate : public QQuickImplicitSizeItemPrivate
{
- Q_DECLARE_PUBLIC(QQuickTextInput)
public:
+ Q_DECLARE_PUBLIC(QQuickTextInput)
+
+ typedef QQuickTextInput Public;
+
QQuickTextInputPrivate()
: hscroll(0)
, vscroll(0)
@@ -105,6 +108,7 @@ public:
, m_passwordCharacter(QLatin1Char('*'))
, focusOnPress(true)
, cursorVisible(false)
+ , cursorPending(false)
, autoScroll(true)
, selectByMouse(false)
, canPaste(false)
@@ -235,6 +239,7 @@ public:
bool focusOnPress:1;
bool cursorVisible:1;
+ bool cursorPending:1;
bool autoScroll:1;
bool selectByMouse:1;
bool canPaste:1;
@@ -265,6 +270,8 @@ public:
return !tripleClickTimer.hasExpired(qApp->styleHints()->mouseDoubleClickInterval());
}
+ void setNativeCursorEnabled(bool enabled) {
+ setCursorBlinkPeriod(enabled && cursorVisible ? qApp->styleHints()->cursorFlashTime() : 0); }
int nextMaskBlank(int pos)
{
diff --git a/src/quick/items/qquicktextutil.cpp b/src/quick/items/qquicktextutil.cpp
new file mode 100644
index 0000000000..c2c11b3daa
--- /dev/null
+++ b/src/quick/items/qquicktextutil.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquicktextutil_p.h"
+
+#include <QtQml/qqmlinfo.h>
+
+#include <private/qqmlglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QQuickItem *QQuickTextUtil::createCursor(
+ QQmlComponent *component, QQuickItem *parent, const QRectF &rectangle, const char *className)
+{
+ QQuickItem *item = 0;
+ if (component->isReady()) {
+ QQmlContext *creationContext = component->creationContext();
+
+ if (QObject *object = component->beginCreate(creationContext
+ ? creationContext
+ : qmlContext(parent))) {
+ if ((item = qobject_cast<QQuickItem *>(object))) {
+ QQml_setParent_noEvent(item, parent);
+ item->setParentItem(parent);
+ item->setPos(rectangle.topLeft());
+ item->setHeight(rectangle.height());
+ } else {
+ qmlInfo(parent) << tr("%1 does not support loading non-visual cursor delegates.")
+ .arg(QString::fromUtf8(className));
+ }
+ component->completeCreate();
+ return item;
+ }
+ } else if (component->isLoading()) {
+ QObject::connect(component, SIGNAL(statusChanged(QQmlComponent::Status)),
+ parent, SLOT(createCursor()), Qt::UniqueConnection);
+ return item;
+ }
+ qmlInfo(parent, component->errors()) << tr("Could not load cursor delegate");
+ return item;
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/items/qquicktextutil_p.h b/src/quick/items/qquicktextutil_p.h
new file mode 100644
index 0000000000..91ef40b221
--- /dev/null
+++ b/src/quick/items/qquicktextutil_p.h
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKTEXTUTIL_P_H
+#define QQUICKTEXTUTIL_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQml/qqml.h>
+#include <QtQml/qqmlincubator.h>
+#include <QtQuick/qquickitem.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickTextUtil : public QObject // For the benefit of translations.
+{
+ Q_OBJECT
+public:
+ template <typename Private> static void setCursorDelegate(Private *d, QQmlComponent *delegate);
+ template <typename Private> static void createCursor(Private *d);
+
+private:
+ static QQuickItem *createCursor(
+ QQmlComponent *component,
+ QQuickItem *parent,
+ const QRectF &cursorRectangle,
+ const char *className);
+};
+
+template <typename Private>
+void QQuickTextUtil::setCursorDelegate(Private *d, QQmlComponent *delegate)
+{
+ if (d->cursorComponent == delegate)
+ return;
+
+ typename Private::Public *parent = d->q_func();
+
+ if (d->cursorComponent) {
+ disconnect(d->cursorComponent, SIGNAL(statusChanged(QQmlComponent::Status)),
+ parent, SLOT(createCursor()));
+ }
+
+ delete d->cursorItem;
+ d->cursorItem = 0;
+ d->cursorPending = true;
+
+ d->cursorComponent = delegate;
+
+ if (parent->isCursorVisible() && parent->isComponentComplete())
+ createCursor(d);
+
+ emit parent->cursorDelegateChanged();
+}
+
+template <typename Private>
+void QQuickTextUtil::createCursor(Private *d)
+{
+ if (!d->cursorPending)
+ return;
+
+ d->cursorPending = false;
+
+ typename Private::Public *parent = d->q_func();
+ if (d->cursorComponent) {
+ d->cursorItem = createCursor(
+ d->cursorComponent,
+ parent,
+ parent->cursorRectangle(),
+ Private::Public::staticMetaObject.className());
+ }
+
+ d->setNativeCursorEnabled(!d->cursorItem);
+ d->updateType = Private::UpdatePaintNode;
+ parent->update();
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTest.qml b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTest.qml
index be4526e22b..043304d027 100644
--- a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTest.qml
+++ b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTest.qml
@@ -9,14 +9,18 @@ Rectangle { width: 300; height: 300; color: "white"
]
TextEdit {
cursorDelegate: cursorFail
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorWait
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorNorm
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorErr
+ cursorVisible: true
}
}
diff --git a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail1.qml b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail1.qml
index 1d7763f913..a6556454fe 100644
--- a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail1.qml
+++ b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail1.qml
@@ -8,11 +8,14 @@ Rectangle { width: 300; height: 300; color: "white"
]
TextEdit {
cursorDelegate: cursorFail
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorWait
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorNorm
+ cursorVisible: true
}
}
diff --git a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail2.qml b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail2.qml
index c82ec02e68..9429779a87 100644
--- a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail2.qml
+++ b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestFail2.qml
@@ -8,11 +8,14 @@ Rectangle { width: 300; height: 300; color: "white"
]
TextEdit {
cursorDelegate: cursorWait
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorNorm
+ cursorVisible: true
}
TextEdit {
cursorDelegate: cursorErr
+ cursorVisible: true
}
}
diff --git a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestPass.qml b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestPass.qml
index 96d582c95d..69e498ef8d 100644
--- a/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestPass.qml
+++ b/tests/auto/quick/qquicktextedit/data/http/cursorHttpTestPass.qml
@@ -8,10 +8,12 @@ Rectangle { width: 300; height: 300; color: "white"
TextEdit {
cursorDelegate: cursorWait
text: "Hello"
+ cursorVisible: true
}
TextEdit {
objectName: "textEditObject"
cursorDelegate: cursorNorm
+ cursorVisible: true
focus: true;
text: "Hello"
}
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index 1b21fcc2b4..c7bf6af6ee 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -1952,9 +1952,12 @@ void tst_qquicktextedit::cursorDelegate()
view.requestActivateWindow();
QQuickTextEdit *textEditObject = view.rootObject()->findChild<QQuickTextEdit*>("textEditObject");
QVERIFY(textEditObject != 0);
- QVERIFY(textEditObject->findChild<QQuickItem*>("cursorInstance"));
+ // Delegate creation is deferred until focus in or cursor visiblity is forced.
+ QVERIFY(!textEditObject->findChild<QQuickItem*>("cursorInstance"));
+ QVERIFY(!textEditObject->isCursorVisible());
//Test Delegate gets created
textEditObject->setFocus(true);
+ QVERIFY(textEditObject->isCursorVisible());
QQuickItem* delegateObject = textEditObject->findChild<QQuickItem*>("cursorInstance");
QVERIFY(delegateObject);
QCOMPARE(delegateObject->property("localProperty").toString(), QString("Hello"));
@@ -2716,6 +2719,7 @@ void tst_qquicktextedit::clipRect()
cursorComponent.setData("import QtQuick 2.0\nRectangle { height: 20; width: 8 }", QUrl());
edit->setCursorDelegate(&cursorComponent);
+ edit->setCursorVisible(true);
// If a cursor delegate is used it's size should determine the excess width.
QCOMPARE(edit->clipRect().x(), qreal(0));
@@ -2797,6 +2801,7 @@ void tst_qquicktextedit::boundingRect()
cursorComponent.setData("import QtQuick 2.0\nRectangle { height: 20; width: 8 }", QUrl());
edit->setCursorDelegate(&cursorComponent);
+ edit->setCursorVisible(true);
// Don't include the size of a cursor delegate as it has its own bounding rect.
QCOMPARE(edit->boundingRect().x(), qreal(0));
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
index e80808badf..5397b6ce9f 100644
--- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
+++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
@@ -1509,6 +1509,7 @@ void tst_qquicktextinput::clipRect()
cursorComponent.setData("import QtQuick 2.0\nRectangle { height: 20; width: 8 }", QUrl());
input->setCursorDelegate(&cursorComponent);
+ input->setCursorVisible(true);
// If a cursor delegate is used it's size should determine the excess width.
QCOMPARE(input->clipRect().x(), qreal(0));
@@ -1596,6 +1597,7 @@ void tst_qquicktextinput::boundingRect()
cursorComponent.setData("import QtQuick 2.0\nRectangle { height: 20; width: 8 }", QUrl());
input->setCursorDelegate(&cursorComponent);
+ input->setCursorVisible(true);
// Don't include the size of a cursor delegate as it has its own bounding rect.
QCOMPARE(input->boundingRect().x(), input->width() - line.naturalTextWidth());
@@ -2481,9 +2483,13 @@ void tst_qquicktextinput::cursorDelegate()
view.requestActivateWindow();
QQuickTextInput *textInputObject = view.rootObject()->findChild<QQuickTextInput*>("textInputObject");
QVERIFY(textInputObject != 0);
- QVERIFY(textInputObject->findChild<QQuickItem*>("cursorInstance"));
+ // Delegate is created on demand, and so won't be available immediately. Focus in or
+ // setCursorVisible(true) will trigger creation.
+ QTRY_VERIFY(!textInputObject->findChild<QQuickItem*>("cursorInstance"));
+ QVERIFY(!textInputObject->isCursorVisible());
//Test Delegate gets created
textInputObject->setFocus(true);
+ QVERIFY(textInputObject->isCursorVisible());
QQuickItem* delegateObject = textInputObject->findChild<QQuickItem*>("cursorInstance");
QVERIFY(delegateObject);
QCOMPARE(delegateObject->property("localProperty").toString(), QString("Hello"));
@@ -2497,7 +2503,6 @@ void tst_qquicktextinput::cursorDelegate()
QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x());
QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y());
-
// Test delegate gets moved on mouse press.
textInputObject->setSelectByMouse(true);
textInputObject->setCursorPosition(0);