File indexing completed on 2024-05-12 05:14:56

0001 /*
0002  *  recurrenceedit_p.h  -  private classes for recurrenceedit.cpp
0003  *  Program:  kalarm
0004  *  SPDX-FileCopyrightText: 2003-2022 David Jarvie <djarvie@kde.org>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #pragma once
0010 
0011 #include "lib/radiobutton.h"
0012 #include "kalarmcalendar/karecurrence.h"
0013 
0014 #include <QAbstractButton>
0015 #include <QBitArray>
0016 #include <QFrame>
0017 #include <QList>
0018 
0019 class QLabel;
0020 class QWidget;
0021 class QVBoxLayout;
0022 class ButtonGroup;
0023 class ComboBox;
0024 class CheckBox;
0025 class SpinBox;
0026 class TimeSpinBox;
0027 class QString;
0028 
0029 using namespace KAlarmCal;
0030 
0031 
0032 class NoRule : public QFrame
0033 {
0034     Q_OBJECT
0035 public:
0036     explicit NoRule(QWidget* parent) : QFrame(parent) { }
0037     virtual int      frequency() const       { return 0; }
0038 };
0039 
0040 class Rule : public NoRule
0041 {
0042     Q_OBJECT
0043 public:
0044     Rule(const QString& freqText, const QString& freqWhatsThis, bool time, bool readOnly,
0045          QWidget* parent);
0046     int              frequency() const override;
0047     void             setFrequency(int);
0048     virtual void     setFrequencyFocus()     { mSpinBox->setFocus(); }
0049     QVBoxLayout*     layout() const          { return mLayout; }
0050     virtual QWidget* validate(QString&)      { return nullptr; }
0051     virtual void     saveState();
0052     virtual bool     stateChanged() const;
0053 
0054 Q_SIGNALS:
0055     void             frequencyChanged();
0056     void             changed();          // emitted whenever any control changes
0057 
0058 private:
0059     QWidget*         mSpinBox;
0060     SpinBox*         mIntSpinBox;
0061     TimeSpinBox*     mTimeSpinBox;
0062     QVBoxLayout*     mLayout;
0063     // Saved state of all controls
0064     int              mSavedFrequency;    // frequency for the selected rule
0065 };
0066 
0067 // Subdaily rule choices
0068 class SubDailyRule : public Rule
0069 {
0070     Q_OBJECT
0071 public:
0072     SubDailyRule(bool readOnly, QWidget* parent);
0073 };
0074 
0075 // Daily/weekly rule choices base class
0076 class DayWeekRule : public Rule
0077 {
0078     Q_OBJECT
0079 public:
0080     DayWeekRule(const QString& freqText, const QString& freqWhatsThis, const QString& daysWhatsThis,
0081                 bool readOnly, QWidget* parent);
0082     QBitArray        days() const;
0083     void             setDays(bool);
0084     void             setDays(const QBitArray& days);
0085     void             setDay(int dayOfWeek);
0086     QWidget*         validate(QString& errorMessage) override;
0087     void             saveState() override;
0088     bool             stateChanged() const override;
0089 
0090 private:
0091     CheckBox*        mDayBox[7];
0092     // Saved state of all controls
0093     QBitArray        mSavedDays;         // ticked days for weekly rule
0094 };
0095 
0096 // Daily rule choices
0097 class DailyRule : public DayWeekRule
0098 {
0099     Q_OBJECT
0100 public:
0101     DailyRule(bool readOnly, QWidget* parent);
0102 };
0103 
0104 // Weekly rule choices
0105 class WeeklyRule : public DayWeekRule
0106 {
0107     Q_OBJECT
0108 public:
0109     WeeklyRule(bool readOnly, QWidget* parent);
0110 };
0111 
0112 // Monthly/yearly rule choices base class
0113 class MonthYearRule : public Rule
0114 {
0115     Q_OBJECT
0116 public:
0117     enum DayPosType { DATE, POS };
0118 
0119     MonthYearRule(const QString& freqText, const QString& freqWhatsThis, bool allowEveryWeek,
0120                   bool readOnly, QWidget* parent);
0121     DayPosType       type() const;
0122     int              date() const;       // if date in month is selected
0123     int              week() const;       // if position is selected
0124     int              dayOfWeek() const;  // if position is selected
0125     void             setType(DayPosType);
0126     void             setDate(int dayOfMonth);
0127     void             setPosition(int week, int dayOfWeek);
0128     void             setDefaultValues(int dayOfMonth, int dayOfWeek);
0129     void             saveState() override;
0130     bool             stateChanged() const override;
0131 
0132 Q_SIGNALS:
0133     void             typeChanged(DayPosType);
0134 
0135 protected:
0136     DayPosType       buttonType(QAbstractButton* b) const  { return b == mDayButton ? DATE : POS; }
0137     virtual void     daySelected(int /*day*/)  { }
0138 
0139 protected Q_SLOTS:
0140     virtual void     clicked(QAbstractButton*);
0141 
0142 private Q_SLOTS:
0143     virtual void     slotDaySelected(int index);
0144 
0145 private:
0146     void             enableSelection(DayPosType);
0147 
0148     ButtonGroup*     mButtonGroup;
0149     RadioButton*     mDayButton;
0150     RadioButton*     mPosButton;
0151     ComboBox*        mDayCombo;
0152     ComboBox*        mWeekCombo;
0153     ComboBox*        mDayOfWeekCombo;
0154     bool             mEveryWeek;         // "Every" week is allowed
0155     // Saved state of all controls
0156     int              mSavedType;         // whether day-of-month or month position radio button was selected
0157     int              mSavedDay;          // chosen day of month selected item
0158     int              mSavedWeek;         // chosen month position: selected week item
0159     int              mSavedWeekDay;      // chosen month position: selected day of week
0160 };
0161 
0162 // Monthly rule choices
0163 class MonthlyRule : public MonthYearRule
0164 {
0165     Q_OBJECT
0166 public:
0167     MonthlyRule(bool readOnly, QWidget* parent);
0168 };
0169 
0170 // Yearly rule choices
0171 class YearlyRule : public MonthYearRule
0172 {
0173     Q_OBJECT
0174 public:
0175     YearlyRule(bool readOnly, QWidget* parent);
0176     QList<int>       months() const;
0177     void             setMonths(const QList<int>& months);
0178     void             setDefaultValues(int dayOfMonth, int dayOfWeek, int month);
0179     KARecurrence::Feb29Type feb29Type() const;
0180     void             setFeb29Type(KARecurrence::Feb29Type);
0181     QWidget*         validate(QString& errorMessage) override;
0182     void             saveState() override;
0183     bool             stateChanged() const override;
0184 
0185 protected:
0186     void             daySelected(int day) override;
0187 
0188 protected Q_SLOTS:
0189     void             clicked(QAbstractButton*) override;
0190 
0191 private Q_SLOTS:
0192     void             enableFeb29();
0193 
0194 private:
0195     CheckBox*        mMonthBox[12];
0196     QLabel*          mFeb29Label;
0197     ComboBox*        mFeb29Combo;
0198     // Saved state of all controls
0199     QList<int>       mSavedMonths;       // ticked months for yearly rule
0200     int              mSavedFeb29Type;    // February 29th recurrence type
0201 };
0202 
0203 // vim: et sw=4: