Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update text examples to new guidelines
Change-Id: I6bbf414f3734bc2f29a7182746c5df158a5924da
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
  • Loading branch information
Alan Alpert authored and Qt by Nokia committed Mar 9, 2012
1 parent 356bdc0 commit 4b56661
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 85 deletions.
10 changes: 0 additions & 10 deletions doc/src/examples/examples-groups.qdoc
Expand Up @@ -49,16 +49,6 @@
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 - 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
Expand Down
4 changes: 2 additions & 2 deletions examples/quick/text/fonts/availableFonts.qml
Expand Up @@ -41,7 +41,7 @@
import QtQuick 2.0

Rectangle {
width: 480; height: 640; color: "steelblue"
width: 320; height: 480; color: "steelblue"

ListView {
anchors.fill: parent; model: Qt.fontFamilies()
Expand All @@ -50,7 +50,7 @@ Rectangle {
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"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/quick/text/fonts/banner.qml
Expand Up @@ -47,7 +47,7 @@ Rectangle {
property color textColor: "lightsteelblue"
property string text: "Hello world! "

width: 640; height: 320
width: 320; height: 480
color: "steelblue"

Row {
Expand Down
30 changes: 16 additions & 14 deletions examples/quick/text/fonts/fonts.qml
Expand Up @@ -43,51 +43,53 @@ import QtQuick 2.0
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: localFont; source: "content/fonts/tarzeau_ocr_a.ttf" }
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: {
Expand All @@ -97,8 +99,8 @@ Rectangle {
}
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
}
}
}
6 changes: 3 additions & 3 deletions examples/quick/text/fonts/hello.qml
Expand Up @@ -43,7 +43,7 @@ import QtQuick 2.0
Rectangle {
id: screen

width: 800; height: 480
width: 320; height: 480
color: "black"

Item {
Expand All @@ -55,12 +55,12 @@ Rectangle {
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)
Expand Down
6 changes: 0 additions & 6 deletions examples/quick/text/imgtag/TextWithImage.qml
Expand Up @@ -46,10 +46,4 @@ Text {
wrapMode: Text.WordWrap
textFormat: Text.StyledText
horizontalAlignment: main.hAlign

Rectangle {
border.color: "#efefef"
color: "transparent"
anchors.fill: parent
}
}
10 changes: 3 additions & 7 deletions examples/quick/text/imgtag/imgtag.qml
Expand Up @@ -44,6 +44,7 @@ Rectangle {
id: main
width: 320; height: 480
focus: true
color: "#dedede"

property var hAlign: Text.AlignLeft

Expand All @@ -62,18 +63,13 @@ Rectangle {
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."
Expand Down
41 changes: 41 additions & 0 deletions examples/quick/text/main.cpp
@@ -0,0 +1,41 @@
/****************************************************************************
**
** 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)
48 changes: 7 additions & 41 deletions examples/quick/text/styledtext-layout.qml
Expand Up @@ -46,60 +46,26 @@ Rectangle {
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.fill: parent
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
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions examples/quick/text/text.pro
@@ -0,0 +1,10 @@
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

14 changes: 13 additions & 1 deletion examples/quick/text/text.qml
Expand Up @@ -40,10 +40,20 @@

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
Expand All @@ -52,6 +62,8 @@ Item {
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"));
}
}
}

0 comments on commit 4b56661

Please sign in to comment.