2
This file is part of libkdepim.
4
Copyright (c) 2004 Bram Schoenmakers <bramschoenmakers@kde.nl>
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.
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.
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.
22
#include "kdatepickerpopup.h"
24
#include <KDatePicker>
27
#include <QtCore/QDateTime>
28
#include <QtGui/QWidgetAction>
30
class KDatePickerAction : public QWidgetAction
33
KDatePickerAction( KDatePicker *widget, QObject *parent )
34
: QWidgetAction( parent ),
35
mDatePicker( widget ), mOriginalParent( widget->parentWidget() )
40
QWidget *createWidget( QWidget *parent )
42
mDatePicker->setParent( parent );
46
void deleteWidget( QWidget *widget )
48
if ( widget != mDatePicker ) {
52
mDatePicker->setParent( mOriginalParent );
56
KDatePicker *mDatePicker;
57
QWidget *mOriginalParent;
60
KDatePickerPopup::KDatePickerPopup( Items items, const QDate &date, QWidget *parent )
65
mDatePicker = new KDatePicker( this );
66
mDatePicker->setCloseButton( false );
68
connect( mDatePicker, SIGNAL( dateEntered( const QDate& ) ),
69
SLOT( slotDateChanged( const QDate& ) ) );
70
connect( mDatePicker, SIGNAL( dateSelected( const QDate& ) ),
71
SLOT( slotDateChanged( const QDate& ) ) );
73
mDatePicker->setDate( date );
78
void KDatePickerPopup::buildMenu()
85
if ( mItems & DatePicker ) {
86
addAction( new KDatePickerAction( mDatePicker, this ) );
88
if ( ( mItems & NoDate ) || ( mItems & Words ) ) {
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() ) );
99
if ( mItems & NoDate ) {
104
if ( mItems & NoDate ) {
105
addAction( i18nc( "@option do not specify a date", "No Date" ), this, SLOT( slotNoDate() ) );
109
KDatePicker *KDatePickerPopup::datePicker() const
114
void KDatePickerPopup::setDate( const QDate &date )
116
mDatePicker->setDate( date );
120
void KDatePickerPopup::setItems( int items )
127
void KDatePickerPopup::slotDateChanged( const QDate &date )
129
emit dateChanged( date );
133
void KDatePickerPopup::slotToday()
135
emit dateChanged( QDate::currentDate() );
138
void KDatePickerPopup::slotTomorrow()
140
emit dateChanged( QDate::currentDate().addDays( 1 ) );
143
void KDatePickerPopup::slotNoDate()
145
emit dateChanged( QDate() );
148
void KDatePickerPopup::slotNextWeek()
150
emit dateChanged( QDate::currentDate().addDays( 7 ) );
153
void KDatePickerPopup::slotNextMonth()
155
emit dateChanged( QDate::currentDate().addMonths( 1 ) );
158
#include "kdatepickerpopup.moc"