~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
import QtQuick 2.0
import Ubuntu.Components 0.1

import "dateExt.js" as DateExt

PathViewBase {
    id: root
    objectName: "YearView"
    property int currentYear: DateExt.today().getFullYear();

    signal monthSelected(var date);

    anchors.fill: parent

    onNextItemHighlighted: {
        currentYear = currentYear + 1;
    }

    onPreviousItemHighlighted: {
        currentYear = currentYear - 1;
    }

    delegate: GridView{
        id: yearView
        clip: true
        focus: index == root.currentIndex

        property bool isCurrentItem: index == root.currentIndex
        property int year: (root.currentYear + root.indexType(index))

        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
                currentMonth: new Date(yearView.year,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.currentMonth);
                    }
                }
            }
        }
    }
}