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

0001 /*
0002   This file is part of KOrganizer.
0003 
0004   SPDX-FileCopyrightText: 2002 Cornelius Schumacher <schumacher@kde.org>
0005   SPDX-FileCopyrightText: 2003-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 <KCalendarCore/IncidenceBase> // for KCalendarCore::DateList typedef
0016 
0017 #include <QDate>
0018 #include <QObject>
0019 /**
0020   This class controls date navigation. All requests to move the views to another
0021   date are sent to the DateNavigator. The DateNavigator processes the new
0022   selection of dates and emits the required signals for the views.
0023 */
0024 class DateNavigator : public QObject
0025 {
0026     Q_OBJECT
0027 public:
0028     explicit DateNavigator(QObject *parent = nullptr);
0029     ~DateNavigator() override;
0030 
0031     [[nodiscard]] KCalendarCore::DateList selectedDates() const;
0032 
0033     [[nodiscard]] int datesCount() const;
0034 
0035 public Q_SLOTS:
0036     void selectDates(const KCalendarCore::DateList &, QDate preferredMonth = QDate());
0037     void selectDate(QDate);
0038 
0039     void selectDates(int count);
0040     void selectDates(const QDate &, int count, const QDate &preferredMonth = QDate());
0041 
0042     void selectWeek();
0043     void selectWeek(const QDate &, const QDate &preferredMonth = QDate());
0044 
0045     void selectWorkWeek();
0046     void selectWorkWeek(QDate);
0047 
0048     void selectWeekByDay(int weekDay, QDate, QDate preferredMonth = QDate());
0049 
0050     void selectToday();
0051 
0052     void selectPreviousYear();
0053     void selectPreviousMonth(const QDate &currentMonth = QDate(), const QDate &selectionLowerLimit = QDate(), const QDate &selectionUpperLimit = QDate());
0054     void selectPreviousWeek();
0055     void selectNextWeek();
0056     void selectNextMonth(const QDate &currentMonth = QDate(), const QDate &selectionLowerLimit = QDate(), const QDate &selectionUpperLimit = QDate());
0057     void selectNextYear();
0058 
0059     void selectPrevious();
0060     void selectNext();
0061 
0062     void selectMonth(int month);
0063     void selectYear(int year);
0064 
0065 Q_SIGNALS:
0066     /* preferredMonth is useful when the datelist crosses months,
0067        if valid, any month-like component should honour it
0068     */
0069     void datesSelected(const KCalendarCore::DateList &, const QDate &preferredMonth);
0070 
0071 protected:
0072     void emitSelected(const QDate &preferredMonth = QDate());
0073 
0074 private:
0075     /*
0076       Selects next month if offset equals 1, or previous month
0077       if offset equals -1.
0078       Bigger offsets are accepted.
0079     */
0080     void shiftMonth(const QDate &date, const QDate &selectionLowerLimit, const QDate &selectionUpperLimit, int offset);
0081 
0082     KCalendarCore::DateList mSelectedDates;
0083 
0084     enum { MAX_SELECTABLE_DAYS = 50 };
0085 };