24 #include <KDatePicker>
27 #include <QtCore/QDateTime>
28 #include <QWidgetAction>
32 class KDatePickerAction :
public QWidgetAction
35 KDatePickerAction( KDatePicker *widget,
QObject *parent )
36 : QWidgetAction( parent ),
37 mDatePicker( widget ), mOriginalParent( widget->parentWidget() )
44 mDatePicker->setParent( parent );
48 void deleteWidget(
QWidget *widget )
50 if ( widget != mDatePicker ) {
54 mDatePicker->setParent( mOriginalParent );
58 KDatePicker *mDatePicker;
62 class KDatePickerPopup::Private
66 : q( qq ), mDatePicker( 0 )
72 void slotDateChanged(
const QDate& );
80 KDatePicker *mDatePicker;
84 void KDatePickerPopup::Private::buildMenu()
91 if ( mModes & DatePicker ) {
92 q->addAction(
new KDatePickerAction( mDatePicker, q ) );
94 if ( (mModes & NoDate) || (mModes & Words) )
98 if ( mModes & Words ) {
99 q->addAction( i18nc(
"@option today",
"&Today" ), q, SLOT(slotToday()) );
100 q->addAction( i18nc(
"@option tomorrow",
"To&morrow" ), q, SLOT(slotTomorrow()) );
101 q->addAction( i18nc(
"@option next week",
"Next &Week" ), q, SLOT(slotNextWeek()) );
102 q->addAction( i18nc(
"@option next month",
"Next M&onth" ), q, SLOT(slotNextMonth()) );
104 if ( mModes & NoDate )
108 if ( mModes & NoDate )
109 q->addAction( i18nc(
"@option do not specify a date",
"No Date" ), q, SLOT(slotNoDate()) );
112 void KDatePickerPopup::Private::slotDateChanged(
const QDate &date )
118 void KDatePickerPopup::Private::slotToday()
120 emit q->dateChanged( QDate::currentDate() );
123 void KDatePickerPopup::Private::slotTomorrow()
125 emit q->dateChanged( QDate::currentDate().addDays( 1 ) );
128 void KDatePickerPopup::Private::slotNoDate()
130 emit q->dateChanged( QDate() );
133 void KDatePickerPopup::Private::slotNextWeek()
135 emit q->dateChanged( QDate::currentDate().addDays( 7 ) );
138 void KDatePickerPopup::Private::slotNextMonth()
140 emit q->dateChanged( QDate::currentDate().addMonths( 1 ) );
145 :
QMenu( parent ), d( new Private( this ) )
149 d->mDatePicker =
new KDatePicker(
this );
150 d->mDatePicker->setCloseButton(
false );
152 connect( d->mDatePicker, SIGNAL(dateEntered(QDate)),
153 SLOT(slotDateChanged(QDate)) );
154 connect( d->mDatePicker, SIGNAL(dateSelected(QDate)),
155 SLOT(slotDateChanged(QDate)) );
157 d->mDatePicker->setDate( date );
169 return d->mDatePicker;
174 d->mDatePicker->setDate( date );
177 #include "kdatepickerpopup.moc"