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

« back to all changes in this revision

Viewing changes to WeekView.qml

  • Committer: Kunal Parmar
  • Date: 2013-09-04 13:37:10 UTC
  • mto: This revision was merged to the branch mainline in revision 109.
  • Revision ID: pkunal.parmar@gmail.com-20130904133710-ysaxcuazkjo0l4xj
Theme and some other modification

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
 
 */
 
1
import QtQuick 2.0
 
2
import Ubuntu.Components 0.1
18
3
 
19
 
import QtQuick 2.3
20
 
import Ubuntu.Components 1.1
21
4
import "dateExt.js" as DateExt
22
 
import "ViewType.js" as ViewType
 
5
import "dataService.js" as DataService
23
6
 
24
 
Page{
25
 
    id: weekViewPage
26
 
    objectName: "weekViewPage"
 
7
Item{
 
8
    id: root
 
9
    anchors.fill: parent
27
10
 
28
11
    property var dayStart: new Date();
29
 
    property var firstDay: dayStart.weekStart(Qt.locale().firstDayOfWeek);
30
 
    property bool isCurrentPage: false
31
 
 
32
 
    signal dateSelected(var date);
33
 
 
34
 
    Keys.forwardTo: [weekViewPath]
35
 
 
36
 
    flickable: null
37
 
 
38
 
    Action {
39
 
        id: calendarTodayAction
40
 
        objectName:"todaybutton"
41
 
        iconName: "calendar-today"
42
 
        text: i18n.tr("Today")
43
 
        onTriggered: {
44
 
            dayStart = new Date()
45
 
        }
46
 
    }
47
 
 
48
 
    head {
49
 
        actions: [
50
 
            calendarTodayAction,
51
 
            commonHeaderActions.newEventAction,
52
 
            commonHeaderActions.showCalendarAction,
53
 
            commonHeaderActions.reloadAction
54
 
        ]
55
 
 
56
 
        contents: Label {
57
 
            id:monthYear
58
 
            objectName:"monthYearLabel"
59
 
            fontSize: "x-large"
60
 
            text: i18n.tr(dayStart.toLocaleString(Qt.locale(),i18n.tr("MMMM yyyy")))
61
 
            font.capitalization: Font.Capitalize
62
 
        }
63
 
    }
64
 
 
65
 
    Column {
66
 
        anchors.fill: parent
67
 
        anchors.topMargin: units.gu(1)
68
 
        spacing: units.gu(1)
69
 
 
70
 
        TimeLineHeader{
71
 
            id: weekHeader
72
 
            objectName: "weekHeader"
73
 
            type: ViewType.ViewTypeWeek
74
 
            date: firstDay
75
 
 
76
 
            onDateSelected: {
77
 
                weekViewPage.dateSelected(date);
78
 
            }
79
 
        }
80
 
 
81
 
        PathViewBase{
82
 
            id: weekViewPath
83
 
            objectName: "weekViewPath"
 
12
 
 
13
    PathViewBase{
 
14
        id: weekViewPath
 
15
 
 
16
        property var visibleWeek: dayStart.weekStart(Qt.locale().firstDayOfWeek);
 
17
        property var weekStart: weekViewPath.visibleWeek.addDays(-7)
 
18
 
 
19
        anchors.top: parent.top
 
20
        anchors.topMargin: units.gu(1.5)
 
21
        width: parent.width
 
22
        height: parent.height - units.gu(3)
 
23
 
 
24
        onNextItemHighlighted: {
 
25
            nextWeek();
 
26
        }
 
27
 
 
28
        onPreviousItemHighlighted: {
 
29
            previousWeek();
 
30
        }
 
31
 
 
32
        function nextWeek() {
 
33
            var weekStartDay = visibleWeek.weekStart(Qt.locale().firstDayOfWeek);
 
34
            dayStart = weekStartDay.addDays(7);
 
35
        }
 
36
 
 
37
        function previousWeek(){
 
38
            var weekStartDay = visibleWeek.weekStart(Qt.locale().firstDayOfWeek);
 
39
            dayStart = weekStartDay.addDays(-7);
 
40
        }
 
41
 
 
42
        delegate: TimeLineBaseComponent {
 
43
            id: timeLineView
 
44
 
 
45
            type: typeWeek
84
46
 
85
47
            width: parent.width
86
 
            height: weekViewPage.height - weekViewPath.y
87
 
 
88
 
            //This is used to scroll all view together when currentItem scrolls
89
 
            property var childContentY;
90
 
 
91
 
            onNextItemHighlighted: {
92
 
                nextWeek();
93
 
                weekHeader.incrementCurrentIndex()
94
 
            }
95
 
 
96
 
            onPreviousItemHighlighted: {
97
 
                previousWeek();
98
 
                weekHeader.decrementCurrentIndex()
99
 
            }
100
 
 
101
 
            function nextWeek() {
102
 
                dayStart = firstDay.addDays(7);
103
 
            }
104
 
 
105
 
            function previousWeek(){
106
 
                dayStart = firstDay.addDays(-7);
107
 
            }
108
 
 
109
 
            delegate: Loader {
110
 
                width: parent.width
111
 
                height: parent.height
112
 
                asynchronous: !weekViewPath.isCurrentItem
113
 
                sourceComponent: delegateComponent
114
 
 
115
 
                Component{
116
 
                    id: delegateComponent
117
 
 
118
 
                    TimeLineBaseComponent {
119
 
                        id: timeLineView
120
 
 
121
 
                        type: ViewType.ViewTypeWeek
122
 
                        anchors.fill: parent
123
 
                        isActive: parent.PathView.isCurrentItem
124
 
                        startDay: firstDay.addDays( weekViewPath.indexType(index) * 7)
125
 
                        keyboardEventProvider: weekViewPath
126
 
 
127
 
                        Component.onCompleted: {
128
 
                            if(weekViewPage.isCurrentPage){
129
 
                                timeLineView.scrollToCurrentTime();
130
 
                            }
131
 
                        }
132
 
 
133
 
                        Connections{
134
 
                            target: weekViewPage
135
 
                            onIsCurrentPageChanged:{
136
 
                                if(weekViewPage.isCurrentPage){
137
 
                                    timeLineView.scrollToCurrentTime();
138
 
                                }
139
 
                            }
140
 
                        }
141
 
 
142
 
                        //get contentY value from PathView, if its not current Item
143
 
                        Binding{
144
 
                            target: timeLineView
145
 
                            property: "contentY"
146
 
                            value: weekViewPath.childContentY;
147
 
                            when: !parent.PathView.isCurrentItem
148
 
                        }
149
 
 
150
 
                        //set PathView's contentY property, if its current item
151
 
                        Binding{
152
 
                            target: weekViewPath
153
 
                            property: "childContentY"
154
 
                            value: contentY
155
 
                            when: parent.PathView.isCurrentItem
156
 
                        }
157
 
                    }
158
 
                }
 
48
            height: parent.height
 
49
            startDay: getWeekStart();
 
50
 
 
51
            function getWeekStart() {
 
52
                if (index === weekViewPath.currentIndex) {
 
53
                    return weekViewPath.weekStart;
 
54
                }
 
55
                var previousIndex = weekViewPath.currentIndex > 0 ? weekViewPath.currentIndex - 1 : 2
 
56
 
 
57
                if ( index === previousIndex ) {
 
58
                    var weekStartDay= weekViewPath.weekStart.weekStart(Qt.locale().firstDayOfWeek);
 
59
                    return weekStartDay.addDays(14);
 
60
                }
 
61
 
 
62
                var weekStartDay = weekViewPath.weekStart.weekStart(Qt.locale().firstDayOfWeek);
 
63
                return weekStartDay.addDays(7);
159
64
            }
160
65
        }
161
66
    }
162
67
}
 
68