aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2013-03-01 15:26:54 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-15 17:59:34 +0100
commit70ce4ec6ae9321a601a5af37d11bd284b2203bfc (patch)
treeecff50aa0266c8b2467e8ebe153f139a1ac2e869 /src
parent1366ad57bca2e45adfd624106602af6bf1f12044 (diff)
Add TextEdit::selectByKeyboard
The main use case is for enabling text selection by keyboard for read-only editors. Change-Id: Ieaa9af366fd0eaf863a104a2fdf33c9ddad38b10 Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquickitemsmodule.cpp1
-rw-r--r--src/quick/items/qquicktextedit.cpp46
-rw-r--r--src/quick/items/qquicktextedit_p.h5
-rw-r--r--src/quick/items/qquicktextedit_p_p.h4
4 files changed, 54 insertions, 2 deletions
diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp
index 20c35f42f2..cd49377822 100644
--- a/src/quick/items/qquickitemsmodule.cpp
+++ b/src/quick/items/qquickitemsmodule.cpp
@@ -158,6 +158,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qmlRegisterType<QQuickScale>(uri,major,minor,"Scale");
qmlRegisterType<QQuickText>(uri,major,minor,"Text");
qmlRegisterType<QQuickTextEdit>(uri,major,minor,"TextEdit");
+ qmlRegisterType<QQuickTextEdit,1>(uri,2,1,"TextEdit");
qmlRegisterType<QQuickTextInput>(uri,major,minor,"TextInput");
qmlRegisterType<QQuickViewSection>(uri,major,minor,"ViewSection");
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp
index dabbc96614..e30b9cb3fd 100644
--- a/src/quick/items/qquicktextedit.cpp
+++ b/src/quick/items/qquicktextedit.cpp
@@ -1238,6 +1238,44 @@ void QQuickTextEdit::componentComplete()
if (d->cursorComponent && isCursorVisible())
QQuickTextUtil::createCursor(d);
}
+
+/*!
+ \qmlproperty bool QtQuick2::TextEdit::selectByKeyboard
+ \since QtQuick 2.1
+
+ Defaults to true when the editor is editable, and false
+ when read-only.
+
+ If true, the user can use the keyboard to select text
+ even if the editor is read-only. If false, the user
+ cannot use the keyboard to select text even if the
+ editor is editable.
+
+ \sa readOnly
+*/
+bool QQuickTextEdit::selectByKeyboard() const
+{
+ Q_D(const QQuickTextEdit);
+ if (d->selectByKeyboardSet)
+ return d->selectByKeyboard;
+ return !isReadOnly();
+}
+
+void QQuickTextEdit::setSelectByKeyboard(bool on)
+{
+ Q_D(QQuickTextEdit);
+ bool was = selectByKeyboard();
+ d->selectByKeyboardSet = true;
+ if (was != on) {
+ d->selectByKeyboard = on;
+ if (on)
+ d->control->setTextInteractionFlags(d->control->textInteractionFlags() | Qt::TextSelectableByKeyboard);
+ else
+ d->control->setTextInteractionFlags(d->control->textInteractionFlags() & ~Qt::TextSelectableByKeyboard);
+ emit selectByKeyboardChanged(on);
+ }
+}
+
/*!
\qmlproperty bool QtQuick2::TextEdit::selectByMouse
@@ -1316,8 +1354,12 @@ void QQuickTextEdit::setReadOnly(bool r)
Qt::TextInteractionFlags flags = Qt::LinksAccessibleByMouse;
if (d->selectByMouse)
flags = flags | Qt::TextSelectableByMouse;
+ if (d->selectByKeyboardSet && d->selectByKeyboard)
+ flags = flags | Qt::TextSelectableByKeyboard;
+ else if (!d->selectByKeyboardSet && !r)
+ flags = flags | Qt::TextSelectableByKeyboard;
if (!r)
- flags = flags | Qt::TextSelectableByKeyboard | Qt::TextEditable;
+ flags = flags | Qt::TextEditable;
d->control->setTextInteractionFlags(flags);
if (!r)
d->control->moveCursor(QTextCursor::End);
@@ -1327,6 +1369,8 @@ void QQuickTextEdit::setReadOnly(bool r)
#endif
q_canPasteChanged();
emit readOnlyChanged(r);
+ if (!d->selectByKeyboardSet)
+ emit selectByKeyboardChanged(!r);
}
bool QQuickTextEdit::isReadOnly() const
diff --git a/src/quick/items/qquicktextedit_p.h b/src/quick/items/qquicktextedit_p.h
index 255c8ac670..8a2d9b1e92 100644
--- a/src/quick/items/qquicktextedit_p.h
+++ b/src/quick/items/qquicktextedit_p.h
@@ -90,6 +90,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickTextEdit : public QQuickImplicitSizeItem
#ifndef QT_NO_IM
Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged)
#endif
+ Q_PROPERTY(bool selectByKeyboard READ selectByKeyboard WRITE setSelectByKeyboard NOTIFY selectByKeyboardChanged REVISION 1)
Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
@@ -201,6 +202,9 @@ public:
void setInputMethodHints(Qt::InputMethodHints hints);
#endif
+ bool selectByKeyboard() const;
+ void setSelectByKeyboard(bool);
+
bool selectByMouse() const;
void setSelectByMouse(bool);
@@ -274,6 +278,7 @@ Q_SIGNALS:
void activeFocusOnPressChanged(bool activeFocusOnPressed);
void persistentSelectionChanged(bool isPersistentSelection);
void textMarginChanged(qreal textMargin);
+ Q_REVISION(1) void selectByKeyboardChanged(bool selectByKeyboard);
void selectByMouseChanged(bool selectByMouse);
void mouseSelectionModeChanged(SelectionMode mode);
void linkActivated(const QString &link);
diff --git a/src/quick/items/qquicktextedit_p_p.h b/src/quick/items/qquicktextedit_p_p.h
index f65af3d2d3..dd0f76f8d9 100644
--- a/src/quick/items/qquicktextedit_p_p.h
+++ b/src/quick/items/qquicktextedit_p_p.h
@@ -87,7 +87,7 @@ public:
, 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(true), inLayout(false)
+ , textCached(true), inLayout(false), selectByKeyboard(false), selectByKeyboardSet(false)
{
}
@@ -168,6 +168,8 @@ public:
bool hAlignImplicit:1;
bool textCached:1;
bool inLayout:1;
+ bool selectByKeyboard:1;
+ bool selectByKeyboardSet:1;
};
QT_END_NAMESPACE