1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* timespinbox.h - time spinbox widget
* Program: kalarm
* Copyright © 2001-2008 by David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef TIMESPINBOX_H
#define TIMESPINBOX_H
#include <tqdatetime.h>
#include "spinbox2.h"
/**
* @short Hours/minutes time entry widget.
*
* The TimeSpinBox class provides a widget to enter a time consisting of an hours/minutes
* value. It can hold a time in any of 3 modes: a time of day using the 24-hour clock; a
* time of day using the 12-hour clock; or a length of time not restricted to 24 hours.
*
* Derived from SpinBox2, it displays a spin box with two pairs of spin buttons, one
* for hours and one for minutes. It provides accelerated stepping using the spin
* buttons, when the shift key is held down (inherited from SpinBox2). The default
* shift steps are 5 minutes and 6 hours.
*
* The widget may be set as read-only. This has the same effect as disabling it, except
* that its appearance is unchanged.
*
* @author David Jarvie <software@astrojar.org.uk>
*/
class TimeSpinBox : public SpinBox2
{
Q_OBJECT
TQ_OBJECT
public:
/** Constructor for a wrapping time spin box which can be used to enter a time of day.
* @param use24hour True for entry of 24-hour clock times (range 00:00 to 23:59).
* False for entry of 12-hour clock times (range 12:00 to 11:59).
* @param parent The parent object of this widget.
* @param name The name of this widget.
*/
explicit TimeSpinBox(bool use24hour, TQWidget* parent = 0, const char* name = 0);
/** Constructor for a non-wrapping time spin box which can be used to enter a length of time.
* @param minMinute The minimum value which the spin box can hold, in minutes.
* @param maxMinute The maximum value which the spin box can hold, in minutes.
* @param parent The parent object of this widget.
* @param name The name of this widget.
*/
TimeSpinBox(int minMinute, int maxMinute, TQWidget* parent = 0, const char* name = 0);
/** Returns true if the spin box holds a valid value.
* An invalid value is displayed as asterisks.
*/
bool isValid() const;
/** Sets the spin box as holding a valid or invalid value.
* If newly invalid, the value is displayed as asterisks.
* If newly valid, the value is set to the minimum value.
*/
void setValid(bool);
/** Returns the current value held in the spin box.
* If an invalid value is displayed, returns a value lower than the minimum value.
*/
TQTime time() const;
/** Sets the maximum value which can be held in the spin box.
* @param minutes The maximum value expressed in minutes.
*/
virtual void setMinValue(int minutes);
/** Sets the maximum value which can be held in the spin box.
* @param minutes The maximum value expressed in minutes.
*/
virtual void setMaxValue(int minutes) { SpinBox2::setMaxValue(minutes); }
/** Sets the maximum value which can be held in the spin box. */
void setMaxValue(const TQTime& t) { SpinBox2::setMaxValue(t.hour()*60 + t.minute()); }
/** Returns the maximum value which can be held in the spin box. */
TQTime maxTime() const { int mv = maxValue(); return TQTime(mv/60, mv%60); }
/** Returns a text describing use of the shift key as an accelerator for
* the spin buttons, designed for incorporation into WhatsThis texts.
*/
static TQString shiftWhatsThis();
virtual TQSize tqsizeHint() const;
virtual TQSize tqminimumSizeHint() const;
public slots:
/** Sets the value of the spin box.
* @param minutes The new value of the spin box, expressed in minutes.
*/
virtual void setValue(int minutes);
/** Sets the value of the spin box. */
void setValue(const TQTime& t) { setValue(t.hour()*60 + t.minute()); }
/** Increments the spin box value.
* If the value was previously invalid, the spin box is set to the minimum value.
*/
virtual void stepUp();
/** Decrements the spin box value.
* If the value was previously invalid, the spin box is set to the minimum value.
*/
virtual void stepDown();
protected:
virtual TQString mapValueToText(int v);
virtual int mapTextToValue(bool* ok);
private slots:
void slotValueChanged(int value);
private:
class TimeValidator;
TimeValidator* mValidator;
int mMinimumValue; // real minimum value, excluding special value for "**:**"
bool m12Hour; // use 12-hour clock
bool mPm; // use PM for manually entered values (with 12-hour clock)
bool mInvalid; // value is currently invalid (asterisks)
bool mEnteredSetValue; // to prevent infinite recursion in setValue()
};
#endif // TIMESPINBOX_H
|