moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / libkdeedu / extdate / extdatetbl.h
blob3829f041a0ebc2512bb7b982cf9316e8060449ce
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 (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.
26 #ifndef EXTDATETBL_H
27 #define EXTDATETBL_H
29 #include <qvalidator.h>
30 #include <qgridview.h>
31 #include <klineedit.h>
32 #include "extcalendarsystemgregorian.h"
34 class KPopupMenu;
36 /** Week selection widget.
37 * @internal
38 * @version $Id$
39 * @author Stephan Binner
41 class ExtDateInternalWeekSelector : public KLineEdit
43 Q_OBJECT
44 protected:
45 QIntValidator *val;
46 int result;
47 public slots:
48 void weekEnteredSlot();
49 void setMaxWeek(int max);
50 signals:
51 void closeMe(int);
52 public:
53 ExtDateInternalWeekSelector( QWidget* parent=0, const char* name=0);
54 int getWeek();
55 void setWeek(int week);
57 private:
58 class ExtDateInternalWeekPrivate;
59 ExtDateInternalWeekPrivate *d;
62 /**
63 * A table containing month names. It is used to pick a month directly.
64 * @internal
65 * @version $Id$
66 * @author Tim Gilman, Mirko Boehm
68 class ExtDateInternalMonthPicker : public QGridView
70 Q_OBJECT
71 protected:
72 /**
73 * Store the month that has been clicked [1..12].
75 int result;
76 /**
77 * the cell under mouse cursor when LBM is pressed
79 short int activeCol;
80 short int activeRow;
81 /**
82 * Contains the largest rectangle needed by the month names.
84 QRect max;
85 signals:
86 /**
87 * This is send from the mouse click event handler.
89 void closeMe(int);
90 public:
91 /**
92 * The constructor.
94 ExtDateInternalMonthPicker(const ExtDate& date, QWidget* parent, const char* name=0);
95 /**
96 * The destructor.
98 ~ExtDateInternalMonthPicker();
99 /**
100 * The size hint.
102 QSize sizeHint() const;
104 * Return the result. 0 means no selection (reject()), 1..12 are the
105 * months.
107 int getResult() const;
108 protected:
110 * Set up the painter.
112 void setupPainter(QPainter *p);
114 * The resize event.
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);
131 private:
132 class ExtDateInternalMonthPrivate;
133 ExtDateInternalMonthPrivate *d;
136 /** Year selection widget.
137 * @internal
138 * @version $Id$
139 * @author Tim Gilman, Mirko Boehm
141 class ExtDateInternalYearSelector : public QLineEdit
143 Q_OBJECT
144 protected:
145 QIntValidator *val;
146 int result;
147 public slots:
148 void yearEnteredSlot();
149 signals:
150 void closeMe(int);
151 public:
152 ExtDateInternalYearSelector( QWidget* parent=0, const char* name=0);
153 ~ExtDateInternalYearSelector();
154 int getYear();
155 void setYear(int year);
157 private:
158 class ExtDateInternalYearPrivate {
159 public:
160 ExtDateInternalYearPrivate() {
161 calendar = new ExtCalendarSystemGregorian();
163 ~ExtDateInternalYearPrivate() {
164 delete calendar;
166 ExtCalendarSystem *calendar;
168 ExtDateInternalYearPrivate *d;
173 * Frame with popup menu behavior.
174 * @author Tim Gilman, Mirko Boehm
175 * @version $Id$
177 class KPopupFrame : public QFrame
179 Q_OBJECT
180 protected:
182 * The result. It is returned from exec() when the popup window closes.
184 int result;
186 * Catch key press events.
188 virtual void keyPressEvent(QKeyEvent* e);
190 * The only subwidget that uses the whole dialog window.
192 QWidget *main;
193 public slots:
195 * Close the popup window. This is called from the main widget, usually.
196 * @p r is the result returned from exec().
198 void close(int r);
199 public:
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
209 * widget.
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.
224 int exec(QPoint p);
226 * Dito.
228 int exec(int x, int y);
230 private:
232 virtual bool close(bool alsoDelete) { return QFrame::close(alsoDelete); }
233 protected:
234 virtual void virtual_hook( int id, void* data );
235 private:
236 class KPopupFramePrivate;
237 KPopupFramePrivate *d;
241 * Validates user-entered dates.
243 class ExtDateValidator : public QValidator
245 public:
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)
261 * @internal
262 * @version $Id$
263 * @author Tim Gilman, Mirko Boehm
265 class ExtDateTable : public QGridView
267 Q_OBJECT
268 //Q_PROPERTY( ExtDate date READ getDate WRITE setDate )
269 Q_PROPERTY( bool popupMenu READ popupMenuEnabled WRITE setPopupMenuEnabled )
271 public:
273 * The constructor.
275 ExtDateTable(QWidget *parent=0,
276 ExtDate date=ExtDate::currentDate(),
277 const char* name=0, WFlags f=0);
280 * The destructor.
282 ~ExtDateTable();
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.
309 * @since 3.2
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.
324 * @since 3.2
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.
331 * @since 3.2
333 void unsetCustomDatePainting( const ExtDate &date );
335 protected:
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
347 * Paint a cell.
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.
368 int fontsize;
370 * The currently selected date.
372 ExtDate date;
374 * The day of the first day in the month [1..7].
376 int firstday;
378 * The number of days in the current month.
380 int numdays;
382 * The number of days in the previous month.
384 int numDaysPrevMonth;
386 * unused
387 * ### remove in KDE 4.0
389 bool unused_hasSelection;
391 * Save the size of the largest used cell content.
393 QRect maxCell;
394 signals:
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.
409 void tableClicked();
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.
416 * @since 3.2
418 void aboutToShowContextMenu( KPopupMenu * menu, const ExtDate &date);
420 protected:
421 virtual void virtual_hook( int id, void* data );
422 private:
423 class ExtDateTablePrivate;
424 ExtDateTablePrivate *d;
427 #endif // EXTDATETBL_H