diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-08-10 12:35:25 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-08-10 16:20:06 +0200 |
commit | 0672882cab3aa2fa9695b4d6b1b3e894c6fa6ebb (patch) | |
tree | b8868ec9bd541047e5cf4425c4e3f8bb60d17a29 /examples/quickcontrols2/texteditor/qml | |
parent | 49ffc6e6af83b295c67fd119b79c925879cc292e (diff) |
Support Markdown in the TextEditor example, including local paths
The example still loads an HTML file from resources by default, but now
it's possible to give either a relative or absolute file path on the
command line to load an html, markdown or plain text file. Alternatively
you can use the file dialog to load any of these types. We assume that
any resources (such as images) with relative paths are to be loaded from
the directory where the source text file is.
Pick-to: 5.15
Change-Id: I37bc2d6aa2306016453770dc2fd66efa41a16618
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'examples/quickcontrols2/texteditor/qml')
-rw-r--r-- | examples/quickcontrols2/texteditor/qml/texteditor.qml | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/examples/quickcontrols2/texteditor/qml/texteditor.qml b/examples/quickcontrols2/texteditor/qml/texteditor.qml index 6c95335b..b1485582 100644 --- a/examples/quickcontrols2/texteditor/qml/texteditor.qml +++ b/examples/quickcontrols2/texteditor/qml/texteditor.qml @@ -173,7 +173,7 @@ ApplicationWindow { id: openDialog fileMode: FileDialog.OpenFile selectedNameFilter.index: 1 - nameFilters: ["Text files (*.txt)", "HTML files (*.html *.htm)"] + nameFilters: ["Text files (*.txt)", "HTML files (*.html *.htm)", "Markdown files (*.md *.markdown)"] folder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation) onAccepted: document.load(file) } @@ -383,8 +383,14 @@ ApplicationWindow { selectionStart: textArea.selectionStart selectionEnd: textArea.selectionEnd textColor: colorDialog.color - Component.onCompleted: document.load("qrc:/texteditor.html") + Component.onCompleted: { + if (Qt.application.arguments.length === 2) + document.load("file:" + Qt.application.arguments[1]); + else + document.load("qrc:/texteditor.html") + } onLoaded: { + textArea.textFormat = format textArea.text = text } onError: { |