aboutsummaryrefslogtreecommitdiffstats
path: root/examples/declarative/dragtarget/launcher/launcher.qml
blob: d3233c937ebfbf5c158240072cfb47af179ae809 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import QtQuick 2.0

Rectangle {
    id: root
    width:  480; height: 640

    gradient: Gradient {
        GradientStop { position: 0.0; color: "#FEFEF2" }
        GradientStop { position: 1.0; color: "#FEF0C9" }
    }

    GridView {
        id: applicationsView
        anchors {
            left: parent.left; top: parent.top; right: parent.right; bottom: favoritesFrame.top
            margins: 32
        }

        interactive: false

        add: Transition {
            NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad }
        }
        move: Transition {
            NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad }
        }

        model: VisualDataModel {
            id: applicationsVisualModel
            delegate: IconDelegate { drag.keys: [ "applications" ] }
            model: ListModel {
                id: applicationsModel

                ListElement { icon: "images/AudioPlayer_48.png" }
                ListElement { icon: "images/EMail_48.png" }
                ListElement { icon: "images/Camera_48.png" }
                ListElement { icon: "images/VideoPlayer_48.png" }
                ListElement { icon: "images/AddressBook_48.png" }
                ListElement { icon: "images/DateBook_48.png" }
                ListElement { icon: "images/TodoList_48.png" }
                ListElement { icon: "images/AudioPlayer_48.png" }
                ListElement { icon: "images/EMail_48.png" }
                ListElement { icon: "images/Camera_48.png" }
                ListElement { icon: "images/VideoPlayer_48.png" }
                ListElement { icon: "images/AddressBook_48.png" }
                ListElement { icon: "images/DateBook_48.png" }
                ListElement { icon: "images/TodoList_48.png" }
            }
        }
    }

    DragTarget {
        property int sourceIndex
        property int destinationIndex

        anchors.fill: applicationsView
        keys: [ "applications" ]

        onEntered: {
            sourceIndex = drag.data
            destinationIndex = sourceIndex
        }
        onPositionChanged: {
            var index = applicationsView.indexAt(drag.x, drag.y)
            if (index != -1) {
                applicationsVisualModel.move(destinationIndex, index, 1)
                destinationIndex = index
            }
        }
        onDropped: applicationsModel.move(sourceIndex, destinationIndex, 1)
        onExited: applicationsVisualModel.move(destinationIndex, sourceIndex, 1)
    }

    DragTarget {
        property int sourceIndex
        property int destinationIndex

        anchors.fill: applicationsView
        keys: [ "favorites" ]

        onEntered: {
            sourceIndex = drag.data
            destinationIndex = applicationsView.indexAt(drag.x, drag.y)
            if (destinationIndex != -1)
                applicationsVisualModel.insert(destinationIndex, favoritesVisualModel, sourceIndex, 1)
        }
        onPositionChanged: {
            var index = applicationsView.indexAt(drag.x, drag.y)
            if (index != -1) {
                if (destinationIndex != -1)
                    applicationsVisualModel.move(destinationIndex, index, 1)
                else
                    applicationsVisualModel.insert(index, favoritesVisualModel, sourceIndex, 1)
                destinationIndex = index
            }
        }
//        onDropped: applicationsModel.move(sourceIndex, destinationIndex, 1)
//        onExited: applicationsModel.move(destinationIndex, sourceIndex, 1)
        onExited: applicationsVisualModel.insert(sourceIndex, favoritesVisualModel, destinationIndex, 1)
    }

    Rectangle {
        id: favoritesFrame
        anchors { left: parent.left; right: parent.right; bottom: parent.bottom; margins: 24 }
        height: 96

        radius: 13

        gradient: Gradient {
            GradientStop { position: 0.0; color: "#D2691E" }
            GradientStop { position: 1.0; color: "#FF7F24" }
        }

        Rectangle {
            radius: 12
            anchors { fill: parent; leftMargin: 4; topMargin: 4; rightMargin: 1; bottomMargin: 1 }
            gradient: Gradient {
                GradientStop { position: 0.0; color: "#FEFEF2" }
                GradientStop { position: 1.0; color: "#FEF0C9" }
            }
        }

        ListView {
            id: favoritesView

            anchors { fill: parent; leftMargin: 32; topMargin: 24; rightMargin: 32; bottomMargin: 24 }

            interactive: false
            orientation: ListView.Horizontal
            spacing: 32

            add: Transition {
                NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad }
            }

            model: VisualDataModel {
                id: favoritesVisualModel
                delegate: IconDelegate { drag.keys: [ "favorites" ] }
                model: ListModel {
                    id: favoritesModel
                    ListElement { icon: "images/AudioPlayer_48.png" }
                    ListElement { icon: "images/EMail_48.png" }
                    ListElement { icon: "images/Camera_48.png" }
                    ListElement { icon: "images/VideoPlayer_48.png" }
                }
            }
        }

        DragTarget {
            property int sourceIndex
            property int destinationIndex

            anchors.fill: favoritesView
            keys: [ "favorites" ]

            onEntered: {
                sourceIndex = drag.data
                destinationIndex = sourceIndex
            }
            onPositionChanged: {
                var index = favoritesView.indexAt(drag.x, drag.y)
                if (index != -1) {
                    if (destinationIndex != -1)
                        favoritesVisualModel.move(destinationIndex, index, 1)
                    destinationIndex = index
                }
            }
            onDropped: favoritesModel.move(sourceIndex, destinationIndex, 1)
            onExited: favoritesVisualModel.move(destinationIndex, sourceIndex, 1)
        }

        DragTarget {
            property int sourceIndex
            property int destinationIndex

            enabled: favoritesVisualModel.count < 4

            anchors.fill: favoritesView
            keys: [ "applications" ]

            onEntered: {
                sourceIndex = drag.data
                destinationIndex = favoritesView.indexAt(drag.x, drag.y)
                if (destinationIndex != -1)
                    favoritesVisualModel.insert(destinationIndex, applicationsVisualModel, sourceIndex, 1)
            }
            onPositionChanged: {
                var index = favoritesView.indexAt(drag.x, drag.y)
                if (index != -1) {
                    if (destinationIndex != -1)
                        favoritesVisualModel.move(destinationIndex, index, 1)
                    else
                        favoritesVisualModel.insert(index, applicationsVisualModel, sourceIndex, 1)
                    destinationIndex = index
                }
            }
//            onDropped: favoritesModel.move(sourceIndex, destinationIndex, 1)
            onExited: favoritesVisualModel.insert(sourceIndex, applicationsVisualModel, destinationIndex, 1)
        }
    }
}