00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <tqpopupmenu.h>
00021 #include <tqcombobox.h>
00022 #include <tqlayout.h>
00023 #include <tqlineedit.h>
00024
00025 #include "knuminput.h"
00026 #include "tdeglobal.h"
00027 #include "tdelocale.h"
00028 #include "kcalendarsystem.h"
00029
00030 #include "kdialog.h"
00031
00032 #include "kdatewidget.h"
00033
00034 class KDateWidgetSpinBox : public TQSpinBox
00035 {
00036 public:
00037 KDateWidgetSpinBox(int min, int max, TQWidget *parent)
00038 : TQSpinBox(min, max, 1, parent)
00039 {
00040 editor()->setAlignment(TQt::AlignRight);
00041 }
00042 };
00043
00044 class KDateWidget::KDateWidgetPrivate
00045 {
00046 public:
00047 KDateWidgetSpinBox *m_day;
00048 TQComboBox *m_month;
00049 KDateWidgetSpinBox *m_year;
00050 TQDate m_dat;
00051 };
00052
00053
00054 KDateWidget::KDateWidget( TQWidget *parent, const char *name )
00055 : TQWidget( parent, name )
00056 {
00057 init(TQDate());
00058 setDate(TQDate());
00059 }
00060
00061
00062 KDateWidget::KDateWidget( TQDate date, TQWidget *parent,
00063 const char *name )
00064 : TQWidget( parent, name )
00065 {
00066 init(date);
00067 setDate(date);
00068 }
00069
00070
00071
00072 void KDateWidget::init()
00073 {
00074 d = new KDateWidgetPrivate;
00075 TDELocale *locale = TDEGlobal::locale();
00076 TQHBoxLayout *layout = new TQHBoxLayout(this, 0, KDialog::spacingHint());
00077 layout->setAutoAdd(true);
00078 d->m_day = new KDateWidgetSpinBox(1, 1, this);
00079 d->m_month = new TQComboBox(false, this);
00080 for (int i = 1; ; ++i)
00081 {
00082 TQString str = locale->calendar()->monthName(i,
00083 locale->calendar()->year(TQDate()));
00084 if (str.isNull()) break;
00085 d->m_month->insertItem(str);
00086 }
00087
00088 d->m_year = new KDateWidgetSpinBox(locale->calendar()->minValidYear(),
00089 locale->calendar()->maxValidYear(), this);
00090
00091 connect(d->m_day, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotDateChanged()));
00092 connect(d->m_month, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotDateChanged()));
00093 connect(d->m_year, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotDateChanged()));
00094 }
00095
00096 void KDateWidget::init(const TQDate& date)
00097 {
00098 d = new KDateWidgetPrivate;
00099 TDELocale *locale = TDEGlobal::locale();
00100 TQHBoxLayout *layout = new TQHBoxLayout(this, 0, KDialog::spacingHint());
00101 layout->setAutoAdd(true);
00102 d->m_day = new KDateWidgetSpinBox(1, 1, this);
00103 d->m_month = new TQComboBox(false, this);
00104 for (int i = 1; ; ++i)
00105 {
00106 TQString str = locale->calendar()->monthName(i,
00107 locale->calendar()->year(date));
00108 if (str.isNull()) break;
00109 d->m_month->insertItem(str);
00110 }
00111
00112 d->m_year = new KDateWidgetSpinBox(locale->calendar()->minValidYear(),
00113 locale->calendar()->maxValidYear(), this);
00114
00115 connect(d->m_day, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotDateChanged()));
00116 connect(d->m_month, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotDateChanged()));
00117 connect(d->m_year, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotDateChanged()));
00118 }
00119
00120 KDateWidget::~KDateWidget()
00121 {
00122 delete d;
00123 }
00124
00125
00126 void KDateWidget::setDate( TQDate date )
00127 {
00128 const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
00129
00130 d->m_day->blockSignals(true);
00131 d->m_month->blockSignals(true);
00132 d->m_year->blockSignals(true);
00133
00134 d->m_day->setMaxValue(calendar->daysInMonth(date));
00135 d->m_day->setValue(calendar->day(date));
00136 d->m_month->setCurrentItem(calendar->month(date)-1);
00137 d->m_year->setValue(calendar->year(date));
00138
00139 d->m_day->blockSignals(false);
00140 d->m_month->blockSignals(false);
00141 d->m_year->blockSignals(false);
00142
00143 d->m_dat = date;
00144 emit changed(d->m_dat);
00145 }
00146
00147 TQDate KDateWidget::date() const
00148 {
00149 return d->m_dat;
00150 }
00151
00152 void KDateWidget::slotDateChanged( )
00153 {
00154 const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
00155
00156 TQDate date;
00157 int y,m,day;
00158
00159 y = d->m_year->value();
00160 y = TQMIN(TQMAX(y, calendar->minValidYear()), calendar->maxValidYear());
00161
00162 calendar->setYMD(date, y, 1, 1);
00163 m = d->m_month->currentItem()+1;
00164 m = TQMIN(TQMAX(m,1), calendar->monthsInYear(date));
00165
00166 calendar->setYMD(date, y, m, 1);
00167 day = d->m_day->value();
00168 day = TQMIN(TQMAX(day,1), calendar->daysInMonth(date));
00169
00170 calendar->setYMD(date, y, m, day);
00171 setDate(date);
00172 }
00173
00174 void KDateWidget::virtual_hook( int, void* )
00175 { }
00176
00177 #include "kdatewidget.moc"