File indexing completed on 2024-05-12 05:14:56
0001 /* 0002 * recurrenceedit.h - widget to edit the event's recurrence definition 0003 * Program: kalarm 0004 * SPDX-FileCopyrightText: 2002-2022 David Jarvie <djarvie@kde.org> 0005 * 0006 * Based originally on KOrganizer module koeditorrecurrence.h, 0007 * SPDX-FileCopyrightText: 2000, 2001 Cornelius Schumacher <schumacher@kde.org> 0008 * 0009 * SPDX-License-Identifier: GPL-2.0-or-later 0010 */ 0011 0012 #pragma once 0013 0014 #include "kalarmcalendar/repetition.h" 0015 #include "kalarmcalendar/kadatetime.h" 0016 0017 #include <QFrame> 0018 0019 class KDateComboBox; 0020 class QDate; 0021 class QShowEvent; 0022 class QStackedWidget; 0023 class QGroupBox; 0024 class QLabel; 0025 class QListWidget; 0026 class QAbstractButton; 0027 class QPushButton; 0028 class SpinBox; 0029 class CheckBox; 0030 class RadioButton; 0031 class TimeEdit; 0032 class ButtonGroup; 0033 class RepetitionButton; 0034 class Rule; 0035 class NoRule; 0036 class SubDailyRule; 0037 class DailyRule; 0038 class WeeklyRule; 0039 class MonthlyRule; 0040 class YearlyRule; 0041 namespace KAlarmCal { class KAEvent; } 0042 0043 using namespace KAlarmCal; 0044 0045 class RecurrenceEdit : public QFrame 0046 { 0047 Q_OBJECT 0048 public: 0049 // Don't alter the order of these recurrence types 0050 enum RepeatType { INVALID_RECUR = -1, NO_RECUR, AT_LOGIN, SUBDAILY, DAILY, WEEKLY, MONTHLY, ANNUAL }; 0051 0052 explicit RecurrenceEdit(bool readOnly, QWidget* parent = nullptr); 0053 ~RecurrenceEdit() override = default; 0054 0055 /** Set widgets to default values */ 0056 void setDefaults(const KADateTime& from); 0057 /** Initialise according to a specified event */ 0058 void set(const KAEvent&); 0059 /** Initialise with repeat-at-login selected, instead of calling set(). */ 0060 void setRepeatAtLogin(); 0061 /** Write recurrence settings into an event */ 0062 void updateEvent(KAEvent&, bool adjustStart); 0063 QWidget* checkData(const KADateTime& startDateTime, QString& errorMessage) const; 0064 RepeatType repeatType() const { return mRuleButtonType; } 0065 bool isTimedRepeatType() const { return mRuleButtonType >= SUBDAILY; } 0066 Repetition subRepetition() const; 0067 void setSubRepetition(int reminderMinutes, bool dateOnly); 0068 void setStartDate(const QDate&, const QDate& today); 0069 void setDefaultEndDate(const QDate&); 0070 void setEndDateTime(const KADateTime&); 0071 KADateTime endDateTime() const; 0072 bool stateChanged() const; 0073 void activateSubRepetition(); 0074 void showMoreOptions(bool); 0075 0076 static QString i18n_combo_NoRecur(); // text of 'No recurrence' selection 0077 static QString i18n_combo_AtLogin(); // text of 'At login' selection 0078 static QString i18n_combo_HourlyMinutely(); // text of 'Hourly/Minutely' 0079 static QString i18n_combo_Daily(); // text of 'Daily' selection 0080 static QString i18n_combo_Weekly(); // text of 'Weekly' selection 0081 static QString i18n_combo_Monthly(); // text of 'Monthly' selection 0082 static QString i18n_combo_Yearly(); // text of 'Yearly' selection 0083 0084 public Q_SLOTS: 0085 void setDateTime(const KADateTime& start) { mCurrStartDateTime = start; } 0086 0087 Q_SIGNALS: 0088 void shown(); 0089 void typeChanged(int recurType); // returns a RepeatType value 0090 void frequencyChanged(); 0091 void repeatNeedsInitialisation(); 0092 void contentsChanged(); 0093 0094 protected: 0095 void showEvent(QShowEvent*) override; 0096 0097 private Q_SLOTS: 0098 void periodClicked(QAbstractButton*); 0099 void rangeTypeClicked(); 0100 void repeatCountChanged(int value); 0101 void slotAnyTimeToggled(bool); 0102 void addException(); 0103 void changeException(); 0104 void deleteException(); 0105 void enableExceptionButtons(); 0106 0107 private: 0108 void setRuleDefaults(const QDate& start); 0109 void saveState(); 0110 0111 // Main rule box and choices 0112 QStackedWidget* mRuleStack; 0113 Rule* mRule {nullptr}; // current rule widget, or 0 if NoRule 0114 NoRule* mNoRule; 0115 SubDailyRule* mSubDailyRule; 0116 DailyRule* mDailyRule; 0117 WeeklyRule* mWeeklyRule; 0118 MonthlyRule* mMonthlyRule; 0119 YearlyRule* mYearlyRule; 0120 0121 ButtonGroup* mRuleButtonGroup; 0122 RadioButton* mNoneButton; 0123 RadioButton* mAtLoginButton; 0124 RadioButton* mSubDailyButton; 0125 RadioButton* mDailyButton; 0126 RadioButton* mWeeklyButton; 0127 RadioButton* mMonthlyButton; 0128 RadioButton* mYearlyButton; 0129 RepeatType mRuleButtonType {INVALID_RECUR}; 0130 bool mDailyShown {false}; // daily rule has been displayed at some time or other 0131 bool mWeeklyShown {false}; // weekly rule has been displayed at some time or other 0132 bool mMonthlyShown {false}; // monthly rule has been displayed at some time or other 0133 bool mYearlyShown {false}; // yearly rule has been displayed at some time or other 0134 0135 // Range 0136 QGroupBox* mRangeButtonBox; 0137 ButtonGroup* mRangeButtonGroup; 0138 RadioButton* mNoEndDateButton; 0139 RadioButton* mRepeatCountButton; 0140 SpinBox* mRepeatCountEntry; 0141 QLabel* mRepeatCountLabel; 0142 RadioButton* mEndDateButton; 0143 KDateComboBox* mEndDateEdit; 0144 TimeEdit* mEndTimeEdit; 0145 CheckBox* mEndAnyTimeCheckBox; 0146 0147 // Exceptions 0148 QGroupBox* mExceptionGroup; 0149 QListWidget* mExceptionDateList; 0150 KDateComboBox* mExceptionDateEdit; 0151 QPushButton* mChangeExceptionButton; 0152 QPushButton* mDeleteExceptionButton; 0153 CheckBox* mExcludeHolidays; 0154 CheckBox* mWorkTimeOnly; 0155 QList<QDate> mExceptionDates; 0156 0157 // Current start date and time 0158 KADateTime mCurrStartDateTime; 0159 RepetitionButton* mSubRepetition; 0160 bool mNoEmitTypeChanged {true}; // suppress typeChanged() signal 0161 bool mReadOnly; 0162 0163 // Initial state of non-rule controls 0164 QAbstractButton* mSavedRuleButton; // which rule button was selected 0165 QAbstractButton* mSavedRangeButton; // which range button was selected 0166 int mSavedRecurCount; // recurrence repeat count 0167 KADateTime mSavedEndDateTime; // end date/time 0168 QList<QDate> mSavedExceptionDates; // exception dates 0169 Repetition mSavedRepetition; // sub-repetition interval & count (via mSubRepetition button) 0170 bool mSavedExclHolidays; // exclude holidays 0171 bool mSavedWorkTimeOnly; // only during working hours 0172 }; 0173 0174 // vim: et sw=4: