Improves feature parity with TextEdit.
Task-number: QTBUG-16355
Change-Id: I3919c71454a4f4574a1ee35ad38969459beb8363
Reviewed-by: Martin Jones <martin.jones@nokia.com>
{
Q_Q(QQuickTextControl);
emit q->updateRequest(q->selectionRect());
+ hasFocus = e->gotFocus();
if (e->gotFocus()) {
setBlinkingCursorEnabled(interactionFlags & (Qt::TextEditable | Qt::TextSelectableByKeyboard));
} else {
&& e->reason() != Qt::PopupFocusReason
&& cursor.hasSelection()) {
cursor.clearSelection();
+ emit q->selectionChanged();
}
}
- hasFocus = e->gotFocus();
}
QString QQuickTextControlPrivate::anchorForCursor(const QTextCursor &anchorCursor) const
control->setView(q);
control->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::TextSelectableByKeyboard | Qt::TextEditable);
control->setAcceptRichText(false);
+ control->setCursorIsFocusIndicator(true);
// QQuickTextControl follows the default text color
// defined by the platform, declarative text
QQuickTextEditPrivate()
: color("black"), hAlign(QQuickTextEdit::AlignLeft), vAlign(QQuickTextEdit::AlignTop),
documentDirty(true), dirty(false), richText(false), cursorVisible(false), focusOnPress(true),
- persistentSelection(true), requireImplicitWidth(false), selectByMouse(false), canPaste(false),
+ persistentSelection(false), requireImplicitWidth(false), selectByMouse(false), canPaste(false),
canPasteValid(false), hAlignImplicit(true), rightToLeftText(false), useImageFallback(false),
textCached(false),
textMargin(0.0), lastSelectionStart(0), lastSelectionEnd(0), cursorComponent(0), cursor(0),
}
/*!
+ \qmlproperty bool QtQuick2::TextInput::persistentSelection
+
+ Whether the TextInput should keep its selection when it loses active focus to another
+ item in the scene. By default this is set to false;
+*/
+
+bool QQuickTextInput::persistentSelection() const
+{
+ Q_D(const QQuickTextInput);
+ return d->persistentSelection;
+}
+
+void QQuickTextInput::setPersistentSelection(bool on)
+{
+ Q_D(QQuickTextInput);
+ if (d->persistentSelection == on)
+ return;
+ d->persistentSelection = on;
+ emit persistentSelectionChanged();
+}
+
+/*!
\qmlproperty bool QtQuick2::TextInput::canPaste
Returns true if the TextInput is writable and the content of the clipboard is
if (!hasFocus) {
d->commitPreedit();
- d->deselect();
+ if (!d->persistentSelection)
+ d->deselect();
disconnect(qApp->inputPanel(), SIGNAL(inputDirectionChanged(Qt::LayoutDirection)),
this, SLOT(q_updateAlignment()));
} else {
Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
+ Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged)
Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged)
SelectionMode mouseSelectionMode() const;
void setMouseSelectionMode(SelectionMode mode);
+ bool persistentSelection() const;
+ void setPersistentSelection(bool persist);
+
bool hasAcceptableInput() const;
QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
void autoScrollChanged(bool autoScroll);
void selectByMouseChanged(bool selectByMouse);
void mouseSelectionModeChanged(SelectionMode mode);
+ void persistentSelectionChanged();
void canPasteChanged();
void canUndoChanged();
void canRedoChanged();
, hAlignImplicit(true)
, selectPressed(false)
, textLayoutDirty(true)
+ , persistentSelection(false)
, m_hideCursor(false)
, m_separator(0)
, m_readOnly(0)
bool hAlignImplicit:1;
bool selectPressed:1;
bool textLayoutDirty:1;
+ bool persistentSelection:1;
uint m_hideCursor : 1; // used to hide the m_cursor inside preedit areas
uint m_separator : 1;
--- /dev/null
+import QtQuick 2.0
+
+TextEdit {
+ property string selected: selectedText
+
+ text: "Hello World!"
+ focus: true
+}
void tst_qquicktextedit::persistentSelection()
{
- {
- QString componentStr = "import QtQuick 2.0\nTextEdit { persistentSelection: true; text: \"Hello World\" }";
- QDeclarativeComponent texteditComponent(&engine);
- texteditComponent.setData(componentStr.toLatin1(), QUrl());
- QQuickTextEdit *textEditObject = qobject_cast<QQuickTextEdit*>(texteditComponent.create());
- QVERIFY(textEditObject != 0);
- QCOMPARE(textEditObject->persistentSelection(), true);
- }
+ QQuickView canvas(testFileUrl("persistentSelection.qml"));
+ canvas.show();
+ canvas.requestActivateWindow();
+ QTest::qWaitForWindowShown(&canvas);
+ QTRY_COMPARE(&canvas, qGuiApp->focusWindow());
+ canvas.requestActivateWindow();
+
+ QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(canvas.rootObject());
+ QVERIFY(edit);
+ QVERIFY(edit->hasActiveFocus());
+
+ QSignalSpy spy(edit, SIGNAL(persistentSelectionChanged(bool)));
+
+ QCOMPARE(edit->persistentSelection(), false);
+
+ edit->setPersistentSelection(false);
+ QCOMPARE(edit->persistentSelection(), false);
+ QCOMPARE(spy.count(), 0);
+
+ edit->select(1, 4);
+ QCOMPARE(edit->property("selected").toString(), QLatin1String("ell"));
+
+ edit->setFocus(false);
+ QCOMPARE(edit->property("selected").toString(), QString());
+
+ edit->setFocus(true);
+ QCOMPARE(edit->property("selected").toString(), QString());
+
+ edit->setPersistentSelection(true);
+ QCOMPARE(edit->persistentSelection(), true);
+ QCOMPARE(spy.count(), 1);
+
+ edit->select(1, 4);
+ QCOMPARE(edit->property("selected").toString(), QLatin1String("ell"));
+
+ edit->setFocus(false);
+ QCOMPARE(edit->property("selected").toString(), QLatin1String("ell"));
+
+ edit->setFocus(true);
+ QCOMPARE(edit->property("selected").toString(), QLatin1String("ell"));
- {
- QString componentStr = "import QtQuick 2.0\nTextEdit { persistentSelection: false; text: \"Hello World\" }";
- QDeclarativeComponent texteditComponent(&engine);
- texteditComponent.setData(componentStr.toLatin1(), QUrl());
- QQuickTextEdit *textEditObject = qobject_cast<QQuickTextEdit*>(texteditComponent.create());
- QVERIFY(textEditObject != 0);
- QCOMPARE(textEditObject->persistentSelection(), false);
- }
}
void tst_qquicktextedit::focusOnPress()
--- /dev/null
+import QtQuick 2.0
+
+TextInput {
+ property string selected: selectedText
+
+ text: "Hello World!"
+ focus: true
+}
void color();
void wrap();
void selection();
+ void persistentSelection();
void isRightToLeft_data();
void isRightToLeft();
void moveCursorSelection_data();
delete textinputObject;
}
+void tst_qquicktextinput::persistentSelection()
+{
+ QQuickView canvas(testFileUrl("persistentSelection.qml"));
+ canvas.show();
+ canvas.requestActivateWindow();
+ QTest::qWaitForWindowShown(&canvas);
+ QTRY_COMPARE(&canvas, qGuiApp->focusWindow());
+ canvas.requestActivateWindow();
+
+ QQuickTextInput *input = qobject_cast<QQuickTextInput *>(canvas.rootObject());
+ QVERIFY(input);
+ QVERIFY(input->hasActiveFocus());
+
+ QSignalSpy spy(input, SIGNAL(persistentSelectionChanged()));
+
+ QCOMPARE(input->persistentSelection(), false);
+
+ input->setPersistentSelection(false);
+ QCOMPARE(input->persistentSelection(), false);
+ QCOMPARE(spy.count(), 0);
+
+ input->select(1, 4);
+ QCOMPARE(input->property("selected").toString(), QLatin1String("ell"));
+
+ input->setFocus(false);
+ QCOMPARE(input->property("selected").toString(), QString());
+
+ input->setFocus(true);
+ QCOMPARE(input->property("selected").toString(), QString());
+
+ input->setPersistentSelection(true);
+ QCOMPARE(input->persistentSelection(), true);
+ QCOMPARE(spy.count(), 1);
+
+ input->select(1, 4);
+ QCOMPARE(input->property("selected").toString(), QLatin1String("ell"));
+
+ input->setFocus(false);
+ QCOMPARE(input->property("selected").toString(), QLatin1String("ell"));
+
+ input->setFocus(true);
+ QCOMPARE(input->property("selected").toString(), QLatin1String("ell"));
+}
+
void tst_qquicktextinput::isRightToLeft_data()
{
QTest::addColumn<QString>("text");