summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagenda.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp
index b99625c..faddac4 100644
--- a/korganizer/koagenda.cpp
+++ b/korganizer/koagenda.cpp
@@ -1,1238 +1,1242 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 Marcus Bains line. 5 Marcus Bains line.
6 Copyright (c) 2001 Ali Rahimi 6 Copyright (c) 2001 Ali Rahimi
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 (at your option) any later version.
12 12
13 This program is distributed in the hope that it will be useful, 13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 GNU General Public License for more details.
17 17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 mTimeBox = new QLabel(this); 73 mTimeBox = new QLabel(this);
74 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom); 74 mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom);
75 QPalette pal = mTimeBox->palette(); 75 QPalette pal = mTimeBox->palette();
76 pal.setColor(QColorGroup::Foreground, Qt::red); 76 pal.setColor(QColorGroup::Foreground, Qt::red);
77 mTimeBox->setPalette(pal); 77 mTimeBox->setPalette(pal);
78 //mTimeBox->setAutoMask(true); 78 //mTimeBox->setAutoMask(true);
79 79
80 agenda->addChild(mTimeBox); 80 agenda->addChild(mTimeBox);
81 81
82 oldToday = -1; 82 oldToday = -1;
83} 83}
84 84
85MarcusBains::~MarcusBains() 85MarcusBains::~MarcusBains()
86{ 86{
87 delete minutes; 87 delete minutes;
88} 88}
89 89
90int MarcusBains::todayColumn() 90int MarcusBains::todayColumn()
91{ 91{
92 QDate currentDate = QDate::currentDate(); 92 QDate currentDate = QDate::currentDate();
93 93
94 DateList dateList = agenda->dateList(); 94 DateList dateList = agenda->dateList();
95 DateList::ConstIterator it; 95 DateList::ConstIterator it;
96 int col = 0; 96 int col = 0;
97 for(it = dateList.begin(); it != dateList.end(); ++it) { 97 for(it = dateList.begin(); it != dateList.end(); ++it) {
98 if((*it) == currentDate) 98 if((*it) == currentDate)
99 return KOGlobals::self()->reverseLayout() ? 99 return KOGlobals::self()->reverseLayout() ?
100 agenda->columns() - 1 - col : col; 100 agenda->columns() - 1 - col : col;
101 ++col; 101 ++col;
102 } 102 }
103 103
104 return -1; 104 return -1;
105} 105}
106void MarcusBains::updateLoc() 106void MarcusBains::updateLoc()
107{ 107{
108 updateLocation(); 108 updateLocation();
109} 109}
110void MarcusBains::updateLocation(bool recalculate) 110void MarcusBains::updateLocation(bool recalculate)
111{ 111{
112 112
113 QTime tim = QTime::currentTime(); 113 QTime tim = QTime::currentTime();
114 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); 114 //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1());
115 if((tim.hour() == 0) && (oldTime.hour()==23)) 115 if((tim.hour() == 0) && (oldTime.hour()==23))
116 recalculate = true; 116 recalculate = true;
117 117
118 int mins = tim.hour()*60 + tim.minute(); 118 int mins = tim.hour()*60 + tim.minute();
119 int minutesPerCell = 24 * 60 / agenda->rows(); 119 int minutesPerCell = 24 * 60 / agenda->rows();
120 int y = mins*agenda->gridSpacingY()/minutesPerCell; 120 int y = mins*agenda->gridSpacingY()/minutesPerCell;
121 int today = recalculate ? todayColumn() : oldToday; 121 int today = recalculate ? todayColumn() : oldToday;
122 int x = agenda->gridSpacingX()*today; 122 int x = agenda->gridSpacingX()*today;
123 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); 123 bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled);
124 124
125 oldTime = tim; 125 oldTime = tim;
126 oldToday = today; 126 oldToday = today;
127 127
128 if(disabled || (today<0)) { 128 if(disabled || (today<0)) {
129 hide(); mTimeBox->hide(); 129 hide(); mTimeBox->hide();
130 return; 130 return;
131 } else { 131 } else {
132 show(); mTimeBox->show(); 132 show(); mTimeBox->show();
133 } 133 }
134 134
135 if(recalculate) 135 if(recalculate)
136 setFixedSize(agenda->gridSpacingX(),1); 136 setFixedSize(agenda->gridSpacingX(),1);
137 agenda->moveChild(this, x, y); 137 agenda->moveChild(this, x, y);
138 raise(); 138 raise();
139 139
140 if(recalculate) 140 if(recalculate)
141 //mTimeBox->setFont(QFont("helvetica",10)); 141 //mTimeBox->setFont(QFont("helvetica",10));
142 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); 142 mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont);
143 143
144 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); 144 mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds));
145 mTimeBox->adjustSize(); 145 mTimeBox->adjustSize();
146 // the -2 below is there because there is a bug in this program 146 // the -2 below is there because there is a bug in this program
147 // somewhere, where the last column of this widget is a few pixels 147 // somewhere, where the last column of this widget is a few pixels
148 // narrower than the other columns. 148 // narrower than the other columns.
149 int offs = (today==agenda->columns()-1) ? -4 : 0; 149 int offs = (today==agenda->columns()-1) ? -4 : 0;
150 agenda->moveChild(mTimeBox, 150 agenda->moveChild(mTimeBox,
151 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, 151 x+agenda->gridSpacingX()-mTimeBox->width()+offs-1,
152 y-mTimeBox->height()); 152 y-mTimeBox->height());
153 153
154 mTimeBox->raise(); 154 mTimeBox->raise();
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 mAllAgendaPopup = 0; 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 mAllAgendaPopup = 0;
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 mPopupTimer = new QTimer(this); 225 mPopupTimer = new QTimer(this);
226 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu())); 226 connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu()));
227 227
228 mNewItemPopup = new QPopupMenu( this ); 228 mNewItemPopup = new QPopupMenu( this );
229 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); 229 connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) );
230 QString pathString = ""; 230 QString pathString = "";
231 if ( !KOPrefs::instance()->mToolBarMiniIcons ) { 231 if ( !KOPrefs::instance()->mToolBarMiniIcons ) {
232 if ( QApplication::desktop()->width() < 480 ) 232 if ( QApplication::desktop()->width() < 480 )
233 pathString += "icons16/"; 233 pathString += "icons16/";
234 } else 234 } else
235 pathString += "iconsmini/"; 235 pathString += "iconsmini/";
236 236
237 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); 237 mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 );
238 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); 238 mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 );
239 mNewItemPopup->insertSeparator ( ); 239 mNewItemPopup->insertSeparator ( );
240 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); 240 mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 );
241 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); 241 mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 );
242 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); 242 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 );
243 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); 243 mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 );
244 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("This month"),6 ); 244 mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("This month"),6 );
245 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); 245 mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 );
246#ifndef _WIN32_ 246#ifndef _WIN32_
247 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase 247 int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase
248 viewport()->setWFlags ( wflags); 248 viewport()->setWFlags ( wflags);
249#endif 249#endif
250 mGridSpacingX = 80; 250 mGridSpacingX = 80;
251 mResizeBorderWidth = 8; 251 mResizeBorderWidth = 8;
252 mScrollBorderWidth = 8; 252 mScrollBorderWidth = 8;
253 mScrollDelay = 30; 253 mScrollDelay = 30;
254 mScrollOffset = 10; 254 mScrollOffset = 10;
255 mPaintPixmap.resize( 20,20); 255 mPaintPixmap.resize( 20,20);
256 //enableClipper(true); 256 //enableClipper(true);
257 257
258 // Grab key strokes for keyboard navigation of agenda. Seems to have no 258 // Grab key strokes for keyboard navigation of agenda. Seems to have no
259 // effect. Has to be fixed. 259 // effect. Has to be fixed.
260 setFocusPolicy(WheelFocus); 260 setFocusPolicy(WheelFocus);
261 261
262 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); 262 connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp()));
263 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); 263 connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown()));
264 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); 264 connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize()));
265 265
266 mStartCellX = 0; 266 mStartCellX = 0;
267 mStartCellY = 0; 267 mStartCellY = 0;
268 mCurrentCellX = 0; 268 mCurrentCellX = 0;
269 mCurrentCellY = 0; 269 mCurrentCellY = 0;
270 270
271 mSelectionCellX = 0; 271 mSelectionCellX = 0;
272 mSelectionYTop = 0; 272 mSelectionYTop = 0;
273 mSelectionHeight = 0; 273 mSelectionHeight = 0;
274 274
275 mOldLowerScrollValue = -1; 275 mOldLowerScrollValue = -1;
276 mOldUpperScrollValue = -1; 276 mOldUpperScrollValue = -1;
277 277
278 mClickedItem = 0; 278 mClickedItem = 0;
279 279
280 mActionItem = 0; 280 mActionItem = 0;
281 mActionType = NOP; 281 mActionType = NOP;
282 mItemMoved = false; 282 mItemMoved = false;
283 283
284 mSelectedItem = 0; 284 mSelectedItem = 0;
285 285
286 // mItems.setAutoDelete(true); 286 // mItems.setAutoDelete(true);
287 287
288 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 288 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
289 289
290 viewport()->update(); 290 viewport()->update();
291 291
292 setMinimumSize(30, 1); 292 setMinimumSize(30, 1);
293// setMaximumHeight(mGridSpacingY * mRows + 5); 293// setMaximumHeight(mGridSpacingY * mRows + 5);
294 294
295 // Disable horizontal scrollbar. This is a hack. The geometry should be 295 // Disable horizontal scrollbar. This is a hack. The geometry should be
296 // controlled in a way that the contents horizontally always fits. Then it is 296 // controlled in a way that the contents horizontally always fits. Then it is
297 // not necessary to turn off the scrollbar. 297 // not necessary to turn off the scrollbar.
298 setHScrollBarMode(AlwaysOff); 298 setHScrollBarMode(AlwaysOff);
299 if ( ! mAllDayMode ) 299 if ( ! mAllDayMode )
300 setVScrollBarMode(AlwaysOn); 300 setVScrollBarMode(AlwaysOn);
301 else 301 else
302 setVScrollBarMode(AlwaysOff); 302 setVScrollBarMode(AlwaysOff);
303 303
304 setStartHour(KOPrefs::instance()->mDayBegins); 304 setStartHour(KOPrefs::instance()->mDayBegins);
305 305
306 calculateWorkingHours(); 306 calculateWorkingHours();
307 307
308 connect(verticalScrollBar(),SIGNAL(valueChanged(int)), 308 connect(verticalScrollBar(),SIGNAL(valueChanged(int)),
309 SLOT(checkScrollBoundaries(int))); 309 SLOT(checkScrollBoundaries(int)));
310 310
311 // Create the Marcus Bains line. 311 // Create the Marcus Bains line.
312 if(mAllDayMode) 312 if(mAllDayMode)
313 mMarcusBains = 0; 313 mMarcusBains = 0;
314 else { 314 else {
315 mMarcusBains = new MarcusBains(this); 315 mMarcusBains = new MarcusBains(this);
316 addChild(mMarcusBains); 316 addChild(mMarcusBains);
317 } 317 }
318 mPopupKind = 0; 318 mPopupKind = 0;
319 mPopupItem = 0; 319 mPopupItem = 0;
320} 320}
321 321
322void KOAgenda::clear() 322void KOAgenda::clear()
323{ 323{
324 KOAgendaItem *item; 324 KOAgendaItem *item;
325 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 325 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
326 mUnusedItems.append( item ); 326 mUnusedItems.append( item );
327 //item->hide(); 327 //item->hide();
328 } 328 }
329 mItems.clear(); 329 mItems.clear();
330 mSelectedItem = 0; 330 mSelectedItem = 0;
331 clearSelection(); 331 clearSelection();
332} 332}
333 333
334void KOAgenda::clearSelection() 334void KOAgenda::clearSelection()
335{ 335{
336 mSelectionCellX = 0; 336 mSelectionCellX = 0;
337 mSelectionYTop = 0; 337 mSelectionYTop = 0;
338 mSelectionHeight = 0; 338 mSelectionHeight = 0;
339} 339}
340 340
341void KOAgenda::marcus_bains() 341void KOAgenda::marcus_bains()
342{ 342{
343 if(mMarcusBains) mMarcusBains->updateLocation(true); 343 if(mMarcusBains) mMarcusBains->updateLocation(true);
344} 344}
345 345
346 346
347void KOAgenda::changeColumns(int columns) 347void KOAgenda::changeColumns(int columns)
348{ 348{
349 if (columns == 0) { 349 if (columns == 0) {
350 qDebug("KOAgenda::changeColumns() called with argument 0 "); 350 qDebug("KOAgenda::changeColumns() called with argument 0 ");
351 return; 351 return;
352 } 352 }
353 clear(); 353 clear();
354 mColumns = columns; 354 mColumns = columns;
355 computeSizes(); 355 computeSizes();
356} 356}
357 357
358/* 358/*
359 This is the eventFilter function, which gets all events from the KOAgendaItems 359 This is the eventFilter function, which gets all events from the KOAgendaItems
360 contained in the agenda. It has to handle moving and resizing for all items. 360 contained in the agenda. It has to handle moving and resizing for all items.
361*/ 361*/
362bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) 362bool KOAgenda::eventFilter ( QObject *object, QEvent *event )
363{ 363{
364 // kdDebug() << "KOAgenda::eventFilter" << endl; 364 // kdDebug() << "KOAgenda::eventFilter" << endl;
365 switch(event->type()) { 365 switch(event->type()) {
366 case QEvent::MouseButtonPress: 366 case QEvent::MouseButtonPress:
367 case QEvent::MouseButtonDblClick: 367 case QEvent::MouseButtonDblClick:
368 case QEvent::MouseButtonRelease: 368 case QEvent::MouseButtonRelease:
369 case QEvent::MouseMove: 369 case QEvent::MouseMove:
370 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); 370 return eventFilter_mouse(object, static_cast<QMouseEvent *>(event));
371 371
372 case (QEvent::Leave): 372 case (QEvent::Leave):
373 if (!mActionItem) 373 if (!mActionItem)
374 setCursor(arrowCursor); 374 setCursor(arrowCursor);
375 return true; 375 return true;
376 376
377 default: 377 default:
378 return QScrollView::eventFilter(object,event); 378 return QScrollView::eventFilter(object,event);
379 } 379 }
380} 380}
381void KOAgenda::popupMenu() 381void KOAgenda::popupMenu()
382{ 382{
383 mPopupTimer->stop(); 383 mPopupTimer->stop();
384 if ( mPopupKind == 1 || mPopupKind == 3 ) { 384 if ( mPopupKind == 1 || mPopupKind == 3 ) {
385 if (mActionItem ) { 385 if (mActionItem ) {
386 endItemAction(); 386 endItemAction();
387 } 387 }
388 mLeftMouseDown = false; // no more leftMouse computation 388 mLeftMouseDown = false; // no more leftMouse computation
389 if (mPopupItem) { 389 if (mPopupItem) {
390 //mClickedItem = mPopupItem; 390 //mClickedItem = mPopupItem;
391 selectItem(mPopupItem); 391 selectItem(mPopupItem);
392 if ( mAllAgendaPopup && KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 1 ) 392 if ( mAllAgendaPopup && KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 1 )
393 mAllAgendaPopup->installEventFilter( this ); 393 mAllAgendaPopup->installEventFilter( this );
394 emit showIncidencePopupSignal(mPopupItem->incidence()); 394 emit showIncidencePopupSignal(mPopupItem->incidence());
395 395
396 } 396 }
397 } else if ( mPopupKind == 2 || mPopupKind == 4 ) { 397 } else if ( mPopupKind == 2 || mPopupKind == 4 ) {
398 if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action 398 if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action
399 endSelectAction( false ); // do not emit new event signal 399 endSelectAction( false ); // do not emit new event signal
400 mLeftMouseDown = false; // no more leftMouse computation 400 mLeftMouseDown = false; // no more leftMouse computation
401 } 401 }
402 if ( KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 2 ) 402 if ( KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 2 )
403 mNewItemPopup->installEventFilter( this ); 403 mNewItemPopup->installEventFilter( this );
404 mNewItemPopup->popup( mPopupPos); 404 mNewItemPopup->popup( mPopupPos);
405 405
406 } 406 }
407 mLeftMouseDown = false; 407 mLeftMouseDown = false;
408 mPopupItem = 0; 408 mPopupItem = 0;
409 mPopupKind = 0; 409 mPopupKind = 0;
410} 410}
411 411
412bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) 412bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me)
413{ 413{
414 static int startX = 0; 414 static int startX = 0;
415 static int startY = 0; 415 static int startY = 0;
416 int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 7 : 9 ); 416 int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 7 : 9 );
417 static bool blockMoving = true; 417 static bool blockMoving = true;
418 418
419 //qDebug("KOAgenda::eventFilter_mous "); 419 //qDebug("KOAgenda::eventFilter_mous ");
420 if ( object == mNewItemPopup ) { 420 if ( object == mNewItemPopup ) {
421 //qDebug("mNewItemPopup "); 421 //qDebug("mNewItemPopup ");
422 if ( me->type() == QEvent::MouseButtonRelease ) { 422 if ( me->type() == QEvent::MouseButtonRelease ) {
423 mNewItemPopup->removeEventFilter( this ); 423 mNewItemPopup->removeEventFilter( this );
424 int dX = me->globalPos().x() - mPopupPos.x();; 424 int dX = me->globalPos().x() - mPopupPos.x();;
425 if ( dX < 0 ) 425 if ( dX < 0 )
426 dX = -dX; 426 dX = -dX;
427 int dY = me->globalPos().y() - mPopupPos.y(); 427 int dY = me->globalPos().y() - mPopupPos.y();
428 if ( dY < 0 ) 428 if ( dY < 0 )
429 dY = -dY; 429 dY = -dY;
430 if ( dX > blockmoveDist || dY > blockmoveDist ) { 430 if ( dX > blockmoveDist || dY > blockmoveDist ) {
431 mNewItemPopup->hide(); 431 mNewItemPopup->hide();
432 } 432 }
433 } 433 }
434 return true; 434 return true;
435 } 435 }
436 if ( object == mAllAgendaPopup ) { 436 if ( object == mAllAgendaPopup ) {
437 //qDebug(" mAllAgendaPopup "); 437 //qDebug(" mAllAgendaPopup ");
438 if ( me->type() == QEvent::MouseButtonRelease ) { 438 if ( me->type() == QEvent::MouseButtonRelease ) {
439 mAllAgendaPopup->removeEventFilter( this ); 439 mAllAgendaPopup->removeEventFilter( this );
440 int dX = me->globalPos().x() - mPopupPos.x();; 440 int dX = me->globalPos().x() - mPopupPos.x();;
441 if ( dX < 0 ) 441 if ( dX < 0 )
442 dX = -dX; 442 dX = -dX;
443 int dY = me->globalPos().y() - mPopupPos.y(); 443 int dY = me->globalPos().y() - mPopupPos.y();
444 if ( dY < 0 ) 444 if ( dY < 0 )
445 dY = -dY; 445 dY = -dY;
446 if ( dX > blockmoveDist || dY > blockmoveDist ) { 446 if ( dX > blockmoveDist || dY > blockmoveDist ) {
447 mAllAgendaPopup->hide(); 447 mAllAgendaPopup->hide();
448 } 448 }
449 } 449 }
450 return true; 450 return true;
451 } 451 }
452 QPoint viewportPos; 452 QPoint viewportPos;
453 if (object != viewport()) { 453 if (object != viewport()) {
454 blockmoveDist = blockmoveDist*2; 454 blockmoveDist = blockmoveDist*2;
455 viewportPos = ((QWidget *)object)->mapToParent(me->pos()); 455 viewportPos = ((QWidget *)object)->mapToParent(me->pos());
456 } else { 456 } else {
457 viewportPos = me->pos(); 457 viewportPos = me->pos();
458 } 458 }
459 bool objIsNotViewport = (object != viewport()); 459 bool objIsNotViewport = (object != viewport());
460 bool leftButt = false;
461#ifdef DESKTOP_VERSION
462 leftButt = (me->button() == LeftButton);
463#endif
460 switch (me->type()) { 464 switch (me->type()) {
461 case QEvent::MouseButtonPress: 465 case QEvent::MouseButtonPress:
462 if (me->button() == LeftButton) { 466 if (me->button() == LeftButton) {
463 mPopupTimer->start( 600 ); 467 mPopupTimer->start( 600 );
464 mLeftMouseDown = true; 468 mLeftMouseDown = true;
465 } 469 }
466 blockMoving = true; 470 blockMoving = true;
467 startX = viewportPos.x(); 471 startX = viewportPos.x();
468 startY = viewportPos.y(); 472 startY = viewportPos.y();
469 mPopupPos = me->globalPos(); 473 mPopupPos = me->globalPos();
470 if ( objIsNotViewport ) { 474 if ( objIsNotViewport && !leftButt ) {
471 KOAgendaItem * tempItem = (KOAgendaItem *)object; 475 KOAgendaItem * tempItem = (KOAgendaItem *)object;
472 if (mAllDayMode) { 476 if (mAllDayMode) {
473 if ( tempItem->height() > 10 ) { 477 if ( tempItem->height() > 10 ) {
474 int minV = tempItem->height()/4; 478 int minV = tempItem->height()/4;
475 if ( minV > (blockmoveDist/2)-2 ) 479 if ( minV > (blockmoveDist/2)-2 )
476 minV = (blockmoveDist/2)-2; 480 minV = (blockmoveDist/2)-2;
477 bool border = false; 481 bool border = false;
478 int diff = tempItem->y() - viewportPos.y(); 482 int diff = tempItem->y() - viewportPos.y();
479 if ( diff < 0 ) 483 if ( diff < 0 )
480 diff *= -1; 484 diff *= -1;
481 if ( diff < minV ) { 485 if ( diff < minV ) {
482 border = true; 486 border = true;
483 objIsNotViewport = false; 487 objIsNotViewport = false;
484 } 488 }
485 if ( ! border ) { 489 if ( ! border ) {
486 diff = tempItem->y() + tempItem->height()- viewportPos.y(); 490 diff = tempItem->y() + tempItem->height()- viewportPos.y();
487 if ( diff < 0 ) 491 if ( diff < 0 )
488 diff *= -1; 492 diff *= -1;
489 if ( diff < minV ) { 493 if ( diff < minV ) {
490 border = true; 494 border = true;
491 objIsNotViewport = false; 495 objIsNotViewport = false;
492 } 496 }
493 } 497 }
494 } 498 }
495 } else { // not allday 499 } else { // not allday
496 if ( tempItem->width() > 10 ) { 500 if ( tempItem->width() > 10 ) {
497 int minH = tempItem->width()/4; 501 int minH = tempItem->width()/4;
498 if ( minH > (blockmoveDist/2)-2 ) 502 if ( minH > (blockmoveDist/2)-2 )
499 minH = (blockmoveDist/2)-2; 503 minH = (blockmoveDist/2)-2;
500 bool border = false; 504 bool border = false;
501 int diff = tempItem->x() - viewportPos.x(); 505 int diff = tempItem->x() - viewportPos.x();
502 if ( diff < 0 ) 506 if ( diff < 0 )
503 diff *= -1; 507 diff *= -1;
504 if ( diff < minH ) { 508 if ( diff < minH ) {
505 border = true; 509 border = true;
506 objIsNotViewport = false; 510 objIsNotViewport = false;
507 } 511 }
508 if ( ! border ) { 512 if ( ! border ) {
509 diff = tempItem->x() + tempItem->width() - viewportPos.x(); 513 diff = tempItem->x() + tempItem->width() - viewportPos.x();
510 if ( diff < 0 ) 514 if ( diff < 0 )
511 diff *= -1; 515 diff *= -1;
512 if ( diff < minH ) { 516 if ( diff < minH ) {
513 border = true; 517 border = true;
514 objIsNotViewport = false; 518 objIsNotViewport = false;
515 } 519 }
516 } 520 }
517 } 521 }
518 } 522 }
519 } 523 }
520 if ( objIsNotViewport ) { 524 if ( objIsNotViewport ) {
521 mPopupItem = (KOAgendaItem *)object; 525 mPopupItem = (KOAgendaItem *)object;
522 mPopupKind = 1; 526 mPopupKind = 1;
523 if (me->button() == RightButton) { 527 if (me->button() == RightButton) {
524 mPopupKind = 3; 528 mPopupKind = 3;
525 popupMenu(); 529 popupMenu();
526 } else if (me->button() == LeftButton) { 530 } else if (me->button() == LeftButton) {
527 mActionItem = (KOAgendaItem *)object; 531 mActionItem = (KOAgendaItem *)object;
528 if (mActionItem) { 532 if (mActionItem) {
529 emit signalClearSelection(); 533 emit signalClearSelection();
530 slotClearSelection(); 534 slotClearSelection();
531 selectItem(mActionItem); 535 selectItem(mActionItem);
532 Incidence *incidence = mActionItem->incidence(); 536 Incidence *incidence = mActionItem->incidence();
533 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { 537 if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) {
534 mActionItem = 0; 538 mActionItem = 0;
535 } else { 539 } else {
536 startItemAction(viewportPos); 540 startItemAction(viewportPos);
537 } 541 }
538 } 542 }
539 } 543 }
540 } else { // ---------- viewport() 544 } else { // ---------- viewport()
541 mPopupItem = 0; 545 mPopupItem = 0;
542 mPopupKind = 2; 546 mPopupKind = 2;
543 selectItem(0); 547 selectItem(0);
544 mActionItem = 0; 548 mActionItem = 0;
545 if (me->button() == RightButton) { 549 if (me->button() == RightButton) {
546 int x,y; 550 int x,y;
547 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 551 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
548 int gx,gy; 552 int gx,gy;
549 contentsToGrid(x,y,gx,gy); 553 contentsToGrid(x,y,gx,gy);
550 mCurrentCellX = gx; 554 mCurrentCellX = gx;
551 mCurrentCellY = gy; 555 mCurrentCellY = gy;
552 mStartCellX = gx; 556 mStartCellX = gx;
553 mStartCellY = gy; 557 mStartCellY = gy;
554 mPopupKind = 4; 558 mPopupKind = 4;
555 popupMenu(); 559 popupMenu();
556 } else if (me->button() == LeftButton) { 560 } else if (me->button() == LeftButton) {
557 setCursor(arrowCursor); 561 setCursor(arrowCursor);
558 startSelectAction(viewportPos); 562 startSelectAction(viewportPos);
559 } 563 }
560 } 564 }
561 break; 565 break;
562 566
563 case QEvent::MouseButtonRelease: 567 case QEvent::MouseButtonRelease:
564 if (me->button() == LeftButton ) { 568 if (me->button() == LeftButton ) {
565 mPopupTimer->stop(); 569 mPopupTimer->stop();
566 } 570 }
567 if (object != viewport()) { 571 if (object != viewport()) {
568 if (me->button() == LeftButton && mLeftMouseDown) { 572 if (me->button() == LeftButton && mLeftMouseDown) {
569 if (mActionItem) { 573 if (mActionItem) {
570 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 574 QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos));
571 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); 575 //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 );
572 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { 576 if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) {
573 mScrollUpTimer.stop(); 577 mScrollUpTimer.stop();
574 mScrollDownTimer.stop(); 578 mScrollDownTimer.stop();
575 mActionItem->resetMove(); 579 mActionItem->resetMove();
576 placeSubCells( mActionItem ); 580 placeSubCells( mActionItem );
577 // emit startDragSignal( mActionItem->incidence() ); 581 // emit startDragSignal( mActionItem->incidence() );
578 setCursor( arrowCursor ); 582 setCursor( arrowCursor );
579 mActionItem = 0; 583 mActionItem = 0;
580 mActionType = NOP; 584 mActionType = NOP;
581 mItemMoved = 0; 585 mItemMoved = 0;
582 mLeftMouseDown = false; 586 mLeftMouseDown = false;
583 return true; 587 return true;
584 } 588 }
585 endItemAction(); 589 endItemAction();
586 } 590 }
587 } 591 }
588 592
589 } else { // ---------- viewport() 593 } else { // ---------- viewport()
590 if (me->button() == LeftButton && mLeftMouseDown ) { //left click 594 if (me->button() == LeftButton && mLeftMouseDown ) { //left click
591 endSelectAction( true ); // emit new event signal 595 endSelectAction( true ); // emit new event signal
592 } 596 }
593 } 597 }
594 if (me->button() == LeftButton) 598 if (me->button() == LeftButton)
595 mLeftMouseDown = false; 599 mLeftMouseDown = false;
596 600
597 break; 601 break;
598 602
599 case QEvent::MouseMove: 603 case QEvent::MouseMove:
600 //qDebug("mm "); 604 //qDebug("mm ");
601 if ( !mLeftMouseDown ) 605 if ( !mLeftMouseDown )
602 return false; 606 return false;
603 if ( blockMoving ) { 607 if ( blockMoving ) {
604 int dX, dY; 608 int dX, dY;
605 dX = startX - viewportPos.x(); 609 dX = startX - viewportPos.x();
606 if ( dX < 0 ) 610 if ( dX < 0 )
607 dX = -dX; 611 dX = -dX;
608 dY = viewportPos.y() - startY; 612 dY = viewportPos.y() - startY;
609 if ( dY < 0 ) 613 if ( dY < 0 )
610 dY = -dY; 614 dY = -dY;
611 //qDebug("%d %d %d ", dX, dY , blockmoveDist ); 615 //qDebug("%d %d %d ", dX, dY , blockmoveDist );
612 if ( dX > blockmoveDist || dY > blockmoveDist ) { 616 if ( dX > blockmoveDist || dY > blockmoveDist ) {
613 blockMoving = false; 617 blockMoving = false;
614 } 618 }
615 } 619 }
616 if ( ! blockMoving ) 620 if ( ! blockMoving )
617 mPopupTimer->stop(); 621 mPopupTimer->stop();
618 if (object != viewport()) { 622 if (object != viewport()) {
619 KOAgendaItem *moveItem = (KOAgendaItem *)object; 623 KOAgendaItem *moveItem = (KOAgendaItem *)object;
620 if (!moveItem->incidence()->isReadOnly() ) { 624 if (!moveItem->incidence()->isReadOnly() ) {
621 if (!mActionItem) 625 if (!mActionItem)
622 setNoActionCursor(moveItem,viewportPos); 626 setNoActionCursor(moveItem,viewportPos);
623 else { 627 else {
624 if ( !blockMoving ) 628 if ( !blockMoving )
625 performItemAction(viewportPos); 629 performItemAction(viewportPos);
626 } 630 }
627 } 631 }
628 } else { // ---------- viewport() 632 } else { // ---------- viewport()
629 mPopupPos = viewport()->mapToGlobal( me->pos() ); 633 mPopupPos = viewport()->mapToGlobal( me->pos() );
630 if ( mActionType == SELECT ) { 634 if ( mActionType == SELECT ) {
631 performSelectAction( viewportPos ); 635 performSelectAction( viewportPos );
632 } 636 }
633 } 637 }
634 break; 638 break;
635 639
636 case QEvent::MouseButtonDblClick: 640 case QEvent::MouseButtonDblClick:
637 mPopupTimer->stop(); 641 mPopupTimer->stop();
638 if (object == viewport()) { 642 if (object == viewport()) {
639 selectItem(0); 643 selectItem(0);
640 int x,y; 644 int x,y;
641 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 645 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
642 int gx,gy; 646 int gx,gy;
643 contentsToGrid(x,y,gx,gy); 647 contentsToGrid(x,y,gx,gy);
644 emit newEventSignal(gx,gy); 648 emit newEventSignal(gx,gy);
645 } else { 649 } else {
646 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; 650 KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object;
647 selectItem(doubleClickedItem); 651 selectItem(doubleClickedItem);
648 if ( KOPrefs::instance()->mEditOnDoubleClick ) 652 if ( KOPrefs::instance()->mEditOnDoubleClick )
649 emit editIncidenceSignal(doubleClickedItem->incidence()); 653 emit editIncidenceSignal(doubleClickedItem->incidence());
650 else 654 else
651 emit showIncidenceSignal(doubleClickedItem->incidence()); 655 emit showIncidenceSignal(doubleClickedItem->incidence());
652 } 656 }
653 break; 657 break;
654 658
655 default: 659 default:
656 break; 660 break;
657 } 661 }
658 return true; 662 return true;
659 663
660} 664}
661 665
662void KOAgenda::newItem( int item ) 666void KOAgenda::newItem( int item )
663{ 667{
664 if ( item == 1 ) { //new event 668 if ( item == 1 ) { //new event
665 newEventSignal(mStartCellX ,mStartCellY ); 669 newEventSignal(mStartCellX ,mStartCellY );
666 } else 670 } else
667 if ( item == 2 ) { //new event 671 if ( item == 2 ) { //new event
668 newTodoSignal(mStartCellX ,mStartCellY ); 672 newTodoSignal(mStartCellX ,mStartCellY );
669 } else 673 } else
670 { 674 {
671 emit showDateView( item, mStartCellX ); 675 emit showDateView( item, mStartCellX );
672 // 3Day view 676 // 3Day view
673 // 4Week view 677 // 4Week view
674 // 5Month view 678 // 5Month view
675 // 6Journal view 679 // 6Journal view
676 } 680 }
677} 681}
678void KOAgenda::slotClearSelection() 682void KOAgenda::slotClearSelection()
679{ 683{
680 if (mSelectionHeight) { 684 if (mSelectionHeight) {
681 int selectionX = mSelectionCellX * mGridSpacingX; 685 int selectionX = mSelectionCellX * mGridSpacingX;
682 int top = mSelectionYTop - 2 *mGridSpacingY; 686 int top = mSelectionYTop - 2 *mGridSpacingY;
683 int hei = mSelectionHeight + 4 *mGridSpacingY; 687 int hei = mSelectionHeight + 4 *mGridSpacingY;
684 clearSelection(); 688 clearSelection();
685 repaintContents( selectionX, top, 689 repaintContents( selectionX, top,
686 mGridSpacingX, hei ,false ); 690 mGridSpacingX, hei ,false );
687 } 691 }
688 692
689} 693}
690void KOAgenda::startSelectAction(QPoint viewportPos) 694void KOAgenda::startSelectAction(QPoint viewportPos)
691{ 695{
692 696
693 emit signalClearSelection(); 697 emit signalClearSelection();
694 slotClearSelection(); 698 slotClearSelection();
695 699
696 mActionType = SELECT; 700 mActionType = SELECT;
697 701
698 int x,y; 702 int x,y;
699 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 703 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
700 int gx,gy; 704 int gx,gy;
701 contentsToGrid(x,y,gx,gy); 705 contentsToGrid(x,y,gx,gy);
702 706
703 mStartCellX = gx; 707 mStartCellX = gx;
704 mStartCellY = gy; 708 mStartCellY = gy;
705 mCurrentCellX = gx; 709 mCurrentCellX = gx;
706 mCurrentCellY = gy; 710 mCurrentCellY = gy;
707 711
708 // Store new selection 712 // Store new selection
709 mSelectionCellX = gx; 713 mSelectionCellX = gx;
710 mSelectionYTop = gy * mGridSpacingY; 714 mSelectionYTop = gy * mGridSpacingY;
711 mSelectionHeight = mGridSpacingY; 715 mSelectionHeight = mGridSpacingY;
712 716
713 // Paint new selection 717 // Paint new selection
714 repaintContents( mSelectionCellX * mGridSpacingX+1, mSelectionYTop, 718 repaintContents( mSelectionCellX * mGridSpacingX+1, mSelectionYTop,
715 mGridSpacingX-1, mSelectionHeight ); 719 mGridSpacingX-1, mSelectionHeight );
716} 720}
717 721
718void KOAgenda::performSelectAction(QPoint viewportPos) 722void KOAgenda::performSelectAction(QPoint viewportPos)
719{ 723{
720 int x,y; 724 int x,y;
721 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 725 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
722 int gx,gy; 726 int gx,gy;
723 contentsToGrid(x,y,gx,gy); 727 contentsToGrid(x,y,gx,gy);
724 728
725 QPoint clipperPos = clipper()-> 729 QPoint clipperPos = clipper()->
726 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 730 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
727 731
728 // Scroll if cursor was moved to upper or lower end of agenda. 732 // Scroll if cursor was moved to upper or lower end of agenda.
729 if (clipperPos.y() < mScrollBorderWidth) { 733 if (clipperPos.y() < mScrollBorderWidth) {
730 mScrollUpTimer.start(mScrollDelay); 734 mScrollUpTimer.start(mScrollDelay);
731 } else if (visibleHeight() - clipperPos.y() < 735 } else if (visibleHeight() - clipperPos.y() <
732 mScrollBorderWidth) { 736 mScrollBorderWidth) {
733 mScrollDownTimer.start(mScrollDelay); 737 mScrollDownTimer.start(mScrollDelay);
734 } else { 738 } else {
735 mScrollUpTimer.stop(); 739 mScrollUpTimer.stop();
736 mScrollDownTimer.stop(); 740 mScrollDownTimer.stop();
737 } 741 }
738 742
739 if ( gy > mCurrentCellY ) { 743 if ( gy > mCurrentCellY ) {
740 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 744 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
741 745
742 746
743 repaintContents( (KOGlobals::self()->reverseLayout() ? 747 repaintContents( (KOGlobals::self()->reverseLayout() ?
744 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 748 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
745 mGridSpacingX, mSelectionYTop, 749 mGridSpacingX, mSelectionYTop,
746 mGridSpacingX, mSelectionHeight , false); 750 mGridSpacingX, mSelectionHeight , false);
747 751
748 mCurrentCellY = gy; 752 mCurrentCellY = gy;
749 } else if ( gy < mCurrentCellY ) { 753 } else if ( gy < mCurrentCellY ) {
750 if ( gy >= mStartCellY ) { 754 if ( gy >= mStartCellY ) {
751 int selectionHeight = mSelectionHeight; 755 int selectionHeight = mSelectionHeight;
752 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; 756 mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop;
753 757
754 repaintContents( (KOGlobals::self()->reverseLayout() ? 758 repaintContents( (KOGlobals::self()->reverseLayout() ?
755 mColumns - 1 - mSelectionCellX : mSelectionCellX) * 759 mColumns - 1 - mSelectionCellX : mSelectionCellX) *
756 mGridSpacingX, mSelectionYTop, 760 mGridSpacingX, mSelectionYTop,
757 mGridSpacingX, selectionHeight,false ); 761 mGridSpacingX, selectionHeight,false );
758 762
759 mCurrentCellY = gy; 763 mCurrentCellY = gy;
760 } else { 764 } else {
761 } 765 }
762 } 766 }
763} 767}
764 768
765void KOAgenda::endSelectAction( bool emitNewEvent ) 769void KOAgenda::endSelectAction( bool emitNewEvent )
766{ 770{
767 mActionType = NOP; 771 mActionType = NOP;
768 mScrollUpTimer.stop(); 772 mScrollUpTimer.stop();
769 mScrollDownTimer.stop(); 773 mScrollDownTimer.stop();
770 774
771 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 775 emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
772 if ( emitNewEvent && mStartCellY < mCurrentCellY ) { 776 if ( emitNewEvent && mStartCellY < mCurrentCellY ) {
773 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); 777 emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY);
774 } 778 }
775} 779}
776 780
777void KOAgenda::startItemAction(QPoint viewportPos) 781void KOAgenda::startItemAction(QPoint viewportPos)
778{ 782{
779 int x,y; 783 int x,y;
780 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 784 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
781 int gx,gy; 785 int gx,gy;
782 contentsToGrid(x,y,gx,gy); 786 contentsToGrid(x,y,gx,gy);
783 787
784 mStartCellX = gx; 788 mStartCellX = gx;
785 mStartCellY = gy; 789 mStartCellY = gy;
786 mCurrentCellX = gx; 790 mCurrentCellX = gx;
787 mCurrentCellY = gy; 791 mCurrentCellY = gy;
788 792
789 if (mAllDayMode) { 793 if (mAllDayMode) {
790 int gridDistanceX = (x - gx * mGridSpacingX); 794 int gridDistanceX = (x - gx * mGridSpacingX);
791 if (gridDistanceX < mResizeBorderWidth && 795 if (gridDistanceX < mResizeBorderWidth &&
792 mActionItem->cellX() == mCurrentCellX) { 796 mActionItem->cellX() == mCurrentCellX) {
793 mActionType = RESIZELEFT; 797 mActionType = RESIZELEFT;
794 setCursor(sizeHorCursor); 798 setCursor(sizeHorCursor);
795 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 799 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
796 mActionItem->cellXWidth() == mCurrentCellX) { 800 mActionItem->cellXWidth() == mCurrentCellX) {
797 mActionType = RESIZERIGHT; 801 mActionType = RESIZERIGHT;
798 setCursor(sizeHorCursor); 802 setCursor(sizeHorCursor);
799 } else { 803 } else {
800 mActionType = MOVE; 804 mActionType = MOVE;
801 mActionItem->startMove(); 805 mActionItem->startMove();
802 setCursor(sizeAllCursor); 806 setCursor(sizeAllCursor);
803 } 807 }
804 } else { 808 } else {
805 int gridDistanceY = (y - gy * mGridSpacingY); 809 int gridDistanceY = (y - gy * mGridSpacingY);
806 bool allowResize = ( mActionItem->incidence()->typeID() != todoID ); 810 bool allowResize = ( mActionItem->incidence()->typeID() != todoID );
807 if (allowResize && gridDistanceY < mResizeBorderWidth && 811 if (allowResize && gridDistanceY < mResizeBorderWidth &&
808 mActionItem->cellYTop() == mCurrentCellY && 812 mActionItem->cellYTop() == mCurrentCellY &&
809 !mActionItem->firstMultiItem()) { 813 !mActionItem->firstMultiItem()) {
810 mActionType = RESIZETOP; 814 mActionType = RESIZETOP;
811 setCursor(sizeVerCursor); 815 setCursor(sizeVerCursor);
812 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 816 } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
813 mActionItem->cellYBottom() == mCurrentCellY && 817 mActionItem->cellYBottom() == mCurrentCellY &&
814 !mActionItem->lastMultiItem()) { 818 !mActionItem->lastMultiItem()) {
815 mActionType = RESIZEBOTTOM; 819 mActionType = RESIZEBOTTOM;
816 setCursor(sizeVerCursor); 820 setCursor(sizeVerCursor);
817 } else { 821 } else {
818 mActionType = MOVE; 822 mActionType = MOVE;
819 mActionItem->startMove(); 823 mActionItem->startMove();
820 setCursor(sizeAllCursor); 824 setCursor(sizeAllCursor);
821 } 825 }
822 } 826 }
823} 827}
824 828
825void KOAgenda::performItemAction(QPoint viewportPos) 829void KOAgenda::performItemAction(QPoint viewportPos)
826{ 830{
827// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 831// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
828// QPoint point = viewport()->mapToGlobal(viewportPos); 832// QPoint point = viewport()->mapToGlobal(viewportPos);
829// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 833// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
830// point = clipper()->mapFromGlobal(point); 834// point = clipper()->mapFromGlobal(point);
831// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 835// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
832// kdDebug() << "visible height: " << visibleHeight() << endl; 836// kdDebug() << "visible height: " << visibleHeight() << endl;
833 int x,y; 837 int x,y;
834 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 838 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
835// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 839// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
836 int gx,gy; 840 int gx,gy;
837 contentsToGrid(x,y,gx,gy); 841 contentsToGrid(x,y,gx,gy);
838 QPoint clipperPos = clipper()-> 842 QPoint clipperPos = clipper()->
839 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 843 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
840 844
841 // Cursor left active agenda area. 845 // Cursor left active agenda area.
842 // This starts a drag. 846 // This starts a drag.
843 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ 847 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/
844 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { 848 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) {
845 if ( mActionType == MOVE ) { 849 if ( mActionType == MOVE ) {
846 mScrollUpTimer.stop(); 850 mScrollUpTimer.stop();
847 mScrollDownTimer.stop(); 851 mScrollDownTimer.stop();
848 mActionItem->resetMove(); 852 mActionItem->resetMove();
849 placeSubCells( mActionItem ); 853 placeSubCells( mActionItem );
850 // emit startDragSignal( mActionItem->incidence() ); 854 // emit startDragSignal( mActionItem->incidence() );
851 setCursor( arrowCursor ); 855 setCursor( arrowCursor );
852 mActionItem = 0; 856 mActionItem = 0;
853 mActionType = NOP; 857 mActionType = NOP;
854 mItemMoved = 0; 858 mItemMoved = 0;
855 return; 859 return;
856 } 860 }
857 } else { 861 } else {
858 switch ( mActionType ) { 862 switch ( mActionType ) {
859 case MOVE: 863 case MOVE:
860 setCursor( sizeAllCursor ); 864 setCursor( sizeAllCursor );
861 break; 865 break;
862 case RESIZETOP: 866 case RESIZETOP:
863 case RESIZEBOTTOM: 867 case RESIZEBOTTOM:
864 setCursor( sizeVerCursor ); 868 setCursor( sizeVerCursor );
865 break; 869 break;
866 case RESIZELEFT: 870 case RESIZELEFT:
867 case RESIZERIGHT: 871 case RESIZERIGHT:
868 setCursor( sizeHorCursor ); 872 setCursor( sizeHorCursor );
869 break; 873 break;
870 default: 874 default:
871 setCursor( arrowCursor ); 875 setCursor( arrowCursor );
872 } 876 }
873 } 877 }
874 878
875 // Scroll if item was moved to upper or lower end of agenda. 879 // Scroll if item was moved to upper or lower end of agenda.
876 if (clipperPos.y() < mScrollBorderWidth) { 880 if (clipperPos.y() < mScrollBorderWidth) {
877 mScrollUpTimer.start(mScrollDelay); 881 mScrollUpTimer.start(mScrollDelay);
878 } else if (visibleHeight() - clipperPos.y() < 882 } else if (visibleHeight() - clipperPos.y() <
879 mScrollBorderWidth) { 883 mScrollBorderWidth) {
880 mScrollDownTimer.start(mScrollDelay); 884 mScrollDownTimer.start(mScrollDelay);
881 } else { 885 } else {
882 mScrollUpTimer.stop(); 886 mScrollUpTimer.stop();
883 mScrollDownTimer.stop(); 887 mScrollDownTimer.stop();
884 } 888 }
885 889
886 // Move or resize item if necessary 890 // Move or resize item if necessary
887 if (mCurrentCellX != gx || mCurrentCellY != gy) { 891 if (mCurrentCellX != gx || mCurrentCellY != gy) {
888 mItemMoved = true; 892 mItemMoved = true;
889 mActionItem->raise(); 893 mActionItem->raise();
890 if (mActionType == MOVE) { 894 if (mActionType == MOVE) {
891 // Move all items belonging to a multi item 895 // Move all items belonging to a multi item
892 KOAgendaItem *moveItem = mActionItem->firstMultiItem(); 896 KOAgendaItem *moveItem = mActionItem->firstMultiItem();
893 bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); 897 bool isMultiItem = (moveItem || mActionItem->lastMultiItem());
894 if (!moveItem) moveItem = mActionItem; 898 if (!moveItem) moveItem = mActionItem;
895 while (moveItem) { 899 while (moveItem) {
896 int dy; 900 int dy;
897 if (isMultiItem) dy = 0; 901 if (isMultiItem) dy = 0;
898 else dy = gy - mCurrentCellY; 902 else dy = gy - mCurrentCellY;
899 moveItem->moveRelative(gx - mCurrentCellX,dy); 903 moveItem->moveRelative(gx - mCurrentCellX,dy);
900 int x,y; 904 int x,y;
901 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); 905 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y);
902 moveItem->resize(mGridSpacingX * moveItem->cellWidth(), 906 moveItem->resize(mGridSpacingX * moveItem->cellWidth(),
903 mGridSpacingY * moveItem->cellHeight()); 907 mGridSpacingY * moveItem->cellHeight());
904 moveChild(moveItem,x,y); 908 moveChild(moveItem,x,y);
905 moveItem = moveItem->nextMultiItem(); 909 moveItem = moveItem->nextMultiItem();
906 } 910 }
907 } else if (mActionType == RESIZETOP) { 911 } else if (mActionType == RESIZETOP) {
908 if (mCurrentCellY <= mActionItem->cellYBottom()) { 912 if (mCurrentCellY <= mActionItem->cellYBottom()) {
909 mActionItem->expandTop(gy - mCurrentCellY); 913 mActionItem->expandTop(gy - mCurrentCellY);
910 mActionItem->resize(mActionItem->width(), 914 mActionItem->resize(mActionItem->width(),
911 mGridSpacingY * mActionItem->cellHeight()); 915 mGridSpacingY * mActionItem->cellHeight());
912 int x,y; 916 int x,y;
913 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); 917 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y);
914 //moveChild(mActionItem,childX(mActionItem),y); 918 //moveChild(mActionItem,childX(mActionItem),y);
915 QScrollView::moveChild( mActionItem,childX(mActionItem),y ); 919 QScrollView::moveChild( mActionItem,childX(mActionItem),y );
916 } 920 }
917 } else if (mActionType == RESIZEBOTTOM) { 921 } else if (mActionType == RESIZEBOTTOM) {
918 if (mCurrentCellY >= mActionItem->cellYTop()) { 922 if (mCurrentCellY >= mActionItem->cellYTop()) {
919 mActionItem->expandBottom(gy - mCurrentCellY); 923 mActionItem->expandBottom(gy - mCurrentCellY);
920 mActionItem->resize(mActionItem->width(), 924 mActionItem->resize(mActionItem->width(),
921 mGridSpacingY * mActionItem->cellHeight()); 925 mGridSpacingY * mActionItem->cellHeight());
922 } 926 }
923 } else if (mActionType == RESIZELEFT) { 927 } else if (mActionType == RESIZELEFT) {
924 if (mCurrentCellX <= mActionItem->cellXWidth()) { 928 if (mCurrentCellX <= mActionItem->cellXWidth()) {
925 mActionItem->expandLeft(gx - mCurrentCellX); 929 mActionItem->expandLeft(gx - mCurrentCellX);
926 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 930 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
927 mActionItem->height()); 931 mActionItem->height());
928 int x,y; 932 int x,y;
929 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); 933 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y);
930 moveChild(mActionItem,x,childY(mActionItem)); 934 moveChild(mActionItem,x,childY(mActionItem));
931 } 935 }
932 } else if (mActionType == RESIZERIGHT) { 936 } else if (mActionType == RESIZERIGHT) {
933 if (mCurrentCellX >= mActionItem->cellX()) { 937 if (mCurrentCellX >= mActionItem->cellX()) {
934 mActionItem->expandRight(gx - mCurrentCellX); 938 mActionItem->expandRight(gx - mCurrentCellX);
935 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 939 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
936 mActionItem->height()); 940 mActionItem->height());
937 } 941 }
938 } 942 }
939 mCurrentCellX = gx; 943 mCurrentCellX = gx;
940 mCurrentCellY = gy; 944 mCurrentCellY = gy;
941 } 945 }
942} 946}
943 947
944void KOAgenda::endItemAction() 948void KOAgenda::endItemAction()
945{ 949{
946 950
947 if ( mItemMoved ) { 951 if ( mItemMoved ) {
948 KOAgendaItem *placeItem = mActionItem->firstMultiItem(); 952 KOAgendaItem *placeItem = mActionItem->firstMultiItem();
949 if ( !placeItem ) { 953 if ( !placeItem ) {
950 placeItem = mActionItem; 954 placeItem = mActionItem;
951 } 955 }
952 if ( placeItem->incidence()->recurrence()->doesRecur() ) { 956 if ( placeItem->incidence()->recurrence()->doesRecur() ) {
953 Incidence* oldInc = placeItem->incidence(); 957 Incidence* oldInc = placeItem->incidence();
954 placeItem->recreateIncidence(); 958 placeItem->recreateIncidence();
955 emit addToCalSignal(placeItem->incidence(), oldInc ); 959 emit addToCalSignal(placeItem->incidence(), oldInc );
956 } 960 }
957 int type = mActionType; 961 int type = mActionType;
958 if ( mAllDayMode ) 962 if ( mAllDayMode )
959 type = -1; 963 type = -1;
960 KOAgendaItem *modifiedItem = placeItem; 964 KOAgendaItem *modifiedItem = placeItem;
961 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); 965 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */);
962 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); 966 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems();
963 KOAgendaItem *item; 967 KOAgendaItem *item;
964 968
965 if ( placeItem->incidence()->typeID() == todoID ) { 969 if ( placeItem->incidence()->typeID() == todoID ) {
966 mSelectedItem = 0; 970 mSelectedItem = 0;
967 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); 971 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth());
968 modifiedItem->mLastMoveXPos = mCurrentCellX; 972 modifiedItem->mLastMoveXPos = mCurrentCellX;
969 emit itemModified( modifiedItem, mActionType ); 973 emit itemModified( modifiedItem, mActionType );
970 } 974 }
971 else { 975 else {
972 976
973 977
974 globalFlagBlockAgendaItemPaint = 1; 978 globalFlagBlockAgendaItemPaint = 1;
975 for ( item=oldconflictItems.first(); item != 0; 979 for ( item=oldconflictItems.first(); item != 0;
976 item=oldconflictItems.next() ) { 980 item=oldconflictItems.next() ) {
977 placeSubCells(item); 981 placeSubCells(item);
978 } 982 }
979 while ( placeItem ) { 983 while ( placeItem ) {
980 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 984 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
981 oldconflictItems = placeItem->conflictItems(); 985 oldconflictItems = placeItem->conflictItems();
982 for ( item=oldconflictItems.first(); item != 0; 986 for ( item=oldconflictItems.first(); item != 0;
983 item=oldconflictItems.next() ) { 987 item=oldconflictItems.next() ) {
984 placeSubCells(item); 988 placeSubCells(item);
985 } 989 }
986 placeSubCells( placeItem ); 990 placeSubCells( placeItem );
987 placeItem = placeItem->nextMultiItem(); 991 placeItem = placeItem->nextMultiItem();
988 } 992 }
989 globalFlagBlockAgendaItemPaint = 0; 993 globalFlagBlockAgendaItemPaint = 0;
990 for ( item=oldconflictItems.first(); item != 0; 994 for ( item=oldconflictItems.first(); item != 0;
991 item=oldconflictItems.next() ) { 995 item=oldconflictItems.next() ) {
992 globalFlagBlockAgendaItemUpdate = 0; 996 globalFlagBlockAgendaItemUpdate = 0;
993 item->repaintMe(); 997 item->repaintMe();
994 globalFlagBlockAgendaItemUpdate = 1; 998 globalFlagBlockAgendaItemUpdate = 1;
995 item->repaint( false ); 999 item->repaint( false );
996 } 1000 }
997 placeItem = modifiedItem; 1001 placeItem = modifiedItem;
998 1002
999 while ( placeItem ) { 1003 while ( placeItem ) {
1000 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1004 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
1001 globalFlagBlockAgendaItemUpdate = 0; 1005 globalFlagBlockAgendaItemUpdate = 0;
1002 placeItem->repaintMe(); 1006 placeItem->repaintMe();
1003 globalFlagBlockAgendaItemUpdate = 1; 1007 globalFlagBlockAgendaItemUpdate = 1;
1004 placeItem->repaint(false); 1008 placeItem->repaint(false);
1005 placeItem = placeItem->nextMultiItem(); 1009 placeItem = placeItem->nextMultiItem();
1006 } 1010 }
1007 emit itemModified( modifiedItem, mActionType ); 1011 emit itemModified( modifiedItem, mActionType );
1008 1012
1009 1013
1010 placeItem = modifiedItem; 1014 placeItem = modifiedItem;
1011 while ( placeItem ) { 1015 while ( placeItem ) {
1012 oldconflictItems = placeItem->conflictItems(); 1016 oldconflictItems = placeItem->conflictItems();
1013 for ( item=oldconflictItems.first(); item != 0; 1017 for ( item=oldconflictItems.first(); item != 0;
1014 item=oldconflictItems.next() ) { 1018 item=oldconflictItems.next() ) {
1015 placeSubCells(item); 1019 placeSubCells(item);
1016 } 1020 }
1017 placeSubCells( placeItem ); 1021 placeSubCells( placeItem );
1018 placeItem = placeItem->nextMultiItem(); 1022 placeItem = placeItem->nextMultiItem();
1019 1023
1020 } 1024 }
1021 placeItem = modifiedItem; 1025 placeItem = modifiedItem;
1022 while ( placeItem ) { 1026 while ( placeItem ) {
1023 oldconflictItems = placeItem->conflictItems(); 1027 oldconflictItems = placeItem->conflictItems();
1024 for ( item=oldconflictItems.first(); item != 0; 1028 for ( item=oldconflictItems.first(); item != 0;
1025 item=oldconflictItems.next() ) { 1029 item=oldconflictItems.next() ) {
1026 globalFlagBlockAgendaItemUpdate = 0; 1030 globalFlagBlockAgendaItemUpdate = 0;
1027 item->repaintMe(); 1031 item->repaintMe();
1028 globalFlagBlockAgendaItemUpdate = 1; 1032 globalFlagBlockAgendaItemUpdate = 1;
1029 item->repaint(false); 1033 item->repaint(false);
1030 } 1034 }
1031 placeItem = placeItem->nextMultiItem(); 1035 placeItem = placeItem->nextMultiItem();
1032 } 1036 }
1033 /* 1037 /*
1034 1038
1035 oldconflictItems = modifiedItem->conflictItems(); 1039 oldconflictItems = modifiedItem->conflictItems();
1036 for ( item=oldconflictItems.first(); item != 0; 1040 for ( item=oldconflictItems.first(); item != 0;
1037 item=oldconflictItems.next() ) { 1041 item=oldconflictItems.next() ) {
1038 globalFlagBlockAgendaItemUpdate = 0; 1042 globalFlagBlockAgendaItemUpdate = 0;
1039 item->paintMe(false); 1043 item->paintMe(false);
1040 globalFlagBlockAgendaItemUpdate = 1; 1044 globalFlagBlockAgendaItemUpdate = 1;
1041 item->repaint(false); 1045 item->repaint(false);
1042 } 1046 }
1043 */ 1047 */
1044 1048
1045 1049
1046 } 1050 }
1047 1051
1048 } 1052 }
1049 1053
1050 mScrollUpTimer.stop(); 1054 mScrollUpTimer.stop();
1051 mScrollDownTimer.stop(); 1055 mScrollDownTimer.stop();
1052 setCursor( arrowCursor ); 1056 setCursor( arrowCursor );
1053 mActionItem = 0; 1057 mActionItem = 0;
1054 mActionType = NOP; 1058 mActionType = NOP;
1055 mItemMoved = 0; 1059 mItemMoved = 0;
1056 1060
1057} 1061}
1058 1062
1059void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) 1063void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos)
1060{ 1064{
1061// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 1065// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
1062// QPoint point = viewport()->mapToGlobal(viewportPos); 1066// QPoint point = viewport()->mapToGlobal(viewportPos);
1063// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 1067// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
1064// point = clipper()->mapFromGlobal(point); 1068// point = clipper()->mapFromGlobal(point);
1065// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 1069// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
1066 1070
1067 int x,y; 1071 int x,y;
1068 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 1072 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
1069// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 1073// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
1070 int gx,gy; 1074 int gx,gy;
1071 contentsToGrid(x,y,gx,gy); 1075 contentsToGrid(x,y,gx,gy);
1072 1076
1073 // Change cursor to resize cursor if appropriate 1077 // Change cursor to resize cursor if appropriate
1074 if (mAllDayMode) { 1078 if (mAllDayMode) {
1075 int gridDistanceX = (x - gx * mGridSpacingX); 1079 int gridDistanceX = (x - gx * mGridSpacingX);
1076 if (gridDistanceX < mResizeBorderWidth && 1080 if (gridDistanceX < mResizeBorderWidth &&
1077 moveItem->cellX() == gx) { 1081 moveItem->cellX() == gx) {
1078 setCursor(sizeHorCursor); 1082 setCursor(sizeHorCursor);
1079 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 1083 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
1080 moveItem->cellXWidth() == gx) { 1084 moveItem->cellXWidth() == gx) {
1081 setCursor(sizeHorCursor); 1085 setCursor(sizeHorCursor);
1082 } else { 1086 } else {
1083 setCursor(arrowCursor); 1087 setCursor(arrowCursor);
1084 } 1088 }
1085 } else { 1089 } else {
1086 int gridDistanceY = (y - gy * mGridSpacingY); 1090 int gridDistanceY = (y - gy * mGridSpacingY);
1087 if (gridDistanceY < mResizeBorderWidth && 1091 if (gridDistanceY < mResizeBorderWidth &&
1088 moveItem->cellYTop() == gy && 1092 moveItem->cellYTop() == gy &&
1089 !moveItem->firstMultiItem()) { 1093 !moveItem->firstMultiItem()) {
1090 setCursor(sizeVerCursor); 1094 setCursor(sizeVerCursor);
1091 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 1095 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
1092 moveItem->cellYBottom() == gy && 1096 moveItem->cellYBottom() == gy &&
1093 !moveItem->lastMultiItem()) { 1097 !moveItem->lastMultiItem()) {
1094 setCursor(sizeVerCursor); 1098 setCursor(sizeVerCursor);
1095 } else { 1099 } else {
1096 setCursor(arrowCursor); 1100 setCursor(arrowCursor);
1097 } 1101 }
1098 } 1102 }
1099} 1103}
1100 1104
1101 1105
1102/* 1106/*
1103 Place item in cell and take care that multiple items using the same cell do 1107 Place item in cell and take care that multiple items using the same cell do
1104 not overlap. This method is not yet optimal. It doesn´t use the maximum space 1108 not overlap. This method is not yet optimal. It doesn´t use the maximum space
1105 it can get in all cases. 1109 it can get in all cases.
1106 At the moment the method has a bug: When an item is placed only the sub cell 1110 At the moment the method has a bug: When an item is placed only the sub cell
1107 widths of the items are changed, which are within the Y region the item to 1111 widths of the items are changed, which are within the Y region the item to
1108 place spans. When the sub cell width change of one of this items affects a 1112 place spans. When the sub cell width change of one of this items affects a
1109 cell, where other items are, which do not overlap in Y with the item to place, 1113 cell, where other items are, which do not overlap in Y with the item to place,
1110 the display gets corrupted, although the corruption looks quite nice. 1114 the display gets corrupted, although the corruption looks quite nice.
1111*/ 1115*/
1112void KOAgenda::placeSubCells(KOAgendaItem *placeItem) 1116void KOAgenda::placeSubCells(KOAgendaItem *placeItem)
1113{ 1117{
1114 1118
1115 QPtrList<KOAgendaItem> conflictItems; 1119 QPtrList<KOAgendaItem> conflictItems;
1116 int maxSubCells = 0; 1120 int maxSubCells = 0;
1117 QIntDict<KOAgendaItem> subCellDict(5); 1121 QIntDict<KOAgendaItem> subCellDict(5);
1118 1122
1119 KOAgendaItem *item; 1123 KOAgendaItem *item;
1120 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1124 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1121 if (item != placeItem) { 1125 if (item != placeItem) {
1122 if (placeItem->cellX() <= item->cellXWidth() && 1126 if (placeItem->cellX() <= item->cellXWidth() &&
1123 placeItem->cellXWidth() >= item->cellX()) { 1127 placeItem->cellXWidth() >= item->cellX()) {
1124 if ((placeItem->cellYTop() <= item->cellYBottom()) && 1128 if ((placeItem->cellYTop() <= item->cellYBottom()) &&
1125 (placeItem->cellYBottom() >= item->cellYTop())) { 1129 (placeItem->cellYBottom() >= item->cellYTop())) {
1126 conflictItems.append(item); 1130 conflictItems.append(item);
1127 if (item->subCells() > maxSubCells) 1131 if (item->subCells() > maxSubCells)
1128 maxSubCells = item->subCells(); 1132 maxSubCells = item->subCells();
1129 subCellDict.insert(item->subCell(),item); 1133 subCellDict.insert(item->subCell(),item);
1130 } 1134 }
1131 } 1135 }
1132 } 1136 }
1133 } 1137 }
1134 1138
1135 if (conflictItems.count() > 0) { 1139 if (conflictItems.count() > 0) {
1136 // Look for unused sub cell and insert item 1140 // Look for unused sub cell and insert item
1137 int i; 1141 int i;
1138 for(i=0;i<maxSubCells;++i) { 1142 for(i=0;i<maxSubCells;++i) {
1139 if (!subCellDict.find(i)) { 1143 if (!subCellDict.find(i)) {
1140 placeItem->setSubCell(i); 1144 placeItem->setSubCell(i);
1141 break; 1145 break;
1142 } 1146 }
1143 } 1147 }
1144 if (i == maxSubCells) { 1148 if (i == maxSubCells) {
1145 placeItem->setSubCell(maxSubCells); 1149 placeItem->setSubCell(maxSubCells);
1146 maxSubCells++; // add new item to number of sub cells 1150 maxSubCells++; // add new item to number of sub cells
1147 } 1151 }
1148 1152
1149 // Prepare for sub cell geometry adjustment 1153 // Prepare for sub cell geometry adjustment
1150 int newSubCellWidth; 1154 int newSubCellWidth;
1151 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; 1155 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells;
1152 else newSubCellWidth = mGridSpacingX / maxSubCells; 1156 else newSubCellWidth = mGridSpacingX / maxSubCells;
1153 conflictItems.append(placeItem); 1157 conflictItems.append(placeItem);
1154 1158
1155 1159
1156 // Adjust sub cell geometry of all direct conflict items 1160 // Adjust sub cell geometry of all direct conflict items
1157 for ( item=conflictItems.first(); item != 0; 1161 for ( item=conflictItems.first(); item != 0;
1158 item=conflictItems.next() ) { 1162 item=conflictItems.next() ) {
1159 item->setSubCells(maxSubCells); 1163 item->setSubCells(maxSubCells);
1160 if (mAllDayMode) { 1164 if (mAllDayMode) {
1161 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1165 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1162 } else { 1166 } else {
1163 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1167 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1164 } 1168 }
1165 int x,y; 1169 int x,y;
1166 gridToContents(item->cellX(),item->cellYTop(),x,y); 1170 gridToContents(item->cellX(),item->cellYTop(),x,y);
1167 if (mAllDayMode) { 1171 if (mAllDayMode) {
1168 y += item->subCell() * newSubCellWidth; 1172 y += item->subCell() * newSubCellWidth;
1169 } else { 1173 } else {
1170 x += item->subCell() * newSubCellWidth; 1174 x += item->subCell() * newSubCellWidth;
1171 } 1175 }
1172 moveChild(item,x,y); 1176 moveChild(item,x,y);
1173 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); 1177 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y);
1174 //item->updateItem(); 1178 //item->updateItem();
1175 } 1179 }
1176 // Adjust sub cell geometry of all conflict items of all conflict items 1180 // Adjust sub cell geometry of all conflict items of all conflict items
1177 for ( item=conflictItems.first(); item != 0; 1181 for ( item=conflictItems.first(); item != 0;
1178 item=conflictItems.next() ) { 1182 item=conflictItems.next() ) {
1179 if ( placeItem != item ) { 1183 if ( placeItem != item ) {
1180 KOAgendaItem *item2; 1184 KOAgendaItem *item2;
1181 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems(); 1185 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems();
1182 for ( item2=conflictItems2.first(); item2 != 0; 1186 for ( item2=conflictItems2.first(); item2 != 0;
1183 item2=conflictItems2.next() ) { 1187 item2=conflictItems2.next() ) {
1184 if ( item2->subCells() != maxSubCells) { 1188 if ( item2->subCells() != maxSubCells) {
1185 item2->setSubCells(maxSubCells); 1189 item2->setSubCells(maxSubCells);
1186 if (mAllDayMode) { 1190 if (mAllDayMode) {
1187 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth); 1191 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth);
1188 } else { 1192 } else {
1189 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY); 1193 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY);
1190 } 1194 }
1191 int x,y; 1195 int x,y;
1192 gridToContents(item2->cellX(),item2->cellYTop(),x,y); 1196 gridToContents(item2->cellX(),item2->cellYTop(),x,y);
1193 if (mAllDayMode) { 1197 if (mAllDayMode) {
1194 y += item2->subCell() * newSubCellWidth; 1198 y += item2->subCell() * newSubCellWidth;
1195 } else { 1199 } else {
1196 x += item2->subCell() * newSubCellWidth; 1200 x += item2->subCell() * newSubCellWidth;
1197 } 1201 }
1198 moveChild(item2,x,y); 1202 moveChild(item2,x,y);
1199 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() ); 1203 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() );
1200 } 1204 }
1201 } 1205 }
1202 } 1206 }
1203 } 1207 }
1204 } else { 1208 } else {
1205 placeItem->setSubCell(0); 1209 placeItem->setSubCell(0);
1206 placeItem->setSubCells(1); 1210 placeItem->setSubCells(1);
1207 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); 1211 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY);
1208 else placeItem->resize(mGridSpacingX,placeItem->height()); 1212 else placeItem->resize(mGridSpacingX,placeItem->height());
1209 int x,y; 1213 int x,y;
1210 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); 1214 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y);
1211 moveChild(placeItem,x,y); 1215 moveChild(placeItem,x,y);
1212 } 1216 }
1213 placeItem->setConflictItems(conflictItems); 1217 placeItem->setConflictItems(conflictItems);
1214 // for ( item=conflictItems.first(); item != 0; 1218 // for ( item=conflictItems.first(); item != 0;
1215// item=conflictItems.next() ) { 1219// item=conflictItems.next() ) {
1216// //item->updateItem(); 1220// //item->updateItem();
1217// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); 1221// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() );
1218// } 1222// }
1219// placeItem->updateItem(); 1223// placeItem->updateItem();
1220} 1224}
1221 1225
1222void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) 1226void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
1223{ 1227{
1224 if ( globalFlagBlockAgenda ) 1228 if ( globalFlagBlockAgenda )
1225 return; 1229 return;
1226 if ( ! mAllDayMode ) { 1230 if ( ! mAllDayMode ) {
1227 // currently not working for 1231 // currently not working for
1228 1232
1229 //qDebug("KOAgenda::drawContents "); 1233 //qDebug("KOAgenda::drawContents ");
1230 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) 1234 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() )
1231 ;//drawContentsToPainter(); 1235 ;//drawContentsToPainter();
1232 1236
1233 QPaintDevice* pd = p->device(); 1237 QPaintDevice* pd = p->device();
1234 p->end(); 1238 p->end();
1235 int vx, vy; 1239 int vx, vy;
1236 int selectionX = KOGlobals::self()->reverseLayout() ? 1240 int selectionX = KOGlobals::self()->reverseLayout() ?
1237 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1241 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1238 mSelectionCellX * mGridSpacingX; 1242 mSelectionCellX * mGridSpacingX;