2 * recurrenceedit_p.h - private classes for recurrenceedit.cpp
4 * Copyright © 2003,2005,2007,2009-2011 by David Jarvie <djarvie@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef RECURRENCEEDIT_P_H
22 #define RECURRENCEEDIT_P_H
24 #include "radiobutton.h"
26 #include <kalarmcal/karecurrence.h>
32 #include <QAbstractButton>
44 using namespace KAlarmCal
;
47 class NoRule
: public QFrame
51 explicit NoRule(QWidget
* parent
) : QFrame(parent
) { }
52 virtual int frequency() const { return 0; }
55 class Rule
: public NoRule
59 Rule(const QString
& freqText
, const QString
& freqWhatsThis
, bool time
, bool readOnly
,
61 int frequency() const override
;
62 void setFrequency(int);
63 virtual void setFrequencyFocus() { mSpinBox
->setFocus(); }
64 QVBoxLayout
* layout() const { return mLayout
; }
65 virtual QWidget
* validate(QString
&) { return nullptr; }
66 virtual void saveState();
67 virtual bool stateChanged() const;
70 void frequencyChanged();
71 void changed(); // emitted whenever any control changes
76 TimeSpinBox
* mTimeSpinBox
;
78 // Saved state of all controls
79 int mSavedFrequency
; // frequency for the selected rule
82 // Subdaily rule choices
83 class SubDailyRule
: public Rule
87 SubDailyRule(bool readOnly
, QWidget
* parent
);
90 // Daily/weekly rule choices base class
91 class DayWeekRule
: public Rule
95 DayWeekRule(const QString
& freqText
, const QString
& freqWhatsThis
, const QString
& daysWhatsThis
,
96 bool readOnly
, QWidget
* parent
);
97 QBitArray
days() const;
99 void setDays(const QBitArray
& days
);
100 void setDay(int dayOfWeek
);
101 QWidget
* validate(QString
& errorMessage
) override
;
102 void saveState() override
;
103 bool stateChanged() const override
;
106 CheckBox
* mDayBox
[7];
107 // Saved state of all controls
108 QBitArray mSavedDays
; // ticked days for weekly rule
111 // Daily rule choices
112 class DailyRule
: public DayWeekRule
116 DailyRule(bool readOnly
, QWidget
* parent
);
119 // Weekly rule choices
120 class WeeklyRule
: public DayWeekRule
124 WeeklyRule(bool readOnly
, QWidget
* parent
);
127 // Monthly/yearly rule choices base class
128 class MonthYearRule
: public Rule
132 enum DayPosType
{ DATE
, POS
};
134 MonthYearRule(const QString
& freqText
, const QString
& freqWhatsThis
, bool allowEveryWeek
,
135 bool readOnly
, QWidget
* parent
);
136 DayPosType
type() const;
137 int date() const; // if date in month is selected
138 int week() const; // if position is selected
139 int dayOfWeek() const; // if position is selected
140 void setType(DayPosType
);
141 void setDate(int dayOfMonth
);
142 void setPosition(int week
, int dayOfWeek
);
143 void setDefaultValues(int dayOfMonth
, int dayOfWeek
);
144 void saveState() override
;
145 bool stateChanged() const override
;
148 void typeChanged(DayPosType
);
151 DayPosType
buttonType(QAbstractButton
* b
) const { return b
== mDayButton
? DATE
: POS
; }
152 virtual void daySelected(int /*day*/) { }
155 virtual void clicked(QAbstractButton
*);
158 virtual void slotDaySelected(int index
);
161 void enableSelection(DayPosType
);
163 ButtonGroup
* mButtonGroup
;
164 RadioButton
* mDayButton
;
165 RadioButton
* mPosButton
;
167 ComboBox
* mWeekCombo
;
168 ComboBox
* mDayOfWeekCombo
;
169 bool mEveryWeek
; // "Every" week is allowed
170 // Saved state of all controls
171 int mSavedType
; // whether day-of-month or month position radio button was selected
172 int mSavedDay
; // chosen day of month selected item
173 int mSavedWeek
; // chosen month position: selected week item
174 int mSavedWeekDay
; // chosen month position: selected day of week
177 // Monthly rule choices
178 class MonthlyRule
: public MonthYearRule
182 MonthlyRule(bool readOnly
, QWidget
* parent
);
185 // Yearly rule choices
186 class YearlyRule
: public MonthYearRule
190 YearlyRule(bool readOnly
, QWidget
* parent
);
191 QVector
<int> months() const;
192 void setMonths(const QList
<int>& months
);
193 void setDefaultValues(int dayOfMonth
, int dayOfWeek
, int month
);
194 KARecurrence::Feb29Type
feb29Type() const;
195 void setFeb29Type(KARecurrence::Feb29Type
);
196 QWidget
* validate(QString
& errorMessage
) override
;
197 void saveState() override
;
198 bool stateChanged() const override
;
201 void daySelected(int day
) override
;
204 void clicked(QAbstractButton
*) override
;
210 CheckBox
* mMonthBox
[12];
212 ComboBox
* mFeb29Combo
;
213 // Saved state of all controls
214 QVector
<int> mSavedMonths
; // ticked months for yearly rule
215 int mSavedFeb29Type
; // February 29th recurrence type
218 #endif // RECURRENCEEDIT_P_H