3
3
import "dateExt.js" as DateExt
4
4
import "colorUtils.js" as Color
9
readonly property var monthStart: currentItem != null ? currentItem.monthStart : (new Date()).monthStart()
10
readonly property var monthEnd: currentItem != null ? currentItem.monthEnd : (new Date()).monthStart().addMonths(1)
11
readonly property var currentDayStart: intern.currentDayStart
13
property bool compressed: false
14
readonly property real compressedHeight: intern.squareUnit + intern.verticalMargin * 2
15
readonly property real expandedHeight: intern.squareUnit * 6 + intern.verticalMargin * 2
17
signal incrementCurrentDay
18
signal decrementCurrentDay
20
signal gotoNextMonth(int month)
21
signal focusOnDay(var dayStart)
23
onCurrentItemChanged: {
24
if (currentItem == null) {
25
intern.currentDayStart = intern.currentDayStart
28
if (currentItem.monthStart <= intern.currentDayStart && intern.currentDayStart < currentItem.monthEnd)
30
if (currentItem.monthStart <= intern.today && intern.today < currentItem.monthEnd)
31
intern.currentDayStart = intern.today
33
intern.currentDayStart = currentItem.monthStart
36
onIncrementCurrentDay: {
37
var t = intern.currentDayStart.addDays(1)
39
intern.currentDayStart = t
41
else if (currentIndex < count - 1) {
42
intern.currentDayStart = t
43
currentIndex = currentIndex + 1
47
onDecrementCurrentDay: {
48
var t = intern.currentDayStart.addDays(-1)
49
if (t >= monthStart) {
50
intern.currentDayStart = t
52
else if (currentIndex > 0) {
53
intern.currentDayStart = t
54
currentIndex = currentIndex - 1
59
if (monthStart.getMonth() != month) {
60
var i = intern.monthIndex0, m = intern.today.getMonth()
70
if (dayStart < monthStart) {
71
if (currentIndex > 0) {
72
intern.currentDayStart = dayStart
73
currentIndex = currentIndex - 1
76
else if (dayStart >= monthEnd) {
77
if (currentIndex < count - 1) {
78
intern.currentDayStart = dayStart
79
currentIndex = currentIndex + 1
82
else intern.currentDayStart = dayStart
86
Keys.onLeftPressed: decrementCurrentDay()
87
Keys.onRightPressed: incrementCurrentDay()
92
property int squareUnit: monthView.width / 8
93
property int verticalMargin: units.gu(1)
94
property int weekstartDay: Qt.locale().firstDayOfWeek
95
property int monthCount: 49 // months for +-2 years
97
property var today: (new Date()).midnight() // TODO: update at midnight
98
property var currentDayStart: today
99
property int monthIndex0: Math.floor(monthCount / 2)
100
property var monthStart0: today.monthStart()
104
height: compressed ? compressedHeight : expandedHeight
106
interactive: !compressed
108
orientation: ListView.Horizontal
109
snapMode: ListView.SnapOneItem
110
cacheBuffer: width + 1
112
highlightRangeMode: ListView.StrictlyEnforceRange
113
preferredHighlightBegin: 0
114
preferredHighlightEnd: width
116
model: intern.monthCount
117
currentIndex: intern.monthIndex0
122
property var monthStart: intern.monthStart0.addMonths(index - intern.monthIndex0)
123
property var monthEnd: monthStart.addMonths(1)
124
property var gridStart: monthStart.weekStart(intern.weekstartDay)
125
property int currentWeekRow: Math.floor((currentDayStart.getTime() - gridStart.getTime()) / Date.msPerWeek)
127
width: monthView.width
128
height: monthView.height
136
x: intern.squareUnit / 2
137
y: intern.verticalMargin
138
width: intern.squareUnit * columns
139
height: intern.squareUnit * rows
142
model: monthGrid.rows * monthGrid.columns
145
property var dayStart: gridStart.addDays(index)
146
property bool isCurrentMonth: monthStart <= dayStart && dayStart < monthEnd
147
property bool isToday: dayStart.getTime() === intern.today.getTime()
148
property bool isCurrent: dayStart.getTime() === intern.currentDayStart.getTime()
149
property int weekday: (index % 7 + intern.weekstartDay) % 7
150
property bool isSunday: weekday == 0
151
property int row: Math.floor(index / 7)
152
property bool isCurrentWeek: row == currentWeekRow
153
property real topMargin: (row == 0 || (monthView.compressed && isCurrentWeek)) ? -intern.verticalMargin : 0
154
property real bottomMargin: (row == 5 || (monthView.compressed && isCurrentWeek)) ? -intern.verticalMargin : 0
155
visible: monthView.compressed ? isCurrentWeek : true
156
width: intern.squareUnit
157
height: intern.squareUnit
161
anchors.topMargin: dayItem.topMargin
162
anchors.bottomMargin: dayItem.bottomMargin
163
color: Color.warmGrey
167
anchors.centerIn: parent
168
text: dayStart.getDate()
169
font: themeDummy.font
170
color: isToday ? Color.ubuntuOrange : themeDummy.color
171
scale: isCurrent ? 1.8 : 1.
172
opacity: isCurrentMonth ? 1. : 0.3
174
NumberAnimation { duration: 50 }
179
anchors.topMargin: dayItem.topMargin
180
anchors.bottomMargin: dayItem.bottomMargin
181
onReleased: monthView.focusOnDay(dayStart)
183
// Component.onCompleted: console.log(dayStart, intern.currentDayStart)
188
// Component.onCompleted: console.log("Created delegate for month", index, monthStart, gridStart, currentWeekRow, currentWeekRowReal)
195
// Component.onCompleted: console.log(color, Qt.lighter(color, 1.74))
8
objectName: "MonthView"
10
property var currentMonth: DateExt.today();
12
signal dateSelected(var date);
14
Keys.forwardTo: [monthViewPath]
19
property var startMonth: currentMonth;
21
anchors.top:parent.top
26
onNextItemHighlighted: {
30
onPreviousItemHighlighted: {
34
function nextMonth() {
35
currentMonth = addMonth(currentMonth, 1);
38
function previousMonth() {
39
currentMonth = addMonth(currentMonth, -1);
42
function addMonth(date,month) {
43
return new Date(date.getFullYear(), date.getMonth() + month, 1, 0, 0, 0);
46
delegate: MonthComponent {
47
property bool isCurrentItem: index === monthViewPath.currentIndex
51
width: parent.width - units.gu(5)
52
height: parent.height - units.gu(5)
54
currentMonth: monthViewPath.addMonth(monthViewPath.startMonth,
55
monthViewPath.indexType(index));
60
monthViewPage.dateSelected(date);