00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <kconfig.h>
00036 #include <kglobal.h>
00037 #include <kglobalsettings.h>
00038 #include <kapplication.h>
00039 #include <kaccel.h>
00040 #include <klocale.h>
00041 #include <kdebug.h>
00042 #include <knotifyclient.h>
00043 #include <kcalendarsystem.h>
00044 #include <kshortcut.h>
00045 #include <kstdaccel.h>
00046 #include "kdatepicker.h"
00047 #include "kdatetbl.h"
00048 #include "kpopupmenu.h"
00049 #include <qdatetime.h>
00050 #include <qstring.h>
00051 #include <qpen.h>
00052 #include <qpainter.h>
00053 #include <qdialog.h>
00054 #include <qdict.h>
00055 #include <assert.h>
00056
00057
00058 class KDateTable::KDateTablePrivate
00059 {
00060 public:
00061 KDateTablePrivate()
00062 {
00063 popupMenuEnabled=false;
00064 useCustomColors=false;
00065 }
00066
00067 ~KDateTablePrivate()
00068 {
00069 }
00070
00071 bool popupMenuEnabled;
00072 bool useCustomColors;
00073
00074 struct DatePaintingMode
00075 {
00076 QColor fgColor;
00077 QColor bgColor;
00078 BackgroundMode bgMode;
00079 };
00080 QDict <DatePaintingMode> customPaintingModes;
00081
00082 };
00083
00084
00085 KDateValidator::KDateValidator(QWidget* parent, const char* name)
00086 : QValidator(parent, name)
00087 {
00088 }
00089
00090 QValidator::State
00091 KDateValidator::validate(QString& text, int&) const
00092 {
00093 QDate temp;
00094
00095 return date(text, temp);
00096 }
00097
00098 QValidator::State
00099 KDateValidator::date(const QString& text, QDate& d) const
00100 {
00101 QDate tmp = KGlobal::locale()->readDate(text);
00102 if (!tmp.isNull())
00103 {
00104 d = tmp;
00105 return Acceptable;
00106 } else
00107 return Valid;
00108 }
00109
00110 void
00111 KDateValidator::fixup( QString& ) const
00112 {
00113
00114 }
00115
00116 KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f)
00117 : QGridView(parent, name, f)
00118 {
00119 d = new KDateTablePrivate;
00120 setFontSize(10);
00121 if(!date_.isValid())
00122 {
00123 kdDebug() << "KDateTable ctor: WARNING: Given date is invalid, using current date." << endl;
00124 date_=QDate::currentDate();
00125 }
00126 setFocusPolicy( QWidget::StrongFocus );
00127 setNumRows(7);
00128 setNumCols(7);
00129 setHScrollBarMode(AlwaysOff);
00130 setVScrollBarMode(AlwaysOff);
00131 viewport()->setEraseColor(KGlobalSettings::baseColor());
00132 setDate(date_);
00133 initAccels();
00134 }
00135
00136 KDateTable::KDateTable(QWidget *parent, const char* name, WFlags f)
00137 : QGridView(parent, name, f)
00138 {
00139 d = new KDateTablePrivate;
00140 setFontSize(10);
00141 setFocusPolicy( QWidget::StrongFocus );
00142 setNumRows(7);
00143 setNumCols(7);
00144 setHScrollBarMode(AlwaysOff);
00145 setVScrollBarMode(AlwaysOff);
00146 viewport()->setEraseColor(KGlobalSettings::baseColor());
00147 setDate(QDate::currentDate());
00148 initAccels();
00149 }
00150
00151 KDateTable::~KDateTable()
00152 {
00153 delete d;
00154 }
00155
00156 void KDateTable::initAccels()
00157 {
00158 KAccel* accel = new KAccel(this, "date table accel");
00159 accel->insert(KStdAccel::Next, this, SLOT(nextMonth()));
00160 accel->insert(KStdAccel::Prior, this, SLOT(previousMonth()));
00161 accel->insert(KStdAccel::Home, this, SLOT(beginningOfMonth()));
00162 accel->insert(KStdAccel::End, this, SLOT(endOfMonth()));
00163 accel->insert(KStdAccel::BeginningOfLine, this, SLOT(beginningOfWeek()));
00164 accel->insert(KStdAccel::EndOfLine, this, SLOT(endOfWeek()));
00165 accel->readSettings();
00166 }
00167
00168 int KDateTable::posFromDate( const QDate &dt )
00169 {
00170 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
00171 const int firstWeekDay = KGlobal::locale()->weekStartDay();
00172 int pos = calendar->day( dt );
00173 int offset = (firstday - firstWeekDay + 7) % 7;
00174
00175
00176 if ( offset < 1 ) offset += 7;
00177 return pos + offset;
00178 }
00179
00180 QDate KDateTable::dateFromPos( int pos )
00181 {
00182 QDate pCellDate;
00183 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
00184 calendar->setYMD(pCellDate, calendar->year(date), calendar->month(date), 1);
00185
00186 int firstWeekDay = KGlobal::locale()->weekStartDay();
00187 int offset = (firstday - firstWeekDay + 7) % 7;
00188
00189
00190 if ( offset < 1 ) offset += 7;
00191 pCellDate = calendar->addDays( pCellDate, pos - offset );
00192 return pCellDate;
00193 }
00194
00195 void
00196 KDateTable::paintCell(QPainter *painter, int row, int col)
00197 {
00198 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
00199
00200 QRect rect;
00201 QString text;
00202 QPen pen;
00203 int w=cellWidth();
00204 int h=cellHeight();
00205 QFont font=KGlobalSettings::generalFont();
00206
00207
00208 if(row == 0)
00209 {
00210 font.setBold(true);
00211 painter->setFont(font);
00212 bool normalday = true;
00213 int firstWeekDay = KGlobal::locale()->weekStartDay();
00214 int daynum = ( col+firstWeekDay < 8 ) ? col+firstWeekDay :
00215 col+firstWeekDay-7;
00216 if ( daynum == calendar->weekDayOfPray() ||
00217 ( daynum == 6 && calendar->calendarName() == "gregorian" ) )
00218 normalday=false;
00219
00220 QBrush brushInvertTitle(colorGroup().base());
00221 QColor titleColor(isEnabled()?( KGlobalSettings::activeTitleColor() ):( KGlobalSettings::inactiveTitleColor() ) );
00222 QColor textColor(isEnabled()?( KGlobalSettings::activeTextColor() ):( KGlobalSettings::inactiveTextColor() ) );
00223 if (!normalday)
00224 {
00225 painter->setPen(textColor);
00226 painter->setBrush(textColor);
00227 painter->drawRect(0, 0, w, h);
00228 painter->setPen(titleColor);
00229 } else {
00230 painter->setPen(titleColor);
00231 painter->setBrush(titleColor);
00232 painter->drawRect(0, 0, w, h);
00233 painter->setPen(textColor);
00234 }
00235 painter->drawText(0, 0, w, h-1, AlignCenter,
00236 calendar->weekDayName(daynum, true), -1, &rect);
00237 painter->setPen(colorGroup().text());
00238 painter->moveTo(0, h-1);
00239 painter->lineTo(w-1, h-1);
00240
00241 } else {
00242 bool paintRect=true;
00243 painter->setFont(font);
00244 int pos=7*(row-1)+col;
00245
00246 QDate pCellDate = dateFromPos( pos );
00247
00248 text = calendar->dayString(pCellDate, true);
00249 if( calendar->month(pCellDate) != calendar->month(date) )
00250 {
00251
00252
00253
00254 painter->setPen( colorGroup().mid() );
00255
00256 } else {
00257 if ( d->useCustomColors )
00258 {
00259 KDateTablePrivate::DatePaintingMode *mode=d->customPaintingModes[pCellDate.toString()];
00260 if (mode)
00261 {
00262 if (mode->bgMode != NoBgMode)
00263 {
00264 QBrush oldbrush=painter->brush();
00265 painter->setBrush( mode->bgColor );
00266 switch(mode->bgMode)
00267 {
00268 case(CircleMode) : painter->drawEllipse(0,0,w,h);break;
00269 case(RectangleMode) : painter->drawRect(0,0,w,h);break;
00270 case(NoBgMode) :
00271
00272 default: break;
00273 }
00274 painter->setBrush( oldbrush );
00275 paintRect=false;
00276 }
00277 painter->setPen( mode->fgColor );
00278 } else
00279 painter->setPen(colorGroup().text());
00280 } else
00281 painter->setPen(colorGroup().text());
00282 }
00283
00284 pen=painter->pen();
00285 int firstWeekDay=KGlobal::locale()->weekStartDay();
00286 int offset=firstday-firstWeekDay;
00287 if(offset<1)
00288 offset+=7;
00289 int d = calendar->day(date);
00290 if( (offset+d) == (pos+1))
00291 {
00292
00293 if (isEnabled())
00294 {
00295 painter->setPen(colorGroup().highlight());
00296 painter->setBrush(colorGroup().highlight());
00297 }
00298 else
00299 {
00300 painter->setPen(colorGroup().text());
00301 painter->setBrush(colorGroup().text());
00302 }
00303 pen=colorGroup().highlightedText();
00304 } else {
00305 painter->setBrush(paletteBackgroundColor());
00306 painter->setPen(paletteBackgroundColor());
00307
00308
00309 }
00310
00311 if ( pCellDate == QDate::currentDate() )
00312 {
00313 painter->setPen(colorGroup().text());
00314 }
00315
00316 if ( paintRect ) painter->drawRect(0, 0, w, h);
00317 painter->setPen(pen);
00318 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect);
00319 }
00320 if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
00321 if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height());
00322 }
00323
00324 void KDateTable::nextMonth()
00325 {
00326 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
00327 setDate(calendar->addMonths( date, 1 ));
00328 }
00329
00330 void KDateTable::previousMonth()
00331 {
00332 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
00333 setDate(calendar->addMonths( date, -1 ));
00334 }
00335
00336 void KDateTable::beginningOfMonth()
00337 {
00338 setDate(date.addDays(1 - date.day()));
00339 }
00340
00341 void KDateTable::endOfMonth()
00342 {
00343 setDate(date.addDays(date.daysInMonth() - date.day()));
00344 }
00345
00346 void KDateTable::beginningOfWeek()
00347 {
00348 setDate(date.addDays(1 - date.dayOfWeek()));
00349 }
00350
00351 void KDateTable::endOfWeek()
00352 {
00353 setDate(date.addDays(7 - date.dayOfWeek()));
00354 }
00355
00356 void
00357 KDateTable::keyPressEvent( QKeyEvent *e )
00358 {
00359 switch( e->key() ) {
00360 case Key_Up:
00361 setDate(date.addDays(-7));
00362 break;
00363 case Key_Down:
00364 setDate(date.addDays(7));
00365 break;
00366 case Key_Left:
00367 setDate(date.addDays(-1));
00368 break;
00369 case Key_Right:
00370 setDate(date.addDays(1));
00371 break;
00372 case Key_Minus:
00373 setDate(date.addDays(-1));
00374 break;
00375 case Key_Plus:
00376 setDate(date.addDays(1));
00377 break;
00378 case Key_N:
00379 setDate(QDate::currentDate());
00380 break;
00381 case Key_Return:
00382 case Key_Enter:
00383 emit tableClicked();
00384 break;
00385 case Key_Control:
00386 case Key_Alt:
00387 case Key_Meta:
00388 case Key_Shift:
00389
00390 break;
00391 default:
00392 if (!e->state()) {
00393 KNotifyClient::beep();
00394 }
00395 }
00396 }
00397
00398 void
00399 KDateTable::viewportResizeEvent(QResizeEvent * e)
00400 {
00401 QGridView::viewportResizeEvent(e);
00402
00403 setCellWidth(viewport()->width()/7);
00404 setCellHeight(viewport()->height()/7);
00405 }
00406
00407 void
00408 KDateTable::setFontSize(int size)
00409 {
00410 int count;
00411 QFontMetrics metrics(fontMetrics());
00412 QRect rect;
00413
00414 fontsize=size;
00415
00416 maxCell.setWidth(0);
00417 maxCell.setHeight(0);
00418 for(count=0; count<7; ++count)
00419 {
00420 rect=metrics.boundingRect(KGlobal::locale()->calendar()
00421 ->weekDayName(count+1, true));
00422 maxCell.setWidth(QMAX(maxCell.width(), rect.width()));
00423 maxCell.setHeight(QMAX(maxCell.height(), rect.height()));
00424 }
00425
00426 rect=metrics.boundingRect(QString::fromLatin1("88"));
00427 maxCell.setWidth(QMAX(maxCell.width()+2, rect.width()));
00428 maxCell.setHeight(QMAX(maxCell.height()+4, rect.height()));
00429 }
00430
00431 void
00432 KDateTable::wheelEvent ( QWheelEvent * e )
00433 {
00434 setDate(date.addMonths( -(int)(e->delta()/120)) );
00435 e->accept();
00436 }
00437
00438 void
00439 KDateTable::contentsMousePressEvent(QMouseEvent *e)
00440 {
00441
00442 if(e->type()!=QEvent::MouseButtonPress)
00443 {
00444 return;
00445 }
00446 if(!isEnabled())
00447 {
00448 KNotifyClient::beep();
00449 return;
00450 }
00451
00452
00453 int row, col, pos, temp;
00454 QPoint mouseCoord;
00455
00456 mouseCoord = e->pos();
00457 row=rowAt(mouseCoord.y());
00458 col=columnAt(mouseCoord.x());
00459 if(row<1 || col<0)
00460 {
00461 return;
00462 }
00463
00464
00465
00466
00467
00468 temp = posFromDate( date );
00469
00470 pos = (7 * (row - 1)) + col;
00471 QDate clickedDate = dateFromPos( pos );
00472
00473
00474
00475 setDate( clickedDate );
00476
00477
00478
00479 updateCell( temp/7+1, temp%7 );
00480 updateCell( row, col );
00481
00482 emit tableClicked();
00483
00484 if ( e->button() == Qt::RightButton && d->popupMenuEnabled )
00485 {
00486 KPopupMenu *menu = new KPopupMenu();
00487 menu->insertTitle( KGlobal::locale()->formatDate(clickedDate) );
00488 emit aboutToShowContextMenu( menu, clickedDate );
00489 menu->popup(e->globalPos());
00490 }
00491 }
00492
00493 bool
00494 KDateTable::setDate(const QDate& date_)
00495 {
00496 bool changed=false;
00497 QDate temp;
00498
00499 if(!date_.isValid())
00500 {
00501 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
00502 return false;
00503 }
00504 if(date!=date_)
00505 {
00506 emit(dateChanged(date, date_));
00507 date=date_;
00508 emit(dateChanged(date));
00509 changed=true;
00510 }
00511 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
00512
00513 calendar->setYMD(temp, calendar->year(date), calendar->month(date), 1);
00514
00515
00516 firstday=temp.dayOfWeek();
00517 numdays=calendar->daysInMonth(date);
00518
00519 temp = calendar->addMonths(temp, -1);
00520 numDaysPrevMonth=calendar->daysInMonth(temp);
00521 if(changed)
00522 {
00523 repaintContents(false);
00524 }
00525 return true;
00526 }
00527
00528 const QDate&
00529 KDateTable::getDate() const
00530 {
00531 return date;
00532 }
00533
00534
00535 void KDateTable::focusInEvent( QFocusEvent *e )
00536 {
00537
00538 QGridView::focusInEvent( e );
00539 }
00540
00541 void KDateTable::focusOutEvent( QFocusEvent *e )
00542 {
00543
00544 QGridView::focusOutEvent( e );
00545 }
00546
00547 QSize
00548 KDateTable::sizeHint() const
00549 {
00550 if(maxCell.height()>0 && maxCell.width()>0)
00551 {
00552 return QSize(maxCell.width()*numCols()+2*frameWidth(),
00553 (maxCell.height()+2)*numRows()+2*frameWidth());
00554 } else {
00555 kdDebug() << "KDateTable::sizeHint: obscure failure - " << endl;
00556 return QSize(-1, -1);
00557 }
00558 }
00559
00560 void KDateTable::setPopupMenuEnabled( bool enable )
00561 {
00562 d->popupMenuEnabled=enable;
00563 }
00564
00565 bool KDateTable::popupMenuEnabled() const
00566 {
00567 return d->popupMenuEnabled;
00568 }
00569
00570 void KDateTable::setCustomDatePainting(const QDate &date, const QColor &fgColor, BackgroundMode bgMode, const QColor &bgColor)
00571 {
00572 if (!fgColor.isValid())
00573 {
00574 unsetCustomDatePainting( date );
00575 return;
00576 }
00577
00578 KDateTablePrivate::DatePaintingMode *mode=new KDateTablePrivate::DatePaintingMode;
00579 mode->bgMode=bgMode;
00580 mode->fgColor=fgColor;
00581 mode->bgColor=bgColor;
00582
00583 d->customPaintingModes.replace( date.toString(), mode );
00584 d->useCustomColors=true;
00585 update();
00586 }
00587
00588 void KDateTable::unsetCustomDatePainting( const QDate &date )
00589 {
00590 d->customPaintingModes.remove( date.toString() );
00591 }
00592
00593 KDateInternalWeekSelector::KDateInternalWeekSelector
00594 (QWidget* parent, const char* name)
00595 : QLineEdit(parent, name),
00596 val(new QIntValidator(this)),
00597 result(0)
00598 {
00599 QFont font;
00600
00601 font=KGlobalSettings::generalFont();
00602 setFont(font);
00603 setFrameStyle(QFrame::NoFrame);
00604 setValidator(val);
00605 connect(this, SIGNAL(returnPressed()), SLOT(weekEnteredSlot()));
00606 }
00607
00608 void
00609 KDateInternalWeekSelector::weekEnteredSlot()
00610 {
00611 bool ok;
00612 int week;
00613
00614 week=text().toInt(&ok);
00615 if(!ok)
00616 {
00617 KNotifyClient::beep();
00618 emit(closeMe(0));
00619 return;
00620 }
00621 result=week;
00622 emit(closeMe(1));
00623 }
00624
00625 int
00626 KDateInternalWeekSelector::getWeek()
00627 {
00628 return result;
00629 }
00630
00631 void
00632 KDateInternalWeekSelector::setWeek(int week)
00633 {
00634 QString temp;
00635
00636 temp.setNum(week);
00637 setText(temp);
00638 }
00639
00640 void
00641 KDateInternalWeekSelector::setMaxWeek(int max)
00642 {
00643 val->setRange(1, max);
00644 }
00645
00646
00647
00648
00649 class KDateInternalMonthPicker::KDateInternalMonthPrivate {
00650 public:
00651 KDateInternalMonthPrivate (int y, int m, int d)
00652 : year(y), month(m), day(d)
00653 {};
00654 int year;
00655 int month;
00656 int day;
00657 };
00658
00659 KDateInternalMonthPicker::~KDateInternalMonthPicker() {
00660 delete d;
00661 }
00662
00663 KDateInternalMonthPicker::KDateInternalMonthPicker
00664 (const QDate & date, QWidget* parent, const char* name)
00665 : QGridView(parent, name),
00666 result(0)
00667 {
00668 QRect rect;
00669 QFont font;
00670
00671 activeCol = -1;
00672 activeRow = -1;
00673 font=KGlobalSettings::generalFont();
00674 setFont(font);
00675 setHScrollBarMode(AlwaysOff);
00676 setVScrollBarMode(AlwaysOff);
00677 setFrameStyle(QFrame::NoFrame);
00678 setNumCols(3);
00679 d = new KDateInternalMonthPrivate(date.year(), date.month(), date.day());
00680
00681 setNumRows( (KGlobal::locale()->calendar()->monthsInYear(date) + 2) / 3);
00682
00683
00684 viewport()->setEraseColor(KGlobalSettings::baseColor());
00685
00686
00687 QFontMetrics metrics(font);
00688 for(int i = 1; ; ++i)
00689 {
00690 QString str = KGlobal::locale()->calendar()->monthName(i,
00691 KGlobal::locale()->calendar()->year(date), false);
00692 if (str.isNull()) break;
00693 rect=metrics.boundingRect(str);
00694 if(max.width()<rect.width()) max.setWidth(rect.width());
00695 if(max.height()<rect.height()) max.setHeight(rect.height());
00696 }
00697 }
00698
00699 QSize
00700 KDateInternalMonthPicker::sizeHint() const
00701 {
00702 return QSize((max.width()+6)*numCols()+2*frameWidth(),
00703 (max.height()+6)*numRows()+2*frameWidth());
00704 }
00705
00706 int
00707 KDateInternalMonthPicker::getResult() const
00708 {
00709 return result;
00710 }
00711
00712 void
00713 KDateInternalMonthPicker::setupPainter(QPainter *p)
00714 {
00715 p->setPen(KGlobalSettings::textColor());
00716 }
00717
00718 void
00719 KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*)
00720 {
00721 setCellWidth(width() / numCols());
00722 setCellHeight(height() / numRows());
00723 }
00724
00725 void
00726 KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col)
00727 {
00728 int index;
00729 QString text;
00730
00731 index=3*row+col+1;
00732 text=KGlobal::locale()->calendar()->monthName(index,
00733 KGlobal::locale()->calendar()->year(QDate(d->year, d->month,
00734 d->day)), false);
00735 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
00736 if ( activeCol == col && activeRow == row )
00737 painter->drawRect( 0, 0, cellWidth(), cellHeight() );
00738 }
00739
00740 void
00741 KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e)
00742 {
00743 if(!isEnabled() || e->button() != LeftButton)
00744 {
00745 KNotifyClient::beep();
00746 return;
00747 }
00748
00749 int row, col;
00750 QPoint mouseCoord;
00751
00752 mouseCoord = e->pos();
00753 row=rowAt(mouseCoord.y());
00754 col=columnAt(mouseCoord.x());
00755
00756 if(row<0 || col<0)
00757 {
00758 activeCol = -1;
00759 activeRow = -1;
00760 } else {
00761 activeCol = col;
00762 activeRow = row;
00763 updateCell( row, col );
00764 }
00765 }
00766
00767 void
00768 KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e)
00769 {
00770 if (e->state() & LeftButton)
00771 {
00772 int row, col;
00773 QPoint mouseCoord;
00774
00775 mouseCoord = e->pos();
00776 row=rowAt(mouseCoord.y());
00777 col=columnAt(mouseCoord.x());
00778 int tmpRow = -1, tmpCol = -1;
00779 if(row<0 || col<0)
00780 {
00781 if ( activeCol > -1 )
00782 {
00783 tmpRow = activeRow;
00784 tmpCol = activeCol;
00785 }
00786 activeCol = -1;
00787 activeRow = -1;
00788 } else {
00789 bool differentCell = (activeRow != row || activeCol != col);
00790 if ( activeCol > -1 && differentCell)
00791 {
00792 tmpRow = activeRow;
00793 tmpCol = activeCol;
00794 }
00795 if ( differentCell)
00796 {
00797 activeRow = row;
00798 activeCol = col;
00799 updateCell( row, col );
00800 }
00801 }
00802 if ( tmpRow > -1 )
00803 updateCell( tmpRow, tmpCol );
00804 }
00805 }
00806
00807 void
00808 KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e)
00809 {
00810 if(!isEnabled())
00811 {
00812 return;
00813 }
00814
00815 int row, col, pos;
00816 QPoint mouseCoord;
00817
00818 mouseCoord = e->pos();
00819 row=rowAt(mouseCoord.y());
00820 col=columnAt(mouseCoord.x());
00821 if(row<0 || col<0)
00822 {
00823 emit(closeMe(0));
00824 return;
00825 }
00826
00827 pos=3*row+col+1;
00828 result=pos;
00829 emit(closeMe(1));
00830 }
00831
00832
00833
00834 KDateInternalYearSelector::KDateInternalYearSelector
00835 (QWidget* parent, const char* name)
00836 : QLineEdit(parent, name),
00837 val(new QIntValidator(this)),
00838 result(0)
00839 {
00840 QFont font;
00841
00842 font=KGlobalSettings::generalFont();
00843 setFont(font);
00844 setFrameStyle(QFrame::NoFrame);
00845
00846 val->setRange(0, 8000);
00847 setValidator(val);
00848 connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot()));
00849 }
00850
00851 void
00852 KDateInternalYearSelector::yearEnteredSlot()
00853 {
00854 bool ok;
00855 int year;
00856 QDate date;
00857
00858 year=text().toInt(&ok);
00859 if(!ok)
00860 {
00861 KNotifyClient::beep();
00862 emit(closeMe(0));
00863 return;
00864 }
00865
00866 KGlobal::locale()->calendar()->setYMD(date, year, 1, 1);
00867 if(!date.isValid())
00868 {
00869 KNotifyClient::beep();
00870 emit(closeMe(0));
00871 return;
00872 }
00873 result=year;
00874 emit(closeMe(1));
00875 }
00876
00877 int
00878 KDateInternalYearSelector::getYear()
00879 {
00880 return result;
00881 }
00882
00883 void
00884 KDateInternalYearSelector::setYear(int year)
00885 {
00886 QString temp;
00887
00888 temp.setNum(year);
00889 setText(temp);
00890 }
00891
00892 class KPopupFrame::KPopupFramePrivate
00893 {
00894 public:
00895 KPopupFramePrivate() : exec(false) {}
00896
00897 bool exec;
00898 };
00899
00900 KPopupFrame::KPopupFrame(QWidget* parent, const char* name)
00901 : QFrame(parent, name, WType_Popup),
00902 result(0),
00903 main(0),
00904 d(new KPopupFramePrivate)
00905 {
00906 setFrameStyle(QFrame::Box|QFrame::Raised);
00907 setMidLineWidth(2);
00908 }
00909
00910 KPopupFrame::~KPopupFrame()
00911 {
00912 delete d;
00913 }
00914
00915 void
00916 KPopupFrame::keyPressEvent(QKeyEvent* e)
00917 {
00918 if(e->key()==Key_Escape)
00919 {
00920 result=0;
00921 d->exec = false;
00922 qApp->exit_loop();
00923 }
00924 }
00925
00926 void
00927 KPopupFrame::close(int r)
00928 {
00929 result=r;
00930 }
00931
00932 void
00933 KPopupFrame::hide()
00934 {
00935 QFrame::hide();
00936 if (d->exec)
00937 {
00938 d->exec = false;
00939 qApp->exit_loop();
00940 }
00941 }
00942
00943 void
00944 KPopupFrame::setMainWidget(QWidget* m)
00945 {
00946 main=m;
00947 if(main)
00948 {
00949 resize(main->width()+2*frameWidth(), main->height()+2*frameWidth());
00950 }
00951 }
00952
00953 void
00954 KPopupFrame::resizeEvent(QResizeEvent*)
00955 {
00956 if(main)
00957 {
00958 main->setGeometry(frameWidth(), frameWidth(),
00959 width()-2*frameWidth(), height()-2*frameWidth());
00960 }
00961 }
00962
00963 void
00964 KPopupFrame::popup(const QPoint &pos)
00965 {
00966
00967 QRect d = KGlobalSettings::desktopGeometry(pos);
00968
00969 int x = pos.x();
00970 int y = pos.y();
00971 int w = width();
00972 int h = height();
00973 if (x+w > d.x()+d.width())
00974 x = d.width() - w;
00975 if (y+h > d.y()+d.height())
00976 y = d.height() - h;
00977 if (x < d.x())
00978 x = 0;
00979 if (y < d.y())
00980 y = 0;
00981
00982
00983 move(x, y);
00984 show();
00985 }
00986
00987 int
00988 KPopupFrame::exec(QPoint pos)
00989 {
00990 popup(pos);
00991 repaint();
00992 d->exec = true;
00993 qApp->enter_loop();
00994 hide();
00995 return result;
00996 }
00997
00998 int
00999 KPopupFrame::exec(int x, int y)
01000 {
01001 return exec(QPoint(x, y));
01002 }
01003
01004 void KPopupFrame::virtual_hook( int, void* )
01005 { }
01006
01007 void KDateTable::virtual_hook( int, void* )
01008 { }
01009
01010 #include "kdatetbl.moc"