korganizer Library API Documentation

koagendaview.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 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., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <qhbox.h>
00025 #include <qvbox.h>
00026 #include <qlabel.h>
00027 #include <qframe.h>
00028 #include <qlayout.h>
00029 #ifndef KORG_NOSPLITTER
00030 #include <qsplitter.h>
00031 #endif
00032 #include <qfont.h>
00033 #include <qfontmetrics.h>
00034 #include <qpopupmenu.h>
00035 #include <qtooltip.h>
00036 #include <qpainter.h>
00037 #include <qpushbutton.h>
00038 
00039 #include <kapplication.h>
00040 #include <kdebug.h>
00041 #include <kglobal.h>
00042 #include <kstandarddirs.h>
00043 #include <kiconloader.h>
00044 #include <klocale.h>
00045 #include <kconfig.h>
00046 
00047 #include <libkcal/calendar.h>
00048 #include <libkcal/icaldrag.h>
00049 #include <libkcal/dndfactory.h>
00050 
00051 #ifndef KORG_NOPLUGINS
00052 #include "kocore.h"
00053 #endif
00054 #include "koprefs.h"
00055 #include "koagenda.h"
00056 #include "koagendaitem.h"
00057 #ifndef KORG_NOPRINTER
00058 #include "calprinter.h"
00059 #endif
00060 
00061 #include "koagendaview.h"
00062 #include "koagendaview.moc"
00063 
00064 using namespace KOrg;
00065 
00066 TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) :
00067   QScrollView(parent,name,f)
00068 {
00069   mRows = rows;
00070 
00071   mCellHeight = KOPrefs::instance()->mHourSize*4;
00072 
00073   enableClipper(true);
00074 
00075   setHScrollBarMode(AlwaysOff);
00076   setVScrollBarMode(AlwaysOff);
00077 
00078   resizeContents(50,mRows * mCellHeight);
00079 
00080   viewport()->setBackgroundMode( PaletteBackground );
00081 }
00082 
00083 void TimeLabels::setCellHeight(int height)
00084 {
00085   mCellHeight = height;
00086 }
00087 
00088 /*
00089   Optimization so that only the "dirty" portion of the scroll view
00090   is redrawn.  Unfortunately, this is not called by default paintEvent() method.
00091 */
00092 void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch)
00093 {
00094   // bug:  the parameters cx, cy, cw, ch are the areas that need to be
00095   //       redrawn, not the area of the widget.  unfortunately, this
00096   //       code assumes the latter...
00097 
00098   // now, for a workaround...
00099   // these two assignments fix the weird redraw bug
00100   cx = contentsX() + 2;
00101   cw = contentsWidth() - 2;
00102   // end of workaround
00103 
00104   int cell = ((int)(cy/mCellHeight));
00105   int y = cell * mCellHeight;
00106   QFontMetrics fm = fontMetrics();
00107   QString hour;
00108   QString suffix;
00109   QString fullTime;
00110 
00111   while (y < cy + ch) {
00112     p->drawLine(cx,y,cx+cw,y);
00113     hour.setNum(cell);
00114     suffix = "am";
00115 
00116     // handle 24h and am/pm time formats
00117     if (KGlobal::locale()->use12Clock()) {
00118       if (cell > 11) suffix = "pm";
00119       if (cell == 0) hour.setNum(12);
00120       if (cell > 12) hour.setNum(cell - 12);
00121     } else {
00122       suffix = ":00";
00123     }
00124 
00125     // create string in format of "XX:XX" or "XXpm/am"
00126     fullTime = hour + suffix;
00127 
00128     // center and draw the time label
00129     int timeWidth = fm.width(fullTime);
00130     int offset = this->width() - timeWidth;
00131     int borderWidth = 5;
00132     p->drawText(cx -borderWidth + offset, y+15, fullTime);
00133 
00134     // increment indices
00135     y += mCellHeight;
00136     cell++;
00137   }
00138 }
00139 
00143 int TimeLabels::minimumWidth() const
00144 {
00145   QFontMetrics fm = fontMetrics();
00146 
00147   //TODO: calculate this value
00148   int borderWidth = 4;
00149 
00150   // the maximum width possible
00151   int width = fm.width("88:88") + borderWidth;
00152 
00153   return width;
00154 }
00155 
00157 void TimeLabels::updateConfig()
00158 {
00159   // set the font
00160 //  config->setGroup("Fonts");
00161 //  QFont font = config->readFontEntry("TimeBar Font");
00162   setFont(KOPrefs::instance()->mTimeBarFont);
00163 
00164   // update geometry restrictions based on new settings
00165   setFixedWidth(minimumWidth());
00166   
00167   // update HourSize
00168   mCellHeight = KOPrefs::instance()->mHourSize*4;
00169   resizeContents(50,mRows * mCellHeight);
00170 }
00171 
00173 void TimeLabels::positionChanged()
00174 {
00175   int adjustment = mAgenda->contentsY();
00176   setContentsPos(0, adjustment);
00177 }
00178 
00180 void TimeLabels::setAgenda(KOAgenda* agenda)
00181 {
00182   mAgenda = agenda;
00183 }
00184 
00185 
00187 void TimeLabels::paintEvent(QPaintEvent*)
00188 {
00189 //  kdDebug() << "paintevent..." << endl;
00190   // this is another hack!
00191 //  QPainter painter(this);
00192   //QString c
00193   repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());
00194 }
00195 
00197 
00198 EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name)
00199   : QFrame(parent,name)
00200 {
00201   mColumns = 1;
00202   mTopBox = 0;
00203   mLocation = loc;
00204   mTopLayout = 0;
00205 
00206   if (mLocation == Top) mPixmap = SmallIcon("1uparrow");
00207   else mPixmap = SmallIcon("1downarrow");
00208 
00209   setMinimumHeight(mPixmap.height());
00210 }
00211 
00212 EventIndicator::~EventIndicator()
00213 {
00214 }
00215 
00216 void EventIndicator::drawContents(QPainter *p)
00217 {
00218 //  kdDebug() << "======== top: " << contentsRect().top() << "  bottom " << //         contentsRect().bottom() << "  left " << contentsRect().left() << "  right " << contentsRect().right() << endl;
00219 
00220   int i;
00221   for(i=0;i<mColumns;++i) {
00222     if (mEnabled[i]) {
00223       int cellWidth = contentsRect().right()/mColumns;
00224       int xOffset = QApplication::reverseLayout() ? 
00225                (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
00226                i*cellWidth + cellWidth/2 -mPixmap.width()/2;
00227       p->drawPixmap(QPoint(xOffset,0),mPixmap);
00228     }
00229   }
00230 }
00231 
00232 void EventIndicator::changeColumns(int columns)
00233 {
00234   mColumns = columns;
00235   mEnabled.resize(mColumns);
00236 
00237   update();
00238 }
00239 
00240 void EventIndicator::enableColumn(int column, bool enable)
00241 {
00242   mEnabled[column] = enable;
00243 }
00244 
00245 
00249 
00250 KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) :
00251   KOEventView (cal,parent,name)
00252 {
00253   mStartHour = 8;
00254   mSelectedDates.append(QDate::currentDate());
00255 
00256   mLayoutDayLabels = 0;
00257   mDayLabelsFrame = 0;
00258   mDayLabels = 0;
00259 
00260   bool isRTL = QApplication::reverseLayout();
00261 
00262   if ( KOPrefs::instance()->mVerticalScreen ) {
00263     mExpandedPixmap = SmallIcon( "1downarrow" );
00264     mNotExpandedPixmap = SmallIcon( "1uparrow" );
00265   } else {
00266     mExpandedPixmap = SmallIcon( isRTL ? "1leftarrow" : "1rightarrow" );
00267     mNotExpandedPixmap = SmallIcon( isRTL ? "1rightarrow" : "1leftarrow" );
00268   }
00269 
00270   QBoxLayout *topLayout = new QVBoxLayout(this);
00271 
00272   // Create day name labels for agenda columns
00273   mDayLabelsFrame = new QHBox(this);
00274   topLayout->addWidget(mDayLabelsFrame);
00275 
00276   // Create agenda splitter
00277 #ifndef KORG_NOSPLITTER
00278   mSplitterAgenda = new QSplitter(Vertical,this);
00279   topLayout->addWidget(mSplitterAgenda);
00280   mSplitterAgenda->setOpaqueResize();
00281   
00282   mAllDayFrame = new QHBox(mSplitterAgenda);
00283 
00284   QWidget *agendaFrame = new QWidget(mSplitterAgenda);
00285 #else
00286   QVBox *mainBox = new QVBox( this );
00287   topLayout->addWidget( mainBox );
00288   
00289   mAllDayFrame = new QHBox(mainBox);
00290 
00291   QWidget *agendaFrame = new QWidget(mainBox);
00292 #endif
00293 
00294   // Create all-day agenda widget
00295   mDummyAllDayLeft = new QVBox( mAllDayFrame );
00296 
00297   mExpandButton = new QPushButton(mDummyAllDayLeft);
00298   mExpandButton->setPixmap( mNotExpandedPixmap );
00299   mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
00300                                 QSizePolicy::Fixed ) );
00301   connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) );
00302  
00303   mAllDayAgenda = new KOAgenda(1,mAllDayFrame);
00304   QWidget *dummyAllDayRight = new QWidget(mAllDayFrame);
00305 
00306   // Create event context menu for all day agenda
00307   mAllDayAgendaPopup = eventPopup();
00308   connect(mAllDayAgenda,SIGNAL(showEventPopupSignal(Event *)),
00309           mAllDayAgendaPopup,SLOT(showEventPopup(Event *)));
00310 
00311   // Create agenda frame
00312   QGridLayout *agendaLayout = new QGridLayout(agendaFrame,3,3);
00313 //  QHBox *agendaFrame = new QHBox(splitterAgenda);
00314 
00315   // create event indicator bars
00316   mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame);
00317   agendaLayout->addWidget(mEventIndicatorTop,0,1);
00318   mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom,
00319                                              agendaFrame);
00320   agendaLayout->addWidget(mEventIndicatorBottom,2,1);
00321   QWidget *dummyAgendaRight = new QWidget(agendaFrame);
00322   agendaLayout->addWidget(dummyAgendaRight,0,2);
00323 
00324   // Create time labels
00325   mTimeLabels = new TimeLabels(24,agendaFrame);
00326   agendaLayout->addWidget(mTimeLabels,1,0);
00327 
00328   // Create agenda
00329   mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame);
00330   agendaLayout->addMultiCellWidget(mAgenda,1,1,1,2);
00331   agendaLayout->setColStretch(1,1);
00332 
00333   // Create event context menu for agenda
00334   mAgendaPopup = eventPopup();
00335   mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")),
00336                                   i18n("Toggle Alarm"),mAgenda,
00337                                   SLOT(popupAlarm()),true);
00338   connect(mAgenda,SIGNAL(showEventPopupSignal(Event *)),
00339           mAgendaPopup,SLOT(showEventPopup(Event *)));
00340 
00341   // make connections between dependent widgets
00342   mTimeLabels->setAgenda(mAgenda);
00343 
00344   // Update widgets to reflect user preferences
00345 //  updateConfig();
00346 
00347   createDayLabels();
00348 
00349   // these blank widgets make the All Day Event box line up with the agenda
00350   dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
00351   dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
00352   mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
00353 
00354   // Scrolling
00355   connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)),
00356           mTimeLabels, SLOT(positionChanged()));
00357   connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)),
00358           SLOT(setContentsPos(int)));
00359 
00360   // Create/Show/Edit/Delete Event
00361   connect(mAgenda,SIGNAL(newEventSignal(int,int)),
00362                   SLOT(newEvent(int,int)));
00363   connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)),
00364                   SLOT(newEvent(int,int,int,int)));
00365   connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)),
00366                         SLOT(newEventAllDay(int,int)));
00367   connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)),
00368                         SLOT(newEventAllDay(int,int)));
00369   connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
00370                         SLOT(newTimeSpanSelected(int,int,int,int)));
00371   connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
00372                         SLOT(newTimeSpanSelectedAllDay(int,int,int,int)));
00373   connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
00374   connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
00375   
00376   connect(mAgenda,SIGNAL(editEventSignal(Event *)),
00377                   SIGNAL(editEventSignal(Event *)));
00378   connect(mAllDayAgenda,SIGNAL(editEventSignal(Event *)),
00379                         SIGNAL(editEventSignal(Event *)));
00380   connect(mAgenda,SIGNAL(showEventSignal(Event *)),
00381                   SIGNAL(showEventSignal(Event *)));
00382   connect(mAllDayAgenda,SIGNAL(showEventSignal(Event *)),
00383                         SIGNAL(showEventSignal(Event *)));
00384   connect(mAgenda,SIGNAL(deleteEventSignal(Event *)),
00385                   SIGNAL(deleteEventSignal(Event *)));
00386   connect(mAllDayAgenda,SIGNAL(deleteEventSignal(Event *)),
00387                         SIGNAL(deleteEventSignal(Event *)));
00388   connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *)),
00389                   SLOT(updateEventDates(KOAgendaItem *)));
00390   connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *)),
00391                         SLOT(updateEventDates(KOAgendaItem *)));
00392 
00393   // event indicator update
00394   connect(mAgenda,SIGNAL(lowerYChanged(int)),
00395           SLOT(updateEventIndicatorTop(int)));
00396   connect(mAgenda,SIGNAL(upperYChanged(int)),
00397           SLOT(updateEventIndicatorBottom(int)));
00398 
00399   // drag signals
00400   connect(mAgenda,SIGNAL(startDragSignal(Event *)),
00401           SLOT(startDrag(Event *)));
00402   connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)),
00403           SLOT(startDrag(Event *)));
00404 
00405   // synchronize selections
00406   connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
00407            mAllDayAgenda, SLOT( deselectItem() ) );
00408   connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
00409            mAgenda, SLOT( deselectItem() ) );
00410   connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
00411            SIGNAL( incidenceSelected( Incidence * ) ) );
00412   connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
00413            SIGNAL( incidenceSelected( Incidence * ) ) );
00414 }
00415 
00416 
00417 KOAgendaView::~KOAgendaView()
00418 {
00419   delete mAgendaPopup;
00420   delete mAllDayAgendaPopup;
00421 }
00422 
00423 void KOAgendaView::createDayLabels()
00424 {
00425 //  kdDebug() << "KOAgendaView::createDayLabels()" << endl;
00426 
00427   delete mDayLabels;
00428 
00429   mDayLabels = new QFrame (mDayLabelsFrame);
00430   mLayoutDayLabels = new QHBoxLayout(mDayLabels);
00431   mLayoutDayLabels->addSpacing(mTimeLabels->width());
00432 
00433   DateList::ConstIterator dit;
00434   for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
00435     QDate date = *dit;
00436     QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels);
00437 
00438     QLabel *dayLabel = new QLabel(mDayLabels);
00439 
00440     int dW = KOCore::self()->calendarSystem()->dayOfTheWeek(date);
00441     QString str = i18n( "short_weekday date (e.g. Mon 13)","%1 %2" )
00442         .arg( KOCore::self()->calendarSystem()->weekDayName( dW, true ) )
00443         .arg( KOCore::self()->calendarSystem()->day(date) );
00444 
00445     dayLabel->setText(str);
00446     dayLabel->setAlignment(QLabel::AlignHCenter);
00447     if (date == QDate::currentDate()) {
00448       QFont font = dayLabel->font();
00449       font.setBold(true);
00450       dayLabel->setFont(font);
00451     }
00452     dayLayout->addWidget(dayLabel);
00453 
00454 #ifndef KORG_NOPLUGINS
00455     CalendarDecoration::List cds = KOCore::self()->calendarDecorations();
00456     CalendarDecoration *it;
00457     for(it = cds.first(); it; it = cds.next()) {
00458       QString text = it->shortText( date );
00459       if ( !text.isEmpty() ) {
00460         QLabel *label = new QLabel(text,mDayLabels);
00461         label->setAlignment(AlignCenter);
00462         dayLayout->addWidget(label);
00463       }
00464     }
00465 
00466     for(it = cds.first(); it; it = cds.next()) {
00467       QWidget *wid = it->smallWidget(mDayLabels,date);
00468       if ( wid ) {
00469 //      wid->setHeight(20);
00470         dayLayout->addWidget(wid);
00471       }
00472     }
00473 #endif
00474   }
00475 
00476   mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width());
00477   mDayLabels->show();
00478 }
00479 
00480 int KOAgendaView::maxDatesHint()
00481 {
00482   // Not sure about the max number of events, so return 0 for now.
00483   return 0;
00484 }
00485 
00486 int KOAgendaView::currentDateCount()
00487 {
00488   return mSelectedDates.count();
00489 }
00490 
00491 QPtrList<Incidence> KOAgendaView::selectedIncidences()
00492 {
00493   QPtrList<Incidence> selectedEvents;
00494   Event *event;
00495 
00496   event = mAgenda->selectedEvent();
00497   if (event) selectedEvents.append(event);
00498 
00499   event = mAllDayAgenda->selectedEvent();
00500   if (event) selectedEvents.append(event);
00501 
00502   return selectedEvents;
00503 }
00504 
00505 DateList KOAgendaView::selectedDates()
00506 {
00507   DateList selectedEventsDates;
00508   QDate qd;
00509 
00510   qd = mAgenda->selectedEventDate();
00511   if (qd.isValid()) selectedEventsDates.append(qd);
00512 
00513   qd = mAllDayAgenda->selectedEventDate();
00514   if (qd.isValid()) selectedEventsDates.append(qd);
00515 
00516   return selectedEventsDates;
00517 }
00518 
00519 
00520 void KOAgendaView::updateView()
00521 {
00522 //  kdDebug() << "KOAgendaView::updateView()" << endl;
00523   fillAgenda();
00524 }
00525 
00526 
00527 /*
00528   Update configuration settings for the agenda view. This method is not
00529   complete.
00530 */
00531 void KOAgendaView::updateConfig()
00532 {
00533 //  kdDebug() << "KOAgendaView::updateConfig()" << endl;
00534 
00535   // update config for children
00536   mTimeLabels->updateConfig();
00537   mAgenda->updateConfig();
00538   mAllDayAgenda->updateConfig();
00539 
00540   // widget synchronization
00541   //TODO: find a better way, maybe signal/slot
00542   mTimeLabels->positionChanged();
00543 
00544   // for some reason, this needs to be called explicitly
00545   mTimeLabels->repaint();
00546 
00547   mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
00548 
00549   // ToolTips displaying summary of events
00550   KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance()
00551                                            ->mEnableToolTips);
00552   
00553   setHolidayMasks();
00554 
00555   createDayLabels();
00556 
00557   updateView();
00558 }
00559 
00560 
00561 void KOAgendaView::updateEventDates(KOAgendaItem *item)
00562 {
00563 //  kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl;
00564 
00565   QDateTime startDt,endDt;
00566   QDate startDate;
00567 
00568   if (item->cellX() < 0) {
00569     startDate = (mSelectedDates.first()).addDays(item->cellX());
00570   } else {
00571     startDate = mSelectedDates[item->cellX()];
00572   }
00573   startDt.setDate(startDate);
00574 
00575   if (item->itemEvent()->doesFloat()) {
00576     endDt.setDate(startDate.addDays(item->cellWidth() - 1));
00577   } else {
00578     startDt.setTime(mAgenda->gyToTime(item->cellYTop()));
00579     if (item->lastMultiItem()) {
00580       endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1));
00581       endDt.setDate(startDate.
00582                     addDays(item->lastMultiItem()->cellX() - item->cellX()));
00583     } else {
00584       endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1));
00585       endDt.setDate(startDate);
00586     }
00587   }
00588 
00589 //  kdDebug() << "KOAgendaView::updateEventDates(): now setting dates" << endl;
00590 
00591   item->itemEvent()->setDtStart(startDt);
00592   item->itemEvent()->setDtEnd(endDt);
00593   item->itemEvent()->setRevision(item->itemEvent()->revision()+1);
00594   item->setItemDate(startDt.date());
00595 
00596   emit eventChanged();
00597 
00598 //  kdDebug() << "KOAgendaView::updateEventDates() done " << endl;
00599 }
00600 
00601 
00602 void KOAgendaView::showDates( const QDate &start, const QDate &end )
00603 {
00604 //  kdDebug() << "KOAgendaView::selectDates" << endl;
00605 
00606   mSelectedDates.clear();
00607 
00608   QDate d = start;
00609   while (d <= end) {
00610     mSelectedDates.append(d);
00611     d = d.addDays( 1 );
00612   }
00613 
00614   // and update the view
00615   fillAgenda();
00616 }
00617 
00618 
00619 void KOAgendaView::showEvents(QPtrList<Event>)
00620 {
00621   kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl;
00622 }
00623 
00624 void KOAgendaView::changeEventDisplay(Event *, int)
00625 {
00626 //  kdDebug() << "KOAgendaView::changeEventDisplay" << endl;
00627   // this should be re-written to be MUCH smarter.  Right now we
00628   // are just playing dumb.
00629   fillAgenda();
00630 }
00631 
00632 void KOAgendaView::fillAgenda(const QDate &)
00633 {
00634   fillAgenda();
00635 }
00636 
00637 void KOAgendaView::fillAgenda()
00638 {
00639 //  clearView();
00640 
00641   mAllDayAgenda->changeColumns(mSelectedDates.count());
00642   mAgenda->changeColumns(mSelectedDates.count());
00643   mEventIndicatorTop->changeColumns(mSelectedDates.count());
00644   mEventIndicatorBottom->changeColumns(mSelectedDates.count());
00645 
00646   createDayLabels();
00647   setHolidayMasks();
00648 
00649   mMinY.resize(mSelectedDates.count());
00650   mMaxY.resize(mSelectedDates.count());
00651 
00652   QPtrList<Event> dayEvents;
00653 
00654   mAgenda->setDateList(mSelectedDates);
00655 
00656   DateList::ConstIterator dit;
00657   int curCol = 0;
00658   for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
00659     QDate currentDate = *dit;
00660 //    kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString()
00661 //              << endl;
00662 
00663     dayEvents = calendar()->events(currentDate,true);
00664 
00665     // Default values, which can never be reached
00666     mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1;
00667     mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1;
00668 
00669     unsigned int numEvent;
00670     for(numEvent=0;numEvent<dayEvents.count();++numEvent) {
00671       Event *event = dayEvents.at(numEvent);
00672 //      kdDebug() << " Event: " << event->summary() << endl;
00673 
00674       int beginX = currentDate.daysTo(event->dtStart().date()) + curCol;
00675       int endX = currentDate.daysTo(event->dtEnd().date()) + curCol;
00676 
00677 //      kdDebug() << "  beginX: " << beginX << "  endX: " << endX << endl;
00678 
00679       if (event->doesFloat()) {
00680         if (event->recurrence()->doesRecur()) {
00681           mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol);
00682         } else {
00683           if (beginX <= 0 && curCol == 0) {
00684             mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
00685           } else if (beginX == curCol) {
00686             mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX);
00687           }
00688         }
00689       } else if (event->isMultiDay()) {
00690         int startY = mAgenda->timeToY(event->dtStart().time());
00691         int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
00692         if ((beginX <= 0 && curCol == 0) || beginX == curCol) {
00693           mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY);
00694         }
00695         if (beginX == curCol) {
00696           mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
00697           if (startY < mMinY[curCol]) mMinY[curCol] = startY;
00698         } else if (endX == curCol) {
00699           mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
00700           if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
00701         } else {
00702           mMinY[curCol] = mAgenda->timeToY(QTime(0,0));
00703           mMaxY[curCol] = mAgenda->timeToY(QTime(23,59));
00704         }
00705       } else {
00706         int startY = mAgenda->timeToY(event->dtStart().time());
00707         int endY = mAgenda->timeToY(event->dtEnd().time()) - 1;
00708         if (endY < startY) endY = startY;
00709         mAgenda->insertItem(event,currentDate,curCol,startY,endY);
00710         if (startY < mMinY[curCol]) mMinY[curCol] = startY;
00711         if (endY > mMaxY[curCol]) mMaxY[curCol] = endY;
00712       }
00713     }
00714 //    if (numEvent == 0) kdDebug() << " No events" << endl;
00715     ++curCol;
00716   }
00717 
00718   mAgenda->checkScrollBoundaries();
00719 
00720 //  mAgenda->viewport()->update();
00721 //  mAllDayAgenda->viewport()->update();
00722 
00723 // make invalid
00724   deleteSelectedDateTime();
00725   
00726   emit incidenceSelected( 0 );
00727 
00728 //  kdDebug() << "Fill Agenda done" << endl;
00729 }
00730 
00731 void KOAgendaView::clearView()
00732 {
00733 //  kdDebug() << "ClearView" << endl;
00734   mAllDayAgenda->clear();
00735   mAgenda->clear();
00736 }
00737 
00738 void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd,
00739                                const QDate &td)
00740 {
00741 #ifndef KORG_NOPRINTER
00742   if (fd == td)
00743     calPrinter->preview(CalPrinter::Day, fd, td);
00744   else
00745     calPrinter->preview(CalPrinter::Week, fd, td);
00746 #endif
00747 }
00748 
00749 
00750 void KOAgendaView::newEvent(int gx, int gy)
00751 {
00752   if (!mSelectedDates.count()) return;
00753   
00754   QDate day = mSelectedDates[gx];
00755 
00756   QTime time = mAgenda->gyToTime(gy);
00757   QDateTime dt(day,time);
00758 
00759   emit newEventSignal(dt);
00760 }
00761 
00762 void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd)
00763 {
00764   if (!mSelectedDates.count()) return;
00765   
00766   QDate dayStart = mSelectedDates[gxStart];
00767   QDate dayEnd = mSelectedDates[gxEnd];
00768 
00769   QTime timeStart = mAgenda->gyToTime(gyStart);
00770   QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
00771 
00772   QDateTime dtStart(dayStart,timeStart);
00773   QDateTime dtEnd(dayEnd,timeEnd);
00774 
00775   emit newEventSignal(dtStart,dtEnd);
00776 }
00777 
00778 void KOAgendaView::newEventAllDay(int gx, int )
00779 {
00780   if (!mSelectedDates.count()) return;
00781 
00782   QDate day = mSelectedDates[gx];
00783 
00784   emit newEventSignal(day);
00785 }
00786 
00787 void KOAgendaView::showAgendaPopup(Event *event)
00788 {
00789   showEventPopup(mAgendaPopup,event);
00790 }
00791 
00792 void KOAgendaView::showAllDayAgendaPopup(Event *event)
00793 {
00794   showEventPopup(mAllDayAgendaPopup,event);
00795 }
00796 
00797 void KOAgendaView::updateEventIndicatorTop(int newY)
00798 {
00799   uint i;
00800   for(i=0;i<mMinY.size();++i) {
00801     if (newY >= mMinY[i]) mEventIndicatorTop->enableColumn(i,true);
00802     else mEventIndicatorTop->enableColumn(i,false);
00803   }
00804 
00805   mEventIndicatorTop->update();
00806 }
00807 
00808 void KOAgendaView::updateEventIndicatorBottom(int newY)
00809 {
00810   uint i;
00811   for(i=0;i<mMaxY.size();++i) {
00812     if (newY <= mMaxY[i]) mEventIndicatorBottom->enableColumn(i,true);
00813     else mEventIndicatorBottom->enableColumn(i,false);
00814   }
00815 
00816   mEventIndicatorBottom->update();
00817 }
00818 
00819 void KOAgendaView::startDrag(Event *event)
00820 {
00821 #ifndef KORG_NODND
00822   DndFactory factory( calendar() );
00823   ICalDrag *vd = factory.createDrag(event,this);
00824   if (vd->drag()) {
00825     kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl;
00826   }
00827 #endif
00828 }
00829 
00830 void KOAgendaView::readSettings()
00831 {
00832   readSettings(KGlobal::config());
00833 }
00834 
00835 void KOAgendaView::readSettings(KConfig *config)
00836 {
00837 //  kdDebug() << "KOAgendaView::readSettings()" << endl;
00838 
00839   config->setGroup("Views");
00840 
00841 #ifndef KORG_NOSPLITTER
00842   QValueList<int> sizes = config->readIntListEntry("Separator AgendaView");
00843   if (sizes.count() == 2) {
00844     mSplitterAgenda->setSizes(sizes);
00845   }
00846 #endif
00847 
00848   updateConfig();
00849 }
00850 
00851 void KOAgendaView::writeSettings(KConfig *config)
00852 {
00853 //  kdDebug() << "KOAgendaView::writeSettings()" << endl;
00854 
00855   config->setGroup("Views");
00856 
00857 #ifndef KORG_NOSPLITTER
00858   QValueList<int> list = mSplitterAgenda->sizes();
00859   config->writeEntry("Separator AgendaView",list);
00860 #endif
00861 }
00862 
00863 void KOAgendaView::setHolidayMasks()
00864 {
00865   mHolidayMask.resize(mSelectedDates.count());
00866 
00867   uint i;
00868   for(i=0;i<mSelectedDates.count();++i) {
00869     QDate date = mSelectedDates[i];
00870     bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6);
00871     bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7);
00872 #ifndef KORG_NOPLUGINS
00873     bool showHoliday = KOPrefs::instance()->mExcludeHolidays &&
00874                        !KOCore::self()->holiday(date).isEmpty();
00875     bool showDay = showSaturday || showSunday || showHoliday;
00876 #else
00877     bool showDay = showSaturday || showSunday;
00878 #endif
00879     if (showDay) {
00880       mHolidayMask[i] = true;
00881     } else {
00882       mHolidayMask[i] = false;
00883     }
00884   }
00885 
00886   mAgenda->setHolidayMask(&mHolidayMask);
00887   mAllDayAgenda->setHolidayMask(&mHolidayMask);
00888 }
00889 
00890 void KOAgendaView::setContentsPos(int y)
00891 {
00892   mAgenda->setContentsPos(0,y);
00893 }
00894 
00895 void KOAgendaView::setExpandedButton( bool expanded )
00896 {
00897   if ( expanded ) {
00898     mExpandButton->setPixmap( mExpandedPixmap );
00899   } else {
00900     mExpandButton->setPixmap( mNotExpandedPixmap );
00901   }
00902 }
00903 
00904 void KOAgendaView::clearSelection()
00905 {
00906   mAgenda->deselectItem();
00907   mAllDayAgenda->deselectItem();
00908 }
00909 
00910 void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart,
00911                                        int gxEnd, int gyEnd)
00912 {
00913   mTimeSpanInAllDay = true;
00914   newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd);
00915 }
00916 
00917 void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart,
00918                                        int gxEnd, int gyEnd)
00919 {
00920   if (!mSelectedDates.count()) return;
00921   
00922   QDate dayStart = mSelectedDates[gxStart];
00923   QDate dayEnd = mSelectedDates[gxEnd];
00924 
00925   QTime timeStart = mAgenda->gyToTime(gyStart);
00926   QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 );
00927 
00928   QDateTime dtStart(dayStart,timeStart);
00929   QDateTime dtEnd(dayEnd,timeEnd);
00930 
00931   mTimeSpanBegin = dtStart;
00932   mTimeSpanEnd = dtEnd;
00933 }
00934                                    
00935 void KOAgendaView::deleteSelectedDateTime()
00936 {
00937   mTimeSpanBegin.setDate(QDate());
00938   mTimeSpanEnd.setDate(QDate());
00939   mTimeSpanInAllDay = false;
00940 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:09 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001