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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • 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 <klocalizedstring.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::StyledPanel );
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  setFocusProxy( mSelectButton );
88  setFocusPolicy( Qt::StrongFocus );
89 
90  mMenu = new KDatePickerPopup( KDatePickerPopup::DatePicker, QDate(), this );
91  mSelectButton->setMenu( mMenu );
92 
93  connect( mClearButton, SIGNAL(clicked()), SLOT(resetDate()) );
94  connect( mMenu, SIGNAL(dateChanged(QDate)), SLOT(dateSelected(QDate)) );
95  connect( mView, SIGNAL(resetDate()), SLOT(resetDate()) );
96 
97  updateView();
98 }
99 
100 DateEditWidget::~DateEditWidget()
101 {
102 }
103 
104 void DateEditWidget::setDate( const QDate &date )
105 {
106  mDate = date;
107  mMenu->setDate( mDate );
108  updateView();
109 }
110 
111 QDate DateEditWidget::date() const
112 {
113  return mDate;
114 }
115 
116 void DateEditWidget::setReadOnly( bool readOnly )
117 {
118  mReadOnly = readOnly;
119 
120  mSelectButton->setEnabled( !readOnly );
121  mClearButton->setEnabled( !readOnly );
122 }
123 
124 void DateEditWidget::dateSelected(const QDate &date)
125 {
126  mDate = date;
127  updateView();
128 }
129 
130 void DateEditWidget::resetDate()
131 {
132  mDate = QDate();
133  updateView();
134 }
135 
136 void DateEditWidget::updateView()
137 {
138  if ( mDate.isValid() ) {
139  mView->setText( KGlobal::locale()->formatDate( mDate ) );
140  mClearButton->show();
141  } else {
142  mView->setText( QString() );
143  mClearButton->hide();
144  }
145 }
146 
KDatePickerPopup
This menu helps the user to select a date quickly.
Definition: kdatepickerpopup_p.h:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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