summaryrefslogtreecommitdiffabout
path: root/korganizer/koagenda.cpp
Unidiff
Diffstat (limited to 'korganizer/koagenda.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagenda.cpp57
1 files changed, 48 insertions, 9 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp
index deadfc9..de964da 100644
--- a/korganizer/koagenda.cpp
+++ b/korganizer/koagenda.cpp
@@ -155,51 +155,52 @@ void MarcusBains::updateLocation(bool recalculate)
155 //mTimeBox->setAutoMask(true); 155 //mTimeBox->setAutoMask(true);
156 minutes->start(5000,true); 156 minutes->start(5000,true);
157} 157}
158 158
159 159
160//////////////////////////////////////////////////////////////////////////// 160////////////////////////////////////////////////////////////////////////////
161 161
162 162
163/* 163/*
164 Create an agenda widget with rows rows and columns columns. 164 Create an agenda widget with rows rows and columns columns.
165*/ 165*/
166KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, 166KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent,
167 const char *name,WFlags f) : 167 const char *name,WFlags f) :
168 QScrollView(parent,name,f) 168 QScrollView(parent,name,f)
169{ 169{
170 170
171 171 mAllAgendaPopup = 0;
172 mColumns = columns; 172 mColumns = columns;
173 mRows = rows; 173 mRows = rows;
174 mGridSpacingY = rowSize; 174 mGridSpacingY = rowSize;
175 mAllDayMode = false; 175 mAllDayMode = false;
176#ifndef DESKTOP_VERSION 176#ifndef DESKTOP_VERSION
177 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 177 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
178#endif 178#endif
179 mHolidayMask = 0; 179 mHolidayMask = 0;
180 init(); 180 init();
181} 181}
182 182
183/* 183/*
184 Create an agenda widget with columns columns and one row. This is used for 184 Create an agenda widget with columns columns and one row. This is used for
185 all-day events. 185 all-day events.
186*/ 186*/
187KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : 187KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) :
188 QScrollView(parent,name,f) 188 QScrollView(parent,name,f)
189{ 189{
190 mAllAgendaPopup = 0;
190 blockResize = false; 191 blockResize = false;
191 mColumns = columns; 192 mColumns = columns;
192 mRows = 1; 193 mRows = 1;
193 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); 194 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize);
194 mGridSpacingY = KOPrefs::instance()->mAllDaySize; 195 mGridSpacingY = KOPrefs::instance()->mAllDaySize;
195 mAllDayMode = true; 196 mAllDayMode = true;
196#ifndef DESKTOP_VERSION 197#ifndef DESKTOP_VERSION
197 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 198 //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
198#endif 199#endif
199 mHolidayMask = 0; 200 mHolidayMask = 0;
200 init(); 201 init();
201} 202}
202 203
203 204
204KOAgenda::~KOAgenda() 205KOAgenda::~KOAgenda()
205{ 206{
@@ -219,33 +220,33 @@ QDate KOAgenda::selectedIncidenceDate() const
219} 220}
220 221
221 222
222void KOAgenda::init() 223void KOAgenda::init()
223{ 224{
224 mPopupTimer = new QTimer(this); 225 mPopupTimer = new QTimer(this);
225 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu())); 226 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu()));
226 227
227 mNewItemPopup = new QPopupMenu( this ); 228 mNewItemPopup = new QPopupMenu( this );
228 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); 229 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) );
229 QString pathString = ""; 230 QString pathString = "";
230 if ( !KOPrefs::instance()->mToolBarMiniIcons ) { 231 if ( !KOPrefs::instance()->mToolBarMiniIcons ) {
231 if ( QApplication::desktop()->width() < 480 ) 232 if ( QApplication::desktop()->width() < 480 )
232 pathString += "icons16/"; 233 pathString += "icons16/";
233 } else 234 } else
234 pathString += "iconsmini/"; 235 pathString += "iconsmini/";
235 236
236 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); 237 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 );
237 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); 238 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 );
238 mNewItemPopup->insertSeparator ( ); 239 mNewItemPopup->insertSeparator ( );
239 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); 240 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 );
240 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); 241 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 );
241 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); 242 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 );
242 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); 243 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 );
243 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("This month"),6 ); 244 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("This month"),6 );
244 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); 245 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 );
245#ifndef _WIN32_ 246#ifndef _WIN32_
246 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase 247 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase
247 viewport()->setWFlags ( wflags); 248 viewport()->setWFlags ( wflags);
248#endif 249#endif
249 mGridSpacingX = 80; 250 mGridSpacingX = 80;
250 mResizeBorderWidth = 8; 251 mResizeBorderWidth = 8;
251 mScrollBorderWidth = 8; 252 mScrollBorderWidth = 8;
@@ -374,101 +375,139 @@ bool KOAgenda::eventFilter ( QObject *object, QEvent *event )
374 return true; 375 return true;
375 376
376 default: 377 default:
377 return QScrollView::eventFilter(object,event); 378 return QScrollView::eventFilter(object,event);
378 } 379 }
379} 380}
380void KOAgenda::popupMenu() 381void KOAgenda::popupMenu()
381{ 382{
382 mPopupTimer->stop(); 383 mPopupTimer->stop();
383 if ( mPopupKind == 1 ) { 384 if ( mPopupKind == 1 ) {
384 if (mActionItem ) { 385 if (mActionItem ) {
385 endItemAction(); 386 endItemAction();
386 } 387 }
387 mLeftMouseDown = false; // no more leftMouse computation 388 mLeftMouseDown = false; // no more leftMouse computation
388 if (mPopupItem) { 389 if (mPopupItem) {
389 selectItem(mPopupItem); 390 selectItem(mPopupItem);
391 if ( mAllAgendaPopup )
392 mAllAgendaPopup->installEventFilter( this );
390 emit showIncidencePopupSignal(mPopupItem->incidence()); 393 emit showIncidencePopupSignal(mPopupItem->incidence());
391 394
392 } 395 }
393 } else if ( mPopupKind == 2 ) { 396 } else if ( mPopupKind == 2 ) {
394 if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action 397 if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action
395 endSelectAction( false ); // do not emit new event signal 398 endSelectAction( false ); // do not emit new event signal
396 mLeftMouseDown = false; // no more leftMouse computation 399 mLeftMouseDown = false; // no more leftMouse computation
397 } 400 }
401 mNewItemPopup->installEventFilter( this );
398 mNewItemPopup->popup( mPopupPos); 402 mNewItemPopup->popup( mPopupPos);
403
399 } 404 }
400 mLeftMouseDown = false; 405 mLeftMouseDown = false;
401 mPopupItem = 0; 406 mPopupItem = 0;
402 mPopupKind = 0; 407 mPopupKind = 0;
403} 408}
404 409
405bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) 410bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
406{ 411{
407 //qDebug("KOAgenda::eventFilter_mous "); 412 static int startX = 0;
413 static int startY = 0;
414 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 );
415 static bool blockMoving = true;
416
417 //qDebug("KOAgenda::eventFilter_mous ");
418 if ( object == mNewItemPopup ) {
419 //qDebug("mNewItemPopup ");
420 if ( me->type() == QEvent::MouseButtonRelease ) {
421 mNewItemPopup->removeEventFilter( this );
422 int dX = me->globalPos().x() - mPopupPos.x();;
423 if ( dX < 0 )
424 dX = -dX;
425 int dY = me->globalPos().y() - mPopupPos.y();
426 if ( dY < 0 )
427 dY = -dY;
428 if ( dX > blockmoveDist || dY > blockmoveDist ) {
429 mNewItemPopup->hide();
430 }
431 }
432 return true;
433 }
434 if ( object == mAllAgendaPopup ) {
435 //qDebug(" mAllAgendaPopup ");
436 if ( me->type() == QEvent::MouseButtonRelease ) {
437 mAllAgendaPopup->removeEventFilter( this );
438 int dX = me->globalPos().x() - mPopupPos.x();;
439 if ( dX < 0 )
440 dX = -dX;
441 int dY = me->globalPos().y() - mPopupPos.y();
442 if ( dY < 0 )
443 dY = -dY;
444 if ( dX > blockmoveDist || dY > blockmoveDist ) {
445 mAllAgendaPopup->hide();
446 }
447 }
448 return true;
449 }
408 QPoint viewportPos; 450 QPoint viewportPos;
409 if (object != viewport()) { 451 if (object != viewport()) {
410 viewportPos = ((QWidget *)object)->mapToParent(me->pos()); 452 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
411 } else { 453 } else {
412 viewportPos = me->pos(); 454 viewportPos = me->pos();
413 } 455 }
414 static int startX = 0; 456
415 static int startY = 0;
416 static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 );
417 static bool blockMoving = true;
418 switch (me->type()) { 457 switch (me->type()) {
419 case QEvent::MouseButtonPress: 458 case QEvent::MouseButtonPress:
420 if (me->button() == LeftButton) { 459 if (me->button() == LeftButton) {
421 mPopupTimer->start( 600 ); 460 mPopupTimer->start( 600 );
422 mLeftMouseDown = true; 461 mLeftMouseDown = true;
423 } 462 }
424 blockMoving = true; 463 blockMoving = true;
425 startX = viewportPos.x(); 464 startX = viewportPos.x();
426 startY = viewportPos.y(); 465 startY = viewportPos.y();
466 mPopupPos = me->globalPos();
427 if (object != viewport()) { 467 if (object != viewport()) {
428 mPopupItem = (KOAgendaItem *)object; 468 mPopupItem = (KOAgendaItem *)object;
429 mPopupKind = 1; 469 mPopupKind = 1;
430 if (me->button() == RightButton) { 470 if (me->button() == RightButton) {
431 popupMenu(); 471 popupMenu();
432 } else if (me->button() == LeftButton) { 472 } else if (me->button() == LeftButton) {
433 mActionItem = (KOAgendaItem *)object; 473 mActionItem = (KOAgendaItem *)object;
434 if (mActionItem) { 474 if (mActionItem) {
435 if ( mSelectionHeight > 0 ) { 475 if ( mSelectionHeight > 0 ) {
436 int selectionCellX = mSelectionCellX * mGridSpacingX; 476 int selectionCellX = mSelectionCellX * mGridSpacingX;
437 int selectionYTop = mSelectionYTop; 477 int selectionYTop = mSelectionYTop;
438 int gridSpacingX = mGridSpacingX; 478 int gridSpacingX = mGridSpacingX;
439 int selectionHeight = mSelectionHeight; 479 int selectionHeight = mSelectionHeight;
440 clearSelection(); 480 clearSelection();
441 repaintContents( selectionCellX, selectionYTop, 481 repaintContents( selectionCellX, selectionYTop,
442 gridSpacingX, selectionHeight,false ); 482 gridSpacingX, selectionHeight,false );
443 } 483 }
444 selectItem(mActionItem); 484 selectItem(mActionItem);
445 Incidence *incidence = mActionItem->incidence(); 485 Incidence *incidence = mActionItem->incidence();
446 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { 486 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) {
447 mActionItem = 0; 487 mActionItem = 0;
448 } else { 488 } else {
449 startItemAction(viewportPos); 489 startItemAction(viewportPos);
450 } 490 }
451 } 491 }
452 } 492 }
453 } else { // ---------- viewport() 493 } else { // ---------- viewport()
454 mPopupItem = 0; 494 mPopupItem = 0;
455 mPopupKind = 2; 495 mPopupKind = 2;
456 selectItem(0); 496 selectItem(0);
457 mActionItem = 0; 497 mActionItem = 0;
458 mPopupPos = viewport()->mapToGlobal( me->pos() );
459 if (me->button() == RightButton) { 498 if (me->button() == RightButton) {
460 int x,y; 499 int x,y;
461 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 500 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
462 int gx,gy; 501 int gx,gy;
463 contentsToGrid(x,y,gx,gy); 502 contentsToGrid(x,y,gx,gy);
464 mCurrentCellX = gx; 503 mCurrentCellX = gx;
465 mCurrentCellY = gy; 504 mCurrentCellY = gy;
466 mStartCellX = gx; 505 mStartCellX = gx;
467 mStartCellY = gy; 506 mStartCellY = gy;
468 popupMenu(); 507 popupMenu();
469 } else if (me->button() == LeftButton) { 508 } else if (me->button() == LeftButton) {
470 setCursor(arrowCursor); 509 setCursor(arrowCursor);
471 startSelectAction(viewportPos); 510 startSelectAction(viewportPos);
472 } 511 }
473 } 512 }
474 break; 513 break;