korganizer Library API Documentation

komonthview.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #include <qpopupmenu.h> 00021 #include <qfont.h> 00022 #include <qfontmetrics.h> 00023 #include <qkeycode.h> 00024 #include <qhbox.h> 00025 #include <qvbox.h> 00026 #include <qpushbutton.h> 00027 #include <qtooltip.h> 00028 #include <qpainter.h> 00029 #include <qcursor.h> 00030 #include <qlistbox.h> 00031 00032 #include <kdebug.h> 00033 #include <klocale.h> 00034 #include <kglobal.h> 00035 #include <kconfig.h> 00036 #include <kiconloader.h> 00037 #include <kwordwrap.h> 00038 00039 #include <kcalendarsystem.h> 00040 00041 #ifndef KORG_NOPRINTER 00042 #include "calprinter.h" 00043 #endif 00044 #include "koprefs.h" 00045 #ifndef KORG_NOPLUGINS 00046 #include "kocore.h" 00047 #endif 00048 #include "koglobals.h" 00049 #include "koincidencetooltip.h" 00050 00051 #include "komonthview.h" 00052 #include "komonthview.moc" 00053 00054 //-------------------------------------------------------------------------- 00055 00056 KOMonthCellToolTip::KOMonthCellToolTip( QWidget* parent, 00057 KNoScrollListBox* lv ) 00058 :QToolTip(parent) 00059 { 00060 eventlist=lv; 00061 } 00062 00063 void KOMonthCellToolTip::maybeTip( const QPoint & pos) 00064 { 00065 QRect r; 00066 QListBoxItem *it = eventlist->itemAt(pos); 00067 MonthViewItem *i = static_cast<MonthViewItem*>(it); 00068 00069 if( i && KOPrefs::instance()->mEnableToolTips ) { 00070 /* Calculate the rectangle. */ 00071 r=eventlist->itemRect( it ); 00072 /* Show the tip */ 00073 QString tipText; 00074 ToolTipVisitor v; 00075 if (v.act(i->incidence(), &tipText, true)) { 00076 tip(r, tipText); 00077 } 00078 } 00079 00080 } 00081 00082 KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) 00083 : QListBox(parent, name), 00084 mSqueezing(false) 00085 { 00086 QPalette pal = palette(); 00087 pal.setColor( QColorGroup::Foreground, KOPrefs::instance()->agendaBgColor().dark( 150 ) ); 00088 pal.setColor( QColorGroup::Base, KOPrefs::instance()->agendaBgColor() ); 00089 setPalette( pal ); 00090 } 00091 00092 void KNoScrollListBox::keyPressEvent(QKeyEvent *e) 00093 { 00094 switch(e->key()) { 00095 case Key_Right: 00096 scrollBy(4,0); 00097 break; 00098 case Key_Left: 00099 scrollBy(-4,0); 00100 break; 00101 case Key_Up: 00102 if(!count()) break; 00103 setCurrentItem((currentItem()+count()-1)%count()); 00104 if(!itemVisible(currentItem())) { 00105 if((unsigned int) currentItem() == (count()-1)) { 00106 setTopItem(currentItem()-numItemsVisible()+1); 00107 } else { 00108 setTopItem(topItem()-1); 00109 } 00110 } 00111 break; 00112 case Key_Down: 00113 if(!count()) break; 00114 setCurrentItem((currentItem()+1)%count()); 00115 if(!itemVisible(currentItem())) { 00116 if(currentItem() == 0) { 00117 setTopItem(0); 00118 } else { 00119 setTopItem(topItem()+1); 00120 } 00121 } 00122 case Key_Shift: 00123 emit shiftDown(); 00124 break; 00125 default: 00126 break; 00127 } 00128 } 00129 00130 void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) 00131 { 00132 switch(e->key()) { 00133 case Key_Shift: 00134 emit shiftUp(); 00135 break; 00136 default: 00137 break; 00138 } 00139 } 00140 00141 void KNoScrollListBox::mousePressEvent(QMouseEvent *e) 00142 { 00143 QListBox::mousePressEvent(e); 00144 00145 if(e->button() == RightButton) { 00146 emit rightClick(); 00147 } 00148 } 00149 00150 void KNoScrollListBox::contentsMouseDoubleClickEvent ( QMouseEvent * e ) 00151 { 00152 QListBox::contentsMouseDoubleClickEvent( e ); 00153 QListBoxItem* item = itemAt( e->pos() ); 00154 if (!item) { 00155 emit doubleClicked( item ); 00156 } 00157 } 00158 00159 void KNoScrollListBox::resizeEvent(QResizeEvent *e) 00160 { 00161 bool s = count() && ( maxItemWidth() > e->size().width() ); 00162 if (mSqueezing || s) 00163 triggerUpdate(false); 00164 00165 mSqueezing = s; 00166 QListBox::resizeEvent(e); 00167 } 00168 00169 MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) 00170 : QListBoxItem() 00171 { 00172 setText( s ); 00173 00174 mIncidence = incidence; 00175 mDate = qd; 00176 00177 mAlarmPixmap = KOGlobals::self()->smallIcon("bell"); 00178 mRecurPixmap = KOGlobals::self()->smallIcon("recur"); 00179 mReplyPixmap = KOGlobals::self()->smallIcon("mail_reply"); 00180 00181 mRecur = false; 00182 mAlarm = false; 00183 mReply = false; 00184 } 00185 00186 void MonthViewItem::paint(QPainter *p) 00187 { 00188 #if QT_VERSION >= 0x030000 00189 bool sel = isSelected(); 00190 #else 00191 bool sel = selected(); 00192 #endif 00193 00194 QColor bgColor = palette().color( QPalette::Normal, 00195 sel ? QColorGroup::Highlight : QColorGroup::Background ); 00196 if (KOPrefs::instance()->monthViewUsesCategoryColor()) 00197 { 00198 p->setBackgroundColor( bgColor ); 00199 p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); 00200 } 00201 int x = 3; 00202 if ( mRecur ) { 00203 p->drawPixmap( x, 0, mRecurPixmap ); 00204 x += mRecurPixmap.width() + 2; 00205 } 00206 if ( mAlarm ) { 00207 p->drawPixmap( x, 0, mAlarmPixmap ); 00208 x += mAlarmPixmap.width() + 2; 00209 } 00210 if ( mReply ) { 00211 p->drawPixmap(x, 0, mReplyPixmap ); 00212 x += mReplyPixmap.width() + 2; 00213 } 00214 QFontMetrics fm = p->fontMetrics(); 00215 int yPos; 00216 int pmheight = QMAX( mRecurPixmap.height(), 00217 QMAX( mAlarmPixmap.height(), mReplyPixmap.height() ) ); 00218 if( pmheight < fm.height() ) 00219 yPos = fm.ascent() + fm.leading()/2; 00220 else 00221 yPos = pmheight/2 - fm.height()/2 + fm.ascent(); 00222 QColor textColor = palette().color( QPalette::Normal, sel ? \ 00223 QColorGroup::HighlightedText : QColorGroup::Text ); 00224 p->setPen( textColor ); 00225 00226 KWordWrap::drawFadeoutText(p, x, yPos, listBox()->width() - x, text()); 00227 } 00228 00229 int MonthViewItem::height(const QListBox *lb) const 00230 { 00231 return QMAX( QMAX( mRecurPixmap.height(), mReplyPixmap.height() ), 00232 QMAX( mAlarmPixmap.height(), lb->fontMetrics().lineSpacing()+1) ); 00233 } 00234 00235 int MonthViewItem::width(const QListBox *lb) const 00236 { 00237 int x = 3; 00238 if( mRecur ) { 00239 x += mRecurPixmap.width()+2; 00240 } 00241 if( mAlarm ) { 00242 x += mAlarmPixmap.width()+2; 00243 } 00244 if( mReply ) { 00245 x += mReplyPixmap.width()+2; 00246 } 00247 00248 return( x + lb->fontMetrics().boundingRect( text() ).width() + 1 ); 00249 } 00250 00251 00252 MonthViewCell::MonthViewCell( KOMonthView *parent) 00253 : QWidget( parent ), 00254 mMonthView( parent ) 00255 { 00256 QVBoxLayout *topLayout = new QVBoxLayout( this ); 00257 00258 mLabel = new QLabel( this ); 00259 mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); 00260 mLabel->setLineWidth( 1 ); 00261 mLabel->setAlignment( AlignCenter ); 00262 00263 mItemList = new KNoScrollListBox( this ); 00264 mItemList->setMinimumSize( 10, 10 ); 00265 mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain ); 00266 mItemList->setLineWidth( 1 ); 00267 00268 new KOMonthCellToolTip( mItemList->viewport(), (KNoScrollListBox*)mItemList ); 00269 00270 topLayout->addWidget( mItemList ); 00271 00272 mLabel->raise(); 00273 00274 mStandardPalette = palette(); 00275 00276 enableScrollBars( false ); 00277 00278 updateConfig(); 00279 00280 connect( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ), 00281 SLOT( defaultAction( QListBoxItem * ) ) ); 00282 connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *, 00283 const QPoint &) ), 00284 SLOT( contextMenu( QListBoxItem * ) ) ); 00285 connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ), 00286 SLOT( selection( QListBoxItem * ) ) ); 00287 connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), 00288 SLOT( cellClicked( QListBoxItem * ) ) ); 00289 } 00290 00291 void MonthViewCell::setDate( const QDate &date ) 00292 { 00293 // kdDebug(5850) << "MonthViewCell::setDate(): " << date.toString() << endl; 00294 00295 mDate = date; 00296 00297 QString text; 00298 if ( KOGlobals::self()->calendarSystem()->day( date ) == 1 ) { 00299 text = KOGlobals::self()->calendarSystem()->monthName( date, true ) + " "; 00300 QFontMetrics fm( mLabel->font() ); 00301 mLabel->resize( mLabelSize + QSize( fm.width( text ), 0 ) ); 00302 } else { 00303 mLabel->resize( mLabelSize ); 00304 } 00305 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 00306 mLabel->setText( text ); 00307 00308 resizeEvent( 0 ); 00309 } 00310 00311 QDate MonthViewCell::date() const 00312 { 00313 return mDate; 00314 } 00315 00316 void MonthViewCell::setPrimary( bool primary ) 00317 { 00318 mPrimary = primary; 00319 00320 if ( mPrimary ) { 00321 mLabel->setBackgroundMode( PaletteBase ); 00322 } else { 00323 mLabel->setBackgroundMode( PaletteBackground ); 00324 } 00325 } 00326 00327 bool MonthViewCell::isPrimary() const 00328 { 00329 return mPrimary; 00330 } 00331 00332 void MonthViewCell::setHoliday( bool holiday ) 00333 { 00334 mHoliday = holiday; 00335 00336 if ( holiday ) { 00337 setPalette( mHolidayPalette ); 00338 } else { 00339 setPalette( mStandardPalette ); 00340 } 00341 } 00342 00343 void MonthViewCell::setHoliday( const QString &holiday ) 00344 { 00345 mHolidayString = holiday; 00346 00347 if ( !holiday.isEmpty() ) { 00348 setHoliday( true ); 00349 } 00350 } 00351 00352 void MonthViewCell::updateCell() 00353 { 00354 if ( mDate == QDate::currentDate() ) { 00355 setPalette( mTodayPalette ); 00356 } 00357 else { 00358 if ( mHoliday ) 00359 setPalette( mHolidayPalette ); 00360 else 00361 setPalette( mStandardPalette ); 00362 } 00363 00364 mItemList->clear(); 00365 00366 if ( !mHolidayString.isEmpty() ) { 00367 MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); 00368 item->setPalette( mHolidayPalette ); 00369 mItemList->insertItem( item ); 00370 } 00371 00372 Event::List events = mMonthView->calendar()->events( mDate, true ); 00373 Event::List::ConstIterator it; 00374 for( it = events.begin(); it != events.end(); ++it ) { 00375 Event *event = *it; 00376 QString text; 00377 if (event->isMultiDay()) { 00378 if (mDate == event->dtStart().date()) { 00379 text = "(-- " + event->summary(); 00380 } else if (mDate == event->dtEnd().date()) { 00381 text = event->summary() + " --)"; 00382 } else if (!(event->dtStart().date().daysTo(mDate) % 7)) { 00383 text = "-- " + event->summary() + " --"; 00384 } else { 00385 text = "----------------"; 00386 } 00387 } else { 00388 if (event->doesFloat()) 00389 text = event->summary(); 00390 else { 00391 text = KGlobal::locale()->formatTime(event->dtStart().time()); 00392 text += " " + event->summary(); 00393 } 00394 } 00395 00396 MonthViewItem *item = new MonthViewItem( event, mDate, text ); 00397 if (KOPrefs::instance()->monthViewUsesCategoryColor()) { 00398 QStringList categories = event->categories(); 00399 QString cat = categories.first(); 00400 if (cat.isEmpty()) { 00401 item->setPalette(QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor)); 00402 } else { 00403 item->setPalette(QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)))); 00404 } 00405 } else { 00406 item->setPalette( mStandardPalette ); 00407 } 00408 item->setRecur( event->doesRecur() ); 00409 item->setAlarm( event->isAlarmEnabled() ); 00410 00411 Attendee *me = event->attendeeByMails(KOPrefs::instance()->additionalMails(), 00412 KOPrefs::instance()->email()); 00413 if ( me != 0 ) { 00414 if ( me->status() == Attendee::NeedsAction && me->RSVP()) 00415 item->setReply(true); 00416 else 00417 item->setReply(false); 00418 } else 00419 item->setReply(false); 00420 00421 mItemList->insertItem( item ); 00422 } 00423 00424 // insert due todos 00425 Todo::List todos = mMonthView->calendar()->todos( mDate ); 00426 Todo::List::ConstIterator it2; 00427 for( it2 = todos.begin(); it2 != todos.end(); ++it2 ) { 00428 Todo *todo = *it2; 00429 QString text; 00430 if (todo->hasDueDate()) { 00431 if (!todo->doesFloat()) { 00432 text += KGlobal::locale()->formatTime(todo->dtDue().time()); 00433 text += " "; 00434 } 00435 } 00436 text += i18n("To-Do: %1").arg(todo->summary()); 00437 00438 MonthViewItem *item = new MonthViewItem( todo, mDate, text ); 00439 item->setPalette( mStandardPalette ); 00440 00441 mItemList->insertItem( item ); 00442 } 00443 } 00444 00445 void MonthViewCell::updateConfig() 00446 { 00447 setFont( KOPrefs::instance()->mMonthViewFont ); 00448 00449 QFontMetrics fm( font() ); 00450 mLabelSize = fm.size( 0, "30" ) + 00451 QSize( mLabel->frameWidth() * 2, mLabel->frameWidth() * 2 ) + 00452 QSize( 2, 2 ); 00453 00454 mHolidayPalette = mStandardPalette; 00455 mHolidayPalette.setColor(QColorGroup::Foreground, 00456 KOPrefs::instance()->holidayColor()); 00457 mHolidayPalette.setColor(QColorGroup::Text, 00458 KOPrefs::instance()->holidayColor()); 00459 mTodayPalette = mStandardPalette; 00460 mTodayPalette.setColor(QColorGroup::Foreground, 00461 KOPrefs::instance()->highlightColor()); 00462 mTodayPalette.setColor(QColorGroup::Text, 00463 KOPrefs::instance()->highlightColor()); 00464 updateCell(); 00465 } 00466 00467 void MonthViewCell::enableScrollBars( bool enabled ) 00468 { 00469 if ( enabled ) { 00470 mItemList->setVScrollBarMode(QScrollView::Auto); 00471 mItemList->setHScrollBarMode(QScrollView::Auto); 00472 } else { 00473 mItemList->setVScrollBarMode(QScrollView::AlwaysOff); 00474 mItemList->setHScrollBarMode(QScrollView::AlwaysOff); 00475 } 00476 } 00477 00478 Incidence *MonthViewCell::selectedIncidence() 00479 { 00480 int index = mItemList->currentItem(); 00481 if ( index < 0 ) return 0; 00482 00483 MonthViewItem *item = 00484 static_cast<MonthViewItem *>( mItemList->item( index ) ); 00485 00486 if ( !item ) return 0; 00487 00488 return item->incidence(); 00489 } 00490 00491 QDate MonthViewCell::selectedIncidenceDate() 00492 { 00493 QDate qd; 00494 int index = mItemList->currentItem(); 00495 if ( index < 0 ) return qd; 00496 00497 MonthViewItem *item = 00498 static_cast<MonthViewItem *>( mItemList->item( index ) ); 00499 00500 if ( !item ) return qd; 00501 00502 return item->incidenceDate(); 00503 } 00504 00505 void MonthViewCell::deselect() 00506 { 00507 mItemList->clearSelection(); 00508 00509 enableScrollBars( false ); 00510 } 00511 00512 void MonthViewCell::resizeEvent ( QResizeEvent * ) 00513 { 00514 mLabel->move( width() - mLabel->width(), height() - mLabel->height() ); 00515 } 00516 00517 void MonthViewCell::defaultAction( QListBoxItem *item ) 00518 { 00519 if ( !item ) { 00520 emit newEventSignal( date() ); 00521 } else { 00522 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 00523 Incidence *incidence = eventItem->incidence(); 00524 if ( incidence ) mMonthView->defaultAction( incidence ); 00525 } 00526 } 00527 00528 void MonthViewCell::cellClicked( QListBoxItem * ) 00529 { 00530 if( KOPrefs::instance()->enableMonthScroll() ) enableScrollBars( true ); 00531 } 00532 00533 void MonthViewCell::contextMenu( QListBoxItem *item ) 00534 { 00535 if ( item ) { 00536 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 00537 Incidence *incidence = eventItem->incidence(); 00538 if ( incidence ) mMonthView->showEventContextMenu( incidence ); 00539 } 00540 else { 00541 mMonthView->showGeneralContextMenu(); 00542 } 00543 } 00544 00545 void MonthViewCell::selection( QListBoxItem *item ) 00546 { 00547 if ( !item ) return; 00548 00549 mMonthView->setSelectedCell( this ); 00550 } 00551 00552 KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) 00553 : KOEventView( calendar, parent, name ), 00554 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), 00555 mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) 00556 { 00557 mCells.setAutoDelete( true ); 00558 00559 QGridLayout *dayLayout = new QGridLayout( this ); 00560 00561 // create the day of the week labels (Sun, Mon, etc) and add them to 00562 // the layout. 00563 mDayLabels.resize( mDaysPerWeek ); 00564 QFont bfont = font(); 00565 bfont.setBold( true ); 00566 int i; 00567 for( i = 0; i < mDaysPerWeek; i++ ) { 00568 QLabel *label = new QLabel( this ); 00569 label->setFont(bfont); 00570 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 00571 label->setLineWidth(1); 00572 label->setAlignment(AlignCenter); 00573 00574 mDayLabels.insert( i, label ); 00575 00576 dayLayout->addWidget( label, 0, i ); 00577 dayLayout->addColSpacing( i, 10 ); 00578 dayLayout->setColStretch( i, 1 ); 00579 } 00580 00581 int row, col; 00582 00583 mCells.resize( mNumCells ); 00584 for( row = 0; row < mNumWeeks; ++row ) { 00585 for( col = 0; col < mDaysPerWeek; ++col ) { 00586 MonthViewCell *cell = new MonthViewCell( this ); 00587 mCells.insert( row * mDaysPerWeek + col, cell ); 00588 dayLayout->addWidget( cell, row + 1, col ); 00589 00590 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 00591 SLOT( defaultAction( Incidence * ) ) ); 00592 connect( cell, SIGNAL( newEventSignal( QDate ) ), 00593 SIGNAL( newEventSignal( QDate ) ) ); 00594 } 00595 dayLayout->setRowStretch( row + 1, 1 ); 00596 } 00597 00598 mEventContextMenu = eventPopup(); 00599 00600 updateConfig(); 00601 00602 emit incidenceSelected( 0 ); 00603 } 00604 00605 KOMonthView::~KOMonthView() 00606 { 00607 if (mEventContextMenu) delete mEventContextMenu; 00608 } 00609 00610 int KOMonthView::maxDatesHint() 00611 { 00612 return mNumCells; 00613 } 00614 00615 int KOMonthView::currentDateCount() 00616 { 00617 return mNumCells; 00618 } 00619 00620 Incidence::List KOMonthView::selectedIncidences() 00621 { 00622 Incidence::List selected; 00623 00624 if ( mSelectedCell ) { 00625 Incidence *incidence = mSelectedCell->selectedIncidence(); 00626 if ( incidence ) selected.append( incidence ); 00627 } 00628 00629 return selected; 00630 } 00631 00632 DateList KOMonthView::selectedDates() 00633 { 00634 DateList selected; 00635 00636 if ( mSelectedCell ) { 00637 QDate qd = mSelectedCell->selectedIncidenceDate(); 00638 if ( qd.isValid() ) selected.append( qd ); 00639 } 00640 00641 return selected; 00642 } 00643 00644 void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, 00645 const QDate &td) 00646 { 00647 #ifndef KORG_NOPRINTER 00648 calPrinter->preview(CalPrinter::Month, fd, td); 00649 #endif 00650 } 00651 00652 void KOMonthView::updateConfig() 00653 { 00654 mWeekStartDay = KGlobal::locale()->weekStartDay(); 00655 00656 QFontMetrics fontmetric(mDayLabels[0]->font()); 00657 mWidthLongDayLabel = 0; 00658 00659 for (int i = 0; i < 7; i++) { 00660 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 00661 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 00662 } 00663 00664 updateDayLabels(); 00665 00666 for (uint i = 0; i < mCells.count(); ++i) { 00667 mCells[i]->updateConfig(); 00668 } 00669 } 00670 00671 void KOMonthView::updateDayLabels() 00672 { 00673 kdDebug(5850) << "KOMonthView::updateDayLabels()" << endl; 00674 00675 const KCalendarSystem*calsys=KOGlobals::self()->calendarSystem(); 00676 int currDay; 00677 for (int i = 0; i < 7; i++) { 00678 currDay = i+mWeekStartDay; 00679 if (currDay>7) currDay-=7; 00680 mDayLabels[i]->setText(calsys->weekDayName(currDay, mShortDayLabels) ); 00681 } 00682 } 00683 00684 void KOMonthView::showDates(const QDate &start, const QDate &) 00685 { 00686 // kdDebug(5850) << "KOMonthView::showDates(): " << start.toString() << endl; 00687 00688 mStartDate = start; 00689 00690 // correct begin of week 00691 int weekdayCol=(mStartDate.dayOfWeek()+7-mWeekStartDay)%7; 00692 mStartDate = mStartDate.addDays(-weekdayCol); 00693 00694 bool primary = false; 00695 uint i; 00696 for( i = 0; i < mCells.size(); ++i ) { 00697 QDate date = mStartDate.addDays( i ); 00698 if ( KOGlobals::self()->calendarSystem()->day(date) == 1 ) { 00699 primary = !primary; 00700 } 00701 mCells[i]->setPrimary( primary ); 00702 00703 if ( KOGlobals::self()->calendarSystem()->dayOfWeek(date) == KOGlobals::self()->calendarSystem()->weekDayOfPray() ) { 00704 mCells[i]->setHoliday( true ); 00705 } else { 00706 mCells[i]->setHoliday( false ); 00707 } 00708 00709 #ifndef KORG_NOPLUGINS 00710 // add holiday, if present 00711 QString hstring(KOCore::self()->holiday(date)); 00712 mCells[i]->setHoliday( hstring ); 00713 #endif 00714 00715 mCells[i]->setDate( date ); 00716 } 00717 00718 updateView(); 00719 } 00720 00721 void KOMonthView::showEvents( const Event::List & ) 00722 { 00723 kdDebug(5850) << "KOMonthView::selectEvents is not implemented yet." << endl; 00724 } 00725 00726 void KOMonthView::changeEventDisplay(Event *, int) 00727 { 00728 // this should be re-written to be much more efficient, but this 00729 // quick-and-dirty-hack gets the job done for right now. 00730 updateView(); 00731 } 00732 00733 void KOMonthView::updateView() 00734 { 00735 uint i; 00736 for( i = 0; i < mCells.count(); ++i ) { 00737 mCells[i]->updateCell(); 00738 } 00739 00740 processSelectionChange(); 00741 } 00742 00743 void KOMonthView::resizeEvent(QResizeEvent *) 00744 { 00745 // select the appropriate heading string size. E.g. "Wednesday" or "Wed". 00746 // note this only changes the text if the requested size crosses the 00747 // threshold between big enough to support the full name and not big 00748 // enough. 00749 if( mDayLabels[0]->width() < mWidthLongDayLabel ) { 00750 if ( !mShortDayLabels ) { 00751 mShortDayLabels = true; 00752 updateDayLabels(); 00753 } 00754 } else { 00755 if ( mShortDayLabels ) { 00756 mShortDayLabels = false; 00757 updateDayLabels(); 00758 } 00759 } 00760 } 00761 00762 void KOMonthView::showEventContextMenu( Incidence *incidence ) 00763 { 00764 mEventContextMenu->showIncidencePopup(incidence); 00765 /* 00766 if( incidence && incidence->type() == "Event" ) { 00767 Event *event = static_cast<Event *>(incidence); 00768 mContextMenu->showEventPopup(event); 00769 } else { 00770 kdDebug(5850) << "MonthView::showContextMenu(): cast failed." << endl; 00771 } 00772 */ 00773 } 00774 00775 void KOMonthView::showGeneralContextMenu() 00776 { 00777 QPopupMenu *menu = newEventPopup(); 00778 00779 if ( menu ) 00780 menu->popup( QCursor::pos() ); 00781 } 00782 00783 void KOMonthView::setSelectedCell( MonthViewCell *cell ) 00784 { 00785 if ( cell == mSelectedCell ) return; 00786 00787 if ( mSelectedCell ) mSelectedCell->deselect(); 00788 00789 mSelectedCell = cell; 00790 00791 if ( !mSelectedCell ) 00792 emit incidenceSelected( 0 ); 00793 else 00794 emit incidenceSelected( mSelectedCell->selectedIncidence() ); 00795 } 00796 00797 void KOMonthView::processSelectionChange() 00798 { 00799 Incidence::List incidences = selectedIncidences(); 00800 if (incidences.count() > 0) { 00801 emit incidenceSelected( incidences.first() ); 00802 } else { 00803 emit incidenceSelected( 0 ); 00804 } 00805 } 00806 00807 void KOMonthView::clearSelection() 00808 { 00809 if ( mSelectedCell ) { 00810 mSelectedCell->deselect(); 00811 mSelectedCell = 0; 00812 } 00813 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:13 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003