summaryrefslogtreecommitdiffstats
path: root/kalarm/recurrenceeditprivate.h
blob: 94472c379796ff184089b5a69a6bca5b9afba171 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 *  recurrenceeditprivate.h  -  private classes for recurrenceedit.cpp
 *  Program:  kalarm
 *  Copyright © 2003,2005,2007 by David Jarvie <[email protected]>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef RECURRENCEEDITPRIVATE_H
#define RECURRENCEEDITPRIVATE_H

#include <tqframe.h>
#include <tqvaluelist.h>
#include <tqbitarray.h>

class TQWidget;
class TQVBoxLayout;
class ButtonGroup;
class RadioButton;
class ComboBox;
class CheckBox;
class SpinBox;
class TimeSpinBox;
class TQString;


class NoRule : public TQFrame
{
	public:
		NoRule(TQWidget* parent, const char* name = 0) : TQFrame(parent, name)
		                                                 { setFrameStyle(TQFrame::NoFrame); }
		virtual int      frequency() const       { return 0; }
};

class Rule : public NoRule
{
		Q_OBJECT
  TQ_OBJECT
	public:
		Rule(const TQString& freqText, const TQString& freqWhatsThis, bool time, bool readOnly,
		     TQWidget* parent, const char* name = 0);
		int              frequency() const;
		void             setFrequency(int);
		virtual void     setFrequencyFocus()     { mSpinBox->setFocus(); }
		TQVBoxLayout*     layout() const          { return mLayout; }
		virtual TQWidget* validate(TQString&)      { return 0; }
		virtual void     saveState();
		virtual bool     stateChanged() const;
	signals:
		void             frequencyChanged();
	private:
		TQWidget*         mSpinBox;
		SpinBox*         mIntSpinBox;
		TimeSpinBox*     mTimeSpinBox;
		TQVBoxLayout*     mLayout;
		// Saved state of all controls
		int              mSavedFrequency;    // frequency for the selected rule
};

// Subdaily rule choices
class SubDailyRule : public Rule
{
		Q_OBJECT
  TQ_OBJECT
	public:
		SubDailyRule(bool readOnly, TQWidget* parent, const char* name = 0);
};

// Daily/weekly rule choices base class
class DayWeekRule : public Rule
{
		Q_OBJECT
  TQ_OBJECT
	public:
		DayWeekRule(const TQString& freqText, const TQString& freqWhatsThis, const TQString& daysWhatsThis,
		            bool readOnly, TQWidget* parent, const char* name = 0);
		TQBitArray        days() const;
		void             setDays(bool);
		void             setDays(const TQBitArray& days);
		void             setDay(int dayOfWeek);
		virtual TQWidget* validate(TQString& errorMessage);
		virtual void     saveState();
		virtual bool     stateChanged() const;
	private:
		CheckBox*        mDayBox[7];
		// Saved state of all controls
		TQBitArray        mSavedDays;         // ticked days for weekly rule
};

// Daily rule choices
class DailyRule : public DayWeekRule
{
	public:
		DailyRule(bool readOnly, TQWidget* parent, const char* name = 0);
};

// Weekly rule choices
class WeeklyRule : public DayWeekRule
{
	public:
		WeeklyRule(bool readOnly, TQWidget* parent, const char* name = 0);
};

// Monthly/yearly rule choices base class
class MonthYearRule : public Rule
{
		Q_OBJECT
  TQ_OBJECT
	public:
		enum DayPosType { DATE, POS };

		MonthYearRule(const TQString& freqText, const TQString& freqWhatsThis, bool allowEveryWeek,
		              bool readOnly, TQWidget* parent, const char* name = 0);
		DayPosType       type() const;
		int              date() const;       // if date in month is selected
		int              week() const;       // if position is selected
		int              dayOfWeek() const;  // if position is selected
		void             setType(DayPosType);
		void             setDate(int dayOfMonth);
		void             setPosition(int week, int dayOfWeek);
		void             setDefaultValues(int dayOfMonth, int dayOfWeek);
		virtual void     saveState();
		virtual bool     stateChanged() const;
	signals:
		void             typeChanged(DayPosType);
	protected:
		DayPosType       buttonType(int id) const  { return id == mDayButtonId ? DATE : POS; }
		virtual void     daySelected(int /*day*/)  { }
	protected slots:
		virtual void     clicked(int id);
	private slots:
		virtual void     slotDaySelected(int index);
	private:
		void             enableSelection(DayPosType);

		ButtonGroup*     mButtonGroup;
		RadioButton*     mDayButton;
		RadioButton*     mPosButton;
		ComboBox*        mDayCombo;
		ComboBox*        mWeekCombo;
		ComboBox*        mDayOfWeekCombo;
		int              mDayButtonId;
		int              mPosButtonId;
		bool             mEveryWeek;         // "Every" week is allowed
		// Saved state of all controls
		int              mSavedType;         // whether day-of-month or month position radio button was selected
		int              mSavedDay;          // chosen day of month selected item
		int              mSavedWeek;         // chosen month position: selected week item
		int              mSavedWeekDay;      // chosen month position: selected day of week
};

// Monthly rule choices
class MonthlyRule : public MonthYearRule
{
	public:
		MonthlyRule(bool readOnly, TQWidget* parent, const char* name = 0);
};

// Yearly rule choices
class YearlyRule : public MonthYearRule
{
		Q_OBJECT
  TQ_OBJECT
	public:
		YearlyRule(bool readOnly, TQWidget* parent, const char* name = 0);
		TQValueList<int>  months() const;
		void             setMonths(const TQValueList<int>& months);
		void             setDefaultValues(int dayOfMonth, int dayOfWeek, int month);
		KARecurrence::Feb29Type feb29Type() const;
		void             setFeb29Type(KARecurrence::Feb29Type);
		virtual TQWidget* validate(TQString& errorMessage);
		virtual void     saveState();
		virtual bool     stateChanged() const;
	protected:
		virtual void     daySelected(int day);
	protected slots:
		virtual void     clicked(int id);
	private slots:
		void             enableFeb29();
	private:
		CheckBox*        mMonthBox[12];
		TQLabel*          mFeb29Label;
		ComboBox*        mFeb29Combo;
		// Saved state of all controls
		TQValueList<int>  mSavedMonths;       // ticked months for yearly rule
		int              mSavedFeb29Type;    // February 29th recurrence type
};

#endif // RECURRENCEEDITPRIVATE_H