kalarm

alarmtimewidget.h
1 /*
2  * alarmtimewidget.h - alarm date/time entry widget
3  * Program: kalarm
4  * Copyright © 2001-2006 by David Jarvie <software@astrojar.org.uk>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef ALARMTIMEWIDGET_H
22 #define ALARMTIMEWIDGET_H
23 
24 #include "buttongroup.h"
25 #include "datetime.h"
26 
27 class RadioButton;
28 class CheckBox;
29 class DateEdit;
30 class TimeEdit;
31 class TimeSpinBox;
32 
33 
34 class AlarmTimeWidget : public ButtonGroup
35 {
36  TQ_OBJECT
37 
38  public:
39  enum { // 'mode' values for constructor. May be OR'ed together.
40  AT_TIME = 0x00, // "At ..."
41  DEFER_TIME = 0x01, // "Defer to ..."
42  NARROW = 0x02 // make a narrow widget
43  };
44  AlarmTimeWidget(const TQString& groupBoxTitle, int mode, TQWidget* parent = 0, const char* name = 0);
45  AlarmTimeWidget(int mode, TQWidget* parent = 0, const char* name = 0);
46  DateTime getDateTime(int* minsFromNow = 0, bool checkExpired = true, bool showErrorMessage = true, TQWidget** errorWidget = 0) const;
47  void setDateTime(const DateTime&);
48  void setMinDateTimeIsCurrent();
49  void setMinDateTime(const TQDateTime& = TQDateTime());
50  void setMaxDateTime(const DateTime& = DateTime());
51  const TQDateTime& maxDateTime() const { return mMaxDateTime; }
52  void setReadOnly(bool);
53  bool anyTime() const { return mAnyTime; }
54  void enableAnyTime(bool enable);
55  void selectTimeFromNow(int minutes = 0);
56  TQSize sizeHint() const { return minimumSizeHint(); }
57 
58  static TQString i18n_w_TimeFromNow(); // text of 'Time from now:' radio button, with 'w' shortcut
59  static TQString i18n_TimeAfterPeriod();
60  static const int maxDelayTime; // maximum time from now
61 
62  signals:
63  void anyTimeToggled(bool anyTime);
64  void pastMax();
65 
66  protected slots:
67  void slotTimer();
68  void slotButtonSet(int id);
69  void dateTimeChanged();
70  void delayTimeChanged(int);
71  void slotAnyTimeToggled(bool);
72 
73  private:
74  void init(int mode);
75  void setAnyTime();
76  void setMaxDelayTime(const TQDateTime& now);
77  void setMaxMinTimeIf(const TQDateTime& now);
78 
79  RadioButton* mAtTimeRadio;
80  RadioButton* mAfterTimeRadio;
81  DateEdit* mDateEdit;
82  TimeEdit* mTimeEdit;
83  TimeSpinBox* mDelayTimeEdit;
84  CheckBox* mAnyTimeCheckBox;
85  TQDateTime mMinDateTime; // earliest allowed date/time
86  TQDateTime mMaxDateTime; // latest allowed date/time
87  int mAnyTime; // 0 = date/time is specified, 1 = only a date, -1 = uninitialised
88  bool mAnyTimeAllowed; // 'mAnyTimeCheckBox' is enabled
89  bool mMinDateTimeIsNow; // earliest allowed date/time is the current time
90  bool mPastMax; // current time is past the maximum date/time
91  bool mMinMaxTimeSet; // limits have been set for the time edit control
92  bool mTimerSyncing; // mTimer is not yet synchronised to the minute boundary
93 };
94 
95 #endif // ALARMTIMEWIDGET_H