3
3
import "dateExt.js" as DateExt
4
4
import "colorUtils.js" as Color
9
// FIXME: change monthview to use this date as start date
10
property alias startDay: intern.currentDayStart
12
readonly property var monthStart: currentItem != null ? currentItem.monthStart : (new Date()).monthStart()
13
readonly property var monthEnd: currentItem != null ? currentItem.monthEnd : (new Date()).monthStart().addMonths(1)
14
readonly property var currentDayStart: intern.currentDayStart
16
property bool compressed: false
17
readonly property real compressedHeight: intern.squareUnit + intern.verticalMargin * 2
18
readonly property real expandedHeight: intern.squareUnit * 6 + intern.verticalMargin * 2
20
signal incrementCurrentDay
21
signal decrementCurrentDay
23
signal gotoNextMonth(int month)
24
signal focusOnDay(var dayStart)
26
onCurrentItemChanged: {
27
if (currentItem == null) {
28
intern.currentDayStart = intern.currentDayStart
31
if (currentItem.monthStart <= intern.currentDayStart && intern.currentDayStart < currentItem.monthEnd)
33
if (currentItem.monthStart <= intern.today && intern.today < currentItem.monthEnd)
34
intern.currentDayStart = intern.today
36
intern.currentDayStart = currentItem.monthStart
39
onIncrementCurrentDay: {
40
var t = intern.currentDayStart.addDays(1)
42
intern.currentDayStart = t
44
else if (currentIndex < count - 1) {
45
intern.currentDayStart = t
46
currentIndex = currentIndex + 1
50
onDecrementCurrentDay: {
51
var t = intern.currentDayStart.addDays(-1)
52
if (t >= monthStart) {
53
intern.currentDayStart = t
55
else if (currentIndex > 0) {
56
intern.currentDayStart = t
57
currentIndex = currentIndex - 1
62
if (monthStart.getMonth() != month) {
63
var i = intern.monthIndex0, m = intern.today.getMonth()
73
if (dayStart < monthStart) {
74
if (currentIndex > 0) {
75
intern.currentDayStart = dayStart
76
currentIndex = currentIndex - 1
79
else if (dayStart >= monthEnd) {
80
if (currentIndex < count - 1) {
81
intern.currentDayStart = dayStart
82
currentIndex = currentIndex + 1
85
else intern.currentDayStart = dayStart
88
function goToToday() {
89
var today = (new Date()).midnight();
90
intern.currentDayStart = today
91
currentIndex= intern.monthIndex0
95
Keys.onLeftPressed: decrementCurrentDay()
96
Keys.onRightPressed: incrementCurrentDay()
101
property int squareUnit: monthView.width / 8
102
property int verticalMargin: units.gu(1)
103
property int weekstartDay: Qt.locale().firstDayOfWeek
104
property int monthCount: 49 // months for +-2 years
106
property var today: (new Date()).midnight() // TODO: update at midnight
107
property var currentDayStart: today
108
property int monthIndex0: Math.floor(monthCount / 2)
109
property var monthStart0: today.monthStart()
113
height: compressed ? compressedHeight : expandedHeight
115
interactive: !compressed
117
orientation: ListView.Horizontal
118
snapMode: ListView.SnapOneItem
119
cacheBuffer: width + 1
121
highlightRangeMode: ListView.StrictlyEnforceRange
122
preferredHighlightBegin: 0
123
preferredHighlightEnd: width
125
model: intern.monthCount
126
currentIndex: intern.monthIndex0
131
property var monthStart: intern.monthStart0.addMonths(index - intern.monthIndex0)
132
property var monthEnd: monthStart.addMonths(1)
133
property var gridStart: monthStart.weekStart(intern.weekstartDay)
134
property int currentWeekRow: Math.floor((currentDayStart.getTime() - gridStart.getTime()) / Date.msPerWeek)
136
width: monthView.width
137
height: monthView.height
145
x: intern.squareUnit / 2
146
y: intern.verticalMargin
147
width: intern.squareUnit * columns
148
height: intern.squareUnit * rows
151
model: monthGrid.rows * monthGrid.columns
154
property var dayStart: gridStart.addDays(index)
155
property bool isCurrentMonth: monthStart <= dayStart && dayStart < monthEnd
156
property bool isToday: dayStart.getTime() === intern.today.getTime()
157
property bool isCurrent: dayStart.getTime() === intern.currentDayStart.getTime()
158
property int weekday: (index % 7 + intern.weekstartDay) % 7
159
property bool isSunday: weekday == 0
160
property int row: Math.floor(index / 7)
161
property bool isCurrentWeek: row == currentWeekRow
162
property real topMargin: (row == 0 || (monthView.compressed && isCurrentWeek)) ? -intern.verticalMargin : 0
163
property real bottomMargin: (row == 5 || (monthView.compressed && isCurrentWeek)) ? -intern.verticalMargin : 0
164
visible: monthView.compressed ? isCurrentWeek : true
165
width: intern.squareUnit
166
height: intern.squareUnit
170
anchors.topMargin: dayItem.topMargin
171
anchors.bottomMargin: dayItem.bottomMargin
172
color: Color.warmGrey
176
anchors.centerIn: parent
177
text: dayStart.getDate()
178
font: themeDummy.font
179
color: isToday ? Color.ubuntuOrange : themeDummy.color
180
scale: isCurrent ? 1.8 : 1.
181
opacity: isCurrentMonth ? 1. : 0.3
183
NumberAnimation { duration: 50 }
188
anchors.topMargin: dayItem.topMargin
189
anchors.bottomMargin: dayItem.bottomMargin
190
onReleased: monthView.focusOnDay(dayStart)
192
// Component.onCompleted: console.log(dayStart, intern.currentDayStart)
197
// Component.onCompleted: console.log("Created delegate for month", index, monthStart, gridStart, currentWeekRow, currentWeekRowReal)
204
// Component.onCompleted: console.log(color, Qt.lighter(color, 1.74))
9
property var currentMonth: DateExt.today();
11
signal dateSelected(var date);
16
property var startMonth: addMonth(currentMonth,-1);
18
anchors.top:parent.top
23
onNextItemHighlighted: {
27
onPreviousItemHighlighted: {
31
function nextMonth() {
32
currentMonth = addMonth(currentMonth,1);
35
function previousMonth(){
36
currentMonth = addMonth(currentMonth,-1);
39
function addMonth(date,month){
40
var temp = new Date(date.getFullYear(),date.getMonth(),1,0,0,0);
41
temp.setMonth(date.getMonth() + month);
45
delegate: MonthComponent{
46
width: parent.width - units.gu(5)
47
height: parent.height - units.gu(5)
49
monthDate: getMonthDate();
51
function getMonthDate() {
53
if (index === monthViewPath.currentIndex) {
54
return monthViewPath.startMonth;
58
var previousIndex = monthViewPath.currentIndex > 0 ? monthViewPath.currentIndex - 1 : 2
59
if ( index === previousIndex ) {
60
return monthViewPath.addMonth(monthViewPath.startMonth,2);
64
return monthViewPath.addMonth(monthViewPath.startMonth,1);
68
monthViewPage.dateSelected(date);