11import org.mauikit.controls as Maui
12import org.mauikit.calendar as Kalendar
14import "dateutils.js" as DateUtils
65 readonly
property date currentDate:
new Date()
70 readonly property
string title:
Qt.formatDate(pathView.currentItem.firstDayOfMonth, "MMM yyyy")
75 property var openOccurrence: ({})
80 property var filter: {
89 readonly
property alias model : _monthViewModel
94 property date startDate
99 property date firstDayOfMonth
114 property bool initialMonth:
true
119 readonly
property bool isLarge: width >
Maui.Style.units.gridUnit * 40
124 readonly
property bool isTiny: width <
Maui.Style.units.gridUnit * 18
129 property date selectedDate : currentDate
134 property bool dragDropEnabled:
true
139 property alias interactive : pathView.interactive
144 signal dateClicked(var date)
149 signal dateRightClicked(var date)
154 signal dateDoubleClicked(var date)
156 background: Rectangle
158 color:
Maui.Theme.backgroundColor
161 Kalendar.InfiniteCalendarViewModel
164 scale: Kalendar.InfiniteCalendarViewModel.MonthScale
167 contentItem: PathView
171 flickDeceleration:
Maui.Style.units.longDuration
172 interactive:
Maui.Handy.isMobile
174 preferredHighlightBegin: 0.5
175 preferredHighlightEnd: 0.5
178 highlightMoveDuration: 0
180 snapMode: PathView.SnapToItem
185 startX: - pathView.width * pathView.count / 2 + pathView.width / 2
186 startY: pathView.height / 2
188 x: pathView.width * pathView.count / 2 + pathView.width / 2
189 y: pathView.height / 2
195 property int startIndex
197 Component.onCompleted:
199 startIndex = count / 2;
200 currentIndex = startIndex;
203 onCurrentIndexChanged:
205 control.startDate = currentItem.startDate;
206 control.firstDayOfMonth = currentItem.firstDayOfMonth;
207 control.month = currentItem.month;
208 control.year = currentItem.year;
210 if(currentIndex >= count - 2) {
211 model.addDates(
true);
212 }
else if (currentIndex <= 1) {
213 model.addDates(
false);
214 startIndex += model.datesToAdd;
222 property date startDate: model.startDate
223 property date firstDayOfMonth: model.firstDay
224 property int month: model.selectedMonth - 1
225 property int year: model.selectedYear
227 property bool isNextOrCurrentItem: index >= pathView.currentIndex -1 && index <= pathView.currentIndex + 1
228 property bool isCurrentItem: PathView.isCurrentItem
230 active: isNextOrCurrentItem
231 asynchronous: !isCurrentItem
232 visible:
status === Loader.Ready
234 sourceComponent: Kalendar.DayGridView
237 objectName:
"monthView"
239 width: pathView.width
240 height: pathView.height
243 isCurrentView: viewLoader.isCurrentItem
244 dragDropEnabled: control.dragDropEnabled
246 startDate: viewLoader.startDate
247 currentDate: control.currentDate
248 month: viewLoader.month
250 onDateClicked: (date) =>
252 control.selectedDate = date
253 control.dateClicked(control.selectedDate)
256 onDateDoubleClicked: (date) =>
258 control.selectedDate = date
259 control.dateDoubleClicked(control.selectedDate)
264 leftPadding:
Maui.Style.units.smallSpacing
265 rightPadding:
Maui.Style.units.smallSpacing
271 let longText = day.toLocaleString(
Qt.locale(),
"dddd");
272 let midText = day.toLocaleString(
Qt.locale(),
"ddd");
273 let shortText = midText.slice(0,1);
276 return control.isTiny ? shortText : midText;
280 horizontalAlignment:
Text.AlignLeft
282 font.weight: Font.Bold
283 font.pointSize:
Maui.Style.fontSizes.big
288 weekHeaderDelegate:
Maui.LabelDelegate
290 padding:
Maui.Style.units.smallSpacing
292 label.horizontalAlignment:
Qt.AlignHCenter
293 text: DateUtils.getWeek(startDate,
Qt.locale().firstDayOfWeek)
301 openOccurrence: control.openOccurrence
311 setToDate(
new Date())
319 setToDate(DateUtils.addMonthsToDate(pathView.currentItem.firstDayOfMonth, 1))
325 function previousDate()
327 setToDate(DateUtils.addMonthsToDate(pathView.currentItem.firstDayOfMonth, -1))
333 function addMonthsToDate(date, days)
335 return DateUtils.addMonthsToDate(date, days)
341 function setToDate(date, isInitialMonth =
true)
343 control.initialMonth = isInitialMonth;
344 let monthDiff = date.getMonth() - pathView.currentItem.firstDayOfMonth.getMonth() + (12 * (date.getFullYear() - pathView.currentItem.firstDayOfMonth.getFullYear()))
345 let newIndex = pathView.currentIndex + monthDiff;
347 let firstItemDate = pathView.model.data(pathView.model.index(1,0), Kalendar.InfiniteCalendarViewModel.FirstDayOfMonthRole);
348 let lastItemDate = pathView.model.data(pathView.model.index(pathView.model.rowCount() - 1,0), Kalendar.InfiniteCalendarViewModel.FirstDayOfMonthRole);
350 while(firstItemDate >= date) {
351 pathView.model.addDates(
false)
352 firstItemDate = pathView.model.data(pathView.model.index(1,0), Kalendar.InfiniteCalendarViewModel.FirstDayOfMonthRole);
355 if(firstItemDate < date && newIndex === 0) {
356 newIndex = date.getMonth() - firstItemDate.getMonth() + (12 * (date.getFullYear() - firstItemDate.getFullYear())) + 1;
359 while(lastItemDate <= date) {
360 pathView.model.addDates(
true)
361 lastItemDate = pathView.model.data(pathView.model.index(pathView.model.rowCount() - 1,0), Kalendar.InfiniteCalendarViewModel.FirstDayOfMonthRole);
363 pathView.currentIndex = newIndex;
Q_SCRIPTABLE CaptureState status()
QString path(const QString &relativePath)
QString label(StandardShortcut id)