diff options
author | Oliver Eftevaag <oliver.eftevaag@qt.io> | 2023-03-03 12:27:25 +0100 |
---|---|---|
committer | Oliver Eftevaag <oliver.eftevaag@qt.io> | 2023-03-10 10:04:01 +0100 |
commit | ba79f20f3170dd365345c3ba89efbbd754fe474d (patch) | |
tree | 032fda3e3596f77efb375018d168892028243cb0 /examples/quick | |
parent | 8ec8133aa2119bf311bf4f1bf6db25d6705204b7 (diff) |
Text example: adhere to guidelines
- mark readonly properties as readonly.
- Use qsTr() on user facing strings that would be sensible to localize.
- Removed unused lines of code.
- Separate lines with multiple bindings into multiple lines instead.
Pick-to: 6.5
Change-Id: I9664cc2291be2f642dc2d9d27b6c356880a491c7
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'examples/quick')
-rw-r--r-- | examples/quick/text/fonts/availableFonts.qml | 7 | ||||
-rw-r--r-- | examples/quick/text/fonts/banner.qml | 31 | ||||
-rw-r--r-- | examples/quick/text/fonts/fonts.qml | 51 | ||||
-rw-r--r-- | examples/quick/text/fonts/hello.qml | 29 | ||||
-rw-r--r-- | examples/quick/text/styledtext-layout.qml | 12 | ||||
-rw-r--r-- | examples/quick/text/text.qml | 13 | ||||
-rw-r--r-- | examples/quick/text/textselection/textselection.qml | 39 |
7 files changed, 135 insertions, 47 deletions
diff --git a/examples/quick/text/fonts/availableFonts.qml b/examples/quick/text/fonts/availableFonts.qml index 2564bb6447..7f4f938b48 100644 --- a/examples/quick/text/fonts/availableFonts.qml +++ b/examples/quick/text/fonts/availableFonts.qml @@ -4,7 +4,9 @@ import QtQuick Rectangle { - width: 320; height: 480; color: "steelblue" + width: 320 + height: 480 + color: "steelblue" ListView { anchors.fill: parent @@ -13,7 +15,8 @@ Rectangle { //! [model] delegate: Item { - height: 40; width: ListView.view.width + height: 40 + width: ListView.view.width required property string modelData Text { anchors.centerIn: parent diff --git a/examples/quick/text/fonts/banner.qml b/examples/quick/text/fonts/banner.qml index 2c0742018a..aae93baea2 100644 --- a/examples/quick/text/fonts/banner.qml +++ b/examples/quick/text/fonts/banner.qml @@ -8,17 +8,36 @@ Rectangle { property int pixelSize: screen.height * 1.25 property color textColor: "lightsteelblue" - property string text: "Hello world! " + readonly property string text: qsTr("Hello world! ") - width: 320; height: 480 + width: 320 + height: 480 color: "steelblue" Row { y: -screen.height / 4.5 - NumberAnimation on x { from: 0; to: -text.width; duration: 6000; loops: Animation.Infinite } - Text { id: text; font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text } - Text { font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text } - Text { font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text } + NumberAnimation on x { + from: 0 + to: -text.width + duration: 6000 + loops: Animation.Infinite + } + Text { + id: text + font.pixelSize: screen.pixelSize + color: screen.textColor + text: screen.text + } + Text { + font.pixelSize: screen.pixelSize + color: screen.textColor + text: screen.text + } + Text { + font.pixelSize: screen.pixelSize + color: screen.textColor + text: screen.text + } } } diff --git a/examples/quick/text/fonts/fonts.qml b/examples/quick/text/fonts/fonts.qml index 8e0f906493..84cb6baa20 100644 --- a/examples/quick/text/fonts/fonts.qml +++ b/examples/quick/text/fonts/fonts.qml @@ -5,20 +5,32 @@ import QtQuick Rectangle { id: root - property string myText: "The quick brown fox jumps over the lazy dog." + readonly property string myText: qsTr("The quick brown fox jumps over the lazy dog.") - width: 320; height: 480 + width: 320 + height: 480 color: "steelblue" //! [fontloaderlocal] - FontLoader { id: localFont; source: "content/fonts/tarzeau_ocr_a.ttf" } + FontLoader { + id: localFont + source: "content/fonts/tarzeau_ocr_a.ttf" + } //! [fontloaderlocal] //! [fontloaderremote] - FontLoader { id: webFont; source: "http://www.princexml.com/fonts/steffmann/Starburst.ttf" } + FontLoader { + id: webFont + source: "http://www.princexml.com/fonts/steffmann/Starburst.ttf" + } //! [fontloaderremote] Column { - anchors { fill: parent; leftMargin: 10; rightMargin: 10; topMargin: 10 } + anchors { + fill: parent + leftMargin: 10 + rightMargin: 10 + topMargin: 10 + } spacing: 15 Text { @@ -37,7 +49,11 @@ Rectangle { width: parent.width wrapMode: Text.WordWrap horizontalAlignment: Text.AlignHCenter - font { family: "Times"; pixelSize: 20; capitalization: Font.AllUppercase } + font { + family: "Times" + pixelSize: 20 + capitalization: Font.AllUppercase + } } Text { text: root.myText @@ -45,21 +61,35 @@ Rectangle { width: parent.width horizontalAlignment: Text.AlignRight wrapMode: Text.WordWrap - font { family: "Courier"; pixelSize: 20; weight: Font.Bold; capitalization: Font.AllLowercase } + font { + family: "Courier" + pixelSize: 20 + weight: Font.Bold + capitalization: Font.AllLowercase + } } Text { text: root.myText color: "lightsteelblue" width: parent.width wrapMode: Text.WordWrap - font { family: "Courier"; pixelSize: 20; italic: true; capitalization: Font.SmallCaps } + font { + family: "Courier" + pixelSize: 20 + italic: true + capitalization: Font.SmallCaps + } } Text { text: root.myText color: "lightsteelblue" width: parent.width wrapMode: Text.WordWrap - font { family: localFont.name; pixelSize: 20; capitalization: Font.Capitalize } + font { + family: localFont.name + pixelSize: 20 + capitalization: Font.Capitalize + } } Text { text: { @@ -70,7 +100,8 @@ Rectangle { color: "lightsteelblue" width: parent.width wrapMode: Text.WordWrap - font.family: webFont.name; font.pixelSize: 20 + font.family: webFont.name + font.pixelSize: 20 } } } diff --git a/examples/quick/text/fonts/hello.qml b/examples/quick/text/fonts/hello.qml index e0cdc26ea6..89760b0b4b 100644 --- a/examples/quick/text/fonts/hello.qml +++ b/examples/quick/text/fonts/hello.qml @@ -6,24 +6,31 @@ import QtQuick Rectangle { id: screen - width: 320; height: 480 + width: 320 + height: 480 color: "black" Item { id: container - x: screen.width / 2; y: screen.height / 2 + x: screen.width / 2 + y: screen.height / 2 Text { id: text anchors.centerIn: parent color: "white" - text: "Hello world!" + text: qsTr("Hello world!") font.pixelSize: 32 //! [letterspacing] SequentialAnimation on font.letterSpacing { - loops: Animation.Infinite; - NumberAnimation { from: 0; to: 50; easing.type: Easing.InQuad; duration: 3000 } + loops: Animation.Infinite + NumberAnimation { + from: 0 + to: 50 + easing.type: Easing.InQuad + duration: 3000 + } ScriptAction { script: { container.y = (screen.height / 4) + (Math.random() * screen.height / 2) @@ -34,9 +41,15 @@ Rectangle { //! [letterspacing] SequentialAnimation on opacity { - loops: Animation.Infinite; - NumberAnimation { from: 1; to: 0; duration: 2600 } - PauseAnimation { duration: 400 } + loops: Animation.Infinite + NumberAnimation { + from: 1 + to: 0 + duration: 2600 + } + PauseAnimation { + duration: 400 + } } } } diff --git a/examples/quick/text/styledtext-layout.qml b/examples/quick/text/styledtext-layout.qml index 4f63d3ea90..1f99729488 100644 --- a/examples/quick/text/styledtext-layout.qml +++ b/examples/quick/text/styledtext-layout.qml @@ -5,11 +5,12 @@ import QtQuick Rectangle { id: main - width: 320; height: 480 - focus: true - property real offset: 0 - property real margin: 8 + readonly property real margin: 8 + + width: 320 + height: 480 + focus: true Text { id: myText @@ -47,11 +48,10 @@ Rectangle { Text { id: theEndText - text: "THE\nEND" + text: qsTr("THE\nEND") anchors.centerIn: parent font.pixelSize: myText.font.pixelSize / 2 } } } - } diff --git a/examples/quick/text/text.qml b/examples/quick/text/text.qml index 8f1c24ebc2..f16c0bf13a 100644 --- a/examples/quick/text/text.qml +++ b/examples/quick/text/text.qml @@ -8,15 +8,14 @@ Item { height: 480 width: 320 LauncherList { - id: ll anchors.fill: parent Component.onCompleted: { - addExample("Hello", "An Animated Hello World", Qt.resolvedUrl("fonts/hello.qml")); - addExample("Fonts", "Using various fonts with a Text element", Qt.resolvedUrl("fonts/fonts.qml")); - addExample("Available Fonts", "A list of your available fonts", Qt.resolvedUrl("fonts/availableFonts.qml")); - addExample("Banner", "Large, scrolling text", Qt.resolvedUrl("fonts/banner.qml")); - addExample("Img tag", "Embedding images into text", Qt.resolvedUrl("imgtag/imgtag.qml")); - addExample("Text Layout", "Flowing text around items", Qt.resolvedUrl("styledtext-layout.qml")); + addExample(qsTr("Hello"), qsTr("An Animated Hello World"), Qt.resolvedUrl("fonts/hello.qml")); + addExample(qsTr("Fonts"), qsTr("Using various fonts with a Text element"), Qt.resolvedUrl("fonts/fonts.qml")); + addExample(qsTr("Available Fonts"), qsTr("A list of your available fonts"), Qt.resolvedUrl("fonts/availableFonts.qml")); + addExample(qsTr("Banner"), qsTr("Large, scrolling text"), Qt.resolvedUrl("fonts/banner.qml")); + addExample(qsTr("Img tag"), qsTr("Embedding images into text"), Qt.resolvedUrl("imgtag/imgtag.qml")); + addExample(qsTr("Text Layout"), qsTr("Flowing text around items"), Qt.resolvedUrl("styledtext-layout.qml")); } } } diff --git a/examples/quick/text/textselection/textselection.qml b/examples/quick/text/textselection/textselection.qml index d4224ee14c..9585354b18 100644 --- a/examples/quick/text/textselection/textselection.qml +++ b/examples/quick/text/textselection/textselection.qml @@ -5,7 +5,8 @@ import QtQuick Rectangle { id: editor color: "lightGrey" - width: 640; height: 480 + width: 640 + height: 480 Rectangle { color: "white" @@ -98,11 +99,17 @@ Rectangle { width: 60 height: 16 - Text { anchors.centerIn: parent; text: "Cut" } + Text { + anchors.centerIn: parent + text: qsTr("Cut") + } MouseArea { anchors.fill: parent - onClicked: { edit.cut(); editor.state = "" } + onClicked: function() { + edit.cut() + editor.state = "" + } } } @@ -113,11 +120,17 @@ Rectangle { width: 60 height: 16 - Text { anchors.centerIn: parent; text: "Copy" } + Text { + anchors.centerIn: parent + text: qsTr("Copy") + } MouseArea { anchors.fill: parent - onClicked: { edit.copy(); editor.state = "selection" } + onClicked: function() { + edit.copy() + editor.state = "selection" + } } } @@ -128,11 +141,18 @@ Rectangle { width: 60 height: 16 - Text { anchors.centerIn: parent; text: "Paste" } + Text { + anchors.centerIn: parent + text: qsTr("Paste") + } MouseArea { anchors.fill: parent - onClicked: { edit.paste(); edit.cursorPosition = edit.selectionEnd; editor.state = "" } + onClicked: function() { + edit.paste() + edit.cursorPosition = edit.selectionEnd + editor.state = "" + } } } @@ -143,7 +163,10 @@ Rectangle { width: 60 height: 16 - Text { anchors.centerIn: parent; text: "Deselect" } + Text { + anchors.centerIn: parent + text: qsTr("Deselect") + } MouseArea { anchors.fill: parent |