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>
This commit is contained in:
Oliver Eftevaag 2023-03-03 12:27:25 +01:00
parent 8ec8133aa2
commit ba79f20f31
7 changed files with 135 additions and 47 deletions

View File

@ -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

View File

@ -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
}
}
}

View File

@ -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
}
}
}

View File

@ -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
}
}
}
}

View File

@ -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
}
}
}
}

View File

@ -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"));
}
}
}

View File

@ -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