kalarm

alarmtimewidget.h

00001 /*
00002  *  alarmtimewidget.h  -  alarm date/time entry widget
00003  *  Program:  kalarm
00004  *  Copyright © 2001-2006 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 ALARMTIMEWIDGET_H
00022 #define ALARMTIMEWIDGET_H
00023 
00024 #include "buttongroup.h"
00025 #include "datetime.h"
00026 
00027 class RadioButton;
00028 class CheckBox;
00029 class DateEdit;
00030 class TimeEdit;
00031 class TimeSpinBox;
00032 
00033 
00034 class AlarmTimeWidget : public ButtonGroup
00035 {
00036         Q_OBJECT
00037   TQ_OBJECT
00038     public:
00039         enum {       // 'mode' values for constructor. May be OR'ed together.
00040             AT_TIME      = 0x00,   // "At ..."
00041             DEFER_TIME   = 0x01,   // "Defer to ..."
00042             NARROW       = 0x02    // make a narrow widget
00043         };
00044         AlarmTimeWidget(const TQString& groupBoxTitle, int mode, TQWidget* parent = 0, const char* name = 0);
00045         AlarmTimeWidget(int mode, TQWidget* parent = 0, const char* name = 0);
00046         DateTime         getDateTime(int* minsFromNow = 0, bool checkExpired = true, bool showErrorMessage = true, TQWidget** errorWidget = 0) const;
00047         void             setDateTime(const DateTime&);
00048         void             setMinDateTimeIsCurrent();
00049         void             setMinDateTime(const TQDateTime& = TQDateTime());
00050         void             setMaxDateTime(const DateTime& = DateTime());
00051         const TQDateTime& maxDateTime() const           { return mMaxDateTime; }
00052         void             setReadOnly(bool);
00053         bool             anyTime() const               { return mAnyTime; }
00054         void             enableAnyTime(bool enable);
00055         void             selectTimeFromNow(int minutes = 0);
00056         TQSize            sizeHint() const              { return minimumSizeHint(); }
00057 
00058         static TQString   i18n_w_TimeFromNow();     // text of 'Time from now:' radio button, with 'w' shortcut
00059         static TQString   i18n_TimeAfterPeriod();
00060         static const int maxDelayTime;    // maximum time from now
00061 
00062     signals:
00063         void             anyTimeToggled(bool anyTime);
00064         void             pastMax();
00065 
00066     protected slots:
00067         void             slotTimer();
00068         void             slotButtonSet(int id);
00069         void             dateTimeChanged();
00070         void             delayTimeChanged(int);
00071         void             slotAnyTimeToggled(bool);
00072 
00073     private:
00074         void             init(int mode);
00075         void             setAnyTime();
00076         void             setMaxDelayTime(const TQDateTime& now);
00077         void             setMaxMinTimeIf(const TQDateTime& now);
00078 
00079         RadioButton*     mAtTimeRadio;
00080         RadioButton*     mAfterTimeRadio;
00081         DateEdit*        mDateEdit;
00082         TimeEdit*        mTimeEdit;
00083         TimeSpinBox*     mDelayTimeEdit;
00084         CheckBox*        mAnyTimeCheckBox;
00085         TQDateTime        mMinDateTime;      // earliest allowed date/time
00086         TQDateTime        mMaxDateTime;      // latest allowed date/time
00087         int              mAnyTime;          // 0 = date/time is specified, 1 = only a date, -1 = uninitialised
00088         bool             mAnyTimeAllowed;   // 'mAnyTimeCheckBox' is enabled
00089         bool             mMinDateTimeIsNow; // earliest allowed date/time is the current time
00090         bool             mPastMax;          // current time is past the maximum date/time
00091         bool             mMinMaxTimeSet;    // limits have been set for the time edit control
00092         bool             mTimerSyncing;     // mTimer is not yet synchronised to the minute boundary
00093 };
00094 
00095 #endif // ALARMTIMEWIDGET_H