File indexing completed on 2024-06-16 04:51:14

0001 /*
0002   SPDX-FileCopyrightText: 2008 Bruno Virlet <bruno.virlet@gmail.com>
0003   SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0004   SPDX-FileContributor: Bertjan Broeksema <broeksema@kde.org>
0005 
0006   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0007 */
0008 
0009 #pragma once
0010 
0011 #include "eventview.h"
0012 
0013 #include <KHolidays/HolidayRegion>
0014 
0015 #include <memory>
0016 
0017 class QModelIndex;
0018 
0019 namespace EventViews
0020 {
0021 class MonthViewPrivate;
0022 
0023 /**
0024   New month view.
0025 */
0026 class EVENTVIEWS_EXPORT MonthView : public EventView
0027 {
0028     Q_OBJECT
0029 public:
0030     enum NavButtonsVisibility { Visible, Hidden };
0031 
0032     explicit MonthView(NavButtonsVisibility visibility = Visible, QWidget *parent = nullptr);
0033     ~MonthView() override;
0034 
0035     void addCalendar(const Akonadi::CollectionCalendar::Ptr &calendar) override;
0036     void removeCalendar(const Akonadi::CollectionCalendar::Ptr &calendar) override;
0037 
0038     [[nodiscard]] int currentDateCount() const override;
0039     [[nodiscard]] int currentMonth() const;
0040 
0041     [[nodiscard]] Akonadi::Item::List selectedIncidences() const override;
0042 
0043     /** Returns dates of the currently selected events */
0044     [[nodiscard]] KCalendarCore::DateList selectedIncidenceDates() const override;
0045 
0046     [[nodiscard]] QDateTime selectionStart() const override;
0047 
0048     [[nodiscard]] QDateTime selectionEnd() const override;
0049 
0050     void setDateRange(const QDateTime &start, const QDateTime &end, const QDate &preferredMonth = QDate()) override;
0051 
0052     [[nodiscard]] bool eventDurationHint(QDateTime &startDt, QDateTime &endDt, bool &allDay) const override;
0053 
0054     /**
0055      * Returns the average date in the view
0056      */
0057     [[nodiscard]] QDate averageDate() const;
0058 
0059     [[nodiscard]] bool usesFullWindow();
0060 
0061     [[nodiscard]] bool supportsDateRangeSelection() const
0062     {
0063         return false;
0064     }
0065 
0066     [[nodiscard]] bool isBusyDay(QDate day) const;
0067 
0068 Q_SIGNALS:
0069     void showIncidencePopupSignal(const Akonadi::CollectionCalendar::Ptr &calendar, const Akonadi::Item &item, const QDate &date);
0070     void showNewEventPopupSignal();
0071     void fullViewChanged(bool enabled);
0072 
0073 public Q_SLOTS:
0074     void updateConfig() override;
0075     void updateView() override;
0076     void showIncidences(const Akonadi::Item::List &incidenceList, const QDate &date) override;
0077 
0078     void changeIncidenceDisplay(const Akonadi::Item &, int);
0079     void changeFullView(); /// Display in full window mode
0080     void moveBackMonth(); /// Shift the view one month back
0081     void moveBackWeek(); /// Shift the view one week back
0082     void moveFwdWeek(); /// Shift the view one week forward
0083     void moveFwdMonth(); /// Shift the view one month forward
0084 
0085 protected Q_SLOTS:
0086     void calendarReset() override;
0087 
0088 private Q_SLOTS:
0089     // void dataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight );
0090     // void rowsInserted( const QModelIndex &parent, int start, int end );
0091     // void rowsAboutToBeRemoved( const QModelIndex &parent, int start, int end );
0092 
0093 protected:
0094 #ifndef QT_NO_WHEELEVENT
0095     void wheelEvent(QWheelEvent *event) override;
0096 #endif
0097     void keyPressEvent(QKeyEvent *event) override;
0098     void keyReleaseEvent(QKeyEvent *event) override;
0099 
0100     QPair<QDateTime, QDateTime> actualDateRange(const QDateTime &start, const QDateTime &end, const QDate &preferredMonth = QDate()) const override;
0101 
0102     KHolidays::Holiday::List holidays(QDate startDate, QDate endDate);
0103 
0104     // Compute and update the whole view
0105     void reloadIncidences();
0106 
0107 protected:
0108     /**
0109      * @deprecated
0110      */
0111     void showDates(const QDate &start, const QDate &end, const QDate &preferedMonth = QDate()) override;
0112 
0113 private:
0114     std::unique_ptr<MonthViewPrivate> const d;
0115     friend class MonthViewPrivate;
0116     friend class MonthScene;
0117 };
0118 }