summaryrefslogtreecommitdiffstats
path: root/kalarm/lib/dateedit.h
blob: 405566ec73927860c9bb3830d09a0785ccdc00d3 (plain)
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
/*
 *  dateedit.h  -  date entry widget
 *  Program:  kalarm
 *  Copyright © 2002-2007 by David Jarvie <[email protected]>
 *
 *  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 DATEEDIT_H
#define DATEEDIT_H

#include <libtdepim/kdateedit.h>

/**
 *  @short Date edit widget with range limits.
 *
 *  The DateEdit class provides a date editor with the ability to set limits on the
 *  dates which can be entered.
 *
 *  Minimum and/or maximum permissible dates may be set, together with corresponding
 *  error messages. If the user tries to enter a date outside the allowed range, the
 *  appropriate error message (if any) is output using KMessageBox::sorry().
 *
 *  @author David Jarvie <[email protected]>
 */
class DateEdit : public KDateEdit
{
		Q_OBJECT
  
	public:
		/** Constructor.
		 *  @param parent The parent object of this widget.
		 *  @param name The name of this widget.
		 */
		explicit DateEdit(TQWidget* parent = 0, const char* name = 0);
		/** Returns true if the widget contains a valid date. */
		bool         isValid() const              { return date().isValid(); }
		/** Returns the earliest date which can be entered.
		 *  If there is no minimum date, returns an invalid date.
		 */
		const TQDate& minDate() const              { return mMinDate; }
		/** Returns the latest date which can be entered.
		 *  If there is no maximum date, returns an invalid date.
		 */
		const TQDate& maxDate() const              { return mMaxDate; }
		/** Sets the earliest date which can be entered.
		 *  @param date Earliest date allowed. If invalid, any minimum limit is removed.
		 *  @param errorDate Error message to be displayed when a date earlier than
		 *         @p date is entered. Set to TQString() to use the default error message.
		 */
		void         setMinDate(const TQDate& date, const TQString& errorDate = TQString());
		/** Sets the latest date which can be entered.
		 *  @param date Latest date allowed. If invalid, any maximum limit is removed.
		 *  @param errorDate Error message to be displayed when a date later than
		 *         @p date is entered. Set to TQString() to use the default error message.
		 */
		void         setMaxDate(const TQDate& date, const TQString& errorDate = TQString());
		/** Sets the date held in the widget to an invalid date. */
		void         setInvalid();

	protected:
		virtual void mousePressEvent(TQMouseEvent*);
		virtual void mouseReleaseEvent(TQMouseEvent*);
		virtual void mouseMoveEvent(TQMouseEvent*);
		virtual void keyPressEvent(TQKeyEvent*);
		virtual void keyReleaseEvent(TQKeyEvent*);

	private slots:
		void         newDateEntered(const TQDate&);

	private:
		void         pastLimitMessage(const TQDate& limit, const TQString& error, const TQString& defaultError);

		TQDate        mMinDate;             // minimum allowed date, or invalid for no minimum
		TQDate        mMaxDate;             // maximum allowed date, or invalid for no maximum
		TQString      mMinDateErrString;    // error message when entered date < mMinDate
		TQString      mMaxDateErrString;    // error message when entered date > mMaxDate
};

#endif // DATEEDIT_H