• 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
kdatepickerpopup.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  Copyright (c) 2004 Bram Schoenmakers <bramschoenmakers@kde.nl>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public 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
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "kdatepickerpopup_p.h"
23 
24 #include <KDatePicker>
25 #include <KLocale>
26 
27 #include <QtCore/QDateTime>
28 #include <QWidgetAction>
29 
30 class KDatePickerAction : public QWidgetAction
31 {
32  public:
33  KDatePickerAction( KDatePicker *widget, QObject *parent )
34  : QWidgetAction( parent ),
35  mDatePicker( widget ), mOriginalParent( widget->parentWidget() )
36  {
37  }
38 
39  protected:
40  QWidget *createWidget( QWidget *parent )
41  {
42  mDatePicker->setParent( parent );
43  return mDatePicker;
44  }
45 
46  void deleteWidget( QWidget *widget )
47  {
48  if ( widget != mDatePicker ) {
49  return;
50  }
51 
52  mDatePicker->setParent( mOriginalParent );
53  }
54 
55  private:
56  KDatePicker *mDatePicker;
57  QWidget *mOriginalParent;
58 };
59 
60 KDatePickerPopup::KDatePickerPopup( Items items, const QDate &date, QWidget *parent )
61  : QMenu( parent )
62 {
63  mItems = items;
64  mDate = date;
65  mDatePicker = new KDatePicker( this );
66  mDatePicker->setCloseButton( false );
67 
68  connect( mDatePicker, SIGNAL(dateEntered(QDate)),
69  SLOT(slotDateChanged(QDate)) );
70  connect( mDatePicker, SIGNAL(dateSelected(QDate)),
71  SLOT(slotDateChanged(QDate)) );
72 
73  connect( this, SIGNAL(aboutToHide()), SLOT(slotHidePickerPopup()));
74  mDatePicker->setDate( date );
75 
76  buildMenu();
77 }
78 
79 void KDatePickerPopup::slotHidePickerPopup()
80 {
81  if (mDatePicker->date() != mDate) {
82  emit dateChanged( mDatePicker->date() );
83  }
84 }
85 
86 void KDatePickerPopup::buildMenu()
87 {
88  if ( isVisible() ) {
89  return;
90  }
91  clear();
92 
93  if ( mItems & DatePicker ) {
94  addAction( new KDatePickerAction( mDatePicker, this ) );
95 
96  if ( ( mItems & NoDate ) || ( mItems & Words ) ) {
97  addSeparator();
98  }
99  }
100 
101  if ( mItems & Words ) {
102  addAction( i18nc( "@option today", "&Today" ), this, SLOT(slotToday()) );
103  addAction( i18nc( "@option tomorrow", "To&morrow" ), this, SLOT(slotTomorrow()) );
104  addAction( i18nc( "@option next week", "Next &Week" ), this, SLOT(slotNextWeek()) );
105  addAction( i18nc( "@option next month", "Next M&onth" ), this, SLOT(slotNextMonth()) );
106 
107  if ( mItems & NoDate ) {
108  addSeparator();
109  }
110  }
111 
112  if ( mItems & NoDate ) {
113  addAction( i18nc( "@option do not specify a date", "No Date" ), this, SLOT(slotNoDate()) );
114  }
115 }
116 
117 KDatePicker *KDatePickerPopup::datePicker() const
118 {
119  return mDatePicker;
120 }
121 
122 void KDatePickerPopup::setDate( const QDate &date )
123 {
124  mDatePicker->setDate( date );
125 }
126 
127 #if 0
128 void KDatePickerPopup::setItems( int items )
129 {
130  mItems = items;
131  buildMenu();
132 }
133 #endif
134 
135 void KDatePickerPopup::slotDateChanged( const QDate &/*date*/ )
136 {
137  hide();
138 }
139 
140 void KDatePickerPopup::slotToday()
141 {
142  emit dateChanged( QDate::currentDate() );
143 }
144 
145 void KDatePickerPopup::slotTomorrow()
146 {
147  emit dateChanged( QDate::currentDate().addDays( 1 ) );
148 }
149 
150 void KDatePickerPopup::slotNoDate()
151 {
152  emit dateChanged( QDate() );
153 }
154 
155 void KDatePickerPopup::slotNextWeek()
156 {
157  emit dateChanged( QDate::currentDate().addDays( 7 ) );
158 }
159 
160 void KDatePickerPopup::slotNextMonth()
161 {
162  emit dateChanged( QDate::currentDate().addMonths( 1 ) );
163 }
164 
165 #include "moc_kdatepickerpopup_p.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:28:43 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