diff options
| author | Shawn Rutledge <shawn.rutledge@qt.io> | 2024-01-22 18:52:47 -0700 |
|---|---|---|
| committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2024-01-23 12:34:26 -0700 |
| commit | 5647b6900b2ecc291022143176b545b933eca3a8 (patch) | |
| tree | c49bc648f00b63541a0a89a0141ff9b803f16147 /src/quick/doc/snippets | |
| parent | ba0816773308d3733cad0ac4a873d792a605f7ff (diff) | |
Replace TextEdit.textDocument.error signal with status property
If we make loading and saving asynchronous later, we'll need the same
sort of status property as in Image, Loader etc. to let the user QML
know when it's done, or when it has failed. Bindings are more flexible
than signal handlers; so we might as well have better-prepared API now.
To make use of the Status enum in QML, we need to de-anonymize
TextDocument and make it merely uncreatable. Anyway, it was already
referred to as the TextDocument type in the docs.
Pick-to: 6.7
Change-Id: Ia4354feba77995759797030382891308b941f0af
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src/quick/doc/snippets')
| -rw-r--r-- | src/quick/doc/snippets/qml/example.md | 146 | ||||
| -rw-r--r-- | src/quick/doc/snippets/qml/images/red.png | bin | 0 -> 130 bytes | |||
| -rw-r--r-- | src/quick/doc/snippets/qml/textEditStatusSwitch.qml | 34 |
3 files changed, 180 insertions, 0 deletions
diff --git a/src/quick/doc/snippets/qml/example.md b/src/quick/doc/snippets/qml/example.md new file mode 100644 index 0000000000..43956c7830 --- /dev/null +++ b/src/quick/doc/snippets/qml/example.md @@ -0,0 +1,146 @@ +# Markdown in Qt Quick + +The Text, TextEdit and TextArea items support rich text formatted in HTML. +Since Qt 5.14, they now support two dialects of Markdown as well: +[The CommonMark Specification](https://spec.commonmark.org/0.29/) is the +conservative formal specification, while +[GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) +adds extra features such as task lists and tables. + +## Font and Paragraph Styles + +Markdown supports **bold**, *italic*, ~~strikethrough~~ and `monospace` font +styles. + +> A block quote is indented according to the convention for email quoting. + + A block of code; + can be indented; + with 4 spaces or a tab; + +or + +``` +Block { + id: code + CanBe { + wrappedBy: "triple backticks" + } +} +``` + +Block quotes can be nested, and block quotes can include indented code blocks. + +In [The CommonMark Specification](https://spec.commonmark.org/0.29/) +John MacFarlane writes: + +> What distinguishes Markdown from many other lightweight markup syntaxes, +> which are often easier to write, is its readability. As Gruber writes: + +> > The overriding design goal for Markdown's formatting syntax is to make it +> > as readable as possible. The idea is that a Markdown-formatted document should +> > be publishable as-is, as plain text, without looking like it's been marked up +> > with tags or formatting instructions. ( +> > [http://daringfireball.net/projects/markdown/](http://daringfireball.net/projects/markdown/)) + +> The point can be illustrated by comparing a sample of AsciiDoc with an +> equivalent sample of Markdown. Here is a sample of AsciiDoc from the AsciiDoc +> manual: + +> 1. List item one. +> + +> List item one continued with a second paragraph followed by an +> Indented block. +> + +> ................. +> $ ls *.sh +> $ mv *.sh ~/tmp +> ................. +> + +> List item continued with a third paragraph. +> +> 2. List item two continued with an open block. +> ... +> + +## Hyperlinks + +Hyperlinks can be written with the link text first, and the URL immediately +following: [Qt Assistant](http://doc.qt.io/qt-6/qtassistant-index.html) + +A plain url is automatically recognized: https://doc.qt.io/qt-6/qml-qtquick-text.html + +There are also "reference links" where the link text is first labeled +and then the URL for the label is given elsewhere: +[The Qt Creator Manual][creatormanual] + +## Images + +Inline images like this one  flow with the surrounding text. + +The code for including an image is just a link that starts with a bang. +An image in its own paragraph is given its own space. + +## Lists + +Different kinds of lists can be included. Standard bullet lists can be nested, +using different symbols for each level of the list. List items can have nested +items such as block quotes, code blocks and images. Check boxes can be included +to form a task list. + +- Disc symbols are typically used for top-level list items. + * Circle symbols can be used to distinguish between items in lower-level + lists. + + Square symbols provide a reasonable alternative to discs and circles. + * Lists can be continued... + * further down +- List items can include images:  +- and even nested quotes, like this: + + The [Qt Documentation](https://doc.qt.io/qt-6/qml-qtquick-textedit.html#details) + points out that + > The TextEdit item displays a block of editable, formatted text. + > + > It can display both plain and rich text. For example: + > + > TextEdit { + > width: 240 + > text: "<b>Hello</b> <i>World!</i>" + > font.family: "Helvetica" + > font.pointSize: 20 + > color: "blue" + > focus: true + > } +- List items with check boxes allow task lists to be incorporated: + * [ ] This task is not yet done + * [x] We aced this one! + +Ordered lists can be used for tables of contents, for example. Each number +should end with a period or a parenthesis: + +1. Markdown in Qt Quick + 1) Font and Paragraph Styles + 5) Hyperlinks + 3) Images  + 2) Lists + 4) Tables +2. Related work + +The list will automatically be renumbered during rendering. + +## Thematic Breaks + +A horizontal rule is possible, as in HTML: + +- - - + +## Tables + +One of the GitHub extensions is support for tables: + +| |Development Tools |Programming Techniques |Graphical User Interfaces| +|-------------|------------------------------------|---------------------------|-------------------------| +|9:00 - 11:00 |Introduction to Qt ||| +|11:00 - 13:00|Using Qt Creator |QML and its runtime |Layouts in Qt | +|13:00 - 15:00|Qt Quick Designer Tutorial |Extreme Programming |Writing Custom Styles | +|15:00 - 17:00|Qt Linguist and Internationalization| | | diff --git a/src/quick/doc/snippets/qml/images/red.png b/src/quick/doc/snippets/qml/images/red.png Binary files differnew file mode 100644 index 0000000000..9038fef784 --- /dev/null +++ b/src/quick/doc/snippets/qml/images/red.png diff --git a/src/quick/doc/snippets/qml/textEditStatusSwitch.qml b/src/quick/doc/snippets/qml/textEditStatusSwitch.qml new file mode 100644 index 0000000000..d87e68f6cd --- /dev/null +++ b/src/quick/doc/snippets/qml/textEditStatusSwitch.qml @@ -0,0 +1,34 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +import QtQuick + +//! [0] +TextEdit { + id: edit + width: 300 + height: 200 + textDocument.source: "example.md" + wrapMode: TextEdit.WordWrap + + Text { + anchors { + bottom: parent.bottom + right: parent.right + } + color: edit.textDocument.status === TextDocument.Loaded ? "darkolivegreen" : "tomato" + text: + switch (edit.textDocument.status) { + case TextDocument.Loading: + return qsTr("Loading ") + edit.textDocument.source + case TextDocument.Loaded: + return qsTr("Loaded ") + edit.textDocument.source + case TextDocument.ReadError: + return qsTr("Failed to load ") + edit.textDocument.source + case TextDocument.NonLocalFileError: + return qsTr("Not a local file: ") + edit.textDocument.source + default: + return "Unexpected status " + edit.textDocument.status + ": " + edit.textDocument.source + } + } +} +//! [0] |
