libkdepim

kdatepickerpopup.cpp

00001 /*
00002   This file is part of libkdepim.
00003 
00004   Copyright (c) 2004 Bram Schoenmakers <bramschoenmakers@kde.nl>
00005 
00006   This library is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Library General Public
00008   License as published by the Free Software Foundation; either
00009   version 2 of the License, or (at your option) any later version.
00010 
00011   This library is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   Library General Public License for more details.
00015 
00016   You should have received a copy of the GNU Library General Public License
00017   along with this library; see the file COPYING.LIB.  If not, write to
00018   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019   Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include <qdatetime.h>
00023 #include <qpopupmenu.h>
00024 
00025 #include <klocale.h>
00026 
00027 #include "kdatepickerpopup.h"
00028 
00029 KDatePickerPopup::KDatePickerPopup( int items, const QDate &date, QWidget *parent,
00030                                     const char *name )
00031   : QPopupMenu( parent, name )
00032 {
00033   mItems = items;
00034 
00035   mDatePicker = new KDatePicker( this );
00036   mDatePicker->setCloseButton( false );
00037 
00038   connect( mDatePicker, SIGNAL( dateEntered( QDate ) ),
00039            SLOT( slotDateChanged( QDate ) ) );
00040   connect( mDatePicker, SIGNAL( dateSelected( QDate ) ),
00041            SLOT( slotDateChanged( QDate ) ) );
00042 
00043   mDatePicker->setDate( date );
00044 
00045   buildMenu();
00046 }
00047 
00048 void KDatePickerPopup::buildMenu()
00049 {
00050   if ( isVisible() ) return;
00051   clear();
00052 
00053   if ( mItems & DatePicker ) {
00054     insertItem( mDatePicker );
00055 
00056     if ( ( mItems & NoDate ) || ( mItems & Words ) )
00057       insertSeparator();
00058   }
00059 
00060   if ( mItems & Words ) {
00061     insertItem( i18n("&Today"), this, SLOT( slotToday() ) );
00062     insertItem( i18n("To&morrow"), this, SLOT( slotTomorrow() ) );
00063     insertItem( i18n("Next &Week"), this, SLOT( slotNextWeek() ) );
00064     insertItem( i18n("Next M&onth"), this, SLOT( slotNextMonth() ) );
00065 
00066     if ( mItems & NoDate )
00067       insertSeparator();
00068   }
00069 
00070   if ( mItems & NoDate )
00071     insertItem( i18n("No Date"), this, SLOT( slotNoDate() ) );
00072 }
00073 
00074 KDatePicker *KDatePickerPopup::datePicker() const
00075 {
00076   return mDatePicker;
00077 }
00078 
00079 void KDatePickerPopup::setDate( const QDate &date )
00080 {
00081   mDatePicker->setDate( date );
00082 }
00083 
00084 #if 0
00085 void KDatePickerPopup::setItems( int items )
00086 {
00087   mItems = items;
00088   buildMenu();
00089 }
00090 #endif
00091 
00092 void KDatePickerPopup::slotDateChanged( QDate date )
00093 {
00094   emit dateChanged( date );
00095   hide();
00096 }
00097 
00098 void KDatePickerPopup::slotToday()
00099 {
00100   emit dateChanged( QDate::currentDate() );
00101 }
00102 
00103 void KDatePickerPopup::slotTomorrow()
00104 {
00105   emit dateChanged( QDate::currentDate().addDays( 1 ) );
00106 }
00107 
00108 void KDatePickerPopup::slotNoDate()
00109 {
00110   emit dateChanged( QDate() );
00111 }
00112 
00113 void KDatePickerPopup::slotNextWeek()
00114 {
00115   emit dateChanged( QDate::currentDate().addDays( 7 ) );
00116 }
00117 
00118 void KDatePickerPopup::slotNextMonth()
00119 {
00120   emit dateChanged( QDate::currentDate().addMonths( 1 ) );
00121 }
00122 
00123 #include "kdatepickerpopup.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys