~pkunal-parmar/ubuntu-calendar-app/Minor-Performance

400.1.1 by mihirsoni-123
Added copyright header comments in all the pages
1
/*
400.1.2 by mihirsoni-123
updated copyright year
2
 * Copyright (C) 2013-2014 Canonical Ltd
400.1.1 by mihirsoni-123
Added copyright header comments in all the pages
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
 */
455.4.4 by Nekhelesh Ramananthan
Improved week views
18
19
import QtQuick 2.3
20
import QtQuick.Layouts 1.1
422.5.1 by Akiva Avraham
Upgraded component library imports
21
import Ubuntu.Components 1.1
22
import Ubuntu.Components.Popups 1.0
191.4.1 by Kunal Parmar
Applying changes
23
import QtOrganizer 5.0
96.2.1 by Kunal Parmar
initial version
24
import "dateExt.js" as DateExt
191.4.1 by Kunal Parmar
Applying changes
25
import "ViewType.js" as ViewType
96.2.1 by Kunal Parmar
initial version
26
96.2.2 by Kunal Parmar
final weekview and dayview
27
Item {
96.2.1 by Kunal Parmar
initial version
28
    id: root
29
522.1.1 by Kunal Parmar
week day view performance improvements
30
    property var keyboardEventProvider;
31
96.2.1 by Kunal Parmar
initial version
32
    property var startDay: DateExt.today();
295.1.1 by Kunal Parmar
Parallex fix for EventBubble
33
    property bool isActive: false
151.1.1 by Kunal Parmar
Day view all component act as one
34
    property alias contentY: timeLineView.contentY
35
    property alias contentInteractive: timeLineView.interactive
96.2.1 by Kunal Parmar
initial version
36
191.4.1 by Kunal Parmar
Applying changes
37
    property int type: ViewType.ViewTypeWeek
96.2.1 by Kunal Parmar
initial version
38
183.1.1 by Kunal Parmar
Key Navigation implemented
39
    //visible hour
183.1.9 by Kunal Parmar
Merge issue resolved
40
    property int scrollHour;
183.1.1 by Kunal Parmar
Key Navigation implemented
41
216.1.2 by Kunal Parmar
Refactoring
42
    function scrollToCurrentTime() {
43
        var currentTime = new Date();
183.1.9 by Kunal Parmar
Merge issue resolved
44
        scrollHour = currentTime.getHours();
216.1.2 by Kunal Parmar
Refactoring
45
183.1.9 by Kunal Parmar
Merge issue resolved
46
        timeLineView.contentY = scrollHour * units.gu(10);
216.1.2 by Kunal Parmar
Refactoring
47
        if(timeLineView.contentY >= timeLineView.contentHeight - timeLineView.height) {
48
            timeLineView.contentY = timeLineView.contentHeight - timeLineView.height
216.1.1 by Kunal Parmar
scroll to currnt time
49
        }
96.2.2 by Kunal Parmar
final weekview and dayview
50
    }
51
183.1.1 by Kunal Parmar
Key Navigation implemented
52
    Connections{
522.1.1 by Kunal Parmar
week day view performance improvements
53
        target: keyboardEventProvider
183.1.1 by Kunal Parmar
Key Navigation implemented
54
        onScrollUp:{
55
            scrollHour--;
56
            if( scrollHour < 0) {
57
                scrollHour =0;
58
            }
183.1.9 by Kunal Parmar
Merge issue resolved
59
            scrollToHour();
183.1.1 by Kunal Parmar
Key Navigation implemented
60
        }
61
62
        onScrollDown:{
63
            scrollHour++;
64
            var visibleHour = root.height / units.gu(10);
183.1.9 by Kunal Parmar
Merge issue resolved
65
            if( scrollHour > (25 -visibleHour)) {
66
                scrollHour = 25 - visibleHour;
183.1.1 by Kunal Parmar
Key Navigation implemented
67
            }
183.1.9 by Kunal Parmar
Merge issue resolved
68
            scrollToHour();
183.1.1 by Kunal Parmar
Key Navigation implemented
69
        }
70
    }
71
72
    function scrollToHour() {
73
        timeLineView.contentY = scrollHour * units.gu(10);
74
        if(timeLineView.contentY >= timeLineView.contentHeight - timeLineView.height) {
75
            timeLineView.contentY = timeLineView.contentHeight - timeLineView.height
76
        }
77
    }
78
233.1.1 by Kunal Parmar
EventView performance improvement
79
    EventListModel {
80
        id: mainModel
81
        startPeriod: startDay.midnight();
82
        endPeriod: type == ViewType.ViewTypeWeek ? startPeriod.addDays(7).endOfDay(): startPeriod.endOfDay()
212.4.10 by Kunal Parmar
merge from trunk
83
        filter: eventModel.filter
233.1.1 by Kunal Parmar
EventView performance improvement
84
    }
85
253.2.1 by Kunal Parmar
Spinner on events loading
86
    ActivityIndicator {
87
        visible: running
391.1.6 by mihirsoni-123
fixed autopilot break by adding activity monitor wait
88
        objectName : "activityIndicator"
253.2.1 by Kunal Parmar
Spinner on events loading
89
        running: mainModel.isLoading
90
        anchors.centerIn: parent
91
        z:2
92
    }
233.1.1 by Kunal Parmar
EventView performance improvement
93
463.1.2 by Akiva Avraham
All Day events now look like this:
94
    AllDayEventComponent {
95
        id: allDayContainer
96
        type: root.type
97
        startDay: root.startDay
98
        model: mainModel
99
        z:1
100
        Component.onCompleted: {
101
            mainModel.addModelChangeListener(createAllDayEvents);
102
        }
103
        Component.onDestruction: {
104
            mainModel.removeModelChangeListener(createAllDayEvents);
105
        }
106
    }
107
530 by Kunal Parmar
some issue resolved
108
    Flickable {
109
        id: timeLineView
110
111
        contentHeight: units.gu(10) * 24
112
        contentWidth: width
455.4.4 by Nekhelesh Ramananthan
Improved week views
113
        anchors.fill: parent
96.2.1 by Kunal Parmar
initial version
114
530 by Kunal Parmar
some issue resolved
115
        clip: true
116
117
        TimeLineBackground {}
118
119
        Row {
120
            id: week
121
122
            anchors {
123
                fill: parent
124
                leftMargin: type == ViewType.ViewTypeWeek ? units.gu(0)
125
                                                          : units.gu(6)
126
127
                rightMargin: type == ViewType.ViewTypeWeek ? units.gu(0)
128
                                                          : units.gu(3)
129
            }
130
131
            Repeater {
132
                model: type == ViewType.ViewTypeWeek ? 7 : 1
133
134
                delegate: TimeLineBase {
135
                    property int idx: index
136
                    anchors.top: parent.top
137
                    width: {
138
                        if( type == ViewType.ViewTypeWeek ) {
139
                            parent.width / 7
140
                        } else {
141
                            (parent.width)
96.2.1 by Kunal Parmar
initial version
142
                        }
530 by Kunal Parmar
some issue resolved
143
                    }
144
145
                    height: parent.height
146
                    delegate: comp
147
                    day: startDay.addDays(index)
532 by Kunal Parmar
error resolved
148
                    model: mainModel
530 by Kunal Parmar
some issue resolved
149
150
                    Loader{
151
                        objectName: "weekdevider"
191.4.1 by Kunal Parmar
Applying changes
152
                        height: parent.height
530 by Kunal Parmar
some issue resolved
153
                        width: units.gu(0.15)
154
                        sourceComponent: type == ViewType.ViewTypeWeek ? weekDeviderComponent : undefined
155
                    }
156
157
                    Component {
158
                        id: weekDeviderComponent
159
                        Rectangle{
160
                            anchors.fill: parent
161
                            color: "#e5e2e2"
162
                        }
163
                    }
164
165
                    Connections{
166
                        target: mainModel
167
                        onStartPeriodChanged:{
168
                            destroyAllChildren();
169
                        }
170
                    }
96.2.1 by Kunal Parmar
initial version
171
                }
172
            }
173
        }
174
    }
175
222.3.10 by Bartosz Kosiorek
Fix indentation
176
    Component {
96.2.1 by Kunal Parmar
initial version
177
        id: comp
222.3.5 by Bartosz Kosiorek
Implementation of the quick add for Day and Week view
178
        EventBubble {
295.1.1 by Kunal Parmar
Parallex fix for EventBubble
179
            type: root.type == ViewType.ViewTypeWeek ? narrowType : wideType
180
            flickable: root.isActive ? timeLineView : null
191.4.1 by Kunal Parmar
Applying changes
181
            clip: true
96.2.1 by Kunal Parmar
initial version
182
        }
183
    }
184
}