From 4b56661fd27cf6ce0c9410759fbd5c390e41dd69 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Fri, 2 Mar 2012 14:30:51 +1000 Subject: Update text examples to new guidelines Change-Id: I6bbf414f3734bc2f29a7182746c5df158a5924da Reviewed-by: Yann Bodson --- doc/src/examples/examples-groups.qdoc | 10 ------ examples/quick/text/fonts/availableFonts.qml | 4 +-- examples/quick/text/fonts/banner.qml | 2 +- examples/quick/text/fonts/fonts.qml | 30 +++++++++-------- examples/quick/text/fonts/hello.qml | 6 ++-- examples/quick/text/imgtag/TextWithImage.qml | 6 ---- examples/quick/text/imgtag/imgtag.qml | 10 ++---- examples/quick/text/main.cpp | 41 ++++++++++++++++++++++++ examples/quick/text/styledtext-layout.qml | 48 ++++------------------------ examples/quick/text/text.pro | 10 ++++++ examples/quick/text/text.qml | 14 +++++++- 11 files changed, 96 insertions(+), 85 deletions(-) create mode 100644 examples/quick/text/main.cpp create mode 100644 examples/quick/text/text.pro diff --git a/doc/src/examples/examples-groups.qdoc b/doc/src/examples/examples-groups.qdoc index 0ecd117128..85a9e51087 100644 --- a/doc/src/examples/examples-groups.qdoc +++ b/doc/src/examples/examples-groups.qdoc @@ -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 diff --git a/examples/quick/text/fonts/availableFonts.qml b/examples/quick/text/fonts/availableFonts.qml index 0b87259556..63a74d269b 100644 --- a/examples/quick/text/fonts/availableFonts.qml +++ b/examples/quick/text/fonts/availableFonts.qml @@ -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() @@ -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" } } } diff --git a/examples/quick/text/fonts/banner.qml b/examples/quick/text/fonts/banner.qml index 6c9aa25fa1..7f690c24c3 100644 --- a/examples/quick/text/fonts/banner.qml +++ b/examples/quick/text/fonts/banner.qml @@ -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 { diff --git a/examples/quick/text/fonts/fonts.qml b/examples/quick/text/fonts/fonts.qml index 78cef25eae..f0e9b60bc5 100644 --- a/examples/quick/text/fonts/fonts.qml +++ b/examples/quick/text/fonts/fonts.qml @@ -43,7 +43,7 @@ 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" } @@ -51,43 +51,45 @@ Rectangle { 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: { @@ -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 } } } diff --git a/examples/quick/text/fonts/hello.qml b/examples/quick/text/fonts/hello.qml index d9479fb208..8920329ddb 100644 --- a/examples/quick/text/fonts/hello.qml +++ b/examples/quick/text/fonts/hello.qml @@ -43,7 +43,7 @@ import QtQuick 2.0 Rectangle { id: screen - width: 800; height: 480 + width: 320; height: 480 color: "black" Item { @@ -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) diff --git a/examples/quick/text/imgtag/TextWithImage.qml b/examples/quick/text/imgtag/TextWithImage.qml index bc09aa2a52..5e6fba5df4 100644 --- a/examples/quick/text/imgtag/TextWithImage.qml +++ b/examples/quick/text/imgtag/TextWithImage.qml @@ -46,10 +46,4 @@ Text { wrapMode: Text.WordWrap textFormat: Text.StyledText horizontalAlignment: main.hAlign - - Rectangle { - border.color: "#efefef" - color: "transparent" - anchors.fill: parent - } } diff --git a/examples/quick/text/imgtag/imgtag.qml b/examples/quick/text/imgtag/imgtag.qml index 9d181af2cb..a28a4911c4 100644 --- a/examples/quick/text/imgtag/imgtag.qml +++ b/examples/quick/text/imgtag/imgtag.qml @@ -44,6 +44,7 @@ Rectangle { id: main width: 320; height: 480 focus: true + color: "#dedede" property var hAlign: Text.AlignLeft @@ -62,18 +63,13 @@ Rectangle { text: "This is a happy face" } TextWithImage { - text: "This is a veryhappy 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 venenatisLorem 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 veryhappy face vertically aligned in the middle." } TextWithImage { text: "This is a tinyhappy face." } TextWithImage { - text: "This is a starfishaligned to the top and another onealigned to the bottom." + text: "This is aaligned to the top and aaligned to the bottom." } TextWithImage { text: "Qt logosaligned in the middle with different sizes." diff --git a/examples/quick/text/main.cpp b/examples/quick/text/main.cpp new file mode 100644 index 0000000000..0c896d9ab7 --- /dev/null +++ b/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) diff --git a/examples/quick/text/styledtext-layout.qml b/examples/quick/text/styledtext-layout.qml index 4571330568..cb5e1ad277 100644 --- a/examples/quick/text/styledtext-layout.qml +++ b/examples/quick/text/styledtext-layout.qml @@ -46,12 +46,7 @@ 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 @@ -59,47 +54,18 @@ Rectangle { 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 www.nokia.com.
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.

Proin consectetur sapien 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 www.nokia.com.
Curabitur ante est, pulvinar quis adipiscing a, iaculis id ipsum. Nunc blandit condimentum odio vel egestas.

Proin consectetur sapien 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 } } } diff --git a/examples/quick/text/text.pro b/examples/quick/text/text.pro new file mode 100644 index 0000000000..ecd0762eda --- /dev/null +++ b/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 + diff --git a/examples/quick/text/text.qml b/examples/quick/text/text.qml index 9bfd290059..e9c40773c9 100644 --- a/examples/quick/text/text.qml +++ b/examples/quick/text/text.qml @@ -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 @@ -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")); } } } -- cgit v1.2.3