19
19
import Ubuntu.Components 1.3
20
21
import "dateExt.js" as DateExt
21
22
import "colorUtils.js" as Color
22
23
import "./3rd-party/lunar.js" as Lunar
26
27
objectName: "monthViewPage"
28
property var currentMonth: DateExt.today();
29
property var anchorDate: DateExt.today();
30
readonly property var firstDayOfAnchorDate: new Date(anchorDate.getFullYear(),
31
anchorDate.getMonth(),
34
readonly property var currentDate: monthViewPath.currentItem.indexDate
29
36
property var selectedDay;
37
property var highlightedDate;
38
property bool displayLunarCalendar: false
31
40
signal dateSelected(var date);
32
signal dateHighlighted(var date);
34
42
Keys.forwardTo: [monthViewPath]
43
createEventAt: highlightedDate ? highlightedDate : currentDate
44
onAnchorDateChanged: monthViewPath.scrollToBegginer()
37
47
id: calendarTodayAction
49
59
leadingActionBar.actions: tabs.tabsAction
50
60
trailingActionBar.actions: [
51
61
calendarTodayAction,
52
commonHeaderActions.newEventAction,
53
62
commonHeaderActions.showCalendarAction,
54
63
commonHeaderActions.reloadAction,
55
64
commonHeaderActions.syncCalendarAction,
56
65
commonHeaderActions.settingsAction
59
// TRANSLATORS: This string is used in the header of the month, week and day views.
60
// %1 is going to be replaced by the month name, %2 by the year.
61
title: i18n.tr("%1 %2").arg(Qt.locale().standaloneMonthName(currentMonth.getMonth(), Locale.LongFormat)).arg(currentMonth.getFullYear())
68
if (displayLunarCalendar) {
69
var year = currentDate.getFullYear()
70
var month = currentDate.getMonth()
71
var day = Math.floor(Date.daysInMonth(year, month) / 2.0)
72
var lunarDate = Lunar.calendar.solar2lunar(year, month + 1, day)
73
return i18n.tr("%1 %2").arg(lunarDate .IMonthCn).arg(lunarDate.gzYear)
75
// TRANSLATORS: This string is used in the header of the month, week and day views.
76
// %1 is going to be replaced by the month name, %2 by the year.
77
return i18n.tr("%1 %2").arg(Qt.locale().standaloneMonthName(currentDate.getMonth(), Locale.LongFormat)).arg(currentDate.getFullYear())
68
85
objectName: "monthViewPath"
70
property var startMonth: currentMonth;
74
89
topMargin: header.height
77
onNextItemHighlighted: {
81
onPreviousItemHighlighted: {
85
function nextMonth() {
86
currentMonth = addMonth(currentMonth, 1);
89
function previousMonth() {
90
currentMonth = addMonth(currentMonth, -1);
93
function addMonth(date,month) {
94
return new Date(date.getFullYear(), date.getMonth() + month, 1, 0, 0, 0);
90
bottomMargin: monthViewPage.bottomEdgeHeight
93
delegate: MonthWithEventsComponent {
94
property var indexDate: firstDayOfAnchorDate.addMonths(monthViewPath.loopCurrentIndex + monthViewPath.indexType(index))
96
currentMonth: indexDate.getMonth()
97
currentYear: indexDate.getFullYear()
98
displayLunarCalendar: monthViewPage.displayLunarCalendar
100
autoUpdate: monthViewPage.tabSelected
101
modelFilter: eventModel.filter
98
102
width: parent.width - units.gu(4)
99
103
height: parent.height
101
sourceComponent: delegateComponent
102
asynchronous: index !== monthViewPath.currentIndex
105
id: delegateComponent
108
isCurrentItem: index === monthViewPath.currentIndex
112
displayWeekNumber: mainView.displayWeekNumber
113
displayLunarCalendar: mainView.displayLunarCalendar
116
currentMonth: monthViewPath.addMonth(monthViewPath.startMonth,
117
monthViewPath.indexType(index));
119
selectedDay: monthViewPage.selectedDay
123
monthViewPage.dateSelected(date);
127
monthViewPage.dateHighlighted(date);
104
isCurrentItem: PathView.isCurrentItem
105
isActive: !monthViewPath.moving && !monthViewPath.flicking
106
displayWeekNumber: mainView.displayWeekNumber
107
highlightedDate: monthViewPage.highlightedDate
111
monthViewPage.dateSelected(date);
114
monthViewPage.highlightedDate = date
134
Component.onCompleted: {
135
pageHeader.title = Qt.binding(function(){
136
if(mainView.displayLunarCalendar){
137
var year = currentMonth.getFullYear()
138
var month = currentMonth.getMonth()
139
var day = Math.floor(Date.daysInMonth(year, month) / 2.0)
140
var lunarDate = Lunar.calendar.solar2lunar( year, month + 1, day)
141
return i18n.tr("%1 %2").arg(lunarDate .IMonthCn).arg(lunarDate.gzYear)
143
// TRANSLATORS: this is a time formatting string,
144
// see http://qt-project.org/doc/qt-5/qml-qtqml-date.html#details for valid expressions.
145
// It's used in the header of the month and week views
146
var monthName = currentMonth.toLocaleString(Qt.locale(),i18n.tr("MMMM yyyy"))
147
return monthName[0].toUpperCase() + monthName.substr(1, monthName.length - 1)