00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KPTDATETABEL_H
00023 #define KPTDATETABEL_H
00024
00025 #include "kptmap.h"
00026
00027 #include <kglobal.h>
00028 #include <klocale.h>
00029
00030 #include <q3gridview.h>
00031 #include <q3memarray.h>
00032 #include <q3dict.h>
00033 #include <qpair.h>
00034
00035 #include <qvalidator.h>
00036 #include <QLineEdit>
00037 #include <qdatetime.h>
00038
00039 #include <QWheelEvent>
00040 #include <QFocusEvent>
00041 #include <QKeyEvent>
00042 #include <Q3Frame>
00043 #include <QResizeEvent>
00044 #include <QMouseEvent>
00045
00046 namespace KPlato
00047 {
00048
00054 class DateInternalWeekSelector : public QLineEdit
00055 {
00056 Q_OBJECT
00057 protected:
00058 QIntValidator *val;
00059 int result;
00060 public slots:
00061 void weekEnteredSlot();
00062 signals:
00063 void closeMe(int);
00064 public:
00065 DateInternalWeekSelector(int fontsize,
00066 QWidget* parent=0,
00067 const char* name=0);
00068 int getWeek() const;
00069 void setWeek(int week);
00070
00071 private:
00072 class DateInternalWeekPrivate;
00073 DateInternalWeekPrivate *d;
00074 };
00075
00082 class DateInternalMonthPicker : public Q3GridView
00083 {
00084 Q_OBJECT
00085 protected:
00089 int result;
00093 short int activeCol;
00094 short int activeRow;
00098 QRect max;
00099 signals:
00103 void closeMe(int);
00104 public:
00108 DateInternalMonthPicker(int fontsize, QWidget* parent, const char* name=0);
00112 QSize sizeHint() const;
00116 QSize minimumSizeHint() const { return sizeHint(); }
00121 int getResult() const;
00122 protected:
00126 void setupPainter(QPainter *p);
00130 virtual void viewportResizeEvent(QResizeEvent*);
00134 virtual void paintCell(QPainter* painter, int row, int col);
00138 virtual void contentsMousePressEvent(QMouseEvent *e);
00139 virtual void contentsMouseMoveEvent(QMouseEvent *e);
00143 virtual void contentsMouseReleaseEvent(QMouseEvent *e);
00144
00145 private:
00146 class DateInternalMonthPrivate;
00147 DateInternalMonthPrivate *d;
00148 };
00149
00155 class DateInternalYearSelector : public QLineEdit
00156 {
00157 Q_OBJECT
00158 protected:
00159 QIntValidator *val;
00160 int result;
00161 public slots:
00162 void yearEnteredSlot();
00163 signals:
00164 void closeMe(int);
00165 public:
00166 DateInternalYearSelector(int fontsize,
00167 QWidget* parent=0,
00168 const char* name=0);
00169 int getYear() const;
00170 void setYear(int year);
00171
00172 private:
00173 class DateInternalYearPrivate;
00174 DateInternalYearPrivate *d;
00175 };
00176
00182 class PopupFrame : public Q3Frame
00183 {
00184 Q_OBJECT
00185 protected:
00189 int result;
00193 virtual void keyPressEvent(QKeyEvent* e);
00197 QWidget *main;
00198 public slots:
00203 void close(int r);
00204 public:
00208 PopupFrame(QWidget* parent=0, const char* name=0);
00216 void setMainWidget(QWidget* m);
00221 virtual void resizeEvent(QResizeEvent*);
00225 void popup(const QPoint &pos);
00229 int exec(QPoint p);
00233 int exec(int x, int y);
00234
00235 private:
00236
00237 virtual bool close(bool alsoDelete) { return Q3Frame::close(alsoDelete); }
00238 protected:
00239 virtual void virtual_hook( int id, void* data );
00240 private:
00241 class PopupFramePrivate;
00242 PopupFramePrivate *d;
00243 };
00244
00248 class DateValidator : public QValidator
00249 {
00250 public:
00251 DateValidator(QWidget* parent=0, const char* name=0);
00252 virtual State validate(QString&, int&) const;
00253 virtual void fixup ( QString & input ) const;
00254 State date(const QString&, QDate&) const;
00255 };
00256
00257
00258 class DateTable : public Q3GridView
00259 {
00260 Q_OBJECT
00261 public:
00265 DateTable(QWidget *parent=0, QDate date=QDate::currentDate(),
00266 const char* name="DateTable", Qt::WFlags f=0);
00267
00275 virtual QSize sizeHint() const;
00279 void setFontSize(int size);
00283 bool setDate(const QDate&, bool repaint=true);
00284 const QDate& getDate() const;
00285 bool selectDate(const QDate& date_);
00286
00287 void addMarkedDate(QDate date, int state) { m_markedDates.insert(date, state); }
00288 bool dateMarked(QDate date);
00289
00290 void addMarkedWeekday(int day, int state);
00291 void setMarkedWeekday(int day, int state) { m_markedWeekdays.insert(day, state); }
00292 void setMarkedWeekdays(const IntMap days);
00293 bool weekdayMarked(int day);
00294
00295 DateMap selectedDates() const { return m_selectedDates; }
00296 IntMap selectedWeekdays() const { return m_selectedWeekdays; }
00297
00298 DateMap markedDates() const { return m_markedDates; }
00299 IntMap markedWeekdays() const { return m_markedWeekdays; }
00300
00301 void clear();
00302 void clearSelection();
00303
00304 void setEnabled(bool yes);
00305 bool isEnabled() const { return m_enabled; }
00306
00307 void markSelected(int state);
00308
00309 protected:
00313 virtual void paintCell(QPainter*, int, int);
00317 virtual void viewportResizeEvent(QResizeEvent *);
00321 virtual void contentsMousePressEvent(QMouseEvent *);
00322 virtual void wheelEvent( QWheelEvent * e );
00323 virtual void keyPressEvent( QKeyEvent *e );
00324 virtual void focusInEvent( QFocusEvent *e );
00325 virtual void focusOutEvent( QFocusEvent *e );
00326
00327 bool contentsMousePressEvent_internal(QMouseEvent *);
00328
00329 int weekOfYear(QDate date) const;
00330 void setWeekNumbers(QDate);
00331
00332 bool weekSelected(int row);
00333 bool weekSelected();
00334 bool weekdaySelected();
00335 bool isWeekdaySelected(int day);
00336 bool dateSelected(QDate date);
00337 bool dateSelected();
00338 void updateSelectedCells();
00339 void updateMarkedCells();
00340 void updateCells();
00341
00342 QDate getDate(int pos) const;
00343
00348 int position(int row, int col) { return ((7 * (row - 1)) + col - m_dateStartCol + 1); }
00349
00350 int weekday(int col) const;
00351 int column(int weekday) const;
00352
00353 void paintWeekday(QPainter *painter, int col);
00354 void paintWeekNumber(QPainter *painter, int row);
00355 void paintDay(QPainter *painter, int row, int col);
00356
00360 int fontsize;
00364 QDate date;
00368 int firstday;
00372 int numdays;
00376 int numDaysPrevMonth;
00380 QRect maxCell;
00381
00382 signals:
00386 void dateChanged(QDate);
00390 void tableClicked();
00391
00392 void weekdaySelected(int);
00393 void weekSelected(int, int);
00397 void selectionCleared();
00398
00399 private:
00400
00401 Q3MemArray< QPair<int, int> > m_weeks;
00402
00403 int m_currentRow;
00404
00405
00406
00407 DateMap m_selectedDates;
00408 IntMap m_selectedWeekdays;
00409
00410
00411 DateMap m_markedDates;
00412 IntMap m_markedWeekdays;
00413
00414 int m_dateStartCol;
00415 bool m_enabled;
00416
00417 QColor colorBackgroundHoliday;
00418 QColor colorBackgroundWorkday;
00419 QColor colorTextHoliday;
00420 QColor colorTextWorkday;
00421 QColor colorLine;
00422 QColor backgroundSelectColor;
00423 QColor penSelectColor;
00424
00425 protected:
00426 virtual void virtual_hook( int id, void* data );
00427 private:
00428 class DateTablePrivate;
00429 DateTablePrivate *d;
00430 };
00431
00432 }
00433
00434 #endif // DATETABEL_H