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   mGeneralContextMenu = 0;
00600 
00601   updateConfig();
00602 
00603   emit incidenceSelected( 0 );
00604 }
00605 
00606 KOMonthView::~KOMonthView()
00607 {
00608   if (mEventContextMenu) delete mEventContextMenu;
00609   if (mGeneralContextMenu) delete mGeneralContextMenu;
00610 }
00611 
00612 int KOMonthView::maxDatesHint()
00613 {
00614   return mNumCells;
00615 }
00616 
00617 int KOMonthView::currentDateCount()
00618 {
00619   return mNumCells;
00620 }
00621 
00622 Incidence::List KOMonthView::selectedIncidences()
00623 {
00624   Incidence::List selected;
00625 
00626   if ( mSelectedCell ) {
00627     Incidence *incidence = mSelectedCell->selectedIncidence();
00628     if ( incidence ) selected.append( incidence );
00629   }
00630 
00631   return selected;
00632 }
00633 
00634 DateList KOMonthView::selectedDates()
00635 {
00636   DateList selected;
00637 
00638   if ( mSelectedCell ) {
00639     QDate qd = mSelectedCell->selectedIncidenceDate();
00640     if ( qd.isValid() ) selected.append( qd );
00641   }
00642 
00643   return selected;
00644 }
00645 
00646 void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd,
00647                                const QDate &td)
00648 {
00649 #ifndef KORG_NOPRINTER
00650   calPrinter->preview(CalPrinter::Month, fd, td);
00651 #endif
00652 }
00653 
00654 void KOMonthView::updateConfig()
00655 {
00656   mWeekStartDay = KGlobal::locale()->weekStartDay();
00657 
00658   QFontMetrics fontmetric(mDayLabels[0]->font());
00659   mWidthLongDayLabel = 0;
00660 
00661   for (int i = 0; i < 7; i++) {
00662     int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
00663     if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
00664   }
00665 
00666   updateDayLabels();
00667 
00668   for (uint i = 0; i < mCells.count(); ++i) {
00669     mCells[i]->updateConfig();
00670   }
00671 }
00672 
00673 void KOMonthView::updateDayLabels()
00674 {
00675   kdDebug(5850) << "KOMonthView::updateDayLabels()" << endl;
00676 
00677   const KCalendarSystem*calsys=KOGlobals::self()->calendarSystem();
00678   int currDay;
00679   for (int i = 0; i < 7; i++) {
00680     currDay = i+mWeekStartDay;
00681     if (currDay>7) currDay-=7;
00682     mDayLabels[i]->setText(calsys->weekDayName(currDay, mShortDayLabels) );
00683   }
00684 }
00685 
00686 void KOMonthView::showDates(const QDate &start, const QDate &)
00687 {
00688 //  kdDebug(5850) << "KOMonthView::showDates(): " << start.toString() << endl;
00689 
00690   mStartDate = start;
00691 
00692   // correct begin of week
00693   int weekdayCol=(mStartDate.dayOfWeek()+7-mWeekStartDay)%7;
00694   mStartDate = mStartDate.addDays(-weekdayCol);
00695 
00696   bool primary = false;
00697   uint i;
00698   for( i = 0; i < mCells.size(); ++i ) {
00699     QDate date = mStartDate.addDays( i );
00700     if ( KOGlobals::self()->calendarSystem()->day(date) == 1 ) {
00701       primary = !primary;
00702     }
00703     mCells[i]->setPrimary( primary );
00704 
00705     if ( KOGlobals::self()->calendarSystem()->dayOfWeek(date) == KOGlobals::self()->calendarSystem()->weekDayOfPray() ) {
00706       mCells[i]->setHoliday( true );
00707     } else {
00708       mCells[i]->setHoliday( false );
00709     }
00710 
00711 #ifndef KORG_NOPLUGINS
00712     // add holiday, if present
00713     QString hstring(KOCore::self()->holiday(date));
00714     mCells[i]->setHoliday( hstring );
00715 #endif
00716 
00717     mCells[i]->setDate( date );
00718   }
00719 
00720   updateView();
00721 }
00722 
00723 void KOMonthView::showEvents( const Event::List & )
00724 {
00725   kdDebug(5850) << "KOMonthView::selectEvents is not implemented yet." << endl;
00726 }
00727 
00728 void KOMonthView::changeEventDisplay(Event *, int)
00729 {
00730   // this should be re-written to be much more efficient, but this
00731   // quick-and-dirty-hack gets the job done for right now.
00732   updateView();
00733 }
00734 
00735 void KOMonthView::updateView()
00736 {
00737   uint i;
00738   for( i = 0; i < mCells.count(); ++i ) {
00739     mCells[i]->updateCell();
00740   }
00741 
00742   processSelectionChange();
00743 }
00744 
00745 void KOMonthView::resizeEvent(QResizeEvent *)
00746 {
00747   // select the appropriate heading string size. E.g. "Wednesday" or "Wed".
00748   // note this only changes the text if the requested size crosses the
00749   // threshold between big enough to support the full name and not big
00750   // enough.
00751   if( mDayLabels[0]->width() < mWidthLongDayLabel ) {
00752     if ( !mShortDayLabels ) {
00753       mShortDayLabels = true;
00754       updateDayLabels();
00755     }
00756   } else {
00757     if ( mShortDayLabels ) {
00758       mShortDayLabels = false;
00759       updateDayLabels();
00760     }
00761   }
00762 }
00763 
00764 void KOMonthView::showEventContextMenu( Incidence *incidence )
00765 {
00766   mEventContextMenu->showIncidencePopup(incidence);
00767   /*
00768   if( incidence && incidence->type() == "Event" ) {
00769     Event *event = static_cast<Event *>(incidence);
00770     mContextMenu->showEventPopup(event);
00771   } else {
00772     kdDebug(5850) << "MonthView::showContextMenu(): cast failed." << endl;
00773   }
00774   */
00775 }
00776 
00777 void KOMonthView::showGeneralContextMenu()
00778 {
00779   if ( !mGeneralContextMenu )
00780     mGeneralContextMenu = newEventPopup();
00781 
00782   if (mGeneralContextMenu)
00783     mGeneralContextMenu->popup(QCursor::pos());
00784 }
00785 
00786 void KOMonthView::setSelectedCell( MonthViewCell *cell )
00787 {
00788   if ( cell == mSelectedCell ) return;
00789 
00790   if ( mSelectedCell ) mSelectedCell->deselect();
00791 
00792   mSelectedCell = cell;
00793 
00794   if ( !mSelectedCell )
00795     emit incidenceSelected( 0 );
00796   else
00797     emit incidenceSelected( mSelectedCell->selectedIncidence() );
00798 }
00799 
00800 void KOMonthView::processSelectionChange()
00801 {
00802   Incidence::List incidences = selectedIncidences();
00803   if (incidences.count() > 0) {
00804     emit incidenceSelected( incidences.first() );
00805   } else {
00806     emit incidenceSelected( 0 );
00807   }
00808 }
00809 
00810 void KOMonthView::clearSelection()
00811 {
00812   if ( mSelectedCell ) {
00813     mSelectedCell->deselect();
00814     mSelectedCell = 0;
00815   }
00816 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Mar 6 17:18:32 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003