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

akonadi/contact

dateeditwidget.cpp

00001 /*
00002     This file is part of Akonadi Contact.
00003 
00004     Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or modify it
00007     under the terms of the GNU Library General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or (at your
00009     option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful, but WITHOUT
00012     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014     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 the
00018     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301, USA.
00020 */
00021 
00022 #include "dateeditwidget.h"
00023 
00024 #include "kdatepickerpopup_p.h"
00025 
00026 #include <kdatepicker.h>
00027 #include <kglobal.h>
00028 #include <kicon.h>
00029 #include <klocale.h>
00030 
00031 #include <QtGui/QContextMenuEvent>
00032 #include <QtGui/QHBoxLayout>
00033 #include <QtGui/QLabel>
00034 #include <QtGui/QToolButton>
00035 
00036 DateView::DateView( QWidget *parent )
00037   : QLabel( parent )
00038 {
00039   setTextInteractionFlags( Qt::TextSelectableByMouse );
00040   setFrameShape( QFrame::Panel );
00041   setFrameShadow( QFrame::Sunken );
00042 }
00043 
00044 void DateView::contextMenuEvent( QContextMenuEvent *event )
00045 {
00046   if(text().isEmpty())
00047     return;
00048   QMenu menu;
00049   menu.addAction( i18n( "Remove" ), this, SLOT( emitSignal() ) );
00050 
00051   menu.exec( event->globalPos() );
00052 }
00053 
00054 void DateView::emitSignal()
00055 {
00056   emit resetDate();
00057 }
00058 
00059 DateEditWidget::DateEditWidget( Type type, QWidget *parent )
00060   : QWidget( parent ), mReadOnly( false )
00061 {
00062   QHBoxLayout *layout = new QHBoxLayout( this );
00063   layout->setMargin( 0 );
00064 
00065   mView = new DateView;
00066   layout->addWidget( mView );
00067 
00068   mClearButton = new QToolButton;
00069   if ( layoutDirection() == Qt::LeftToRight )
00070     mClearButton->setIcon( KIcon( QLatin1String( "edit-clear-locationbar-rtl" ) ) );
00071   else
00072     mClearButton->setIcon( KIcon( QLatin1String( "edit-clear-locationbar-ltr" ) ) );
00073   layout->addWidget( mClearButton );
00074 
00075   mSelectButton = new QToolButton;
00076   mSelectButton->setPopupMode( QToolButton::InstantPopup );
00077   switch ( type ) {
00078     case General: mSelectButton->setIcon( KIcon( QLatin1String( "view-calendar-day" ) ) ); break;
00079     case Birthday: mSelectButton->setIcon( KIcon( QLatin1String( "view-calendar-birthday" ) ) ); break;
00080     case Anniversary: mSelectButton->setIcon( KIcon( QLatin1String( "view-calendar-wedding-anniversary" ) ) ); break;
00081   }
00082 
00083   layout->addWidget( mSelectButton );
00084 
00085   mMenu = new KPIM::KDatePickerPopup( KPIM::KDatePickerPopup::DatePicker, QDate(), this );
00086   mSelectButton->setMenu( mMenu );
00087 
00088   connect( mClearButton, SIGNAL( clicked() ), SLOT( resetDate() ) );
00089   connect( mMenu, SIGNAL( dateChanged( const QDate& ) ), SLOT( dateSelected( const QDate& ) ) );
00090   connect( mView, SIGNAL( resetDate() ), SLOT( resetDate() ) );
00091 
00092   updateView();
00093 }
00094 
00095 DateEditWidget::~DateEditWidget()
00096 {
00097 }
00098 
00099 void DateEditWidget::setDate( const QDate &date )
00100 {
00101   mDate = date;
00102   mMenu->setDate( mDate );
00103   updateView();
00104 }
00105 
00106 QDate DateEditWidget::date() const
00107 {
00108   return mDate;
00109 }
00110 
00111 void DateEditWidget::setReadOnly( bool readOnly )
00112 {
00113   mReadOnly = readOnly;
00114 
00115   mSelectButton->setEnabled( !readOnly );
00116   mClearButton->setEnabled( !readOnly );
00117 }
00118 
00119 void DateEditWidget::dateSelected(const QDate &date)
00120 {
00121   mDate = date;
00122   updateView();
00123 }
00124 
00125 void DateEditWidget::resetDate()
00126 {
00127   mDate = QDate();
00128   updateView();
00129 }
00130 
00131 void DateEditWidget::updateView()
00132 {
00133   if ( mDate.isValid() ) {
00134     mView->setText( KGlobal::locale()->formatDate( mDate ) );
00135     mClearButton->show();
00136   } else {
00137     mView->setText( QString() );
00138     mClearButton->hide();
00139   }
00140 }
00141 
00142 #include "dateeditwidget.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