Warning, /plasma-mobile/calindori/src/contents/ui/CalendarMonthView.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.0 as Kirigami
0011 import org.kde.calindori 0.1 as Calindori
0012 
0013 /**
0014  * Calendar component that displays:
0015  *  - a header with current day's information
0016  *  - a table (grid) with the days of the current month
0017  *  - a set of actions to navigate between months
0018  * It offers vertical swiping
0019  */
0020 Controls2.SwipeView {
0021     id: root
0022 
0023     property alias selectedDate: monthView.selectedDate
0024     property alias displayedMonthName: monthView.displayedMonthName
0025     property alias displayedYear: monthView.displayedYear
0026     property alias showHeader: monthView.showHeader
0027     property alias showMonthName: monthView.showMonthName
0028     property alias showYear: monthView.showYear
0029     property alias dayRectangleWidth: monthView.dayRectWidth
0030     property int previousIndex
0031     property var cal
0032     /**
0033      * @brief When set, we take over the handling of the container items indexes programmatically
0034      *
0035      */
0036     property bool manualIndexing: false
0037 
0038     signal nextMonth
0039     signal previousMonth
0040     signal goToday
0041     /**
0042      * @brief It should be emitted when the SwipeView currentIndex is set to the first or the last one
0043      *
0044      * @param lastDate p_lastDate:...
0045      */
0046     signal viewEnd(var lastDate)
0047 
0048     signal dayPressed(date dayOfPress)
0049     signal dayLongPressed(date dayOfLongPress)
0050     signal dayReleased(date dayOfRelease)
0051 
0052     onNextMonth: {
0053         mm.goNextMonth();
0054         root.selectedDate = new Date(mm.year, mm.month-1, 1, root.selectedDate.getHours(), root.selectedDate.getMinutes());
0055     }
0056 
0057     onPreviousMonth: {
0058         mm.goPreviousMonth();
0059         root.selectedDate = new Date(mm.year, mm.month-1, 1, root.selectedDate.getHours(), root.selectedDate.getMinutes());
0060     }
0061 
0062     onGoToday: {
0063         mm.goCurrentMonth();
0064         root.selectedDate = Calindori.CalendarController.localSystemDateTime();
0065     }
0066 
0067     onCurrentItemChanged: manageIndex()
0068 
0069     function manageIndex ()
0070     {
0071         if(!manualIndexing)
0072         {
0073             return;
0074         }
0075 
0076         var returnDate = root.selectedDate;
0077 
0078         if (currentIndex > previousIndex)
0079         {
0080             returnDate = (returnDate.getMonth() == 11) ? new Date(returnDate.getFullYear() + 1, 0, 1) : new Date(returnDate.getFullYear(), returnDate.getMonth() + 1, 1);
0081         }
0082         else
0083         {
0084             returnDate = (returnDate.getMonth() == 0) ? new Date(returnDate.getFullYear() - 1, 11, 1) : new Date(returnDate.getFullYear(), returnDate.getMonth() - 1, 1);
0085         }
0086 
0087         previousIndex = currentIndex;
0088 
0089         if(currentIndex != 1)
0090         {
0091             viewEnd(returnDate) //Inform parents about the date to set as selected when re-pushing this page
0092         }
0093     }
0094 
0095     Connections {
0096         target: cal
0097 
0098         function onTodosChanged () { monthView.reloadSelectedDate(); }
0099         function onEventsChanged () { monthView.reloadSelectedDate(); }
0100     }
0101 
0102     Component.onCompleted: {
0103         currentIndex = 1;
0104         previousIndex = currentIndex;
0105         manualIndexing = true;
0106         orientation = Qt.Horizontal //Change orientation after the object has been instantiated. Otherwise, we get a non-intuitive animation when swiping upwards
0107     }
0108 
0109     orientation: Qt.Vertical
0110 
0111     Calindori.DaysOfMonthIncidenceModel {
0112         id: mm
0113 
0114         year: monthView.selectedDate.getFullYear()
0115         month: monthView.selectedDate.getMonth() + 1
0116         calendar: cal
0117     }
0118 
0119     Item {}
0120 
0121     Item {
0122         MonthView {
0123             id: monthView
0124 
0125             anchors.centerIn: parent
0126 
0127             applicationLocale: _appLocale
0128             displayedYear: mm.year
0129             displayedMonthName: _appLocale.standaloneMonthName(mm.month-1)
0130             selectedDayTodosCount: cal.todosCount(selectedDate)
0131             selectedDayEventsCount: cal.eventsCount(selectedDate)
0132             daysModel: mm
0133             selectedDate: Calindori.CalendarController.localSystemDateTime()
0134             currentDate: Calindori.CalendarController.localSystemDateTime()
0135             loadAsync: true
0136 
0137             reloadSelectedDate: function() {
0138                 selectedDayTodosCount = cal.todosCount(root.selectedDate)
0139                 selectedDayEventsCount = cal.eventsCount(root.selectedDate)
0140             }
0141 
0142             onDatePressed: root.dayPressed(dateOfPress)
0143             onDateLongPressed: root.dayLongPressed(dateOfLongPress)
0144             onDateReleased: root.dayReleased(dateOfRelease)
0145         }
0146     }
0147 
0148     Item {}
0149 }