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

« back to all changes in this revision

Viewing changes to YearViewDelegate.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:
 
1
import QtQuick 2.0
 
2
import Ubuntu.Components 1.1
 
3
 
 
4
GridView{
 
5
    id: yearView
 
6
    clip: true
 
7
 
 
8
    property int scrollMonth;
 
9
    property bool isCurrentItem;
 
10
    property int year;
 
11
 
 
12
    readonly property int minCellWidth: units.gu(30)
 
13
    cellWidth: Math.floor(Math.min.apply(Math, [3, 4].map(function(n)
 
14
    { return ((width / n >= minCellWidth) ? width / n : width / 2) })))
 
15
 
 
16
    cellHeight: cellWidth * 1.4
 
17
 
 
18
    model: 12 /* months in a year */
 
19
 
 
20
    onYearChanged: {
 
21
        scrollMonth = 0;
 
22
        var today = new Date();
 
23
        if(year == today.getFullYear()) {
 
24
            scrollMonth = today.getMonth();
 
25
        }
 
26
        yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
 
27
    }
 
28
 
 
29
    //scroll in case content height changed
 
30
    onHeightChanged: {
 
31
        yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
 
32
    }
 
33
 
 
34
    Component.onCompleted: {
 
35
        yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
 
36
    }
 
37
 
 
38
    Connections{
 
39
        target: yearPathView
 
40
        onScrollUp: {
 
41
            scrollMonth -= 2;
 
42
            if(scrollMonth < 0) {
 
43
                scrollMonth = 0;
 
44
            }
 
45
            yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
 
46
        }
 
47
 
 
48
        onScrollDown: {
 
49
            scrollMonth += 2;
 
50
            var visibleMonths = yearView.height / cellHeight;
 
51
            if( scrollMonth >= (11 - visibleMonths)) {
 
52
                scrollMonth = (11 - visibleMonths);
 
53
            }
 
54
            yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
 
55
        }
 
56
    }
 
57
 
 
58
    delegate: Loader {
 
59
        width: yearView.cellWidth
 
60
        height: yearView.cellHeight
 
61
 
 
62
        sourceComponent: delegateComponent
 
63
        asynchronous: !yearView.focus
 
64
 
 
65
        Component {
 
66
            id: delegateComponent
 
67
 
 
68
            UbuntuShape {
 
69
                anchors.fill: parent
 
70
                anchors.margins: units.gu(0.5)
 
71
                radius: "medium"
 
72
 
 
73
                MonthComponent {
 
74
                    id: monthComponent
 
75
                    objectName: "monthComponent" + index
 
76
                    showEvents: false
 
77
                    currentMonth: new Date(yearView.year, index, 1, 0, 0, 0, 0)
 
78
 
 
79
                    isCurrentItem: yearView.focus
 
80
 
 
81
                    isYearView: true
 
82
                    anchors.fill: parent
 
83
 
 
84
                    dayLabelFontSize:"x-small"
 
85
                    dateLabelFontSize: "medium"
 
86
                    monthLabelFontSize: "medium"
 
87
                    yearLabelFontSize: "small"
 
88
 
 
89
                    onMonthSelected: {
 
90
                        yearViewPage.monthSelected(date);
 
91
                    }
 
92
                }
 
93
            }
 
94
        }
 
95
    }
 
96
}