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
|
import QtQuick 2.0
import Ubuntu.Components 0.1
PathViewBase {
id: root
anchors.fill: parent
property var year: getDateFromYear(intern.now.getFullYear()-1);
signal monthSelected(var date);
onNextItemHighlighted: {
year = getDateFromYear(year.getFullYear() + 1);
}
onPreviousItemHighlighted: {
year = getDateFromYear(year.getFullYear() - 1);
}
function getDateFromYear(year) {
return new Date(year,0,1,0,0,0,0);
}
QtObject{
id: intern
property var now: new Date()
property int weekstartDay: Qt.locale().firstDayOfWeek
}
delegate: Item{
id: yearView
property var year: {
if (index === root.currentIndex) {
return root.year;
}
var previousIndex = root.currentIndex > 0 ? root.currentIndex - 1 : 2
if ( index === previousIndex ) {
return getDateFromYear(root.year.getFullYear()-1);
}
return getDateFromYear(root.year.getFullYear()+ 1);
}
width: parent.width
height: parent.height
Label{
id: yearLabel
text: year.getFullYear()
fontSize: "large"
anchors.horizontalCenter: parent.horizontalCenter
font.bold: true
}
Grid{
id: yearGrid
rows: 4
columns: 3
width: parent.width
height: parent.height
anchors.top: yearLabel.bottom
spacing: units.gu(2.5)
Repeater{
model: yearGrid.rows * yearGrid.columns
delegate: MonthComponent{
date: new Date(year.getFullYear(),index,1,0,0,0,0)
onMonthSelected: {
root.monthSelected(date);
}
}
}
}
}
}
|