File indexing completed on 2024-11-17 04:42:37

0001 /*
0002   SPDX-FileCopyrightText: 2000, 2001, 2003 Cornelius Schumacher <schumacher@kde.org>
0003   SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
0004   SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0005   SPDX-FileContributor: Kevin Krammer <krake@kdab.com>
0006   SPDX-FileContributor: Sergio Martins <sergio@kdab.com>
0007 
0008   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0009 */
0010 #pragma once
0011 
0012 #include "eventview.h"
0013 #include "eventviews_export.h"
0014 #include "viewcalendar.h"
0015 
0016 #include <KCalendarCore/Todo>
0017 
0018 #include <memory>
0019 
0020 class KConfig;
0021 
0022 class QSplitter;
0023 
0024 namespace EventViews
0025 {
0026 namespace CalendarDecoration
0027 {
0028 class Decoration;
0029 }
0030 
0031 class TimeLabels;
0032 class TimeLabelsZone;
0033 
0034 class Agenda;
0035 class AgendaItem;
0036 class AgendaView;
0037 
0038 class EventIndicatorPrivate;
0039 
0040 class EventIndicator : public QWidget
0041 {
0042     Q_OBJECT
0043 public:
0044     enum Location { Top, Bottom };
0045     explicit EventIndicator(Location loc = Top, QWidget *parent = nullptr);
0046     ~EventIndicator() override;
0047 
0048     void changeColumns(int columns);
0049 
0050     void enableColumn(int column, bool enable);
0051 
0052 protected:
0053     void paintEvent(QPaintEvent *event) override;
0054     bool eventFilter(QObject *, QEvent *) override;
0055 
0056 private:
0057     std::unique_ptr<EventIndicatorPrivate> const d;
0058 };
0059 
0060 class AgendaViewPrivate;
0061 
0062 /**
0063   AgendaView is the agenda-like view that displays events in a single
0064   or multi-day view.
0065 */
0066 class EVENTVIEWS_EXPORT AgendaView : public EventView
0067 {
0068     Q_OBJECT
0069 public:
0070     explicit AgendaView(const PrefsPtr &preferences, QDate start, QDate end, bool isInteractive, bool isSideBySide = false, QWidget *parent = nullptr);
0071 
0072     explicit AgendaView(QDate start, QDate end, bool isInteractive, bool isSideBySide = false, QWidget *parent = nullptr);
0073 
0074     ~AgendaView() override;
0075 
0076     enum {
0077         MAX_DAY_COUNT = 42 // (6 * 7)
0078     };
0079 
0080     void addCalendar(const Akonadi::CollectionCalendar::Ptr &calendar) override;
0081     void removeCalendar(const Akonadi::CollectionCalendar::Ptr &calendar) override;
0082 
0083     /** Returns number of currently shown dates. */
0084     [[nodiscard]] int currentDateCount() const override;
0085 
0086     /** returns the currently selected events */
0087     [[nodiscard]] Akonadi::Item::List selectedIncidences() const override;
0088 
0089     /** returns the currently selected incidence's dates */
0090     [[nodiscard]] KCalendarCore::DateList selectedIncidenceDates() const override;
0091 
0092     /** return the default start/end date/time for new events   */
0093     bool eventDurationHint(QDateTime &startDt, QDateTime &endDt, bool &allDay) const override;
0094 
0095     /** start-datetime of selection */
0096     [[nodiscard]] QDateTime selectionStart() const override;
0097 
0098     /** end-datetime of selection */
0099     [[nodiscard]] QDateTime selectionEnd() const override;
0100 
0101     /** returns true if selection is for whole day */
0102     [[nodiscard]] bool selectedIsAllDay() const;
0103 
0104     /** make selected start/end invalid */
0105     void deleteSelectedDateTime();
0106 
0107     /** returns if only a single cell is selected, or a range of cells */
0108     [[nodiscard]] bool selectedIsSingleCell() const;
0109 
0110     /* reimp from EventView */
0111     virtual void addCalendar(const ViewCalendar::Ptr &cal);
0112 
0113     QSplitter *splitter() const;
0114 
0115     // FIXME: we already have startDateTime() and endDateTime() in the base class
0116 
0117     /** First shown day */
0118     [[nodiscard]] QDate startDate() const;
0119     /** Last shown day */
0120     [[nodiscard]] QDate endDate() const;
0121 
0122     /** Update event belonging to agenda item
0123         If the incidence is multi-day, item is the first one
0124     */
0125     void updateEventDates(AgendaItem *item, bool addIncidence, Akonadi::Collection::Id collectionId);
0126 
0127     [[nodiscard]] QList<bool> busyDayMask() const;
0128 
0129     /**
0130      * Return calendar object for a concrete incidence.
0131      * this function is able to use multiple calendars
0132      * TODO: replace EventsView::calendar()
0133      */
0134     virtual KCalendarCore::Calendar::Ptr calendar2(const KCalendarCore::Incidence::Ptr &incidence) const;
0135     virtual KCalendarCore::Calendar::Ptr calendar2(const QString &incidenceIdentifier) const;
0136 
0137     void showDates(const QDate &start, const QDate &end, const QDate &preferredMonth = QDate()) override;
0138 
0139     void showIncidences(const Akonadi::Item::List &incidenceList, const QDate &date) override;
0140 
0141     void clearSelection() override;
0142 
0143     void startDrag(const Akonadi::Item &);
0144 
0145     void readSettings();
0146     void readSettings(const KConfig *);
0147     void writeSettings(KConfig *);
0148 
0149     void enableAgendaUpdate(bool enable);
0150     void setIncidenceChanger(Akonadi::IncidenceChanger *changer) override;
0151 
0152     void zoomInHorizontally(QDate date = QDate());
0153     void zoomOutHorizontally(QDate date = QDate());
0154 
0155     void zoomInVertically();
0156     void zoomOutVertically();
0157 
0158     void zoomView(const int delta, QPoint pos, const Qt::Orientation orient = Qt::Horizontal);
0159 
0160     void clearTimeSpanSelection();
0161 
0162     // Used by the timelabelszone
0163     void updateTimeBarWidth();
0164     /** Create labels for the selected dates. */
0165     void createDayLabels(bool force);
0166 
0167     void createTimeBarHeaders();
0168 
0169     void setChanges(EventView::Changes) override;
0170 
0171     void setTitle(const QString &title);
0172 
0173 Q_SIGNALS:
0174     void showNewEventPopupSignal();
0175     void showIncidencePopupSignal(const Akonadi::CollectionCalendar::Ptr &, const Akonadi::Item &, const QDate &);
0176     void zoomViewHorizontally(const QDate &, int count);
0177 
0178     void timeSpanSelectionChanged();
0179 
0180 protected:
0181     /** Fill agenda using the current set value for the start date */
0182     void fillAgenda();
0183 
0184     void connectAgenda(Agenda *agenda, Agenda *otherAgenda);
0185 
0186     /**
0187       Set the masks on the agenda widgets indicating, which days are holidays.
0188     */
0189     void setHolidayMasks();
0190 
0191     void removeIncidence(const KCalendarCore::Incidence::Ptr &inc);
0192 
0193 public Q_SLOTS:
0194     void updateView() override;
0195     void updateConfig() override;
0196     /** reschedule the todo  to the given x- and y- coordinates.
0197         Third parameter determines all-day (no time specified) */
0198     void slotIncidencesDropped(const KCalendarCore::Incidence::List &incidences, const QPoint &, bool);
0199     void slotIncidencesDropped(const QList<QUrl> &incidences, const QPoint &, bool);
0200     void startDrag(const KCalendarCore::Incidence::Ptr &);
0201 
0202 protected Q_SLOTS:
0203     void updateEventIndicatorTop(int newY);
0204     void updateEventIndicatorBottom(int newY);
0205 
0206     /** Updates data for selected timespan */
0207     void newTimeSpanSelected(const QPoint &start, const QPoint &end);
0208     /** Updates data for selected timespan for all day event*/
0209     void newTimeSpanSelectedAllDay(const QPoint &start, const QPoint &end);
0210     /**
0211       Updates the event indicators after a certain incidence was modified or
0212       removed.
0213     */
0214     void updateEventIndicators();
0215     void scheduleUpdateEventIndicators();
0216 
0217     void alignAgendas();
0218 
0219 protected:
0220     void showEvent(QShowEvent *showEvent) override;
0221     bool eventFilter(QObject *object, QEvent *event) override;
0222 
0223 private Q_SLOTS:
0224     void slotIncidenceSelected(const KCalendarCore::Incidence::Ptr &incidence, QDate date);
0225     void slotShowIncidencePopup(const KCalendarCore::Incidence::Ptr &incidence, QDate date);
0226     void slotEditIncidence(const KCalendarCore::Incidence::Ptr &incidence);
0227     void slotShowIncidence(const KCalendarCore::Incidence::Ptr &incidence);
0228     void slotDeleteIncidence(const KCalendarCore::Incidence::Ptr &incidence);
0229 
0230 private:
0231     void init(QDate start, QDate end);
0232     bool filterByCollectionSelection(const KCalendarCore::Incidence::Ptr &incidence);
0233     void setupTimeLabel(TimeLabels *timeLabel);
0234     bool displayIncidence(const KCalendarCore::Incidence::Ptr &incidence, bool createSelected);
0235 
0236     friend class TimeLabelsZone;
0237     friend class MultiAgendaViewPrivate;
0238     friend class MultiAgendaView;
0239     Agenda *agenda() const;
0240     Agenda *allDayAgenda() const;
0241 
0242 private:
0243     friend class AgendaViewPrivate;
0244     std::unique_ptr<AgendaViewPrivate> const d;
0245 };
0246 }