kalarm

recurrenceeditprivate.h
00001 /*
00002  *  recurrenceeditprivate.h  -  private classes for recurrenceedit.cpp
00003  *  Program:  kalarm
00004  *  Copyright © 2003,2005,2007 by David Jarvie <software@astrojar.org.uk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef RECURRENCEEDITPRIVATE_H
00022 #define RECURRENCEEDITPRIVATE_H
00023 
00024 #include <tqframe.h>
00025 #include <tqvaluelist.h>
00026 #include <tqbitarray.h>
00027 
00028 class TQWidget;
00029 class TQVBoxLayout;
00030 class ButtonGroup;
00031 class RadioButton;
00032 class ComboBox;
00033 class CheckBox;
00034 class SpinBox;
00035 class TimeSpinBox;
00036 class TQString;
00037 
00038 
00039 class NoRule : public TQFrame
00040 {
00041     public:
00042         NoRule(TQWidget* parent, const char* name = 0) : TQFrame(parent, name)
00043                                                          { setFrameStyle(TQFrame::NoFrame); }
00044         virtual int       frequency() const       { return 0; }
00045 };
00046 
00047 class Rule : public NoRule
00048 {
00049         Q_OBJECT
00050 
00051     public:
00052         Rule(const TQString& freqText, const TQString& freqWhatsThis, bool time, bool readOnly,
00053              TQWidget* parent, const char* name = 0);
00054         int               frequency() const;
00055         void              setFrequency(int);
00056         virtual void      setFrequencyFocus()     { mSpinBox->setFocus(); }
00057         TQVBoxLayout*     layout() const          { return mLayout; }
00058         virtual TQWidget* validate(TQString&)      { return 0; }
00059         virtual void      saveState();
00060         virtual bool      stateChanged() const;
00061     signals:
00062         void              frequencyChanged();
00063     private:
00064         TQWidget*         mSpinBox;
00065         SpinBox*          mIntSpinBox;
00066         TimeSpinBox*      mTimeSpinBox;
00067         TQVBoxLayout*     mLayout;
00068         // Saved state of all controls
00069         int               mSavedFrequency;    // frequency for the selected rule
00070 };
00071 
00072 // Subdaily rule choices
00073 class SubDailyRule : public Rule
00074 {
00075         Q_OBJECT
00076 
00077     public:
00078         SubDailyRule(bool readOnly, TQWidget* parent, const char* name = 0);
00079 };
00080 
00081 // Daily/weekly rule choices base class
00082 class DayWeekRule : public Rule
00083 {
00084         Q_OBJECT
00085 
00086     public:
00087         DayWeekRule(const TQString& freqText, const TQString& freqWhatsThis, const TQString& daysWhatsThis,
00088                     bool readOnly, TQWidget* parent, const char* name = 0);
00089         TQBitArray        days() const;
00090         void              setDays(bool);
00091         void              setDays(const TQBitArray& days);
00092         void              setDay(int dayOfWeek);
00093         virtual TQWidget* validate(TQString& errorMessage);
00094         virtual void      saveState();
00095         virtual bool      stateChanged() const;
00096     private:
00097         CheckBox*         mDayBox[7];
00098         // Saved state of all controls
00099         TQBitArray        mSavedDays;         // ticked days for weekly rule
00100 };
00101 
00102 // Daily rule choices
00103 class DailyRule : public DayWeekRule
00104 {
00105     public:
00106         DailyRule(bool readOnly, TQWidget* parent, const char* name = 0);
00107 };
00108 
00109 // Weekly rule choices
00110 class WeeklyRule : public DayWeekRule
00111 {
00112     public:
00113         WeeklyRule(bool readOnly, TQWidget* parent, const char* name = 0);
00114 };
00115 
00116 // Monthly/yearly rule choices base class
00117 class MonthYearRule : public Rule
00118 {
00119         Q_OBJECT
00120 
00121     public:
00122         enum DayPosType { DATE, POS };
00123 
00124         MonthYearRule(const TQString& freqText, const TQString& freqWhatsThis, bool allowEveryWeek,
00125                       bool readOnly, TQWidget* parent, const char* name = 0);
00126         DayPosType       type() const;
00127         int              date() const;       // if date in month is selected
00128         int              week() const;       // if position is selected
00129         int              dayOfWeek() const;  // if position is selected
00130         void             setType(DayPosType);
00131         void             setDate(int dayOfMonth);
00132         void             setPosition(int week, int dayOfWeek);
00133         void             setDefaultValues(int dayOfMonth, int dayOfWeek);
00134         virtual void     saveState();
00135         virtual bool     stateChanged() const;
00136     signals:
00137         void             typeChanged(DayPosType);
00138     protected:
00139         DayPosType       buttonType(int id) const  { return id == mDayButtonId ? DATE : POS; }
00140         virtual void     daySelected(int /*day*/)  { }
00141     protected slots:
00142         virtual void     clicked(int id);
00143     private slots:
00144         virtual void     slotDaySelected(int index);
00145     private:
00146         void             enableSelection(DayPosType);
00147 
00148         ButtonGroup*     mButtonGroup;
00149         RadioButton*     mDayButton;
00150         RadioButton*     mPosButton;
00151         ComboBox*        mDayCombo;
00152         ComboBox*        mWeekCombo;
00153         ComboBox*        mDayOfWeekCombo;
00154         int              mDayButtonId;
00155         int              mPosButtonId;
00156         bool             mEveryWeek;         // "Every" week is allowed
00157         // Saved state of all controls
00158         int              mSavedType;         // whether day-of-month or month position radio button was selected
00159         int              mSavedDay;          // chosen day of month selected item
00160         int              mSavedWeek;         // chosen month position: selected week item
00161         int              mSavedWeekDay;      // chosen month position: selected day of week
00162 };
00163 
00164 // Monthly rule choices
00165 class MonthlyRule : public MonthYearRule
00166 {
00167     public:
00168         MonthlyRule(bool readOnly, TQWidget* parent, const char* name = 0);
00169 };
00170 
00171 // Yearly rule choices
00172 class YearlyRule : public MonthYearRule
00173 {
00174         Q_OBJECT
00175 
00176     public:
00177         YearlyRule(bool readOnly, TQWidget* parent, const char* name = 0);
00178         TQValueList<int>  months() const;
00179         void              setMonths(const TQValueList<int>& months);
00180         void              setDefaultValues(int dayOfMonth, int dayOfWeek, int month);
00181         KARecurrence::Feb29Type feb29Type() const;
00182         void              setFeb29Type(KARecurrence::Feb29Type);
00183         virtual TQWidget* validate(TQString& errorMessage);
00184         virtual void      saveState();
00185         virtual bool      stateChanged() const;
00186     protected:
00187         virtual void      daySelected(int day);
00188     protected slots:
00189         virtual void      clicked(int id);
00190     private slots:
00191         void              enableFeb29();
00192     private:
00193         CheckBox*         mMonthBox[12];
00194         TQLabel*          mFeb29Label;
00195         ComboBox*         mFeb29Combo;
00196         // Saved state of all controls
00197         TQValueList<int>  mSavedMonths;       // ticked months for yearly rule
00198         int               mSavedFeb29Type;    // February 29th recurrence type
00199 };
00200 
00201 #endif // RECURRENCEEDITPRIVATE_H