• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 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 <QContextMenuEvent>
32 #include <QHBoxLayout>
33 #include <QLabel>
34 #include <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 
50  QMenu menu;
51  menu.addAction( i18n( "Remove" ), this, SLOT(emitSignal()) );
52 
53  menu.exec( event->globalPos() );
54 }
55 
56 void DateView::emitSignal()
57 {
58  emit resetDate();
59 }
60 
61 DateEditWidget::DateEditWidget( Type type, QWidget *parent )
62  : QWidget( parent ), mReadOnly( false )
63 {
64  QHBoxLayout *layout = new QHBoxLayout( this );
65  layout->setMargin( 0 );
66 
67  mView = new DateView;
68  layout->addWidget( mView );
69 
70  mClearButton = new QToolButton;
71  if ( layoutDirection() == Qt::LeftToRight ) {
72  mClearButton->setIcon( KIcon( QLatin1String( "edit-clear-locationbar-rtl" ) ) );
73  } else {
74  mClearButton->setIcon( KIcon( QLatin1String( "edit-clear-locationbar-ltr" ) ) );
75  }
76  layout->addWidget( mClearButton );
77 
78  mSelectButton = new QToolButton;
79  mSelectButton->setPopupMode( QToolButton::InstantPopup );
80  switch ( type ) {
81  case General: mSelectButton->setIcon( KIcon( QLatin1String( "view-calendar-day" ) ) ); break;
82  case Birthday: mSelectButton->setIcon( KIcon( QLatin1String( "view-calendar-birthday" ) ) ); break;
83  case Anniversary: mSelectButton->setIcon( KIcon( QLatin1String( "view-calendar-wedding-anniversary" ) ) ); break;
84  }
85 
86  layout->addWidget( mSelectButton );
87 
88  mMenu = new KDatePickerPopup( KDatePickerPopup::DatePicker, QDate(), this );
89  mSelectButton->setMenu( mMenu );
90 
91  connect( mClearButton, SIGNAL(clicked()), SLOT(resetDate()) );
92  connect( mMenu, SIGNAL(dateChanged(QDate)), SLOT(dateSelected(QDate)) );
93  connect( mView, SIGNAL(resetDate()), SLOT(resetDate()) );
94 
95  updateView();
96 }
97 
98 DateEditWidget::~DateEditWidget()
99 {
100 }
101 
102 void DateEditWidget::setDate( const QDate &date )
103 {
104  mDate = date;
105  mMenu->setDate( mDate );
106  updateView();
107 }
108 
109 QDate DateEditWidget::date() const
110 {
111  return mDate;
112 }
113 
114 void DateEditWidget::setReadOnly( bool readOnly )
115 {
116  mReadOnly = readOnly;
117 
118  mSelectButton->setEnabled( !readOnly );
119  mClearButton->setEnabled( !readOnly );
120 }
121 
122 void DateEditWidget::dateSelected(const QDate &date)
123 {
124  mDate = date;
125  updateView();
126 }
127 
128 void DateEditWidget::resetDate()
129 {
130  mDate = QDate();
131  updateView();
132 }
133 
134 void DateEditWidget::updateView()
135 {
136  if ( mDate.isValid() ) {
137  mView->setText( KGlobal::locale()->formatDate( mDate ) );
138  mClearButton->show();
139  } else {
140  mView->setText( QString() );
141  mClearButton->hide();
142  }
143 }
144 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:28:42 by doxygen 1.8.3.1 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.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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