00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include <qpopupmenu.h>
00021
#include <qcombobox.h>
00022
#include <qlayout.h>
00023
#include <qlineedit.h>
00024
00025
#include "knuminput.h"
00026
#include "kglobal.h"
00027
#include "klocale.h"
00028
#include "kcalendarsystem.h"
00029
00030
#include "kdialog.h"
00031
00032
#include "kdatewidget.h"
00033
00034
class KDateWidgetSpinBox :
public QSpinBox
00035 {
00036
public:
00037 KDateWidgetSpinBox(
int min,
int max,
QWidget *parent)
00038 :
QSpinBox(min, max, 1, parent)
00039 {
00040
editor()->setAlignment(AlignRight);
00041 }
00042 };
00043
00044
class KDateWidget::KDateWidgetPrivate
00045 {
00046
public:
00047 KDateWidgetSpinBox *m_day;
00048
QComboBox *m_month;
00049 KDateWidgetSpinBox *m_year;
00050
QDate m_dat;
00051 };
00052
00053
00054 KDateWidget::KDateWidget(
QWidget *parent,
const char *name )
00055 :
QWidget( parent, name )
00056 {
00057 init(
QDate());
00058
setDate(
QDate());
00059 }
00060
00061
00062 KDateWidget::KDateWidget(
QDate date,
QWidget *parent,
00063
const char *name )
00064 :
QWidget( parent, name )
00065 {
00066 init(date);
00067
setDate(date);
00068 }
00069
00070
00071
00072
void KDateWidget::init()
00073 {
00074 d =
new KDateWidgetPrivate;
00075
KLocale *locale =
KGlobal::locale();
00076
QHBoxLayout *layout =
new QHBoxLayout(
this, 0, KDialog::spacingHint());
00077 layout->setAutoAdd(
true);
00078 d->m_day =
new KDateWidgetSpinBox(1, 1,
this);
00079 d->m_month =
new QComboBox(
false,
this);
00080
for (
int i = 1; ; ++i)
00081 {
00082
QString str = locale->
calendar()->
monthName(i,
00083 locale->
calendar()->
year(
QDate()));
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, SIGNAL(valueChanged(
int)),
this, SLOT(slotDateChanged()));
00092 connect(d->m_month, SIGNAL(activated(
int)),
this, SLOT(slotDateChanged()));
00093 connect(d->m_year, SIGNAL(valueChanged(
int)),
this, SLOT(slotDateChanged()));
00094 }
00095
00096
void KDateWidget::init(
const QDate& date)
00097 {
00098 d =
new KDateWidgetPrivate;
00099
KLocale *locale =
KGlobal::locale();
00100
QHBoxLayout *layout =
new QHBoxLayout(
this, 0, KDialog::spacingHint());
00101 layout->setAutoAdd(
true);
00102 d->m_day =
new KDateWidgetSpinBox(1, 1,
this);
00103 d->m_month =
new QComboBox(
false,
this);
00104
for (
int i = 1; ; ++i)
00105 {
00106
QString 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, SIGNAL(valueChanged(
int)),
this, SLOT(slotDateChanged()));
00116 connect(d->m_month, SIGNAL(activated(
int)),
this, SLOT(slotDateChanged()));
00117 connect(d->m_year, SIGNAL(valueChanged(
int)),
this, SLOT(slotDateChanged()));
00118 }
00119
00120 KDateWidget::~KDateWidget()
00121 {
00122 }
00123
00124
00125 void KDateWidget::setDate(
QDate date )
00126 {
00127
const KCalendarSystem * calendar =
KGlobal::locale()->
calendar();
00128
00129 d->m_day->blockSignals(
true);
00130 d->m_month->blockSignals(
true);
00131 d->m_year->blockSignals(
true);
00132
00133 d->m_day->setMaxValue(calendar->
daysInMonth(date));
00134 d->m_day->setValue(calendar->
day(date));
00135 d->m_month->setCurrentItem(calendar->
month(date)-1);
00136 d->m_year->setValue(calendar->
year(date));
00137
00138 d->m_day->blockSignals(
false);
00139 d->m_month->blockSignals(
false);
00140 d->m_year->blockSignals(
false);
00141
00142 d->m_dat = date;
00143 emit
changed(d->m_dat);
00144 }
00145
00146
QDate KDateWidget::date()
const
00147
{
00148
return d->m_dat;
00149 }
00150
00151
void KDateWidget::slotDateChanged( )
00152 {
00153
const KCalendarSystem * calendar =
KGlobal::locale()->
calendar();
00154
00155
QDate date;
00156
int y,m,day;
00157
00158 y = d->m_year->value();
00159 y = QMIN(QMAX(y, calendar->
minValidYear()), calendar->
maxValidYear());
00160
00161 calendar->
setYMD(date, y, 1, 1);
00162 m = d->m_month->currentItem()+1;
00163 m = QMIN(QMAX(m,1), calendar->
monthsInYear(date));
00164
00165 calendar->
setYMD(date, y, m, 1);
00166 day = d->m_day->value();
00167 day = QMIN(QMAX(day,1), calendar->
daysInMonth(date));
00168
00169 calendar->
setYMD(date, y, m, day);
00170
setDate(date);
00171 }
00172
00173
void KDateWidget::virtual_hook(
int,
void* )
00174 { }
00175
00176
#include "kdatewidget.moc"