korganizer

koeditorrecurrence.h

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org>
00004     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
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
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 #ifndef _KOEDITORRECURRENCE_H
00025 #define _KOEDITORRECURRENCE_H
00026 
00027 #include <qdatetime.h>
00028 #include <qwidget.h>
00029 #include <qbitarray.h>
00030 
00031 #include <kdialogbase.h>
00032 
00033 #include <libkcal/incidencebase.h>
00034 
00035 class QWidgetStack;
00036 class QSpinBox;
00037 class QRadioButton;
00038 class QGroupBox;
00039 class QCheckBox;
00040 
00041 class KDateEdit;
00042 namespace KCal {
00043 class Incidence;
00044 }
00045 using namespace KCal;
00046 
00047 class RecurBase : public QWidget
00048 {
00049   public:
00050     RecurBase( QWidget *parent = 0, const char *name = 0 );
00051 
00052     void setFrequency( int );
00053     int frequency();
00054     // FIXME: If we want to adjust the recurrence when the start/due date change,
00055     // we need to reimplement this method in the derived classes!
00056     void setDateTimes( const QDateTime &/*start*/, const QDateTime &/*end*/ ) {}
00057 
00058     QWidget *frequencyEdit();
00059 
00060   protected:
00061     static QComboBox *createWeekCountCombo( QWidget *parent=0, const char *name=0 );
00062     static QComboBox *createWeekdayCombo( QWidget *parent=0, const char *name=0 );
00063     static QComboBox *createMonthNameCombo( QWidget *parent=0, const char *name=0 );
00064     QBoxLayout *createFrequencySpinBar( QWidget *parent, QLayout *layout,
00065     QString everyText, QString unitText );
00066 
00067   private:
00068     QSpinBox *mFrequencyEdit;
00069 };
00070 
00071 class RecurDaily : public RecurBase
00072 {
00073   public:
00074     RecurDaily( QWidget *parent = 0, const char *name = 0 );
00075 };
00076 
00077 class RecurWeekly : public RecurBase
00078 {
00079   public:
00080     RecurWeekly( QWidget *parent = 0, const char *name = 0 );
00081 
00082     void setDays( const QBitArray & );
00083     QBitArray days();
00084 
00085   private:
00086     QCheckBox *mDayBoxes[7];
00087 };
00088 
00089 class RecurMonthly : public RecurBase
00090 {
00091   public:
00092     RecurMonthly( QWidget *parent = 0, const char *name = 0 );
00093 
00094     void setByDay( int day );
00095     void setByPos( int count, int weekday );
00096 
00097     bool byDay();
00098     bool byPos();
00099 
00100     int day();
00101 
00102     int count();
00103     int weekday();
00104 
00105   private:
00106     QRadioButton *mByDayRadio;
00107     QComboBox *mByDayCombo;
00108 
00109     QRadioButton *mByPosRadio;
00110     QComboBox *mByPosCountCombo;
00111     QComboBox *mByPosWeekdayCombo;
00112 };
00113 
00114 class RecurYearly : public RecurBase
00115 {
00116   public:
00117     enum YearlyType { byDay, byPos, byMonth };
00118 
00119     RecurYearly( QWidget *parent = 0, const char *name = 0 );
00120 
00121     void setByDay( int day );
00122     void setByPos( int count, int weekday, int month );
00123     void setByMonth( int day, int month );
00124 
00125     YearlyType getType();
00126 
00127     int day();
00128     int posCount();
00129     int posWeekday();
00130     int posMonth();
00131     int monthDay();
00132     int month();
00133 
00134   private:
00135     QRadioButton *mByMonthRadio;
00136     QRadioButton *mByPosRadio;
00137     QRadioButton *mByDayRadio;
00138 
00139     QSpinBox *mByMonthSpin;
00140     QComboBox *mByMonthCombo;
00141 
00142     QComboBox *mByPosDayCombo;
00143     QComboBox *mByPosWeekdayCombo;
00144     QComboBox *mByPosMonthCombo;
00145 
00146     QSpinBox *mByDaySpin;
00147 };
00148 
00149 class RecurrenceChooser : public QWidget
00150 {
00151     Q_OBJECT
00152   public:
00153     RecurrenceChooser( QWidget *parent = 0, const char *name = 0 );
00154 
00155     enum { Daily, Weekly, Monthly, Yearly };
00156 
00157     void setType( int );
00158     int type();
00159 
00160   signals:
00161     void chosen( int );
00162 
00163   protected slots:
00164     void emitChoice();
00165 
00166   private:
00167     QComboBox *mTypeCombo;
00168 
00169     QRadioButton *mDailyButton;
00170     QRadioButton *mWeeklyButton;
00171     QRadioButton *mMonthlyButton;
00172     QRadioButton *mYearlyButton;
00173 };
00174 
00175 class ExceptionsBase
00176 {
00177   public:
00178     virtual void setDates( const DateList & ) = 0;
00179     virtual DateList dates() = 0;
00180 };
00181 
00182 class ExceptionsWidget : public QWidget, public ExceptionsBase
00183 {
00184     Q_OBJECT
00185   public:
00186     ExceptionsWidget( QWidget *parent = 0, const char *name = 0 );
00187 
00188     void setDates( const DateList & );
00189     DateList dates();
00190 
00191   protected slots:
00192     void addException();
00193     void changeException();
00194     void deleteException();
00195 
00196   private:
00197     KDateEdit *mExceptionDateEdit;
00198     QListBox *mExceptionList;
00199     DateList mExceptionDates;
00200 };
00201 
00202 class ExceptionsDialog : public KDialogBase, public ExceptionsBase
00203 {
00204   public:
00205     ExceptionsDialog( QWidget *parent, const char *name = 0 );
00206 
00207     void setDates( const DateList & );
00208     DateList dates();
00209 
00210   private:
00211     ExceptionsWidget *mExceptions;
00212 };
00213 
00214 class RecurrenceRangeBase
00215 {
00216   public:
00217     virtual void setDefaults( const QDateTime &from ) = 0;
00218 
00219     virtual void setDuration( int ) = 0;
00220     virtual int duration() = 0;
00221 
00222     virtual void setEndDate( const QDate & ) = 0;
00223     virtual QDate endDate() = 0;
00224 
00225     virtual void setDateTimes( const QDateTime &start,
00226                                const QDateTime &end = QDateTime() ) = 0;
00227 };
00228 
00229 class RecurrenceRangeWidget : public QWidget, public RecurrenceRangeBase
00230 {
00231     Q_OBJECT
00232   public:
00233     RecurrenceRangeWidget( QWidget *parent = 0, const char *name = 0 );
00234 
00235     void setDefaults( const QDateTime &from );
00236 
00237     void setDuration( int );
00238     int duration();
00239 
00240     void setEndDate( const QDate & );
00241     QDate endDate();
00242 
00243     void setDateTimes( const QDateTime &start,
00244                        const QDateTime &end = QDateTime() );
00245 
00246   protected slots:
00247     void showCurrentRange();
00248 
00249   private:
00250     QGroupBox *mRangeGroupBox;
00251     QLabel *mStartDateLabel;
00252     QRadioButton *mNoEndDateButton;
00253     QRadioButton *mEndDurationButton;
00254     QSpinBox *mEndDurationEdit;
00255     QRadioButton *mEndDateButton;
00256     KDateEdit *mEndDateEdit;
00257 };
00258 
00259 class RecurrenceRangeDialog : public KDialogBase, public RecurrenceRangeBase
00260 {
00261   public:
00262     RecurrenceRangeDialog( QWidget *parent = 0, const char *name = 0 );
00263 
00264     void setDefaults( const QDateTime &from );
00265 
00266     void setDuration( int );
00267     int duration();
00268 
00269     void setEndDate( const QDate & );
00270     QDate endDate();
00271 
00272     void setDateTimes( const QDateTime &start,
00273                        const QDateTime &end = QDateTime() );
00274 
00275   private:
00276     RecurrenceRangeWidget *mRecurrenceRangeWidget;
00277 };
00278 
00279 class KOEditorRecurrence : public QWidget
00280 {
00281     Q_OBJECT
00282   public:
00283     KOEditorRecurrence ( QWidget *parent = 0, const char *name = 0 );
00284     virtual ~KOEditorRecurrence();
00285 
00286     enum { Daily, Weekly, Monthly, Yearly };
00287 
00289     void setDefaults( const QDateTime &from, const QDateTime &to, bool allday );
00291     void readIncidence( Incidence * );
00293     void writeIncidence( Incidence * );
00294 
00296     bool validateInput();
00297 
00298     bool doesRecur();
00299 
00300   public slots:
00301     void setRecurrenceEnabled( bool );
00302     void setDateTimes( const QDateTime &start, const QDateTime &end );
00303     void setDateTimeStr( const QString & );
00304 
00305   signals:
00306     void dateTimesChanged( const QDateTime &start, const QDateTime &end );
00307 
00308   protected slots:
00309     void showCurrentRule( int );
00310     void showExceptionsDialog();
00311     void showRecurrenceRangeDialog();
00312 
00313   private:
00314     QCheckBox *mEnabledCheck;
00315 
00316     QGroupBox *mTimeGroupBox;
00317     QLabel *mDateTimeLabel;
00318 
00319     QGroupBox *mRuleBox;
00320     QWidgetStack *mRuleStack;
00321     RecurrenceChooser *mRecurrenceChooser;
00322 
00323     RecurDaily *mDaily;
00324     RecurWeekly *mWeekly;
00325     RecurMonthly *mMonthly;
00326     RecurYearly *mYearly;
00327 
00328     RecurrenceRangeBase *mRecurrenceRange;
00329     RecurrenceRangeWidget *mRecurrenceRangeWidget;
00330     RecurrenceRangeDialog *mRecurrenceRangeDialog;
00331     QPushButton *mRecurrenceRangeButton;
00332 
00333     ExceptionsBase *mExceptions;
00334     ExceptionsDialog *mExceptionsDialog;
00335     ExceptionsWidget *mExceptionsWidget;
00336     QPushButton *mExceptionsButton;
00337 
00338     QDateTime mEventStartDt;
00339 };
00340 
00341 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys