File indexing completed on 2024-04-28 05:11:36
0001 /* 0002 SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org> 0003 SPDX-FileCopyrightText: 2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "incidenceeditor-ng.h" 0011 0012 #include <KLocalizedString> 0013 #include <QDate> 0014 namespace Ui 0015 { 0016 class EventOrTodoDesktop; 0017 } 0018 0019 namespace IncidenceEditorNG 0020 { 0021 class IncidenceDateTime; 0022 0023 /// Keep this in sync with the values in mUi->mRecurrenceTypeCombo 0024 enum RecurrenceType { 0025 RecurrenceTypeNone = 0, 0026 RecurrenceTypeDaily, 0027 RecurrenceTypeWeekly, 0028 RecurrenceTypeMonthly, 0029 RecurrenceTypeYearly, 0030 RecurrenceTypeUnknown, // keep this one at the end of the ones which are also in the combobox 0031 RecurrenceTypeException 0032 }; 0033 0034 class IncidenceRecurrence : public IncidenceEditor 0035 { 0036 Q_OBJECT 0037 public: 0038 using IncidenceEditorNG::IncidenceEditor::load; // So we don't trigger -Woverloaded-virtual 0039 using IncidenceEditorNG::IncidenceEditor::save; // So we don't trigger -Woverloaded-virtual 0040 0041 IncidenceRecurrence(IncidenceDateTime *dateTime, Ui::EventOrTodoDesktop *ui); 0042 0043 void load(const KCalendarCore::Incidence::Ptr &incidence) override; 0044 void save(const KCalendarCore::Incidence::Ptr &incidence) override; 0045 [[nodiscard]] bool isDirty() const override; 0046 [[nodiscard]] bool isValid() const override; 0047 0048 void focusInvalidField() override; 0049 0050 [[nodiscard]] RecurrenceType currentRecurrenceType() const; 0051 0052 Q_SIGNALS: 0053 void recurrenceChanged(IncidenceEditorNG::RecurrenceType type); 0054 0055 private: 0056 void addException(); 0057 void fillCombos(); 0058 void handleDateTimeToggle(); 0059 void handleEndAfterOccurrencesChange(int currentValue); 0060 void handleExceptionDateChange(const QDate ¤tDate); 0061 void handleFrequencyChange(); 0062 void handleRecurrenceTypeChange(int currentIndex); 0063 void removeExceptions(); 0064 void updateRemoveExceptionButton(); 0065 void updateWeekDays(const QDate &newStartDate); 0066 void handleStartDateChange(const QDate &); 0067 0068 /** 0069 I needed save() to be const, so created this func. 0070 save() calls this now, and changes members outside. 0071 */ 0072 void writeToIncidence(const KCalendarCore::Incidence::Ptr &incidence) const; 0073 0074 KLocalizedString subsOrdinal(const KLocalizedString &text, int number) const; 0075 /** 0076 * Return the day in the month/year on which the event recurs, starting at the 0077 * beginning/end. Both return a positive number. 0078 */ 0079 short dayOfMonthFromStart() const; 0080 short dayOfMonthFromEnd() const; 0081 short dayOfYearFromStart() const; // We don't need from end for year 0082 int duration() const; 0083 0084 /** Returns the week number (1-5) of the month in which the start date occurs. */ 0085 short monthWeekFromStart() const; 0086 short monthWeekFromEnd() const; 0087 0088 /** DO NOT USE THIS METHOD DIRECTLY 0089 use subsOrdinal() instead for i18n * */ 0090 QString numberToString(int number) const; 0091 void selectMonthlyItem(KCalendarCore::Recurrence *recurrence, ushort recurenceType); 0092 void selectYearlyItem(KCalendarCore::Recurrence *recurrence, ushort recurenceType); 0093 void setDefaults(); 0094 void setDuration(int duration); 0095 void setExceptionDates(const KCalendarCore::DateList &dates); 0096 void setExceptionDateTimes(const KCalendarCore::DateTimeList &dateTimes); 0097 void setFrequency(int freq); 0098 void toggleRecurrenceWidgets(int enable); 0099 /** Returns an array with the weekday on which the event occurs set to 1 */ 0100 QBitArray weekday() const; 0101 0102 /** 0103 * Return how many times the weekday represented by @param date occurs in 0104 * the month of @param date. 0105 */ 0106 int weekdayCountForMonth(const QDate &date) const; 0107 0108 QDate currentDate() const; 0109 0110 private: 0111 Ui::EventOrTodoDesktop *const mUi; 0112 QDate mCurrentDate; 0113 IncidenceDateTime *const mDateTime; 0114 KCalendarCore::DateList mExceptionDates; 0115 0116 // So we can easily detect if the user changed the type, 0117 // without going through complicated recurrence logic: 0118 int mMonthlyInitialType = -1; 0119 int mYearlyInitialType = -1; 0120 }; 0121 }