~vthompson/ubuntu-calendar-app/scroll-in-test

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import QtQuick 2.0
import Ubuntu.Components 0.1
import "dateExt.js" as DateExt
import "colorUtils.js" as Color

Item{
    id: root
    objectName: "MonthComponent"

    property var monthDate;

    property string dayLabelFontSize: "medium"
    property string dateLabelFontSize: "large"
    property string monthLabelFontSize: "x-large"
    property string yearLabelFontSize: "large"

    property alias dayLabelDelegate : dayLabelRepeater.delegate
    property alias dateLabelDelegate : dateLabelRepeater.delegate

    signal dateSelected(var date)

    height: ubuntuShape.height

    UbuntuShape {
        id: ubuntuShape

        anchors.fill: parent
        radius: "medium"

        Column{
            id: column

            anchors.top: parent.top
            anchors.topMargin: units.gu(1.5)
            anchors.bottomMargin: units.gu(1)
            anchors.fill: parent
            spacing: units.gu(1.5)

            ViewHeader{
                id: monthHeader
                date: root.monthDate
                monthLabelFontSize: root.monthLabelFontSize
                yearLabelFontSize: root.yearLabelFontSize
            }

            Item {
                width: parent.width
                height: dayLabelRow.height + units.gu(1)

                DayHeaderBackground{}

                Row{
                    id: dayLabelRow
                    width: parent.width
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.verticalCenter: parent.verticalCenter

                    Repeater{
                        id: dayLabelRepeater
                        model:7
                        delegate: dafaultDayLabelComponent
                    }
                }
            }

            Grid{
                id: monthGrid
                objectName: "monthGrid"

                property int weekCount : 6
                property var monthStart: root.monthDate.weekStart( Qt.locale().firstDayOfWeek )

                width: parent.width
                height: parent.height - monthHeader.height - dayLabelRow.height - units.gu(3)

                rows: weekCount
                columns: 7

                Repeater{
                    id: dateLabelRepeater
                    model: monthGrid.rows * monthGrid.columns
                    delegate: defaultDateLabelComponent
                }
            }
        }
    }

    Component{
        id: defaultDateLabelComponent

        Item{
            id: dateRootItem

            property var date: parent.monthStart.addDays(index);
            property bool isCurrentMonth: DateExt.isSameMonth(root.monthDate,date)

            width: parent.width / 7;
            height: parent.height / parent.weekCount

            Loader {
                width: parent.width < parent.height ? parent.width : parent.height
                height: width
                anchors.centerIn: parent
                sourceComponent: date.isSameDay(DateExt.today()) && isCurrentMonth ? highLightComp : undefined
            }

            Label{
                id: dateLabel
                anchors.centerIn: parent
                text: date.getDate()
                horizontalAlignment: Text.AlignHCenter
                fontSize: root.dateLabelFontSize
                color: {
                    if( date.isSameDay(DateExt.today()) && isCurrentMonth ) {
                        "#2C001E"
                    } else if( parent.isCurrentMonth ) {
                        "white"
                    } else {
                        "#AEA79F"
                    }
                }
            }

            MouseArea{
                anchors.fill: parent
                onClicked: {
                    root.dateSelected(date);
                }
            }
        }
    }

    Component{
        id: dafaultDayLabelComponent

        Label{
            id: weekDay
            width: parent.width / 7
            property var day :Qt.locale().standaloneDayName(( Qt.locale().firstDayOfWeek + index), Locale.ShortFormat)
            text: day.toUpperCase();
            horizontalAlignment: Text.AlignHCenter
            fontSize: root.dayLabelFontSize
            color: "#AEA79F"
        }
    }

    Component{
        id: highLightComp
        UbuntuShape{
            color: "white"
        }
    }
}