d526969ba662923bd96beb44f6fd1839e18fad54
[profile/ivi/qtdeclarative.git] / tests / testapplications / elements / content / FlickableElement.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 test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 import QtQuick 2.0
43
44 Item {
45     id: flickableelementtest
46     anchors.fill: parent
47     property string testtext: ""
48     property int sidelength: 1500
49
50     Rectangle {
51         id: flickableelementbox
52         color: "lightgray"; border.color: "gray"; radius: 5; clip: true; opacity: .1
53         height: 250; width: parent.width *.8
54         anchors.centerIn: parent
55
56         Flickable {
57             id: flickableelement
58             anchors.fill: parent
59             contentHeight: sidelength; contentWidth: sidelength; contentX: (sidelength/2)-125; contentY: (sidelength/2)-125
60             onAtYBeginningChanged: {
61                 if (flicking && atYBeginning && statenum == 1) { advance(); }
62                 else if (flicking && atYBeginning && atXBeginning && statenum == 4) { advance(); }
63             }
64             onAtXEndChanged: {
65                 if (atYEnd && atXEnd && statenum == 2) {
66                     if (flicking){ advance();
67                     } else {
68                         testtext = "The view must be flicked into the bottom left corner. Move the grid away slightly and try again"
69                     }
70                 }
71             }
72             onAtXBeginningChanged: {
73                 if (atYEnd && atXBeginning && statenum == 3) {
74                     if (!flicking) { advance(); } else { testtext = "Drag - do not flick. Move the grid away slightly and try again" }
75                 }
76             }
77
78             Row {
79                 width: sidelength; height: sidelength
80                 Repeater {
81                     model: 30
82                     Column {
83                         Repeater {
84                             id: griprep
85                             height: flickableelement.contentHeight; width: 50; model: 30
86                             Rectangle { height: 50; width: 50; color: "gray"; border.color: "black" }
87                         }
88                     }
89                 }
90             }
91             Text { anchors.centerIn: parent; text: "Center" }
92         }
93     }
94     Text { anchors.left: flickableelementbox.left; anchors.top: flickableelementbox.bottom; anchors.topMargin: 5;
95         text: "Dragging"; color: !flickableelement.flicking && flickableelement.moving ? "Green" : "Red"
96     }
97     Text { anchors.right: flickableelementbox.right; anchors.top: flickableelementbox.bottom; anchors.topMargin: 5;
98         text: "Flicking"; color: flickableelement.flicking ? "Green" : "Red"
99     }
100
101     SystemTestHelp { id: helpbubble; visible: statenum != 0
102         anchors { top: parent.top; horizontalCenter: parent.horizontalCenter; topMargin: 50 }
103     }
104     BugPanel { id: bugpanel }
105
106     states: [
107         State { name: "start"; when: statenum == 1
108             StateChangeScript { script: { flickableelement.contentX = (sidelength/2)-125; flickableelement.contentY = (sidelength/2)-125 } }
109             PropertyChanges { target: helpbubble; showadvance: false }
110             PropertyChanges { target: flickableelementtest
111                 testtext: "This is a Flickable element. At present it should be displaying a grid,\n"+
112                 "with the center marked and in the center of the view.\n"+
113                 "Next, please flick the view to the top" }
114         },
115         State { name: "top"; when: statenum == 2
116             PropertyChanges { target: helpbubble; showadvance: false }
117             PropertyChanges { target: flickableelementtest; testtext: "Good. Now flick to the bottom right hand corner." }
118         },
119         State { name: "bottomright"; when: statenum == 3
120             PropertyChanges { target: helpbubble; showadvance: false }
121             PropertyChanges { target: flickableelementtest; testtext: "Great. Now drag, not flick, the view to the bottom left." }
122         },
123         State { name: "bottomleft"; when: statenum == 4
124             PropertyChanges { target: helpbubble; showadvance: false }
125             PropertyChanges { target: flickableelementtest; testtext: "Almost there. Flick to the top left" }
126         },
127         State { name: "sections"; when: statenum == 5
128             PropertyChanges { target: helpbubble; showadvance: true }
129             PropertyChanges { target: flickableelementtest
130                 testtext: "Excellent.\n"+
131                 "Advance to restart the test." }
132         }
133     ]
134
135 }