63.1.1
by Kunal Parmar
year view implementation |
1 |
import QtQuick 2.0 |
2 |
import Ubuntu.Components 0.1 |
|
3 |
||
94.1.1
by Kunal Parmar
MonthView/YearView chaged according to new design |
4 |
import "dateExt.js" as DateExt |
5 |
||
212.1.2
by nskaggs
revert to 211 |
6 |
PathViewBase { |
63.1.1
by Kunal Parmar
year view implementation |
7 |
id: root
|
180.1.1
by nskaggs
Tweak for swipe timing and slower device issues |
8 |
objectName: "YearView" |
212.1.2
by nskaggs
revert to 211 |
9 |
|
94.1.1
by Kunal Parmar
MonthView/YearView chaged according to new design |
10 |
property var currentYear: DateExt.today(); |
212.1.2
by nskaggs
revert to 211 |
11 |
|
94.1.1
by Kunal Parmar
MonthView/YearView chaged according to new design |
12 |
signal monthSelected(var date); |
13 |
||
212.1.2
by nskaggs
revert to 211 |
14 |
anchors.fill: parent |
15 |
||
16 |
onNextItemHighlighted: { |
|
17 |
currentYear = getDateFromYear(currentYear.getFullYear() + 1); |
|
18 |
}
|
|
19 |
||
20 |
onPreviousItemHighlighted: { |
|
21 |
currentYear = getDateFromYear(currentYear.getFullYear() - 1); |
|
22 |
}
|
|
23 |
||
24 |
function getDateFromYear(year) { |
|
25 |
return new Date(year,0,1,0,0,0,0); |
|
26 |
}
|
|
27 |
||
28 |
delegate: GridView{ |
|
29 |
id: yearView
|
|
30 |
clip: true |
|
31 |
||
32 |
property bool isCurrentItem: index == root.currentIndex |
|
33 |
property var year: getYear(); |
|
34 |
||
35 |
function getYear() { |
|
36 |
switch( root.indexType(index)) { |
|
37 |
case 0: |
|
38 |
return currentYear; |
|
39 |
case -1: |
|
40 |
return getDateFromYear(currentYear.getFullYear() - 1); |
|
41 |
case 1: |
|
42 |
return getDateFromYear(currentYear.getFullYear() + 1); |
|
63.1.1
by Kunal Parmar
year view implementation |
43 |
}
|
212.1.2
by nskaggs
revert to 211 |
44 |
}
|
45 |
||
46 |
width: parent.width |
|
47 |
height: parent.height |
|
48 |
anchors.top: parent.top |
|
49 |
||
50 |
readonly property int minCellWidth: units.gu(30) |
|
51 |
cellWidth: Math.floor(Math.min.apply(Math, [3, 4].map(function(n) |
|
192.1.3
by Kunal Parmar
Review comment |
52 |
{ return ((width / n >= minCellWidth) ? width / n : width / 2) }))) |
53 |
||
212.1.2
by nskaggs
revert to 211 |
54 |
cellHeight: cellWidth * 1.4 |
55 |
||
56 |
model: 12 /* months in a year */ |
|
57 |
delegate: Item { |
|
58 |
width: yearView.cellWidth |
|
59 |
height: yearView.cellHeight |
|
60 |
||
61 |
MonthComponent{ |
|
62 |
id: monthComponent
|
|
63 |
monthDate: new Date(yearView.year.getFullYear(),index,1,0,0,0,0) |
|
64 |
anchors.fill: parent |
|
65 |
anchors.margins: units.gu(0.5) |
|
66 |
||
67 |
dayLabelFontSize:"x-small" |
|
68 |
dateLabelFontSize: "medium" |
|
69 |
monthLabelFontSize: "medium" |
|
70 |
yearLabelFontSize: "small" |
|
71 |
||
72 |
MouseArea{ |
|
138.1.1
by Kunal Parmar
creating month hightlight when necessary |
73 |
anchors.fill: parent |
212.1.2
by nskaggs
revert to 211 |
74 |
onClicked: { |
75 |
root.monthSelected(monthComponent.monthDate); |
|
63.1.1
by Kunal Parmar
year view implementation |
76 |
}
|
77 |
}
|
|
78 |
}
|
|
79 |
}
|
|
80 |
}
|
|
81 |
}
|