22 #include "kdatepickerpopup_p.h"
24 #include <KDatePicker>
25 #include <KLocalizedString>
27 #include <QtCore/QDateTime>
28 #include <QWidgetAction>
30 class KDatePickerAction :
public QWidgetAction
33 KDatePickerAction( KDatePicker *widget, QObject *parent )
34 : QWidgetAction( parent ),
35 mDatePicker( widget ), mOriginalParent( widget->parentWidget() )
40 QWidget *createWidget( QWidget *parent )
42 mDatePicker->setParent( parent );
46 void deleteWidget( QWidget *widget )
48 if ( widget != mDatePicker ) {
52 mDatePicker->setParent( mOriginalParent );
56 KDatePicker *mDatePicker;
57 QWidget *mOriginalParent;
65 mDatePicker =
new KDatePicker(
this );
66 mDatePicker->setCloseButton(
false );
68 connect( mDatePicker, SIGNAL(dateEntered(QDate)),
69 SLOT(slotDateChanged(QDate)) );
70 connect( mDatePicker, SIGNAL(dateSelected(QDate)),
71 SLOT(slotDateChanged(QDate)) );
73 mDatePicker->setDate( date );
78 void KDatePickerPopup::buildMenu()
85 if ( mItems & DatePicker ) {
86 addAction(
new KDatePickerAction( mDatePicker,
this ) );
88 if ( ( mItems & NoDate ) || ( mItems & Words ) ) {
93 if ( mItems & Words ) {
94 addAction( i18nc(
"@option today",
"&Today" ),
this, SLOT(slotToday()) );
95 addAction( i18nc(
"@option tomorrow",
"To&morrow" ),
this, SLOT(slotTomorrow()) );
96 addAction( i18nc(
"@option next week",
"Next &Week" ),
this, SLOT(slotNextWeek()) );
97 addAction( i18nc(
"@option next month",
"Next M&onth" ),
this, SLOT(slotNextMonth()) );
99 if ( mItems & NoDate ) {
104 if ( mItems & NoDate ) {
105 addAction( i18nc(
"@option do not specify a date",
"No Date" ),
this, SLOT(slotNoDate()) );
114 void KDatePickerPopup::setDate(
const QDate &date )
116 mDatePicker->setDate( date );
120 void KDatePickerPopup::setItems(
int items )
127 void KDatePickerPopup::slotDateChanged(
const QDate &date )
135 void KDatePickerPopup::slotToday()
140 void KDatePickerPopup::slotTomorrow()
142 emit
dateChanged( QDate::currentDate().addDays( 1 ) );
145 void KDatePickerPopup::slotNoDate()
150 void KDatePickerPopup::slotNextWeek()
152 emit
dateChanged( QDate::currentDate().addDays( 7 ) );
155 void KDatePickerPopup::slotNextMonth()
157 emit
dateChanged( QDate::currentDate().addMonths( 1 ) );
160 #include "moc_kdatepickerpopup_p.cpp"