dateselect.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00006 /*
00007   AUTHOR(S): Stephan Broennimann (vb)
00008 
00009   RCS information
00010    $Name: OSB_060808 $
00011    $Revision: 1.14 $
00012 
00013   License
00014    OSB rating and billing library for communication networks
00015    Copyright (C) 2004, 2005, 2006  OSB systems
00016 
00017    This file may be distributed and/or modify under the terms of the
00018    GNU General Public License (GPL) as published by the Free Software
00019    Foundation which is provided in the file LICENSE.GPL included in the
00020    packaging of this file.
00021 
00022    The file is distributed in the hope that it will be useful, but WITHOUT
00023    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00024    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00025    for more details.
00026 
00027    Holders of a OSB Commercial License may use this file under the terms
00028    and conditions of this commercial license.
00029  */
00030 #ifndef _DATESELECT_H_
00031 #define _DATESELECT_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 
00037 // + libraries
00038 #include <qspinbox.h>
00039 #include <qdatetime.h>
00040 
00041 // + local headers
00042 
00043 // ************************************************************************
00044 // class declarations
00045 class QGridLayout;
00046 class QHBoxLayout;
00047 class QPushButton;
00048 
00049 // ************************************************************************
00050 // namespace extensions
00051 namespace OSB_GUI {
00052 
00053 // ************************************************************************
00054 // forward declarations
00055     class MonthSpin;
00056     class MonthDays;
00057 
00058 // ************************************************************************
00059 // class definitions
00063     class DateSelect : public QFrame {
00064         Q_OBJECT                        // for vim ->;
00065     public:
00067         enum SelectMode {
00069             smNever,
00071             smAlways,
00076             smToggleOn,
00081             smToggleOff
00082         };
00083     public:
00087         DateSelect(
00088             const QDate&   date,
00089                   QWidget* parent,
00090             const char*    name   = "dateSelect_",
00091                   WFlags   fl     = 0
00092         );
00096         explicit DateSelect(
00097                   QWidget* parent,
00098             const char*    name   = "dateSelect_",
00099                   WFlags   fl     = 0
00100         );
00101     public:
00103         QDate selected() const;
00105         void setSelected(const QDate& date);
00107         SelectMode selectMode() const;
00109         void setSelectMode(SelectMode mode);
00118         void popup(const QPoint& pos);
00119     signals:
00127         void selected(const QDate& date);
00128 
00129     private slots:
00135         void accept();
00136 
00137     private:
00144         void build(QDate date);
00151         void keyPressEvent(QKeyEvent* event);
00152     private:
00154         MonthSpin* monthSpin_;
00156         QSpinBox*  spYear_;
00158         MonthDays* monthDays_;
00160         QPushButton* pbOk_;
00161 
00163         QGridLayout* layout_;
00165         QHBoxLayout* spinLayout_;
00166     };                                  // class DateSelect
00167 
00174     class MonthDays : public QWidget {
00175         Q_OBJECT                        // for vim ->;
00177         static const int dw_ = 2;
00179         static const int dh_ = 0;
00180     public:
00182         typedef DateSelect::SelectMode SelectMode;
00183     public:
00190         MonthDays(
00191             const QDate&   date,
00192                   QWidget* parent,
00193             const char*    name = "monthDays_",
00194                   WFlags   f = 0
00195         );
00197         QDate selected() const;
00199         void setSelected(const QDate& date);
00201         SelectMode selectMode() const;
00203         void setSelectMode(SelectMode mode);
00209         bool showSelected() const;
00211         int width() const;
00213         int height() const;
00214     signals:
00216         void prevMonth();
00218         void nextMonth();
00219     public slots:
00221         void setMonth(int m);
00223         void setYear(int y);
00224     private:                            // overwritten virtuals
00226         void polish();
00228         void paintEvent(QPaintEvent*);
00230         void mousePressEvent(QMouseEvent* e);
00232         void keyPressEvent(QKeyEvent* e);
00234         void setYearMonth(const QDate& date);
00235     private:
00237         bool cursorKey(Qt::Key key);
00239         int day(int x, int y);
00241         void calcWidth();
00243         void calcMonth();
00245         void showCurrent(QPainter& p);
00247         void showSelected(QPainter& p);
00249         QRect dayRect(int d, bool withBorder);
00251         QRect wdayRect(int wd, bool withBorder);
00252     private:
00254         QDate curMonthYear_;
00256         SelectMode mode_;
00258         QDate selected_;
00266         int selectedDay_;
00268         int dayWidth_;
00270         int dayHeight_;
00272         int wdayWidth_;
00274         int wdayHeight_;
00276         int firstDay_;
00278         int numRows_;
00279     };                                  // class MonthDays
00280 
00284     class MonthSpin : public QSpinBox {
00285         Q_OBJECT                        // for vim ->;
00286     public:
00294         MonthSpin(
00295                   int      month,
00296                   QWidget* parent,
00297             const char*    name   = 0
00298         );
00299     signals:
00301         void prevYear();
00303         void nextYear();
00304     private:
00306         void valueChange();
00308         QString mapValueToText(int v);
00309     private:
00311         int calcWidth();
00312     private:
00314         int month_;
00315     };                                  // class MonthSpin
00316 }                                       // namespace OSB_GUI
00317 #endif                                  // #ifndef _DATESELECT_H_

Generated on Sat Sep 2 14:17:36 2006 for OSB Library by  doxygen 1.4.7