libkdepim Library API Documentation

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., 59 Temple Place - Suite 330,
00019   Boston, MA 02111-1307, 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();
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("&Friday"), this, SLOT( slotFriday() ) );
00064     insertItem( i18n("&Sunday"), this, SLOT( slotSunday() ) );
00065     insertItem( i18n("Next &Week"), this, SLOT( slotNextWeek() ) );
00066     insertItem( i18n("Next M&onth"), this, SLOT( slotNextMonth() ) );
00067 
00068     if ( mItems & NoDate )
00069       insertSeparator();
00070   }
00071 
00072   if ( mItems & NoDate )
00073     insertItem( i18n("No Date"), this, SLOT( slotNoDate() ) );
00074 }
00075 
00076 KDatePickerPopup::~KDatePickerPopup()
00077 {
00078   delete mDatePicker;
00079 }
00080 
00081 KDatePicker *KDatePickerPopup::datePicker() const
00082 {
00083   return mDatePicker;
00084 }
00085 
00086 #if 0
00087 void KDatePickerPopup::setItems( int items )
00088 {
00089   mItems = items;
00090   buildMenu();
00091 }
00092 #endif
00093 
00094 void KDatePickerPopup::slotDateChanged( QDate date )
00095 {
00096   emit dateChanged( date );
00097   hide();
00098 }
00099 
00100 void KDatePickerPopup::slotToday()
00101 {
00102   emit dateChanged( QDate::currentDate() );
00103 }
00104 
00105 void KDatePickerPopup::slotTomorrow()
00106 {
00107   emit dateChanged( QDate::currentDate().addDays( 1 ) );
00108 }
00109 
00110 void KDatePickerPopup::slotFriday()
00111 {
00112   QDate date = QDate::currentDate();
00113   int day = date.dayOfWeek();
00114   if ( day < 6 )
00115     date = date.addDays( 5 - day );
00116   else
00117     date = date.addDays( 5 - day + 7 );
00118 
00119   emit dateChanged( date );
00120 }
00121 
00122 void KDatePickerPopup::slotSunday()
00123 {
00124   QDate date = QDate::currentDate();
00125   emit dateChanged( date.addDays( 7 - date.dayOfWeek() ) );
00126 }
00127 
00128 void KDatePickerPopup::slotNoDate()
00129 {
00130   emit dateChanged( QDate() );
00131 }
00132 
00133 void KDatePickerPopup::slotNextWeek()
00134 {
00135   emit dateChanged( QDate::currentDate().addDays( 7 ) );
00136 }
00137 
00138 void KDatePickerPopup::slotNextMonth()
00139 {
00140   emit dateChanged( QDate::currentDate().addMonths( 1 ) );
00141 }
00142 
00143 #include "kdatepickerpopup.moc"
KDE Logo
This file is part of the documentation for libkdepim Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 17 09:53:56 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003