kalarm/lib

timespinbox.h
1 /*
2  * timespinbox.h - time spinbox widget
3  * Program: kalarm
4  * Copyright © 2001-2008 by David Jarvie <djarvie@kde.org>
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 TIMESPINBOX_H
22 #define TIMESPINBOX_H
23 
24 #include <tqdatetime.h>
25 #include "spinbox2.h"
26 
27 
45 class TimeSpinBox : public SpinBox2
46 {
47  TQ_OBJECT
48 
49  public:
56  explicit TimeSpinBox(bool use24hour, TQWidget* parent = 0, const char* name = 0);
63  TimeSpinBox(int minMinute, int maxMinute, TQWidget* parent = 0, const char* name = 0);
67  bool isValid() const;
72  void setValid(bool);
76  TQTime time() const;
80  virtual void setMinValue(int minutes);
84  virtual void setMaxValue(int minutes) { SpinBox2::setMaxValue(minutes); }
86  void setMaxValue(const TQTime& t) { SpinBox2::setMaxValue(t.hour()*60 + t.minute()); }
88  TQTime maxTime() const { int mv = maxValue(); return TQTime(mv/60, mv%60); }
92  static TQString shiftWhatsThis();
93 
94  virtual TQSize sizeHint() const;
95  virtual TQSize minimumSizeHint() const;
96 
97  public slots:
101  virtual void setValue(int minutes);
103  void setValue(const TQTime& t) { setValue(t.hour()*60 + t.minute()); }
107  virtual void stepUp();
111  virtual void stepDown();
112 
113  protected:
114  virtual TQString mapValueToText(int v);
115  virtual int mapTextToValue(bool* ok);
116  private slots:
117  void slotValueChanged(int value);
118  private:
119  class TimeValidator;
120  TimeValidator* mValidator;
121  int mMinimumValue; // real minimum value, excluding special value for "**:**"
122  bool m12Hour; // use 12-hour clock
123  bool mPm; // use PM for manually entered values (with 12-hour clock)
124  bool mInvalid; // value is currently invalid (asterisks)
125  bool mEnteredSetValue; // to prevent infinite recursion in setValue()
126 };
127 
128 #endif // TIMESPINBOX_H
Spin box with a pair of spin buttons on either side.
Definition: spinbox2.h:57
int maxValue() const
Returns the maximum value of the spin box.
Definition: spinbox2.h:140
virtual void setMaxValue(int val)
Sets the maximum value of the spin box.
Definition: spinbox2.cpp:202
int value() const
Returns the current value of the spin box.
Definition: spinbox2.h:148
Hours/minutes time entry widget.
Definition: timespinbox.h:46
virtual void stepUp()
Increments the spin box value.
static TQString shiftWhatsThis()
Returns a text describing use of the shift key as an accelerator for the spin buttons,...
Definition: timespinbox.cpp:94
virtual void setMinValue(int minutes)
Sets the maximum value which can be held in the spin box.
virtual void setValue(int minutes)
Sets the value of the spin box.
void setValue(const TQTime &t)
Sets the value of the spin box.
Definition: timespinbox.h:103
TQTime time() const
Returns the current value held in the spin box.
Definition: timespinbox.cpp:99
bool isValid() const
Returns true if the spin box holds a valid value.
void setMaxValue(const TQTime &t)
Sets the maximum value which can be held in the spin box.
Definition: timespinbox.h:86
TQTime maxTime() const
Returns the maximum value which can be held in the spin box.
Definition: timespinbox.h:88
virtual void stepDown()
Decrements the spin box value.
void setValid(bool)
Sets the spin box as holding a valid or invalid value.
virtual void setMaxValue(int minutes)
Sets the maximum value which can be held in the spin box.
Definition: timespinbox.h:84
TimeSpinBox(bool use24hour, TQWidget *parent=0, const char *name=0)
Constructor for a wrapping time spin box which can be used to enter a time of day.
Definition: timespinbox.cpp:57