~pkunal-parmar/ubuntu-calendar-app/PerformanceImprovements

« back to all changes in this revision

Viewing changes to YearView.qml

  • Committer: Kunal Parmar
  • Date: 2014-10-22 17:28:07 UTC
  • Revision ID: pkunal.parmar@gmail.com-20141022172807-f8q4u2eb3obvutjv
performce improvements

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
            currentYear = currentYear - 1;
63
63
        }
64
64
 
65
 
        delegate: GridView{
66
 
            id: yearView
67
 
            clip: true
68
 
            focus: index == yearPathView.currentIndex
69
 
 
70
 
            property int scrollMonth: 0;
71
 
            property bool isCurrentItem: index == yearPathView.currentIndex
72
 
            property int year: (yearViewPage.currentYear + yearPathView.indexType(index))
73
 
 
 
65
        delegate: Loader {
74
66
            width: parent.width
75
67
            height: parent.height
76
68
            anchors.top: parent.top
77
69
 
78
 
            readonly property int minCellWidth: units.gu(30)
79
 
            cellWidth: Math.floor(Math.min.apply(Math, [3, 4].map(function(n)
80
 
            { return ((width / n >= minCellWidth) ? width / n : width / 2) })))
81
 
 
82
 
            cellHeight: cellWidth * 1.4
83
 
 
84
 
            model: 12 /* months in a year */
85
 
 
86
 
            onYearChanged: {
87
 
                scrollMonth = 0;
88
 
                var today = new Date();
89
 
                if(year == today.getFullYear()) {
90
 
                    scrollMonth = today.getMonth();
91
 
                }
92
 
                yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
93
 
            }
94
 
 
95
 
            //scroll in case content height changed
96
 
            onHeightChanged: {
97
 
                yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
98
 
            }
99
 
 
100
 
            Component.onCompleted: {
101
 
                yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
102
 
            }
103
 
 
104
 
            Connections{
105
 
                target: yearPathView
106
 
                onScrollUp: {
107
 
                    scrollMonth -= 2;
108
 
                    if(scrollMonth < 0) {
109
 
                        scrollMonth = 0;
110
 
                    }
111
 
                    yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
112
 
                }
113
 
 
114
 
                onScrollDown: {
115
 
                    scrollMonth += 2;
116
 
                    var visibleMonths = yearView.height / cellHeight;
117
 
                    if( scrollMonth >= (11 - visibleMonths)) {
118
 
                        scrollMonth = (11 - visibleMonths);
119
 
                    }
120
 
                    yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
121
 
                }
122
 
            }
123
 
 
124
 
            delegate: Item {
125
 
                width: yearView.cellWidth
126
 
                height: yearView.cellHeight
127
 
 
128
 
                UbuntuShape {
 
70
            asynchronous: index !== yearPathView.currentIndex
 
71
            sourceComponent: delegateComponent
 
72
 
 
73
            Component{
 
74
                id: delegateComponent
 
75
 
 
76
                YearViewDelegate{
 
77
                    focus: index == yearPathView.currentIndex
 
78
 
 
79
                    scrollMonth: 0;
 
80
                    isCurrentItem: index == yearPathView.currentIndex
 
81
                    year: (yearViewPage.currentYear + yearPathView.indexType(index))
 
82
 
129
83
                    anchors.fill: parent
130
 
                    anchors.margins: units.gu(0.5)
131
 
                    radius: "medium"
132
 
 
133
 
                    MonthComponent {
134
 
                        id: monthComponent
135
 
                        objectName: "monthComponent" + index
136
 
                        showEvents: false
137
 
                        currentMonth: new Date(yearView.year, index, 1, 0, 0, 0, 0)
138
 
 
139
 
                        isYearView: true
140
 
                        anchors.fill: parent
141
 
 
142
 
                        dayLabelFontSize:"x-small"
143
 
                        dateLabelFontSize: "medium"
144
 
                        monthLabelFontSize: "medium"
145
 
                        yearLabelFontSize: "small"
146
 
 
147
 
                        onMonthSelected: {
148
 
                            yearViewPage.monthSelected(date);
149
 
                        }
150
 
                    }
151
84
                }
152
85
            }
153
86
        }