From 2525b7cb66877479df393b84bba1bd4a76146b45 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 11 Jul 2018 07:28:04 +0200 Subject: Make the calendar work with the current time --- views/calendar/main.qml | 1 + views/calendar/qml/View.qml | 8 ++++++-- views/calendar/qml/WeekEvents.qml | 2 -- views/calendar/qml/WeekView.qml | 26 ++++++++++++++++++++++++-- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/views/calendar/main.qml b/views/calendar/main.qml index e3915e74..e8cd9c4d 100644 --- a/views/calendar/main.qml +++ b/views/calendar/main.qml @@ -143,5 +143,6 @@ ApplicationWindow { View { anchors.fill: parent + currentDate: "2018-04-09" } } diff --git a/views/calendar/qml/View.qml b/views/calendar/qml/View.qml index 434c92d1..f870a850 100644 --- a/views/calendar/qml/View.qml +++ b/views/calendar/qml/View.qml @@ -26,6 +26,9 @@ import org.kube.framework 1.0 as Kube RowLayout { id: root + //TODO update every second + property date currentDate: new Date() + anchors.fill: parent Rectangle { @@ -100,7 +103,8 @@ RowLayout { } WeekView { - Layout.fillHeight: parent.height - Layout.fillWidth: parent.height + Layout.fillHeight: true + Layout.fillWidth: true + currentDate: root.currentDate } } diff --git a/views/calendar/qml/WeekEvents.qml b/views/calendar/qml/WeekEvents.qml index 774f254e..73774b27 100644 --- a/views/calendar/qml/WeekEvents.qml +++ b/views/calendar/qml/WeekEvents.qml @@ -3,6 +3,4 @@ import QtQuick 2.7 import org.kube.framework 1.0 as Kube Kube.PeriodDayEventModel { - start: "2018-04-09" - length: 7 } diff --git a/views/calendar/qml/WeekView.qml b/views/calendar/qml/WeekView.qml index 08a15ccf..781aefa5 100644 --- a/views/calendar/qml/WeekView.qml +++ b/views/calendar/qml/WeekView.qml @@ -28,6 +28,25 @@ FocusScope { property var dayWidth: (root.width - Kube.Units.gridUnit - Kube.Units.largeSpacing * 2) / 7 property var hourHeight: Kube.Units.gridUnit * 2 + property date currentDate + + function getMonday(date) { + 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() === Locale.Monday) { + return date + } + day = day - 1 + date = new Date(year, month, day) + } + return date + } + + property date startDate: getMonday(currentDate) Item { anchors { @@ -167,7 +186,10 @@ FocusScope { //END time labels Repeater { - model: WeekEvents{} + model: WeekEvents { + start: root.startDate + length: 7 + } delegate: Rectangle { id: day @@ -219,7 +241,7 @@ FocusScope { rightMargin: Kube.Units.smallSpacing } width: root.dayWidth - Kube.Units.smallSpacing * 2 - Kube.Units.gridUnit * model.modelData.indention - height: root.hourHeight * model.modelData.duration + height: Math.max(root.hourHeight * 0.5, root.hourHeight * model.modelData.duration) y: root.hourHeight * model.modelData.starts x: Kube.Units.gridUnit * model.modelData.indention -- cgit v1.2.3