summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-04 14:59:07 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-04 14:59:07 +0200
commitdd0e823ddd72dda8adb3da5adf896abaed4feffe (patch)
treea4610d4a9e9d2d6365a092fdfc4ddf1e87dfc3ca
parent3cf284d8248efbb1556105b4be20a3b369923e4d (diff)
downloadkube-dd0e823ddd72dda8adb3da5adf896abaed4feffe.tar.gz
kube-dd0e823ddd72dda8adb3da5adf896abaed4feffe.zip
Always select first day of week initially
-rw-r--r--views/calendar/qml/View.qml23
-rw-r--r--views/calendar/qml/WeekView.qml20
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 {
27 id: root 27 id: root
28 28
29 property date currentDate: new Date() 29 property date currentDate: new Date()
30 property date selectedDate: currentDate 30 property date selectedDate: getFirstDayOfWeek(currentDate)
31 property bool autoUpdateDate: true 31 property bool autoUpdateDate: true
32 32
33 Timer { 33 Timer {
@@ -36,6 +36,24 @@ RowLayout {
36 onTriggered: root.currentDate = new Date() 36 onTriggered: root.currentDate = new Date()
37 } 37 }
38 38
39 function getFirstDayOfWeek(date) {
40 var firstDay = Qt.locale().firstDayOfWeek
41 var year = date.getFullYear()
42 var month = date.getMonth()
43 //Jup, getDate returns the day of the month
44 var day = date.getDate()
45
46 while (true) {
47 if (date.getDay() === firstDay) {
48 return date
49 }
50 day = day - 1
51 date = new Date(year, month, day)
52 }
53 return date
54 }
55
56
39 StackView.onActivated: { 57 StackView.onActivated: {
40 Kube.Fabric.postMessage(Kube.Messages.synchronize, {"type": "event"}) 58 Kube.Fabric.postMessage(Kube.Messages.synchronize, {"type": "event"})
41 } 59 }
@@ -136,6 +154,7 @@ RowLayout {
136 WeekView { 154 WeekView {
137 Layout.fillHeight: true 155 Layout.fillHeight: true
138 Layout.fillWidth: true 156 Layout.fillWidth: true
139 currentDate: root.selectedDate 157 currentDate: root.currentDate
158 startDate: root.selectedDate
140 } 159 }
141} 160}
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 {
29 property var dayWidth: (root.width - Kube.Units.gridUnit - Kube.Units.largeSpacing * 2) / root.daysToShow 29 property var dayWidth: (root.width - Kube.Units.gridUnit - Kube.Units.largeSpacing * 2) / root.daysToShow
30 property var hourHeight: Kube.Units.gridUnit * 2 30 property var hourHeight: Kube.Units.gridUnit * 2
31 property date currentDate 31 property date currentDate
32 32 property date startDate: currentDate
33 function getFirstDayOfWeek(date) {
34 var firstDay = Qt.locale().firstDayOfWeek
35 var year = date.getFullYear()
36 var month = date.getMonth()
37 //Jup, getDate returns the day of the month
38 var day = date.getDate()
39
40 while (true) {
41 if (date.getDay() === firstDay) {
42 return date
43 }
44 day = day - 1
45 date = new Date(year, month, day)
46 }
47 return date
48 }
49
50 property date startDate: getFirstDayOfWeek(currentDate)
51 33
52 Item { 34 Item {
53 anchors { 35 anchors {