kplato

kptdatetable.h
1/* This file is part of the KDE project
2 Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
3 (C) 1998-2001 Mirko Boehm (mirko@kde.org)
4 (C) 2004-2006 Dag Andersen <danders@get2net.dk>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#ifndef KPTDATETABEL_H
23#define KPTDATETABEL_H
24
25#include "kptmap.h"
26
27#include <tdeglobal.h>
28#include <tdelocale.h>
29
30#include <tqgridview.h>
31#include <tqmemarray.h>
32#include <tqdict.h>
33#include <tqpair.h>
34
35#include <tqvalidator.h>
36#include <tqlineedit.h>
37#include <tqdatetime.h>
38
39namespace KPlato
40{
41
47class DateInternalWeekSelector : public TQLineEdit
48{
49 TQ_OBJECT
50
51protected:
52 TQIntValidator *val;
53 int result;
54public slots:
55 void weekEnteredSlot();
56signals:
57 void closeMe(int);
58public:
59 DateInternalWeekSelector(int fontsize,
60 TQWidget* parent=0,
61 const char* name=0);
62 int getWeek() const;
63 void setWeek(int week);
64
65private:
66 class DateInternalWeekPrivate;
67 DateInternalWeekPrivate *d;
68};
69
76class DateInternalMonthPicker : public TQGridView
77{
78 TQ_OBJECT
79
80protected:
84 int result;
88 short int activeCol;
89 short int activeRow;
93 TQRect max;
94signals:
98 void closeMe(int);
99public:
103 DateInternalMonthPicker(int fontsize, TQWidget* parent, const char* name=0);
107 TQSize sizeHint() const;
111 TQSize minimumSizeHint() const { return sizeHint(); }
116 int getResult() const;
117protected:
121 void setupPainter(TQPainter *p);
125 virtual void viewportResizeEvent(TQResizeEvent*);
129 virtual void paintCell(TQPainter* painter, int row, int col);
133 virtual void contentsMousePressEvent(TQMouseEvent *e);
134 virtual void contentsMouseMoveEvent(TQMouseEvent *e);
138 virtual void contentsMouseReleaseEvent(TQMouseEvent *e);
139
140private:
141 class DateInternalMonthPrivate;
142 DateInternalMonthPrivate *d;
143};
144
150class DateInternalYearSelector : public TQLineEdit
151{
152 TQ_OBJECT
153
154protected:
155 TQIntValidator *val;
156 int result;
157public slots:
158 void yearEnteredSlot();
159signals:
160 void closeMe(int);
161public:
162 DateInternalYearSelector(int fontsize,
163 TQWidget* parent=0,
164 const char* name=0);
165 int getYear() const;
166 void setYear(int year);
167
168private:
169 class DateInternalYearPrivate;
170 DateInternalYearPrivate *d;
171};
172
178class PopupFrame : public TQFrame
179{
180 TQ_OBJECT
181
182protected:
190 virtual void keyPressEvent(TQKeyEvent* e);
194 TQWidget *main;
195public slots:
200 void close(int r);
201public:
205 PopupFrame(TQWidget* parent=0, const char* name=0);
213 void setMainWidget(TQWidget* m);
218 virtual void resizeEvent(TQResizeEvent*);
222 void popup(const TQPoint &pos);
226 int exec(TQPoint p);
230 int exec(int x, int y);
231
232private:
233
234 virtual bool close(bool alsoDelete) { return TQFrame::close(alsoDelete); }
235protected:
236 virtual void virtual_hook( int id, void* data );
237private:
238 class PopupFramePrivate;
239 PopupFramePrivate *d;
240};
241
245class DateValidator : public TQValidator
246{
247public:
248 DateValidator(TQWidget* parent=0, const char* name=0);
249 virtual State validate(TQString&, int&) const;
250 virtual void fixup ( TQString & input ) const;
251 State date(const TQString&, TQDate&) const;
252};
253
254
255class DateTable : public TQGridView
256{
257 TQ_OBJECT
258
259public:
263 DateTable(TQWidget *parent=0, TQDate date=TQDate::currentDate(),
264 const char* name="DateTable", WFlags f=0);
265
273 virtual TQSize sizeHint() const;
277 void setFontSize(int size);
281 bool setDate(const TQDate&, bool repaint=true);
282 const TQDate& getDate() const;
283 bool selectDate(const TQDate& date_);
284
285 void addMarkedDate(TQDate date, int state) { m_markedDates.insert(date, state); }
286 bool dateMarked(TQDate date);
287
288 void addMarkedWeekday(int day, int state);
289 void setMarkedWeekday(int day, int state) { m_markedWeekdays.insert(day, state); }
290 void setMarkedWeekdays(const IntMap days);
291 bool weekdayMarked(int day);
292
293 DateMap selectedDates() const { return m_selectedDates; }
294 IntMap selectedWeekdays() const { return m_selectedWeekdays; }
295
296 DateMap markedDates() const { return m_markedDates; }
297 IntMap markedWeekdays() const { return m_markedWeekdays; }
298
299 void clear();
300 void clearSelection();
301
302 void setEnabled(bool yes);
303 bool isEnabled() const { return m_enabled; }
304
305 void markSelected(int state);
306
307protected:
311 virtual void paintCell(TQPainter*, int, int);
315 virtual void viewportResizeEvent(TQResizeEvent *);
319 virtual void contentsMousePressEvent(TQMouseEvent *);
320 virtual void wheelEvent( TQWheelEvent * e );
321 virtual void keyPressEvent( TQKeyEvent *e );
322 virtual void focusInEvent( TQFocusEvent *e );
323 virtual void focusOutEvent( TQFocusEvent *e );
324
325 bool contentsMousePressEvent_internal(TQMouseEvent *);
326
327 int weekOfYear(TQDate date) const;
328 void setWeekNumbers(TQDate);
329
330 bool weekSelected(int row);
331 bool weekSelected();
332 bool weekdaySelected();
333 bool isWeekdaySelected(int day);
334 bool dateSelected(TQDate date);
335 bool dateSelected();
336 void updateSelectedCells();
337 void updateMarkedCells();
338 void updateCells();
339
340 TQDate getDate(int pos) const;
341
346 int position(int row, int col) { return ((7 * (row - 1)) + col - m_dateStartCol + 1); }
347
348 int weekday(int col) const;
349 int column(int weekday) const;
350
351 void paintWeekday(TQPainter *painter, int col);
352 void paintWeekNumber(TQPainter *painter, int row);
353 void paintDay(TQPainter *painter, int row, int col);
354
358 int fontsize;
362 TQDate date;
366 int firstday;
370 int numdays;
374 int numDaysPrevMonth;
378 TQRect maxCell;
379
380signals:
384 void dateChanged(TQDate);
388 void tableClicked();
389
390 void weekdaySelected(int);
391 void weekSelected(int, int);
395 void selectionCleared();
396
397private:
398
399 TQMemArray< TQPair<int, int> > m_weeks;
400
401 int m_currentRow; // row of selected date
402
403 // User has selected these, results in "select coloring" the dates in datetable
404
405 DateMap m_selectedDates;
406 IntMap m_selectedWeekdays;
407
408 // These results in marking the dates, weekdays and weeks respectivly
409 DateMap m_markedDates;
410 IntMap m_markedWeekdays;
411
412 int m_dateStartCol;
413 bool m_enabled;
414
415 TQColor colorBackgroundHoliday;
416 TQColor colorBackgroundWorkday;
417 TQColor colorTextHoliday;
418 TQColor colorTextWorkday;
419 TQColor colorLine;
420 TQColor backgroundSelectColor;
421 TQColor penSelectColor;
422
423protected:
424 virtual void virtual_hook( int id, void* data );
425private:
426 class DateTablePrivate;
427 DateTablePrivate *d;
428};
429
430} //KPlato namespace
431
432#endif // DATETABEL_H
A table containing month names.
TQSize sizeHint() const
The size hint.
virtual void contentsMouseReleaseEvent(TQMouseEvent *e)
Emit monthSelected(int) when a cell has been released.
void closeMe(int)
This is send from the mouse click event handler.
int result
Store the month that has been clicked [1..12].
TQRect max
Contains the largest rectangle needed by the month names.
int getResult() const
Return the result.
virtual void contentsMousePressEvent(TQMouseEvent *e)
Catch mouse click and move events to paint a rectangle around the item.
virtual void viewportResizeEvent(TQResizeEvent *)
The resize event.
void setupPainter(TQPainter *p)
Set up the painter.
TQSize minimumSizeHint() const
The minimum size hint.
virtual void paintCell(TQPainter *painter, int row, int col)
Paint a cell.
short int activeCol
the cell under mouse cursor when LBM is pressed
Week selection widget.
Validates user-entered dates.
Frame with popup menu behaviour.
TQWidget * main
The only subwidget that uses the whole dialog window.
void close(int r)
Close the popup window.
int result
The result.
int exec(TQPoint p)
Execute the popup window.
void setMainWidget(TQWidget *m)
Set the main widget.
void popup(const TQPoint &pos)
Open the popup window at position pos.
virtual void resizeEvent(TQResizeEvent *)
The resize event.
virtual void keyPressEvent(TQKeyEvent *e)
Catch key press events.