~renatofilho/ubuntu-calendar-app/optimize

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.3.5 by Nekhelesh Ramananthan
Small change
18
614.1.132 by Renato Araujo Oliveira Filho
Update to ubuntu sdk 1.3 and qtquick 2.4
19
import QtQuick 2.4
614.47.1 by Kunal Parmar
updating toolkit
20
import Ubuntu.Components 1.3
645 by Renato Araujo Oliveira Filho
Merged: ~renatofilho/ubuntu-calendar-app/optimize-page-load
21
72.2.11 by Kunal Parmar
adding missing files
22
import "dateExt.js" as DateExt
191.4.1 by Kunal Parmar
Applying changes
23
import "ViewType.js" as ViewType
72.2.11 by Kunal Parmar
adding missing files
24
614.51.1 by Renato Araujo Oliveira Filho
Implemented Bottom edge for views.
25
PageWithBottomEdge {
338.1.1 by Nicholas Skaggs
restructure yearview, add test
26
    id: dayViewPage
27
    objectName: "dayViewPage"
72.2.31 by Kunal Parmar
Re-apply revision 98.
28
646 by Renato Araujo Oliveira Filho
Merged: ~renatofilho/ubuntu-calendar-app/bottom-edge
29
626 by Renato Araujo Oliveira Filho
Optimize views.
30
    property var anchorDate: new Date()
31
    readonly property var currentDate: dayViewPath.currentItem.startDay
72.2.11 by Kunal Parmar
adding missing files
32
508.2.1 by Kunal Parmar
bug fixed
33
    signal dateSelected(var date);
660 by Renato Araujo Oliveira Filho
Allow create all day events by pressing and hold at all day header.
34
    signal pressAndHoldAt(var date, bool allDay)
508.2.1 by Kunal Parmar
bug fixed
35
685 by Renato Araujo Oliveira Filho
After create a new event scroll view to new event position.
36
    function delayScrollToDate(date) {
687 by Renato Araujo Oliveira Filho
Fixed scroll to today for week view and day view.
37
        idleScroll.scrollToDate = new Date(date)
685 by Renato Araujo Oliveira Filho
After create a new event scroll view to new event position.
38
        idleScroll.restart()
39
    }
40
183.1.1 by Kunal Parmar
Key Navigation implemented
41
    Keys.forwardTo: [dayViewPath]
671 by Renato Araujo Oliveira Filho
Create new event based on scrolled view.
42
646 by Renato Araujo Oliveira Filho
Merged: ~renatofilho/ubuntu-calendar-app/bottom-edge
43
    createEventAt: currentDate
685 by Renato Araujo Oliveira Filho
After create a new event scroll view to new event position.
44
    onAnchorDateChanged: {
45
        dayViewPath.scrollToBegginer()
46
    }
47
48
    onEventCreated: {
687 by Renato Araujo Oliveira Filho
Fixed scroll to today for week view and day view.
49
        var eventDate = event.startDateTime
691 by Renato Araujo Oliveira Filho
Does not try to scroll to created event date if the event is already visible.
50
        var needScroll = false
687 by Renato Araujo Oliveira Filho
Fixed scroll to today for week view and day view.
51
        if ((currentDate.getFullYear() !== eventDate.getFullYear()) ||
52
            (currentDate.getMonth() !== eventDate.getMonth()) ||
53
            (currentDate.getDate() !== eventDate.getDate())) {
54
            anchorDate = event.startDateTime
691 by Renato Araujo Oliveira Filho
Does not try to scroll to created event date if the event is already visible.
55
            needScroll = true
56
        } else if (!dayViewPath.currentItem.timeIsVisible(eventDate)) {
57
            needScroll = true
687 by Renato Araujo Oliveira Filho
Fixed scroll to today for week view and day view.
58
        }
691 by Renato Araujo Oliveira Filho
Does not try to scroll to created event date if the event is already visible.
59
60
        if (needScroll)
61
            delayScrollToDate(event.startDateTime)
685 by Renato Araujo Oliveira Filho
After create a new event scroll view to new event position.
62
    }
63
455.3.1 by Mihir Soni
Removed duplicate header section from views and added common header
64
    Action {
455.3.6 by Nekhelesh Ramananthan
Just fixed the code indentation. No other change
65
        id: calendarTodayAction
66
        objectName:"todaybutton"
67
        iconName: "calendar-today"
68
        text: i18n.tr("Today")
69
        onTriggered: {
626 by Renato Araujo Oliveira Filho
Optimize views.
70
            anchorDate = new Date()
685 by Renato Araujo Oliveira Filho
After create a new event scroll view to new event position.
71
            delayScrollToDate(anchorDate)
72
        }
73
    }
74
75
76
    Timer {
77
        id: idleScroll
78
79
        property var scrollToDate: null
80
81
        interval: 200
82
        repeat:false
83
        onTriggered: {
84
            if (scrollToDate) {
85
                dayViewPath.currentItem.scrollToTime(scrollToDate)
86
                scrollToDate = null
87
            } else {
88
                dayViewPath.currentItem.scrollToBegin()
89
            }
455.3.6 by Nekhelesh Ramananthan
Just fixed the code indentation. No other change
90
        }
91
    }
455.3.1 by Mihir Soni
Removed duplicate header section from views and added common header
92
614.49.2 by Renato Araujo Oliveira Filho
Use new page header API.
93
    header: PageHeader {
94
        id: pageHeader
95
614.51.1 by Renato Araujo Oliveira Filho
Implemented Bottom edge for views.
96
        flickable: null
614.49.2 by Renato Araujo Oliveira Filho
Use new page header API.
97
        leadingActionBar.actions: tabs.tabsAction
98
        trailingActionBar.actions: [
455.5.1 by Nekhelesh Ramananthan
Improved DayView.qml
99
            calendarTodayAction,
100
            commonHeaderActions.showCalendarAction,
581.3.1 by Andrew Hayzen
* Add sync header action to AgendaView.qml DayView.qml MonthView.qml WeekView.qml YearView.qml
101
            commonHeaderActions.reloadAction,
614.41.1 by Gary.Wzl
1.UI fine-tuned for week number display in monthly view(bug #1464407)
102
            commonHeaderActions.syncCalendarAction,
103
            commonHeaderActions.settingsAction
455.5.1 by Nekhelesh Ramananthan
Improved DayView.qml
104
        ]
105
614.49.2 by Renato Araujo Oliveira Filho
Use new page header API.
106
        title: {
107
            // TRANSLATORS: this is a time formatting string,
108
            // see http://qt-project.org/doc/qt-5/qml-qtqml-date.html#details for valid expressions.
109
            // It's used in the header of the month and week views
614.51.1 by Renato Araujo Oliveira Filho
Implemented Bottom edge for views.
110
            var monthName = currentDate.toLocaleString(Qt.locale(),i18n.tr("MMMM yyyy"))
614.49.2 by Renato Araujo Oliveira Filho
Use new page header API.
111
            return monthName[0].toUpperCase() + monthName.substr(1, monthName.length - 1)
455.5.1 by Nekhelesh Ramananthan
Improved DayView.qml
112
        }
113
    }
114
671 by Renato Araujo Oliveira Filho
Create new event based on scrolled view.
115
    onBottomEdgeCommitStarted: {
116
        var eventAt = new Date()
117
        if (dayViewPath.currentItem) {
705 by Renato Araujo Oliveira Filho
Fixed event date used for bottom edge on day view.
118
            eventAt.setFullYear(currentDate.getFullYear())
119
            eventAt.setMonth(currentDate.getMonth())
678 by Renato Araujo Oliveira Filho
Always create today event on week view bottom edge.
120
            eventAt.setDate(currentDate.getDate())
671 by Renato Araujo Oliveira Filho
Create new event based on scrolled view.
121
        }
122
        createEventAt = eventAt
123
    }
124
550.3.1 by Kunal Parmar
new day and week view
125
    PathViewBase{
126
        id: dayViewPath
127
        objectName: "dayViewPath"
128
614.51.1 by Renato Araujo Oliveira Filho
Implemented Bottom edge for views.
129
        property var startDay: currentDate
550.3.1 by Kunal Parmar
new day and week view
130
        //This is used to scroll all view together when currentItem scrolls
679 by Renato Araujo Oliveira Filho
Make sure that all day views scroll to the same position.
131
        property real childContentY;
550.3.1 by Kunal Parmar
new day and week view
132
614.49.2 by Renato Araujo Oliveira Filho
Use new page header API.
133
        anchors {
134
            fill: parent
135
            topMargin: header.height
136
        }
550.3.1 by Kunal Parmar
new day and week view
137
626 by Renato Araujo Oliveira Filho
Optimize views.
138
        delegate: TimeLineBaseComponent {
139
            id: timeLineView
140
            objectName: "DayComponent-"+index
141
72.2.11 by Kunal Parmar
adding missing files
142
            width: parent.width
550.3.1 by Kunal Parmar
new day and week view
143
            height: parent.height
626 by Renato Araujo Oliveira Filho
Optimize views.
144
145
            type: ViewType.ViewTypeDay
679 by Renato Araujo Oliveira Filho
Make sure that all day views scroll to the same position.
146
            isCurrentItem: PathView.isCurrentItem
147
            isActive: !dayViewPath.moving && !dayViewPath.flicking
626 by Renato Araujo Oliveira Filho
Optimize views.
148
            contentInteractive: PathView.isCurrentItem
149
            startDay: anchorDate.addDays(dayViewPath.loopCurrentIndex + dayViewPath.indexType(index))
150
            keyboardEventProvider: dayViewPath
661 by Renato Araujo Oliveira Filho
Make sure the timeline events are recreated when model changes.
151
            modelFilter: dayViewPage.model ? dayViewPage.model.filter : null
626 by Renato Araujo Oliveira Filho
Optimize views.
152
636 by Renato Araujo Oliveira Filho
Merged: ~renatofilho/ubuntu-calendar-app/week-press-and-hold-create-event
153
            onPressAndHoldAt: {
660 by Renato Araujo Oliveira Filho
Allow create all day events by pressing and hold at all day header.
154
                dayViewPage.pressAndHoldAt(date, allDay)
636 by Renato Araujo Oliveira Filho
Merged: ~renatofilho/ubuntu-calendar-app/week-press-and-hold-create-event
155
            }
156
626 by Renato Araujo Oliveira Filho
Optimize views.
157
            Component.onCompleted: {
695 by Renato Araujo Oliveira Filho
Rewrite events layout and drawing;
158
                if(dayViewPage.tabSelected){
685 by Renato Araujo Oliveira Filho
After create a new event scroll view to new event position.
159
                    timeLineView.scrollToTime(new Date());
626 by Renato Araujo Oliveira Filho
Optimize views.
160
                }
161
            }
162
163
            Connections{
164
                target: dayViewPage
695 by Renato Araujo Oliveira Filho
Rewrite events layout and drawing;
165
                onTabSelectedChanged: {
166
                    if(tabSelected){
685 by Renato Araujo Oliveira Filho
After create a new event scroll view to new event position.
167
                        timeLineView.scrollToTime(new Date());
626 by Renato Araujo Oliveira Filho
Optimize views.
168
                    }
169
                }
170
            }
171
172
            //get contentY value from PathView, if its not current Item
173
            Binding{
174
                target: timeLineView
175
                property: "contentY"
176
                value: dayViewPath.childContentY;
679 by Renato Araujo Oliveira Filho
Make sure that all day views scroll to the same position.
177
                when: !timeLineView.isCurrentItem
626 by Renato Araujo Oliveira Filho
Optimize views.
178
            }
179
180
            //set PathView's contentY property, if its current item
181
            Binding{
182
                target: dayViewPath
183
                property: "childContentY"
679 by Renato Araujo Oliveira Filho
Make sure that all day views scroll to the same position.
184
                value: timeLineView.contentY
185
                when: timeLineView.isCurrentItem
489.2.1 by Kunal Parmar
Dayview like iOS
186
            }
72.2.11 by Kunal Parmar
adding missing files
187
        }
188
    }
189
}