koviewmanager.h 4.57 KB
Newer Older
1 2 3
/*
  This file is part of KOrganizer.

4 5
  SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org>
  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 11

#ifndef KORG_KOVIEWMANAGER_H
#define KORG_KOVIEWMANAGER_H
12

Laurent Montel's avatar
Laurent Montel committed
13
#include <EventViews/EventView>
14

15
#include <KCalendarCore/IncidenceBase> //for KCalendarCore::DateList typedef
16

17 18
#include <QDate>
#include <QObject>
19 20 21 22

class CalendarView;
class KOAgendaView;
class KOJournalView;
23
class KOListView;
24
class KOTimelineView;
25 26
class KOTodoView;
class KOWhatsNextView;
Laurent Montel's avatar
Laurent Montel committed
27
namespace KOrg {
Laurent Montel's avatar
Laurent Montel committed
28 29 30
class BaseView;
class MultiAgendaView;
class MonthView;
31 32
}

Laurent Montel's avatar
Laurent Montel committed
33
namespace Akonadi {
Laurent Montel's avatar
Laurent Montel committed
34
class Item;
André Wöbbeking's avatar
André Wöbbeking committed
35
}
36

37
class KConfig;
Laurent Montel's avatar
Laurent Montel committed
38
class QTabWidget;
39

40 41 42 43 44 45
/**
  This class manages the views of the calendar. It owns the objects and handles
  creation and selection.
*/
class KOViewManager : public QObject
{
Laurent Montel's avatar
Laurent Montel committed
46 47
    Q_OBJECT
public:
48 49

    enum RangeMode {
Laurent Montel's avatar
Laurent Montel committed
50 51 52 53 54 55
        NO_RANGE,
        DAY_RANGE,
        WORK_WEEK_RANGE,
        WEEK_RANGE,
        NEXTX_RANGE,
        OTHER_RANGE // for example, showing 8 days
56 57
    };

Laurent Montel's avatar
Laurent Montel committed
58
    explicit KOViewManager(CalendarView *);
Laurent Montel's avatar
Laurent Montel committed
59
    ~KOViewManager() override;
60 61

    /** changes the view to be the currently selected view */
Laurent Montel's avatar
Laurent Montel committed
62
    void showView(KOrg::BaseView *);
63

Laurent Montel's avatar
Laurent Montel committed
64 65
    void readSettings(KConfig *config);
    void writeSettings(KConfig *config);
66 67

    /** Read which view was shown last from config file */
Laurent Montel's avatar
Laurent Montel committed
68
    void readCurrentView(KConfig *config);
69
    /** Write which view is currently shown to config file */
Laurent Montel's avatar
Laurent Montel committed
70
    void writeCurrentView(KConfig *config);
71 72 73

    KOrg::BaseView *currentView();

Laurent Montel's avatar
Laurent Montel committed
74
    void setDocumentId(const QString &);
75 76

    void updateView();
Laurent Montel's avatar
Laurent Montel committed
77
    void updateView(QDate start, QDate end, QDate preferredMonth);
78

Laurent Montel's avatar
Laurent Montel committed
79
    void goMenu(bool enable);
80 81
    void raiseCurrentView();

Laurent Montel's avatar
Laurent Montel committed
82 83
    void connectView(KOrg::BaseView *);
    void addView(KOrg::BaseView *, bool isTab = false);
84

Laurent Montel's avatar
Laurent Montel committed
85
    Q_REQUIRED_RESULT Akonadi::Item currentSelection();
86 87 88 89 90

    /**
     * If there's a selected incidence, it's date is returned, otherwise
     * an invalid QDate is returned.
     */
Laurent Montel's avatar
Laurent Montel committed
91
    Q_REQUIRED_RESULT QDate currentSelectionDate();
92

Laurent Montel's avatar
Laurent Montel committed
93 94 95 96
    KOAgendaView *agendaView() const
    {
        return mAgendaView;
    }
Laurent Montel's avatar
Laurent Montel committed
97

Laurent Montel's avatar
Laurent Montel committed
98 99 100 101
    KOrg::MultiAgendaView *multiAgendaView() const
    {
        return mAgendaSideBySideView;
    }
Laurent Montel's avatar
Laurent Montel committed
102

Laurent Montel's avatar
Laurent Montel committed
103 104 105 106
    KOTodoView *todoView() const
    {
        return mTodoView;
    }
Laurent Montel's avatar
Laurent Montel committed
107

Laurent Montel's avatar
Laurent Montel committed
108 109 110 111
    KOrg::MonthView *monthView() const
    {
        return mMonthView;
    }
112 113 114 115 116 117 118 119 120 121

    void updateMultiCalendarDisplay();

    /**
     * Returns true if agenda is the current view.
     *
     * Never use the pointer returned by agendaView()
     * to know if agenda is selected, because agenda has other modes
     * (tabbed, side by side). Use this function instead.
     */
Laurent Montel's avatar
Laurent Montel committed
122
    Q_REQUIRED_RESULT bool agendaIsSelected() const;
123 124 125 126 127

    /**
      Return the current range mode:
      week, work week, day or nextX days, etc.
    */
Laurent Montel's avatar
Laurent Montel committed
128
    Q_REQUIRED_RESULT RangeMode rangeMode() const
Laurent Montel's avatar
Laurent Montel committed
129 130 131
    {
        return mRangeMode;
    }
132

Laurent Montel's avatar
Laurent Montel committed
133
Q_SIGNALS:
134
    void configChanged();
135
    void datesSelected(const KCalendarCore::DateList &);
136

Laurent Montel's avatar
Laurent Montel committed
137
public Q_SLOTS:
138 139 140 141 142 143 144 145 146 147 148 149 150 151
    void showWhatsNextView();
    void showListView();
    void showAgendaView();
    void showTodoView();
    void showTimeLineView();
    void showMonthView();
    void showJournalView();
    void showEventView();

    void selectDay();
    void selectWorkWeek();
    void selectWeek();
    void selectNextX();

Laurent Montel's avatar
Laurent Montel committed
152
    void connectTodoView(KOTodoView *todoView);
153 154 155 156 157 158 159 160 161 162 163

    void zoomInHorizontally();
    void zoomOutHorizontally();
    void zoomInVertically();
    void zoomOutVertically();

    /**
       Notifies all views that an update is needed. This means that the
       next time CalendarView::updateView() is called, views won't try to be smart
       and ignore the update for performance reasons.
    */
Laurent Montel's avatar
Laurent Montel committed
164
    void addChange(EventViews::EventView::Change change);
165

Laurent Montel's avatar
Laurent Montel committed
166
private Q_SLOTS:
Laurent Montel's avatar
Laurent Montel committed
167
    void currentAgendaViewTabChanged(int index);
168

Laurent Montel's avatar
Laurent Montel committed
169 170 171
private:
    QWidget *widgetForView(KOrg::BaseView *) const;
    QList<KOrg::BaseView *> mViews;
Laurent Montel's avatar
Laurent Montel committed
172 173 174 175 176 177 178 179 180 181 182 183 184 185
    CalendarView *mMainView = nullptr;

    KOAgendaView *mAgendaView = nullptr;
    KOrg::MultiAgendaView *mAgendaSideBySideView = nullptr;
    KOListView *mListView = nullptr;
    KOTodoView *mTodoView = nullptr;
    KOWhatsNextView *mWhatsNextView = nullptr;
    KOJournalView *mJournalView = nullptr;
    KOTimelineView *mTimelineView = nullptr;
    KOrg::MonthView *mMonthView = nullptr;
    KOrg::BaseView *mCurrentView = nullptr;

    KOrg::BaseView *mLastEventView = nullptr;
    QTabWidget *mAgendaViewTabs = nullptr;
186
    int mAgendaViewTabIndex = 0;
187

188
    RangeMode mRangeMode = NO_RANGE;
189 190 191
};

#endif