• 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
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 <KLocalizedString>
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  mDatePicker->setDate( date );
74 
75  buildMenu();
76 }
77 
78 void KDatePickerPopup::buildMenu()
79 {
80  if ( isVisible() ) {
81  return;
82  }
83  clear();
84 
85  if ( mItems & DatePicker ) {
86  addAction( new KDatePickerAction( mDatePicker, this ) );
87 
88  if ( ( mItems & NoDate ) || ( mItems & Words ) ) {
89  addSeparator();
90  }
91  }
92 
93  if ( mItems & Words ) {
94  addAction( i18nc( "@option today", "&Today" ), this, SLOT(slotToday()) );
95  addAction( i18nc( "@option tomorrow", "To&morrow" ), this, SLOT(slotTomorrow()) );
96  addAction( i18nc( "@option next week", "Next &Week" ), this, SLOT(slotNextWeek()) );
97  addAction( i18nc( "@option next month", "Next M&onth" ), this, SLOT(slotNextMonth()) );
98 
99  if ( mItems & NoDate ) {
100  addSeparator();
101  }
102  }
103 
104  if ( mItems & NoDate ) {
105  addAction( i18nc( "@option do not specify a date", "No Date" ), this, SLOT(slotNoDate()) );
106  }
107 }
108 
109 KDatePicker *KDatePickerPopup::datePicker() const
110 {
111  return mDatePicker;
112 }
113 
114 void KDatePickerPopup::setDate( const QDate &date )
115 {
116  mDatePicker->setDate( date );
117 }
118 
119 #if 0
120 void KDatePickerPopup::setItems( int items )
121 {
122  mItems = items;
123  buildMenu();
124 }
125 #endif
126 
127 void KDatePickerPopup::slotDateChanged( const QDate &date )
128 {
129  if (date != mDate) {
130  emit dateChanged( date );
131  }
132  hide();
133 }
134 
135 void KDatePickerPopup::slotToday()
136 {
137  emit dateChanged( QDate::currentDate() );
138 }
139 
140 void KDatePickerPopup::slotTomorrow()
141 {
142  emit dateChanged( QDate::currentDate().addDays( 1 ) );
143 }
144 
145 void KDatePickerPopup::slotNoDate()
146 {
147  emit dateChanged( QDate() );
148 }
149 
150 void KDatePickerPopup::slotNextWeek()
151 {
152  emit dateChanged( QDate::currentDate().addDays( 7 ) );
153 }
154 
155 void KDatePickerPopup::slotNextMonth()
156 {
157  emit dateChanged( QDate::currentDate().addMonths( 1 ) );
158 }
159 
160 #include "moc_kdatepickerpopup_p.cpp"
KDatePickerPopup::dateChanged
void dateChanged(const QDate &date)
This signal emits the new date (selected with datepicker or other menu-items).
KDatePickerPopup::datePicker
KDatePicker * datePicker() const
Definition: kdatepickerpopup.cpp:109
KDatePickerPopup::KDatePickerPopup
KDatePickerPopup(Items items=DatePicker, const QDate &date=QDate::currentDate(), QWidget *parent=0)
A constructor for the KDatePickerPopup.
Definition: kdatepickerpopup.cpp:60
KDatePickerPopup::items
int items() const
Definition: kdatepickerpopup_p.h:87
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