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

« back to all changes in this revision

Viewing changes to DayView.qml

  • Committer: Tarmac
  • Author(s): Kunal Parmar
  • Date: 2014-09-28 17:30:53 UTC
  • mfrom: (478.1.1 ubuntu-calendar-app)
  • Revision ID: tarmac-20140928173053-swmerv646i24s6pm
Resolves Bug #1357255. Fixes: https://bugs.launchpad.net/bugs/1357255.

Approved by Ubuntu Phone Apps Jenkins Bot, Mihir Soni.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    property var currentDay: new Date()
29
29
    property bool isCurrentPage: false
30
30
 
31
 
    signal dateSelected(var date);
32
 
 
33
31
    Keys.forwardTo: [dayViewPath]
34
32
    flickable: null
35
33
 
51
49
            commonHeaderActions.reloadAction
52
50
        ]
53
51
 
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
 
52
        contents: Column{
 
53
            width: parent ? parent.width - units.gu(2) : undefined
 
54
 
 
55
            Label {
 
56
                fontSize: "medium"
 
57
                text: Qt.locale().standaloneDayName(currentDay.getDay())
 
58
                font.capitalization: Font.Capitalize
 
59
            }
 
60
 
 
61
            Label {
 
62
                id:cuurentDay
 
63
                objectName:"monthYearLabel"
 
64
                fontSize: "large"
 
65
                // TRANSLATORS: this is a time formatting string,
 
66
                // see http://qt-project.org/doc/qt-5/qml-qtqml-date.html#details for valid expressions.
 
67
                // It's used in the header of the day view
 
68
                text:i18n.tr(currentDay.toLocaleString(Qt.locale(),i18n.tr("MMMM dd, yyyy")))
 
69
            }
60
70
        }
61
71
    }
62
72
 
63
 
    Column {
 
73
    PathViewBase{
 
74
        id: dayViewPath
 
75
        objectName: "dayViewPath"
 
76
 
 
77
        property var startDay: currentDay
 
78
        //This is used to scroll all view together when currentItem scrolls
 
79
        property var childContentY;
 
80
 
64
81
        anchors.fill: parent
65
 
        anchors.topMargin: units.gu(1)
66
 
        spacing: units.gu(1)
67
 
 
68
 
        TimeLineHeader{
69
 
            id: dayHeader
70
 
            objectName: "dayHeader"
 
82
 
 
83
        onNextItemHighlighted: {
 
84
            //next day
 
85
            currentDay = currentDay.addDays(1);
 
86
        }
 
87
 
 
88
        onPreviousItemHighlighted: {
 
89
            //previous day
 
90
            currentDay = currentDay.addDays(-1);
 
91
        }
 
92
 
 
93
        delegate: TimeLineBaseComponent {
 
94
            id: timeLineView
 
95
            objectName: "DayComponent-"+index
 
96
 
71
97
            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
98
 
106
99
            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
 
                        }
 
100
            height: parent.height
 
101
            z: index == dayViewPath.currentIndex ? 2 : 1
 
102
            isActive: true
 
103
 
 
104
            Connections{
 
105
                target: dayViewPage
 
106
                onIsCurrentPageChanged:{
 
107
                    if(dayViewPage.isCurrentPage){
 
108
                        timeLineView.scrollToCurrentTime();
172
109
                    }
173
110
                }
174
111
            }
 
112
 
 
113
            //get contentY value from PathView, if its not current Item
 
114
            Binding{
 
115
                target: timeLineView
 
116
                property: "contentY"
 
117
                value: dayViewPath.childContentY;
 
118
                when: !timeLineView.PathView.isCurrentItem
 
119
            }
 
120
 
 
121
            //set PathView's contentY property, if its current item
 
122
            Binding{
 
123
                target: dayViewPath
 
124
                property: "childContentY"
 
125
                value: contentY
 
126
                when: timeLineView.PathView.isCurrentItem
 
127
            }
 
128
 
 
129
            contentInteractive: timeLineView.PathView.isCurrentItem
 
130
 
 
131
            startDay: dayViewPath.startDay.addDays(dayViewPath.indexType(index))
175
132
        }
176
133
    }
177
134
}
 
135