summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagenda.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp
index ffa2678..a72e470 100644
--- a/korganizer/koagenda.cpp
+++ b/korganizer/koagenda.cpp
@@ -21,830 +21,840 @@
21 21
22 As a special exception, permission is given to link this program 22 As a special exception, permission is given to link this program
23 with any edition of Qt, and distribute the resulting executable, 23 with any edition of Qt, and distribute the resulting executable,
24 without including the source code for Qt in the source distribution. 24 without including the source code for Qt in the source distribution.
25*/ 25*/
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#define protected public 28#define protected public
29#include <qwidget.h> 29#include <qwidget.h>
30#undef protected 30#undef protected
31#endif 31#endif
32#include <qintdict.h> 32#include <qintdict.h>
33#include <qdatetime.h> 33#include <qdatetime.h>
34#include <qapplication.h> 34#include <qapplication.h>
35#include <qpopupmenu.h> 35#include <qpopupmenu.h>
36#include <qcursor.h> 36#include <qcursor.h>
37#include <qpainter.h> 37#include <qpainter.h>
38 38
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41#include <kiconloader.h> 41#include <kiconloader.h>
42#include <kglobal.h> 42#include <kglobal.h>
43 43
44#include "koagendaitem.h" 44#include "koagendaitem.h"
45#include "koprefs.h" 45#include "koprefs.h"
46#include "koglobals.h" 46#include "koglobals.h"
47 47
48#include "koagenda.h" 48#include "koagenda.h"
49 49
50#include <libkcal/event.h> 50#include <libkcal/event.h>
51#include <libkcal/todo.h> 51#include <libkcal/todo.h>
52 52
53#ifndef DESKTOP_VERSION 53#ifndef DESKTOP_VERSION
54#include <qpe/qpeapplication.h> 54#include <qpe/qpeapplication.h>
55#endif 55#endif
56 56
57//extern bool globalFlagBlockPainting; 57//extern bool globalFlagBlockPainting;
58extern int globalFlagBlockAgenda; 58extern int globalFlagBlockAgenda;
59extern int globalFlagBlockAgendaItemPaint; 59extern int globalFlagBlockAgendaItemPaint;
60extern int globalFlagBlockAgendaItemUpdate; 60extern int globalFlagBlockAgendaItemUpdate;
61extern int globalFlagBlockStartup; 61extern int globalFlagBlockStartup;
62 62
63//////////////////////////////////////////////////////////////////////////// 63////////////////////////////////////////////////////////////////////////////
64MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name) 64MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name)
65 : QFrame(_agenda->viewport(),name), agenda(_agenda) 65 : QFrame(_agenda->viewport(),name), agenda(_agenda)
66{ 66{
67 setLineWidth(0); 67 setLineWidth(0);
68 setMargin(0); 68 setMargin(0);
69 setBackgroundColor(Qt::red); 69 setBackgroundColor(Qt::red);
70 minutes = new QTimer(this); 70 minutes = new QTimer(this);
71 connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc())); 71 connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc()));
72 minutes->start(0, true); 72 minutes->start(0, true);
73 73
74 mTimeBox = new QLabel(this); 74 mTimeBox = new QLabel(this);
75 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom); 75 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom);
76 QPalette pal = mTimeBox->palette(); 76 QPalette pal = mTimeBox->palette();
77 pal.setColor(QColorGroup::Foreground, Qt::red); 77 pal.setColor(QColorGroup::Foreground, Qt::red);
78 mTimeBox->setPalette(pal); 78 mTimeBox->setPalette(pal);
79 //mTimeBox->setAutoMask(true); 79 //mTimeBox->setAutoMask(true);
80 80
81 agenda->addChild(mTimeBox); 81 agenda->addChild(mTimeBox);
82 82
83 oldToday = -1; 83 oldToday = -1;
84} 84}
85 85
86MarcusBains::~MarcusBains() 86MarcusBains::~MarcusBains()
87{ 87{
88 delete minutes; 88 delete minutes;
89} 89}
90 90
91int MarcusBains::todayColumn() 91int MarcusBains::todayColumn()
92{ 92{
93 QDate currentDate = QDate::currentDate(); 93 QDate currentDate = QDate::currentDate();
94 94
95 DateList dateList = agenda->dateList(); 95 DateList dateList = agenda->dateList();
96 DateList::ConstIterator it; 96 DateList::ConstIterator it;
97 int col = 0; 97 int col = 0;
98 for(it = dateList.begin(); it != dateList.end(); ++it) { 98 for(it = dateList.begin(); it != dateList.end(); ++it) {
99 if((*it) == currentDate) 99 if((*it) == currentDate)
100 return KOGlobals::self()->reverseLayout() ? 100 return KOGlobals::self()->reverseLayout() ?
101 agenda->columns() - 1 - col : col; 101 agenda->columns() - 1 - col : col;
102 ++col; 102 ++col;
103 } 103 }
104 104
105 return -1; 105 return -1;
106} 106}
107void MarcusBains::updateLoc() 107void MarcusBains::updateLoc()
108{ 108{
109 updateLocation(); 109 updateLocation();
110} 110}
111void MarcusBains::updateLocation(bool recalculate) 111void MarcusBains::updateLocation(bool recalculate)
112{ 112{
113 113
114 QTime tim = QTime::currentTime(); 114 QTime tim = QTime::currentTime();
115 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); 115 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1());
116 if((tim.hour() == 0) && (oldTime.hour()==23)) 116 if((tim.hour() == 0) && (oldTime.hour()==23))
117 recalculate = true; 117 recalculate = true;
118 118
119 int mins = tim.hour()*60 + tim.minute(); 119 int mins = tim.hour()*60 + tim.minute();
120 int minutesPerCell = 24 * 60 / agenda->rows(); 120 int minutesPerCell = 24 * 60 / agenda->rows();
121 int y = mins*agenda->gridSpacingY()/minutesPerCell; 121 int y = mins*agenda->gridSpacingY()/minutesPerCell;
122 int today = recalculate ? todayColumn() : oldToday; 122 int today = recalculate ? todayColumn() : oldToday;
123 int x = agenda->gridSpacingX()*today; 123 int x = agenda->gridSpacingX()*today;
124 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); 124 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled);
125 125
126 oldTime = tim; 126 oldTime = tim;
127 oldToday = today; 127 oldToday = today;
128 128
129 if(disabled || (today<0)) { 129 if(disabled || (today<0)) {
130 hide(); mTimeBox->hide(); 130 hide(); mTimeBox->hide();
131 return; 131 return;
132 } else { 132 } else {
133 show(); mTimeBox->show(); 133 show(); mTimeBox->show();
134 } 134 }
135 135
136 if(recalculate) 136 if(recalculate)
137 setFixedSize(agenda->gridSpacingX(),1); 137 setFixedSize(agenda->gridSpacingX(),1);
138 agenda->moveChild(this, x, y); 138 agenda->moveChild(this, x, y);
139 raise(); 139 raise();
140 140
141 if(recalculate) 141 if(recalculate)
142 //mTimeBox->setFont(QFont("helvetica",10)); 142 //mTimeBox->setFont(QFont("helvetica",10));
143 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); 143 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont);
144 144
145 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); 145 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds));
146 mTimeBox->adjustSize(); 146 mTimeBox->adjustSize();
147 // the -2 below is there because there is a bug in this program 147 // the -2 below is there because there is a bug in this program
148 // somewhere, where the last column of this widget is a few pixels 148 // somewhere, where the last column of this widget is a few pixels
149 // narrower than the other columns. 149 // narrower than the other columns.
150 int offs = (today==agenda->columns()-1) ? -4 : 0; 150 int offs = (today==agenda->columns()-1) ? -4 : 0;
151 agenda->moveChild(mTimeBox, 151 agenda->moveChild(mTimeBox,
152 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, 152 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1,
153 y-mTimeBox->height()); 153 y-mTimeBox->height());
154 154
155 mTimeBox->raise(); 155 mTimeBox->raise();
156 //mTimeBox->setAutoMask(true); 156 //mTimeBox->setAutoMask(true);
157 minutes->start(5000,true); 157 minutes->start(5000,true);
158} 158}
159 159
160 160
161//////////////////////////////////////////////////////////////////////////// 161////////////////////////////////////////////////////////////////////////////
162 162
163 163
164/* 164/*
165 Create an agenda widget with rows rows and columns columns. 165 Create an agenda widget with rows rows and columns columns.
166*/ 166*/
167KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, 167KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent,
168 const char *name,WFlags f) : 168 const char *name,WFlags f) :
169 QScrollView(parent,name,f) 169 QScrollView(parent,name,f)
170{ 170{
171 171
172 172
173 mColumns = columns; 173 mColumns = columns;
174 mRows = rows; 174 mRows = rows;
175 mGridSpacingY = rowSize; 175 mGridSpacingY = rowSize;
176 mAllDayMode = false; 176 mAllDayMode = false;
177#ifndef DESKTOP_VERSION 177#ifndef DESKTOP_VERSION
178 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 178 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
179#endif 179#endif
180 mHolidayMask = 0; 180 mHolidayMask = 0;
181 init(); 181 init();
182} 182}
183 183
184/* 184/*
185 Create an agenda widget with columns columns and one row. This is used for 185 Create an agenda widget with columns columns and one row. This is used for
186 all-day events. 186 all-day events.
187*/ 187*/
188KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : 188KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) :
189 QScrollView(parent,name,f) 189 QScrollView(parent,name,f)
190{ 190{
191 blockResize = false; 191 blockResize = false;
192 mColumns = columns; 192 mColumns = columns;
193 mRows = 1; 193 mRows = 1;
194 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); 194 //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize);
195 mGridSpacingY = KOPrefs::instance()->mAllDaySize; 195 mGridSpacingY = KOPrefs::instance()->mAllDaySize;
196 mAllDayMode = true; 196 mAllDayMode = true;
197#ifndef DESKTOP_VERSION 197#ifndef DESKTOP_VERSION
198 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 198 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
199#endif 199#endif
200 mHolidayMask = 0; 200 mHolidayMask = 0;
201 init(); 201 init();
202} 202}
203 203
204 204
205KOAgenda::~KOAgenda() 205KOAgenda::~KOAgenda()
206{ 206{
207 if(mMarcusBains) delete mMarcusBains; 207 if(mMarcusBains) delete mMarcusBains;
208 208
209} 209}
210 210
211Incidence *KOAgenda::selectedIncidence() const 211Incidence *KOAgenda::selectedIncidence() const
212{ 212{
213 return (mSelectedItem ? mSelectedItem->incidence() : 0); 213 return (mSelectedItem ? mSelectedItem->incidence() : 0);
214} 214}
215 215
216 216
217QDate KOAgenda::selectedIncidenceDate() const 217QDate KOAgenda::selectedIncidenceDate() const
218{ 218{
219 return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); 219 return (mSelectedItem ? mSelectedItem->itemDate() : QDate());
220} 220}
221 221
222 222
223void KOAgenda::init() 223void KOAgenda::init()
224{ 224{
225 mNewItemPopup = new QPopupMenu( this ); 225 mNewItemPopup = new QPopupMenu( this );
226 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); 226 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) );
227 QString pathString = ""; 227 QString pathString = "";
228 if ( !KOPrefs::instance()->mToolBarMiniIcons ) { 228 if ( !KOPrefs::instance()->mToolBarMiniIcons ) {
229 if ( QApplication::desktop()->width() < 480 ) 229 if ( QApplication::desktop()->width() < 480 )
230 pathString += "icons16/"; 230 pathString += "icons16/";
231 } else 231 } else
232 pathString += "iconsmini/"; 232 pathString += "iconsmini/";
233 233
234 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); 234 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 );
235 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); 235 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 );
236 mNewItemPopup->insertSeparator ( ); 236 mNewItemPopup->insertSeparator ( );
237 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); 237 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 );
238 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); 238 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 );
239 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); 239 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 );
240 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); 240 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 );
241 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("Next month"),6 ); 241 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("Next month"),6 );
242 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); 242 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 );
243#ifndef _WIN32_ 243#ifndef _WIN32_
244 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase 244 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase
245 viewport()->setWFlags ( wflags); 245 viewport()->setWFlags ( wflags);
246#endif 246#endif
247 mGridSpacingX = 80; 247 mGridSpacingX = 80;
248 mResizeBorderWidth = 8; 248 mResizeBorderWidth = 8;
249 mScrollBorderWidth = 8; 249 mScrollBorderWidth = 8;
250 mScrollDelay = 30; 250 mScrollDelay = 30;
251 mScrollOffset = 10; 251 mScrollOffset = 10;
252 mPaintPixmap.resize( 20,20); 252 mPaintPixmap.resize( 20,20);
253 //enableClipper(true); 253 //enableClipper(true);
254 254
255 // Grab key strokes for keyboard navigation of agenda. Seems to have no 255 // Grab key strokes for keyboard navigation of agenda. Seems to have no
256 // effect. Has to be fixed. 256 // effect. Has to be fixed.
257 setFocusPolicy(WheelFocus); 257 setFocusPolicy(WheelFocus);
258 258
259 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); 259 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp()));
260 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); 260 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown()));
261 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); 261 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize()));
262 262
263 mStartCellX = 0; 263 mStartCellX = 0;
264 mStartCellY = 0; 264 mStartCellY = 0;
265 mCurrentCellX = 0; 265 mCurrentCellX = 0;
266 mCurrentCellY = 0; 266 mCurrentCellY = 0;
267 267
268 mSelectionCellX = 0; 268 mSelectionCellX = 0;
269 mSelectionYTop = 0; 269 mSelectionYTop = 0;
270 mSelectionHeight = 0; 270 mSelectionHeight = 0;
271 271
272 mOldLowerScrollValue = -1; 272 mOldLowerScrollValue = -1;
273 mOldUpperScrollValue = -1; 273 mOldUpperScrollValue = -1;
274 274
275 mClickedItem = 0; 275 mClickedItem = 0;
276 276
277 mActionItem = 0; 277 mActionItem = 0;
278 mActionType = NOP; 278 mActionType = NOP;
279 mItemMoved = false; 279 mItemMoved = false;
280 280
281 mSelectedItem = 0; 281 mSelectedItem = 0;
282 282
283 // mItems.setAutoDelete(true); 283 // mItems.setAutoDelete(true);
284 284
285 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 285 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
286 286
287 viewport()->update(); 287 viewport()->update();
288 288
289 setMinimumSize(30, 1); 289 setMinimumSize(30, 1);
290// setMaximumHeight(mGridSpacingY * mRows + 5); 290// setMaximumHeight(mGridSpacingY * mRows + 5);
291 291
292 // Disable horizontal scrollbar. This is a hack. The geometry should be 292 // Disable horizontal scrollbar. This is a hack. The geometry should be
293 // controlled in a way that the contents horizontally always fits. Then it is 293 // controlled in a way that the contents horizontally always fits. Then it is
294 // not necessary to turn off the scrollbar. 294 // not necessary to turn off the scrollbar.
295 setHScrollBarMode(AlwaysOff); 295 setHScrollBarMode(AlwaysOff);
296 if ( ! mAllDayMode ) 296 if ( ! mAllDayMode )
297 setVScrollBarMode(AlwaysOn); 297 setVScrollBarMode(AlwaysOn);
298 else 298 else
299 setVScrollBarMode(AlwaysOff); 299 setVScrollBarMode(AlwaysOff);
300 300
301 setStartHour(KOPrefs::instance()->mDayBegins); 301 setStartHour(KOPrefs::instance()->mDayBegins);
302 302
303 calculateWorkingHours(); 303 calculateWorkingHours();
304 304
305 connect(verticalScrollBar(),SIGNAL(valueChanged(int)), 305 connect(verticalScrollBar(),SIGNAL(valueChanged(int)),
306 SLOT(checkScrollBoundaries(int))); 306 SLOT(checkScrollBoundaries(int)));
307 307
308 // Create the Marcus Bains line. 308 // Create the Marcus Bains line.
309 if(mAllDayMode) 309 if(mAllDayMode)
310 mMarcusBains = 0; 310 mMarcusBains = 0;
311 else { 311 else {
312 mMarcusBains = new MarcusBains(this); 312 mMarcusBains = new MarcusBains(this);
313 addChild(mMarcusBains); 313 addChild(mMarcusBains);
314 } 314 }
315} 315}
316 316
317void KOAgenda::clear() 317void KOAgenda::clear()
318{ 318{
319 KOAgendaItem *item; 319 KOAgendaItem *item;
320 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 320 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
321 mUnusedItems.append( item ); 321 mUnusedItems.append( item );
322 //item->hide(); 322 //item->hide();
323 } 323 }
324 mItems.clear(); 324 mItems.clear();
325 mSelectedItem = 0; 325 mSelectedItem = 0;
326 clearSelection(); 326 clearSelection();
327} 327}
328 328
329void KOAgenda::clearSelection() 329void KOAgenda::clearSelection()
330{ 330{
331 mSelectionCellX = 0; 331 mSelectionCellX = 0;
332 mSelectionYTop = 0; 332 mSelectionYTop = 0;
333 mSelectionHeight = 0; 333 mSelectionHeight = 0;
334} 334}
335 335
336void KOAgenda::marcus_bains() 336void KOAgenda::marcus_bains()
337{ 337{
338 if(mMarcusBains) mMarcusBains->updateLocation(true); 338 if(mMarcusBains) mMarcusBains->updateLocation(true);
339} 339}
340 340
341 341
342void KOAgenda::changeColumns(int columns) 342void KOAgenda::changeColumns(int columns)
343{ 343{
344 if (columns == 0) { 344 if (columns == 0) {
345 kdDebug() << "KOAgenda::changeColumns() called with argument 0" << endl; 345 kdDebug() << "KOAgenda::changeColumns() called with argument 0" << endl;
346 return; 346 return;
347 } 347 }
348 348
349 clear(); 349 clear();
350 350
351 mColumns = columns; 351 mColumns = columns;
352// setMinimumSize(mColumns * 10, mGridSpacingY + 1); 352// setMinimumSize(mColumns * 10, mGridSpacingY + 1);
353// init(); 353// init();
354// update(); 354// update();
355 //qDebug("KOAgenda::changeColumns "); 355 //qDebug("KOAgenda::changeColumns ");
356 computeSizes(); 356 computeSizes();
357 // QResizeEvent event( size(), size() ); 357 // QResizeEvent event( size(), size() );
358 358
359 //QApplication::sendEvent( this, &event ); 359 //QApplication::sendEvent( this, &event );
360} 360}
361 361
362/* 362/*
363 This is the eventFilter function, which gets all events from the KOAgendaItems 363 This is the eventFilter function, which gets all events from the KOAgendaItems
364 contained in the agenda. It has to handle moving and resizing for all items. 364 contained in the agenda. It has to handle moving and resizing for all items.
365*/ 365*/
366bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) 366bool KOAgenda::eventFilter ( QObject *object, QEvent *event )
367{ 367{
368// kdDebug() << "KOAgenda::eventFilter" << endl; 368// kdDebug() << "KOAgenda::eventFilter" << endl;
369 switch(event->type()) { 369 switch(event->type()) {
370 case QEvent::MouseButtonPress: 370 case QEvent::MouseButtonPress:
371 case QEvent::MouseButtonDblClick: 371 case QEvent::MouseButtonDblClick:
372 case QEvent::MouseButtonRelease: 372 case QEvent::MouseButtonRelease:
373 case QEvent::MouseMove: 373 case QEvent::MouseMove:
374 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); 374 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event));
375 375
376 case (QEvent::Leave): 376 case (QEvent::Leave):
377 if (!mActionItem) 377 if (!mActionItem)
378 setCursor(arrowCursor); 378 setCursor(arrowCursor);
379 return true; 379 return true;
380 380
381 default: 381 default:
382 return QScrollView::eventFilter(object,event); 382 return QScrollView::eventFilter(object,event);
383 } 383 }
384} 384}
385 385
386 386
387bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) 387bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
388{ 388{
389 //qDebug("KOAgenda::eventFilter_mous "); 389 //qDebug("KOAgenda::eventFilter_mous ");
390 QPoint viewportPos; 390 QPoint viewportPos;
391 if (object != viewport()) { 391 if (object != viewport()) {
392 viewportPos = ((QWidget *)object)->mapToParent(me->pos()); 392 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
393 } else { 393 } else {
394 viewportPos = me->pos(); 394 viewportPos = me->pos();
395 } 395 }
396 static int startX = 0; 396 static int startX = 0;
397 static int startY = 0; 397 static int startY = 0;
398 static bool block = true; 398 static bool block = true;
399 switch (me->type()) { 399 switch (me->type()) {
400 case QEvent::MouseButtonPress: 400 case QEvent::MouseButtonPress:
401 //qDebug("QEvent::MouseButtonPress: "); 401 //qDebug("QEvent::MouseButtonPress: ");
402 // kdDebug() << "koagenda: filtered button press" << endl; 402 // kdDebug() << "koagenda: filtered button press" << endl;
403 if (object != viewport()) { 403 if (object != viewport()) {
404 if (me->button() == RightButton) { 404 if (me->button() == RightButton) {
405
406 mClickedItem = (KOAgendaItem *)object; 405 mClickedItem = (KOAgendaItem *)object;
407 if (mClickedItem) { 406 if (mClickedItem) {
408 selectItem(mClickedItem); 407 selectItem(mClickedItem);
409 // emit showIncidencePopupSignal(mClickedItem->incidence()); 408 // emit showIncidencePopupSignal(mClickedItem->incidence());
410 } 409 }
411 //mItemPopup->popup(QCursor::pos()); 410 //mItemPopup->popup(QCursor::pos());
412 } else { 411 } else {
413 mActionItem = (KOAgendaItem *)object; 412 mActionItem = (KOAgendaItem *)object;
414 if (mActionItem) { 413 if (mActionItem) {
415 if ( mSelectionHeight > 0 ) { 414 if ( mSelectionHeight > 0 ) {
416 int selectionCellX = mSelectionCellX * mGridSpacingX; 415 int selectionCellX = mSelectionCellX * mGridSpacingX;
417 int selectionYTop = mSelectionYTop; 416 int selectionYTop = mSelectionYTop;
418 int gridSpacingX = mGridSpacingX; 417 int gridSpacingX = mGridSpacingX;
419 int selectionHeight = mSelectionHeight; 418 int selectionHeight = mSelectionHeight;
420 clearSelection(); 419 clearSelection();
421 repaintContents( selectionCellX, selectionYTop, 420 repaintContents( selectionCellX, selectionYTop,
422 gridSpacingX, selectionHeight,false ); 421 gridSpacingX, selectionHeight,false );
423 } 422 }
424 selectItem(mActionItem); 423 selectItem(mActionItem);
425 Incidence *incidence = mActionItem->incidence(); 424 Incidence *incidence = mActionItem->incidence();
426 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { 425 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) {
427 mActionItem = 0; 426 mActionItem = 0;
428 } else { 427 } else {
429 startItemAction(viewportPos); 428 startItemAction(viewportPos);
430 startX = viewportPos.x(); 429 startX = viewportPos.x();
431 startY = viewportPos.y(); 430 startY = viewportPos.y();
432 block = true; 431 block = true;
433 } 432 }
434 } 433 }
435 } 434 }
436 } else { 435 } else {
437 selectItem(0); 436 selectItem(0);
438 mActionItem = 0; 437 mActionItem = 0;
439 if (me->button() == RightButton ) { 438 if (me->button() == RightButton ) {
440 blockNewEvent = true; 439 blockNewEvent = true;
441 block = false; 440 block = false;
442 } else { 441 } else {
443 blockNewEvent = false; 442 blockNewEvent = false;
444 setCursor(arrowCursor); 443 setCursor(arrowCursor);
445 startSelectAction(viewportPos); 444 startSelectAction(viewportPos);
446 } 445 }
447 } 446 }
448 break; 447 break;
449 448
450 case QEvent::MouseButtonRelease: 449 case QEvent::MouseButtonRelease:
451 //qDebug("QEvent::MouseButtonRelease: %d",blockNewEvent ); 450 //qDebug("QEvent::MouseButtonRelease: %d",blockNewEvent );
452 if (me->button() == RightButton && blockNewEvent && !block) { 451 if (me->button() == RightButton && blockNewEvent && !block) {
453 int x,y; 452 int x,y;
454 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 453 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
455 int gx,gy; 454 int gx,gy;
456 contentsToGrid(x,y,gx,gy); 455 contentsToGrid(x,y,gx,gy);
457 if ( mCurrentCellY < mStartCellY +1 ) { 456 if ( object == viewport() ) {
458 //qDebug("mCurrentCellY %d mStartCellY %d ", mCurrentCellY,mStartCellY); 457 if ( mCurrentCellY < mStartCellY +1 ) {
459 mCurrentCellX = gx; 458 //qDebug("mCurrentCellY %d mStartCellY %d ", mCurrentCellY,mStartCellY);
460 mCurrentCellY = gy; 459 mCurrentCellX = gx;
461 mStartCellX = gx; 460 mCurrentCellY = gy;
462 mStartCellY = gy; 461 mStartCellX = gx;
463 mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); 462 mStartCellY = gy;
464 break; 463 mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) );
464 break;
465 } else {
466 blockNewEvent = false;
467 }
465 } else { 468 } else {
466 blockNewEvent = false; 469 mClickedItem = (KOAgendaItem *)object;
470 if (mActionItem ) {
471 endItemAction();
472 }
473 if (mClickedItem) {
474 selectItem(mClickedItem);
475 emit showIncidencePopupSignal(mClickedItem->incidence());
476 }
467 } 477 }
468 } else if (me->button() == RightButton && block ) { 478 } else if (me->button() == RightButton && block ) {
469 if (object != viewport()) { 479 if (object != viewport()) {
470 mClickedItem = (KOAgendaItem *)object; 480 mClickedItem = (KOAgendaItem *)object;
471 if (mActionItem ) { 481 if (mActionItem ) {
472 endItemAction(); 482 endItemAction();
473 } 483 }
474 if (mClickedItem) { 484 if (mClickedItem) {
475 selectItem(mClickedItem); 485 selectItem(mClickedItem);
476 emit showIncidencePopupSignal(mClickedItem->incidence()); 486 emit showIncidencePopupSignal(mClickedItem->incidence());
477 } 487 }
478 } 488 }
479 break; 489 break;
480 } 490 }
481 block = true; 491 block = true;
482 if (mActionItem) { 492 if (mActionItem) {
483 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 493 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos));
484 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); 494 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 );
485 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { 495 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) {
486 mScrollUpTimer.stop(); 496 mScrollUpTimer.stop();
487 mScrollDownTimer.stop(); 497 mScrollDownTimer.stop();
488 mActionItem->resetMove(); 498 mActionItem->resetMove();
489 placeSubCells( mActionItem ); 499 placeSubCells( mActionItem );
490 // emit startDragSignal( mActionItem->incidence() ); 500 // emit startDragSignal( mActionItem->incidence() );
491 setCursor( arrowCursor ); 501 setCursor( arrowCursor );
492 mActionItem = 0; 502 mActionItem = 0;
493 mActionType = NOP; 503 mActionType = NOP;
494 mItemMoved = 0; 504 mItemMoved = 0;
495 return true; 505 return true;
496 } 506 }
497 endItemAction(); 507 endItemAction();
498 } else if ( mActionType == SELECT ) { 508 } else if ( mActionType == SELECT ) {
499 if (me->button() == RightButton ) { 509 if (me->button() == RightButton ) {
500 } else { 510 } else {
501 endSelectAction( !blockNewEvent ); 511 endSelectAction( !blockNewEvent );
502 } 512 }
503 } 513 }
504 break; 514 break;
505 515
506 case QEvent::MouseMove: 516 case QEvent::MouseMove:
507 if (object != viewport()) { 517 if (object != viewport()) {
508 KOAgendaItem *moveItem = (KOAgendaItem *)object; 518 KOAgendaItem *moveItem = (KOAgendaItem *)object;
509 //qDebug("moveItem %d ",moveItem ); 519 //qDebug("moveItem %d ",moveItem );
510 if (!moveItem->incidence()->isReadOnly() /*&& 520 if (!moveItem->incidence()->isReadOnly() /*&&
511 !moveItem->incidence()->recurrence()->doesRecur()*/ ) 521 !moveItem->incidence()->recurrence()->doesRecur()*/ )
512 if (!mActionItem) 522 if (!mActionItem)
513 setNoActionCursor(moveItem,viewportPos); 523 setNoActionCursor(moveItem,viewportPos);
514 else { 524 else {
515 if ( block ) { 525 if ( block ) {
516 int dX, dY; 526 int dX, dY;
517 dX = startX - viewportPos.x(); 527 dX = startX - viewportPos.x();
518 if ( dX < 0 ) 528 if ( dX < 0 )
519 dX = -dX; 529 dX = -dX;
520 dY = viewportPos.y() - startY; 530 dY = viewportPos.y() - startY;
521 if ( dY < 0 ) 531 if ( dY < 0 )
522 dY = -dY; 532 dY = -dY;
523 int diff = 30; 533 int diff = 30;
524 if ( QApplication::desktop()->width() < 480 ) 534 if ( QApplication::desktop()->width() < 480 )
525 diff = 15; 535 diff = 15;
526 // qDebug(" %d %d ",dX, dY ); 536 // qDebug(" %d %d ",dX, dY );
527 if ( dX > diff || dY > diff ) { 537 if ( dX > diff || dY > diff ) {
528 block = false; 538 block = false;
529 } 539 }
530 } 540 }
531 if ( !block ) 541 if ( !block )
532 performItemAction(viewportPos); 542 performItemAction(viewportPos);
533 } 543 }
534 } else { 544 } else {
535 if ( mActionType == SELECT ) { 545 if ( mActionType == SELECT ) {
536 performSelectAction( viewportPos ); 546 performSelectAction( viewportPos );
537 } 547 }
538 } 548 }
539 break; 549 break;
540 550
541 case QEvent::MouseButtonDblClick: 551 case QEvent::MouseButtonDblClick:
542 if (object == viewport()) { 552 if (object == viewport()) {
543 selectItem(0); 553 selectItem(0);
544 int x,y; 554 int x,y;
545 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 555 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
546 int gx,gy; 556 int gx,gy;
547 contentsToGrid(x,y,gx,gy); 557 contentsToGrid(x,y,gx,gy);
548 emit newEventSignal(gx,gy); 558 emit newEventSignal(gx,gy);
549 } else { 559 } else {
550 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; 560 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object;
551 selectItem(doubleClickedItem); 561 selectItem(doubleClickedItem);
552 if ( KOPrefs::instance()->mEditOnDoubleClick ) 562 if ( KOPrefs::instance()->mEditOnDoubleClick )
553 emit editIncidenceSignal(doubleClickedItem->incidence()); 563 emit editIncidenceSignal(doubleClickedItem->incidence());
554 else 564 else
555 emit showIncidenceSignal(doubleClickedItem->incidence()); 565 emit showIncidenceSignal(doubleClickedItem->incidence());
556 } 566 }
557 break; 567 break;
558 568
559 default: 569 default:
560 break; 570 break;
561 } 571 }
562 572
563 return true; 573 return true;
564} 574}
565 575
566void KOAgenda::newItem( int item ) 576void KOAgenda::newItem( int item )
567{ 577{
568 if ( item == 1 ) { //new event 578 if ( item == 1 ) { //new event
569 newEventSignal(mStartCellX ,mStartCellY ); 579 newEventSignal(mStartCellX ,mStartCellY );
570 } else 580 } else
571 if ( item == 2 ) { //new event 581 if ( item == 2 ) { //new event
572 newTodoSignal(mStartCellX ,mStartCellY ); 582 newTodoSignal(mStartCellX ,mStartCellY );
573 } else 583 } else
574 { 584 {
575 QDate day = mSelectedDates[mStartCellX]; 585 QDate day = mSelectedDates[mStartCellX];
576 emit showDateView( item, day ); 586 emit showDateView( item, day );
577 // 3Day view 587 // 3Day view
578 // 4Week view 588 // 4Week view
579 // 5Month view 589 // 5Month view
580 // 6Journal view 590 // 6Journal view
581 } 591 }
582} 592}
583void KOAgenda::startSelectAction(QPoint viewportPos) 593void KOAgenda::startSelectAction(QPoint viewportPos)
584{ 594{
585 //emit newStartSelectSignal(); 595 //emit newStartSelectSignal();
586 596
587 mActionType = SELECT; 597 mActionType = SELECT;
588 598
589 int x,y; 599 int x,y;
590 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 600 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
591 int gx,gy; 601 int gx,gy;
592 contentsToGrid(x,y,gx,gy); 602 contentsToGrid(x,y,gx,gy);
593 603
594 mStartCellX = gx; 604 mStartCellX = gx;
595 mStartCellY = gy; 605 mStartCellY = gy;
596 mCurrentCellX = gx; 606 mCurrentCellX = gx;
597 mCurrentCellY = gy; 607 mCurrentCellY = gy;
598 608
599 // Store coordinates of old selection 609 // Store coordinates of old selection
600 int selectionX = mSelectionCellX * mGridSpacingX; 610 int selectionX = mSelectionCellX * mGridSpacingX;
601 int selectionYTop = mSelectionYTop; 611 int selectionYTop = mSelectionYTop;
602 int selectionHeight = mSelectionHeight; 612 int selectionHeight = mSelectionHeight;
603 613
604 // Store new selection 614 // Store new selection
605 mSelectionCellX = gx; 615 mSelectionCellX = gx;
606 mSelectionYTop = gy * mGridSpacingY; 616 mSelectionYTop = gy * mGridSpacingY;
607 mSelectionHeight = mGridSpacingY; 617 mSelectionHeight = mGridSpacingY;
608 618
609 // Clear old selection 619 // Clear old selection
610 repaintContents( selectionX, selectionYTop, 620 repaintContents( selectionX, selectionYTop,
611 mGridSpacingX, selectionHeight,false ); 621 mGridSpacingX, selectionHeight,false );
612 622
613 // Paint new selection 623 // Paint new selection
614 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, 624 // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop,
615 // mGridSpacingX, mSelectionHeight ); 625 // mGridSpacingX, mSelectionHeight );
616} 626}
617 627
618void KOAgenda::performSelectAction(QPoint viewportPos) 628void KOAgenda::performSelectAction(QPoint viewportPos)
619{ 629{
620 int x,y; 630 int x,y;
621 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 631 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
622 int gx,gy; 632 int gx,gy;
623 contentsToGrid(x,y,gx,gy); 633 contentsToGrid(x,y,gx,gy);
624 634
625 QPoint clipperPos = clipper()-> 635 QPoint clipperPos = clipper()->
626 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 636 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
627 637
628 // Scroll if cursor was moved to upper or lower end of agenda. 638 // Scroll if cursor was moved to upper or lower end of agenda.
629 if (clipperPos.y() < mScrollBorderWidth) { 639 if (clipperPos.y() < mScrollBorderWidth) {
630 mScrollUpTimer.start(mScrollDelay); 640 mScrollUpTimer.start(mScrollDelay);
631 } else if (visibleHeight() - clipperPos.y() < 641 } else if (visibleHeight() - clipperPos.y() <
632 mScrollBorderWidth) { 642 mScrollBorderWidth) {
633 mScrollDownTimer.start(mScrollDelay); 643 mScrollDownTimer.start(mScrollDelay);
634 } else { 644 } else {
635 mScrollUpTimer.stop(); 645 mScrollUpTimer.stop();
636 mScrollDownTimer.stop(); 646 mScrollDownTimer.stop();
637 } 647 }
638 648
639 if ( gy > mCurrentCellY ) { 649 if ( gy > mCurrentCellY ) {
640 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 650 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
641 651
642#if 0 652#if 0
643 // FIXME: Repaint only the newly selected region 653 // FIXME: Repaint only the newly selected region
644 repaintContents( mSelectionCellX * mGridSpacingX, 654 repaintContents( mSelectionCellX * mGridSpacingX,
645 mCurrentCellY + mGridSpacingY, 655 mCurrentCellY + mGridSpacingY,
646 mGridSpacingX, 656 mGridSpacingX,
647 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY ); 657 mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY );
648#else 658#else
649 repaintContents( (KOGlobals::self()->reverseLayout() ? 659 repaintContents( (KOGlobals::self()->reverseLayout() ?
650 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 660 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
651 mGridSpacingX, mSelectionYTop, 661 mGridSpacingX, mSelectionYTop,
652 mGridSpacingX, mSelectionHeight , false); 662 mGridSpacingX, mSelectionHeight , false);
653#endif 663#endif
654 664
655 mCurrentCellY = gy; 665 mCurrentCellY = gy;
656 } else if ( gy < mCurrentCellY ) { 666 } else if ( gy < mCurrentCellY ) {
657 if ( gy >= mStartCellY ) { 667 if ( gy >= mStartCellY ) {
658 int selectionHeight = mSelectionHeight; 668 int selectionHeight = mSelectionHeight;
659 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 669 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
660 670
661 repaintContents( (KOGlobals::self()->reverseLayout() ? 671 repaintContents( (KOGlobals::self()->reverseLayout() ?
662 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 672 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
663 mGridSpacingX, mSelectionYTop, 673 mGridSpacingX, mSelectionYTop,
664 mGridSpacingX, selectionHeight,false ); 674 mGridSpacingX, selectionHeight,false );
665 675
666 mCurrentCellY = gy; 676 mCurrentCellY = gy;
667 } else { 677 } else {
668 } 678 }
669 } 679 }
670} 680}
671 681
672void KOAgenda::endSelectAction( bool emitNewEvent ) 682void KOAgenda::endSelectAction( bool emitNewEvent )
673{ 683{
674 mActionType = NOP; 684 mActionType = NOP;
675 mScrollUpTimer.stop(); 685 mScrollUpTimer.stop();
676 mScrollDownTimer.stop(); 686 mScrollDownTimer.stop();
677 687
678 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 688 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
679 if ( emitNewEvent && mStartCellY < mCurrentCellY ) 689 if ( emitNewEvent && mStartCellY < mCurrentCellY )
680 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 690 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
681} 691}
682 692
683void KOAgenda::startItemAction(QPoint viewportPos) 693void KOAgenda::startItemAction(QPoint viewportPos)
684{ 694{
685 int x,y; 695 int x,y;
686 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 696 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
687 int gx,gy; 697 int gx,gy;
688 contentsToGrid(x,y,gx,gy); 698 contentsToGrid(x,y,gx,gy);
689 699
690 mStartCellX = gx; 700 mStartCellX = gx;
691 mStartCellY = gy; 701 mStartCellY = gy;
692 mCurrentCellX = gx; 702 mCurrentCellX = gx;
693 mCurrentCellY = gy; 703 mCurrentCellY = gy;
694 704
695 if (mAllDayMode) { 705 if (mAllDayMode) {
696 int gridDistanceX = (x - gx * mGridSpacingX); 706 int gridDistanceX = (x - gx * mGridSpacingX);
697 if (gridDistanceX < mResizeBorderWidth && 707 if (gridDistanceX < mResizeBorderWidth &&
698 mActionItem->cellX() == mCurrentCellX) { 708 mActionItem->cellX() == mCurrentCellX) {
699 mActionType = RESIZELEFT; 709 mActionType = RESIZELEFT;
700 setCursor(sizeHorCursor); 710 setCursor(sizeHorCursor);
701 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 711 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
702 mActionItem->cellXWidth() == mCurrentCellX) { 712 mActionItem->cellXWidth() == mCurrentCellX) {
703 mActionType = RESIZERIGHT; 713 mActionType = RESIZERIGHT;
704 setCursor(sizeHorCursor); 714 setCursor(sizeHorCursor);
705 } else { 715 } else {
706 mActionType = MOVE; 716 mActionType = MOVE;
707 mActionItem->startMove(); 717 mActionItem->startMove();
708 setCursor(sizeAllCursor); 718 setCursor(sizeAllCursor);
709 } 719 }
710 } else { 720 } else {
711 int gridDistanceY = (y - gy * mGridSpacingY); 721 int gridDistanceY = (y - gy * mGridSpacingY);
712 bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); 722 bool allowResize = ( mActionItem->incidence()->type() != "Todo" );
713 if (allowResize && gridDistanceY < mResizeBorderWidth && 723 if (allowResize && gridDistanceY < mResizeBorderWidth &&
714 mActionItem->cellYTop() == mCurrentCellY && 724 mActionItem->cellYTop() == mCurrentCellY &&
715 !mActionItem->firstMultiItem()) { 725 !mActionItem->firstMultiItem()) {
716 mActionType = RESIZETOP; 726 mActionType = RESIZETOP;
717 setCursor(sizeVerCursor); 727 setCursor(sizeVerCursor);
718 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 728 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
719 mActionItem->cellYBottom() == mCurrentCellY && 729 mActionItem->cellYBottom() == mCurrentCellY &&
720 !mActionItem->lastMultiItem()) { 730 !mActionItem->lastMultiItem()) {
721 mActionType = RESIZEBOTTOM; 731 mActionType = RESIZEBOTTOM;
722 setCursor(sizeVerCursor); 732 setCursor(sizeVerCursor);
723 } else { 733 } else {
724 mActionType = MOVE; 734 mActionType = MOVE;
725 mActionItem->startMove(); 735 mActionItem->startMove();
726 setCursor(sizeAllCursor); 736 setCursor(sizeAllCursor);
727 } 737 }
728 } 738 }
729} 739}
730 740
731void KOAgenda::performItemAction(QPoint viewportPos) 741void KOAgenda::performItemAction(QPoint viewportPos)
732{ 742{
733// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 743// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
734// QPoint point = viewport()->mapToGlobal(viewportPos); 744// QPoint point = viewport()->mapToGlobal(viewportPos);
735// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 745// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
736// point = clipper()->mapFromGlobal(point); 746// point = clipper()->mapFromGlobal(point);
737// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 747// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
738// kdDebug() << "visible height: " << visibleHeight() << endl; 748// kdDebug() << "visible height: " << visibleHeight() << endl;
739 int x,y; 749 int x,y;
740 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 750 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
741// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 751// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
742 int gx,gy; 752 int gx,gy;
743 contentsToGrid(x,y,gx,gy); 753 contentsToGrid(x,y,gx,gy);
744 QPoint clipperPos = clipper()-> 754 QPoint clipperPos = clipper()->
745 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 755 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
746 756
747 // Cursor left active agenda area. 757 // Cursor left active agenda area.
748 // This starts a drag. 758 // This starts a drag.
749 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ 759 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/
750 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { 760 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) {
751 if ( mActionType == MOVE ) { 761 if ( mActionType == MOVE ) {
752 mScrollUpTimer.stop(); 762 mScrollUpTimer.stop();
753 mScrollDownTimer.stop(); 763 mScrollDownTimer.stop();
754 mActionItem->resetMove(); 764 mActionItem->resetMove();
755 placeSubCells( mActionItem ); 765 placeSubCells( mActionItem );
756 // emit startDragSignal( mActionItem->incidence() ); 766 // emit startDragSignal( mActionItem->incidence() );
757 setCursor( arrowCursor ); 767 setCursor( arrowCursor );
758 mActionItem = 0; 768 mActionItem = 0;
759 mActionType = NOP; 769 mActionType = NOP;
760 mItemMoved = 0; 770 mItemMoved = 0;
761 return; 771 return;
762 } 772 }
763 } else { 773 } else {
764 switch ( mActionType ) { 774 switch ( mActionType ) {
765 case MOVE: 775 case MOVE:
766 setCursor( sizeAllCursor ); 776 setCursor( sizeAllCursor );
767 break; 777 break;
768 case RESIZETOP: 778 case RESIZETOP:
769 case RESIZEBOTTOM: 779 case RESIZEBOTTOM:
770 setCursor( sizeVerCursor ); 780 setCursor( sizeVerCursor );
771 break; 781 break;
772 case RESIZELEFT: 782 case RESIZELEFT:
773 case RESIZERIGHT: 783 case RESIZERIGHT:
774 setCursor( sizeHorCursor ); 784 setCursor( sizeHorCursor );
775 break; 785 break;
776 default: 786 default:
777 setCursor( arrowCursor ); 787 setCursor( arrowCursor );
778 } 788 }
779 } 789 }
780 790
781 // Scroll if item was moved to upper or lower end of agenda. 791 // Scroll if item was moved to upper or lower end of agenda.
782 if (clipperPos.y() < mScrollBorderWidth) { 792 if (clipperPos.y() < mScrollBorderWidth) {
783 mScrollUpTimer.start(mScrollDelay); 793 mScrollUpTimer.start(mScrollDelay);
784 } else if (visibleHeight() - clipperPos.y() < 794 } else if (visibleHeight() - clipperPos.y() <
785 mScrollBorderWidth) { 795 mScrollBorderWidth) {
786 mScrollDownTimer.start(mScrollDelay); 796 mScrollDownTimer.start(mScrollDelay);
787 } else { 797 } else {
788 mScrollUpTimer.stop(); 798 mScrollUpTimer.stop();
789 mScrollDownTimer.stop(); 799 mScrollDownTimer.stop();
790 } 800 }
791 801
792 // Move or resize item if necessary 802 // Move or resize item if necessary
793 if (mCurrentCellX != gx || mCurrentCellY != gy) { 803 if (mCurrentCellX != gx || mCurrentCellY != gy) {
794 mItemMoved = true; 804 mItemMoved = true;
795 mActionItem->raise(); 805 mActionItem->raise();
796 if (mActionType == MOVE) { 806 if (mActionType == MOVE) {
797 // Move all items belonging to a multi item 807 // Move all items belonging to a multi item
798 KOAgendaItem *moveItem = mActionItem->firstMultiItem(); 808 KOAgendaItem *moveItem = mActionItem->firstMultiItem();
799 bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); 809 bool isMultiItem = (moveItem || mActionItem->lastMultiItem());
800 if (!moveItem) moveItem = mActionItem; 810 if (!moveItem) moveItem = mActionItem;
801 while (moveItem) { 811 while (moveItem) {
802 int dy; 812 int dy;
803 if (isMultiItem) dy = 0; 813 if (isMultiItem) dy = 0;
804 else dy = gy - mCurrentCellY; 814 else dy = gy - mCurrentCellY;
805 moveItem->moveRelative(gx - mCurrentCellX,dy); 815 moveItem->moveRelative(gx - mCurrentCellX,dy);
806 int x,y; 816 int x,y;
807 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); 817 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y);
808 moveItem->resize(mGridSpacingX * moveItem->cellWidth(), 818 moveItem->resize(mGridSpacingX * moveItem->cellWidth(),
809 mGridSpacingY * moveItem->cellHeight()); 819 mGridSpacingY * moveItem->cellHeight());
810 moveChild(moveItem,x,y); 820 moveChild(moveItem,x,y);
811 moveItem = moveItem->nextMultiItem(); 821 moveItem = moveItem->nextMultiItem();
812 } 822 }
813 } else if (mActionType == RESIZETOP) { 823 } else if (mActionType == RESIZETOP) {
814 if (mCurrentCellY <= mActionItem->cellYBottom()) { 824 if (mCurrentCellY <= mActionItem->cellYBottom()) {
815 mActionItem->expandTop(gy - mCurrentCellY); 825 mActionItem->expandTop(gy - mCurrentCellY);
816 mActionItem->resize(mActionItem->width(), 826 mActionItem->resize(mActionItem->width(),
817 mGridSpacingY * mActionItem->cellHeight()); 827 mGridSpacingY * mActionItem->cellHeight());
818 int x,y; 828 int x,y;
819 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); 829 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y);
820 //moveChild(mActionItem,childX(mActionItem),y); 830 //moveChild(mActionItem,childX(mActionItem),y);
821 QScrollView::moveChild( mActionItem,childX(mActionItem),y ); 831 QScrollView::moveChild( mActionItem,childX(mActionItem),y );
822 } 832 }
823 } else if (mActionType == RESIZEBOTTOM) { 833 } else if (mActionType == RESIZEBOTTOM) {
824 if (mCurrentCellY >= mActionItem->cellYTop()) { 834 if (mCurrentCellY >= mActionItem->cellYTop()) {
825 mActionItem->expandBottom(gy - mCurrentCellY); 835 mActionItem->expandBottom(gy - mCurrentCellY);
826 mActionItem->resize(mActionItem->width(), 836 mActionItem->resize(mActionItem->width(),
827 mGridSpacingY * mActionItem->cellHeight()); 837 mGridSpacingY * mActionItem->cellHeight());
828 } 838 }
829 } else if (mActionType == RESIZELEFT) { 839 } else if (mActionType == RESIZELEFT) {
830 if (mCurrentCellX <= mActionItem->cellXWidth()) { 840 if (mCurrentCellX <= mActionItem->cellXWidth()) {
831 mActionItem->expandLeft(gx - mCurrentCellX); 841 mActionItem->expandLeft(gx - mCurrentCellX);
832 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 842 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
833 mActionItem->height()); 843 mActionItem->height());
834 int x,y; 844 int x,y;
835 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); 845 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y);
836 moveChild(mActionItem,x,childY(mActionItem)); 846 moveChild(mActionItem,x,childY(mActionItem));
837 } 847 }
838 } else if (mActionType == RESIZERIGHT) { 848 } else if (mActionType == RESIZERIGHT) {
839 if (mCurrentCellX >= mActionItem->cellX()) { 849 if (mCurrentCellX >= mActionItem->cellX()) {
840 mActionItem->expandRight(gx - mCurrentCellX); 850 mActionItem->expandRight(gx - mCurrentCellX);
841 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 851 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
842 mActionItem->height()); 852 mActionItem->height());
843 } 853 }
844 } 854 }
845 mCurrentCellX = gx; 855 mCurrentCellX = gx;
846 mCurrentCellY = gy; 856 mCurrentCellY = gy;
847 } 857 }
848} 858}
849 859
850void KOAgenda::endItemAction() 860void KOAgenda::endItemAction()