• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi/contact

kdatepickerpopup.cpp

00001 /*
00002     This file is part of Akonadi Contact.
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 "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"

akonadi/contact

Skip menu "akonadi/contact"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal