-rw-r--r-- | korganizer/koagenda.cpp | 75 |
1 files changed, 31 insertions, 44 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp index 2820ca2..66ad4ec 100644 --- a/korganizer/koagenda.cpp +++ b/korganizer/koagenda.cpp | |||
@@ -82,193 +82,193 @@ MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name) | |||
82 | 82 | ||
83 | oldToday = -1; | 83 | oldToday = -1; |
84 | } | 84 | } |
85 | 85 | ||
86 | MarcusBains::~MarcusBains() | 86 | MarcusBains::~MarcusBains() |
87 | { | 87 | { |
88 | delete minutes; | 88 | delete minutes; |
89 | } | 89 | } |
90 | 90 | ||
91 | int MarcusBains::todayColumn() | 91 | int 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 | } |
107 | void MarcusBains::updateLoc() | 107 | void MarcusBains::updateLoc() |
108 | { | 108 | { |
109 | updateLocation(); | 109 | updateLocation(); |
110 | } | 110 | } |
111 | void MarcusBains::updateLocation(bool recalculate) | 111 | void 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 | */ |
167 | KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, | 167 | KOAgenda::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 | */ |
188 | KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : | 188 | KOAgenda::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 | ||
205 | KOAgenda::~KOAgenda() | 205 | KOAgenda::~KOAgenda() |
206 | { | 206 | { |
207 | if(mMarcusBains) delete mMarcusBains; | 207 | if(mMarcusBains) delete mMarcusBains; |
208 | 208 | ||
209 | } | 209 | } |
210 | 210 | ||
211 | Incidence *KOAgenda::selectedIncidence() const | 211 | Incidence *KOAgenda::selectedIncidence() const |
212 | { | 212 | { |
213 | return (mSelectedItem ? mSelectedItem->incidence() : 0); | 213 | return (mSelectedItem ? mSelectedItem->incidence() : 0); |
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
217 | QDate KOAgenda::selectedIncidenceDate() const | 217 | QDate KOAgenda::selectedIncidenceDate() const |
218 | { | 218 | { |
219 | return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); | 219 | return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); |
220 | } | 220 | } |
221 | 221 | ||
222 | 222 | ||
223 | void KOAgenda::init() | 223 | void 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 | ||
@@ -305,345 +305,332 @@ void KOAgenda::init() | |||
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 | ||
317 | void KOAgenda::clear() | 317 | void 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 | ||
329 | void KOAgenda::clearSelection() | 329 | void 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 | ||
336 | void KOAgenda::marcus_bains() | 336 | void KOAgenda::marcus_bains() |
337 | { | 337 | { |
338 | if(mMarcusBains) mMarcusBains->updateLocation(true); | 338 | if(mMarcusBains) mMarcusBains->updateLocation(true); |
339 | } | 339 | } |
340 | 340 | ||
341 | 341 | ||
342 | void KOAgenda::changeColumns(int columns) | 342 | void 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 | */ |
366 | bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) | 366 | bool 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 | ||
387 | bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) | 387 | bool 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 int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); | 398 | static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); |
399 | static bool blockMoving = true; | 399 | static bool blockMoving = true; |
400 | static bool leftMouseDown = false; | 400 | static bool leftMouseDown = false; |
401 | static bool rightMouseDown = false; | ||
402 | static QTime rightClickTime; | ||
403 | bool rightButtonPressed = false; | 401 | bool rightButtonPressed = false; |
404 | switch (me->type()) { | 402 | switch (me->type()) { |
405 | case QEvent::MouseButtonPress: | 403 | case QEvent::MouseButtonPress: |
406 | rightClickTime.restart(); | ||
407 | if (me->button() == LeftButton) { | 404 | if (me->button() == LeftButton) { |
408 | leftMouseDown = true; | 405 | leftMouseDown = true; |
409 | } | 406 | } |
410 | else if (me->button() == RightButton) | 407 | else if (me->button() == RightButton) { |
411 | rightMouseDown = true; | 408 | leftMouseDown = false; |
409 | } | ||
412 | blockMoving = true; | 410 | blockMoving = true; |
413 | startX = viewportPos.x(); | 411 | startX = viewportPos.x(); |
414 | startY = viewportPos.y(); | 412 | startY = viewportPos.y(); |
415 | if (object != viewport()) { | 413 | if (object != viewport()) { // item clicked ************** |
416 | if (me->button() == RightButton) { | 414 | if (me->button() == RightButton) { |
415 | leftMouseDown = false; | ||
417 | mClickedItem = (KOAgendaItem *)object; | 416 | mClickedItem = (KOAgendaItem *)object; |
417 | if (mActionItem ) { | ||
418 | endItemAction(); | ||
419 | } | ||
418 | if (mClickedItem) { | 420 | if (mClickedItem) { |
419 | selectItem(mClickedItem); | 421 | selectItem(mClickedItem); |
422 | emit showIncidencePopupSignal(mClickedItem->incidence()); | ||
420 | } | 423 | } |
424 | return true; | ||
421 | } else if (me->button() == LeftButton) { | 425 | } else if (me->button() == LeftButton) { |
422 | mActionItem = (KOAgendaItem *)object; | 426 | mActionItem = (KOAgendaItem *)object; |
423 | if (mActionItem) { | 427 | if (mActionItem) { |
424 | if ( mSelectionHeight > 0 ) { | 428 | if ( mSelectionHeight > 0 ) { |
425 | int selectionCellX = mSelectionCellX * mGridSpacingX; | 429 | int selectionCellX = mSelectionCellX * mGridSpacingX; |
426 | int selectionYTop = mSelectionYTop; | 430 | int selectionYTop = mSelectionYTop; |
427 | int gridSpacingX = mGridSpacingX; | 431 | int gridSpacingX = mGridSpacingX; |
428 | int selectionHeight = mSelectionHeight; | 432 | int selectionHeight = mSelectionHeight; |
429 | clearSelection(); | 433 | clearSelection(); |
430 | repaintContents( selectionCellX, selectionYTop, | 434 | repaintContents( selectionCellX, selectionYTop, |
431 | gridSpacingX, selectionHeight,false ); | 435 | gridSpacingX, selectionHeight,false ); |
432 | } | 436 | } |
433 | selectItem(mActionItem); | 437 | selectItem(mActionItem); |
434 | Incidence *incidence = mActionItem->incidence(); | 438 | Incidence *incidence = mActionItem->incidence(); |
435 | if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { | 439 | if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { |
436 | mActionItem = 0; | 440 | mActionItem = 0; |
437 | } else { | 441 | } else { |
438 | startItemAction(viewportPos); | 442 | startItemAction(viewportPos); |
439 | } | 443 | } |
440 | } | 444 | } |
441 | } | 445 | } |
442 | } else { // ---------- viewport() | 446 | } else { // ---------- viewport() |
443 | selectItem(0); | 447 | selectItem(0); |
444 | mActionItem = 0; | 448 | mActionItem = 0; |
445 | if (me->button() == LeftButton ) { | 449 | if (me->button() == LeftButton ) { |
446 | setCursor(arrowCursor); | 450 | setCursor(arrowCursor); |
447 | startSelectAction(viewportPos); | 451 | startSelectAction(viewportPos); |
452 | } else if (me->button() == RightButton ) { | ||
453 | setCursor(arrowCursor); | ||
454 | if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action | ||
455 | endSelectAction( false ); // do not emit new event signal | ||
456 | leftMouseDown = false; // no more leftMouse computation | ||
457 | } | ||
458 | int x,y; | ||
459 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | ||
460 | int gx,gy; | ||
461 | contentsToGrid(x,y,gx,gy); | ||
462 | mCurrentCellX = gx; | ||
463 | mCurrentCellY = gy; | ||
464 | mStartCellX = gx; | ||
465 | mStartCellY = gy; | ||
466 | mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); | ||
448 | } | 467 | } |
449 | } | 468 | } |
450 | break; | 469 | break; |
451 | 470 | ||
452 | case QEvent::MouseButtonRelease: | 471 | case QEvent::MouseButtonRelease: |
453 | if ( rightClickTime.elapsed() > 500 && blockMoving ) | 472 | |
454 | rightButtonPressed = true; | ||
455 | if (object != viewport()) { | 473 | if (object != viewport()) { |
456 | if (me->button() == RightButton || rightButtonPressed ) { | 474 | if (me->button() == LeftButton && leftMouseDown) { |
457 | if ( blockMoving ) { | ||
458 | mClickedItem = (KOAgendaItem *)object; | ||
459 | if (mActionItem ) { | ||
460 | endItemAction(); | ||
461 | } | ||
462 | leftMouseDown = false; // no more leftMouse computation | ||
463 | if (mClickedItem) { | ||
464 | selectItem(mClickedItem); | ||
465 | emit showIncidencePopupSignal(mClickedItem->incidence()); | ||
466 | } | ||
467 | } | ||
468 | } else if (me->button() == LeftButton && leftMouseDown) { | ||
469 | if (mActionItem) { | 475 | if (mActionItem) { |
470 | QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); | 476 | QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); |
471 | //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); | 477 | //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); |
472 | if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { | 478 | if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { |
473 | mScrollUpTimer.stop(); | 479 | mScrollUpTimer.stop(); |
474 | mScrollDownTimer.stop(); | 480 | mScrollDownTimer.stop(); |
475 | mActionItem->resetMove(); | 481 | mActionItem->resetMove(); |
476 | placeSubCells( mActionItem ); | 482 | placeSubCells( mActionItem ); |
477 | // emit startDragSignal( mActionItem->incidence() ); | 483 | // emit startDragSignal( mActionItem->incidence() ); |
478 | setCursor( arrowCursor ); | 484 | setCursor( arrowCursor ); |
479 | mActionItem = 0; | 485 | mActionItem = 0; |
480 | mActionType = NOP; | 486 | mActionType = NOP; |
481 | mItemMoved = 0; | 487 | mItemMoved = 0; |
482 | leftMouseDown = false; | 488 | leftMouseDown = false; |
483 | return true; | 489 | return true; |
484 | } | 490 | } |
485 | endItemAction(); | 491 | endItemAction(); |
486 | } | 492 | } |
487 | } | 493 | } |
488 | 494 | ||
489 | } else { // ---------- viewport() | 495 | } else { // ---------- viewport() |
490 | if (me->button() == RightButton || rightButtonPressed ) { //right click | 496 | if (me->button() == LeftButton && leftMouseDown ) { //left click |
491 | if ( blockMoving ) { // we did mot moved the mouse much - popup menu | ||
492 | if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action | ||
493 | endSelectAction( false ); // do not emit new event signal | ||
494 | leftMouseDown = false; // no more leftMouse computation | ||
495 | } | ||
496 | int x,y; | ||
497 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | ||
498 | int gx,gy; | ||
499 | contentsToGrid(x,y,gx,gy); | ||
500 | mCurrentCellX = gx; | ||
501 | mCurrentCellY = gy; | ||
502 | mStartCellX = gx; | ||
503 | mStartCellY = gy; | ||
504 | mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); | ||
505 | } | ||
506 | } | ||
507 | else if (me->button() == LeftButton && leftMouseDown ) { //left click | ||
508 | endSelectAction( true ); // emit new event signal | 497 | endSelectAction( true ); // emit new event signal |
509 | } | 498 | } |
510 | } | 499 | } |
511 | if (me->button() == LeftButton) | 500 | if (me->button() == LeftButton) |
512 | leftMouseDown = false; | 501 | leftMouseDown = false; |
513 | else if (me->button() == RightButton) | 502 | |
514 | rightMouseDown = false; | ||
515 | break; | 503 | break; |
516 | 504 | ||
517 | case QEvent::MouseMove: | 505 | case QEvent::MouseMove: |
518 | if ( !rightMouseDown && !leftMouseDown ) | 506 | if ( !leftMouseDown ) |
519 | return true; | 507 | return true; |
520 | if ( blockMoving ) { | 508 | if ( blockMoving ) { |
521 | int dX, dY; | 509 | int dX, dY; |
522 | dX = startX - viewportPos.x(); | 510 | dX = startX - viewportPos.x(); |
523 | if ( dX < 0 ) | 511 | if ( dX < 0 ) |
524 | dX = -dX; | 512 | dX = -dX; |
525 | dY = viewportPos.y() - startY; | 513 | dY = viewportPos.y() - startY; |
526 | if ( dY < 0 ) | 514 | if ( dY < 0 ) |
527 | dY = -dY; | 515 | dY = -dY; |
528 | //qDebug("%d %d %d ", dX, dY , blockmoveDist ); | 516 | //qDebug("%d %d %d ", dX, dY , blockmoveDist ); |
529 | if ( dX > blockmoveDist || dY > blockmoveDist ) { | 517 | if ( dX > blockmoveDist || dY > blockmoveDist ) { |
530 | blockMoving = false; | 518 | blockMoving = false; |
531 | } | 519 | } |
532 | } | 520 | } |
533 | if (object != viewport()) { | 521 | if (object != viewport()) { |
534 | KOAgendaItem *moveItem = (KOAgendaItem *)object; | 522 | KOAgendaItem *moveItem = (KOAgendaItem *)object; |
535 | if (!moveItem->incidence()->isReadOnly() ) { | 523 | if (!moveItem->incidence()->isReadOnly() ) { |
536 | if (!mActionItem) | 524 | if (!mActionItem) |
537 | setNoActionCursor(moveItem,viewportPos); | 525 | setNoActionCursor(moveItem,viewportPos); |
538 | else { | 526 | else { |
539 | if ( !blockMoving ) | 527 | if ( !blockMoving ) |
540 | performItemAction(viewportPos); | 528 | performItemAction(viewportPos); |
541 | } | 529 | } |
542 | } | 530 | } |
543 | } else { // ---------- viewport() | 531 | } else { // ---------- viewport() |
544 | if ( mActionType == SELECT ) { | 532 | if ( mActionType == SELECT ) { |
545 | performSelectAction( viewportPos ); | 533 | performSelectAction( viewportPos ); |
546 | } | 534 | } |
547 | } | 535 | } |
548 | break; | 536 | break; |
549 | 537 | ||
550 | case QEvent::MouseButtonDblClick: | 538 | case QEvent::MouseButtonDblClick: |
551 | blockMoving = false; | 539 | blockMoving = false; |
552 | leftMouseDown = false; | 540 | leftMouseDown = false; |
553 | rightMouseDown = false; | ||
554 | if (object == viewport()) { | 541 | if (object == viewport()) { |
555 | selectItem(0); | 542 | selectItem(0); |
556 | int x,y; | 543 | int x,y; |
557 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 544 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
558 | int gx,gy; | 545 | int gx,gy; |
559 | contentsToGrid(x,y,gx,gy); | 546 | contentsToGrid(x,y,gx,gy); |
560 | emit newEventSignal(gx,gy); | 547 | emit newEventSignal(gx,gy); |
561 | } else { | 548 | } else { |
562 | KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; | 549 | KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; |
563 | selectItem(doubleClickedItem); | 550 | selectItem(doubleClickedItem); |
564 | if ( KOPrefs::instance()->mEditOnDoubleClick ) | 551 | if ( KOPrefs::instance()->mEditOnDoubleClick ) |
565 | emit editIncidenceSignal(doubleClickedItem->incidence()); | 552 | emit editIncidenceSignal(doubleClickedItem->incidence()); |
566 | else | 553 | else |
567 | emit showIncidenceSignal(doubleClickedItem->incidence()); | 554 | emit showIncidenceSignal(doubleClickedItem->incidence()); |
568 | } | 555 | } |
569 | break; | 556 | break; |
570 | 557 | ||
571 | default: | 558 | default: |
572 | break; | 559 | break; |
573 | } | 560 | } |
574 | return true; | 561 | return true; |
575 | } | 562 | } |
576 | 563 | ||
577 | void KOAgenda::newItem( int item ) | 564 | void KOAgenda::newItem( int item ) |
578 | { | 565 | { |
579 | if ( item == 1 ) { //new event | 566 | if ( item == 1 ) { //new event |
580 | newEventSignal(mStartCellX ,mStartCellY ); | 567 | newEventSignal(mStartCellX ,mStartCellY ); |
581 | } else | 568 | } else |
582 | if ( item == 2 ) { //new event | 569 | if ( item == 2 ) { //new event |
583 | newTodoSignal(mStartCellX ,mStartCellY ); | 570 | newTodoSignal(mStartCellX ,mStartCellY ); |
584 | } else | 571 | } else |
585 | { | 572 | { |
586 | QDate day = mSelectedDates[mStartCellX]; | 573 | QDate day = mSelectedDates[mStartCellX]; |
587 | emit showDateView( item, day ); | 574 | emit showDateView( item, day ); |
588 | // 3Day view | 575 | // 3Day view |
589 | // 4Week view | 576 | // 4Week view |
590 | // 5Month view | 577 | // 5Month view |
591 | // 6Journal view | 578 | // 6Journal view |
592 | } | 579 | } |
593 | } | 580 | } |
594 | void KOAgenda::startSelectAction(QPoint viewportPos) | 581 | void KOAgenda::startSelectAction(QPoint viewportPos) |
595 | { | 582 | { |
596 | //emit newStartSelectSignal(); | 583 | //emit newStartSelectSignal(); |
597 | 584 | ||
598 | mActionType = SELECT; | 585 | mActionType = SELECT; |
599 | 586 | ||
600 | int x,y; | 587 | int x,y; |
601 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 588 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
602 | int gx,gy; | 589 | int gx,gy; |
603 | contentsToGrid(x,y,gx,gy); | 590 | contentsToGrid(x,y,gx,gy); |
604 | 591 | ||
605 | mStartCellX = gx; | 592 | mStartCellX = gx; |
606 | mStartCellY = gy; | 593 | mStartCellY = gy; |
607 | mCurrentCellX = gx; | 594 | mCurrentCellX = gx; |
608 | mCurrentCellY = gy; | 595 | mCurrentCellY = gy; |
609 | 596 | ||
610 | // Store coordinates of old selection | 597 | // Store coordinates of old selection |
611 | int selectionX = mSelectionCellX * mGridSpacingX; | 598 | int selectionX = mSelectionCellX * mGridSpacingX; |
612 | int selectionYTop = mSelectionYTop; | 599 | int selectionYTop = mSelectionYTop; |
613 | int selectionHeight = mSelectionHeight; | 600 | int selectionHeight = mSelectionHeight; |
614 | 601 | ||
615 | // Store new selection | 602 | // Store new selection |
616 | mSelectionCellX = gx; | 603 | mSelectionCellX = gx; |
617 | mSelectionYTop = gy * mGridSpacingY; | 604 | mSelectionYTop = gy * mGridSpacingY; |
618 | mSelectionHeight = mGridSpacingY; | 605 | mSelectionHeight = mGridSpacingY; |
619 | 606 | ||
620 | // Clear old selection | 607 | // Clear old selection |
621 | repaintContents( selectionX, selectionYTop, | 608 | repaintContents( selectionX, selectionYTop, |
622 | mGridSpacingX, selectionHeight,false ); | 609 | mGridSpacingX, selectionHeight,false ); |
623 | 610 | ||
624 | // Paint new selection | 611 | // Paint new selection |
625 | // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, | 612 | // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, |
626 | // mGridSpacingX, mSelectionHeight ); | 613 | // mGridSpacingX, mSelectionHeight ); |
627 | } | 614 | } |
628 | 615 | ||
629 | void KOAgenda::performSelectAction(QPoint viewportPos) | 616 | void KOAgenda::performSelectAction(QPoint viewportPos) |
630 | { | 617 | { |
631 | int x,y; | 618 | int x,y; |
632 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 619 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
633 | int gx,gy; | 620 | int gx,gy; |
634 | contentsToGrid(x,y,gx,gy); | 621 | contentsToGrid(x,y,gx,gy); |
635 | 622 | ||
636 | QPoint clipperPos = clipper()-> | 623 | QPoint clipperPos = clipper()-> |
637 | mapFromGlobal(viewport()->mapToGlobal(viewportPos)); | 624 | mapFromGlobal(viewport()->mapToGlobal(viewportPos)); |
638 | 625 | ||
639 | // Scroll if cursor was moved to upper or lower end of agenda. | 626 | // Scroll if cursor was moved to upper or lower end of agenda. |
640 | if (clipperPos.y() < mScrollBorderWidth) { | 627 | if (clipperPos.y() < mScrollBorderWidth) { |
641 | mScrollUpTimer.start(mScrollDelay); | 628 | mScrollUpTimer.start(mScrollDelay); |
642 | } else if (visibleHeight() - clipperPos.y() < | 629 | } else if (visibleHeight() - clipperPos.y() < |
643 | mScrollBorderWidth) { | 630 | mScrollBorderWidth) { |
644 | mScrollDownTimer.start(mScrollDelay); | 631 | mScrollDownTimer.start(mScrollDelay); |
645 | } else { | 632 | } else { |
646 | mScrollUpTimer.stop(); | 633 | mScrollUpTimer.stop(); |
647 | mScrollDownTimer.stop(); | 634 | mScrollDownTimer.stop(); |
648 | } | 635 | } |
649 | 636 | ||