qtdeclarative/examples/quickcontrols/texteditor/qml/texteditor.qml

560 lines
16 KiB
QML
Raw Normal View History

// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtCore
import QtQuick
import QtQuick.Controls
import QtQuick.Dialogs
// TODO:
// - make designer-friendly
ApplicationWindow {
id: window
width: 1024
height: 600
visible: true
Add load/save functionality to QQuickTextDocument (Tech Preview) Since QTBUG-92155 is not done, we need an easy way to load and save text into and out of a QTextDocument in QML. This patch follows the pattern from Image and other types: add a `source` property, a URL from which the file is to be loaded. When it comes to saving, the pattern is not set: so far the only file writing that has been available from QML is ItemGrabResult.saveToFile(). Since we need to save in specific formats, it makes sense to continue that pattern: the text document knows how to do its own serialization, so this is not suitable for generic data file I/O, even if we did have a QML API for that. We add invokable functions save() and saveAs() for the usual use cases in word processors and such. The URL extension determines the file format. Setting QQuickTextDocument's source is not allowed if the document has unsaved changes. The user (app author) needs to call save() or override modified to false first. [ChangeLog][QtQuick][TextEdit] TextEdit.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. [ChangeLog][Controls][TextArea] TextArea.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. Change-Id: I687318523c7a520e02244e47224d067da55318b5 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-11-06 14:14:06 +00:00
title: textArea.textDocument.source +
" - Text Editor Example" + (textArea.textDocument.modified ? " *" : "")
Action {
id: openAction
text: qsTr("&Open")
shortcut: StandardKey.Open
Add load/save functionality to QQuickTextDocument (Tech Preview) Since QTBUG-92155 is not done, we need an easy way to load and save text into and out of a QTextDocument in QML. This patch follows the pattern from Image and other types: add a `source` property, a URL from which the file is to be loaded. When it comes to saving, the pattern is not set: so far the only file writing that has been available from QML is ItemGrabResult.saveToFile(). Since we need to save in specific formats, it makes sense to continue that pattern: the text document knows how to do its own serialization, so this is not suitable for generic data file I/O, even if we did have a QML API for that. We add invokable functions save() and saveAs() for the usual use cases in word processors and such. The URL extension determines the file format. Setting QQuickTextDocument's source is not allowed if the document has unsaved changes. The user (app author) needs to call save() or override modified to false first. [ChangeLog][QtQuick][TextEdit] TextEdit.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. [ChangeLog][Controls][TextArea] TextArea.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. Change-Id: I687318523c7a520e02244e47224d067da55318b5 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-11-06 14:14:06 +00:00
onTriggered: {
if (textArea.textDocument.modified)
discardDialog.open()
else
openDialog.open()
}
}
Action {
id: saveAction
text: qsTr("&Save…")
Add load/save functionality to QQuickTextDocument (Tech Preview) Since QTBUG-92155 is not done, we need an easy way to load and save text into and out of a QTextDocument in QML. This patch follows the pattern from Image and other types: add a `source` property, a URL from which the file is to be loaded. When it comes to saving, the pattern is not set: so far the only file writing that has been available from QML is ItemGrabResult.saveToFile(). Since we need to save in specific formats, it makes sense to continue that pattern: the text document knows how to do its own serialization, so this is not suitable for generic data file I/O, even if we did have a QML API for that. We add invokable functions save() and saveAs() for the usual use cases in word processors and such. The URL extension determines the file format. Setting QQuickTextDocument's source is not allowed if the document has unsaved changes. The user (app author) needs to call save() or override modified to false first. [ChangeLog][QtQuick][TextEdit] TextEdit.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. [ChangeLog][Controls][TextArea] TextArea.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. Change-Id: I687318523c7a520e02244e47224d067da55318b5 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-11-06 14:14:06 +00:00
shortcut: StandardKey.Save
enabled: textArea.textDocument.modified
Add load/save functionality to QQuickTextDocument (Tech Preview) Since QTBUG-92155 is not done, we need an easy way to load and save text into and out of a QTextDocument in QML. This patch follows the pattern from Image and other types: add a `source` property, a URL from which the file is to be loaded. When it comes to saving, the pattern is not set: so far the only file writing that has been available from QML is ItemGrabResult.saveToFile(). Since we need to save in specific formats, it makes sense to continue that pattern: the text document knows how to do its own serialization, so this is not suitable for generic data file I/O, even if we did have a QML API for that. We add invokable functions save() and saveAs() for the usual use cases in word processors and such. The URL extension determines the file format. Setting QQuickTextDocument's source is not allowed if the document has unsaved changes. The user (app author) needs to call save() or override modified to false first. [ChangeLog][QtQuick][TextEdit] TextEdit.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. [ChangeLog][Controls][TextArea] TextArea.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. Change-Id: I687318523c7a520e02244e47224d067da55318b5 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-11-06 14:14:06 +00:00
onTriggered: textArea.textDocument.save()
}
Action {
id: saveAsAction
text: qsTr("Save &As…")
shortcut: StandardKey.SaveAs
onTriggered: saveDialog.open()
}
Action {
id: quitAction
text: qsTr("&Quit")
shortcut: StandardKey.Quit
onTriggered: close()
}
Action {
id: copyAction
text: qsTr("&Copy")
shortcut: StandardKey.Copy
enabled: textArea.selectedText
onTriggered: textArea.copy()
}
Action {
id: cutAction
text: qsTr("Cu&t")
shortcut: StandardKey.Cut
enabled: textArea.selectedText
onTriggered: textArea.cut()
}
Action {
id: pasteAction
text: qsTr("&Paste")
shortcut: StandardKey.Paste
enabled: textArea.canPaste
onTriggered: textArea.paste()
}
Action {
id: boldAction
text: qsTr("&Bold")
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
onTriggered: textArea.cursorSelection.font.bold = checked
}
Action {
id: italicAction
text: qsTr("&Italic")
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
onTriggered: textArea.cursorSelection.font.italic = checked
}
Action {
id: underlineAction
text: qsTr("&Underline")
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
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
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
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
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
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
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
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
}
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()
}
}
menuBar: MenuBar {
Menu {
title: qsTr("&File")
MenuItem {
action: openAction
}
MenuItem {
action: saveAction
}
MenuItem {
action: saveAsAction
}
MenuItem {
action: quitAction
}
}
Menu {
title: qsTr("&Edit")
MenuItem {
action: copyAction
}
MenuItem {
action: cutAction
}
MenuItem {
action: pasteAction
}
}
Menu {
title: qsTr("F&ormat")
MenuItem {
action: boldAction
}
MenuItem {
action: italicAction
}
MenuItem {
action: underlineAction
}
MenuItem {
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
}
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
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
MenuItem {
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
}
MenuItem {
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
}
MenuItem {
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
}
MenuItem {
action: alignRightAction
}
}
}
FileDialog {
id: openDialog
fileMode: FileDialog.OpenFile
selectedNameFilter.index: 1
nameFilters: ["Text files (*.txt)", "HTML files (*.html *.htm)", "Markdown files (*.md *.markdown)"]
currentFolder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
Add load/save functionality to QQuickTextDocument (Tech Preview) Since QTBUG-92155 is not done, we need an easy way to load and save text into and out of a QTextDocument in QML. This patch follows the pattern from Image and other types: add a `source` property, a URL from which the file is to be loaded. When it comes to saving, the pattern is not set: so far the only file writing that has been available from QML is ItemGrabResult.saveToFile(). Since we need to save in specific formats, it makes sense to continue that pattern: the text document knows how to do its own serialization, so this is not suitable for generic data file I/O, even if we did have a QML API for that. We add invokable functions save() and saveAs() for the usual use cases in word processors and such. The URL extension determines the file format. Setting QQuickTextDocument's source is not allowed if the document has unsaved changes. The user (app author) needs to call save() or override modified to false first. [ChangeLog][QtQuick][TextEdit] TextEdit.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. [ChangeLog][Controls][TextArea] TextArea.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. Change-Id: I687318523c7a520e02244e47224d067da55318b5 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-11-06 14:14:06 +00:00
onAccepted: {
textArea.textDocument.modified = false // we asked earlier, if necessary
textArea.textDocument.source = selectedFile
}
}
FileDialog {
id: saveDialog
fileMode: FileDialog.SaveFile
nameFilters: openDialog.nameFilters
currentFolder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
Add load/save functionality to QQuickTextDocument (Tech Preview) Since QTBUG-92155 is not done, we need an easy way to load and save text into and out of a QTextDocument in QML. This patch follows the pattern from Image and other types: add a `source` property, a URL from which the file is to be loaded. When it comes to saving, the pattern is not set: so far the only file writing that has been available from QML is ItemGrabResult.saveToFile(). Since we need to save in specific formats, it makes sense to continue that pattern: the text document knows how to do its own serialization, so this is not suitable for generic data file I/O, even if we did have a QML API for that. We add invokable functions save() and saveAs() for the usual use cases in word processors and such. The URL extension determines the file format. Setting QQuickTextDocument's source is not allowed if the document has unsaved changes. The user (app author) needs to call save() or override modified to false first. [ChangeLog][QtQuick][TextEdit] TextEdit.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. [ChangeLog][Controls][TextArea] TextArea.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. Change-Id: I687318523c7a520e02244e47224d067da55318b5 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-11-06 14:14:06 +00:00
onAccepted: textArea.textDocument.saveAs(selectedFile)
}
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
}
ColorDialog {
id: colorDialog
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
}
MessageDialog {
title: qsTr("Error")
id: errorDialog
}
MessageDialog {
id : quitDialog
title: qsTr("Quit?")
text: qsTr("The file has been modified. Quit anyway?")
buttons: MessageDialog.Yes | MessageDialog.No
onButtonClicked: function (button, role) {
if (role === MessageDialog.YesRole) {
textArea.textDocument.modified = false
Qt.quit()
}
}
}
Add load/save functionality to QQuickTextDocument (Tech Preview) Since QTBUG-92155 is not done, we need an easy way to load and save text into and out of a QTextDocument in QML. This patch follows the pattern from Image and other types: add a `source` property, a URL from which the file is to be loaded. When it comes to saving, the pattern is not set: so far the only file writing that has been available from QML is ItemGrabResult.saveToFile(). Since we need to save in specific formats, it makes sense to continue that pattern: the text document knows how to do its own serialization, so this is not suitable for generic data file I/O, even if we did have a QML API for that. We add invokable functions save() and saveAs() for the usual use cases in word processors and such. The URL extension determines the file format. Setting QQuickTextDocument's source is not allowed if the document has unsaved changes. The user (app author) needs to call save() or override modified to false first. [ChangeLog][QtQuick][TextEdit] TextEdit.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. [ChangeLog][Controls][TextArea] TextArea.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. Change-Id: I687318523c7a520e02244e47224d067da55318b5 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
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()
}
}
header: ToolBar {
Flow {
width: parent.width
Row {
id: fileRow
ToolButton {
id: openButton
text: "\uF115" // icon-folder-open-empty
font.family: "fontello"
action: openAction
focusPolicy: Qt.TabFocus
}
Add load/save functionality to QQuickTextDocument (Tech Preview) Since QTBUG-92155 is not done, we need an easy way to load and save text into and out of a QTextDocument in QML. This patch follows the pattern from Image and other types: add a `source` property, a URL from which the file is to be loaded. When it comes to saving, the pattern is not set: so far the only file writing that has been available from QML is ItemGrabResult.saveToFile(). Since we need to save in specific formats, it makes sense to continue that pattern: the text document knows how to do its own serialization, so this is not suitable for generic data file I/O, even if we did have a QML API for that. We add invokable functions save() and saveAs() for the usual use cases in word processors and such. The URL extension determines the file format. Setting QQuickTextDocument's source is not allowed if the document has unsaved changes. The user (app author) needs to call save() or override modified to false first. [ChangeLog][QtQuick][TextEdit] TextEdit.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. [ChangeLog][Controls][TextArea] TextArea.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. Change-Id: I687318523c7a520e02244e47224d067da55318b5 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-11-06 14:14:06 +00:00
ToolButton {
id: saveButton
text: "\uE80A" // icon-floppy-disk
font.family: "fontello"
action: saveAction
focusPolicy: Qt.TabFocus
}
ToolSeparator {
contentItem.visible: fileRow.y === editRow.y
}
}
Row {
id: editRow
ToolButton {
id: copyButton
text: "\uF0C5" // icon-docs
font.family: "fontello"
focusPolicy: Qt.TabFocus
action: copyAction
}
ToolButton {
id: cutButton
text: "\uE802" // icon-scissors
font.family: "fontello"
focusPolicy: Qt.TabFocus
action: cutAction
}
ToolButton {
id: pasteButton
text: "\uF0EA" // icon-paste
font.family: "fontello"
focusPolicy: Qt.TabFocus
action: pasteAction
}
ToolSeparator {
contentItem.visible: editRow.y === formatRow.y
}
}
Row {
id: formatRow
ToolButton {
id: boldButton
text: "\uE800" // icon-bold
font.family: "fontello"
focusPolicy: Qt.TabFocus
action: boldAction
}
ToolButton {
id: italicButton
text: "\uE801" // icon-italic
font.family: "fontello"
focusPolicy: Qt.TabFocus
action: italicAction
}
ToolButton {
id: underlineButton
text: "\uF0CD" // icon-underline
font.family: "fontello"
focusPolicy: Qt.TabFocus
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
}
ToolButton {
id: fontFamilyToolButton
text: qsTr("\uE808") // icon-font
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
focusPolicy: Qt.TabFocus
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
fontDialog.open()
}
}
ToolButton {
id: textColorButton
text: "\uF1FC" // icon-brush
font.family: "fontello"
focusPolicy: Qt.TabFocus
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
colorDialog.open()
}
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
parent: textColorButton.contentItem
anchors.horizontalCenter: parent.horizontalCenter
anchors.baseline: parent.baseline
anchors.baselineOffset: 6
TextMetrics {
id: aFontMetrics
font: textColorButton.font
text: textColorButton.text
}
}
}
ToolSeparator {
contentItem.visible: formatRow.y === alignRow.y
}
}
Row {
id: alignRow
ToolButton {
id: alignLeftButton
text: "\uE803" // icon-align-left
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
}
ToolButton {
id: alignCenterButton
text: "\uE804" // icon-align-center
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
}
ToolButton {
id: alignRightButton
text: "\uE805" // icon-align-right
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
}
ToolButton {
id: alignJustifyButton
text: "\uE806" // icon-align-justify
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
}
}
}
}
Flickable {
id: flickable
flickableDirection: Flickable.VerticalFlick
anchors.fill: parent
ScrollBar.vertical: ScrollBar {}
TextArea.flickable: TextArea {
id: textArea
textFormat: Qt.AutoText
wrapMode: TextArea.Wrap
focus: true
selectByMouse: true
persistentSelection: true
// 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
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: contextMenu.popup()
}
onLinkActivated: function (link) {
Qt.openUrlExternally(link)
}
Add load/save functionality to QQuickTextDocument (Tech Preview) Since QTBUG-92155 is not done, we need an easy way to load and save text into and out of a QTextDocument in QML. This patch follows the pattern from Image and other types: add a `source` property, a URL from which the file is to be loaded. When it comes to saving, the pattern is not set: so far the only file writing that has been available from QML is ItemGrabResult.saveToFile(). Since we need to save in specific formats, it makes sense to continue that pattern: the text document knows how to do its own serialization, so this is not suitable for generic data file I/O, even if we did have a QML API for that. We add invokable functions save() and saveAs() for the usual use cases in word processors and such. The URL extension determines the file format. Setting QQuickTextDocument's source is not allowed if the document has unsaved changes. The user (app author) needs to call save() or override modified to false first. [ChangeLog][QtQuick][TextEdit] TextEdit.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. [ChangeLog][Controls][TextArea] TextArea.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. Change-Id: I687318523c7a520e02244e47224d067da55318b5 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-11-06 14:14:06 +00:00
Component.onCompleted: {
if (Qt.application.arguments.length === 2)
textDocument.source = "file:" + Qt.application.arguments[1]
else
textDocument.source = "qrc:/texteditor.html"
}
textDocument.onStatusChanged: {
// 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”"),
}
const err = statusMessages[textDocument.status]
if (err) {
errorDialog.text = err.arg(textDocument.source)
errorDialog.open()
}
Add load/save functionality to QQuickTextDocument (Tech Preview) Since QTBUG-92155 is not done, we need an easy way to load and save text into and out of a QTextDocument in QML. This patch follows the pattern from Image and other types: add a `source` property, a URL from which the file is to be loaded. When it comes to saving, the pattern is not set: so far the only file writing that has been available from QML is ItemGrabResult.saveToFile(). Since we need to save in specific formats, it makes sense to continue that pattern: the text document knows how to do its own serialization, so this is not suitable for generic data file I/O, even if we did have a QML API for that. We add invokable functions save() and saveAs() for the usual use cases in word processors and such. The URL extension determines the file format. Setting QQuickTextDocument's source is not allowed if the document has unsaved changes. The user (app author) needs to call save() or override modified to false first. [ChangeLog][QtQuick][TextEdit] TextEdit.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. [ChangeLog][Controls][TextArea] TextArea.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. Change-Id: I687318523c7a520e02244e47224d067da55318b5 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-11-06 14:14:06 +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()
}
}
}
onClosing: function (close) {
Add load/save functionality to QQuickTextDocument (Tech Preview) Since QTBUG-92155 is not done, we need an easy way to load and save text into and out of a QTextDocument in QML. This patch follows the pattern from Image and other types: add a `source` property, a URL from which the file is to be loaded. When it comes to saving, the pattern is not set: so far the only file writing that has been available from QML is ItemGrabResult.saveToFile(). Since we need to save in specific formats, it makes sense to continue that pattern: the text document knows how to do its own serialization, so this is not suitable for generic data file I/O, even if we did have a QML API for that. We add invokable functions save() and saveAs() for the usual use cases in word processors and such. The URL extension determines the file format. Setting QQuickTextDocument's source is not allowed if the document has unsaved changes. The user (app author) needs to call save() or override modified to false first. [ChangeLog][QtQuick][TextEdit] TextEdit.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. [ChangeLog][Controls][TextArea] TextArea.textDocument now has a source property for loading files; save() and saveAs() functions for writing; a modified property which tracks QTextDocument::modified; and an error signal in case any of these operations fail. Setting the source property is allowed only if the document is in unmodified state. This API is in Tech Preview. Change-Id: I687318523c7a520e02244e47224d067da55318b5 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-11-06 14:14:06 +00:00
if (textArea.textDocument.modified) {
quitDialog.open()
close.accepted = false
}
}
}