2022-05-13 13:12:05 +00:00
|
|
|
// Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
import QtCore
|
2023-12-13 18:11:57 +00:00
|
|
|
import QtQuick
|
2020-03-26 16:01:51 +00:00
|
|
|
import QtQuick.Controls
|
2021-09-23 15:45:44 +00:00
|
|
|
import QtQuick.Dialogs
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2016-07-26 12:15:31 +00:00
|
|
|
// TODO:
|
|
|
|
// - make designer-friendly
|
|
|
|
|
2016-07-06 11:04:07 +00:00
|
|
|
ApplicationWindow {
|
|
|
|
id: window
|
|
|
|
width: 1024
|
|
|
|
height: 600
|
|
|
|
visible: true
|
2023-11-06 14:14:06 +00:00
|
|
|
title: textArea.textDocument.source +
|
|
|
|
" - Text Editor Example" + (textArea.textDocument.modified ? " *" : "")
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
Action {
|
|
|
|
id: openAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("&Open")
|
2021-09-23 15:45:44 +00:00
|
|
|
shortcut: StandardKey.Open
|
2023-11-06 14:14:06 +00:00
|
|
|
onTriggered: {
|
|
|
|
if (textArea.textDocument.modified)
|
|
|
|
discardDialog.open()
|
|
|
|
else
|
|
|
|
openDialog.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Action {
|
|
|
|
id: saveAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("&Save…")
|
2023-11-06 14:14:06 +00:00
|
|
|
shortcut: StandardKey.Save
|
2023-11-22 20:45:46 +00:00
|
|
|
enabled: textArea.textDocument.modified
|
2023-11-06 14:14:06 +00:00
|
|
|
onTriggered: textArea.textDocument.save()
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: saveAsAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("Save &As…")
|
2021-09-23 15:45:44 +00:00
|
|
|
shortcut: StandardKey.SaveAs
|
|
|
|
onTriggered: saveDialog.open()
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: quitAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("&Quit")
|
2021-09-23 15:45:44 +00:00
|
|
|
shortcut: StandardKey.Quit
|
|
|
|
onTriggered: close()
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: copyAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("&Copy")
|
2021-09-23 15:45:44 +00:00
|
|
|
shortcut: StandardKey.Copy
|
2024-03-11 22:59:46 +00:00
|
|
|
enabled: textArea.selectedText
|
2021-09-23 15:45:44 +00:00
|
|
|
onTriggered: textArea.copy()
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: cutAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("Cu&t")
|
2021-09-23 15:45:44 +00:00
|
|
|
shortcut: StandardKey.Cut
|
2024-03-11 22:59:46 +00:00
|
|
|
enabled: textArea.selectedText
|
2021-09-23 15:45:44 +00:00
|
|
|
onTriggered: textArea.cut()
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: pasteAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("&Paste")
|
2021-09-23 15:45:44 +00:00
|
|
|
shortcut: StandardKey.Paste
|
2024-03-11 22:59:46 +00:00
|
|
|
enabled: textArea.canPaste
|
2021-09-23 15:45:44 +00:00
|
|
|
onTriggered: textArea.paste()
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: boldAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("&Bold")
|
2021-09-23 15:45:44 +00:00
|
|
|
shortcut: StandardKey.Bold
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
checkable: true
|
|
|
|
checked: textArea.cursorSelection.font.bold
|
TextEditor example: allow setting multiple font attributes
When a user activates the boldAction for example, the code was replacing
QTextCharFormat's font with a default-constructed font that has the bold
attribute set, which meant that it could not be bold, italic, underlined
struck out, and with a custom size and color at the same time. On the
other hand, when we do it the current way:
textArea.cursorSelection.font.bold = checked
we call QQuickTextSelection::font(), QFont::setBold(), and then
QQuickTextSelection::setFont(). (QFont is a QML value type, so it's the
only way.) Perhaps at some point, something was going wrong with that,
but it seems to work now.
Amends 045f9ce192d841f3cc36d514b5f238b46488b41e
Fixes: QTBUG-136250
Pick-to: 6.8
Change-Id: I268e5814e7aa52aeb5aaec2d1a8fbfbc0d670236
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
(cherry picked from commit 17a225f09ac5ec7ebd065197917ddd9586571ec1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-25 12:37:27 +00:00
|
|
|
onTriggered: textArea.cursorSelection.font.bold = checked
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: italicAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("&Italic")
|
2021-09-23 15:45:44 +00:00
|
|
|
shortcut: StandardKey.Italic
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
checkable: true
|
|
|
|
checked: textArea.cursorSelection.font.italic
|
TextEditor example: allow setting multiple font attributes
When a user activates the boldAction for example, the code was replacing
QTextCharFormat's font with a default-constructed font that has the bold
attribute set, which meant that it could not be bold, italic, underlined
struck out, and with a custom size and color at the same time. On the
other hand, when we do it the current way:
textArea.cursorSelection.font.bold = checked
we call QQuickTextSelection::font(), QFont::setBold(), and then
QQuickTextSelection::setFont(). (QFont is a QML value type, so it's the
only way.) Perhaps at some point, something was going wrong with that,
but it seems to work now.
Amends 045f9ce192d841f3cc36d514b5f238b46488b41e
Fixes: QTBUG-136250
Pick-to: 6.8
Change-Id: I268e5814e7aa52aeb5aaec2d1a8fbfbc0d670236
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
(cherry picked from commit 17a225f09ac5ec7ebd065197917ddd9586571ec1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-25 12:37:27 +00:00
|
|
|
onTriggered: textArea.cursorSelection.font.italic = checked
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2021-09-23 15:45:44 +00:00
|
|
|
|
|
|
|
Action {
|
|
|
|
id: underlineAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("&Underline")
|
2021-09-23 15:45:44 +00:00
|
|
|
shortcut: StandardKey.Underline
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
checkable: true
|
|
|
|
checked: textArea.cursorSelection.font.underline
|
TextEditor example: allow setting multiple font attributes
When a user activates the boldAction for example, the code was replacing
QTextCharFormat's font with a default-constructed font that has the bold
attribute set, which meant that it could not be bold, italic, underlined
struck out, and with a custom size and color at the same time. On the
other hand, when we do it the current way:
textArea.cursorSelection.font.bold = checked
we call QQuickTextSelection::font(), QFont::setBold(), and then
QQuickTextSelection::setFont(). (QFont is a QML value type, so it's the
only way.) Perhaps at some point, something was going wrong with that,
but it seems to work now.
Amends 045f9ce192d841f3cc36d514b5f238b46488b41e
Fixes: QTBUG-136250
Pick-to: 6.8
Change-Id: I268e5814e7aa52aeb5aaec2d1a8fbfbc0d670236
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
(cherry picked from commit 17a225f09ac5ec7ebd065197917ddd9586571ec1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-25 12:37:27 +00:00
|
|
|
onTriggered: textArea.cursorSelection.font.underline = checked
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Action {
|
|
|
|
id: strikeoutAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("&Strikeout")
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
checkable: true
|
|
|
|
checked: textArea.cursorSelection.font.strikeout
|
TextEditor example: allow setting multiple font attributes
When a user activates the boldAction for example, the code was replacing
QTextCharFormat's font with a default-constructed font that has the bold
attribute set, which meant that it could not be bold, italic, underlined
struck out, and with a custom size and color at the same time. On the
other hand, when we do it the current way:
textArea.cursorSelection.font.bold = checked
we call QQuickTextSelection::font(), QFont::setBold(), and then
QQuickTextSelection::setFont(). (QFont is a QML value type, so it's the
only way.) Perhaps at some point, something was going wrong with that,
but it seems to work now.
Amends 045f9ce192d841f3cc36d514b5f238b46488b41e
Fixes: QTBUG-136250
Pick-to: 6.8
Change-Id: I268e5814e7aa52aeb5aaec2d1a8fbfbc0d670236
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
(cherry picked from commit 17a225f09ac5ec7ebd065197917ddd9586571ec1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-25 12:37:27 +00:00
|
|
|
onTriggered: textArea.cursorSelection.font.strikeout = checked
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Action {
|
|
|
|
id: alignLeftAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("Align &Left")
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
shortcut: "Ctrl+{"
|
|
|
|
checkable: true
|
|
|
|
checked: textArea.cursorSelection.alignment === Qt.AlignLeft
|
|
|
|
onTriggered: textArea.cursorSelection.alignment = Qt.AlignLeft
|
|
|
|
}
|
|
|
|
|
|
|
|
Action {
|
|
|
|
id: alignCenterAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("&Center")
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
shortcut: "Ctrl+|"
|
|
|
|
checkable: true
|
|
|
|
checked: textArea.cursorSelection.alignment === Qt.AlignCenter
|
|
|
|
onTriggered: textArea.cursorSelection.alignment = Qt.AlignCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
Action {
|
|
|
|
id: alignRightAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("Align &Right")
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
shortcut: "Ctrl+}"
|
|
|
|
checkable: true
|
|
|
|
checked: textArea.cursorSelection.alignment === Qt.AlignRight
|
|
|
|
onTriggered: textArea.cursorSelection.alignment = Qt.AlignRight
|
|
|
|
}
|
|
|
|
|
|
|
|
Action {
|
|
|
|
id: alignJustifyAction
|
2024-03-11 22:59:46 +00:00
|
|
|
text: qsTr("&Justify")
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
shortcut: "Ctrl+Alt+}"
|
|
|
|
checkable: true
|
|
|
|
checked: textArea.cursorSelection.alignment === Qt.AlignJustify
|
|
|
|
onTriggered: textArea.cursorSelection.alignment = Qt.AlignJustify
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
2025-03-19 18:55:46 +00:00
|
|
|
Action {
|
|
|
|
id: fontDialogAction
|
|
|
|
text: qsTr("Fon&t…")
|
|
|
|
shortcut: "Ctrl+T"
|
|
|
|
onTriggered: {
|
|
|
|
fontDialog.selectedFont = textArea.cursorSelection.font
|
|
|
|
fontDialog.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Action {
|
|
|
|
id: colorDialogAction
|
|
|
|
text: qsTr("Color…")
|
|
|
|
shortcut: "Ctrl+Shift+C"
|
|
|
|
onTriggered: {
|
|
|
|
colorDialog.selectedColor = textArea.cursorSelection.color
|
|
|
|
colorDialog.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-13 17:38:28 +00:00
|
|
|
menuBar: MenuBar {
|
|
|
|
Menu {
|
2016-09-07 15:19:43 +00:00
|
|
|
title: qsTr("&File")
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: openAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: saveAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: saveAsAction
|
|
|
|
}
|
|
|
|
MenuItem {
|
|
|
|
action: quitAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-13 17:38:28 +00:00
|
|
|
Menu {
|
2016-09-07 15:19:43 +00:00
|
|
|
title: qsTr("&Edit")
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: copyAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: cutAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: pasteAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-13 17:38:28 +00:00
|
|
|
Menu {
|
2016-09-07 15:19:43 +00:00
|
|
|
title: qsTr("F&ormat")
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: boldAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: italicAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: underlineAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: strikeoutAction
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
}
|
2025-04-25 18:03:10 +00:00
|
|
|
MenuItem {
|
|
|
|
action: fontDialogAction
|
|
|
|
}
|
|
|
|
MenuItem {
|
|
|
|
action: colorDialogAction
|
|
|
|
}
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuSeparator {}
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: alignLeftAction
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
}
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: alignCenterAction
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
}
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: alignJustifyAction
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
}
|
2023-12-13 17:38:28 +00:00
|
|
|
MenuItem {
|
2024-03-11 22:59:46 +00:00
|
|
|
action: alignRightAction
|
2021-09-23 15:45:44 +00:00
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileDialog {
|
|
|
|
id: openDialog
|
|
|
|
fileMode: FileDialog.OpenFile
|
2016-10-04 11:48:45 +00:00
|
|
|
selectedNameFilter.index: 1
|
2020-08-10 10:35:25 +00:00
|
|
|
nameFilters: ["Text files (*.txt)", "HTML files (*.html *.htm)", "Markdown files (*.md *.markdown)"]
|
2021-09-23 15:45:44 +00:00
|
|
|
currentFolder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
|
2023-11-06 14:14:06 +00:00
|
|
|
onAccepted: {
|
|
|
|
textArea.textDocument.modified = false // we asked earlier, if necessary
|
|
|
|
textArea.textDocument.source = selectedFile
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FileDialog {
|
|
|
|
id: saveDialog
|
|
|
|
fileMode: FileDialog.SaveFile
|
|
|
|
nameFilters: openDialog.nameFilters
|
2021-09-23 15:45:44 +00:00
|
|
|
currentFolder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
|
2023-11-06 14:14:06 +00:00
|
|
|
onAccepted: textArea.textDocument.saveAs(selectedFile)
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FontDialog {
|
|
|
|
id: fontDialog
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
onAccepted: textArea.cursorSelection.font = selectedFont
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
2022-08-10 17:57:26 +00:00
|
|
|
ColorDialog {
|
2016-07-06 11:04:07 +00:00
|
|
|
id: colorDialog
|
2023-12-13 18:11:57 +00:00
|
|
|
selectedColor: textArea.cursorSelection.color
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
onAccepted: textArea.cursorSelection.color = selectedColor
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
2022-05-09 21:16:05 +00:00
|
|
|
MessageDialog {
|
|
|
|
title: qsTr("Error")
|
2016-07-06 11:04:07 +00:00
|
|
|
id: errorDialog
|
|
|
|
}
|
|
|
|
|
2022-05-09 21:16:05 +00:00
|
|
|
MessageDialog {
|
2019-08-19 14:01:05 +00:00
|
|
|
id : quitDialog
|
|
|
|
title: qsTr("Quit?")
|
|
|
|
text: qsTr("The file has been modified. Quit anyway?")
|
2022-05-09 21:16:05 +00:00
|
|
|
buttons: MessageDialog.Yes | MessageDialog.No
|
2023-11-22 20:45:46 +00:00
|
|
|
onButtonClicked: function (button, role) {
|
|
|
|
if (role === MessageDialog.YesRole) {
|
|
|
|
textArea.textDocument.modified = false
|
|
|
|
Qt.quit()
|
|
|
|
}
|
|
|
|
}
|
2019-08-19 14:01:05 +00:00
|
|
|
}
|
|
|
|
|
2023-11-06 14:14:06 +00:00
|
|
|
MessageDialog {
|
|
|
|
id : discardDialog
|
|
|
|
title: qsTr("Discard changes?")
|
|
|
|
text: qsTr("The file has been modified. Open a new file anyway?")
|
|
|
|
buttons: MessageDialog.Yes | MessageDialog.No
|
|
|
|
onButtonClicked: function (button, role) {
|
|
|
|
if (role === MessageDialog.YesRole)
|
|
|
|
openDialog.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-06 11:04:07 +00:00
|
|
|
header: ToolBar {
|
2016-08-12 08:45:17 +00:00
|
|
|
Flow {
|
|
|
|
width: parent.width
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2016-08-12 08:45:17 +00:00
|
|
|
Row {
|
|
|
|
id: fileRow
|
|
|
|
ToolButton {
|
|
|
|
id: openButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uF115" // icon-folder-open-empty
|
2016-08-12 08:45:17 +00:00
|
|
|
font.family: "fontello"
|
2021-09-23 15:45:44 +00:00
|
|
|
action: openAction
|
|
|
|
focusPolicy: Qt.TabFocus
|
2016-08-12 08:45:17 +00:00
|
|
|
}
|
2023-11-06 14:14:06 +00:00
|
|
|
ToolButton {
|
|
|
|
id: saveButton
|
|
|
|
text: "\uE80A" // icon-floppy-disk
|
|
|
|
font.family: "fontello"
|
|
|
|
action: saveAction
|
|
|
|
focusPolicy: Qt.TabFocus
|
|
|
|
}
|
2016-08-12 08:45:17 +00:00
|
|
|
ToolSeparator {
|
|
|
|
contentItem.visible: fileRow.y === editRow.y
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
2016-08-12 08:45:17 +00:00
|
|
|
id: editRow
|
2016-07-06 11:04:07 +00:00
|
|
|
ToolButton {
|
|
|
|
id: copyButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uF0C5" // icon-docs
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
2021-09-23 15:45:44 +00:00
|
|
|
action: copyAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: cutButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE802" // icon-scissors
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
2021-09-23 15:45:44 +00:00
|
|
|
action: cutAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: pasteButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uF0EA" // icon-paste
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
2021-09-23 15:45:44 +00:00
|
|
|
action: pasteAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2016-08-12 08:45:17 +00:00
|
|
|
ToolSeparator {
|
|
|
|
contentItem.visible: editRow.y === formatRow.y
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
2016-08-12 08:45:17 +00:00
|
|
|
id: formatRow
|
2016-07-06 11:04:07 +00:00
|
|
|
ToolButton {
|
|
|
|
id: boldButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE800" // icon-bold
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
2021-09-23 15:45:44 +00:00
|
|
|
action: boldAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: italicButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE801" // icon-italic
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
2021-09-23 15:45:44 +00:00
|
|
|
action: italicAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: underlineButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uF0CD" // icon-underline
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
2021-09-23 15:45:44 +00:00
|
|
|
action: underlineAction
|
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: strikeoutButton
|
|
|
|
text: "\uF0CC"
|
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
action: strikeoutAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
2016-08-12 12:22:07 +00:00
|
|
|
ToolButton {
|
|
|
|
id: fontFamilyToolButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: qsTr("\uE808") // icon-font
|
2016-08-12 12:22:07 +00:00
|
|
|
font.family: "fontello"
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
font.bold: textArea.cursorSelection.font.bold
|
|
|
|
font.italic: textArea.cursorSelection.font.italic
|
|
|
|
font.underline: textArea.cursorSelection.font.underline
|
|
|
|
font.strikeout: textArea.cursorSelection.font.strikeout
|
2021-09-23 15:45:44 +00:00
|
|
|
focusPolicy: Qt.TabFocus
|
2022-08-10 17:57:26 +00:00
|
|
|
onClicked: function () {
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
fontDialog.selectedFont = textArea.cursorSelection.font
|
2022-08-10 17:57:26 +00:00
|
|
|
fontDialog.open()
|
|
|
|
}
|
2016-08-12 12:22:07 +00:00
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
ToolButton {
|
|
|
|
id: textColorButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uF1FC" // icon-brush
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
2022-08-10 17:57:26 +00:00
|
|
|
onClicked: function () {
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
colorDialog.selectedColor = textArea.cursorSelection.color
|
2022-08-10 17:57:26 +00:00
|
|
|
colorDialog.open()
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
width: aFontMetrics.width + 3
|
|
|
|
height: 2
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
color: textArea.cursorSelection.color
|
2016-07-06 11:04:07 +00:00
|
|
|
parent: textColorButton.contentItem
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.baseline: parent.baseline
|
2016-08-12 12:22:07 +00:00
|
|
|
anchors.baselineOffset: 6
|
2016-07-06 11:04:07 +00:00
|
|
|
|
|
|
|
TextMetrics {
|
|
|
|
id: aFontMetrics
|
|
|
|
font: textColorButton.font
|
|
|
|
text: textColorButton.text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-12 08:45:17 +00:00
|
|
|
ToolSeparator {
|
|
|
|
contentItem.visible: formatRow.y === alignRow.y
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
2016-08-12 08:45:17 +00:00
|
|
|
id: alignRow
|
2016-07-06 11:04:07 +00:00
|
|
|
ToolButton {
|
|
|
|
id: alignLeftButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE803" // icon-align-left
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
action: alignLeftAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: alignCenterButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE804" // icon-align-center
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
action: alignCenterAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: alignRightButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE805" // icon-align-right
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
action: alignRightAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
id: alignJustifyButton
|
2016-07-26 12:15:31 +00:00
|
|
|
text: "\uE806" // icon-align-justify
|
2016-07-06 11:04:07 +00:00
|
|
|
font.family: "fontello"
|
|
|
|
focusPolicy: Qt.TabFocus
|
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>
2023-11-03 03:10:40 +00:00
|
|
|
action: alignJustifyAction
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Flickable {
|
|
|
|
id: flickable
|
|
|
|
flickableDirection: Flickable.VerticalFlick
|
|
|
|
anchors.fill: parent
|
|
|
|
|
2024-03-06 05:15:44 +00:00
|
|
|
ScrollBar.vertical: ScrollBar {}
|
|
|
|
|
2016-07-06 11:04:07 +00:00
|
|
|
TextArea.flickable: TextArea {
|
|
|
|
id: textArea
|
2024-03-05 21:26:06 +00:00
|
|
|
textFormat: Qt.AutoText
|
2016-07-06 11:04:07 +00:00
|
|
|
wrapMode: TextArea.Wrap
|
|
|
|
focus: true
|
|
|
|
selectByMouse: true
|
2016-08-12 19:18:17 +00:00
|
|
|
persistentSelection: true
|
2016-07-06 11:04:07 +00:00
|
|
|
// Different styles have different padding and background
|
|
|
|
// decorations, but since this editor is almost taking up the
|
|
|
|
// entire window, we don't need them.
|
|
|
|
leftPadding: 6
|
|
|
|
rightPadding: 6
|
|
|
|
topPadding: 0
|
|
|
|
bottomPadding: 0
|
|
|
|
background: null
|
|
|
|
|
2025-05-13 04:08:24 +00:00
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.RightButton
|
|
|
|
onTapped: contextMenu.popup()
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
onLinkActivated: function (link) {
|
|
|
|
Qt.openUrlExternally(link)
|
|
|
|
}
|
2023-11-06 14:14:06 +00:00
|
|
|
|
2023-11-22 20:45:46 +00:00
|
|
|
Component.onCompleted: {
|
|
|
|
if (Qt.application.arguments.length === 2)
|
2024-02-05 21:59:57 +00:00
|
|
|
textDocument.source = "file:" + Qt.application.arguments[1]
|
2023-11-22 20:45:46 +00:00
|
|
|
else
|
2024-02-05 21:59:57 +00:00
|
|
|
textDocument.source = "qrc:/texteditor.html"
|
2023-11-22 20:45:46 +00:00
|
|
|
}
|
|
|
|
|
2024-02-02 22:47:14 +00:00
|
|
|
textDocument.onStatusChanged: {
|
2024-02-05 21:59:57 +00:00
|
|
|
// a message lookup table using computed properties:
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer
|
|
|
|
const statusMessages = {
|
|
|
|
[ TextDocument.ReadError ]: qsTr("Failed to load “%1”"),
|
|
|
|
[ TextDocument.WriteError ]: qsTr("Failed to save “%1”"),
|
|
|
|
[ TextDocument.NonLocalFileError ]: qsTr("Not a local file: “%1”"),
|
2024-02-02 22:47:14 +00:00
|
|
|
}
|
2024-02-05 21:59:57 +00:00
|
|
|
const err = statusMessages[textDocument.status]
|
|
|
|
if (err) {
|
|
|
|
errorDialog.text = err.arg(textDocument.source)
|
2024-02-02 22:47:14 +00:00
|
|
|
errorDialog.open()
|
|
|
|
}
|
2023-11-06 14:14:06 +00:00
|
|
|
}
|
2025-05-13 04:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
|
2025-05-13 04:08:24 +00:00
|
|
|
Menu {
|
|
|
|
id: contextMenu
|
|
|
|
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Copy")
|
|
|
|
action: copyAction
|
|
|
|
}
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Cut")
|
|
|
|
action: cutAction
|
|
|
|
}
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Paste")
|
|
|
|
action: pasteAction
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuSeparator {}
|
|
|
|
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Font...")
|
|
|
|
onTriggered: function () {
|
|
|
|
fontDialog.selectedFont = textArea.cursorSelection.font
|
|
|
|
fontDialog.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Color...")
|
|
|
|
onTriggered: function () {
|
|
|
|
colorDialog.selectedColor = textArea.cursorSelection.color
|
|
|
|
colorDialog.open()
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-19 14:01:05 +00:00
|
|
|
|
2021-09-23 15:45:44 +00:00
|
|
|
onClosing: function (close) {
|
2023-11-06 14:14:06 +00:00
|
|
|
if (textArea.textDocument.modified) {
|
2019-08-19 14:01:05 +00:00
|
|
|
quitDialog.open()
|
|
|
|
close.accepted = false
|
|
|
|
}
|
|
|
|
}
|
2016-07-06 11:04:07 +00:00
|
|
|
}
|