File indexing completed on 2024-06-09 05:15:58

0001 /*
0002   This file is part of KOrganizer.
0003 
0004   SPDX-FileCopyrightText: 2001, 2003 Cornelius Schumacher <schumacher@kde.org>
0005   SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
0006 
0007   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0008 */
0009 
0010 #pragma once
0011 
0012 #include <Akonadi/CollectionCalendar>
0013 #include <KCalendarCore/IncidenceBase> //for DateList typedef
0014 #include <QDate>
0015 #include <QFrame>
0016 
0017 class KODayMatrix;
0018 class NavigatorBar;
0019 
0020 namespace Akonadi
0021 {
0022 class Item;
0023 }
0024 
0025 class QLabel;
0026 
0027 class KDateNavigator : public QFrame
0028 {
0029     Q_OBJECT
0030 public:
0031     explicit KDateNavigator(QWidget *parent = nullptr);
0032     ~KDateNavigator() override;
0033 
0034     void addCalendar(const Akonadi::CollectionCalendar::Ptr &calendar);
0035     void removeCalendar(const Akonadi::CollectionCalendar::Ptr &calendar);
0036 
0037     void setBaseDate(const QDate &);
0038 
0039     [[nodiscard]] KCalendarCore::DateList selectedDates() const
0040     {
0041         return mSelectedDates;
0042     }
0043 
0044     [[nodiscard]] QSizePolicy sizePolicy() const;
0045 
0046     NavigatorBar *navigatorBar() const
0047     {
0048         return mNavigatorBar;
0049     }
0050 
0051     [[nodiscard]] QDate startDate() const;
0052     [[nodiscard]] QDate endDate() const;
0053     void setHighlightMode(bool highlightEvents, bool highlightTodos, bool highlightJournals) const;
0054 
0055     /**
0056        Returns the current displayed month.
0057        It's a QDate instead of uint so it can be easily feed to KCalendarSystem's
0058        functions.
0059     */
0060     [[nodiscard]] QDate month() const;
0061 
0062 public Q_SLOTS:
0063     void selectDates(const KCalendarCore::DateList &);
0064     void selectPreviousMonth();
0065     void selectNextMonth();
0066     void updateView();
0067     void updateConfig();
0068     void updateDayMatrix();
0069     void updateToday();
0070     void setUpdateNeeded();
0071 
0072 Q_SIGNALS:
0073     void datesSelected(const KCalendarCore::DateList &);
0074     void incidenceDropped(const Akonadi::Item &, const QDate &);
0075     void incidenceDroppedMove(const Akonadi::Item &, const QDate &);
0076     void newEventSignal(const QDate &, const QDate &);
0077     void newTodoSignal(const QDate &);
0078     void newJournalSignal(const QDate &);
0079     void weekClicked(const QDate &week, const QDate &month);
0080 
0081     void goPrevious();
0082     void goNext();
0083     void nextMonthClicked();
0084     void prevMonthClicked();
0085     void nextYearClicked();
0086     void prevYearClicked();
0087 
0088     void monthSelected(int month);
0089     void yearSelected(int year);
0090 
0091 protected:
0092     void updateDates();
0093 
0094     void wheelEvent(QWheelEvent *) override;
0095 
0096     bool eventFilter(QObject *, QEvent *) override;
0097 
0098     void setShowWeekNums(bool enabled);
0099 
0100 private:
0101     void selectMonthHelper(int monthDifference);
0102     NavigatorBar *const mNavigatorBar;
0103 
0104     QLabel *mHeadings[7];
0105     QLabel *mWeeknos[7];
0106 
0107     KODayMatrix *mDayMatrix = nullptr;
0108 
0109     KCalendarCore::DateList mSelectedDates;
0110     QDate mBaseDate;
0111 
0112     // Disabling copy constructor and assignment operator
0113     KDateNavigator(const KDateNavigator &);
0114     KDateNavigator &operator=(const KDateNavigator &);
0115 };