Handle MouseArea.enabled = false after mouse is pressed.
[profile/ivi/qtdeclarative.git] / examples / qml / text / styledtext-layout.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the examples of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 **     the names of its contributors may be used to endorse or promote
22 **     products derived from this software without specific prior written
23 **     permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 import QtQuick 2.0
42
43 Rectangle {
44     id: main
45     width: 320; height: 480
46     focus: true
47
48     property real offset: 0
49     property real margin: 10
50
51     Keys.onLeftPressed: myText.horizontalAlignment = Text.AlignLeft
52     Keys.onUpPressed: myText.horizontalAlignment = Text.AlignHCenter
53     Keys.onRightPressed: myText.horizontalAlignment = Text.AlignRight
54     Keys.onDownPressed: myText.horizontalAlignment = Text.AlignJustify
55
56     Text {
57         id: myText
58         anchors.fill: parent
59         anchors.margins: 10
60         wrapMode: Text.WordWrap
61         font.family: "Times New Roman"
62         font.pixelSize: 13
63         textFormat: Text.StyledText
64         horizontalAlignment: Text.AlignJustify
65
66         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."
67
68         onLineLaidOut: {
69             line.width = width / 2  - (2 * margin)
70             if (line.number === 30) {
71                 main.offset = line.y
72             }
73             if (line.number >= 30) {
74                 line.x = width / 2 + margin
75                 line.y -= main.offset
76             }
77             if ((line.y + line.height) > rect.y && line.y < (rect.y + rect.height)) {
78                 if (line.number < 30)
79                     line.width = Math.min((rect.x - line.x), line.width)
80                 else {
81                     line.x = Math.max((rect.x + rect.width), width / 2 + margin)
82                     line.width = Math.min((width - margin - line.x), line.width)
83                 }
84             }
85         }
86
87         Item {
88             id: rect
89             x: 28; y: 20
90             width: 60; height: 60
91
92             Rectangle {
93                 anchors { fill: parent; leftMargin: 2; rightMargin: 2 }
94                 color: "lightsteelblue"; opacity: 0.3
95             }
96
97             MouseArea {
98                 anchors.fill: parent
99                 drag.target: rect
100                 acceptedButtons: Qt.LeftButton | Qt.RightButton
101                 onClicked: mouse.button == Qt.RightButton ? myText.font.pixelSize -= 1 : myText.font.pixelSize += 1
102                 onPositionChanged: myText.doLayout()
103             }
104         }
105     }
106
107 }