kalarm

recurrenceedit.h

00001 /*
00002  *  recurrenceedit.h  -  widget to edit the event's recurrence definition
00003  *  Program:  kalarm
00004  *  Copyright © 2002-2005,2008 by David Jarvie <djarvie@kde.org>
00005  *
00006  *  Based originally on KOrganizer module koeditorrecurrence.h,
00007  *  Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
00008  *
00009  *  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License along
00020  *  with this program; if not, write to the Free Software Foundation, Inc.,
00021  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00022  */
00023 
00024 #ifndef RECURRENCEEDIT_H
00025 #define RECURRENCEEDIT_H
00026 
00027 #include <qframe.h>
00028 #include <qdatetime.h>
00029 #include <qvaluelist.h>
00030 
00031 #include "datetime.h"
00032 class QWidgetStack;
00033 class QGroupBox;
00034 class QLabel;
00035 class QListBox;
00036 class QButton;
00037 class QPushButton;
00038 class QBoxLayout;
00039 class SpinBox;
00040 class CheckBox;
00041 class RadioButton;
00042 class DateEdit;
00043 class TimeEdit;
00044 class ButtonGroup;
00045 class RepetitionButton;
00046 class KAEvent;
00047 class Rule;
00048 class NoRule;
00049 class SubDailyRule;
00050 class DailyRule;
00051 class WeeklyRule;
00052 class MonthlyRule;
00053 class YearlyRule;
00054 
00055 
00056 class RecurrenceEdit : public QFrame
00057 {
00058         Q_OBJECT
00059     public:
00060         // Don't alter the order of these recurrence types
00061         enum RepeatType { INVALID_RECUR = -1, NO_RECUR, AT_LOGIN, SUBDAILY, DAILY, WEEKLY, MONTHLY, ANNUAL };
00062 
00063         RecurrenceEdit(bool readOnly, QWidget* parent, const char* name = 0);
00064         virtual ~RecurrenceEdit()  { }
00065 
00067         void          setDefaults(const QDateTime& from);
00069         void          set(const KAEvent&, bool keepDuration);
00071         void          updateEvent(KAEvent&, bool adjustStart);
00072         QWidget*      checkData(const QDateTime& startDateTime, QString& errorMessage) const;
00073         RepeatType    repeatType() const                    { return mRuleButtonType; }
00074         bool          isTimedRepeatType() const             { return mRuleButtonType >= SUBDAILY; }
00075         int           subRepeatCount(int* subRepeatInterval = 0) const;
00076         void          setSubRepetition(int reminderMinutes, bool dateOnly);
00077         void          setStartDate(const QDate&, const QDate& today);
00078         void          setDefaultEndDate(const QDate&);
00079         void          setEndDateTime(const DateTime&);
00080         DateTime      endDateTime() const;
00081         bool          stateChanged() const;
00082         void          activateSubRepetition();
00083 
00084         static QString i18n_Norecur();           // text of 'No recurrence' selection, lower case
00085         static QString i18n_NoRecur();           // text of 'No Recurrence' selection, initial capitals
00086         static QString i18n_AtLogin();           // text of 'At Login' selection
00087         static QString i18n_l_Atlogin();         // text of 'At &login' selection, with 'L' shortcut
00088         static QString i18n_HourlyMinutely();    // text of 'Hourly/Minutely'
00089         static QString i18n_u_HourlyMinutely();  // text of 'Ho&urly/Minutely' selection, with 'U' shortcut
00090         static QString i18n_Daily();             // text of 'Daily' selection
00091         static QString i18n_d_Daily();           // text of '&Daily' selection, with 'D' shortcut
00092         static QString i18n_Weekly();            // text of 'Weekly' selection
00093         static QString i18n_w_Weekly();          // text of '&Weekly' selection, with 'W' shortcut
00094         static QString i18n_Monthly();           // text of 'Monthly' selection
00095         static QString i18n_m_Monthly();         // text of '&Monthly' selection, with 'M' shortcut
00096         static QString i18n_Yearly();            // text of 'Yearly' selection
00097         static QString i18n_y_Yearly();          // text of '&Yearly' selection, with 'Y' shortcut
00098 
00099     public slots:
00100         void          setDateTime(const QDateTime& start)   { mCurrStartDateTime = start; }
00101 
00102     signals:
00103         void          shown();
00104         void          typeChanged(int recurType);   // returns a RepeatType value
00105         void          frequencyChanged();
00106         void          repeatNeedsInitialisation();
00107 
00108     protected:
00109         virtual void  showEvent(QShowEvent*);
00110 
00111     private slots:
00112         void          periodClicked(int);
00113         void          rangeTypeClicked();
00114         void          repeatCountChanged(int value);
00115         void          slotAnyTimeToggled(bool);
00116         void          addException();
00117         void          changeException();
00118         void          deleteException();
00119         void          enableExceptionButtons();
00120 
00121     private:
00122         void          setRuleDefaults(const QDate& start);
00123         void          saveState();
00124 
00125         // Main rule box and choices
00126         QWidgetStack*     mRuleStack;
00127         Rule*             mRule;         // current rule widget, or 0 if NoRule
00128         NoRule*           mNoRule;
00129         SubDailyRule*     mSubDailyRule;
00130         DailyRule*        mDailyRule;
00131         WeeklyRule*       mWeeklyRule;
00132         MonthlyRule*      mMonthlyRule;
00133         YearlyRule*       mYearlyRule;
00134 
00135         ButtonGroup*      mRuleButtonGroup;
00136         RadioButton*      mNoneButton;
00137         RadioButton*      mAtLoginButton;
00138         RadioButton*      mSubDailyButton;
00139         RadioButton*      mDailyButton;
00140         RadioButton*      mWeeklyButton;
00141         RadioButton*      mMonthlyButton;
00142         RadioButton*      mYearlyButton;
00143         int               mNoneButtonId;
00144         int               mAtLoginButtonId;
00145         int               mSubDailyButtonId;
00146         int               mDailyButtonId;
00147         int               mWeeklyButtonId;
00148         int               mMonthlyButtonId;
00149         int               mYearlyButtonId;
00150         RepeatType        mRuleButtonType;
00151         bool              mDailyShown;       // daily rule has been displayed at some time or other
00152         bool              mWeeklyShown;      // weekly rule has been displayed at some time or other
00153         bool              mMonthlyShown;     // monthly rule has been displayed at some time or other
00154         bool              mYearlyShown;      // yearly rule has been displayed at some time or other
00155 
00156         // Range
00157         ButtonGroup*      mRangeButtonGroup;
00158         RadioButton*      mNoEndDateButton;
00159         RadioButton*      mRepeatCountButton;
00160         SpinBox*          mRepeatCountEntry;
00161         QLabel*           mRepeatCountLabel;
00162         RadioButton*      mEndDateButton;
00163         DateEdit*         mEndDateEdit;
00164         TimeEdit*         mEndTimeEdit;
00165         CheckBox*         mEndAnyTimeCheckBox;
00166 
00167         // Exceptions
00168         QGroupBox*        mExceptionGroup;
00169         QListBox*         mExceptionDateList;
00170         DateEdit*         mExceptionDateEdit;
00171         QPushButton*      mChangeExceptionButton;
00172         QPushButton*      mDeleteExceptionButton;
00173         QValueList<QDate> mExceptionDates;
00174 
00175         // Current start date and time
00176         QDateTime         mCurrStartDateTime;
00177         RepetitionButton* mSubRepetition;
00178         bool              mNoEmitTypeChanged;        // suppress typeChanged() signal
00179         bool              mReadOnly;
00180 
00181         // Initial state of non-rule controls
00182         QButton*          mSavedRuleButton;          // which rule button was selected
00183         QButton*          mSavedRangeButton;         // which range button was selected
00184         int               mSavedRecurCount;          // recurrence repeat count
00185         DateTime          mSavedEndDateTime;         // end date/time
00186         QValueList<QDate> mSavedExceptionDates;      // exception dates
00187         int               mSavedRepeatInterval;      // sub-repetition interval (via mSubRepetition button)
00188         int               mSavedRepeatCount;         // sub-repetition count (via mSubRepetition button)
00189 };
00190 
00191 #endif // RECURRENCEEDIT_H