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

« back to all changes in this revision

Viewing changes to DayView.qml

  • Committer: mhall119
  • Date: 2013-07-24 21:24:52 UTC
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: mhall119@ubuntu.com-20130724212452-y181o9l9f4v3gm2z
Add individual contributors to debian/copyright

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 Ubuntu.Components 1.1
21
 
import "dateExt.js" as DateExt
22
 
import "ViewType.js" as ViewType
23
 
 
24
 
Page{
25
 
    id: dayViewPage
26
 
    objectName: "dayViewPage"
27
 
 
28
 
    property var currentDay: new Date()
29
 
    property bool isCurrentPage: false
30
 
 
31
 
    signal dateSelected(var date);
32
 
 
33
 
    Keys.forwardTo: [dayViewPath]
34
 
    flickable: null
35
 
 
36
 
    Action {
37
 
        id: calendarTodayAction
38
 
        objectName:"todaybutton"
39
 
        iconName: "calendar-today"
40
 
        text: i18n.tr("Today")
41
 
        onTriggered: {
42
 
            currentDay = new Date()
43
 
        }
44
 
    }
45
 
 
46
 
    head {
47
 
        actions: [
48
 
            calendarTodayAction,
49
 
            commonHeaderActions.newEventAction,
50
 
            commonHeaderActions.showCalendarAction,
51
 
            commonHeaderActions.reloadAction
52
 
        ]
53
 
 
54
 
        contents: Label {
55
 
            id:monthYear
56
 
            objectName:"monthYearLabel"
57
 
            fontSize: "x-large"
58
 
            text: i18n.tr(currentDay.toLocaleString(Qt.locale(),i18n.tr("MMMM yyyy")))
59
 
            font.capitalization: Font.Capitalize
60
 
        }
61
 
    }
62
 
 
63
 
    Column {
64
 
        anchors.fill: parent
65
 
        anchors.topMargin: units.gu(1)
66
 
        spacing: units.gu(1)
67
 
 
68
 
        TimeLineHeader{
69
 
            id: dayHeader
70
 
            objectName: "dayHeader"
71
 
            type: ViewType.ViewTypeDay
72
 
            currentDay: dayViewPage.currentDay
73
 
 
74
 
            onDateSelected: {
75
 
                dayViewPage.currentDay = date;
76
 
                dayViewPage.dateSelected(date);
77
 
            }
78
 
 
79
 
            onCurrentDayChanged: {
80
 
                date = dayViewPage.currentDay.weekStart(Qt.locale().firstDayOfWeek);
81
 
            }
82
 
 
83
 
            function nextDay() {
84
 
                if(currentDay >= date.addDays(7)) {
85
 
                    date = dayViewPage.currentDay.weekStart(Qt.locale().firstDayOfWeek);
86
 
                    dayHeader.incrementCurrentIndex();
87
 
                }
88
 
            }
89
 
 
90
 
            function previousDay() {
91
 
                if( currentDay < date) {
92
 
                    date = dayViewPage.currentDay.weekStart(Qt.locale().firstDayOfWeek);
93
 
                    dayHeader.decrementCurrentIndex();
94
 
                }
95
 
            }
96
 
        }
97
 
 
98
 
        PathViewBase{
99
 
            id: dayViewPath
100
 
            objectName: "dayViewPath"
101
 
 
102
 
            property var startDay: currentDay
103
 
            //This is used to scroll all view together when currentItem scrolls
104
 
            property var childContentY;
105
 
 
106
 
            width: parent.width
107
 
            height: dayViewPage.height - dayViewPath.y
108
 
 
109
 
            onNextItemHighlighted: {
110
 
                //next day
111
 
                currentDay = currentDay.addDays(1);
112
 
                dayHeader.nextDay();
113
 
            }
114
 
 
115
 
            onPreviousItemHighlighted: {
116
 
                //previous day
117
 
                currentDay = currentDay.addDays(-1);
118
 
                dayHeader.previousDay();
119
 
            }
120
 
 
121
 
            delegate: Loader {
122
 
                width: parent.width
123
 
                height: parent.height
124
 
                asynchronous: !dayViewPath.isCurrentItem
125
 
                sourceComponent: delegateComponent
126
 
 
127
 
                Component {
128
 
                    id: delegateComponent
129
 
 
130
 
                    TimeLineBaseComponent {
131
 
                        id: timeLineView
132
 
                        objectName: "DayComponent-"+index
133
 
 
134
 
                        type: ViewType.ViewTypeDay
135
 
                        anchors.fill: parent
136
 
 
137
 
                        isActive: parent.PathView.isCurrentItem
138
 
                        contentInteractive: parent.PathView.isCurrentItem
139
 
                        startDay: dayViewPath.startDay.addDays(dayViewPath.indexType(index))
140
 
                        keyboardEventProvider: dayViewPath
141
 
 
142
 
                        Component.onCompleted: {
143
 
                            if(dayViewPage.isCurrentPage){
144
 
                                timeLineView.scrollToCurrentTime();
145
 
                            }
146
 
                        }
147
 
 
148
 
                        Connections{
149
 
                            target: dayViewPage
150
 
                            onIsCurrentPageChanged:{
151
 
                                if(dayViewPage.isCurrentPage){
152
 
                                    timeLineView.scrollToCurrentTime();
153
 
                                }
154
 
                            }
155
 
                        }
156
 
 
157
 
                        //get contentY value from PathView, if its not current Item
158
 
                        Binding{
159
 
                            target: timeLineView
160
 
                            property: "contentY"
161
 
                            value: dayViewPath.childContentY;
162
 
                            when: !parent.PathView.isCurrentItem
163
 
                        }
164
 
 
165
 
                        //set PathView's contentY property, if its current item
166
 
                        Binding{
167
 
                            target: dayViewPath
168
 
                            property: "childContentY"
169
 
                            value: contentY
170
 
                            when: parent.PathView.isCurrentItem
171
 
                        }
172
 
                    }
173
 
                }
174
 
            }
175
 
        }
176
 
    }
177
 
}