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 (C) 2004 Jason Harris (jharris@30doradus.org)
7 These classes has been derived from those in kdatetbl.[h|cpp].
8 The only differences are adaptations to use ExtDate instead of QDate,
9 to allow for more remote dates. These changes by Jason Harris.
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Library General Public
13 License as published by the Free Software Foundation; either
14 version 2 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Library General Public License for more details.
21 You should have received a copy of the GNU Library General Public License
22 along with this library; see the file COPYING.LIB. If not, write to
23 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA.
29 #include <qvalidator.h>
30 #include <qgridview.h>
31 #include <klineedit.h>
32 #include "extcalendarsystemgregorian.h"
36 /** Week selection widget.
39 * @author Stephan Binner
41 class ExtDateInternalWeekSelector
: public KLineEdit
48 void weekEnteredSlot();
49 void setMaxWeek(int max
);
53 ExtDateInternalWeekSelector( QWidget
* parent
=0, const char* name
=0);
55 void setWeek(int week
);
58 class ExtDateInternalWeekPrivate
;
59 ExtDateInternalWeekPrivate
*d
;
63 * A table containing month names. It is used to pick a month directly.
66 * @author Tim Gilman, Mirko Boehm
68 class ExtDateInternalMonthPicker
: public QGridView
73 * Store the month that has been clicked [1..12].
77 * the cell under mouse cursor when LBM is pressed
82 * Contains the largest rectangle needed by the month names.
87 * This is send from the mouse click event handler.
94 ExtDateInternalMonthPicker(const ExtDate
& date
, QWidget
* parent
, const char* name
=0);
98 ~ExtDateInternalMonthPicker();
102 QSize
sizeHint() const;
104 * Return the result. 0 means no selection (reject()), 1..12 are the
107 int getResult() const;
110 * Set up the painter.
112 void setupPainter(QPainter
*p
);
116 virtual void viewportResizeEvent(QResizeEvent
*);
118 * Paint a cell. This simply draws the month names in it.
120 virtual void paintCell(QPainter
* painter
, int row
, int col
);
122 * Catch mouse click and move events to paint a rectangle around the item.
124 virtual void contentsMousePressEvent(QMouseEvent
*e
);
125 virtual void contentsMouseMoveEvent(QMouseEvent
*e
);
127 * Emit monthSelected(int) when a cell has been released.
129 virtual void contentsMouseReleaseEvent(QMouseEvent
*e
);
132 class ExtDateInternalMonthPrivate
;
133 ExtDateInternalMonthPrivate
*d
;
136 /** Year selection widget.
139 * @author Tim Gilman, Mirko Boehm
141 class ExtDateInternalYearSelector
: public QLineEdit
148 void yearEnteredSlot();
152 ExtDateInternalYearSelector( QWidget
* parent
=0, const char* name
=0);
153 ~ExtDateInternalYearSelector();
155 void setYear(int year
);
158 class ExtDateInternalYearPrivate
{
160 ExtDateInternalYearPrivate() {
161 calendar
= new ExtCalendarSystemGregorian();
163 ~ExtDateInternalYearPrivate() {
166 ExtCalendarSystem
*calendar
;
168 ExtDateInternalYearPrivate
*d
;
173 * Frame with popup menu behavior.
174 * @author Tim Gilman, Mirko Boehm
177 class KPopupFrame
: public QFrame
182 * The result. It is returned from exec() when the popup window closes.
186 * Catch key press events.
188 virtual void keyPressEvent(QKeyEvent
* e
);
190 * The only subwidget that uses the whole dialog window.
195 * Close the popup window. This is called from the main widget, usually.
196 * @p r is the result returned from exec().
201 * The contructor. Creates a dialog without buttons.
203 KPopupFrame(QWidget
* parent
=0, const char* name
=0);
205 * Set the main widget. You cannot set the main widget from the constructor,
206 * since it must be a child of the frame itselfes.
207 * Be careful: the size is set to the main widgets size. It is up to you to
208 * set the main widgets correct size before setting it as the main
211 void setMainWidget(QWidget
* m
);
213 * The resize event. Simply resizes the main widget to the whole
214 * widgets client size.
216 virtual void resizeEvent(QResizeEvent
*);
218 * Open the popup window at position pos.
220 void popup(const QPoint
&pos
);
222 * Execute the popup window.
228 int exec(int x
, int y
);
232 virtual bool close(bool alsoDelete
) { return QFrame::close(alsoDelete
); }
234 virtual void virtual_hook( int id
, void* data
);
236 class KPopupFramePrivate
;
237 KPopupFramePrivate
*d
;
241 * Validates user-entered dates.
243 class ExtDateValidator
: public QValidator
246 ExtDateValidator(QWidget
* parent
=0, const char* name
=0);
247 virtual State
validate(QString
&, int&) const;
248 virtual void fixup ( QString
& input
) const;
249 State
date(const QString
&, ExtDate
&) const;
253 * Date selection table.
254 * This is a support class for the ExtDatePicker class. It just
255 * draws the calender table without titles, but could theoretically
256 * be used as a standalone.
258 * When a date is selected by the user, it emits a signal:
259 * dateSelected(ExtDate)
263 * @author Tim Gilman, Mirko Boehm
265 class ExtDateTable
: public QGridView
268 //Q_PROPERTY( ExtDate date READ getDate WRITE setDate )
269 Q_PROPERTY( bool popupMenu READ popupMenuEnabled WRITE setPopupMenuEnabled
)
275 ExtDateTable(QWidget
*parent
=0,
276 ExtDate date
=ExtDate::currentDate(),
277 const char* name
=0, WFlags f
=0);
285 * Returns a recommended size for the widget.
286 * To save some time, the size of the largest used cell content is
287 * calculated in each paintCell() call, since all calculations have
288 * to be done there anyway. The size is stored in maxCell. The
289 * sizeHint() simply returns a multiple of maxCell.
291 virtual QSize
sizeHint() const;
293 * Set the font size of the date table.
295 void setFontSize(int size
);
297 * Select and display this date.
299 bool setDate(const ExtDate
&);
300 // ### 4.0 rename to date()
301 const ExtDate
& getDate() const;
304 * Enables a popup menu when right clicking on a date.
306 * When it's enabled, this object emits a aboutToShowContextMenu signal
307 * where you can fill in the menu items.
311 void setPopupMenuEnabled( bool enable
);
314 * Returns if the popup menu is enabled or not
316 bool popupMenuEnabled() const;
318 enum BackgroundMode
{ NoBgMode
=0, RectangleMode
, CircleMode
};
321 * Makes a given date be painted with a given foregroundColor, and background
322 * (a rectangle, or a circle/ellipse) in a given color.
326 void setCustomDatePainting( const ExtDate
&date
, const QColor
&fgColor
, BackgroundMode bgMode
=NoBgMode
, const QColor
&bgColor
=QColor());
329 * Unsets the custom painting of a date so that the date is painted as usual.
333 void unsetCustomDatePainting( const ExtDate
&date
);
337 * calculate the position of the cell in the matrix for the given date. The result is the 0-based index.
339 int posFromDate( const ExtDate
&date
); // KDE4: make this virtual, so subclasses can reimplement this and use a different default for the start of the matrix
341 * calculate the date that is displayed at a given cell in the matrix. pos is the
342 * 0-based index in the matrix. Inverse function to posForDate().
344 ExtDate
dateFromPos( int pos
); // KDE4: make this virtual
349 virtual void paintCell(QPainter
*, int, int);
351 * Handle the resize events.
353 virtual void viewportResizeEvent(QResizeEvent
*);
355 * React on mouse clicks that select a date.
357 virtual void contentsMousePressEvent(QMouseEvent
*);
358 virtual void wheelEvent( QWheelEvent
* e
);
359 virtual void keyPressEvent( QKeyEvent
*e
);
360 virtual void focusInEvent( QFocusEvent
*e
);
361 virtual void focusOutEvent( QFocusEvent
*e
);
363 // ### KDE 4.0 make the following private and mark as members
366 * The font size of the displayed text.
370 * The currently selected date.
374 * The day of the first day in the month [1..7].
378 * The number of days in the current month.
382 * The number of days in the previous month.
384 int numDaysPrevMonth
;
387 * ### remove in KDE 4.0
389 bool unused_hasSelection
;
391 * Save the size of the largest used cell content.
396 * The selected date changed.
398 void dateChanged(const ExtDate
&);
400 * This function behaves essentially like the one above.
401 * The selected date changed.
402 * @param cur The current date
403 * @param old The date before the date was changed
405 void dateChanged(const ExtDate
& cur
, const ExtDate
& old
);
407 * A date has been selected by clicking on the table.
412 * A popup menu for a given date is about to be shown (as when the user
413 * right clicks on that date and the popup menu is enabled). Connect
414 * the slot where you fill the menu to this signal.
418 void aboutToShowContextMenu( KPopupMenu
* menu
, const ExtDate
&date
);
421 virtual void virtual_hook( int id
, void* data
);
423 class ExtDateTablePrivate
;
424 ExtDateTablePrivate
*d
;
427 #endif // EXTDATETBL_H