kplato

kptdatetable.h

00001 /* This file is part of the KDE project
00002     Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
00003               (C) 1998-2001 Mirko Boehm (mirko@kde.org)
00004               (C) 2004 Dag Andersen <danders@get2net.dk>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
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 <qgridview.h>
00031 #include <qmemarray.h>
00032 #include <qdict.h>
00033 #include <qpair.h>
00034 
00035 #include <qvalidator.h>
00036 #include <qlineedit.h>
00037 #include <qdatetime.h>
00038 
00039 namespace KPlato
00040 {
00041 
00047 class DateInternalWeekSelector : public QLineEdit
00048 {
00049   Q_OBJECT
00050 protected:
00051   QIntValidator *val;
00052   int result;
00053 public slots:
00054   void weekEnteredSlot();
00055 signals:
00056   void closeMe(int);
00057 public:
00058   DateInternalWeekSelector(int fontsize,
00059                 QWidget* parent=0,
00060                 const char* name=0);
00061   int getWeek() const;
00062   void setWeek(int week);
00063 
00064 private:
00065   class DateInternalWeekPrivate;
00066   DateInternalWeekPrivate *d;
00067 };
00068 
00075 class DateInternalMonthPicker : public QGridView
00076 {
00077   Q_OBJECT
00078 protected:
00082   int result;
00086   short int activeCol;
00087   short int activeRow;
00091   QRect max;
00092 signals:
00096   void closeMe(int);
00097 public:
00101   DateInternalMonthPicker(int fontsize, QWidget* parent, const char* name=0);
00105   QSize sizeHint() const;
00109   QSize minimumSizeHint() const { return sizeHint(); }
00114   int getResult() const;
00115 protected:
00119   void setupPainter(QPainter *p);
00123   virtual void viewportResizeEvent(QResizeEvent*);
00127   virtual void paintCell(QPainter* painter, int row, int col);
00131   virtual void contentsMousePressEvent(QMouseEvent *e);
00132   virtual void contentsMouseMoveEvent(QMouseEvent *e);
00136   virtual void contentsMouseReleaseEvent(QMouseEvent *e);
00137 
00138 private:
00139   class DateInternalMonthPrivate;
00140   DateInternalMonthPrivate *d;
00141 };
00142 
00148 class DateInternalYearSelector : public QLineEdit
00149 {
00150   Q_OBJECT
00151 protected:
00152   QIntValidator *val;
00153   int result;
00154 public slots:
00155   void yearEnteredSlot();
00156 signals:
00157   void closeMe(int);
00158 public:
00159   DateInternalYearSelector(int fontsize,
00160                 QWidget* parent=0,
00161                 const char* name=0);
00162   int getYear() const;
00163   void setYear(int year);
00164 
00165 private:
00166   class DateInternalYearPrivate;
00167   DateInternalYearPrivate *d;
00168 };
00169 
00175 class PopupFrame : public QFrame
00176 {
00177   Q_OBJECT
00178 protected:
00182   int result;
00186   virtual void keyPressEvent(QKeyEvent* e);
00190   QWidget *main;
00191 public slots:
00196   void close(int r);
00197 public:
00201   PopupFrame(QWidget* parent=0, const char*  name=0);
00209   void setMainWidget(QWidget* m);
00214   virtual void resizeEvent(QResizeEvent*);
00218   void popup(const QPoint &pos);
00222   int exec(QPoint p);
00226   int exec(int x, int y);
00227 
00228 private:
00229 
00230   virtual bool close(bool alsoDelete) { return QFrame::close(alsoDelete); }
00231 protected:
00232   virtual void virtual_hook( int id, void* data );
00233 private:
00234   class PopupFramePrivate;
00235   PopupFramePrivate *d;
00236 };
00237 
00241 class DateValidator : public QValidator
00242 {
00243 public:
00244     DateValidator(QWidget* parent=0, const char* name=0);
00245     virtual State validate(QString&, int&) const;
00246     virtual void fixup ( QString & input ) const;
00247     State date(const QString&, QDate&) const;
00248 };
00249 
00250 
00251 class DateTable : public QGridView
00252 {
00253     Q_OBJECT
00254 public:
00258     DateTable(QWidget *parent=0, QDate date=QDate::currentDate(),
00259                  const char* name="DateTable", WFlags f=0);
00260 
00268     virtual QSize sizeHint() const;
00272     void setFontSize(int size);
00276     bool setDate(const QDate&, bool repaint=true);
00277     const QDate& getDate() const;
00278     bool selectDate(const QDate& date_);
00279 
00280     void addMarkedDate(QDate date, int state) { m_markedDates.insert(date, state); }
00281     bool dateMarked(QDate date);
00282 
00283     void addMarkedWeekday(int day, int state);
00284     void setMarkedWeekday(int day, int state) { m_markedWeekdays.insert(day, state); }
00285     void setMarkedWeekdays(const IntMap days);
00286     bool weekdayMarked(int day);
00287 
00288     DateMap selectedDates() const { return m_selectedDates; }
00289     IntMap selectedWeekdays() const { return m_selectedWeekdays; }
00290 
00291     DateMap markedDates() const { return m_markedDates; }
00292     IntMap markedWeekdays() const { return m_markedWeekdays; }
00293 
00294     void clear();
00295     void clearSelection();
00296 
00297     void setEnabled(bool yes);
00298     bool isEnabled() const { return m_enabled; }
00299 
00300     void markSelected(int state);
00301 
00302 protected:
00306     virtual void paintCell(QPainter*, int, int);
00310     virtual void viewportResizeEvent(QResizeEvent *);
00314     virtual void contentsMousePressEvent(QMouseEvent *);
00315     virtual void wheelEvent( QWheelEvent * e );
00316     virtual void keyPressEvent( QKeyEvent *e );
00317     virtual void focusInEvent( QFocusEvent *e );
00318     virtual void focusOutEvent( QFocusEvent *e );
00319 
00320     bool contentsMousePressEvent_internal(QMouseEvent *);
00321 
00322     int weekOfYear(QDate date) const;
00323     void setWeekNumbers(QDate);
00324 
00325     bool weekSelected(int row);
00326     bool weekSelected();
00327     bool weekdaySelected();
00328     bool isWeekdaySelected(int day);
00329     bool dateSelected(QDate date);
00330     bool dateSelected();
00331     void updateSelectedCells();
00332     void updateMarkedCells();
00333     void updateCells();
00334 
00335     QDate getDate(int pos) { return QDate(date.year(), date.month(), 1).addDays(pos-firstday); }
00336 
00341     int position(int row, int col) { return ((7 * (row - 1)) + col - m_dateStartCol + 1); }
00342 
00343     int weekday(int col) {
00344         int day = col - m_dateStartCol + KGlobal::locale()->weekStartDay();
00345         if (day > 7) day % 7;
00346         return day;
00347     }
00348 
00349     void paintWeekday(QPainter *painter, int col);
00350     void paintWeekNumber(QPainter *painter, int row);
00351     void paintDay(QPainter *painter, int row, int col);
00352 
00356     int fontsize;
00360     QDate date;
00364     int firstday;
00368     int numdays;
00372     int numDaysPrevMonth;
00376     QRect maxCell;
00377 
00378 signals:
00382     void dateChanged(QDate);
00386     void tableClicked();
00387 
00388     void weekdaySelected(int);
00389     void weekSelected(int, int);
00393     void selectionCleared();
00394 
00395 private:
00396 
00397     QMemArray< QPair<int, int> > m_weeks;
00398 
00399     int m_currentRow; // row of selected date
00400 
00401     // User has selected these, results in "select coloring" the dates in datetable
00402 
00403     DateMap m_selectedDates;
00404     IntMap m_selectedWeekdays;
00405 
00406     // These results in marking the dates, weekdays and weeks respectivly
00407     DateMap m_markedDates;
00408     IntMap m_markedWeekdays;
00409 
00410     int m_dateStartCol;
00411     bool m_enabled;
00412 
00413     QColor colorBackgroundHoliday;
00414     QColor colorBackgroundWorkday;
00415     QColor colorTextHoliday;
00416     QColor colorTextWorkday;
00417     QColor colorLine;
00418     QColor backgroundSelectColor;
00419     QColor penSelectColor;
00420 
00421 protected:
00422   virtual void virtual_hook( int id, void* data );
00423 private:
00424     class DateTablePrivate;
00425     DateTablePrivate *d;
00426 };
00427 
00428 }  //KPlato namespace
00429 
00430 #endif // DATETABEL_H
KDE Home | KDE Accessibility Home | Description of Access Keys