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(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( TQWidget::StrongFocus );
130 setHScrollBarMode(AlwaysOff);
131 setVScrollBarMode(AlwaysOff);
139 : TQGridView(parent, name, (f | TQt::WNoAutoErase))
141 d =
new KDateTablePrivate;
143 setFocusPolicy( TQWidget::StrongFocus );
146 setHScrollBarMode(AlwaysOff);
147 setVScrollBarMode(AlwaysOff);
149 setDate(TQDate::currentDate());
158 void KDateTable::initAccels()
161 accel->
insert(TDEStdAccel::Next,
this, TQ_SLOT(nextMonth()));
162 accel->
insert(TDEStdAccel::Prior,
this, TQ_SLOT(previousMonth()));
163 accel->
insert(TDEStdAccel::Home,
this, TQ_SLOT(beginningOfMonth()));
164 accel->
insert(TDEStdAccel::End,
this, TQ_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());
417 TQGridView::viewportResizeEvent(e);
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 )
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() == TQt::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(
this)),
619 setFrameStyle(TQFrame::NoFrame);
621 connect(
this, TQ_SIGNAL(returnPressed()), TQ_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() != TQt::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() & TQt::LeftButton)
791 mouseCoord = e->pos();
792 row=rowAt(mouseCoord.y());
793 col=columnAt(mouseCoord.x());
794 int tmpRow = -1, tmpCol = -1;
797 if ( activeCol > -1 )
805 bool differentCell = (activeRow != row || activeCol != col);
806 if ( activeCol > -1 && differentCell)
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(
this)),
860 setFrameStyle(TQFrame::NoFrame);
862 val->setRange(0, 8000);
864 connect(
this, TQ_SIGNAL(returnPressed()), TQ_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 =
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" static TQColor inactiveTitleColor()
virtual TQString monthName(int month, int year, bool shortName=false) const=0
void setFontSize(int size)
Set the font size of the date table.
int numdays
The number of days in the current month.
KDateInternalMonthPicker(const TQDate &date, TQWidget *parent, const char *name=0)
The constructor.
void setPopupMenuEnabled(bool enable)
Enables a popup menu when right clicking on a date.
virtual TQDate addMonths(const TQDate &date, int nmonths) const=0
void aboutToShowContextMenu(TDEPopupMenu *menu, const TQDate &date)
A popup menu for a given date is about to be shown (as when the user right clicks on that date and th...
void setupPainter(TQPainter *p)
Set up the painter.
static TQColor activeTitleColor()
void beep(const TQString &reason=TQString::null)
virtual int year(const TQDate &date) const=0
static TQColor baseColor()
int getResult() const
Return the result.
const KCalendarSystem * calendar() const
virtual TQSize sizeHint() const
Returns a recommended size for the widget.
kdbgstream kdDebug(int area=0)
virtual void contentsMousePressEvent(TQMouseEvent *e)
Catch mouse click and move events to paint a rectangle around the item.
TQSize sizeHint() const
The size hint.
bool setDate(const TQDate &)
Select and display this date.
int numDaysPrevMonth
The number of days in the previous month.
TDEAccelAction * insert(const TQString &sAction, const TQString &sLabel, const TQString &sWhatsThis, const TDEShortcut &cutDef, const TQObject *pObjSlot, const char *psMethodSlot, bool bConfigurable=true, bool bEnabled=true)
virtual TQString dayString(const TQDate &pDate, bool bShort) const
static TQColor activeTextColor()
void tableClicked()
A date has been selected by clicking on the table.
static TQColor inactiveTextColor()
virtual int daysInMonth(const TQDate &date) const=0
virtual void paintCell(TQPainter *, int, int)
Paint a cell.
TQDate date
The currently selected date.
void unsetCustomDatePainting(const TQDate &date)
Unsets the custom painting of a date so that the date is painted as usual.
static TQRect desktopGeometry(const TQPoint &point)
const TQDate & date() const
int posFromDate(const TQDate &date)
calculate the position of the cell in the matrix for the given date.
bool readSettings(TDEConfigBase *pConfig=0)
TQRect maxCell
Save the size of the largest used cell content.
void dateChanged(TQDate)
The selected date changed.
static TQFont generalFont()
static TQColor textColor()
~KDateTable()
The destructor.
KDateTable(TQWidget *parent=0, TQDate date=TQDate::currentDate(), const char *name=0, WFlags f=0)
The constructor.
virtual int month(const TQDate &date) const=0
virtual TQString weekDayName(int weekDay, bool shortName=false) const=0
void setCustomDatePainting(const TQDate &date, const TQColor &fgColor, BackgroundMode bgMode=NoBgMode, const TQColor &bgColor=TQColor())
Makes a given date be painted with a given foregroundColor, and background (a rectangle, or a circle/ellipse) in a given color.
virtual void viewportResizeEvent(TQResizeEvent *)
Handle the resize events.
virtual int day(const TQDate &date) const=0
virtual void contentsMousePressEvent(TQMouseEvent *)
React on mouse clicks that select a date.
static TDELocale * locale()
virtual void viewportResizeEvent(TQResizeEvent *)
The resize event.
bool popupMenuEnabled() const
Returns if the popup menu is enabled or not.
virtual void contentsMouseReleaseEvent(TQMouseEvent *e)
Emit monthSelected(int) when a cell has been released.
int firstday
The day of the first day in the month [1..7].
kndbgstream & endl(kndbgstream &s)
virtual int weekDayOfPray() const=0
virtual TQDate addDays(const TQDate &date, int ndays) const=0
TQDate readDate(const TQString &str, bool *ok=0) const
TQDate dateFromPos(int pos)
calculate the date that is displayed at a given cell in the matrix.
virtual void paintEmptyArea(TQPainter *, int, int, int, int)
Paint the empty area (background).
int fontsize
The font size of the displayed text.
~KDateInternalMonthPicker()
The destructor.
virtual void paintCell(TQPainter *painter, int row, int col)
Paint a cell.
virtual TQString calendarName() const=0
virtual bool setYMD(TQDate &date, int y, int m, int d) const=0