File indexing completed on 2024-05-12 05:21:22

0001 /*
0002   This file is part of KOrganizer.
0003 
0004   SPDX-FileCopyrightText: 2004 Cornelius Schumacher <schumacher@kde.org>
0005   SPDX-FileCopyrightText: 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
0006 
0007   SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0008   SPDX-FileContributor: Sergio Martins <sergio@kdab.com>
0009 
0010   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0011 */
0012 
0013 #pragma once
0014 
0015 #include <Akonadi/CollectionCalendar>
0016 
0017 #include <QDate>
0018 #include <QFrame>
0019 #include <QList>
0020 
0021 class KDateNavigator;
0022 
0023 class DateNavigatorContainer : public QFrame
0024 {
0025     Q_OBJECT
0026 public:
0027     explicit DateNavigatorContainer(QWidget *parent = nullptr);
0028     ~DateNavigatorContainer() override;
0029 
0030     /**
0031       Associate date navigator with a calendar. It is used by KODayMatrix.
0032     */
0033     void addCalendar(const Akonadi::CollectionCalendar::Ptr &calendar);
0034     void removeCalendar(const Akonadi::CollectionCalendar::Ptr &calendar);
0035 
0036     QSize minimumSizeHint() const override;
0037     QSize sizeHint() const override;
0038     void setHighlightMode(bool highlightEvents, bool highlightTodos, bool highlightJournals) const;
0039     void setUpdateNeeded();
0040 
0041     /**
0042        Returns the month of the specified KDateNavigator.
0043        The first navigatorIndex is 0.
0044        Returns a QDate instead of uint so it can be easily feed to KCalendarSystem's
0045        functions.
0046        An invalid QDate() is returned if the index is too big or too small.
0047     */
0048     [[nodiscard]] QDate monthOfNavigator(int navigatorIndex = 0) const;
0049 public Q_SLOTS:
0050 
0051     /**
0052        preferredMonth is useful when the datelist crosses months, if different
0053        from -1, it has the month that the kdatenavigator should show in case
0054        of ambiguity
0055     */
0056     void selectDates(const KCalendarCore::DateList &, const QDate &preferredMonth = QDate());
0057 
0058     void updateView();
0059     void updateConfig();
0060     void updateDayMatrix();
0061     void updateToday();
0062 
0063     void goPrevMonth();
0064     void goNextMonth();
0065 
0066 Q_SIGNALS:
0067     void datesSelected(const KCalendarCore::DateList &, const QDate &preferredMonth);
0068     void incidenceDropped(const Akonadi::Item &, const QDate &);
0069     void incidenceDroppedMove(const Akonadi::Item &, const QDate &);
0070     void newEventSignal(const QDate &, const QDate &);
0071     void newTodoSignal(const QDate &);
0072     void newJournalSignal(const QDate &);
0073 
0074     /**
0075      * @param preferredMonth Holds the month that should be selected when the
0076      * week crosses months. It's a QDate instead of uint so it can be easily
0077      * fed to KCalendarSystem's functions.
0078      */
0079     void weekClicked(const QDate &week, const QDate &preferredMonth);
0080 
0081     void goPrevious();
0082     void goNext();
0083 
0084     void nextYearClicked();
0085     void prevYearClicked();
0086 
0087     /** Signals that the previous month button has been clicked.
0088 
0089         @param currentMonth The month displayed on the first KDateNavigator.
0090                DateNavigator doesn't know anything abouts months, it just has
0091                a list of selected dates, so we must send this.
0092         @param selectionLowerLimit The first date of the first KDateNavigator.
0093         @param selectionUpperLimit The last date of the last KDateNavigator.
0094     */
0095     void prevMonthClicked(const QDate &currentMonth, const QDate &selectionLowerLimit, const QDate &selectionUpperLimit);
0096 
0097     void nextMonthClicked(const QDate &currentMonth, const QDate &selectionLowerLimit, const QDate &selectionUpperLimit);
0098 
0099     void monthSelected(int month);
0100 
0101     void yearSelected(int year);
0102 
0103 protected:
0104     void resizeEvent(QResizeEvent *) override;
0105     void setBaseDates(const QDate &start);
0106     void connectNavigatorView(KDateNavigator *v);
0107 
0108 protected Q_SLOTS:
0109     /**
0110      * Resizes all the child elements after the size of the widget changed.
0111      * This slot is called by a QTimer::singleShot from resizeEvent.
0112      * This makes the UI seem more responsive, since the other parts
0113      * of the splitter are resized earlier now.
0114      */
0115     void resizeAllContents();
0116 
0117 private Q_SLOTS:
0118     void handleDatesSelectedSignal(const KCalendarCore::DateList &);
0119     void handleWeekClickedSignal(const QDate &, const QDate &);
0120 
0121 private:
0122     /* Returns the first day of the first KDateNavigator, and the last day
0123        of the last KDateNavigator.
0124 
0125        @param monthOffset If you have two KDateNavigators displaying
0126        January and February and want to know the boundaries of,
0127        for e.g. displaying February and March, use monthOffset = 1.
0128     */
0129     QPair<QDate, QDate> dateLimits(int monthOffset = 0) const;
0130 
0131     /**
0132      * Returns the first KDateNavigator that displays date, or 0 if
0133      * no KDateNavigator displays it.
0134      */
0135     KDateNavigator *firstNavigatorForDate(const QDate &date) const;
0136 
0137     KDateNavigator *const mNavigatorView;
0138 
0139     QList<Akonadi::CollectionCalendar::Ptr> mCalendars;
0140 
0141     QList<KDateNavigator *> mExtraViews;
0142 
0143     int mHorizontalCount = 1;
0144     int mVerticalCount = 1;
0145 
0146     bool mIgnoreNavigatorUpdates = false;
0147 };