1/* -*- C++ -*-
2 This file is part of the KDE libraries
3 Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
4 (C) 1998-2001 Mirko Boehm (mirko@kde.org)
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20#ifndef KPTDATEPICKER_H
21#define KPTDATEPICKER_H
22
23#include "../kplatomodels_export.h"
24
25#include "kdatetable.h"
26
27#include <QDateTime>
28#include <QFrame>
29
30class QLineEdit;
31class QToolButton;
32
33namespace KPlato
34{
35
36class KDateValidator;
37class KDateTable;
38
39/**
40 * @short A date selection widget.
41 *
42 * Provides a widget for calendar date input.
43 *
44 * Different from the
45 * previous versions, it now emits two types of signals, either
46 * dateSelected() or dateEntered() (see documentation for both
47 * signals).
48 *
49 * A line edit has been added in the newer versions to allow the user
50 * to select a date directly by entering numbers like 19990101
51 * or 990101.
52 *
53 * \image html kdatepicker.png "KDE Date Widget"
54 *
55 * @author Tim Gilman, Mirko Boehm
56 *
57 **/
58class KPLATOMODELS_EXPORT KDatePicker: public QFrame
59{
60 Q_OBJECT
61 Q_PROPERTY( QDate date READ date WRITE setDate USER true )
62 Q_PROPERTY( bool closeButton READ hasCloseButton WRITE setCloseButton )
63 Q_PROPERTY( int fontSize READ fontSize WRITE setFontSize )
64
65public:
66 /**
67 * The constructor. The current date will be displayed initially.
68 **/
69 explicit KDatePicker(QWidget* parent = 0);
70
71 /**
72 * The constructor. The given date will be displayed initially.
73 **/
74 explicit KDatePicker(const QDate& dt, QWidget* parent = 0);
75
76 /**
77 * The destructor.
78 **/
79 virtual ~KDatePicker();
80
81 /** The size hint for date pickers. The size hint recommends the
82 * minimum size of the widget so that all elements may be placed
83 * without clipping. This sometimes looks ugly, so when using the
84 * size hint, try adding 28 to each of the reported numbers of
85 * pixels.
86 **/
87 QSize sizeHint() const;
88
89 /**
90 * Sets the date.
91 *
92 * @returns @p false and does not change anything
93 * if the date given is invalid.
94 **/
95 bool setDate(const QDate&);
96
97 /**
98 * @returns the selected date.
99 */
100 const QDate &date() const;
101
102 /**
103 * Enables or disables the widget.
104 **/
105 void setEnabled(bool);
106
107 /**
108 * @returns the KDateTable widget child of this KDatePicker
109 * widget.
110 */
111 KDateTable *dateTable() const;
112
113 /**
114 * Sets the font size of the widgets elements.
115 **/
116 void setFontSize(int);
117
118 /**
119 * Returns the font size of the widget elements.
120 */
121 int fontSize() const;
122
123 /**
124 * By calling this method with @p enable = true, KDatePicker will show
125 * a little close-button in the upper button-row. Clicking the
126 * close-button will cause the KDatePicker's topLevelWidget()'s close()
127 * method being called. This is mostly useful for toplevel datepickers
128 * without a window manager decoration.
129 * @see hasCloseButton
130 */
131 void setCloseButton( bool enable );
132
133 /**
134 * @returns true if a KDatePicker shows a close-button.
135 * @see setCloseButton
136 */
137 bool hasCloseButton() const;
138
139protected:
140 /// to catch move keyEvents when QLineEdit has keyFocus
141 virtual bool eventFilter(QObject *o, QEvent *e );
142 /// the resize event
143 virtual void resizeEvent(QResizeEvent*);
144 virtual void paintEvent(QPaintEvent *e);
145 void drawFrame(QPainter *p);
146
147protected Q_SLOTS:
148 void dateChangedSlot(const QDate&);
149 void tableClickedSlot();
150 void monthForwardClicked();
151 void monthBackwardClicked();
152 void yearForwardClicked();
153 void yearBackwardClicked();
154 void selectMonthClicked();
155 void selectYearClicked();
156 void lineEnterPressed();
157 void todayButtonClicked();
158 void weekSelected(int);
159
160Q_SIGNALS:
161 /** This signal is emitted each time the selected date is changed.
162 * Usually, this does not mean that the date has been entered,
163 * since the date also changes, for example, when another month is
164 * selected.
165 * @see dateSelected
166 */
167 void dateChanged( const QDate&);
168 /** This signal is emitted each time a day has been selected by
169 * clicking on the table (hitting a day in the current month). It
170 * has the same meaning as dateSelected() in older versions of
171 * KDatePicker.
172 */
173 void dateSelected( const QDate&);
174 /** This signal is emitted when enter is pressed and a VALID date
175 * has been entered before into the line edit. Connect to both
176 * dateEntered() and dateSelected() to receive all events where the
177 * user really enters a date.
178 */
179 void dateEntered( const QDate &);
180 /** This signal is emitted when the day has been selected by
181 * clicking on it in the table.
182 */
183 void tableClicked();
184
185private:
186 void init( const QDate &dt );
187 void fillWeeksCombo(const QDate &date);
188 class KDatePickerPrivate;
189 KDatePickerPrivate *const d;
190};
191
192} //namespace KPlato
193
194#endif // KDATEPICKER_H
195