00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _DATESELECT_H_
00031 #define _DATESELECT_H_
00032
00033
00034
00035
00036
00037
00038 #include <qspinbox.h>
00039 #include <qdatetime.h>
00040
00041
00042
00043
00044
00045 class QGridLayout;
00046 class QHBoxLayout;
00047 class QPushButton;
00048
00049
00050
00051 namespace OSB_GUI {
00052
00053
00054
00055 class MonthSpin;
00056 class MonthDays;
00057
00058
00059
00063 class DateSelect : public QFrame {
00064 Q_OBJECT
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 };
00167
00174 class MonthDays : public QWidget {
00175 Q_OBJECT
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:
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 };
00280
00284 class MonthSpin : public QSpinBox {
00285 Q_OBJECT
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 };
00316 }
00317 #endif // #ifndef _DATESELECT_H_