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