00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
#include <qpopupmenu.h>
00026
#include <qfont.h>
00027
#include <qfontmetrics.h>
00028
#include <qkeycode.h>
00029
#include <qhbox.h>
00030
#include <qvbox.h>
00031
#include <qpushbutton.h>
00032
#include <qtooltip.h>
00033
#include <qpainter.h>
00034
#include <qcursor.h>
00035
#include <qlistbox.h>
00036
#include <qlayout.h>
00037
#include <qlabel.h>
00038
00039
#include <kdebug.h>
00040
#include <klocale.h>
00041
#include <kglobal.h>
00042
#include <kconfig.h>
00043
#include <kiconloader.h>
00044
#include <kwordwrap.h>
00045
00046
#include <kcalendarsystem.h>
00047
#include <libkcal/calfilter.h>
00048
00049
#ifndef KORG_NOPRINTER
00050
#include "calprinter.h"
00051
#endif
00052
#include "koprefs.h"
00053
#ifndef KORG_NOPLUGINS
00054
#include "kocore.h"
00055
#endif
00056
#include "koglobals.h"
00057
#include "koincidencetooltip.h"
00058
#include "koeventpopupmenu.h"
00059
00060
#include "komonthview.h"
00061
#include "komonthview.moc"
00062
00063
00064
00065 KOMonthCellToolTip::KOMonthCellToolTip(
QWidget *parent,
00066 KNoScrollListBox *lv )
00067 :
QToolTip( parent )
00068 {
00069 eventlist = lv;
00070 }
00071
00072
void KOMonthCellToolTip::maybeTip(
const QPoint & pos )
00073 {
00074
QRect r;
00075
QListBoxItem *it = eventlist->itemAt( pos );
00076 MonthViewItem *i = static_cast<MonthViewItem*>( it );
00077
00078
if( i && KOPrefs::instance()->mEnableToolTips ) {
00079
00080 r=eventlist->itemRect( it );
00081
00082
QString tipText;
00083 ToolTipVisitor v;
00084
if ( v.act( i->incidence(), &tipText,
true ) ) {
00085 tip( r, tipText );
00086 }
00087 }
00088 }
00089
00090 KNoScrollListBox::KNoScrollListBox(
QWidget *parent,
const char *name )
00091 :
QListBox( parent, name ),
00092 mSqueezing( false )
00093 {
00094
QPalette pal = palette();
00095 pal.setColor( QColorGroup::Foreground, KOPrefs::instance()->agendaBgColor().dark( 150 ) );
00096 pal.setColor( QColorGroup::Base, KOPrefs::instance()->agendaBgColor() );
00097 setPalette( pal );
00098 }
00099
00100
void KNoScrollListBox::setBackground(
bool primary,
bool workDay )
00101 {
00102
QColor color;
00103
if ( workDay ) {
00104 color = KOPrefs::instance()->workingHoursColor();
00105 }
else {
00106 color = KOPrefs::instance()->agendaBgColor();
00107 }
00108
00109
QPalette pal = palette();
00110
if ( primary ) {
00111 pal.setColor( QColorGroup::Base, color );
00112 }
else {
00113 pal.setColor( QColorGroup::Base, color.dark( 115 ) );
00114 }
00115 setPalette( pal );
00116 }
00117
00118
void KNoScrollListBox::keyPressEvent(
QKeyEvent *e )
00119 {
00120
switch( e->key() ) {
00121
case Key_Right:
00122 scrollBy( 4, 0 );
00123
break;
00124
case Key_Left:
00125 scrollBy( -4, 0 );
00126
break;
00127
case Key_Up:
00128
if ( !count() )
break;
00129 setCurrentItem( ( currentItem() + count() - 1 ) % count() );
00130
if ( !itemVisible( currentItem() ) ) {
00131
if ( (
unsigned int)currentItem() == ( count() - 1 ) ) {
00132 setTopItem( currentItem() - numItemsVisible() + 1 );
00133 }
else {
00134 setTopItem( topItem() - 1 );
00135 }
00136 }
00137
break;
00138
case Key_Down:
00139
if ( !count() )
break;
00140 setCurrentItem( ( currentItem() + 1 ) % count() );
00141
if( !itemVisible( currentItem() ) ) {
00142
if( currentItem() == 0 ) {
00143 setTopItem( 0 );
00144 }
else {
00145 setTopItem( topItem() + 1 );
00146 }
00147 }
00148
case Key_Shift:
00149 emit shiftDown();
00150
break;
00151
default:
00152
break;
00153 }
00154 }
00155
00156
void KNoScrollListBox::keyReleaseEvent(
QKeyEvent *e )
00157 {
00158
switch( e->key() ) {
00159
case Key_Shift:
00160 emit shiftUp();
00161
break;
00162
default:
00163
break;
00164 }
00165 }
00166
00167
void KNoScrollListBox::mousePressEvent(
QMouseEvent *e )
00168 {
00169 QListBox::mousePressEvent( e );
00170
00171
if ( e->button() == RightButton ) {
00172 emit rightClick();
00173 }
00174 }
00175
00176
void KNoScrollListBox::contentsMouseDoubleClickEvent (
QMouseEvent * e )
00177 {
00178 QListBox::contentsMouseDoubleClickEvent( e );
00179
QListBoxItem *item = itemAt( e->pos() );
00180
if ( !item ) {
00181 emit doubleClicked( item );
00182 }
00183 }
00184
00185
void KNoScrollListBox::resizeEvent(
QResizeEvent *e )
00186 {
00187
bool s = count() && ( maxItemWidth() > e->size().width() );
00188
if ( mSqueezing || s )
00189 triggerUpdate(
false );
00190
00191 mSqueezing = s;
00192 QListBox::resizeEvent( e );
00193 }
00194
00195 MonthViewItem::MonthViewItem( Incidence *incidence,
QDate qd,
const QString & s)
00196 :
QListBoxItem()
00197 {
00198 setText( s );
00199
00200 mIncidence = incidence;
00201 mDate = qd;
00202
00203 mTodoPixmap = KOGlobals::self()->smallIcon(
"todo");
00204 mTodoDonePixmap = KOGlobals::self()->smallIcon(
"checkedbox");
00205 mAlarmPixmap = KOGlobals::self()->smallIcon(
"bell");
00206 mRecurPixmap = KOGlobals::self()->smallIcon(
"recur");
00207 mReplyPixmap = KOGlobals::self()->smallIcon(
"mail_reply");
00208
00209 mTodo =
false;
00210 mTodoDone =
false;
00211 mRecur =
false;
00212 mAlarm =
false;
00213 mReply =
false;
00214 }
00215
00216
void MonthViewItem::paint(
QPainter *p )
00217 {
00218
#if QT_VERSION >= 0x030000
00219
bool sel = isSelected();
00220
#else
00221
bool sel = selected();
00222
#endif
00223
00224
QColor bgColor = palette().color( QPalette::Normal,
00225 sel ? QColorGroup::Highlight : QColorGroup::Background );
00226
if ( KOPrefs::instance()->monthViewUsesCategoryColor() ) {
00227 p->setBackgroundColor( bgColor );
00228 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) );
00229 }
00230
int x = 3;
00231
if ( mTodo ) {
00232 p->drawPixmap( x, 0, mTodoPixmap );
00233 x += mTodoPixmap.width() + 2;
00234 }
00235
if ( mTodoDone ) {
00236 p->drawPixmap( x, 0, mTodoDonePixmap );
00237 x += mTodoPixmap.width() + 2;
00238 }
00239
if ( mRecur ) {
00240 p->drawPixmap( x, 0, mRecurPixmap );
00241 x += mRecurPixmap.width() + 2;
00242 }
00243
if ( mAlarm ) {
00244 p->drawPixmap( x, 0, mAlarmPixmap );
00245 x += mAlarmPixmap.width() + 2;
00246 }
00247
if ( mReply ) {
00248 p->drawPixmap(x, 0, mReplyPixmap );
00249 x += mReplyPixmap.width() + 2;
00250 }
00251
QFontMetrics fm = p->fontMetrics();
00252
int yPos;
00253
int pmheight = QMAX( mRecurPixmap.height(),
00254 QMAX( mAlarmPixmap.height(), mReplyPixmap.height() ) );
00255
if( pmheight < fm.height() )
00256 yPos = fm.ascent() + fm.leading()/2;
00257
else
00258 yPos = pmheight/2 - fm.height()/2 + fm.ascent();
00259
QColor textColor = palette().color( QPalette::Normal, sel ? \
00260 QColorGroup::HighlightedText : QColorGroup::Text );
00261 p->setPen( textColor );
00262
00263 KWordWrap::drawFadeoutText( p, x, yPos, listBox()->width() - x, text() );
00264 }
00265
00266
int MonthViewItem::height(
const QListBox *lb )
const
00267
{
00268
return QMAX( QMAX( mRecurPixmap.height(), mReplyPixmap.height() ),
00269 QMAX( mAlarmPixmap.height(), lb->fontMetrics().lineSpacing()+1) );
00270 }
00271
00272
int MonthViewItem::width(
const QListBox *lb )
const
00273
{
00274
int x = 3;
00275
if( mRecur ) {
00276 x += mRecurPixmap.width()+2;
00277 }
00278
if( mAlarm ) {
00279 x += mAlarmPixmap.width()+2;
00280 }
00281
if( mReply ) {
00282 x += mReplyPixmap.width()+2;
00283 }
00284
00285
return( x + lb->fontMetrics().boundingRect( text() ).width() + 1 );
00286 }
00287
00288
00289 MonthViewCell::MonthViewCell(
KOMonthView *parent)
00290 :
QWidget( parent ),
00291 mMonthView( parent ), mPrimary( false ), mHoliday( false )
00292 {
00293
QVBoxLayout *topLayout =
new QVBoxLayout(
this );
00294
00295 mLabel =
new QLabel(
this );
00296 mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain );
00297 mLabel->setLineWidth( 1 );
00298 mLabel->setAlignment( AlignCenter );
00299
00300 mItemList =
new KNoScrollListBox(
this );
00301 mItemList->setMinimumSize( 10, 10 );
00302 mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain );
00303 mItemList->setLineWidth( 1 );
00304
00305
new KOMonthCellToolTip( mItemList->viewport(),
00306 static_cast<KNoScrollListBox *>( mItemList ) );
00307
00308 topLayout->addWidget( mItemList );
00309
00310 mLabel->raise();
00311
00312 mStandardPalette = palette();
00313
00314 enableScrollBars(
false );
00315
00316
updateConfig();
00317
00318 connect( mItemList, SIGNAL( doubleClicked(
QListBoxItem *) ),
00319 SLOT(
defaultAction(
QListBoxItem * ) ) );
00320 connect( mItemList, SIGNAL( rightButtonPressed(
QListBoxItem *,
00321
const QPoint &) ),
00322 SLOT( contextMenu(
QListBoxItem * ) ) );
00323 connect( mItemList, SIGNAL( highlighted(
QListBoxItem *) ),
00324 SLOT( selection(
QListBoxItem * ) ) );
00325 connect( mItemList, SIGNAL( clicked(
QListBoxItem * ) ),
00326 SLOT( cellClicked(
QListBoxItem * ) ) );
00327 }
00328
00329 void MonthViewCell::setDate(
const QDate &date )
00330 {
00331
00332
00333 mDate = date;
00334
00335
QString text;
00336
if ( KOGlobals::self()->calendarSystem()->day( date ) == 1 ) {
00337 text = KOGlobals::self()->calendarSystem()->monthName( date,
true ) +
" ";
00338
QFontMetrics fm( mLabel->font() );
00339 mLabel->resize( mLabelSize +
QSize( fm.width( text ), 0 ) );
00340 }
else {
00341 mLabel->resize( mLabelSize );
00342 }
00343 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
00344 mLabel->setText( text );
00345
00346 resizeEvent( 0 );
00347 }
00348
00349 QDate MonthViewCell::date()
const
00350
{
00351
return mDate;
00352 }
00353
00354
void MonthViewCell::setPrimary(
bool primary )
00355 {
00356 mPrimary = primary;
00357
00358
if ( mPrimary ) {
00359 mLabel->setBackgroundMode( PaletteBase );
00360 }
else {
00361 mLabel->setBackgroundMode( PaletteBackground );
00362 }
00363
00364 mItemList->setBackground( mPrimary, KOCore::self()->isWorkDay( mDate ) );
00365 }
00366
00367
bool MonthViewCell::isPrimary()
const
00368
{
00369
return mPrimary;
00370 }
00371
00372 void MonthViewCell::setHoliday(
bool holiday )
00373 {
00374 mHoliday = holiday;
00375
00376
if ( holiday ) {
00377 setPalette( mHolidayPalette );
00378 }
else {
00379 setPalette( mStandardPalette );
00380 }
00381 }
00382
00383
void MonthViewCell::setHoliday(
const QString &holiday )
00384 {
00385 mHolidayString = holiday;
00386
00387
if ( !holiday.isEmpty() ) {
00388
setHoliday(
true );
00389 }
00390 }
00391
00392
void MonthViewCell::updateCell()
00393 {
00394
if ( mDate == QDate::currentDate() ) {
00395 setPalette( mTodayPalette );
00396 }
00397
else {
00398
if ( mHoliday )
00399 setPalette( mHolidayPalette );
00400
else
00401 setPalette( mStandardPalette );
00402 }
00403
00404 mItemList->clear();
00405
00406
if ( !mHolidayString.isEmpty() ) {
00407 MonthViewItem *item =
new MonthViewItem( 0, mDate, mHolidayString );
00408 item->setPalette( mHolidayPalette );
00409 mItemList->insertItem( item );
00410 }
00411 }
00412
00413 void MonthViewCell::addIncidence( Incidence *incidence )
00414 {
00415
QString text;
00416 MonthViewItem *item = 0;
00417
if ( incidence->type() ==
"Event" ) {
00418 Event *event = static_cast<Event *>(incidence);
00419
if (event->isMultiDay()) {
00420
if (mDate == event->dtStart().date()) {
00421 text =
"(-- " + event->summary();
00422 }
else if (mDate == event->dtEnd().date()) {
00423 text = event->summary() +
" --)";
00424 }
else if (!(event->dtStart().date().daysTo(mDate) % 7)) {
00425 text =
"-- " + event->summary() +
" --";
00426 }
else {
00427 text =
"----------------";
00428 }
00429 }
else {
00430
if (event->doesFloat())
00431 text = event->summary();
00432
else {
00433 text = KGlobal::locale()->formatTime(event->dtStart().time());
00434 text +=
" " + event->summary();
00435 }
00436 }
00437
00438 item =
new MonthViewItem( event, mDate, text );
00439
if (KOPrefs::instance()->monthViewUsesCategoryColor()) {
00440
QStringList categories = event->categories();
00441
QString cat = categories.first();
00442
if (cat.isEmpty()) {
00443 item->setPalette(
QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor));
00444 }
else {
00445 item->setPalette(
QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))));
00446 }
00447 }
else {
00448 item->setPalette( mStandardPalette );
00449 }
00450
00451 Attendee *me = event->attendeeByMails( KOPrefs::instance()->allEmails() );
00452
if ( me != 0 ) {
00453
if ( me->status() == Attendee::NeedsAction && me->RSVP())
00454 item->setReply(
true);
00455
else
00456 item->setReply(
false);
00457 }
else
00458 item->setReply(
false);
00459 }
00460
00461
if ( incidence->type() ==
"Todo" &&
00462 KOPrefs::instance()->showAllDayTodo() ) {
00463 Todo *todo = static_cast<Todo *>(incidence);
00464
if (todo->hasDueDate()) {
00465
if (!todo->doesFloat()) {
00466 text += KGlobal::locale()->formatTime(todo->dtDue().time());
00467 text +=
" ";
00468 }
00469 }
00470 text += todo->summary();
00471
00472 item =
new MonthViewItem( todo, mDate, text );
00473
if ( todo->doesRecur() ) {
00474 mDate < todo->dtDue().date() ?
00475 item->setTodoDone(
true ) : item->setTodo(
true );
00476 }
00477
else
00478 todo->isCompleted() ? item->setTodoDone(
true ) : item->setTodo(
true );
00479 item->setPalette( mStandardPalette );
00480 }
00481
00482
if ( item ) {
00483 item->setAlarm( incidence->isAlarmEnabled() );
00484 item->setRecur( incidence->doesRecur() );
00485 mItemList->insertItem( item );
00486 }
00487 }
00488
00489 bool MonthViewCell::removeIncidence( Incidence *incidence )
00490 {
00491
for ( uint i = 0; i < mItemList->count(); i++ ) {
00492 MonthViewItem *item = static_cast<MonthViewItem *>(mItemList->item( i ) );
00493
if ( item && item->incidence() &&
00494 item->incidence()->uid() == incidence->uid() ) {
00495 mItemList->removeItem( i );
00496
return true;
00497 }
00498 }
00499
00500
return false;
00501 }
00502
00503
void MonthViewCell::updateConfig()
00504 {
00505 setFont( KOPrefs::instance()->mMonthViewFont );
00506
00507
QFontMetrics fm( font() );
00508 mLabelSize = fm.size( 0,
"30" ) +
00509
QSize( mLabel->frameWidth() * 2, mLabel->frameWidth() * 2 ) +
00510
QSize( 2, 2 );
00511
00512
QColor bg = mStandardPalette.color( QPalette::Active, QColorGroup::Background );
00513
int h,s,v;
00514 bg.getHsv( &h, &s, &v );
00515
if (
date().month() %2 == 0 ) {
00516
if ( v < 128 ) {
00517 bg = bg.light( 125 );
00518 }
else {
00519 bg = bg.dark( 125 );
00520 }
00521 }
00522 setPaletteBackgroundColor( bg );
00523
00524
00525 mHolidayPalette = mStandardPalette;
00526 mHolidayPalette.setColor( QColorGroup::Foreground,
00527 KOPrefs::instance()->holidayColor() );
00528 mHolidayPalette.setColor( QColorGroup::Text,
00529 KOPrefs::instance()->holidayColor() );
00530 mTodayPalette = mStandardPalette;
00531 mTodayPalette.setColor( QColorGroup::Foreground,
00532 KOPrefs::instance()->highlightColor() );
00533 mTodayPalette.setColor( QColorGroup::Text,
00534 KOPrefs::instance()->highlightColor() );
00535 updateCell();
00536
00537 mItemList->setBackground( mPrimary, KOCore::self()->isWorkDay( mDate ) );
00538 }
00539
00540
void MonthViewCell::enableScrollBars(
bool enabled )
00541 {
00542
if ( enabled ) {
00543 mItemList->setVScrollBarMode( QScrollView::Auto );
00544 mItemList->setHScrollBarMode( QScrollView::Auto );
00545 }
else {
00546 mItemList->setVScrollBarMode( QScrollView::AlwaysOff );
00547 mItemList->setHScrollBarMode( QScrollView::AlwaysOff );
00548 }
00549 }
00550
00551 Incidence *MonthViewCell::selectedIncidence()
00552 {
00553
int index = mItemList->currentItem();
00554
if ( index < 0 )
return 0;
00555
00556 MonthViewItem *item =
00557 static_cast<MonthViewItem *>( mItemList->item( index ) );
00558
00559
if ( !item )
return 0;
00560
00561
return item->incidence();
00562 }
00563
00564
QDate MonthViewCell::selectedIncidenceDate()
00565 {
00566
QDate qd;
00567
int index = mItemList->currentItem();
00568
if ( index < 0 )
return qd;
00569
00570 MonthViewItem *item =
00571 static_cast<MonthViewItem *>( mItemList->item( index ) );
00572
00573
if ( !item )
return qd;
00574
00575
return item->incidenceDate();
00576 }
00577
00578
void MonthViewCell::deselect()
00579 {
00580 mItemList->clearSelection();
00581
00582 enableScrollBars(
false );
00583 }
00584
00585
void MonthViewCell::resizeEvent (
QResizeEvent * )
00586 {
00587 mLabel->move( width() - mLabel->width(), height() - mLabel->height() );
00588 }
00589
00590
void MonthViewCell::defaultAction(
QListBoxItem *item )
00591 {
00592
if ( !item ) {
00593 emit newEventSignal(
date() );
00594 }
else {
00595 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
00596 Incidence *incidence = eventItem->incidence();
00597
if ( incidence ) mMonthView->
defaultAction( incidence );
00598 }
00599 }
00600
00601
void MonthViewCell::cellClicked(
QListBoxItem * )
00602 {
00603
if( KOPrefs::instance()->enableMonthScroll() ) enableScrollBars(
true );
00604 }
00605
00606
void MonthViewCell::contextMenu(
QListBoxItem *item )
00607 {
00608 mMonthView->
setSelectedCell(
this );
00609
if ( item ) {
00610 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
00611 Incidence *incidence = eventItem->incidence();
00612
if ( incidence ) mMonthView->
showEventContextMenu( incidence,
date() );
00613 }
00614
else {
00615 mMonthView->
showGeneralContextMenu();
00616 }
00617 }
00618
00619
void MonthViewCell::selection(
QListBoxItem *item )
00620 {
00621
if ( !item )
return;
00622
00623 mMonthView->
setSelectedCell(
this );
00624 }
00625
00626 KOMonthView::KOMonthView( Calendar *calendar,
QWidget *parent,
const char *name )
00627 :
KOEventView( calendar, parent, name ),
00628 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
00629 mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
00630 {
00631 mCells.setAutoDelete(
true );
00632
00633
QGridLayout *dayLayout =
new QGridLayout(
this );
00634
00635
00636
00637 mDayLabels.resize( mDaysPerWeek );
00638
QFont bfont = font();
00639 bfont.setBold(
true );
00640
int i;
00641
for( i = 0; i < mDaysPerWeek; i++ ) {
00642
QLabel *label =
new QLabel(
this );
00643 label->setFont( bfont );
00644 label->setFrameStyle( QFrame::Panel | QFrame::Raised );
00645 label->setLineWidth( 1 );
00646 label->setAlignment( AlignCenter );
00647
00648 mDayLabels.insert( i, label );
00649
00650 dayLayout->addWidget( label, 0, i );
00651 dayLayout->addColSpacing( i, 10 );
00652 dayLayout->setColStretch( i, 1 );
00653 }
00654
00655
int row, col;
00656
00657 mCells.resize( mNumCells );
00658
for( row = 0; row < mNumWeeks; ++row ) {
00659
for( col = 0; col < mDaysPerWeek; ++col ) {
00660
MonthViewCell *cell =
new MonthViewCell(
this );
00661 mCells.insert( row * mDaysPerWeek + col, cell );
00662 dayLayout->addWidget( cell, row + 1, col );
00663
00664 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
00665 SLOT( defaultAction( Incidence * ) ) );
00666 connect( cell, SIGNAL( newEventSignal(
QDate ) ),
00667 SIGNAL( newEventSignal(
QDate ) ) );
00668 }
00669 dayLayout->setRowStretch( row + 1, 1 );
00670 }
00671
00672 mEventContextMenu = eventPopup();
00673
00674 updateConfig();
00675
00676 emit incidenceSelected( 0 );
00677 }
00678
00679 KOMonthView::~KOMonthView()
00680 {
00681
delete mEventContextMenu;
00682 }
00683
00684 int KOMonthView::maxDatesHint()
00685 {
00686
return mNumCells;
00687 }
00688
00689 int KOMonthView::currentDateCount()
00690 {
00691
return mNumCells;
00692 }
00693
00694 Incidence::List
KOMonthView::selectedIncidences()
00695 {
00696 Incidence::List selected;
00697
00698
if ( mSelectedCell ) {
00699 Incidence *incidence = mSelectedCell->
selectedIncidence();
00700
if ( incidence ) selected.append( incidence );
00701 }
00702
00703
return selected;
00704 }
00705
00706 DateList
KOMonthView::selectedDates()
00707 {
00708 DateList selected;
00709
00710
if ( mSelectedCell ) {
00711
QDate qd = mSelectedCell->
selectedIncidenceDate();
00712
if ( qd.isValid() ) selected.append( qd );
00713 }
00714
00715
return selected;
00716 }
00717
00718 bool KOMonthView::eventDurationHint(
QDateTime &startDt,
QDateTime &endDt,
bool &allDay )
00719 {
00720
if ( mSelectedCell ) {
00721 startDt.setDate( mSelectedCell->
date() );
00722 endDt.setDate( mSelectedCell->
date() );
00723 allDay =
true;
00724
return true;
00725 }
00726
return false;
00727 }
00728
00729 void KOMonthView::printPreview(
CalPrinter *calPrinter,
const QDate &fd,
00730
const QDate &td )
00731 {
00732
#ifndef KORG_NOPRINTER
00733
calPrinter->
preview( CalPrinter::Month, fd, td );
00734
#endif
00735
}
00736
00737 void KOMonthView::updateConfig()
00738 {
00739 mWeekStartDay = KGlobal::locale()->weekStartDay();
00740
00741
QFontMetrics fontmetric( mDayLabels[0]->font() );
00742 mWidthLongDayLabel = 0;
00743
00744
for (
int i = 0; i < 7; i++) {
00745
int width =
00746 fontmetric.width( KOGlobals::self()->calendarSystem()->weekDayName( i + 1 ) );
00747
if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
00748 }
00749
00750 updateDayLabels();
00751
00752
for ( uint i = 0; i < mCells.count(); ++i ) {
00753 mCells[i]->updateConfig();
00754 }
00755 }
00756
00757
void KOMonthView::updateDayLabels()
00758 {
00759 kdDebug(5850) <<
"KOMonthView::updateDayLabels()" << endl;
00760
00761
const KCalendarSystem*calsys=KOGlobals::self()->calendarSystem();
00762
int currDay;
00763
for (
int i = 0; i < 7; i++ ) {
00764 currDay = i+mWeekStartDay;
00765
if ( currDay > 7 ) currDay -= 7;
00766 mDayLabels[i]->setText( calsys->weekDayName( currDay, mShortDayLabels ) );
00767 }
00768 }
00769
00770 void KOMonthView::showDates(
const QDate &start,
const QDate & )
00771 {
00772
00773
00774 mStartDate = start;
00775
00776
00777
int weekdayCol=( mStartDate.dayOfWeek() + 7 - mWeekStartDay ) % 7;
00778 mStartDate = mStartDate.addDays( -weekdayCol );
00779
00780
bool primary =
false;
00781 uint i;
00782
for( i = 0; i < mCells.size(); ++i ) {
00783
QDate date = mStartDate.addDays( i );
00784
if ( KOGlobals::self()->calendarSystem()->day( date ) == 1 ) {
00785 primary = !primary;
00786 }
00787 mCells[i]->setDate( date );
00788
00789 mCells[i]->setPrimary( primary );
00790
00791
if ( KOGlobals::self()->calendarSystem()->dayOfWeek( date ) ==
00792 KOGlobals::self()->calendarSystem()->weekDayOfPray() ) {
00793 mCells[i]->setHoliday(
true );
00794 }
else {
00795 mCells[i]->setHoliday(
false );
00796 }
00797
00798
#ifndef KORG_NOPLUGINS
00799
00800
QString hstring( KOCore::self()->holiday( date ) );
00801 mCells[i]->setHoliday( hstring );
00802
#endif
00803
}
00804
00805
updateView();
00806 }
00807
00808 void KOMonthView::showIncidences(
const Incidence::List & )
00809 {
00810 kdDebug(5850) <<
"KOMonthView::showIncidences( const Incidence::List & ) is not implemented yet." << endl;
00811 }
00812
00813
void KOMonthView::changeIncidenceDisplayAdded( Incidence *incidence )
00814 {
00815
MonthViewCell *mvc;
00816 Event *event = 0;
00817 Todo *todo = 0;
00818
QDate date;
00819
if ( incidence->type() ==
"Event" ) {
00820 event = static_cast<Event *>( incidence );
00821 date = event->dtStart().date();
00822 }
00823
if ( incidence->type() ==
"Todo" ) {
00824 todo = static_cast<Todo *>( incidence );
00825
if ( !todo->hasDueDate() )
return;
00826 date = todo->dtDue().date();
00827 }
00828
00829
if ( incidence->doesRecur() ) {
00830
for ( uint i = 0; i < mCells.count(); i++ ) {
00831
if ( incidence->recursOn( mCells[i]->date() ) ) {
00832 mCells[i]->addIncidence( incidence );
00833 }
00834 }
00835 }
else if ( event ) {
00836
for (
QDateTime _date = date;
00837 _date <= event->dtEnd(); _date = _date.addDays( 1 ) ) {
00838 mvc =
lookupCellByDate( _date.date() );
00839
if ( mvc ) mvc->
addIncidence( event );
00840 }
00841 }
else if ( todo ) {
00842 mvc =
lookupCellByDate( date );
00843
if ( mvc ) mvc->
addIncidence( todo );
00844 }
00845 }
00846
00847 void KOMonthView::changeIncidenceDisplay( Incidence *incidence,
int action )
00848 {
00849
switch ( action ) {
00850
case KOGlobals::INCIDENCEADDED:
00851 changeIncidenceDisplayAdded( incidence );
00852
break;
00853
case KOGlobals::INCIDENCEEDITED:
00854
for( uint i = 0; i < mCells.count(); i++ )
00855 mCells[i]->removeIncidence( incidence );
00856 changeIncidenceDisplayAdded( incidence );
00857
break;
00858
case KOGlobals::INCIDENCEDELETED:
00859
for( uint i = 0; i < mCells.count(); i++ )
00860 mCells[i]->removeIncidence( incidence );
00861
break;
00862
default:
00863
return;
00864 }
00865 }
00866
00867 void KOMonthView::updateView()
00868 {
00869
for( uint i = 0; i < mCells.count(); ++i ) {
00870 mCells[i]->updateCell();
00871 }
00872
00873 Incidence::List incidences =
calendar()->incidences();
00874 Incidence::List::ConstIterator it;
00875
00876
for ( it = incidences.begin(); it != incidences.end(); ++it )
00877 changeIncidenceDisplayAdded( *it );
00878
00879 processSelectionChange();
00880 }
00881
00882
void KOMonthView::resizeEvent(
QResizeEvent * )
00883 {
00884
00885
00886
00887
00888
if( mDayLabels[0]->width() < mWidthLongDayLabel ) {
00889
if ( !mShortDayLabels ) {
00890 mShortDayLabels =
true;
00891 updateDayLabels();
00892 }
00893 }
else {
00894
if ( mShortDayLabels ) {
00895 mShortDayLabels =
false;
00896 updateDayLabels();
00897 }
00898 }
00899 }
00900
00901
void KOMonthView::showEventContextMenu( Incidence *incidence,
QDate qd )
00902 {
00903 mEventContextMenu->showIncidencePopup( incidence, qd );
00904
00905
00906
00907
00908
00909
00910
00911
00912 }
00913
00914
void KOMonthView::showGeneralContextMenu()
00915 {
00916 showNewEventPopup();
00917 }
00918
00919
void KOMonthView::setSelectedCell(
MonthViewCell *cell )
00920 {
00921
if ( cell == mSelectedCell )
return;
00922
00923
if ( mSelectedCell ) mSelectedCell->
deselect();
00924
00925 mSelectedCell = cell;
00926
00927
if ( !mSelectedCell )
00928 emit incidenceSelected( 0 );
00929
else
00930 emit incidenceSelected( mSelectedCell->
selectedIncidence() );
00931 }
00932
00933
void KOMonthView::processSelectionChange()
00934 {
00935 Incidence::List incidences =
selectedIncidences();
00936
if (incidences.count() > 0) {
00937 emit incidenceSelected( incidences.first() );
00938 }
else {
00939 emit incidenceSelected( 0 );
00940 }
00941 }
00942
00943 void KOMonthView::clearSelection()
00944 {
00945
if ( mSelectedCell ) {
00946 mSelectedCell->
deselect();
00947 mSelectedCell = 0;
00948 }
00949 }
00950
00951 MonthViewCell *
KOMonthView::lookupCellByDate (
const QDate &date )
00952 {
00953
for( uint i = 0; i < mCells.count(); i++ ) {
00954
if ( mCells[i]->date() == date )
00955
return mCells[i];
00956 }
00957
return 0;
00958 }