• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.3 API Reference
  • KDE Home
  • Contact Us
 

akonadi/contact

  • akonadi
  • contact
  • editor
dateeditwidget.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "dateeditwidget.h"
23 
24 #include "kdatepickerpopup_p.h"
25 
26 #include <kdatepicker.h>
27 #include <kglobal.h>
28 #include <kicon.h>
29 #include <klocale.h>
30 
31 #include <QtGui/QContextMenuEvent>
32 #include <QtGui/QHBoxLayout>
33 #include <QtGui/QLabel>
34 #include <QtGui/QToolButton>
35 
36 DateView::DateView( QWidget *parent )
37  : QLabel( parent )
38 {
39  setTextInteractionFlags( Qt::TextSelectableByMouse );
40  setFrameShape( QFrame::Panel );
41  setFrameShadow( QFrame::Sunken );
42 }
43 
44 void DateView::contextMenuEvent( QContextMenuEvent *event )
45 {
46  if ( text().isEmpty() )
47  return;
48 
49  QMenu menu;
50  menu.addAction( i18n( "Remove" ), this, SLOT(emitSignal()) );
51 
52  menu.exec( event->globalPos() );
53 }
54 
55 void DateView::emitSignal()
56 {
57  emit resetDate();
58 }
59 
60 DateEditWidget::DateEditWidget( Type type, QWidget *parent )
61  : QWidget( parent ), mReadOnly( false )
62 {
63  QHBoxLayout *layout = new QHBoxLayout( this );
64  layout->setMargin( 0 );
65 
66  mView = new DateView;
67  layout->addWidget( mView );
68 
69  mClearButton = new QToolButton;
70  if ( layoutDirection() == Qt::LeftToRight )
71  mClearButton->setIcon( KIcon( QLatin1String( "edit-clear-locationbar-rtl" ) ) );
72  else
73  mClearButton->setIcon( KIcon( QLatin1String( "edit-clear-locationbar-ltr" ) ) );
74  layout->addWidget( mClearButton );
75 
76  mSelectButton = new QToolButton;
77  mSelectButton->setPopupMode( QToolButton::InstantPopup );
78  switch ( type ) {
79  case General: mSelectButton->setIcon( KIcon( QLatin1String( "view-calendar-day" ) ) ); break;
80  case Birthday: mSelectButton->setIcon( KIcon( QLatin1String( "view-calendar-birthday" ) ) ); break;
81  case Anniversary: mSelectButton->setIcon( KIcon( QLatin1String( "view-calendar-wedding-anniversary" ) ) ); break;
82  }
83 
84  layout->addWidget( mSelectButton );
85 
86  mMenu = new KDatePickerPopup( KDatePickerPopup::DatePicker, QDate(), this );
87  mSelectButton->setMenu( mMenu );
88 
89  connect( mClearButton, SIGNAL(clicked()), SLOT(resetDate()) );
90  connect( mMenu, SIGNAL(dateChanged(QDate)), SLOT(dateSelected(QDate)) );
91  connect( mView, SIGNAL(resetDate()), SLOT(resetDate()) );
92 
93  updateView();
94 }
95 
96 DateEditWidget::~DateEditWidget()
97 {
98 }
99 
100 void DateEditWidget::setDate( const QDate &date )
101 {
102  mDate = date;
103  mMenu->setDate( mDate );
104  updateView();
105 }
106 
107 QDate DateEditWidget::date() const
108 {
109  return mDate;
110 }
111 
112 void DateEditWidget::setReadOnly( bool readOnly )
113 {
114  mReadOnly = readOnly;
115 
116  mSelectButton->setEnabled( !readOnly );
117  mClearButton->setEnabled( !readOnly );
118 }
119 
120 void DateEditWidget::dateSelected(const QDate &date)
121 {
122  mDate = date;
123  updateView();
124 }
125 
126 void DateEditWidget::resetDate()
127 {
128  mDate = QDate();
129  updateView();
130 }
131 
132 void DateEditWidget::updateView()
133 {
134  if ( mDate.isValid() ) {
135  mView->setText( KGlobal::locale()->formatDate( mDate ) );
136  mClearButton->show();
137  } else {
138  mView->setText( QString() );
139  mClearButton->hide();
140  }
141 }
142 
143 #include "dateeditwidget.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Nov 26 2012 16:49:09 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi/contact

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

kdepimlibs-4.9.3 API Reference

Skip menu "kdepimlibs-4.9.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal