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

« back to all changes in this revision

Viewing changes to YearView.qml

  • Committer: Tarmac
  • Author(s): Kunal Parmar
  • Date: 2014-03-13 07:53:02 UTC
  • mfrom: (174.1.21 ubuntu-calendar-app)
  • Revision ID: tarmac-20140313075302-4z7bye5g50i672y9
Not loading all page at startup, instead now using loader element to load particular view on tab selection,.

Approved by Ubuntu Phone Apps Jenkins Bot, Olivier Tilloy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
import "dateExt.js" as DateExt
5
5
 
6
 
PathViewBase {
 
6
Page {
7
7
    id: root
8
8
    objectName: "YearView"
9
 
 
10
9
    property var currentYear: DateExt.today();
11
 
 
12
10
    signal monthSelected(var date);
13
11
 
14
 
    anchors.fill: parent
15
 
 
16
 
    onNextItemHighlighted: {
17
 
        currentYear = getDateFromYear(currentYear.getFullYear() + 1);
18
 
    }
19
 
 
20
 
    onPreviousItemHighlighted: {
21
 
        currentYear = getDateFromYear(currentYear.getFullYear() - 1);
22
 
    }
23
 
 
24
 
    function getDateFromYear(year) {
25
 
        return new Date(year,0,1,0,0,0,0);
26
 
    }
27
 
 
28
 
    delegate: GridView{
29
 
        id: yearView
30
 
        clip: true
31
 
 
32
 
        property bool isCurrentItem: index == root.currentIndex
33
 
        property var year: getYear();
34
 
 
35
 
        function getYear() {
36
 
            switch( root.indexType(index)) {
37
 
            case 0:
38
 
                return currentYear;
39
 
            case -1:
40
 
                return getDateFromYear(currentYear.getFullYear() - 1);
41
 
            case 1:
42
 
                return getDateFromYear(currentYear.getFullYear() + 1);
 
12
    PathViewBase {
 
13
        id: pathView
 
14
 
 
15
        anchors.fill: parent
 
16
 
 
17
        onNextItemHighlighted: {
 
18
            root.currentYear = pathView.getDateFromYear(root.currentYear.getFullYear() + 1);
 
19
        }
 
20
 
 
21
        onPreviousItemHighlighted: {
 
22
            root.currentYear = pathView.getDateFromYear(root.currentYear.getFullYear() - 1);
 
23
        }
 
24
 
 
25
        function getDateFromYear(year) {
 
26
            return new Date(year,0,1,0,0,0,0);
 
27
        }
 
28
 
 
29
        delegate: GridView{
 
30
            id: yearView
 
31
            clip: true
 
32
 
 
33
            property bool isCurrentItem: index == pathView.currentIndex
 
34
            property var year: getYear();
 
35
 
 
36
            function getYear() {
 
37
                switch( pathView.indexType(index)) {
 
38
                case 0:
 
39
                    return root.currentYear;
 
40
                case -1:
 
41
                    return pathView.getDateFromYear(root.currentYear.getFullYear() - 1);
 
42
                case 1:
 
43
                    return pathView.getDateFromYear(root.currentYear.getFullYear() + 1);
 
44
                }
43
45
            }
44
 
        }
45
 
 
46
 
        width: parent.width
47
 
        height: parent.height
48
 
        anchors.top: parent.top
49
 
 
50
 
        readonly property int minCellWidth: units.gu(30)
51
 
        cellWidth: Math.floor(Math.min.apply(Math, [3, 4].map(function(n)
 
46
 
 
47
            width: parent.width
 
48
            height: parent.height
 
49
            anchors.top: parent.top
 
50
 
 
51
            readonly property int minCellWidth: units.gu(30)
 
52
            cellWidth: Math.floor(Math.min.apply(Math, [3, 4].map(function(n)
52
53
            { return ((width / n >= minCellWidth) ? width / n : width / 2) })))
53
54
 
54
 
        cellHeight: cellWidth * 1.4
55
 
 
56
 
        model: 12 /* months in a year */
57
 
        delegate: Item {
58
 
            width: yearView.cellWidth
59
 
            height: yearView.cellHeight
60
 
 
61
 
            MonthComponent{
62
 
                id: monthComponent
63
 
                monthDate: new Date(yearView.year.getFullYear(),index,1,0,0,0,0)
64
 
                anchors.fill: parent
65
 
                anchors.margins: units.gu(0.5)
66
 
 
67
 
                dayLabelFontSize:"x-small"
68
 
                dateLabelFontSize: "medium"
69
 
                monthLabelFontSize: "medium"
70
 
                yearLabelFontSize: "small"
71
 
 
72
 
                MouseArea{
 
55
            cellHeight: cellWidth * 1.4
 
56
 
 
57
            model: 12 /* months in a year */
 
58
            delegate: Item {
 
59
                width: yearView.cellWidth
 
60
                height: yearView.cellHeight
 
61
 
 
62
                MonthComponent{
 
63
                    id: monthComponent
 
64
                    monthDate: new Date(yearView.year.getFullYear(),index,1,0,0,0,0)
73
65
                    anchors.fill: parent
74
 
                    onClicked: {
75
 
                        root.monthSelected(monthComponent.monthDate);
 
66
                    anchors.margins: units.gu(0.5)
 
67
 
 
68
                    dayLabelFontSize:"x-small"
 
69
                    dateLabelFontSize: "medium"
 
70
                    monthLabelFontSize: "medium"
 
71
                    yearLabelFontSize: "small"
 
72
 
 
73
                    MouseArea{
 
74
                        anchors.fill: parent
 
75
                        onClicked: {
 
76
                            root.monthSelected(monthComponent.monthDate);
 
77
                        }
76
78
                    }
77
79
                }
78
80
            }