~pkunal-parmar/ubuntu-calendar-app/ICalImport

« back to all changes in this revision

Viewing changes to TimeLineBaseComponent.qml

New Calendar App management tests. Fixes: https://bugs.launchpad.net/bugs/1300354.

Approved by Ubuntu Phone Apps Jenkins Bot, Nicholas Skaggs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013-2014 Canonical Ltd
 
3
 *
 
4
 * This file is part of Ubuntu Calendar App
 
5
 *
 
6
 * Ubuntu Calendar App is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License version 3 as
 
8
 * published by the Free Software Foundation.
 
9
 *
 
10
 * Ubuntu Calendar App is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
import QtQuick 2.3
 
20
import QtQuick.Layouts 1.1
 
21
import Ubuntu.Components 1.1
 
22
import Ubuntu.Components.Popups 1.0
 
23
import QtOrganizer 5.0
 
24
 
 
25
import "dateExt.js" as DateExt
 
26
import "ViewType.js" as ViewType
 
27
 
 
28
Item {
 
29
    id: root
 
30
 
 
31
    property var keyboardEventProvider;
 
32
 
 
33
    property date startDay: DateExt.today();
 
34
    property int weekNumber: startDay.weekNumber();
 
35
    property bool isActive: false
 
36
    property alias contentY: timeLineView.contentY
 
37
    property alias contentInteractive: timeLineView.interactive
 
38
 
 
39
    property int type: ViewType.ViewTypeWeek
 
40
 
 
41
    //visible hour
 
42
    property int scrollHour;
 
43
 
 
44
    property EventListModel mainModel;
 
45
 
 
46
    signal dateSelected(var date);
 
47
 
 
48
    function scrollToCurrentTime() {
 
49
        var currentTime = new Date();
 
50
        scrollHour = currentTime.getHours();
 
51
 
 
52
        timeLineView.contentY = scrollHour * units.gu(8);
 
53
        if(timeLineView.contentY >= timeLineView.contentHeight - timeLineView.height) {
 
54
            timeLineView.contentY = timeLineView.contentHeight - timeLineView.height
 
55
        }
 
56
    }
 
57
 
 
58
    function scrollTocurrentDate() {
 
59
        if ( type != ViewType.ViewTypeWeek ){
 
60
            return;
 
61
        }
 
62
 
 
63
        var today = DateExt.today();
 
64
        var startOfWeek = today.weekStart(Qt.locale().firstDayOfWeek);
 
65
        var weekDay = today.getDay();
 
66
        if( startOfWeek.isSameDay(startDay) && weekDay > 2) {
 
67
            timeLineView.contentX = (weekDay * timeLineView.delegateWidth);
 
68
            if( timeLineView.contentX  > (timeLineView.contentWidth - timeLineView.width) ) {
 
69
                timeLineView.contentX = timeLineView.contentWidth - timeLineView.width
 
70
            }
 
71
        } else {
 
72
            timeLineView.contentX = 0;
 
73
        }
 
74
    }
 
75
 
 
76
    Connections{
 
77
        target: keyboardEventProvider
 
78
        onScrollUp:{
 
79
            scrollHour--;
 
80
            if( scrollHour < 0) {
 
81
                scrollHour = 0;
 
82
            }
 
83
            scrollToHour();
 
84
        }
 
85
 
 
86
        onScrollDown:{
 
87
            scrollHour++;
 
88
            var visibleHour = root.height / units.gu(8);
 
89
            if( scrollHour > (25 -visibleHour)) {
 
90
                scrollHour = 25 - visibleHour;
 
91
            }
 
92
            scrollToHour();
 
93
        }
 
94
    }
 
95
 
 
96
    function scrollToHour() {
 
97
        timeLineView.contentY = scrollHour * units.gu(8);
 
98
        if(timeLineView.contentY >= timeLineView.contentHeight - timeLineView.height) {
 
99
            timeLineView.contentY = timeLineView.contentHeight - timeLineView.height
 
100
        }
 
101
    }
 
102
 
 
103
    Timer{
 
104
       interval: 200; running: true; repeat: false
 
105
       onTriggered: {
 
106
           mainModel = modelComponent.createObject();
 
107
           activityLoader.running = Qt.binding( function (){ return mainModel.isLoading;});
 
108
       }
 
109
    }
 
110
 
 
111
    Component {
 
112
        id: modelComponent
 
113
        EventListModel {
 
114
            id: mainModel
 
115
            startPeriod: startDay.midnight();
 
116
            endPeriod: type == ViewType.ViewTypeWeek ? startPeriod.addDays(7).endOfDay(): startPeriod.endOfDay()
 
117
            filter: eventModel.filter
 
118
        }
 
119
    }
 
120
 
 
121
    ActivityIndicator {
 
122
        id: activityLoader
 
123
        visible: running
 
124
        objectName : "activityIndicator"
 
125
        anchors.centerIn: parent
 
126
        z:2
 
127
    }
 
128
 
 
129
    Column {
 
130
        anchors.fill: parent
 
131
 
 
132
        TimeLineHeader{
 
133
            id: header
 
134
            objectName: "viewHeader"
 
135
            startDay: root.startDay
 
136
            contentX: timeLineView.contentX
 
137
            type: root.type
 
138
 
 
139
            onDateSelected: {
 
140
                root.dateSelected(date);
 
141
            }
 
142
        }
 
143
 
 
144
        SimpleDivider{}
 
145
 
 
146
        Row {
 
147
            width: parent.width
 
148
            height: parent.height - header.height
 
149
 
 
150
            TimeLineTimeScale{
 
151
                contentY: timeLineView.contentY
 
152
            }
 
153
 
 
154
            SimpleDivider{
 
155
                width: units.gu(0.1)
 
156
                height: parent.height
 
157
            }
 
158
 
 
159
            Flickable {
 
160
                id: timeLineView
 
161
                objectName: "timelineview"
 
162
 
 
163
                height: parent.height
 
164
                width: parent.width - units.gu(6)
 
165
 
 
166
                boundsBehavior: Flickable.StopAtBounds
 
167
 
 
168
                property int delegateWidth: {
 
169
                    if( type == ViewType.ViewTypeWeek ) {
 
170
                        width/3 - units.gu(1) /*partial visible area*/
 
171
                    } else {
 
172
                        width
 
173
                    }
 
174
                }
 
175
 
 
176
                contentHeight: units.gu(8) * 24
 
177
                contentWidth: {
 
178
                    if( type == ViewType.ViewTypeWeek ) {
 
179
                        delegateWidth*7
 
180
                    } else {
 
181
                        width
 
182
                    }
 
183
                }
 
184
 
 
185
                clip: true
 
186
 
 
187
                TimeLineBackground{}
 
188
 
 
189
                Row {
 
190
                    id: week
 
191
                    anchors.fill: parent
 
192
                    Repeater {
 
193
                        model: type == ViewType.ViewTypeWeek ? 7 : 1
 
194
 
 
195
                        delegate: TimeLineBase {
 
196
                            property int idx: index
 
197
                            anchors.top: parent.top
 
198
                            width: {
 
199
                                if( type == ViewType.ViewTypeWeek ) {
 
200
                                    parent.width / 7
 
201
                                } else {
 
202
                                    (parent.width)
 
203
                                }
 
204
                            }
 
205
                            height: parent.height
 
206
                            delegate: comp
 
207
                            day: startDay.addDays(index)
 
208
                            model: mainModel
 
209
 
 
210
                            Connections{
 
211
                                target: mainModel
 
212
 
 
213
                                onModelChanged: {
 
214
                                    createEvents();
 
215
                                }
 
216
                            }
 
217
 
 
218
                            DropArea {
 
219
                                id: dropArea
 
220
                                objectName: "mouseArea"
 
221
                                anchors.fill: parent
 
222
 
 
223
                                 function modifyEventForDrag(drag) {
 
224
                                    var event = drag.source.event;
 
225
                                    var diff = event.endDateTime.getTime() - event.startDateTime.getTime();
 
226
 
 
227
                                    var startDate = getTimeFromYPos(drag.y, day);
 
228
                                    var endDate = new Date( startDate.getTime() + diff );
 
229
 
 
230
                                    event.startDateTime = startDate;
 
231
                                    event.endDateTime = endDate;
 
232
 
 
233
                                     return event;
 
234
                                }
 
235
 
 
236
                                onDropped: {
 
237
                                    var event = dropArea.modifyEventForDrag(drop);
 
238
                                    model.saveItem(event);
 
239
                                }
 
240
 
 
241
                                onPositionChanged: {
 
242
                                    dropArea.modifyEventForDrag(drag)
 
243
                                    var eventBubble = drag.source;
 
244
                                    eventBubble.assingnBgColor();
 
245
                                    eventBubble.setDetails();
 
246
 
 
247
                                    if( eventBubble.y + eventBubble.height + units.gu(8) > timeLineView.contentY + timeLineView.height ) {
 
248
                                        var diff = Math.abs((eventBubble.y + eventBubble.height + units.gu(8))  -
 
249
                                                            (timeLineView.height + timeLineView.contentY));
 
250
                                        timeLineView.contentY += diff
 
251
 
 
252
                                        if(timeLineView.contentY >= timeLineView.contentHeight - timeLineView.height) {
 
253
                                            timeLineView.contentY = timeLineView.contentHeight - timeLineView.height
 
254
                                        }
 
255
                                    }
 
256
 
 
257
                                    if(eventBubble.y - units.gu(8) < timeLineView.contentY ) {
 
258
                                        var diff = Math.abs((eventBubble.y - units.gu(8))  - timeLineView.contentY);
 
259
                                        timeLineView.contentY -= diff
 
260
 
 
261
                                        if(timeLineView.contentY <= 0) {
 
262
                                            timeLineView.contentY = 0;
 
263
                                        }
 
264
                                    }
 
265
                                }
 
266
                            }
 
267
 
 
268
                            Loader{
 
269
                                objectName: "weekdevider"
 
270
                                height: parent.height
 
271
                                width: units.gu(0.15)
 
272
                                sourceComponent: type == ViewType.ViewTypeWeek ? weekDividerComponent : undefined
 
273
                            }
 
274
 
 
275
                            Component {
 
276
                                id: weekDividerComponent
 
277
                                SimpleDivider{
 
278
                                    anchors.fill: parent
 
279
                                }
 
280
                            }
 
281
 
 
282
                            Connections{
 
283
                                target: mainModel
 
284
                                onStartPeriodChanged:{
 
285
                                    destroyAllChildren();
 
286
                                }
 
287
                            }
 
288
                        }
 
289
                    }
 
290
                }
 
291
            }
 
292
        }
 
293
    }
 
294
 
 
295
    Component {
 
296
        id: comp
 
297
        EventBubble {
 
298
            type: root.type == ViewType.ViewTypeWeek ? narrowType : wideType
 
299
            flickable: root.isActive ? timeLineView : null
 
300
            clip: true
 
301
        }
 
302
    }
 
303
}