35 #include <tdeconfig.h>
36 #include <tdeglobal.h>
37 #include <tdeglobalsettings.h>
38 #include <tdeapplication.h>
42 #include <knotifyclient.h>
43 #include <kcalendarsystem.h>
44 #include <tdeshortcut.h>
45 #include <tdestdaccel.h>
46 #include "kdatepicker.h"
48 #include "tdepopupmenu.h"
49 #include <tqdatetime.h>
50 #include <tqguardedptr.h>
53 #include <tqpainter.h>
59 class KDateTable::KDateTablePrivate
65 useCustomColors=
false;
75 struct DatePaintingMode
79 BackgroundMode bgMode;
81 TQDict <DatePaintingMode> customPaintingModes;
86 KDateValidator::KDateValidator(TQWidget* parent,
const char* name)
87 : TQValidator(TQT_TQOBJECT(parent), name)
92 KDateValidator::validate(TQString& text,
int&)
const
96 return date(text, temp);
100 KDateValidator::date(
const TQString& text, TQDate& d)
const
112 KDateValidator::fixup( TQString& )
const
118 : TQGridView(parent, name, (f | TQt::WNoAutoErase))
120 d =
new KDateTablePrivate;
124 kdDebug() <<
"KDateTable ctor: WARNING: Given date is invalid, using current date." <<
endl;
125 date_=TQDate::currentDate();
127 setFocusPolicy( TQ_StrongFocus );
130 setHScrollBarMode(AlwaysOff);
131 setVScrollBarMode(AlwaysOff);
139 : TQGridView(parent, name, (f | TQt::WNoAutoErase))
141 d =
new KDateTablePrivate;
143 setFocusPolicy( TQ_StrongFocus );
146 setHScrollBarMode(AlwaysOff);
147 setVScrollBarMode(AlwaysOff);
149 setDate(TQDate::currentDate());
158 void KDateTable::initAccels()
161 accel->
insert(TDEStdAccel::Next, TQT_TQOBJECT(
this), TQT_SLOT(nextMonth()));
162 accel->
insert(TDEStdAccel::Prior, TQT_TQOBJECT(
this), TQT_SLOT(previousMonth()));
163 accel->
insert(TDEStdAccel::Home, TQT_TQOBJECT(
this), TQT_SLOT(beginningOfMonth()));
164 accel->
insert(TDEStdAccel::End, TQT_TQOBJECT(
this), TQT_SLOT(endOfMonth()));
174 int pos = calendar->
day( dt );
175 int offset = (
firstday - firstWeekDay + 7) % 7;
178 if ( offset < 1 ) offset += 7;
189 int offset = (
firstday - firstWeekDay + 7) % 7;
192 if ( offset < 1 ) offset += 7;
193 pCellDate = calendar->
addDays( pCellDate, pos - offset );
201 TQRect unusedRight = frameRect();
202 unusedRight.setLeft(gridSize().width());
204 TQRect unusedBottom = frameRect();
205 unusedBottom.setTop(gridSize().height());
207 paint->eraseRect(unusedRight);
208 paint->eraseRect(unusedBottom);
227 painter->setFont(font);
228 bool normalday =
true;
230 int daynum = ( col+firstWeekDay < 8 ) ? col+firstWeekDay :
233 ( daynum == 6 && calendar->
calendarName() ==
"gregorian" ) )
236 TQBrush brushInvertTitle(colorGroup().base());
241 painter->setPen(textColor);
242 painter->setBrush(textColor);
243 painter->drawRect(0, 0, w, h);
244 painter->setPen(titleColor);
246 painter->setPen(titleColor);
247 painter->setBrush(titleColor);
248 painter->drawRect(0, 0, w, h);
249 painter->setPen(textColor);
251 painter->drawText(0, 0, w, h-1, AlignCenter,
253 painter->setPen(colorGroup().text());
254 painter->moveTo(0, h-1);
255 painter->lineTo(w-1, h-1);
259 painter->setFont(font);
260 int pos=7*(row-1)+col;
264 text = calendar->
dayString(pCellDate,
true);
270 painter->setPen( colorGroup().mid() );
273 if ( d->useCustomColors )
275 KDateTablePrivate::DatePaintingMode *mode=d->customPaintingModes[pCellDate.toString()];
278 if (mode->bgMode != NoBgMode)
280 TQBrush oldbrush=painter->brush();
281 painter->setBrush( mode->bgColor );
284 case(CircleMode) : painter->drawEllipse(0,0,w,h);
break;
285 case(RectangleMode) : painter->drawRect(0,0,w,h);
break;
290 painter->setBrush( oldbrush );
293 painter->setPen( mode->fgColor );
295 painter->setPen(colorGroup().text());
297 painter->setPen(colorGroup().text());
306 if( (offset+d) == (pos+1))
311 painter->setPen(colorGroup().highlight());
312 painter->setBrush(colorGroup().highlight());
316 painter->setPen(colorGroup().text());
317 painter->setBrush(colorGroup().text());
319 pen=TQPen(colorGroup().highlightedText());
321 painter->setBrush(paletteBackgroundColor());
322 painter->setPen(paletteBackgroundColor());
327 if ( pCellDate == TQDate::currentDate() )
329 painter->setPen(colorGroup().text());
332 if ( paintRect ) painter->drawRect(0, 0, w, h);
333 painter->setPen(pen);
334 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect);
337 if(rect.height()>
maxCell.height())
maxCell.setHeight(rect.height());
340 void KDateTable::nextMonth()
346 void KDateTable::previousMonth()
352 void KDateTable::beginningOfMonth()
357 void KDateTable::endOfMonth()
362 void KDateTable::beginningOfWeek()
367 void KDateTable::endOfWeek()
373 KDateTable::keyPressEvent( TQKeyEvent *e )
395 setDate(TQDate::currentDate());
419 setCellWidth(viewport()->width()/7);
420 setCellHeight(viewport()->height()/7);
427 TQFontMetrics metrics(fontMetrics());
434 for(count=0; count<7; ++count)
437 ->weekDayName(count+1,
true));
442 rect=metrics.boundingRect(TQString::fromLatin1(
"88"));
448 KDateTable::wheelEvent ( TQWheelEvent * e )
450 setDate(TQT_TQDATE_OBJECT(
date.addMonths( -(
int)(e->delta()/120)) ));
458 if(e->type()!=TQEvent::MouseButtonPress)
469 int row, col, pos, temp;
472 mouseCoord = e->pos();
473 row=rowAt(mouseCoord.y());
474 col=columnAt(mouseCoord.x());
486 pos = (7 * (row - 1)) + col;
495 updateCell( temp/7+1, temp%7 );
496 updateCell( row, col );
500 if ( e->button() == Qt::RightButton && d->popupMenuEnabled )
505 menu->popup(e->globalPos());
517 kdDebug() <<
"KDateTable::setDate: refusing to set invalid date." <<
endl;
539 repaintContents(
false);
545 KDateTable::getDate()
const
551 void KDateTable::focusInEvent( TQFocusEvent *e )
554 TQGridView::focusInEvent( e );
557 void KDateTable::focusOutEvent( TQFocusEvent *e )
560 TQGridView::focusOutEvent( e );
568 return TQSize(
maxCell.width()*numCols()+2*frameWidth(),
569 (
maxCell.height()+2)*numRows()+2*frameWidth());
571 kdDebug() <<
"KDateTable::sizeHint: obscure failure - " <<
endl;
572 return TQSize(-1, -1);
578 d->popupMenuEnabled=enable;
583 return d->popupMenuEnabled;
588 if (!fgColor.isValid())
594 KDateTablePrivate::DatePaintingMode *mode=
new KDateTablePrivate::DatePaintingMode;
596 mode->fgColor=fgColor;
597 mode->bgColor=bgColor;
599 d->customPaintingModes.replace( date.toString(), mode );
600 d->useCustomColors=
true;
606 d->customPaintingModes.remove( date.toString() );
609 KDateInternalWeekSelector::KDateInternalWeekSelector
610 (TQWidget* parent,
const char* name)
611 : TQLineEdit(parent, name),
612 val(new TQIntValidator(TQT_TQOBJECT(this))),
619 setFrameStyle(TQFrame::NoFrame);
621 connect(
this, TQT_SIGNAL(returnPressed()), TQT_SLOT(weekEnteredSlot()));
625 KDateInternalWeekSelector::weekEnteredSlot()
630 week=text().toInt(&ok);
642 KDateInternalWeekSelector::getWeek()
648 KDateInternalWeekSelector::setWeek(
int week)
657 KDateInternalWeekSelector::setMaxWeek(
int max)
659 val->setRange(1, max);
665 class KDateInternalMonthPicker::KDateInternalMonthPrivate {
667 KDateInternalMonthPrivate (
int y,
int m,
int d)
668 : year(y), month(m), day(d)
680 (
const TQDate & date, TQWidget* parent,
const char* name)
681 : TQGridView(parent, name),
691 setHScrollBarMode(AlwaysOff);
692 setVScrollBarMode(AlwaysOff);
693 setFrameStyle(TQFrame::NoFrame);
695 d =
new KDateInternalMonthPrivate(date.year(), date.month(), date.day());
703 TQFontMetrics metrics(font);
704 for(
int i = 1; ; ++i)
708 if (str.isNull())
break;
709 rect=metrics.boundingRect(str);
710 if(max.width()<rect.width()) max.setWidth(rect.width());
711 if(max.height()<rect.height()) max.setHeight(rect.height());
718 return TQSize((max.width()+6)*numCols()+2*frameWidth(),
719 (max.height()+6)*numRows()+2*frameWidth());
737 setCellWidth(width() / numCols());
738 setCellHeight(height() / numRows());
751 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
752 if (
activeCol == col && activeRow == row )
753 painter->drawRect( 0, 0, cellWidth(), cellHeight() );
759 if(!isEnabled() || e->button() != Qt::LeftButton)
768 mouseCoord = e->pos();
769 row=rowAt(mouseCoord.y());
770 col=columnAt(mouseCoord.x());
779 updateCell( row, col );
784 KDateInternalMonthPicker::contentsMouseMoveEvent(TQMouseEvent *e)
786 if (e->state() & Qt::LeftButton)
791 mouseCoord = e->pos();
792 row=rowAt(mouseCoord.y());
793 col=columnAt(mouseCoord.x());
794 int tmpRow = -1, tmpCol = -1;
805 bool differentCell = (activeRow != row ||
activeCol != col);
815 updateCell( row, col );
819 updateCell( tmpRow, tmpCol );
834 mouseCoord = e->pos();
835 row=rowAt(mouseCoord.y());
836 col=columnAt(mouseCoord.x());
850 KDateInternalYearSelector::KDateInternalYearSelector
851 (TQWidget* parent,
const char* name)
852 : TQLineEdit(parent, name),
853 val(new TQIntValidator(TQT_TQOBJECT(this))),
860 setFrameStyle(TQFrame::NoFrame);
862 val->setRange(0, 8000);
864 connect(
this, TQT_SIGNAL(returnPressed()), TQT_SLOT(yearEnteredSlot()));
868 KDateInternalYearSelector::yearEnteredSlot()
874 year=text().toInt(&ok);
894 KDateInternalYearSelector::getYear()
900 KDateInternalYearSelector::setYear(
int year)
908 class TDEPopupFrame::TDEPopupFramePrivate
911 TDEPopupFramePrivate() :
exec(false) {}
917 : TQFrame(parent, name, (WFlags)WType_Popup),
920 d(new TDEPopupFramePrivate)
922 setFrameStyle(TQFrame::Box|TQFrame::Raised);
934 if(e->key()==Key_Escape)
967 resize(
main->width()+2*frameWidth(),
main->height()+2*frameWidth());
976 main->setGeometry(frameWidth(), frameWidth(),
977 width()-2*frameWidth(), height()-2*frameWidth());
991 if (x+w > d.x()+d.width())
993 if (y+h > d.y()+d.height())
1011 const TQGuardedPtr<TQObject> that = TQT_TQOBJECT(
this);
1012 tqApp->enter_loop();
1014 return TQDialog::Rejected;
1022 return exec(TQPoint(x, y));
1025 void TDEPopupFrame::virtual_hook(
int,
void* )
1028 void KDateTable::virtual_hook(
int,
void* )
1031 #include "kdatetbl.moc"