23 #include <tqpainter.h>
26 #include <tqtoolbutton.h>
27 #include <tqcombobox.h>
28 #include <tqtooltip.h>
30 #include <tqvalidator.h>
31 #include <tqpopupmenu.h>
34 #include "kdatepicker.h"
35 #include <tdeglobal.h>
36 #include <tdeapplication.h>
39 #include <kiconloader.h>
40 #include <tdetoolbar.h>
41 #include <klineedit.h>
43 #include <knotifyclient.h>
44 #include <kcalendarsystem.h>
47 #include "kdatepicker.moc"
52 class KDatePicker::KDatePickerPrivate
55 KDatePickerPrivate() : closeButton(0L), selectWeek(0L), todayButton(0), navigationLayout(0) {}
57 void fillWeeksCombo(
const TQDate &
date);
59 TQToolButton *closeButton;
60 TQComboBox *selectWeek;
61 TQToolButton *todayButton;
62 TQBoxLayout *navigationLayout;
65 void KDatePicker::fillWeeksCombo(
const TQDate &date)
73 d->selectWeek->clear();
80 calendar->
setYMD(day, year, 1, 1);
82 TQDate lastDay, firstDayOfLastMonth;
83 calendar->
setYMD(firstDayOfLastMonth, year, lastMonth, 1);
84 calendar->
setYMD(lastDay, year, lastMonth, calendar->
daysInMonth(firstDayOfLastMonth));
86 for (; day <= lastDay ; day = calendar->
addDays(day, 7 ) )
88 TQString week = i18n(
"Week %1").arg(calendar->
weekNumber(day, &year));
89 if ( year != calendar->
year(day) ) week +=
"*";
90 d->selectWeek->insertItem(week);
94 if(day < lastDay && day.daysTo(lastDay) < 7 && calendar->
weekNumber(day) != calendar->
weekNumber(lastDay))
95 day = lastDay.addDays(-7);
100 : TQFrame(parent,name)
106 : TQFrame(parent,name, f)
112 : TQFrame(parent,name)
114 init( TQDate::currentDate() );
117 void KDatePicker::init(
const TQDate &dt )
119 d =
new KDatePickerPrivate();
121 TQBoxLayout * topLayout =
new TQVBoxLayout(
this);
123 d->navigationLayout =
new TQHBoxLayout(topLayout);
124 d->navigationLayout->addStretch();
148 d->navigationLayout->addStretch();
159 d->selectWeek =
new TQComboBox(
false,
this);
160 d->todayButton =
new TQToolButton(
this);
161 d->todayButton->setIconSet(SmallIconSet(
"today"));
167 TQToolTip::add(d->selectWeek, i18n(
"Select a week"));
168 TQToolTip::add(
selectMonth, i18n(
"Select a month"));
169 TQToolTip::add(
selectYear, i18n(
"Select a year"));
170 TQToolTip::add(d->todayButton, i18n(
"Select the current day"));
175 line->installEventFilter(
this );
176 if ( TQApplication::reverseLayout() )
178 yearForward->setIconSet(BarIconSet(TQString::fromLatin1(
"2leftarrow")));
179 yearBackward->setIconSet(BarIconSet(TQString::fromLatin1(
"2rightarrow")));
180 monthForward->setIconSet(BarIconSet(TQString::fromLatin1(
"1leftarrow")));
181 monthBackward->setIconSet(BarIconSet(TQString::fromLatin1(
"1rightarrow")));
185 yearForward->setIconSet(BarIconSet(TQString::fromLatin1(
"2rightarrow")));
186 yearBackward->setIconSet(BarIconSet(TQString::fromLatin1(
"2leftarrow")));
187 monthForward->setIconSet(BarIconSet(TQString::fromLatin1(
"1rightarrow")));
188 monthBackward->setIconSet(BarIconSet(TQString::fromLatin1(
"1leftarrow")));
190 connect(
table, TQ_SIGNAL(
dateChanged(TQDate)), TQ_SLOT(dateChangedSlot(TQDate)));
192 connect(
monthForward, TQ_SIGNAL(clicked()), TQ_SLOT(monthForwardClicked()));
193 connect(
monthBackward, TQ_SIGNAL(clicked()), TQ_SLOT(monthBackwardClicked()));
194 connect(
yearForward, TQ_SIGNAL(clicked()), TQ_SLOT(yearForwardClicked()));
195 connect(
yearBackward, TQ_SIGNAL(clicked()), TQ_SLOT(yearBackwardClicked()));
196 connect(d->selectWeek, TQ_SIGNAL(activated(
int)), TQ_SLOT(
weekSelected(
int)));
204 topLayout->addWidget(
table);
206 TQBoxLayout * bottomLayout =
new TQHBoxLayout(topLayout);
207 bottomLayout->addWidget(d->todayButton);
208 bottomLayout->addWidget(
line);
209 bottomLayout->addWidget(d->selectWeek);
223 if ( e->type() == TQEvent::KeyPress ) {
224 TQKeyEvent *k = (TQKeyEvent *)e;
226 if ( (k->key() == TQt::Key_Prior) ||
227 (k->key() == TQt::Key_Next) ||
228 (k->key() == TQt::Key_Up) ||
229 (k->key() == TQt::Key_Down) )
231 TQApplication::sendEvent(
table, e );
236 return TQFrame::eventFilter( o, e );
242 TQWidget::resizeEvent(e);
246 KDatePicker::dateChangedSlot(TQDate date)
248 kdDebug(298) <<
"KDatePicker::dateChangedSlot: date changed (" <<
date.year() <<
"/" <<
date.month() <<
"/" <<
date.day() <<
")." <<
endl;
254 fillWeeksCombo(
date);
266 KDatePicker::tableClickedSlot()
268 kdDebug(298) <<
"KDatePicker::tableClickedSlot: table clicked." <<
endl;
276 return table->getDate();
282 return table->getDate();
295 kdDebug(298) <<
"KDatePicker::setDate: refusing to set invalid date." <<
endl;
301 KDatePicker::monthForwardClicked()
310 KDatePicker::monthBackwardClicked()
319 KDatePicker::yearForwardClicked()
328 KDatePicker::yearBackwardClicked()
364 for (i = 1; i <= months; i++)
367 popup.setActiveItem(calendar->
month(
date) - 1);
369 if ( (month = popup.exec(
selectMonth->mapToGlobal(TQPoint(0, 0)), calendar->
month(
date) - 1)) == -1 )
return;
393 picker->resize(picker->sizeHint());
394 picker->setYear(
table->getDate().year() );
397 connect(picker, TQ_SIGNAL(closeMe(
int)), popup, TQ_SLOT(close(
int)));
404 year=picker->getYear();
419 TQTimer::singleShot(0,
this, TQ_SLOT(ensureSelectYearIsUp()));
423 KDatePicker::ensureSelectYearIsUp()
434 TQWidget *widgets[]= {
437 line,
table, d->selectWeek, d->todayButton };
438 const int Size=
sizeof(widgets)/
sizeof(widgets[0]);
441 for(count=0; count<Size; ++count)
443 widgets[count]->setEnabled(enable);
452 if(
val->date(
line->text(), temp)==TQValidator::Acceptable)
454 kdDebug(298) <<
"KDatePicker::lineEnterPressed: valid date entered." <<
endl;
459 kdDebug(298) <<
"KDatePicker::lineEnterPressed: invalid date entered." <<
endl;
466 setDate(TQDate::currentDate());
472 return TQWidget::sizeHint();
478 TQWidget *buttons[]= {
486 const int NoOfButtons=
sizeof(buttons)/
sizeof(buttons[0]);
492 for(count=0; count<NoOfButtons; ++count)
494 font=buttons[count]->font();
495 font.setPointSize(s);
496 buttons[count]->setFont(font);
500 for (
int i = 1; ; ++i)
504 if (str.isNull())
break;
505 r=metrics.boundingRect(str);
510 TQSize metricBound = style().sizeFromContents(TQStyle::CT_ToolButton,
521 if ( enable == (d->closeButton != 0L) )
525 d->closeButton =
new TQToolButton(
this );
526 d->closeButton->setAutoRaise(
true);
528 d->navigationLayout->addWidget(d->closeButton);
529 TQToolTip::add(d->closeButton, i18n(
"Close"));
530 d->closeButton->setPixmap( SmallIcon(
"remove") );
531 connect( d->closeButton, TQ_SIGNAL( clicked() ),
532 topLevelWidget(), TQ_SLOT( close() ) );
535 delete d->closeButton;
544 return (d->closeButton);
547 void KDatePicker::virtual_hook(
int ,
void* )
virtual TQDate addYears(const TQDate &date, int nyears) const=0
virtual int dayOfYear(const TQDate &date) const=0
virtual int monthsInYear(const TQDate &date) const=0
virtual int dayOfWeek(const TQDate &date) const=0
virtual int daysInMonth(const TQDate &date) const=0
virtual int weekNumber(const TQDate &date, int *yearNum=0) const=0
virtual int day(const TQDate &date) const=0
virtual TQDate addDays(const TQDate &date, int ndays) const=0
virtual int month(const TQDate &date) const=0
virtual TQString yearString(const TQDate &pDate, bool bShort) const
virtual TQString monthName(int month, int year, bool shortName=false) const=0
virtual bool setYMD(TQDate &date, int y, int m, int d) const=0
virtual int year(const TQDate &date) const=0
virtual TQDate addMonths(const TQDate &date, int nmonths) const=0
TQSize sizeHint() const
The size hint for date pickers.
void setEnabled(bool)
Enables or disables the widget.
bool setDate(const TQDate &)
Sets the date.
void todayButtonClicked()
virtual ~KDatePicker()
The destructor.
TQSize maxMonthRect
the size calculated during resize events
TQLineEdit * line
the line edit to enter the date directly
void dateChanged(TQDate)
This signal is emitted each time the selected date is changed.
void dateSelected(TQDate)
This signal is emitted each time a day has been selected by clicking on the table (hitting a day in t...
bool hasCloseButton() const
void setFontSize(int)
Sets the font size of the widgets elements.
virtual void resizeEvent(TQResizeEvent *)
the resize event
TQToolButton * yearBackward
the year backward button
virtual bool eventFilter(TQObject *o, TQEvent *e)
to catch move keyEvents when TQLineEdit has keyFocus
KDateValidator * val
the validator for the line edit:
const TQDate & getDate() const TDE_DEPRECATED
Returns the selected date.
TQToolButton * selectMonth
the button for selecting the month directly
void setCloseButton(bool enable)
By calling this method with enable = true, KDatePicker will show a little close-button in the upper b...
void selectMonthClicked()
TQToolButton * selectYear
the button for selecting the year directly
void dateEntered(TQDate)
This signal is emitted when enter is pressed and a VALID date has been entered before into the line e...
KDatePicker(TQWidget *parent=0, TQDate=TQDate::currentDate(), const char *name=0)
The usual constructor.
const TQDate & date() const
KDateTable * table
the date table
TQToolButton * monthBackward
the month backward button
TQToolButton * yearForward
the year forward button
void tableClicked()
This signal is emitted when the day has been selected by clicking on it in the table.
TQToolButton * monthForward
the month forward button
void setFontSize(int size)
Set the font size of the date table.
bool setDate(const TQDate &)
Select and display this date.
Validates user-entered dates.
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
An enhanced TQLineEdit widget for inputting text.
static TQFont generalFont()
static TDELocale * locale()
const KCalendarSystem * calendar() const
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
void beep(const TQString &reason=TQString::null)