libtdepim

kdatepickerpopup.cpp
1/*
2 This file is part of libtdepim.
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 <tqdatetime.h>
23#include <tqpopupmenu.h>
24
25#include <tdelocale.h>
26
27#include "kdatepickerpopup.h"
28
29KDatePickerPopup::KDatePickerPopup( int items, const TQDate &date, TQWidget *parent,
30 const char *name )
31 : TQPopupMenu( parent, name )
32{
33 mItems = items;
34
35 mDatePicker = new KDatePicker( this );
36 mDatePicker->setCloseButton( false );
37
38 connect( mDatePicker, TQ_SIGNAL( dateEntered( TQDate ) ),
39 TQ_SLOT( slotDateChanged( TQDate ) ) );
40 connect( mDatePicker, TQ_SIGNAL( dateSelected( TQDate ) ),
41 TQ_SLOT( slotDateChanged( TQDate ) ) );
42
43 mDatePicker->setDate( date );
44
45 buildMenu();
46}
47
48void KDatePickerPopup::buildMenu()
49{
50 if ( isVisible() ) return;
51 clear();
52
53 if ( mItems & DatePicker ) {
54 insertItem( mDatePicker );
55
56 if ( ( mItems & NoDate ) || ( mItems & Words ) )
57 insertSeparator();
58 }
59
60 if ( mItems & Words ) {
61 insertItem( i18n("&Today"), this, TQ_SLOT( slotToday() ) );
62 insertItem( i18n("To&morrow"), this, TQ_SLOT( slotTomorrow() ) );
63 insertItem( i18n("Next &Week"), this, TQ_SLOT( slotNextWeek() ) );
64 insertItem( i18n("Next M&onth"), this, TQ_SLOT( slotNextMonth() ) );
65
66 if ( mItems & NoDate )
67 insertSeparator();
68 }
69
70 if ( mItems & NoDate )
71 insertItem( i18n("No Date"), this, TQ_SLOT( slotNoDate() ) );
72}
73
74KDatePicker *KDatePickerPopup::datePicker() const
75{
76 return mDatePicker;
77}
78
79void KDatePickerPopup::setDate( const TQDate &date )
80{
81 mDatePicker->setDate( date );
82}
83
84#if 0
85void KDatePickerPopup::setItems( int items )
86{
87 mItems = items;
88 buildMenu();
89}
90#endif
91
92void KDatePickerPopup::slotDateChanged( TQDate date )
93{
94 emit dateChanged( date );
95 hide();
96}
97
98void KDatePickerPopup::slotToday()
99{
100 emit dateChanged( TQDate::currentDate() );
101}
102
103void KDatePickerPopup::slotTomorrow()
104{
105 emit dateChanged( TQDate::currentDate().addDays( 1 ) );
106}
107
108void KDatePickerPopup::slotNoDate()
109{
110 emit dateChanged( TQDate() );
111}
112
113void KDatePickerPopup::slotNextWeek()
114{
115 emit dateChanged( TQDate::currentDate().addDays( 7 ) );
116}
117
118void KDatePickerPopup::slotNextMonth()
119{
120 emit dateChanged( TQDate::currentDate().addMonths( 1 ) );
121}
122
123#include "kdatepickerpopup.moc"
KDatePickerPopup(int items=DatePicker, const TQDate &date=TQDate::currentDate(), TQWidget *parent=0, const char *name=0)
A constructor for the KDatePickerPopup.
void dateChanged(TQDate)
This signal emits the new date (selected with datepicker or other menu-items).
KDatePicker * datePicker() const