Warning, /plasma-mobile/calindori/src/contents/ui/WeekView.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: 2020 Dimitris Kardarakos <dimkard@posteo.net>
0003 *
0004 * SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006
0007 import QtQuick 2.7
0008 import QtQuick.Controls 2.0 as Controls2
0009 import QtQuick.Layouts 1.3
0010 import org.kde.kirigami 2.12 as Kirigami
0011 import org.kde.calindori 0.1 as Calindori
0012
0013 ListView {
0014 id: root
0015
0016 property int fstDayOfWeek: _appLocale.firstDayOfWeek
0017 property date startDate
0018 property date selectedWeekDate: firstDateOfWeek(startDate)
0019 property date selectedDate: startDate
0020 property var cal
0021 property bool wideScreen
0022
0023 signal nextWeek
0024 signal previousWeek
0025 signal goCurrentWeek
0026 signal addEvent
0027 signal addTodo
0028
0029 /**
0030 * @brief Get the date of the first day of a week, given a date in the week
0031 *
0032 */
0033
0034 function firstDateOfWeek(inputDate)
0035 {
0036 var t = inputDate;
0037 t.setDate(inputDate.getDate() - inputDate.getDay() + (inputDate.getDay() >= fstDayOfWeek ? fstDayOfWeek : fstDayOfWeek-7));
0038 t.setHours(inputDate.getHours())
0039 t.setMinutes(0);
0040 t.setSeconds(0);
0041
0042 return t;
0043 }
0044
0045 /**
0046 * @brief Remove the editor page from the stack. If an incidence page exists in the page stack, remove it as well
0047 *
0048 */
0049 function removeEditorPage() {
0050 pageStack.pop();
0051 if(pageStack.lastItem && pageStack.lastItem.hasOwnProperty("isIncidencePage")) {
0052 pageStack.pop(incidencePage);
0053 }
0054 }
0055
0056 function moveDate(startDt, offset)
0057 {
0058 var movedDt = startDt;
0059 movedDt.setDate(startDt.getDate() + offset);
0060
0061 return movedDt;
0062 }
0063
0064 onNextWeek: {
0065 selectedWeekDate = moveDate(selectedWeekDate, 7);
0066 selectedDate = selectedWeekDate;
0067 currentIndex = 0;
0068 }
0069
0070 onPreviousWeek: {
0071 selectedWeekDate = moveDate(selectedWeekDate, -7);
0072 selectedDate = selectedWeekDate;
0073 currentIndex = 0;
0074 }
0075
0076 onGoCurrentWeek: {
0077 selectedWeekDate = firstDateOfWeek(startDate);
0078 selectedDate = startDate;
0079 currentIndex = selectedDate.getDay() >= fstDayOfWeek ? selectedDate.getDay() - fstDayOfWeek : 7 - (selectedDate.getDay() + fstDayOfWeek)
0080 }
0081
0082 onCurrentIndexChanged: {
0083 if (pageStack.depth > 1) {
0084 pageStack.pop(null);
0085 }
0086 }
0087
0088 model: 7
0089 currentIndex: selectedDate.getDay() >= fstDayOfWeek ? selectedDate.getDay() - fstDayOfWeek : 7 - (selectedDate.getDay() + fstDayOfWeek)
0090
0091 delegate: Kirigami.SwipeListItem {
0092 id: dayListItem
0093
0094 property var weekDay: model.index
0095 property var itemDate: {
0096 var dt = root.selectedWeekDate;
0097 dt.setDate(dt.getDate() + index);
0098 dt.setHours(dt.getHours() + 1);
0099 dt.setMinutes(0);
0100 dt.setSeconds(0);
0101 dt.setMilliseconds(0);
0102
0103 return dt;
0104 }
0105
0106 alwaysVisibleActions: false
0107
0108 contentItem: RowLayout {
0109 spacing: Kirigami.Units.largeSpacing * 2
0110
0111 ColumnLayout {
0112 Layout.minimumWidth: Kirigami.Units.gridUnit * 2
0113
0114 Controls2.Label {
0115 text: _appLocale.dayName(model.index + fstDayOfWeek, Locale.ShortFormat)
0116 Layout.alignment: Qt.AlignHCenter
0117 }
0118
0119 Controls2.Label {
0120 font: Kirigami.Theme.smallFont
0121 text: itemDate.toLocaleDateString(_appLocale, "d MMM")
0122 Layout.alignment: Qt.AlignHCenter
0123 }
0124 }
0125
0126 ColumnLayout {
0127
0128 Repeater {
0129 model: Calindori.IncidenceModel {
0130 appLocale: _appLocale
0131 filterDt: moveDate(root.selectedWeekDate, dayListItem.weekDay)
0132 filterMode: 4
0133 }
0134
0135 IncidenceItemDelegate {
0136 itemBackgroundColor: model.type === 0 ? Kirigami.Theme.backgroundColor : Qt.darker(Kirigami.Theme.backgroundColor, 1.1)
0137 label: model.summary
0138 subtitle: (model.type == 0 ? model.displayStartEndTime : (model.displayDueTime || model.displayStartTime))
0139 Layout.fillWidth: true
0140
0141 onClicked: {
0142 if(pageStack.lastItem && pageStack.lastItem.hasOwnProperty("isIncidencePage")) {
0143 pageStack.pop(incidencePage);
0144 }
0145
0146 pageStack.push(incidencePage, { incidence: model })
0147 }
0148 }
0149 }
0150 }
0151 }
0152
0153 actions: [
0154 Kirigami.Action {
0155 iconName: "resource-calendar-insert"
0156 text: i18n("Create Event")
0157
0158 onTriggered: pageStack.push(eventEditor, { startDt: itemDate })
0159 },
0160
0161 Kirigami.Action {
0162 iconName: "task-new"
0163 text: i18n("Create Task")
0164
0165 onTriggered: pageStack.push(todoEditor, { startDt: itemDate })}
0166 ]
0167
0168 onClicked: { root.selectedDate = moveDate(root.selectedWeekDate, model.index) }
0169
0170 }
0171
0172 Component {
0173 id: incidencePage
0174
0175 IncidencePage {
0176 calendar: root.cal
0177 }
0178 }
0179
0180 Component {
0181 id: eventEditor
0182
0183 EventEditorPage {
0184 calendar: root.cal
0185
0186 onEditcompleted: removeEditorPage()
0187 }
0188 }
0189
0190 Component {
0191 id: todoEditor
0192
0193 TodoEditorPage {
0194 onEditcompleted: removeEditorPage()
0195 }
0196 }
0197 }