00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "kdatepickerpopup_p.h"
00023
00024 #include <KDatePicker>
00025 #include <KLocale>
00026
00027 #include <QtCore/QDateTime>
00028 #include <QtGui/QWidgetAction>
00029
00030 class KDatePickerAction : public QWidgetAction
00031 {
00032 public:
00033 KDatePickerAction( KDatePicker *widget, QObject *parent )
00034 : QWidgetAction( parent ),
00035 mDatePicker( widget ), mOriginalParent( widget->parentWidget() )
00036 {
00037 }
00038
00039 protected:
00040 QWidget *createWidget( QWidget *parent )
00041 {
00042 mDatePicker->setParent( parent );
00043 return mDatePicker;
00044 }
00045
00046 void deleteWidget( QWidget *widget )
00047 {
00048 if ( widget != mDatePicker ) {
00049 return;
00050 }
00051
00052 mDatePicker->setParent( mOriginalParent );
00053 }
00054
00055 private:
00056 KDatePicker *mDatePicker;
00057 QWidget *mOriginalParent;
00058 };
00059
00060 KDatePickerPopup::KDatePickerPopup( Items items, const QDate &date, QWidget *parent )
00061 : QMenu( parent )
00062 {
00063 mItems = items;
00064
00065 mDatePicker = new KDatePicker( this );
00066 mDatePicker->setCloseButton( false );
00067
00068 connect( mDatePicker, SIGNAL( dateEntered( const QDate& ) ),
00069 SLOT( slotDateChanged( const QDate& ) ) );
00070 connect( mDatePicker, SIGNAL( dateSelected( const QDate& ) ),
00071 SLOT( slotDateChanged( const QDate& ) ) );
00072
00073 mDatePicker->setDate( date );
00074
00075 buildMenu();
00076 }
00077
00078 void KDatePickerPopup::buildMenu()
00079 {
00080 if ( isVisible() ) {
00081 return;
00082 }
00083 clear();
00084
00085 if ( mItems & DatePicker ) {
00086 addAction( new KDatePickerAction( mDatePicker, this ) );
00087
00088 if ( ( mItems & NoDate ) || ( mItems & Words ) ) {
00089 addSeparator();
00090 }
00091 }
00092
00093 if ( mItems & Words ) {
00094 addAction( i18nc( "@option today", "&Today" ), this, SLOT( slotToday() ) );
00095 addAction( i18nc( "@option tomorrow", "To&morrow" ), this, SLOT( slotTomorrow() ) );
00096 addAction( i18nc( "@option next week", "Next &Week" ), this, SLOT( slotNextWeek() ) );
00097 addAction( i18nc( "@option next month", "Next M&onth" ), this, SLOT( slotNextMonth() ) );
00098
00099 if ( mItems & NoDate ) {
00100 addSeparator();
00101 }
00102 }
00103
00104 if ( mItems & NoDate ) {
00105 addAction( i18nc( "@option do not specify a date", "No Date" ), this, SLOT( slotNoDate() ) );
00106 }
00107 }
00108
00109 KDatePicker *KDatePickerPopup::datePicker() const
00110 {
00111 return mDatePicker;
00112 }
00113
00114 void KDatePickerPopup::setDate( const QDate &date )
00115 {
00116 mDatePicker->setDate( date );
00117 }
00118
00119 #if 0
00120 void KDatePickerPopup::setItems( int items )
00121 {
00122 mItems = items;
00123 buildMenu();
00124 }
00125 #endif
00126
00127 void KDatePickerPopup::slotDateChanged( const QDate &date )
00128 {
00129 emit dateChanged( date );
00130 hide();
00131 }
00132
00133 void KDatePickerPopup::slotToday()
00134 {
00135 emit dateChanged( QDate::currentDate() );
00136 }
00137
00138 void KDatePickerPopup::slotTomorrow()
00139 {
00140 emit dateChanged( QDate::currentDate().addDays( 1 ) );
00141 }
00142
00143 void KDatePickerPopup::slotNoDate()
00144 {
00145 emit dateChanged( QDate() );
00146 }
00147
00148 void KDatePickerPopup::slotNextWeek()
00149 {
00150 emit dateChanged( QDate::currentDate().addDays( 7 ) );
00151 }
00152
00153 void KDatePickerPopup::slotNextMonth()
00154 {
00155 emit dateChanged( QDate::currentDate().addMonths( 1 ) );
00156 }
00157
00158 #include "kdatepickerpopup_p.moc"