9ee8ae81203a234fc1597bb2d844d338835c5e67
[profile/ivi/qtdeclarative.git] / examples / declarative / qtquick1 / righttoleft / layoutmirroring / layoutmirroring.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the examples of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
11 **
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
14 ** met:
15 **   * Redistributions of source code must retain the above copyright
16 **     notice, this list of conditions and the following disclaimer.
17 **   * Redistributions in binary form must reproduce the above copyright
18 **     notice, this list of conditions and the following disclaimer in
19 **     the documentation and/or other materials provided with the
20 **     distribution.
21 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 **     the names of its contributors may be used to endorse or promote
23 **     products derived from this software without specific prior written
24 **     permission.
25 **
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 import QtQuick 1.1
42
43 Rectangle {
44     id: root
45     property bool mirror: Qt.application.layoutDirection == Qt.RightToLeft
46     LayoutMirroring.enabled: mirror
47     LayoutMirroring.childrenInherit: true
48     width: 400
49     height: 875
50     color: "lightsteelblue"
51
52     Column {
53         spacing: 10
54         anchors { left: parent.left; right: parent.right; top: parent.top; margins: 10 }
55
56         Text {
57             text: "Positioners"
58             anchors.left: parent.left
59         }
60
61         Column {
62             id: positioners
63             spacing: 5
64             anchors.left: parent.left
65             Row {
66                 id: row
67                 spacing: 4
68                 property string text: "THISISROW"
69                 anchors.left: parent.left
70                 Repeater {
71                     model: parent.text.length
72                     delegate: positionerDelegate
73                 }
74             }
75             Flow {
76                 id: flow
77                 spacing: 4
78                 width: 90
79                 property string text: "THISISFLOW"
80                 anchors.left: parent.left
81                 Repeater {
82                     model: parent.text.length
83                     delegate: positionerDelegate
84                 }
85             }
86             Grid {
87                 id: grid
88                 spacing: 4
89                 columns: 6
90                 property string text: "THISISGRID"
91                 anchors.left: parent.left
92                 Repeater {
93                     model: parent.text.length
94                     delegate: positionerDelegate
95                 }
96             }
97             Component {
98                 id: positionerDelegate
99                 Text {
100                     color: "white"
101                     font.pixelSize: 20
102                     text: parent.text[index]
103                     Rectangle {
104                         z: -1
105                         opacity: 0.7
106                         color: "black"
107                         anchors.fill: parent
108                     }
109                 }
110             }
111         }
112
113         Text {
114             text: "Text alignment"
115             anchors.left: parent.left
116         }
117
118         Rectangle {
119             id: textStrings
120             width: 148
121             height: 85
122             color: "white"
123             anchors.left: parent.left
124             Column {
125                 spacing: 5
126                 width: parent.width
127                 anchors { fill: parent; margins: 5 }
128                 Text {
129                     id: englishText
130                     width: parent.width
131                     text: "English text"
132                 }
133                 Text {
134                     id: arabicText
135                     width: parent.width
136                     text: "النص العربي"
137                 }
138                 Text {
139                     id: leftAlignedText
140                     width: parent.width
141                     text: "Text aligned to left"
142                     horizontalAlignment: Text.AlignLeft
143                 }
144                 Text {
145                     id: rightAlignedText
146                     width: parent.width
147                     text: "Text aligned to right"
148                     horizontalAlignment: Text.AlignRight
149                 }
150             }
151         }
152
153         Text {
154             text: "Model views"
155             anchors.left: parent.left
156         }
157
158         Column {
159             id: views
160             spacing: 10
161             anchors.left: parent.left
162             ListView {
163                 id: listView
164                 z: -1
165                 clip: true
166                 model: text.length
167                 width: 360; height: 45
168                 orientation: Qt.Horizontal
169                 property string text: "LISTVIEWLISTVIEWLISTVIEWLISTVIEWLISTVIEWLISTVIEW"
170                 delegate: Rectangle {
171                     color: "black"
172                     width: 45; height: 45
173                     Rectangle {
174                         anchors { fill: parent; margins: 1 }
175                         color: "red"
176                     }
177                     Text {
178                         text: listView.text[index]
179                         font.pixelSize: 30
180                         anchors.centerIn: parent
181                     }
182                 }
183             }
184             GridView {
185                 id: gridView
186                 z: -1
187                 clip: true
188                 model: text.length
189                 width: 180; height: 90
190                 cellWidth: 45; cellHeight: 45
191                 property string text: "GRIDVIEWGRIDVIEWGRIDVIEWGRIDVIEWGRIDVIEWGRIDVIEW"
192                 anchors.left: parent.left
193                 delegate: Rectangle {
194                     color: "black"
195                     width: 45; height: 45
196                     Rectangle {
197                         anchors { fill: parent; margins: 1 }
198                         color: "red"
199                     }
200                     Text {
201                         anchors.centerIn: parent
202                         font.pixelSize: 30
203                         text: gridView.text[index]
204                     }
205                 }
206             }
207         }
208
209         Text {
210             text: "Item x"
211             anchors.left: parent.left
212         }
213         Rectangle {
214             id: items
215             color: Qt.rgba(0.2, 0.2, 0.2, 0.6)
216             width: 275; height: 95
217             anchors.left: parent.left
218             Rectangle {
219                 y: 5; x: 5
220                 width: 130; height: 40
221                 Text {
222                     text: "Item with x: 5\n(not mirrored)"
223                     anchors.centerIn: parent
224                 }
225             }
226             Rectangle {
227                 color:  Qt.rgba(0.7, 0.7, 0.7)
228                 y: 50; x: mirror(5)
229                 width: 130; height: 40
230                 function mirror(value) {
231                     return LayoutMirroring.enabled ? (parent.width - width - value) : value;
232                 }
233                 Text {
234                     text: "Item with x: " + parent.x + "\n(manually mirrored)"
235                     anchors.centerIn: parent
236                 }
237             }
238         }
239         Text {
240             text: "Item anchors"
241             anchors.left: parent.left
242         }
243
244         Rectangle {
245             id: anchoredItems
246             color: Qt.rgba(0.2, 0.2, 0.2, 0.6)
247             width: 270; height: 170
248             anchors.left: parent.left
249             Rectangle {
250                 id: blackRectangle
251                 color: "black"
252                 width: 180; height: 90
253                 anchors { horizontalCenter: parent.horizontalCenter; horizontalCenterOffset: 30 }
254                 Text {
255                     text: "Horizontal center anchored\nwith offset 30\nto the horizontal center\nof the parent."
256                     color: "white"
257                     anchors.centerIn: parent
258                 }
259             }
260             Rectangle {
261                 id: whiteRectangle
262                 color: "white"
263                 width: 120; height: 70
264                 anchors { left: parent.left; bottom: parent.bottom }
265                 Text {
266                     text: "Left side anchored\nto the left side\nof the parent."
267                     color: "black"
268                     anchors.centerIn: parent
269                 }
270             }
271             Rectangle {
272                 id: grayRectangle
273                 color: Qt.rgba(0.7, 0.7, 0.7)
274                 width: 140; height: 90
275                 anchors { right: parent.right; bottom: parent.bottom }
276                 Text {
277                     text: "Right side anchored\nto the right side\nof the parent."
278                     anchors.centerIn: parent
279                 }
280             }
281         }
282         Rectangle {
283             id: mirrorButton
284             color: mouseArea2.pressed ? "black" : "gray"
285             height: 50; width: parent.width
286             anchors.left: parent.left
287             Column {
288                 anchors.centerIn: parent
289                 Text {
290                     text: root.mirror ? "Mirrored" : "Not mirrored"
291                     color: "white"
292                     font.pixelSize: 16
293                     anchors.horizontalCenter: parent.horizontalCenter
294                 }
295                 Text {
296                     text: "(click here to toggle)"
297                     color: "white"
298                     font.pixelSize: 10
299                     font.italic: true
300                     anchors.horizontalCenter: parent.horizontalCenter
301                 }
302             }
303             MouseArea {
304                 id: mouseArea2
305                 anchors.fill: parent
306                 onClicked: {
307                     root.mirror = !root.mirror;
308                 }
309             }
310         }
311     }
312 }
313