~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to tests/system/qmlorganizer/contents/TimelineView.qml

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the examples of the Qt Mobility Components.
 
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 Digia Plc and its Subsidiary(-ies) nor the names
 
21
**     of its contributors may be used to endorse or promote products derived
 
22
**     from this software without specific prior written permission.
 
23
**
 
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
import QtOrganizer 5.0
 
43
import "timeline.js" as Timeline
 
44
 
 
45
Rectangle {
 
46
    id : timelineView
 
47
    anchors.fill : parent
 
48
    opacity : parent.opacity
 
49
    property int year:calendar.year
 
50
    property int month:calendar.month
 
51
    property int day:calendar.day
 
52
    Connections {
 
53
        target: calendar
 
54
        onCurrentDateChanged : {
 
55
            dayList.currentIndex = day - 1;
 
56
            monthList.currentIndex = month;
 
57
            yearList.currentIndex = year - yearModel.start;
 
58
        }
 
59
    }
 
60
 
 
61
    //Day view
 
62
    Rectangle {
 
63
        id: dayView
 
64
        color: "#9eaf30"
 
65
        gradient: Gradient {
 
66
            GradientStop {
 
67
                position: 0.00;
 
68
                color: "#9eaf30";
 
69
            }
 
70
            GradientStop {
 
71
                position: 0.89;
 
72
                color: "#ffffff";
 
73
            }
 
74
        }
 
75
        anchors.right : parent.right
 
76
        anchors.left : monthView.right
 
77
        anchors.top : parent.top
 
78
        anchors.bottom : parent.bottom
 
79
        opacity : parent.opacity
 
80
 
 
81
        ListView {
 
82
            id : dayList
 
83
            model : dayModel
 
84
            anchors.fill: parent
 
85
            clip: true
 
86
            focus: true
 
87
            opacity : parent.opacity
 
88
 
 
89
            delegate : dayDelegate
 
90
            highlight: dayHighlight
 
91
            preferredHighlightBegin: dayList.height * 0.5
 
92
            preferredHighlightEnd: preferredHighlightBegin
 
93
            highlightFollowsCurrentItem : true
 
94
            highlightMoveSpeed : 2000
 
95
            keyNavigationWraps : true
 
96
 
 
97
            onCurrentIndexChanged : {
 
98
                if (timelineView.opacity > 0) {
 
99
                    calendar.currentDate = new Date(timelineView.year, timelineView.month, currentIndex + 1);
 
100
                    monthList.currentIndex = timelineView.month;
 
101
                    currentIndex = timelineView.day - 1;
 
102
                }
 
103
            }
 
104
 
 
105
        }
 
106
 
 
107
        Component {
 
108
            id: dayHighlight
 
109
            Rectangle {
 
110
                width: dayList.width;
 
111
                height: dayList.height /7 ;
 
112
                color: "lightsteelblue" ;radius: 5
 
113
            }
 
114
        }
 
115
 
 
116
        Component {
 
117
            id: dayDelegate
 
118
            Item {
 
119
                width : dayList.width
 
120
                height : childrenRect.height
 
121
                Column {
 
122
                    Rectangle {
 
123
                        height : 1
 
124
                        width : dayList.width
 
125
                        color : "black"
 
126
                    }
 
127
                    Text {
 
128
                        text: day
 
129
                    }
 
130
                    Repeater {
 
131
                        focus: true
 
132
                        model:calendar.organizer.items? calendar.organizer.itemsByTimePeriod(new Date(timelineView.year,timelineView.month, index + 1),
 
133
                                                                                      new Date(timelineView.year,timelineView.month, index + 2))
 
134
                                                      : 0
 
135
 
 
136
                        Text {
 
137
                            clip: true
 
138
                            focus: true
 
139
                            text: "<a href=\"#\">" + modelData.displayLabel + "</a>"
 
140
                            onLinkActivated: {
 
141
                                detailsView.isNewItem = false
 
142
                                detailsView.item = modelData;
 
143
                                if (detailsView.item.itemType == Type.EventOccurrence || detailsView.item.itemType == Type.TodoOccurrence)
 
144
                                    calendar.state = "OccurrenceDialogView";
 
145
                                else
 
146
                                    calendar.state = "DetailsView";
 
147
                            }
 
148
                        }
 
149
                    }
 
150
                }
 
151
            }
 
152
        }
 
153
 
 
154
        ListModel {
 
155
            id : dayModel
 
156
            ListElement {day : "1"}
 
157
            ListElement {day : "2"}
 
158
            ListElement {day : "3"}
 
159
            ListElement {day : "4"}
 
160
            ListElement {day : "5"}
 
161
            ListElement {day : "6"}
 
162
            ListElement {day : "7"}
 
163
            ListElement {day : "8"}
 
164
            ListElement {day : "9"}
 
165
            ListElement {day : "10"}
 
166
            ListElement {day : "11"}
 
167
            ListElement {day : "12"}
 
168
            ListElement {day : "13"}
 
169
            ListElement {day : "14"}
 
170
            ListElement {day : "15"}
 
171
            ListElement {day : "16"}
 
172
            ListElement {day : "17"}
 
173
            ListElement {day : "18"}
 
174
            ListElement {day : "19"}
 
175
            ListElement {day : "20"}
 
176
            ListElement {day : "21"}
 
177
            ListElement {day : "22"}
 
178
            ListElement {day : "23"}
 
179
            ListElement {day : "24"}
 
180
            ListElement {day : "25"}
 
181
            ListElement {day : "26"}
 
182
            ListElement {day : "27"}
 
183
            ListElement {day : "28"}
 
184
            ListElement {day : "29"}
 
185
            ListElement {day : "30"}
 
186
            ListElement {day : "31"}
 
187
        }
 
188
    }
 
189
 
 
190
    //Month view
 
191
    Rectangle {
 
192
        id:monthView
 
193
        color : "lightgray"
 
194
        width : 30
 
195
        anchors.left : yearView.right
 
196
        anchors.top : parent.top
 
197
        anchors.bottom : parent.bottom
 
198
 
 
199
        ListView {
 
200
            id : monthList
 
201
            model : monthModel
 
202
            anchors.fill: parent
 
203
            clip: true
 
204
            delegate : monthDelegate
 
205
            highlight: monthHighlight
 
206
            preferredHighlightBegin: monthList.height * 0.5
 
207
            preferredHighlightEnd: preferredHighlightBegin
 
208
            highlightFollowsCurrentItem : true
 
209
            highlightMoveSpeed : 1000
 
210
            Component.onCompleted : {
 
211
               var now = new Date();
 
212
               var month = now.getMonth();
 
213
               monthList.currentIndex = month;
 
214
               var  d = Date.parse("Feb 31, 2010");
 
215
            }
 
216
            onCurrentIndexChanged : {
 
217
                if (timelineView.opacity > 0) {
 
218
                    calendar.currentDate = new Date(timelineView.year, currentIndex, timelineView.day);
 
219
                    currentIndex = timelineView.month;
 
220
                    dayList.currentIndex = timelineView.day - 1;
 
221
                }
 
222
            }
 
223
        }
 
224
 
 
225
        Component {
 
226
            id: monthHighlight
 
227
            Rectangle {
 
228
                width: monthList.width; height: monthList.height / 12 ; color: "lightsteelblue" ;radius: 5
 
229
            }
 
230
        }
 
231
 
 
232
        Component {
 
233
            id: monthDelegate
 
234
            Item {
 
235
                width : monthList.width
 
236
                height : monthList.height / 12
 
237
                Column {
 
238
                    Rectangle {
 
239
                        height : 1
 
240
                        width : monthList.width
 
241
                        color : "black"
 
242
                    }
 
243
                    Text {
 
244
                        text: month
 
245
                    }
 
246
                }
 
247
                MouseArea {
 
248
                    anchors.fill: parent
 
249
                    onClicked : monthList.currentIndex = index
 
250
                }
 
251
            }
 
252
        }
 
253
 
 
254
        ListModel {
 
255
            id : monthModel
 
256
            ListElement {month : "Jan"}
 
257
            ListElement {month : "Feb"}
 
258
            ListElement {month : "Mar"}
 
259
            ListElement {month : "Apr"}
 
260
            ListElement {month : "May"}
 
261
            ListElement {month : "Jun"}
 
262
            ListElement {month : "Jul"}
 
263
            ListElement {month : "Aug"}
 
264
            ListElement {month : "Sep"}
 
265
            ListElement {month : "Oct"}
 
266
            ListElement {month : "Nov"}
 
267
            ListElement {month : "Dec"}
 
268
        }
 
269
    }
 
270
 
 
271
    //Year view
 
272
    Rectangle {
 
273
        id:yearView
 
274
        color : "gray"
 
275
        anchors.top : parent.top
 
276
        anchors.bottom : parent.bottom
 
277
        anchors.left : parent.left
 
278
        width : 50
 
279
 
 
280
 
 
281
        Component {
 
282
            id: yearHighlight
 
283
            Rectangle {
 
284
                width: yearList.width; height: yearList.height / 10; color: "lightsteelblue" ;radius: 5
 
285
            }
 
286
        }
 
287
 
 
288
        Component {
 
289
            id: yearDelegate
 
290
 
 
291
            Item {
 
292
                width : yearList.width
 
293
                height : yearList.height / 10
 
294
                Column {
 
295
                    Rectangle {
 
296
                        height : 1
 
297
                        width : yearList.width
 
298
                        color : "black"
 
299
                    }
 
300
                    Text {
 
301
                        text: year
 
302
                    }
 
303
                }
 
304
                MouseArea {
 
305
                    anchors.fill: parent
 
306
                    onClicked : yearList.currentIndex = index
 
307
                }
 
308
            }
 
309
        }
 
310
 
 
311
 
 
312
        ListView {
 
313
            id : yearList
 
314
            model : yearModel
 
315
            delegate : yearDelegate
 
316
            anchors.fill: parent
 
317
            clip: true
 
318
            highlight: yearHighlight
 
319
 
 
320
            preferredHighlightBegin: yearList.height * 0.5
 
321
            preferredHighlightEnd: preferredHighlightBegin
 
322
            highlightRangeMode: "StrictlyEnforceRange"
 
323
            highlightFollowsCurrentItem : true
 
324
 
 
325
            Component.onCompleted: Timeline.extendYearModel(true);
 
326
            onCurrentIndexChanged: {
 
327
                Timeline.extendYearModel(false);
 
328
                if (timelineView.opacity > 0) {
 
329
                    calendar.currentDate = new Date(yearModel.start + currentIndex,  timelineView.month, timelineView.day);
 
330
                    monthList.currentIndex = timelineView.month;
 
331
                    dayList.currentIndex = timelineView.day - 1;
 
332
                }
 
333
            }
 
334
 
 
335
        ListModel {
 
336
            id : yearModel
 
337
            property int start : 0;
 
338
            property int end : 0;
 
339
 
 
340
            ListElement {
 
341
                year : 0;
 
342
            }
 
343
        }
 
344
    }
 
345
    }
 
346
}