1 /*
2   This file is part of KOrganizer.
3 
4   SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org>
5   SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 
7   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
8 */
9 
10 #pragma once
11 
12 #include <EventViews/EventView>
13 
14 #include <KCalendarCore/IncidenceBase> //for KCalendarCore::DateList typedef
15 
16 #include <QDate>
17 #include <QObject>
18 
19 class CalendarView;
20 class KOAgendaView;
21 class KOJournalView;
22 class KOListView;
23 class KOTimelineView;
24 class KOTodoView;
25 class KOWhatsNextView;
26 namespace KOrg
27 {
28 class BaseView;
29 class MultiAgendaView;
30 class MonthView;
31 }
32 
33 namespace Akonadi
34 {
35 class Item;
36 }
37 
38 class KConfig;
39 class QTabWidget;
40 
41 /**
42   This class manages the views of the calendar. It owns the objects and handles
43   creation and selection.
44 */
45 class KOViewManager : public QObject
46 {
47     Q_OBJECT
48 public:
49     enum RangeMode {
50         NO_RANGE,
51         DAY_RANGE,
52         WORK_WEEK_RANGE,
53         WEEK_RANGE,
54         NEXTX_RANGE,
55         OTHER_RANGE // for example, showing 8 days
56     };
57 
58     explicit KOViewManager(CalendarView *);
59     ~KOViewManager() override;
60 
61     /** changes the view to be the currently selected view */
62     void showView(KOrg::BaseView *);
63 
64     void readSettings(KConfig *config);
65     void writeSettings(KConfig *config);
66 
67     KOrg::BaseView *currentView();
68 
69     void setDocumentId(const QString &);
70 
71     void updateView();
72     void updateView(QDate start, QDate end, QDate preferredMonth);
73 
74     void goMenu(bool enable);
75     void raiseCurrentView();
76 
77     void connectView(KOrg::BaseView *);
78     void addView(KOrg::BaseView *, bool isTab = false);
79 
80     Q_REQUIRED_RESULT Akonadi::Item currentSelection();
81 
82     /**
83      * If there's a selected incidence, it's date is returned, otherwise
84      * an invalid QDate is returned.
85      */
86     Q_REQUIRED_RESULT QDate currentSelectionDate();
87 
agendaView()88     KOAgendaView *agendaView() const
89     {
90         return mAgendaView;
91     }
92 
multiAgendaView()93     KOrg::MultiAgendaView *multiAgendaView() const
94     {
95         return mAgendaSideBySideView;
96     }
97 
todoView()98     KOTodoView *todoView() const
99     {
100         return mTodoView;
101     }
102 
monthView()103     KOrg::MonthView *monthView() const
104     {
105         return mMonthView;
106     }
107 
108     void updateMultiCalendarDisplay();
109 
110     /**
111      * Returns true if agenda is the current view.
112      *
113      * Never use the pointer returned by agendaView()
114      * to know if agenda is selected, because agenda has other modes
115      * (tabbed, side by side). Use this function instead.
116      */
117     Q_REQUIRED_RESULT bool agendaIsSelected() const;
118 
119     /**
120       Return the current range mode:
121       week, work week, day or nextX days, etc.
122     */
rangeMode()123     Q_REQUIRED_RESULT RangeMode rangeMode() const
124     {
125         return mRangeMode;
126     }
127 
128 Q_SIGNALS:
129     void configChanged();
130     void datesSelected(const KCalendarCore::DateList &);
131 
132 public Q_SLOTS:
133     void showWhatsNextView();
134     void showListView();
135     void showAgendaView();
136     void showTodoView();
137     void showTimeLineView();
138     void showMonthView();
139     void showJournalView();
140     void showEventView();
141 
142     void selectDay();
143     void selectWorkWeek();
144     void selectWeek();
145     void selectNextX();
146 
147     void connectTodoView(KOTodoView *todoView);
148 
149     void zoomInHorizontally();
150     void zoomOutHorizontally();
151     void zoomInVertically();
152     void zoomOutVertically();
153 
154     /**
155        Notifies all views that an update is needed. This means that the
156        next time CalendarView::updateView() is called, views won't try to be smart
157        and ignore the update for performance reasons.
158     */
159     void addChange(EventViews::EventView::Change change);
160 
161 private Q_SLOTS:
162     void currentAgendaViewTabChanged(int index);
163 
164 private:
165     QWidget *widgetForView(KOrg::BaseView *) const;
166     QList<KOrg::BaseView *> mViews;
167     CalendarView *const mMainView;
168 
169     KOAgendaView *mAgendaView = nullptr;
170     KOrg::MultiAgendaView *mAgendaSideBySideView = nullptr;
171     KOListView *mListView = nullptr;
172     KOTodoView *mTodoView = nullptr;
173     KOWhatsNextView *mWhatsNextView = nullptr;
174     KOJournalView *mJournalView = nullptr;
175     KOTimelineView *mTimelineView = nullptr;
176     KOrg::MonthView *mMonthView = nullptr;
177     KOrg::BaseView *mCurrentView = nullptr;
178 
179     KOrg::BaseView *mLastEventView = nullptr;
180     QTabWidget *mAgendaViewTabs = nullptr;
181     int mAgendaViewTabIndex = 0;
182 
183     RangeMode mRangeMode = NO_RANGE;
184 };
185 
186