feature. You can run and observe the behavior of each example.
*/
/*!
- \title QML Examples - Text
- \example declarative/text
- \brief This is a collection of QML examples
- \image qml-text-example.png
-
- This is a collection of small QML examples relating to text. Each example is
- a small QML file, usually containing or emphasizing a particular element or
- feature. You can run and observe the behavior of each example.
-*/
-/*!
\title QML Examples - Touch Interaction
\example declarative/touchinteraction
\brief This is a collection of QML examples
import QtQuick 2.0
Rectangle {
- width: 480; height: 640; color: "steelblue"
+ width: 320; height: 480; color: "steelblue"
ListView {
anchors.fill: parent; model: Qt.fontFamilies()
height: 40; width: ListView.view.width
Text {
anchors.centerIn: parent
- text: modelData; font.family: modelData; font.pixelSize: 24; color: "white"
+ text: modelData; font.family: modelData; font.pixelSize: 20; color: "white"
}
}
}
property color textColor: "lightsteelblue"
property string text: "Hello world! "
- width: 640; height: 320
+ width: 320; height: 480
color: "steelblue"
Row {
Rectangle {
property string myText: "The quick brown fox jumps over the lazy dog."
- width: 800; height: 480
+ width: 320; height: 480
color: "steelblue"
FontLoader { id: fixedFont; name: "Courier" }
FontLoader { id: webFont; source: "http://www.princexml.com/fonts/steffmann/Starburst.ttf" }
Column {
- anchors { fill: parent; leftMargin: 10; rightMargin: 10 }
+ anchors { fill: parent; leftMargin: 10; rightMargin: 10; topMargin: 10 }
spacing: 15
Text {
text: myText
color: "lightsteelblue"
width: parent.width
- elide: Text.ElideRight
- font.family: "Times"; font.pointSize: 42
+ wrapMode: Text.WordWrap
+ font.family: "Times"; font.pixelSize: 20
}
Text {
text: myText
color: "lightsteelblue"
width: parent.width
- elide: Text.ElideLeft
- font { family: "Times"; pointSize: 42; capitalization: Font.AllUppercase }
+ wrapMode: Text.WordWrap
+ horizontalAlignment: Text.AlignHCenter
+ font { family: "Times"; pixelSize: 20; capitalization: Font.AllUppercase }
}
Text {
text: myText
color: "lightsteelblue"
width: parent.width
- elide: Text.ElideMiddle
- font { family: fixedFont.name; pointSize: 42; weight: Font.Bold; capitalization: Font.AllLowercase }
+ horizontalAlignment: Text.AlignRight
+ wrapMode: Text.WordWrap
+ font { family: fixedFont.name; pixelSize: 20; weight: Font.Bold; capitalization: Font.AllLowercase }
}
Text {
text: myText
color: "lightsteelblue"
width: parent.width
- elide: Text.ElideRight
- font { family: fixedFont.name; pointSize: 42; italic: true; capitalization: Font.SmallCaps }
+ wrapMode: Text.WordWrap
+ font { family: fixedFont.name; pixelSize: 20; italic: true; capitalization: Font.SmallCaps }
}
Text {
text: myText
color: "lightsteelblue"
width: parent.width
- elide: Text.ElideLeft
- font { family: localFont.name; pointSize: 42; capitalization: Font.Capitalize }
+ wrapMode: Text.WordWrap
+ font { family: localFont.name; pixelSize: 20; capitalization: Font.Capitalize }
}
Text {
text: {
}
color: "lightsteelblue"
width: parent.width
- elide: Text.ElideMiddle
- font.family: webFont.name; font.pointSize: 42
+ wrapMode: Text.WordWrap
+ font.family: webFont.name; font.pixelSize: 20
}
}
}
Rectangle {
id: screen
- width: 800; height: 480
+ width: 320; height: 480
color: "black"
Item {
anchors.centerIn: parent
color: "white"
text: "Hello world!"
- font.pixelSize: 60
+ font.pixelSize: 32
smooth: true
SequentialAnimation on font.letterSpacing {
loops: Animation.Infinite;
- NumberAnimation { from: 0; to: 150; easing.type: Easing.InQuad; duration: 3000 }
+ NumberAnimation { from: 0; to: 50; easing.type: Easing.InQuad; duration: 3000 }
ScriptAction {
script: {
container.y = (screen.height / 4) + (Math.random() * screen.height / 2)
wrapMode: Text.WordWrap
textFormat: Text.StyledText
horizontalAlignment: main.hAlign
-
- Rectangle {
- border.color: "#efefef"
- color: "transparent"
- anchors.fill: parent
- }
}
id: main
width: 320; height: 480
focus: true
+ color: "#dedede"
property var hAlign: Text.AlignLeft
text: "This is a <b>happy</b> face<img src=\"images/face-smile.png\">"
}
TextWithImage {
- text: "This is a <b>very<img src=\"images/face-smile-big.png\" align=\"middle\"/>happy</b> face aligned in the middle."
- }
- TextWithImage {
- elide: Text.ElideRight
- maximumLineCount: 2
- text: "This is a sad face aligned to the top. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc rutrum dui pretium ipsum malesuada venenatis. Nulla sed turpis risus. Integer sit amet odio quis mauris varius venenatis<img src=\"images/face-sad.png\" align=\"top\">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc rutrum dui pretium ipsum malesuada venenatis. Nulla sed turpis risus. Integer sit amet odio quis mauris varius venenatis."
+ text: "This is a <b>very<img src=\"images/face-smile-big.png\" align=\"middle\"/>happy</b> face vertically aligned in the middle."
}
TextWithImage {
text: "This is a tiny<img src=\"images/face-smile.png\" width=\"15\" height=\"15\">happy face."
}
TextWithImage {
- text: "This is a starfish<img src=\"images/starfish_2.png\" width=\"50\" height=\"50\" align=\"top\">aligned to the top and another one<img src=\"images/heart200.png\" width=\"50\" height=\"50\">aligned to the bottom."
+ text: "This is a<img src=\"images/starfish_2.png\" width=\"50\" height=\"50\" align=\"top\">aligned to the top and a<img src=\"images/heart200.png\" width=\"50\" height=\"50\">aligned to the bottom."
}
TextWithImage {
text: "Qt logos<img src=\"images/qtlogo.png\" width=\"55\" height=\"60\" align=\"middle\"><img src=\"images/qtlogo.png\" width=\"37\" height=\"40\" align=\"middle\"><img src=\"images/qtlogo.png\" width=\"18\" height=\"20\" align=\"middle\">aligned in the middle with different sizes."
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "../../shared/shared.h"
+DECLARATIVE_EXAMPLE_MAIN(text)
focus: true
property real offset: 0
- property real margin: 10
-
- Keys.onLeftPressed: myText.horizontalAlignment = Text.AlignLeft
- Keys.onUpPressed: myText.horizontalAlignment = Text.AlignHCenter
- Keys.onRightPressed: myText.horizontalAlignment = Text.AlignRight
- Keys.onDownPressed: myText.horizontalAlignment = Text.AlignJustify
+ property real margin: 8
Text {
id: myText
anchors.margins: 10
wrapMode: Text.WordWrap
font.family: "Times New Roman"
- font.pixelSize: 13
+ font.pixelSize: 14
textFormat: Text.StyledText
horizontalAlignment: Text.AlignJustify
- text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer at ante dui sed eu egestas est facilis <a href=\"www.nokia.com\">www.nokia.com</a>.<br/>Curabitur ante est, pulvinar quis adipiscing a, iaculis id ipsum. Phasellus id neque id velit facilisis cursus ac sit amet nibh. Donec enim arcu, pharetra non semper nec, iaculis eget elit. Nunc blandit condimentum odio vel egestas.<br><ul type=\"bullet\"><li>Coffee<ol type=\"a\"><li>Espresso<li><b>Cappuccino</b><li><i>Flat White</i><li>Latte</ol><li>Juice<ol type=\"1\"><li>Orange</li><li>Apple</li><li>Pineapple</li><li>Tomato</li></ol></li></ul><p><font color=\"#434343\"><i>Proin consectetur <b>sapien</b> in ipsum lacinia sit amet mattis orci interdum. Quisque vitae accumsan lectus. Ut nisi turpis, sollicitudin ut dignissim id, fermentum ac est. Maecenas nec libero leo. Sed ac leo eget ipsum ultricies viverra sit amet eu orci. Praesent et tortor risus, viverra accumsan sapien. Sed faucibus eleifend lectus, sed euismod urna porta eu. Aenean ultricies lectus ut orci dictum quis convallis nisi ultrices. Nunc elit mi, iaculis a porttitor rutrum, venenatis malesuada nisi. Suspendisse turpis quam, euismod non imperdiet et, rutrum nec ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit."
+ text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer at ante dui <a href=\"www.nokia.com\">www.nokia.com</a>.<br/>Curabitur ante est, pulvinar quis adipiscing a, iaculis id ipsum. Nunc blandit condimentum odio vel egestas.<br><ul type=\"bullet\"><li>Coffee<ol type=\"a\"><li>Espresso<li>Cappuccino<li>Latte</ol><li>Juice<ol type=\"1\"><li>Orange</li><li>Apple</li><li>Pineapple</li><li>Tomato</li></ol></li></ul><p><font color=\"#434343\"><i>Proin consectetur <b>sapien</b> in ipsum lacinia sit amet mattis orci interdum. Quisque vitae accumsan lectus. Ut nisi turpis, sollicitudin ut dignissim id, fermentum ac est. Maecenas nec libero leo. Sed ac leo eget ipsum ultricies viverra sit amet eu orci. Praesent et tortor risus, viverra accumsan sapien. Sed faucibus eleifend lectus, sed euismod urna porta eu. Quisque vitae accumsan lectus. Ut nisi turpis, sollicitudin ut dignissim id, fermentum ac est. Maecenas nec libero leo. Sed ac leo eget ipsum ultricies viverra sit amet eu orci."
onLineLaidOut: {
- line.width = width / 2 - (2 * margin)
- if (line.number === 30) {
- main.offset = line.y
- }
- if (line.number >= 30) {
- line.x = width / 2 + margin
- line.y -= main.offset
- }
- if ((line.y + line.height) > rect.y && line.y < (rect.y + rect.height)) {
- if (line.number < 30)
- line.width = Math.min((rect.x - line.x), line.width)
- else {
- line.x = Math.max((rect.x + rect.width), width / 2 + margin)
- line.width = Math.min((width - margin - line.x), line.width)
- }
- }
- }
-
- Item {
- id: rect
- x: 28; y: 20
- width: 60; height: 60
+ line.width = width / 2 - (margin)
- Rectangle {
- anchors { fill: parent; leftMargin: 2; rightMargin: 2 }
- color: "lightsteelblue"; opacity: 0.3
- }
-
- MouseArea {
- anchors.fill: parent
- drag.target: rect
- acceptedButtons: Qt.LeftButton | Qt.RightButton
- onClicked: mouse.button == Qt.RightButton ? myText.font.pixelSize -= 1 : myText.font.pixelSize += 1
- onPositionChanged: myText.doLayout()
+ if (line.y + line.height >= height) {
+ line.y -= height - margin
+ line.x = width / 2 + margin
}
}
}
--- /dev/null
+TEMPLATE = app
+
+QT += quick declarative
+SOURCES += main.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/qtdeclarative/qtquick/text
+qml.files = fonts imgtag styledtext-layout.qml text.qml textselection
+qml.path = $$[QT_INSTALL_EXAMPLES]/qtdeclarative/qtquick/text
+INSTALLS += target qml
+
import QtQuick 2.0
import "../../shared"
+/*!
+ \title QML Examples - Text
+ \example declarative/text
+ \brief This is a collection of QML examples
+ \image qml-text-example.png
+
+ This is a collection of small QML examples relating to text. Each example is
+ a small QML file, usually containing or emphasizing a particular element or
+ feature. You can run and observe the behavior of each example.
+*/
Item {
height: 480
- width: 480
+ width: 320
LauncherList {
id: ll
anchors.fill: parent
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"));
}
}
}