• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kdatetbl.cpp
1 /*
2  This file is part of the KDE libraries
3  Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
4  (C) 1998-2001 Mirko Boehm (mirko@kde.org)
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
22 //
23 // Copyright (C) 1997 Tim D. Gilman
24 // (C) 1998-2001 Mirko Boehm
25 // Written using Qt (http://www.troll.no) for the
26 // KDE project (http://www.kde.org)
27 //
28 // This is a support class for the KDatePicker class. It just
29 // draws the calender table without titles, but could theoretically
30 // be used as a standalone.
31 //
32 // When a date is selected by the user, it emits a signal:
33 // dateSelected(TQDate)
34 
35 #include <tdeconfig.h>
36 #include <tdeglobal.h>
37 #include <tdeglobalsettings.h>
38 #include <tdeapplication.h>
39 #include <tdeaccel.h>
40 #include <tdelocale.h>
41 #include <kdebug.h>
42 #include <knotifyclient.h>
43 #include <kcalendarsystem.h>
44 #include <tdeshortcut.h>
45 #include <tdestdaccel.h>
46 #include "kdatepicker.h"
47 #include "kdatetbl.h"
48 #include "tdepopupmenu.h"
49 #include <tqdatetime.h>
50 #include <tqguardedptr.h>
51 #include <tqstring.h>
52 #include <tqpen.h>
53 #include <tqpainter.h>
54 #include <tqdialog.h>
55 #include <tqdict.h>
56 #include <assert.h>
57 
58 
59 class KDateTable::KDateTablePrivate
60 {
61 public:
62  KDateTablePrivate()
63  {
64  popupMenuEnabled=false;
65  useCustomColors=false;
66  }
67 
68  ~KDateTablePrivate()
69  {
70  }
71 
72  bool popupMenuEnabled;
73  bool useCustomColors;
74 
75  struct DatePaintingMode
76  {
77  TQColor fgColor;
78  TQColor bgColor;
79  BackgroundMode bgMode;
80  };
81  TQDict <DatePaintingMode> customPaintingModes;
82 
83 };
84 
85 
86 KDateValidator::KDateValidator(TQWidget* parent, const char* name)
87  : TQValidator(TQT_TQOBJECT(parent), name)
88 {
89 }
90 
91 TQValidator::State
92 KDateValidator::validate(TQString& text, int&) const
93 {
94  TQDate temp;
95  // ----- everything is tested in date():
96  return date(text, temp);
97 }
98 
99 TQValidator::State
100 KDateValidator::date(const TQString& text, TQDate& d) const
101 {
102  TQDate tmp = TDEGlobal::locale()->readDate(text);
103  if (!tmp.isNull())
104  {
105  d = tmp;
106  return Acceptable;
107  } else
108  return Valid;
109 }
110 
111 void
112 KDateValidator::fixup( TQString& ) const
113 {
114 
115 }
116 
117 KDateTable::KDateTable(TQWidget *parent, TQDate date_, const char* name, WFlags f)
118  : TQGridView(parent, name, (f | TQt::WNoAutoErase))
119 {
120  d = new KDateTablePrivate;
121  setFontSize(10);
122  if(!date_.isValid())
123  {
124  kdDebug() << "KDateTable ctor: WARNING: Given date is invalid, using current date." << endl;
125  date_=TQDate::currentDate();
126  }
127  setFocusPolicy( TQ_StrongFocus );
128  setNumRows(7); // 6 weeks max + headline
129  setNumCols(7); // 7 days a week
130  setHScrollBarMode(AlwaysOff);
131  setVScrollBarMode(AlwaysOff);
132  viewport()->setEraseColor(TDEGlobalSettings::baseColor());
133  setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth
134 
135  initAccels();
136 }
137 
138 KDateTable::KDateTable(TQWidget *parent, const char* name, WFlags f)
139  : TQGridView(parent, name, (f | TQt::WNoAutoErase))
140 {
141  d = new KDateTablePrivate;
142  setFontSize(10);
143  setFocusPolicy( TQ_StrongFocus );
144  setNumRows(7); // 6 weeks max + headline
145  setNumCols(7); // 7 days a week
146  setHScrollBarMode(AlwaysOff);
147  setVScrollBarMode(AlwaysOff);
148  viewport()->setEraseColor(TDEGlobalSettings::baseColor());
149  setDate(TQDate::currentDate()); // this initializes firstday, numdays, numDaysPrevMonth
150  initAccels();
151 }
152 
153 KDateTable::~KDateTable()
154 {
155  delete d;
156 }
157 
158 void KDateTable::initAccels()
159 {
160  TDEAccel* accel = new TDEAccel(this, "date table accel");
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()));
165  accel->insert(TDEStdAccel::BeginningOfLine, TQT_TQOBJECT(this), TQT_SLOT(beginningOfWeek()));
166  accel->insert(TDEStdAccel::EndOfLine, TQT_TQOBJECT(this), TQT_SLOT(endOfWeek()));
167  accel->readSettings();
168 }
169 
170 int KDateTable::posFromDate( const TQDate &dt )
171 {
172  const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
173  const int firstWeekDay = TDEGlobal::locale()->weekStartDay();
174  int pos = calendar->day( dt );
175  int offset = (firstday - firstWeekDay + 7) % 7;
176  // make sure at least one day of the previous month is visible.
177  // adjust this <1 if more days should be forced visible:
178  if ( offset < 1 ) offset += 7;
179  return pos + offset;
180 }
181 
182 TQDate KDateTable::dateFromPos( int pos )
183 {
184  TQDate pCellDate;
185  const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
186  calendar->setYMD(pCellDate, calendar->year(date), calendar->month(date), 1);
187 
188  int firstWeekDay = TDEGlobal::locale()->weekStartDay();
189  int offset = (firstday - firstWeekDay + 7) % 7;
190  // make sure at least one day of the previous month is visible.
191  // adjust this <1 if more days should be forced visible:
192  if ( offset < 1 ) offset += 7;
193  pCellDate = calendar->addDays( pCellDate, pos - offset );
194  return pCellDate;
195 }
196 
197 void
198 KDateTable::paintEmptyArea(TQPainter *paint, int, int, int, int)
199 {
200  // Erase the unused areas on the right and bottom.
201  TQRect unusedRight = frameRect();
202  unusedRight.setLeft(gridSize().width());
203 
204  TQRect unusedBottom = frameRect();
205  unusedBottom.setTop(gridSize().height());
206 
207  paint->eraseRect(unusedRight);
208  paint->eraseRect(unusedBottom);
209 }
210 
211 void
212 KDateTable::paintCell(TQPainter *painter, int row, int col)
213 {
214  const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
215 
216  TQRect rect;
217  TQString text;
218  TQPen pen;
219  int w=cellWidth();
220  int h=cellHeight();
221  TQFont font=TDEGlobalSettings::generalFont();
222  // -----
223 
224  if(row == 0)
225  { // we are drawing the headline
226  font.setBold(true);
227  painter->setFont(font);
228  bool normalday = true;
229  int firstWeekDay = TDEGlobal::locale()->weekStartDay();
230  int daynum = ( col+firstWeekDay < 8 ) ? col+firstWeekDay :
231  col+firstWeekDay-7;
232  if ( daynum == calendar->weekDayOfPray() ||
233  ( daynum == 6 && calendar->calendarName() == "gregorian" ) )
234  normalday=false;
235 
236  TQBrush brushInvertTitle(colorGroup().base());
237  TQColor titleColor(isEnabled()?( TDEGlobalSettings::activeTitleColor() ):( TDEGlobalSettings::inactiveTitleColor() ) );
238  TQColor textColor(isEnabled()?( TDEGlobalSettings::activeTextColor() ):( TDEGlobalSettings::inactiveTextColor() ) );
239  if (!normalday)
240  {
241  painter->setPen(textColor);
242  painter->setBrush(textColor);
243  painter->drawRect(0, 0, w, h);
244  painter->setPen(titleColor);
245  } else {
246  painter->setPen(titleColor);
247  painter->setBrush(titleColor);
248  painter->drawRect(0, 0, w, h);
249  painter->setPen(textColor);
250  }
251  painter->drawText(0, 0, w, h-1, AlignCenter,
252  calendar->weekDayName(daynum, true), -1, &rect);
253  painter->setPen(colorGroup().text());
254  painter->moveTo(0, h-1);
255  painter->lineTo(w-1, h-1);
256  // ----- draw the weekday:
257  } else {
258  bool paintRect=true;
259  painter->setFont(font);
260  int pos=7*(row-1)+col;
261 
262  TQDate pCellDate = dateFromPos( pos );
263  // First day of month
264  text = calendar->dayString(pCellDate, true);
265  if( calendar->month(pCellDate) != calendar->month(date) )
266  { // we are either
267  // ° painting a day of the previous month or
268  // ° painting a day of the following month
269  // TODO: don't hardcode gray here! Use a color with less contrast to the background than normal text.
270  painter->setPen( colorGroup().mid() );
271 // painter->setPen(gray);
272  } else { // paint a day of the current month
273  if ( d->useCustomColors )
274  {
275  KDateTablePrivate::DatePaintingMode *mode=d->customPaintingModes[pCellDate.toString()];
276  if (mode)
277  {
278  if (mode->bgMode != NoBgMode)
279  {
280  TQBrush oldbrush=painter->brush();
281  painter->setBrush( mode->bgColor );
282  switch(mode->bgMode)
283  {
284  case(CircleMode) : painter->drawEllipse(0,0,w,h);break;
285  case(RectangleMode) : painter->drawRect(0,0,w,h);break;
286  case(NoBgMode) : // Should never be here, but just to get one
287  // less warning when compiling
288  default: break;
289  }
290  painter->setBrush( oldbrush );
291  paintRect=false;
292  }
293  painter->setPen( mode->fgColor );
294  } else
295  painter->setPen(colorGroup().text());
296  } else //if ( firstWeekDay < 4 ) // <- this doesn' make sense at all!
297  painter->setPen(colorGroup().text());
298  }
299 
300  pen=painter->pen();
301  int firstWeekDay=TDEGlobal::locale()->weekStartDay();
302  int offset=firstday-firstWeekDay;
303  if(offset<1)
304  offset+=7;
305  int d = calendar->day(date);
306  if( (offset+d) == (pos+1))
307  {
308  // draw the currently selected date
309  if (isEnabled())
310  {
311  painter->setPen(colorGroup().highlight());
312  painter->setBrush(colorGroup().highlight());
313  }
314  else
315  {
316  painter->setPen(colorGroup().text());
317  painter->setBrush(colorGroup().text());
318  }
319  pen=TQPen(colorGroup().highlightedText());
320  } else {
321  painter->setBrush(paletteBackgroundColor());
322  painter->setPen(paletteBackgroundColor());
323 // painter->setBrush(colorGroup().base());
324 // painter->setPen(colorGroup().base());
325  }
326 
327  if ( pCellDate == TQDate::currentDate() )
328  {
329  painter->setPen(colorGroup().text());
330  }
331 
332  if ( paintRect ) painter->drawRect(0, 0, w, h);
333  painter->setPen(pen);
334  painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect);
335  }
336  if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
337  if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height());
338 }
339 
340 void KDateTable::nextMonth()
341 {
342  const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
343  setDate(calendar->addMonths( date, 1 ));
344 }
345 
346 void KDateTable::previousMonth()
347 {
348  const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
349  setDate(calendar->addMonths( date, -1 ));
350 }
351 
352 void KDateTable::beginningOfMonth()
353 {
354  setDate(TQT_TQDATE_OBJECT(date.addDays(1 - date.day())));
355 }
356 
357 void KDateTable::endOfMonth()
358 {
359  setDate(TQT_TQDATE_OBJECT(date.addDays(date.daysInMonth() - date.day())));
360 }
361 
362 void KDateTable::beginningOfWeek()
363 {
364  setDate(TQT_TQDATE_OBJECT(date.addDays(1 - date.dayOfWeek())));
365 }
366 
367 void KDateTable::endOfWeek()
368 {
369  setDate(TQT_TQDATE_OBJECT(date.addDays(7 - date.dayOfWeek())));
370 }
371 
372 void
373 KDateTable::keyPressEvent( TQKeyEvent *e )
374 {
375  switch( e->key() ) {
376  case Key_Up:
377  setDate(TQT_TQDATE_OBJECT(date.addDays(-7)));
378  break;
379  case Key_Down:
380  setDate(TQT_TQDATE_OBJECT(date.addDays(7)));
381  break;
382  case Key_Left:
383  setDate(TQT_TQDATE_OBJECT(date.addDays(-1)));
384  break;
385  case Key_Right:
386  setDate(TQT_TQDATE_OBJECT(date.addDays(1)));
387  break;
388  case Key_Minus:
389  setDate(TQT_TQDATE_OBJECT(date.addDays(-1)));
390  break;
391  case Key_Plus:
392  setDate(TQT_TQDATE_OBJECT(date.addDays(1)));
393  break;
394  case Key_N:
395  setDate(TQDate::currentDate());
396  break;
397  case Key_Return:
398  case Key_Enter:
399  emit tableClicked();
400  break;
401  case Key_Control:
402  case Key_Alt:
403  case Key_Meta:
404  case Key_Shift:
405  // Don't beep for modifiers
406  break;
407  default:
408  if (!e->state()) { // hm
409  KNotifyClient::beep();
410 }
411  }
412 }
413 
414 void
415 KDateTable::viewportResizeEvent(TQResizeEvent * e)
416 {
417  TQGridView::viewportResizeEvent(e);
418 
419  setCellWidth(viewport()->width()/7);
420  setCellHeight(viewport()->height()/7);
421 }
422 
423 void
424 KDateTable::setFontSize(int size)
425 {
426  int count;
427  TQFontMetrics metrics(fontMetrics());
428  TQRect rect;
429  // ----- store rectangles:
430  fontsize=size;
431  // ----- find largest day name:
432  maxCell.setWidth(0);
433  maxCell.setHeight(0);
434  for(count=0; count<7; ++count)
435  {
436  rect=metrics.boundingRect(TDEGlobal::locale()->calendar()
437  ->weekDayName(count+1, true));
438  maxCell.setWidth(TQMAX(maxCell.width(), rect.width()));
439  maxCell.setHeight(TQMAX(maxCell.height(), rect.height()));
440  }
441  // ----- compare with a real wide number and add some space:
442  rect=metrics.boundingRect(TQString::fromLatin1("88"));
443  maxCell.setWidth(TQMAX(maxCell.width()+2, rect.width()));
444  maxCell.setHeight(TQMAX(maxCell.height()+4, rect.height()));
445 }
446 
447 void
448 KDateTable::wheelEvent ( TQWheelEvent * e )
449 {
450  setDate(TQT_TQDATE_OBJECT(date.addMonths( -(int)(e->delta()/120)) ));
451  e->accept();
452 }
453 
454 void
455 KDateTable::contentsMousePressEvent(TQMouseEvent *e)
456 {
457 
458  if(e->type()!=TQEvent::MouseButtonPress)
459  { // the KDatePicker only reacts on mouse press events:
460  return;
461  }
462  if(!isEnabled())
463  {
464  KNotifyClient::beep();
465  return;
466  }
467 
468  // -----
469  int row, col, pos, temp;
470  TQPoint mouseCoord;
471  // -----
472  mouseCoord = e->pos();
473  row=rowAt(mouseCoord.y());
474  col=columnAt(mouseCoord.x());
475  if(row<1 || col<0)
476  { // the user clicked on the frame of the table
477  return;
478  }
479 
480  // Rows and columns are zero indexed. The (row - 1) below is to avoid counting
481  // the row with the days of the week in the calculation.
482 
483  // old selected date:
484  temp = posFromDate( date );
485  // new position and date
486  pos = (7 * (row - 1)) + col;
487  TQDate clickedDate = dateFromPos( pos );
488 
489  // set the new date. If it is in the previous or next month, the month will
490  // automatically be changed, no need to do that manually...
491  setDate( clickedDate );
492 
493  // call updateCell on the old and new selection. If setDate switched to a different
494  // month, these cells will be painted twice, but that's no problem.
495  updateCell( temp/7+1, temp%7 );
496  updateCell( row, col );
497 
498  emit tableClicked();
499 
500  if ( e->button() == Qt::RightButton && d->popupMenuEnabled )
501  {
502  TDEPopupMenu *menu = new TDEPopupMenu();
503  menu->insertTitle( TDEGlobal::locale()->formatDate(clickedDate) );
504  emit aboutToShowContextMenu( menu, clickedDate );
505  menu->popup(e->globalPos());
506  }
507 }
508 
509 bool
510 KDateTable::setDate(const TQDate& date_)
511 {
512  bool changed=false;
513  TQDate temp;
514  // -----
515  if(!date_.isValid())
516  {
517  kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
518  return false;
519  }
520  if(date!=date_)
521  {
522  emit(dateChanged(date, date_));
523  date=date_;
524  emit(dateChanged(date));
525  changed=true;
526  }
527  const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
528 
529  calendar->setYMD(temp, calendar->year(date), calendar->month(date), 1);
530  //temp.setYMD(date.year(), date.month(), 1);
531  //kdDebug() << "firstDayInWeek: " << temp.toString() << endl;
532  firstday=temp.dayOfWeek();
533  numdays=calendar->daysInMonth(date);
534 
535  temp = calendar->addMonths(temp, -1);
536  numDaysPrevMonth=calendar->daysInMonth(temp);
537  if(changed)
538  {
539  repaintContents(false);
540  }
541  return true;
542 }
543 
544 const TQDate&
545 KDateTable::getDate() const
546 {
547  return date;
548 }
549 
550 // what are those repaintContents() good for? (pfeiffer)
551 void KDateTable::focusInEvent( TQFocusEvent *e )
552 {
553 // repaintContents(false);
554  TQGridView::focusInEvent( e );
555 }
556 
557 void KDateTable::focusOutEvent( TQFocusEvent *e )
558 {
559 // repaintContents(false);
560  TQGridView::focusOutEvent( e );
561 }
562 
563 TQSize
564 KDateTable::sizeHint() const
565 {
566  if(maxCell.height()>0 && maxCell.width()>0)
567  {
568  return TQSize(maxCell.width()*numCols()+2*frameWidth(),
569  (maxCell.height()+2)*numRows()+2*frameWidth());
570  } else {
571  kdDebug() << "KDateTable::sizeHint: obscure failure - " << endl;
572  return TQSize(-1, -1);
573  }
574 }
575 
576 void KDateTable::setPopupMenuEnabled( bool enable )
577 {
578  d->popupMenuEnabled=enable;
579 }
580 
581 bool KDateTable::popupMenuEnabled() const
582 {
583  return d->popupMenuEnabled;
584 }
585 
586 void KDateTable::setCustomDatePainting(const TQDate &date, const TQColor &fgColor, BackgroundMode bgMode, const TQColor &bgColor)
587 {
588  if (!fgColor.isValid())
589  {
590  unsetCustomDatePainting( date );
591  return;
592  }
593 
594  KDateTablePrivate::DatePaintingMode *mode=new KDateTablePrivate::DatePaintingMode;
595  mode->bgMode=bgMode;
596  mode->fgColor=fgColor;
597  mode->bgColor=bgColor;
598 
599  d->customPaintingModes.replace( date.toString(), mode );
600  d->useCustomColors=true;
601  update();
602 }
603 
604 void KDateTable::unsetCustomDatePainting( const TQDate &date )
605 {
606  d->customPaintingModes.remove( date.toString() );
607 }
608 
609 KDateInternalWeekSelector::KDateInternalWeekSelector
610 (TQWidget* parent, const char* name)
611  : TQLineEdit(parent, name),
612  val(new TQIntValidator(TQT_TQOBJECT(this))),
613  result(0)
614 {
615  TQFont font;
616  // -----
617  font=TDEGlobalSettings::generalFont();
618  setFont(font);
619  setFrameStyle(TQFrame::NoFrame);
620  setValidator(val);
621  connect(this, TQT_SIGNAL(returnPressed()), TQT_SLOT(weekEnteredSlot()));
622 }
623 
624 void
625 KDateInternalWeekSelector::weekEnteredSlot()
626 {
627  bool ok;
628  int week;
629  // ----- check if this is a valid week:
630  week=text().toInt(&ok);
631  if(!ok)
632  {
633  KNotifyClient::beep();
634  emit(closeMe(0));
635  return;
636  }
637  result=week;
638  emit(closeMe(1));
639 }
640 
641 int
642 KDateInternalWeekSelector::getWeek()
643 {
644  return result;
645 }
646 
647 void
648 KDateInternalWeekSelector::setWeek(int week)
649 {
650  TQString temp;
651  // -----
652  temp.setNum(week);
653  setText(temp);
654 }
655 
656 void
657 KDateInternalWeekSelector::setMaxWeek(int max)
658 {
659  val->setRange(1, max);
660 }
661 
662 // ### CFM To avoid binary incompatibility.
663 // In future releases, remove this and replace by a QDate
664 // private member, needed in KDateInternalMonthPicker::paintCell
665 class KDateInternalMonthPicker::KDateInternalMonthPrivate {
666 public:
667  KDateInternalMonthPrivate (int y, int m, int d)
668  : year(y), month(m), day(d)
669  {}
670  int year;
671  int month;
672  int day;
673 };
674 
675 KDateInternalMonthPicker::~KDateInternalMonthPicker() {
676  delete d;
677 }
678 
679 KDateInternalMonthPicker::KDateInternalMonthPicker
680 (const TQDate & date, TQWidget* parent, const char* name)
681  : TQGridView(parent, name),
682  result(0) // invalid
683 {
684  TQRect rect;
685  TQFont font;
686  // -----
687  activeCol = -1;
688  activeRow = -1;
689  font=TDEGlobalSettings::generalFont();
690  setFont(font);
691  setHScrollBarMode(AlwaysOff);
692  setVScrollBarMode(AlwaysOff);
693  setFrameStyle(TQFrame::NoFrame);
694  setNumCols(3);
695  d = new KDateInternalMonthPrivate(date.year(), date.month(), date.day());
696  // For monthsInYear != 12
697  setNumRows( (TDEGlobal::locale()->calendar()->monthsInYear(date) + 2) / 3);
698  // enable to find drawing failures:
699  // setTableFlags(Tbl_clipCellPainting);
700  viewport()->setEraseColor(TDEGlobalSettings::baseColor()); // for consistency with the datepicker
701  // ----- find the preferred size
702  // (this is slow, possibly, but unfortunately it is needed here):
703  TQFontMetrics metrics(font);
704  for(int i = 1; ; ++i)
705  {
706  TQString str = TDEGlobal::locale()->calendar()->monthName(i,
707  TDEGlobal::locale()->calendar()->year(date), false);
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());
712  }
713 }
714 
715 TQSize
716 KDateInternalMonthPicker::sizeHint() const
717 {
718  return TQSize((max.width()+6)*numCols()+2*frameWidth(),
719  (max.height()+6)*numRows()+2*frameWidth());
720 }
721 
722 int
723 KDateInternalMonthPicker::getResult() const
724 {
725  return result;
726 }
727 
728 void
729 KDateInternalMonthPicker::setupPainter(TQPainter *p)
730 {
731  p->setPen(TDEGlobalSettings::textColor());
732 }
733 
734 void
735 KDateInternalMonthPicker::viewportResizeEvent(TQResizeEvent*)
736 {
737  setCellWidth(width() / numCols());
738  setCellHeight(height() / numRows());
739 }
740 
741 void
742 KDateInternalMonthPicker::paintCell(TQPainter* painter, int row, int col)
743 {
744  int index;
745  TQString text;
746  // ----- find the number of the cell:
747  index=3*row+col+1;
748  text=TDEGlobal::locale()->calendar()->monthName(index,
749  TDEGlobal::locale()->calendar()->year(TQDate(d->year, d->month,
750  d->day)), false);
751  painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
752  if ( activeCol == col && activeRow == row )
753  painter->drawRect( 0, 0, cellWidth(), cellHeight() );
754 }
755 
756 void
757 KDateInternalMonthPicker::contentsMousePressEvent(TQMouseEvent *e)
758 {
759  if(!isEnabled() || e->button() != Qt::LeftButton)
760  {
761  KNotifyClient::beep();
762  return;
763  }
764  // -----
765  int row, col;
766  TQPoint mouseCoord;
767  // -----
768  mouseCoord = e->pos();
769  row=rowAt(mouseCoord.y());
770  col=columnAt(mouseCoord.x());
771 
772  if(row<0 || col<0)
773  { // the user clicked on the frame of the table
774  activeCol = -1;
775  activeRow = -1;
776  } else {
777  activeCol = col;
778  activeRow = row;
779  updateCell( row, col /*, false */ );
780  }
781 }
782 
783 void
784 KDateInternalMonthPicker::contentsMouseMoveEvent(TQMouseEvent *e)
785 {
786  if (e->state() & Qt::LeftButton)
787  {
788  int row, col;
789  TQPoint mouseCoord;
790  // -----
791  mouseCoord = e->pos();
792  row=rowAt(mouseCoord.y());
793  col=columnAt(mouseCoord.x());
794  int tmpRow = -1, tmpCol = -1;
795  if(row<0 || col<0)
796  { // the user clicked on the frame of the table
797  if ( activeCol > -1 )
798  {
799  tmpRow = activeRow;
800  tmpCol = activeCol;
801  }
802  activeCol = -1;
803  activeRow = -1;
804  } else {
805  bool differentCell = (activeRow != row || activeCol != col);
806  if ( activeCol > -1 && differentCell)
807  {
808  tmpRow = activeRow;
809  tmpCol = activeCol;
810  }
811  if ( differentCell)
812  {
813  activeRow = row;
814  activeCol = col;
815  updateCell( row, col /*, false */ ); // mark the new active cell
816  }
817  }
818  if ( tmpRow > -1 ) // repaint the former active cell
819  updateCell( tmpRow, tmpCol /*, true */ );
820  }
821 }
822 
823 void
824 KDateInternalMonthPicker::contentsMouseReleaseEvent(TQMouseEvent *e)
825 {
826  if(!isEnabled())
827  {
828  return;
829  }
830  // -----
831  int row, col, pos;
832  TQPoint mouseCoord;
833  // -----
834  mouseCoord = e->pos();
835  row=rowAt(mouseCoord.y());
836  col=columnAt(mouseCoord.x());
837  if(row<0 || col<0)
838  { // the user clicked on the frame of the table
839  emit(closeMe(0));
840  return;
841  }
842 
843  pos=3*row+col+1;
844  result=pos;
845  emit(closeMe(1));
846 }
847 
848 
849 
850 KDateInternalYearSelector::KDateInternalYearSelector
851 (TQWidget* parent, const char* name)
852  : TQLineEdit(parent, name),
853  val(new TQIntValidator(TQT_TQOBJECT(this))),
854  result(0)
855 {
856  TQFont font;
857  // -----
858  font=TDEGlobalSettings::generalFont();
859  setFont(font);
860  setFrameStyle(TQFrame::NoFrame);
861  // we have to respect the limits of TQDate here, I fear:
862  val->setRange(0, 8000);
863  setValidator(val);
864  connect(this, TQT_SIGNAL(returnPressed()), TQT_SLOT(yearEnteredSlot()));
865 }
866 
867 void
868 KDateInternalYearSelector::yearEnteredSlot()
869 {
870  bool ok;
871  int year;
872  TQDate date;
873  // ----- check if this is a valid year:
874  year=text().toInt(&ok);
875  if(!ok)
876  {
877  KNotifyClient::beep();
878  emit(closeMe(0));
879  return;
880  }
881  //date.setYMD(year, 1, 1);
882  TDEGlobal::locale()->calendar()->setYMD(date, year, 1, 1);
883  if(!date.isValid())
884  {
885  KNotifyClient::beep();
886  emit(closeMe(0));
887  return;
888  }
889  result=year;
890  emit(closeMe(1));
891 }
892 
893 int
894 KDateInternalYearSelector::getYear()
895 {
896  return result;
897 }
898 
899 void
900 KDateInternalYearSelector::setYear(int year)
901 {
902  TQString temp;
903  // -----
904  temp.setNum(year);
905  setText(temp);
906 }
907 
908 class TDEPopupFrame::TDEPopupFramePrivate
909 {
910  public:
911  TDEPopupFramePrivate() : exec(false) {}
912 
913  bool exec;
914 };
915 
916 TDEPopupFrame::TDEPopupFrame(TQWidget* parent, const char* name)
917  : TQFrame(parent, name, (WFlags)WType_Popup),
918  result(0), // rejected
919  main(0),
920  d(new TDEPopupFramePrivate)
921 {
922  setFrameStyle(TQFrame::Box|TQFrame::Raised);
923  setMidLineWidth(2);
924 }
925 
926 TDEPopupFrame::~TDEPopupFrame()
927 {
928  delete d;
929 }
930 
931 void
932 TDEPopupFrame::keyPressEvent(TQKeyEvent* e)
933 {
934  if(e->key()==Key_Escape)
935  {
936  result=0; // rejected
937  d->exec = false;
938  tqApp->exit_loop();
939  }
940 }
941 
942 void
943 TDEPopupFrame::close(int r)
944 {
945  result=r;
946  d->exec = false;
947  tqApp->exit_loop();
948 }
949 
950 void
951 TDEPopupFrame::hide()
952 {
953  TQFrame::hide();
954  if (d->exec)
955  {
956  d->exec = false;
957  tqApp->exit_loop();
958  }
959 }
960 
961 void
962 TDEPopupFrame::setMainWidget(TQWidget* m)
963 {
964  main=m;
965  if(main)
966  {
967  resize(main->width()+2*frameWidth(), main->height()+2*frameWidth());
968  }
969 }
970 
971 void
972 TDEPopupFrame::resizeEvent(TQResizeEvent*)
973 {
974  if(main)
975  {
976  main->setGeometry(frameWidth(), frameWidth(),
977  width()-2*frameWidth(), height()-2*frameWidth());
978  }
979 }
980 
981 void
982 TDEPopupFrame::popup(const TQPoint &pos)
983 {
984  // Make sure the whole popup is visible.
985  TQRect d = TDEGlobalSettings::desktopGeometry(pos);
986 
987  int x = pos.x();
988  int y = pos.y();
989  int w = width();
990  int h = height();
991  if (x+w > d.x()+d.width())
992  x = d.width() - w;
993  if (y+h > d.y()+d.height())
994  y = d.height() - h;
995  if (x < d.x())
996  x = 0;
997  if (y < d.y())
998  y = 0;
999 
1000  // Pop the thingy up.
1001  move(x, y);
1002  show();
1003 }
1004 
1005 int
1006 TDEPopupFrame::exec(TQPoint pos)
1007 {
1008  popup(pos);
1009  repaint();
1010  d->exec = true;
1011  const TQGuardedPtr<TQObject> that = TQT_TQOBJECT(this);
1012  tqApp->enter_loop();
1013  if ( !that )
1014  return TQDialog::Rejected;
1015  hide();
1016  return result;
1017 }
1018 
1019 int
1020 TDEPopupFrame::exec(int x, int y)
1021 {
1022  return exec(TQPoint(x, y));
1023 }
1024 
1025 void TDEPopupFrame::virtual_hook( int, void* )
1026 { /*BASE::virtual_hook( id, data );*/ }
1027 
1028 void KDateTable::virtual_hook( int, void* )
1029 { /*BASE::virtual_hook( id, data );*/ }
1030 
1031 #include "kdatetbl.moc"
TDEGlobalSettings::inactiveTitleColor
static TQColor inactiveTitleColor()
KCalendarSystem::monthName
virtual TQString monthName(int month, int year, bool shortName=false) const =0
TDELocale::weekStartDay
int weekStartDay() const
KDateTable::setFontSize
void setFontSize(int size)
Set the font size of the date table.
Definition: kdatetbl.cpp:424
KDateTable::numdays
int numdays
The number of days in the current month.
Definition: kdatetbl.h:389
KDateInternalMonthPicker::KDateInternalMonthPicker
KDateInternalMonthPicker(const TQDate &date, TQWidget *parent, const char *name=0)
The constructor.
Definition: kdatetbl.cpp:680
TDEStdAccel::BeginningOfLine
TDEPopupFrame::~TDEPopupFrame
~TDEPopupFrame()
The destructor.
Definition: kdatetbl.cpp:926
KDateTable::setPopupMenuEnabled
void setPopupMenuEnabled(bool enable)
Enables a popup menu when right clicking on a date.
Definition: kdatetbl.cpp:576
KCalendarSystem::addMonths
virtual TQDate addMonths(const TQDate &date, int nmonths) const =0
KDateTable::aboutToShowContextMenu
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...
KDateTable::popupMenuEnabled
bool popupMenuEnabled() const
Returns if the popup menu is enabled or not.
Definition: kdatetbl.cpp:581
KDateInternalMonthPicker::setupPainter
void setupPainter(TQPainter *p)
Set up the painter.
Definition: kdatetbl.cpp:729
TDEGlobalSettings::activeTitleColor
static TQColor activeTitleColor()
KNotifyClient::beep
void beep(const TQString &reason=TQString::null)
TDEPopupFrame::popup
void popup(const TQPoint &pos)
Open the popup window at position pos.
Definition: kdatetbl.cpp:982
KCalendarSystem::year
virtual int year(const TQDate &date) const =0
TDEPopupFrame::setMainWidget
void setMainWidget(TQWidget *m)
Set the main widget.
Definition: kdatetbl.cpp:962
TDEGlobalSettings::baseColor
static TQColor baseColor()
KDateInternalMonthPicker::result
int result
Store the month that has been clicked [1..12].
Definition: kdatetbl.h:74
KCalendarSystem::dayString
virtual TQString dayString(const TQDate &pDate, bool bShort) const
KDateInternalMonthPicker::activeCol
short int activeCol
the cell under mouse cursor when LBM is pressed
Definition: kdatetbl.h:78
kdDebug
kdbgstream kdDebug(int area=0)
KDateInternalMonthPicker::contentsMousePressEvent
virtual void contentsMousePressEvent(TQMouseEvent *e)
Catch mouse click and move events to paint a rectangle around the item.
Definition: kdatetbl.cpp:757
TDEPopupFrame::close
void close(int r)
Close the popup window.
Definition: kdatetbl.cpp:943
KCalendarSystem
KDateTable::setDate
bool setDate(const TQDate &)
Select and display this date.
Definition: kdatetbl.cpp:510
KDateTable::numDaysPrevMonth
int numDaysPrevMonth
The number of days in the previous month.
Definition: kdatetbl.h:393
TDEPopupFrame::resizeEvent
virtual void resizeEvent(TQResizeEvent *)
The resize event.
Definition: kdatetbl.cpp:972
TDEAccel::insert
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)
TDEGlobalSettings::activeTextColor
static TQColor activeTextColor()
KDateTable::tableClicked
void tableClicked()
A date has been selected by clicking on the table.
TDEGlobalSettings::inactiveTextColor
static TQColor inactiveTextColor()
KCalendarSystem::daysInMonth
virtual int daysInMonth(const TQDate &date) const =0
TDEAccel
KDateTable::paintCell
virtual void paintCell(TQPainter *, int, int)
Paint a cell.
Definition: kdatetbl.cpp:212
KDateTable::date
TQDate date
The currently selected date.
Definition: kdatetbl.h:381
KDateTable::unsetCustomDatePainting
void unsetCustomDatePainting(const TQDate &date)
Unsets the custom painting of a date so that the date is painted as usual.
Definition: kdatetbl.cpp:604
tdelocale.h
TDEGlobalSettings::desktopGeometry
static TQRect desktopGeometry(const TQPoint &point)
KDateTable::posFromDate
int posFromDate(const TQDate &date)
calculate the position of the cell in the matrix for the given date.
Definition: kdatetbl.cpp:170
TDEPopupMenu::insertTitle
int insertTitle(const TQString &text, int id=-1, int index=-1)
Inserts a title item with no icon.
Definition: tdepopupmenu.cpp:185
TDEAccel::readSettings
bool readSettings(TDEConfigBase *pConfig=0)
KDateTable::maxCell
TQRect maxCell
Save the size of the largest used cell content.
Definition: kdatetbl.h:402
TDEPopupFrame::keyPressEvent
virtual void keyPressEvent(TQKeyEvent *e)
Catch key press events.
Definition: kdatetbl.cpp:932
KDateTable::dateChanged
void dateChanged(TQDate)
The selected date changed.
TDEGlobalSettings::generalFont
static TQFont generalFont()
TDEGlobalSettings::textColor
static TQColor textColor()
KDateTable::~KDateTable
~KDateTable()
The destructor.
Definition: kdatetbl.cpp:153
KDateTable::KDateTable
KDateTable(TQWidget *parent=0, TQDate date=TQDate::currentDate(), const char *name=0, WFlags f=0)
The constructor.
Definition: kdatetbl.cpp:117
KCalendarSystem::month
virtual int month(const TQDate &date) const =0
KCalendarSystem::weekDayName
virtual TQString weekDayName(int weekDay, bool shortName=false) const =0
KDateTable::setCustomDatePainting
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.
Definition: kdatetbl.cpp:586
TDELocale::calendar
const KCalendarSystem * calendar() const
KDateTable::viewportResizeEvent
virtual void viewportResizeEvent(TQResizeEvent *)
Handle the resize events.
Definition: kdatetbl.cpp:415
TDEPopupFrame::main
TQWidget * main
The only subwidget that uses the whole dialog window.
Definition: kdatetbl.h:181
KDateTable::sizeHint
virtual TQSize sizeHint() const
Returns a recommended size for the widget.
Definition: kdatetbl.cpp:564
KCalendarSystem::day
virtual int day(const TQDate &date) const =0
KDateTable::contentsMousePressEvent
virtual void contentsMousePressEvent(TQMouseEvent *)
React on mouse clicks that select a date.
Definition: kdatetbl.cpp:455
TDEGlobal::locale
static TDELocale * locale()
TDEPopupFrame::result
int result
The result.
Definition: kdatetbl.h:173
KDateInternalMonthPicker::viewportResizeEvent
virtual void viewportResizeEvent(TQResizeEvent *)
The resize event.
Definition: kdatetbl.cpp:735
TDEPopupFrame::exec
int exec(TQPoint p)
Execute the popup window.
Definition: kdatetbl.cpp:1006
KDateInternalMonthPicker::getResult
int getResult() const
Return the result.
Definition: kdatetbl.cpp:723
KDateInternalMonthPicker::contentsMouseReleaseEvent
virtual void contentsMouseReleaseEvent(TQMouseEvent *e)
Emit monthSelected(int) when a cell has been released.
Definition: kdatetbl.cpp:824
KDateTable::firstday
int firstday
The day of the first day in the month [1..7].
Definition: kdatetbl.h:385
TDEPopupMenu
A menu with title items.
Definition: tdepopupmenu.h:123
endl
kndbgstream & endl(kndbgstream &s)
KCalendarSystem::weekDayOfPray
virtual int weekDayOfPray() const =0
KCalendarSystem::addDays
virtual TQDate addDays(const TQDate &date, int ndays) const =0
TDEPopupFrame::TDEPopupFrame
TDEPopupFrame(TQWidget *parent=0, const char *name=0)
The contructor.
Definition: kdatetbl.cpp:916
TDEStdAccel::EndOfLine
KDateTable::dateFromPos
TQDate dateFromPos(int pos)
calculate the date that is displayed at a given cell in the matrix.
Definition: kdatetbl.cpp:182
KDateTable::paintEmptyArea
virtual void paintEmptyArea(TQPainter *, int, int, int, int)
Paint the empty area (background).
Definition: kdatetbl.cpp:198
TDEPopupFrame::hide
void hide()
Hides the widget.
Definition: kdatetbl.cpp:951
KDateInternalMonthPicker::sizeHint
TQSize sizeHint() const
The size hint.
Definition: kdatetbl.cpp:716
KDateTable::fontsize
int fontsize
The font size of the displayed text.
Definition: kdatetbl.h:377
TDELocale::readDate
TQDate readDate(const TQString &str, bool *ok=0) const
KDateInternalMonthPicker::~KDateInternalMonthPicker
~KDateInternalMonthPicker()
The destructor.
Definition: kdatetbl.cpp:675
KDateInternalMonthPicker::closeMe
void closeMe(int)
This is send from the mouse click event handler.
KDateInternalMonthPicker::paintCell
virtual void paintCell(TQPainter *painter, int row, int col)
Paint a cell.
Definition: kdatetbl.cpp:742
KCalendarSystem::calendarName
virtual TQString calendarName() const =0
KCalendarSystem::setYMD
virtual bool setYMD(TQDate &date, int y, int m, int d) const =0

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.