From dd0e823ddd72dda8adb3da5adf896abaed4feffe Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 4 Aug 2018 14:59:07 +0200 Subject: Always select first day of week initially --- views/calendar/qml/View.qml | 23 +++++++++++++++++++++-- views/calendar/qml/WeekView.qml | 20 +------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/views/calendar/qml/View.qml b/views/calendar/qml/View.qml index 601ca0cf..f49d8bff 100644 --- a/views/calendar/qml/View.qml +++ b/views/calendar/qml/View.qml @@ -27,7 +27,7 @@ RowLayout { id: root property date currentDate: new Date() - property date selectedDate: currentDate + property date selectedDate: getFirstDayOfWeek(currentDate) property bool autoUpdateDate: true Timer { @@ -36,6 +36,24 @@ RowLayout { onTriggered: root.currentDate = new Date() } + function getFirstDayOfWeek(date) { + var firstDay = Qt.locale().firstDayOfWeek + var year = date.getFullYear() + var month = date.getMonth() + //Jup, getDate returns the day of the month + var day = date.getDate() + + while (true) { + if (date.getDay() === firstDay) { + return date + } + day = day - 1 + date = new Date(year, month, day) + } + return date + } + + StackView.onActivated: { Kube.Fabric.postMessage(Kube.Messages.synchronize, {"type": "event"}) } @@ -136,6 +154,7 @@ RowLayout { WeekView { Layout.fillHeight: true Layout.fillWidth: true - currentDate: root.selectedDate + currentDate: root.currentDate + startDate: root.selectedDate } } diff --git a/views/calendar/qml/WeekView.qml b/views/calendar/qml/WeekView.qml index 484a151f..c9717241 100644 --- a/views/calendar/qml/WeekView.qml +++ b/views/calendar/qml/WeekView.qml @@ -29,25 +29,7 @@ FocusScope { property var dayWidth: (root.width - Kube.Units.gridUnit - Kube.Units.largeSpacing * 2) / root.daysToShow property var hourHeight: Kube.Units.gridUnit * 2 property date currentDate - - function getFirstDayOfWeek(date) { - var firstDay = Qt.locale().firstDayOfWeek - var year = date.getFullYear() - var month = date.getMonth() - //Jup, getDate returns the day of the month - var day = date.getDate() - - while (true) { - if (date.getDay() === firstDay) { - return date - } - day = day - 1 - date = new Date(year, month, day) - } - return date - } - - property date startDate: getFirstDayOfWeek(currentDate) + property date startDate: currentDate Item { anchors { -- cgit v1.2.3