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

libkdepim

  • sources
  • kde-4.12
  • kdepim
  • libkdepim
  • widgets
kdatepickerpopup.cpp
Go to the documentation of this file.
1 /*
2  This file is part of libkdepim.
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.h"
23 
24 #include <KDatePicker>
25 #include <KLocale>
26 
27 #include <QtCore/QDateTime>
28 #include <QWidgetAction>
29 
30 using namespace KPIM;
31 
32 class KDatePickerAction : public QWidgetAction
33 {
34  public:
35  KDatePickerAction( KDatePicker *widget, QObject *parent )
36  : QWidgetAction( parent ),
37  mDatePicker( widget ), mOriginalParent( widget->parentWidget() )
38  {
39  }
40 
41  protected:
42  QWidget *createWidget( QWidget *parent )
43  {
44  mDatePicker->setParent( parent );
45  return mDatePicker;
46  }
47 
48  void deleteWidget( QWidget *widget )
49  {
50  if ( widget != mDatePicker ) {
51  return;
52  }
53 
54  mDatePicker->setParent( mOriginalParent );
55  }
56 
57  private:
58  KDatePicker *mDatePicker;
59  QWidget *mOriginalParent;
60 };
61 
62 class KDatePickerPopup::Private
63 {
64  public:
65  Private( KDatePickerPopup *qq )
66  : q( qq ), mDatePicker( 0 )
67  {
68  }
69 
70  void buildMenu();
71 
72  void slotDateChanged( const QDate& );
73  void slotToday();
74  void slotTomorrow();
75  void slotNextWeek();
76  void slotNextMonth();
77  void slotNoDate();
78 
79  KDatePickerPopup *q;
80  KDatePicker *mDatePicker;
81  Modes mModes;
82 };
83 
84 void KDatePickerPopup::Private::buildMenu()
85 {
86  if ( q->isVisible() )
87  return;
88 
89  q->clear();
90 
91  if ( mModes & DatePicker ) {
92  q->addAction( new KDatePickerAction( mDatePicker, q ) );
93 
94  if ( (mModes & NoDate) || (mModes & Words) )
95  q->addSeparator();
96  }
97 
98  if ( mModes & Words ) {
99  q->addAction( i18nc( "@option today", "&Today" ), q, SLOT(slotToday()) );
100  q->addAction( i18nc( "@option tomorrow", "To&morrow" ), q, SLOT(slotTomorrow()) );
101  q->addAction( i18nc( "@option next week", "Next &Week" ), q, SLOT(slotNextWeek()) );
102  q->addAction( i18nc( "@option next month", "Next M&onth" ), q, SLOT(slotNextMonth()) );
103 
104  if ( mModes & NoDate )
105  q->addSeparator();
106  }
107 
108  if ( mModes & NoDate )
109  q->addAction( i18nc( "@option do not specify a date", "No Date" ), q, SLOT(slotNoDate()) );
110 }
111 
112 void KDatePickerPopup::Private::slotDateChanged( const QDate &date )
113 {
114  emit q->dateChanged( date );
115  q->hide();
116 }
117 
118 void KDatePickerPopup::Private::slotToday()
119 {
120  emit q->dateChanged( QDate::currentDate() );
121 }
122 
123 void KDatePickerPopup::Private::slotTomorrow()
124 {
125  emit q->dateChanged( QDate::currentDate().addDays( 1 ) );
126 }
127 
128 void KDatePickerPopup::Private::slotNoDate()
129 {
130  emit q->dateChanged( QDate() );
131 }
132 
133 void KDatePickerPopup::Private::slotNextWeek()
134 {
135  emit q->dateChanged( QDate::currentDate().addDays( 7 ) );
136 }
137 
138 void KDatePickerPopup::Private::slotNextMonth()
139 {
140  emit q->dateChanged( QDate::currentDate().addMonths( 1 ) );
141 }
142 
143 
144 KDatePickerPopup::KDatePickerPopup( Modes modes, const QDate &date, QWidget *parent )
145  : QMenu( parent ), d( new Private( this ) )
146 {
147  d->mModes = modes;
148 
149  d->mDatePicker = new KDatePicker( this );
150  d->mDatePicker->setCloseButton( false );
151 
152  connect( d->mDatePicker, SIGNAL(dateEntered(QDate)),
153  SLOT(slotDateChanged(QDate)) );
154  connect( d->mDatePicker, SIGNAL(dateSelected(QDate)),
155  SLOT(slotDateChanged(QDate)) );
156 
157  d->mDatePicker->setDate( date );
158 
159  d->buildMenu();
160 }
161 
162 KDatePickerPopup::~KDatePickerPopup()
163 {
164  delete d;
165 }
166 
167 KDatePicker *KDatePickerPopup::datePicker() const
168 {
169  return d->mDatePicker;
170 }
171 
172 void KDatePickerPopup::setDate( const QDate &date )
173 {
174  d->mDatePicker->setDate( date );
175 }
176 
177 #include "kdatepickerpopup.moc"
KPIM::KDatePickerPopup::KDatePickerPopup
KDatePickerPopup(Modes modes=DatePicker, const QDate &date=QDate::currentDate(), QWidget *parent=0)
Describes the a set of combined modes.
Definition: kdatepickerpopup.cpp:144
QWidget
QObject
KPIM::KDatePickerPopup::setDate
void setDate(const QDate &date)
Sets the current date.
Definition: kdatepickerpopup.cpp:172
KPIM::KDatePickerPopup::datePicker
KDatePicker * datePicker() const
Returns the used KDatePicker object.
Definition: kdatepickerpopup.cpp:167
QMenu
KPIM::KDatePickerPopup::dateChanged
void dateChanged(const QDate &date)
This signal is emitted whenever the user has selected a new date.
kdatepickerpopup.h
KPIM::KDatePickerPopup
This menu helps the user to select a date quickly.
Definition: kdatepickerpopup.h:48
KPIM::KDatePickerPopup::~KDatePickerPopup
~KDatePickerPopup()
Destroys the date picker popup.
Definition: kdatepickerpopup.cpp:162
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

Skip menu "libkdepim"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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