diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2023-11-02 20:10:40 -0700 |
---|---|---|
committer | Oliver Eftevaag <oliver.eftevaag@qt.io> | 2023-12-08 20:11:28 +0100 |
commit | 045f9ce192d841f3cc36d514b5f238b46488b41e (patch) | |
tree | 2dddf5bea40d39f4e197c51f203887638ac4c08a /src/quick/CMakeLists.txt | |
parent | 0a1313d8e75e805f6dff86d8b682cb6f9bf3a7bb (diff) |
Add TextSelection (Tech Preview)
In the Controls text editor example, DocumentHandler always sounded like
a hack, just by its name.
We don't expect to be able to handle multiple selections anytime soon;
but if we realistically expect to have multi-seat support in Qt some
day, then probably the multi-user experience should include support for
multiple text cursors and selections. So we shouldn't paint ourselves
into a corner. QQuickTextControl works with only one QTextCursor most
of the time (but it's private, thus modifiable); and TextEdit has
properties like selectionStart, selectionEnd, selectedText, etc. which
seem to assume that there is only one selection. So probably if we
needed to support multiple selections, we could add
Q_PROPERTY(QQmlListProperty<QQuickTextSelection> selections ...),
document that those legacy properties just work with the first
selection, and/or deprecate them.
So with that in mind, let's get started with a QQuickTextSelection
object. We add TextEdit.cursorSelection which holds the single selection
near the text cursor. It provides API needed for tracking and
manipulating often-used properties of selected rich text (such as
QTextCharFormat properties) so that DocumentHandler can be removed.
The example now uses TextArea.cursorSelection to manipulate the selected
text's format. It's not possible to be fully declarative with this API
though; we need to call setFont (by assigning a font), but QFont is a
value type, and is not as mergeable as QTextCharFormat is, for example.
If we used a binding rather than Action.onTriggered, it would trigger
reading the font for an entire span of selected text (which may have had
multiple fonts), setting one attribute (like bold), then applying the
font to the whole span. What we do now is almost like that; but instead
of reading the font first, we start with a default-constructed QFont,
set one attribute, and call QTextCursor::mergeCharFormat(), in the hope
that it can merge only the features of QFont that have actually been
set. Unfortunately this is not quite true either: if you toggle the
bold button, it might change the font size too, and so on; so maybe we
really need QTextCharFormat in QML (as a value type, presumably) to
implement those feature-toggling toolbar buttons correctly.
This API is in tech preview, because of such issues as described above;
because we're just scratching the surface of what might be possible;
because we should perhaps compare popular JavaScript text-editing APIs
that might be found elsewhere, in the meantime get feedback from users
during the tech preview phase, and keep iterating.
[ChangeLog][QtQuick][TextEdit] TextEdit.cursorSelection is a
TextSelection object, which provides properties to inspect and modify
the formatting of the single selection that is currently supported.
This API is in Tech Preview.
[ChangeLog][Controls][TextArea] TextArea.cursorSelection is a
TextSelection object, which provides properties to inspect and modify
the formatting of the single selection that is currently supported.
This API is in Tech Preview.
Task-number: QTBUG-36521
Task-number: QTBUG-38830
Task-number: QTBUG-81022
Change-Id: Icea99f633694aa712d0b4730b77369077288540f
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
Diffstat (limited to 'src/quick/CMakeLists.txt')
-rw-r--r-- | src/quick/CMakeLists.txt | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/quick/CMakeLists.txt b/src/quick/CMakeLists.txt index ebdd698de3..2ba1d560a6 100644 --- a/src/quick/CMakeLists.txt +++ b/src/quick/CMakeLists.txt @@ -212,6 +212,7 @@ qt_internal_add_qml_module(Quick util/qquicksvgparser.cpp util/qquicksvgparser_p.h util/qquicksystempalette.cpp util/qquicksystempalette_p.h util/qquicktextmetrics.cpp util/qquicktextmetrics_p.h + util/qquicktextselection.cpp util/qquicktextselection_p.h util/qquicktimeline.cpp util/qquicktimeline_p_p.h util/qquicktransition.cpp util/qquicktransition_p.h |