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