00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qlabel.h>
00021 #include <qlayout.h>
00022 #include <qhbox.h>
00023 #include <qtooltip.h>
00024 #include <qdragobject.h>
00025
00026 #include <kiconloader.h>
00027 #include <kdebug.h>
00028 #include <klocale.h>
00029
00030 #include <libkcal/icaldrag.h>
00031 #include <libkcal/vcaldrag.h>
00032
00033 #include "koprefs.h"
00034
00035 #include "koagendaitem.h"
00036 #include "koagendaitem.moc"
00037
00038 QToolTipGroup *KOAgendaItem::mToolTipGroup = 0;
00039
00040 KOAgendaItem::KOAgendaItem(Event *event, QDate qd, QWidget *parent,
00041 const char *name,WFlags) :
00042 QFrame( parent, name )
00043 {
00044 mFirstMultiItem = 0;
00045 mNextMultiItem = 0;
00046 mLastMultiItem = 0;
00047
00048 mEvent = event;
00049 mDate = qd;
00050
00051 QStringList categories = mEvent->categories();
00052 QString cat = categories.first();
00053 if (cat.isEmpty()) {
00054 setPalette(QPalette(KOPrefs::instance()->mEventColor,
00055 KOPrefs::instance()->mEventColor));
00056 } else {
00057 setPalette(QPalette(*(KOPrefs::instance()->categoryColor(cat)),
00058 *(KOPrefs::instance()->categoryColor(cat))));
00059 }
00060
00061 mItemLabel = new QLabel(mEvent->summary(),this,"KOAgendaItem::itemLabel");
00062 mItemLabel->setAlignment(AlignCenter|WordBreak);
00063 mItemLabel->setMouseTracking(true);
00064
00065 mItemLabel->installEventFilter(this);
00066
00067 mItemLabel->setFrameStyle(Panel|Sunken);
00068
00069 mItemLabel->setFont(KOPrefs::instance()->mAgendaViewFont);
00070
00071 setCellXY(0,0,1);
00072 setCellXWidth(0);
00073 setSubCell(0);
00074 setSubCells(1);
00075 setMouseTracking(true);
00076 setMultiItem(0,0,0);
00077
00078 startMove();
00079
00080 mIconAlarm = new QLabel(this,"KOAgendaItem::IconAlarmLabel");
00081 mIconRecur = new QLabel(this,"KOAgendaItem::IconRecurLabel");
00082 mIconReadonly = new QLabel(this,"KOAgendaItem::IconReadonlyLabel");
00083 mIconReply = new QLabel(this,"KOAgendaItem::IconReplyLabel");
00084 mIconGroup = new QLabel(this,"KOAgendaItem::IconGroupLabel");
00085 mIconOrganizer = new QLabel(this,"KOAgendaItem::IconOrganizerLabel");
00086
00087 mIconAlarm->installEventFilter(this);
00088 mIconRecur->installEventFilter(this);
00089 mIconReadonly->installEventFilter(this);
00090 mIconReply->installEventFilter(this);
00091 mIconGroup->installEventFilter(this);
00092 mIconOrganizer->installEventFilter(this);
00093
00094 mIconAlarm->setMouseTracking(true);
00095 mIconRecur->setMouseTracking(true);
00096 mIconReadonly->setMouseTracking(true);
00097 mIconReply->setMouseTracking(true);
00098 mIconGroup->setMouseTracking(true);
00099 mIconOrganizer->setMouseTracking(true);
00100
00101 static const QPixmap alarmPxmp = SmallIcon("bell");
00102 static const QPixmap recurPxmp = SmallIcon("recur");
00103 static const QPixmap readonlyPxmp = SmallIcon("readonlyevent");
00104 static const QPixmap replyPxmp = SmallIcon("mail_reply");
00105 static const QPixmap groupPxmp = SmallIcon("groupevent");
00106 static const QPixmap organizerPxmp = SmallIcon("organizer");
00107
00108 mIconAlarm->setPixmap(alarmPxmp);
00109 mIconRecur->setPixmap(recurPxmp);
00110 mIconReadonly->setPixmap(readonlyPxmp);
00111 mIconReply->setPixmap(replyPxmp);
00112 mIconGroup->setPixmap(groupPxmp);
00113 mIconOrganizer->setPixmap(organizerPxmp);
00114
00115 QVBoxLayout *topLayout = new QVBoxLayout(this,margin()+3);
00116 topLayout->addWidget(mItemLabel,1);
00117
00118 QBoxLayout *iconLayout = new QHBoxLayout;
00119 topLayout->addLayout(iconLayout);
00120
00121 iconLayout->addWidget(mIconAlarm);
00122 iconLayout->addWidget(mIconRecur);
00123 iconLayout->addWidget(mIconReadonly);
00124 iconLayout->addWidget(mIconReply);
00125 iconLayout->addWidget(mIconGroup);
00126 iconLayout->addWidget(mIconOrganizer);
00127 iconLayout->addStretch(1);
00128
00129 updateIcons();
00130
00131
00132 mSelected = true;
00133 select(false);
00134
00135
00136 QString tipText = mEvent->summary();
00137 if (!mEvent->doesFloat()) {
00138 if (mEvent->isMultiDay()) {
00139 tipText += "\n"+i18n("From: ")+mEvent->dtStartStr();
00140 tipText += "\n"+i18n("To: ")+mEvent->dtEndStr();
00141 }
00142 else {
00143 tipText += "\n"+i18n("Time: ")+mEvent->dtStartTimeStr();
00144 tipText += " - "+mEvent->dtEndTimeStr();
00145 }
00146 }
00147 if (!mEvent->location().isEmpty()) {
00148 tipText += "\n"+i18n("Location: ")+mEvent->location();
00149 }
00150
00151 QToolTip::add(this,tipText,toolTipGroup(),"");
00152
00153 setAcceptDrops(true);
00154 }
00155
00156
00157 void KOAgendaItem::updateIcons()
00158 {
00159 if (mEvent->isReadOnly()) mIconReadonly->show();
00160 else mIconReadonly->hide();
00161 if (mEvent->recurrence()->doesRecur()) mIconRecur->show();
00162 else mIconRecur->hide();
00163 if (mEvent->isAlarmEnabled()) mIconAlarm->show();
00164 else mIconAlarm->hide();
00165
00166 if (mEvent->attendeeCount()>0) {
00167 if (mEvent->organizer() == KOPrefs::instance()->email()) {
00168 mIconReply->hide();
00169 mIconGroup->hide();
00170 mIconOrganizer->show();
00171 }
00172 else {
00173 Attendee *me = mEvent->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
00174 if (me!=0) {
00175 if (me->status()==Attendee::NeedsAction && me->RSVP()) {
00176 mIconReply->show();
00177 mIconGroup->hide();
00178 mIconOrganizer->hide();
00179 }
00180 else {
00181 mIconReply->hide();
00182 mIconGroup->show();
00183 mIconOrganizer->hide();
00184 }
00185 }
00186 else {
00187 mIconReply->hide();
00188 mIconGroup->show();
00189 mIconOrganizer->hide();
00190 }
00191 }
00192 }
00193 else {
00194 mIconReply->hide();
00195 mIconGroup->hide();
00196 mIconOrganizer->hide();
00197 }
00198 }
00199
00200
00201 void KOAgendaItem::select(bool selected)
00202 {
00203 if (mSelected == selected) return;
00204 mSelected = selected;
00205 if (mSelected) {
00206 mItemLabel->setFrameStyle(Panel|Sunken);
00207 mItemLabel->setLineWidth(1);
00208 } else {
00209 mItemLabel->setFrameStyle(Panel|Plain);
00210 mItemLabel->setLineWidth(0);
00211 }
00212 }
00213
00214
00215
00216
00217
00218
00219
00220 bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e )
00221 {
00222
00223 if (e->type() == QEvent::MouseButtonPress ||
00224 e->type() == QEvent::MouseButtonDblClick ||
00225 e->type() == QEvent::MouseButtonRelease ||
00226 e->type() == QEvent::MouseMove) {
00227 QMouseEvent *me = (QMouseEvent *)e;
00228 QPoint itemPos = this->mapFromGlobal(((QWidget *)object)->
00229 mapToGlobal(me->pos()));
00230 QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state());
00231 return event(&returnEvent);
00232 } else {
00233 return false;
00234 }
00235 }
00236
00237
00238
00239
00240
00241 int KOAgendaItem::cellHeight()
00242 {
00243 return mCellYBottom - mCellYTop + 1;
00244 }
00245
00246
00247
00248
00249 int KOAgendaItem::cellWidth()
00250 {
00251 return mCellXWidth - mCellX + 1;
00252 }
00253
00254 void KOAgendaItem::setItemDate(QDate qd)
00255 {
00256 mDate = qd;
00257 }
00258
00259 void KOAgendaItem::setCellXY(int X, int YTop, int YBottom)
00260 {
00261 mCellX = X;
00262 mCellYTop = YTop;
00263 mCellYBottom = YBottom;
00264 }
00265
00266 void KOAgendaItem::setCellXWidth(int xwidth)
00267 {
00268 mCellXWidth = xwidth;
00269 }
00270
00271 void KOAgendaItem::setCellX(int XLeft, int XRight)
00272 {
00273 mCellX = XLeft;
00274 mCellXWidth = XRight;
00275 }
00276
00277 void KOAgendaItem::setCellY(int YTop, int YBottom)
00278 {
00279 mCellYTop = YTop;
00280 mCellYBottom = YBottom;
00281 }
00282
00283 void KOAgendaItem::setSubCell(int subCell)
00284 {
00285 mSubCell = subCell;
00286 }
00287
00288 void KOAgendaItem::setSubCells(int subCells)
00289 {
00290 mSubCells = subCells;
00291 }
00292
00293 void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next,
00294 KOAgendaItem *last)
00295 {
00296 mFirstMultiItem = first;
00297 mNextMultiItem = next;
00298 mLastMultiItem = last;
00299 }
00300
00301 void KOAgendaItem::startMove()
00302 {
00303 mStartCellX = mCellX;
00304 mStartCellXWidth = mCellXWidth;
00305 mStartCellYTop = mCellYTop;
00306 mStartCellYBottom = mCellYBottom;
00307 }
00308
00309 void KOAgendaItem::resetMove()
00310 {
00311 mCellX = mStartCellX;
00312 mCellXWidth = mStartCellXWidth;
00313 mCellYTop = mStartCellYTop;
00314 mCellYBottom = mStartCellYBottom;
00315 }
00316
00317 void KOAgendaItem::moveRelative(int dx, int dy)
00318 {
00319 int newX = cellX() + dx;
00320 int newXWidth = cellXWidth() + dx;
00321 int newYTop = cellYTop() + dy;
00322 int newYBottom = cellYBottom() + dy;
00323 setCellXY(newX,newYTop,newYBottom);
00324 setCellXWidth(newXWidth);
00325 }
00326
00327 void KOAgendaItem::expandTop(int dy)
00328 {
00329 int newYTop = cellYTop() + dy;
00330 int newYBottom = cellYBottom();
00331 if (newYTop > newYBottom) newYTop = newYBottom;
00332 setCellY(newYTop, newYBottom);
00333 }
00334
00335 void KOAgendaItem::expandBottom(int dy)
00336 {
00337 int newYTop = cellYTop();
00338 int newYBottom = cellYBottom() + dy;
00339 if (newYBottom < newYTop) newYBottom = newYTop;
00340 setCellY(newYTop, newYBottom);
00341 }
00342
00343 void KOAgendaItem::expandLeft(int dx)
00344 {
00345 int newX = cellX() + dx;
00346 int newXWidth = cellXWidth();
00347 if (newX > newXWidth) newX = newXWidth;
00348 setCellX(newX,newXWidth);
00349 }
00350
00351 void KOAgendaItem::expandRight(int dx)
00352 {
00353 int newX = cellX();
00354 int newXWidth = cellXWidth() + dx;
00355 if (newXWidth < newX) newXWidth = newX;
00356 setCellX(newX,newXWidth);
00357 }
00358
00359 QToolTipGroup *KOAgendaItem::toolTipGroup()
00360 {
00361 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
00362 return mToolTipGroup;
00363 }
00364
00365 void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e )
00366 {
00367 #ifndef KORG_NODND
00368 if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) ||
00369 !QTextDrag::canDecode( e ) ) {
00370 e->ignore();
00371 return;
00372 }
00373 e->accept();
00374 #endif
00375 }
00376
00377 void KOAgendaItem::dropEvent( QDropEvent *e )
00378 {
00379 #ifndef KORG_NODND
00380 QString text;
00381 if(QTextDrag::decode(e,text))
00382 {
00383 kdDebug() << "Dropped : " << text << endl;
00384 QStringList emails = QStringList::split(",",text);
00385 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
00386 kdDebug() << " Email: " << (*it) << endl;
00387 int pos = (*it).find("<");
00388 QString name = (*it).left(pos);
00389 QString email = (*it).mid(pos);
00390 if (!email.isEmpty()) {
00391 mEvent->addAttendee(new Attendee(name,email));
00392 }
00393 }
00394 }
00395 #endif
00396 }
00397
00398
00399 QPtrList<KOAgendaItem> KOAgendaItem::conflictItems()
00400 {
00401 return mConflictItems;
00402 }
00403
00404 void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci)
00405 {
00406 mConflictItems = ci;
00407 KOAgendaItem *item;
00408 for ( item=mConflictItems.first(); item != 0;
00409 item=mConflictItems.next() ) {
00410 item->addConflictItem(this);
00411 }
00412 }
00413
00414 void KOAgendaItem::addConflictItem(KOAgendaItem *ci)
00415 {
00416 if (mConflictItems.find(ci)<0)
00417 mConflictItems.append(ci);
00418 }