Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / examples / declarative / modelviews / visualdatamodel / dragselection.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 Item {
44     id: root
45
46     width: 320
47     height: 480
48
49     property bool dragging: false
50
51     Component {
52         id: packageDelegate
53         Package {
54             id: packageRoot
55
56             MouseArea {
57                 id: visibleContainer
58                 Package.name: "visible"
59
60                 width: 64
61                 height: 64
62                 enabled: packageRoot.VisualDataModel.inSelected
63
64                 drag.target: draggable
65
66                 Item {
67                     id: draggable
68
69                     width: 64
70                     height: 64
71
72                     Drag.active: visibleContainer.drag.active
73
74                     anchors { horizontalCenter: parent.horizontalCenter; verticalCenter: parent.verticalCenter }
75
76                     states: State {
77                         when: visibleContainer.drag.active
78                         AnchorChanges { target:  draggable; anchors { horizontalCenter: undefined; verticalCenter: undefined} }
79                         ParentChange { target: selectionView; parent: draggable; x: 0; y: 0 }
80                         PropertyChanges { target: root; dragging: true }
81                         ParentChange { target: draggable; parent: root }
82                     }
83                 }
84                 DropArea {
85                     anchors.fill: parent
86                     onEntered: selectedItems.move(0, visualModel.items.get(packageRoot.VisualDataModel.itemsIndex), selectedItems.count)
87                 }
88             }
89             Item {
90                 id: selectionContainer
91                 Package.name: "selection"
92
93                 width: 64
94                 height: 64
95
96                 visible: PathView.onPath
97             }
98             Rectangle {
99                 id: content
100                 parent: visibleContainer
101
102                 width: 58
103                 height: 58
104
105                 radius: 8
106
107                 gradient: Gradient {
108                     GradientStop { id: gradientStart; position: 0.0; color: "#8AC953" }
109                     GradientStop { id: gradientEnd; position: 1.0; color: "#8BC953" }
110                 }
111
112                 border.width: 2
113                 border.color: "#007423"
114
115                 state: root.dragging && packageRoot.VisualDataModel.inSelected ? "selected" : "visible"
116
117                 Text {
118                     anchors.fill: parent
119                     horizontalAlignment: Text.AlignHCenter
120                     verticalAlignment: Text.AlignVCenter
121                     color: "white"
122                     text: modelData
123                     font.pixelSize: 18
124                 }
125
126                 Rectangle {
127                     anchors { right: parent.right; top: parent.top; margins: 3 }
128                     width: 12; height: 12
129                     color: packageRoot.VisualDataModel.inSelected ? "black" : "white"
130                     radius: 6
131
132                     border.color: "white"
133                     border.width: 2
134
135                     MouseArea {
136                         anchors.fill: parent
137                         onClicked: packageRoot.VisualDataModel.inSelected = !packageRoot.VisualDataModel.inSelected
138                     }
139                 }
140
141                 states: [
142                     State {
143                         name: "selected"
144                         ParentChange { target: content; parent: selectionContainer; x: 3; y: 3 }
145                         PropertyChanges { target: packageRoot; VisualDataModel.inItems: visibleContainer.drag.active }
146                         PropertyChanges { target: gradientStart; color: "#017423" }
147                         PropertyChanges { target: gradientStart; color: "#007423" }
148                     }, State {
149                         name: "visible"
150                         PropertyChanges { target: packageRoot; VisualDataModel.inItems: true }
151                         ParentChange { target: content; parent: visibleContainer; x: 3; y: 3 }
152                         PropertyChanges { target: gradientStart; color: "#8AC953" }
153                         PropertyChanges { target: gradientStart; color: "#8BC953" }
154                     }
155                 ]
156                 transitions: Transition {
157                     PropertyAction { target: packageRoot; properties: "VisualDataModel.inItems" }
158                     ParentAnimation {
159                         target: content
160                         NumberAnimation { target: content; properties: "x,y"; duration: 500 }
161                     }
162                     ColorAnimation { targets: [gradientStart, gradientEnd]; duration: 500 }
163                 }
164             }
165         }
166     }
167
168     VisualDataModel {
169         id: visualModel
170         model: 35
171         delegate: packageDelegate
172
173         groups: VisualDataGroup { id: selectedItems; name: "selected" }
174
175         Component.onCompleted:  parts.selection.filterOnGroup = "selected"
176     }
177
178     PathView {
179         id: selectionView
180
181         height: 64
182         width: 64
183
184         model: visualModel.parts.selection
185
186         path: Path {
187             startX: 0
188             startY: 0
189             PathLine { x: 64; y: 64 }
190         }
191     }
192
193     GridView {
194         id: itemsView
195         anchors { fill: parent }
196         cellWidth: 64
197         cellHeight: 64
198         model: visualModel.parts.visible
199     }
200 }