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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import QtQuick 2.0
import Ubuntu.Components 0.1

import "dateExt.js" as DateExt

Page {
    id: root
    objectName: "YearView"
    property var currentYear: DateExt.today();
    signal monthSelected(var date);

    PathViewBase {
        id: pathView

        anchors.fill: parent

        onNextItemHighlighted: {
            root.currentYear = pathView.getDateFromYear(root.currentYear.getFullYear() + 1);
        }

        onPreviousItemHighlighted: {
            root.currentYear = pathView.getDateFromYear(root.currentYear.getFullYear() - 1);
        }

        function getDateFromYear(year) {
            return new Date(year,0,1,0,0,0,0);
        }

        delegate: GridView{
            id: yearView
            clip: true

            property bool isCurrentItem: index == pathView.currentIndex
            property var year: getYear();

            function getYear() {
                switch( pathView.indexType(index)) {
                case 0:
                    return root.currentYear;
                case -1:
                    return pathView.getDateFromYear(root.currentYear.getFullYear() - 1);
                case 1:
                    return pathView.getDateFromYear(root.currentYear.getFullYear() + 1);
                }
            }

            width: parent.width
            height: parent.height
            anchors.top: parent.top

            readonly property int minCellWidth: units.gu(30)
            cellWidth: Math.floor(Math.min.apply(Math, [3, 4].map(function(n)
            { return ((width / n >= minCellWidth) ? width / n : width / 2) })))

            cellHeight: cellWidth * 1.4

            model: 12 /* months in a year */
            delegate: Item {
                width: yearView.cellWidth
                height: yearView.cellHeight

                MonthComponent{
                    id: monthComponent
                    monthDate: new Date(yearView.year.getFullYear(),index,1,0,0,0,0)
                    anchors.fill: parent
                    anchors.margins: units.gu(0.5)

                    dayLabelFontSize:"x-small"
                    dateLabelFontSize: "medium"
                    monthLabelFontSize: "medium"
                    yearLabelFontSize: "small"

                    MouseArea{
                        anchors.fill: parent
                        onClicked: {
                            root.monthSelected(monthComponent.monthDate);
                        }
                    }
                }
            }
        }
    }
}