kalarm

repetition.h
1 /*
2  * repetition.h - pushbutton and dialogue to specify alarm repetition
3  * Program: kalarm
4  * Copyright © 2004,2007 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 REPETITION_H
22 #define REPETITION_H
23 
24 #include <tqpushbutton.h>
25 #include <kdialogbase.h>
26 
27 class ButtonGroup;
28 class RadioButton;
29 class SpinBox;
30 class TimeSelector;
31 class TimePeriod;
32 class RepetitionDlg;
33 
34 
35 class RepetitionButton : public TQPushButton
36 {
37  TQ_OBJECT
38 
39  public:
40  RepetitionButton(const TQString& caption, bool waitForInitialisation, TQWidget* parent, const char* name = 0);
41  void set(int interval, int count);
42  void set(int interval, int count, bool dateOnly, int maxDuration = -1);
43  void initialise(int interval, int count, bool dateOnly, int maxDuration = -1); // use only after needsInitialisation() signal
44  void activate() { activate(false); }
45  int interval() const { return mInterval; }
46  int count() const { return mCount; }
47  virtual void setReadOnly(bool ro) { mReadOnly = ro; }
48  virtual bool isReadOnly() const { return mReadOnly; }
49 
50  signals:
51  void needsInitialisation(); // dialog has been created and needs set() to be called
52  void changed(); // the repetition dialog has been edited
53 
54  private slots:
55  void slotPressed() { activate(mWaitForInit); }
56 
57  private:
58  void activate(bool waitForInitialisation);
59  void displayDialog();
60 
61  RepetitionDlg* mDialog;
62  int mInterval; // interval between repetitions, in minutes
63  int mCount; // total number of repetitions, including first occurrence
64  int mMaxDuration; // maximum allowed duration in minutes, or -1 for infinite
65  bool mDateOnly; // hours/minutes cannot be displayed
66  bool mWaitForInit; // emit needsInitialisation() when button pressed, display when initialise() called
67  bool mReadOnly;
68 };
69 
70 
71 class RepetitionDlg : public KDialogBase
72 {
73  TQ_OBJECT
74 
75  public:
76  RepetitionDlg(const TQString& caption, bool readOnly, TQWidget* parent = 0, const char* name = 0);
77  void setReadOnly(bool);
78  void set(int interval, int count, bool dateOnly = false, int maxDuration = -1);
79  int interval() const; // get the interval between repetitions, in minutes
80  int count() const; // get the repeat count
81 
82  private slots:
83  void typeClicked();
84  void intervalChanged(int);
85  void countChanged(int);
86  void durationChanged(int);
87  void repetitionToggled(bool);
88 
89  private:
90  TimeSelector* mTimeSelector;
91  ButtonGroup* mButtonGroup;
92  RadioButton* mCountButton;
93  SpinBox* mCount;
94  RadioButton* mDurationButton;
95  TimePeriod* mDuration;
96  int mMaxDuration; // maximum allowed duration in minutes, or -1 for infinite
97  bool mDateOnly; // hours/minutes cannot be displayed
98  bool mReadOnly; // the widget is read only
99 };
100 
101 #endif // REPETITION_H