Warning, /maui/mauikit-calendar/src/controls.6/YearView.qml is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2018 Michael Bohlender, <bohlender@kolabsys.com>
0002 // Copyright (C) 2018 Christian Mollekopf, <mollekopf@kolabsys.com>
0003 // SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
0004 // SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006 import QtQuick
0007 import QtQuick.Layouts 
0008 import QtQuick.Controls 
0009 
0010 import org.mauikit.controls 1.3 as Maui
0011 import org.mauikit.calendar 1.0 as Kalendar
0012 
0013 import "dateutils.js" as DateUtils
0014 
0015 /**
0016  * @inherit QtQuick.Controls.Pane
0017  * @brief A browsing view of the calendar organized by years.
0018  * 
0019  * @image html yearview.png
0020  * 
0021  * @code 
0022  * Maui.ApplicationWindow
0023  * {
0024  *    id: root
0025  *    title: _view.title
0026  * 
0027  *    Maui.Page
0028  *    {
0029  *        anchors.fill: parent
0030  *        Maui.Controls.showCSD: true
0031  *        title: root.title
0032  * 
0033  *        MC.YearView
0034  *        {
0035  *            id: _view
0036  *            anchors.fill: parent
0037  * 
0038  *            onSelectedDateChanged: root.title = selectedDate.toString()
0039  * 
0040  *            onMonthClicked: (month) => console.log("Month Clicked, ", month)
0041  *        }
0042  *    }
0043  * }
0044  * @endcode
0045  */
0046 Pane
0047 {
0048     id: control
0049     
0050     /**
0051      * @brief
0052      */
0053     property date selectedDate: currentDate
0054     
0055     /**
0056      * @brief
0057      */
0058     readonly property date currentDate: new Date()
0059         
0060     /**
0061      * @brief
0062      */
0063     property date startDate
0064     
0065     /**
0066      * @brief
0067      */
0068     property date firstDayOfMonth
0069     
0070     /**
0071      * @brief
0072      */
0073     property int year : currentDate.getUTCFullYear()
0074     
0075     /**
0076      * @brief
0077      */
0078     property bool initialMonth: true
0079     
0080     /**
0081      * @brief
0082      */
0083     readonly property bool isLarge: width > Maui.Style.units.gridUnit * 40
0084     
0085     /**
0086      * @brief
0087      */
0088     readonly property bool isTiny: width <= Maui.Style.units.gridUnit * 40
0089     
0090     /**
0091      * @brief
0092      */
0093     readonly property alias gridView : _gridView
0094     
0095     /**
0096      * @brief
0097      */
0098     readonly property string title: control.year
0099     
0100     /**
0101      * @brief
0102      * @param date
0103      */
0104     signal monthClicked(var date)
0105     
0106     contentItem: Maui.GridBrowser
0107     {
0108         id: _gridView
0109         
0110         itemHeight: Math.max(itemSize, 160)
0111         itemSize: Math.min(width/3, 400)
0112         
0113         currentIndex: currentDate.getUTCMonth()
0114         model: 12
0115         
0116         delegate: Loader
0117         {
0118             id: viewLoader
0119             
0120             property bool isNextOrCurrentItem: index >= _gridView.currentIndex -1 && index <= _gridView.currentIndex + 1
0121             property bool isCurrentItem: GridView.isCurrentItem
0122             
0123             active: true
0124             asynchronous: !isCurrentItem
0125             visible: status === Loader.Ready
0126             
0127             width: GridView.view.cellWidth - (control.isTiny ? 0 : Maui.Style.space.small)
0128             height: GridView.view.cellHeight - (control.isTiny ? 0 : Maui.Style.space.small)
0129             
0130             sourceComponent: Kalendar.DaysGrid
0131             {
0132                 //                 Maui.Theme.colorSet: Maui.Theme.Button
0133                 //                 Maui.Theme.inherit: false
0134                 //                 
0135                 id: _monthDelegate
0136                 year: control.year
0137                 month: modelData+1
0138                 compact: control.isTiny
0139                 onDateClicked: control.selectedDate = date
0140                 header: Maui.LabelDelegate
0141                 {
0142                     width: parent.width
0143                     isSection: true
0144                     color: Maui.Theme.textColor
0145                     text: _monthDelegate.title
0146                 }
0147                 
0148                 background: Rectangle
0149                 {
0150                     color:  _monthDelegate.month === control.currentDate.getUTCMonth()+1 ? Maui.Theme.alternateBackgroundColor : (_monthDelegate.hovered ? Maui.Theme.hoverColor : Maui.Theme.backgroundColor) 
0151                     radius: Maui.Style.radiusV
0152                     
0153                     MouseArea
0154                     {
0155                         id: _mouseArea
0156                         hoverEnabled: true
0157                         anchors.fill: parent
0158                         onClicked: control.monthClicked(new Date(_monthDelegate.year, _monthDelegate.month))
0159                     }
0160                 }
0161             }
0162         }
0163         
0164         Component.onCompleted: _gridView.flickable.positionViewAtIndex(_gridView.currentIndex, GridView.Visible)
0165     }
0166     
0167     function resetDate()
0168     {
0169         control.year = control.currentDate.getUTCFullYear()
0170     }
0171     
0172     function nextDate()
0173     {
0174         control.year++
0175     }
0176     
0177     function previousDate()
0178     {
0179         control.year--
0180     }
0181 }
0182