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

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
84
85
86
87
88
import QtQuick 2.0
import Ubuntu.Components 0.1

import "dateExt.js" as DateExt

PathViewBase {
    id: root

    property var currentYear: DateExt.today();

    signal monthSelected(var date);

    anchors.fill: parent

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

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

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

    QtObject{
        id: intern
        property var startYear: getDateFromYear(currentYear.getFullYear()-1);
    }

    delegate: Flickable{
        id: yearView
        clip: true

        property var year: getYear();

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

        width: parent.width
        height: parent.height

        contentHeight: yearGrid.height + units.gu(2)
        contentWidth: width

        Grid{
            id: yearGrid
            rows: 6
            columns: 2

            anchors.top: parent.top
            anchors.topMargin: units.gu(1.5)

            width: parent.width - ((columns-1) * yearGrid.spacing)
            spacing: units.gu(2)
            anchors.horizontalCenter: parent.horizontalCenter

            Repeater{
                model: yearGrid.rows * yearGrid.columns
                delegate: MonthComponent{
                    monthDate: new Date(yearView.year.getFullYear(),index,1,0,0,0,0)
                    width: (parent.width - units.gu(2))/2
                    height: width * 1.5
                    dayLabelFontSize:"x-small"
                    dateLabelFontSize: "medium"
                    monthLabelFontSize: "medium"
                    yearLabelFontSize: "small"

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