summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebookday.cpp52
-rw-r--r--core/pim/datebook/datebookday.h31
-rw-r--r--core/pim/datebook/datebookweek.cpp52
-rw-r--r--core/pim/datebook/datebookweek.h16
-rw-r--r--core/pim/datebook/datebookweeklst.cpp5
5 files changed, 107 insertions, 49 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp
index 9cc5fcd..5474cfc 100644
--- a/core/pim/datebook/datebookday.cpp
+++ b/core/pim/datebook/datebookday.cpp
@@ -57,728 +57,740 @@ DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent,
57 // get rid of being able to edit things... 57 // get rid of being able to edit things...
58 QTableItem *tmp; 58 QTableItem *tmp;
59 int row; 59 int row;
60 for ( row = 0; row < numRows(); row++ ) { 60 for ( row = 0; row < numRows(); row++ ) {
61 tmp = new QTableItem( this, QTableItem::Never, QString::null); 61 tmp = new QTableItem( this, QTableItem::Never, QString::null);
62 setItem( row, 0, tmp ); 62 setItem( row, 0, tmp );
63 //setRowHeight( row, 40); 63 //setRowHeight( row, 40);
64 } 64 }
65 initHeader(); 65 initHeader();
66 QObject::connect( qApp, SIGNAL(clockChanged(bool)), 66 QObject::connect( qApp, SIGNAL(clockChanged(bool)),
67 this, SLOT(slotChangeClock(bool)) ); 67 this, SLOT(slotChangeClock(bool)) );
68} 68}
69 69
70void DateBookDayView::initHeader() 70void DateBookDayView::initHeader()
71{ 71{
72 QString strTmp; 72 QString strTmp;
73 for ( int i = 0; i < 24; ++i ) { 73 for ( int i = 0; i < 24; ++i ) {
74 if ( ampm ) { 74 if ( ampm ) {
75 if ( i == 0 ) 75 if ( i == 0 )
76 strTmp = QString::number(12) + ":00"; 76 strTmp = QString::number(12) + ":00";
77 else if ( i == 12 ) 77 else if ( i == 12 )
78 strTmp = QString::number(12) + tr(":00p"); 78 strTmp = QString::number(12) + tr(":00p");
79 else if ( i > 12 ) 79 else if ( i > 12 )
80 strTmp = QString::number( i - 12 ) + tr(":00p"); 80 strTmp = QString::number( i - 12 ) + tr(":00p");
81 else 81 else
82 strTmp = QString::number(i) + ":00"; 82 strTmp = QString::number(i) + ":00";
83 } else { 83 } else {
84 if ( i < 10 ) 84 if ( i < 10 )
85 strTmp = "0" + QString::number(i) + ":00"; 85 strTmp = "0" + QString::number(i) + ":00";
86 else 86 else
87 strTmp = QString::number(i) + ":00"; 87 strTmp = QString::number(i) + ":00";
88 } 88 }
89 strTmp = strTmp.rightJustify( 6, ' ' ); 89 strTmp = strTmp.rightJustify( 6, ' ' );
90 verticalHeader()->setLabel( i, strTmp ); 90 verticalHeader()->setLabel( i, strTmp );
91 setRowStretchable( i, FALSE ); 91 setRowStretchable( i, FALSE );
92 } 92 }
93} 93}
94 94
95void DateBookDayView::slotChangeClock( bool newClock ) 95void DateBookDayView::slotChangeClock( bool newClock )
96{ 96{
97 ampm = newClock; 97 ampm = newClock;
98 initHeader(); 98 initHeader();
99} 99}
100 100
101bool DateBookDayView::whichClock() const 101bool DateBookDayView::whichClock() const
102{ 102{
103 return ampm; 103 return ampm;
104} 104}
105 105
106void DateBookDayView::moveUp() 106void DateBookDayView::moveUp()
107{ 107{
108 scrollBy(0, -20); 108 scrollBy(0, -20);
109} 109}
110 110
111void DateBookDayView::moveDown() 111void DateBookDayView::moveDown()
112{ 112{
113 scrollBy(0, 20); 113 scrollBy(0, 20);
114} 114}
115 115
116void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) 116void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool )
117{ 117{
118 int w = cr.width(); 118 int w = cr.width();
119 int h = cr.height(); 119 int h = cr.height();
120 p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); 120 p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) );
121 if ( showGrid() ) { 121 if ( showGrid() ) {
122 // Draw our lines 122 // Draw our lines
123 int x2 = w - 1; 123 int x2 = w - 1;
124 int y2 = h - 1; 124 int y2 = h - 1;
125 QPen pen( p->pen() ); 125 QPen pen( p->pen() );
126 p->setPen( colorGroup().dark() ); 126 p->setPen( colorGroup().dark() );
127 p->drawLine( x2, 0, x2, y2 ); 127 p->drawLine( x2, 0, x2, y2 );
128 p->drawLine( 0, y2, x2, y2 ); 128 p->drawLine( 0, y2, x2, y2 );
129 129
130 p->setPen( colorGroup().midlight() ); 130 p->setPen( colorGroup().midlight() );
131 p->drawLine( 0, y2 - h/2, x2, y2 - h/2); 131 p->drawLine( 0, y2 - h/2, x2, y2 - h/2);
132 132
133 p->setPen( pen ); 133 p->setPen( pen );
134 } 134 }
135} 135}
136 136
137void DateBookDayView::paintFocus( QPainter *, const QRect & ) 137void DateBookDayView::paintFocus( QPainter *, const QRect & )
138{ 138{
139} 139}
140 140
141 141
142void DateBookDayView::resizeEvent( QResizeEvent *e ) 142void DateBookDayView::resizeEvent( QResizeEvent *e )
143{ 143{
144 QTable::resizeEvent( e ); 144 QTable::resizeEvent( e );
145 columnWidthChanged( 0 ); 145 columnWidthChanged( 0 );
146 emit sigColWidthChanged(); 146 emit sigColWidthChanged();
147} 147}
148 148
149void DateBookDayView::keyPressEvent( QKeyEvent *e ) 149void DateBookDayView::keyPressEvent( QKeyEvent *e )
150{ 150{
151 QString txt = e->text(); 151 QString txt = e->text();
152 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { 152 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) {
153 // we this is some sort of thing we know about... 153 // we this is some sort of thing we know about...
154 e->accept(); 154 e->accept();
155 emit sigCapturedKey( txt ); 155 emit sigCapturedKey( txt );
156 } else { 156 } else {
157 // I don't know what this key is, do you? 157 // I don't know what this key is, do you?
158 e->ignore(); 158 e->ignore();
159 } 159 }
160} 160}
161 161
162void DateBookDayView::setRowStyle( int style ) 162void DateBookDayView::setRowStyle( int style )
163{ 163{
164 if (style<0) style = 0; 164 if (style<0) style = 0;
165 165
166 for (int i=0; i<numRows(); i++) 166 for (int i=0; i<numRows(); i++)
167 setRowHeight(i, style*10+20); 167 setRowHeight(i, style*10+20);
168} 168}
169 169
170//=========================================================================== 170//===========================================================================
171 171
172DateBookDay::DateBookDay( bool ampm, bool startOnMonday, 172DateBookDay::DateBookDay( bool ampm, bool startOnMonday,
173 DateBookDB *newDb, QWidget *parent, 173 DateBookDB *newDb, QWidget *parent,
174 const char *name ) 174 const char *name )
175 : QVBox( parent, name ), 175 : QVBox( parent, name ),
176 currDate( QDate::currentDate() ), 176 currDate( QDate::currentDate() ),
177 db( newDb ), 177 db( newDb ),
178 startTime( 0 ) 178 startTime( 0 )
179{ 179{
180 widgetList.setAutoDelete( true ); 180 widgetList.setAutoDelete( true );
181 header = new DateBookDayHeader( startOnMonday, this, "day header" ); 181 header = new DateBookDayHeader( startOnMonday, this, "day header" );
182 header->setDate( currDate.year(), currDate.month(), currDate.day() ); 182 header->setDate( currDate.year(), currDate.month(), currDate.day() );
183 view = new DateBookDayView( ampm, this, "day view" ); 183 view = new DateBookDayView( ampm, this, "day view" );
184 184
185 connect( header, SIGNAL( dateChanged( int, int, int ) ), 185 connect( header, SIGNAL( dateChanged( int, int, int ) ),
186 this, SLOT( dateChanged( int, int, int ) ) ); 186 this, SLOT( dateChanged( int, int, int ) ) );
187 connect( view, SIGNAL( sigColWidthChanged() ), 187 connect( view, SIGNAL( sigColWidthChanged() ),
188 this, SLOT( slotColWidthChanged() ) ); 188 this, SLOT( slotColWidthChanged() ) );
189 connect( qApp, SIGNAL(weekChanged(bool)), 189 connect( qApp, SIGNAL(weekChanged(bool)),
190 this, SLOT(slotWeekChanged(bool)) ); 190 this, SLOT(slotWeekChanged(bool)) );
191 connect( view, SIGNAL(sigCapturedKey(const QString &)), 191 connect( view, SIGNAL(sigCapturedKey(const QString &)),
192 this, SIGNAL(sigNewEvent(const QString&)) ); 192 this, SIGNAL(sigNewEvent(const QString&)) );
193 193
194 QTimer *timer = new QTimer( this ); 194 QTimer *timer = new QTimer( this );
195 195
196 connect( timer, SIGNAL(timeout()), 196 connect( timer, SIGNAL(timeout()),
197 this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors 197 this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors
198 timer->start( 1000*60*5, FALSE ); //update every 5min 198 timer->start( 1000*60*5, FALSE ); //update every 5min
199 199
200 selectedWidget = 0; 200 selectedWidget = 0;
201 201
202 timeMarker = new DateBookDayTimeMarker( this ); 202 timeMarker = new DateBookDayTimeMarker( this );
203 timeMarker->setTime( QTime::currentTime() ); 203 timeMarker->setTime( QTime::currentTime() );
204 rowStyle = -1; // initialize with bogus values 204 rowStyle = -1; // initialize with bogus values
205} 205}
206 206
207void DateBookDay::setJumpToCurTime( bool bJump ) 207void DateBookDay::setJumpToCurTime( bool bJump )
208{ 208{
209 jumpToCurTime = bJump; 209 jumpToCurTime = bJump;
210} 210}
211 211
212void DateBookDay::setRowStyle( int style ) 212void DateBookDay::setRowStyle( int style )
213{ 213{
214 if (rowStyle != style) view->setRowStyle( style ); 214 if (rowStyle != style) view->setRowStyle( style );
215 rowStyle = style; 215 rowStyle = style;
216} 216}
217 217
218void DateBookDay::updateView( void ) 218void DateBookDay::updateView( void )
219{ 219{
220 timeMarker->setTime( QTime::currentTime() ); 220 timeMarker->setTime( QTime::currentTime() );
221 //need to find a way to update all DateBookDayWidgets 221 //need to find a way to update all DateBookDayWidgets
222} 222}
223 223
224void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) 224void DateBookDay::setSelectedWidget( DateBookDayWidget *w )
225{ 225{
226 selectedWidget = w; 226 selectedWidget = w;
227} 227}
228 228
229DateBookDayWidget * DateBookDay::getSelectedWidget( void ) 229DateBookDayWidget * DateBookDay::getSelectedWidget( void )
230{ 230{
231 return selectedWidget; 231 return selectedWidget;
232} 232}
233 233
234void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) 234void DateBookDay::selectedDates( QDateTime &start, QDateTime &end )
235{ 235{
236 start.setDate( currDate ); 236 start.setDate( currDate );
237 end.setDate( currDate ); 237 end.setDate( currDate );
238 238
239 int sh=99,eh=-1; 239 int sh=99,eh=-1;
240 240
241 int n = dayView()->numSelections(); 241 int n = dayView()->numSelections();
242 242
243 for (int i=0; i<n; i++) { 243 for (int i=0; i<n; i++) {
244 QTableSelection sel = dayView()->selection( i ); 244 QTableSelection sel = dayView()->selection( i );
245 sh = QMIN(sh,sel.topRow()); 245 sh = QMIN(sh,sel.topRow());
246 eh = QMAX(sh,sel.bottomRow()+1); 246 eh = QMAX(sh,sel.bottomRow()+1);
247 } 247 }
248 if (sh > 23 || eh < 1) { 248 if (sh > 23 || eh < 1) {
249 sh=8; 249 sh=8;
250 eh=9; 250 eh=9;
251 } 251 }
252 252
253 start.setTime( QTime( sh, 0, 0 ) ); 253 start.setTime( QTime( sh, 0, 0 ) );
254 end.setTime( QTime( eh, 0, 0 ) ); 254 end.setTime( QTime( eh, 0, 0 ) );
255} 255}
256 256
257void DateBookDay::setDate( int y, int m, int d ) 257void DateBookDay::setDate( int y, int m, int d )
258{ 258{
259 header->setDate( y, m, d ); 259 header->setDate( y, m, d );
260 260
261 selectedWidget = 0; 261 selectedWidget = 0;
262} 262}
263 263
264void DateBookDay::setDate( QDate d) 264void DateBookDay::setDate( QDate d)
265{ 265{
266 header->setDate( d.year(), d.month(), d.day() ); 266 header->setDate( d.year(), d.month(), d.day() );
267 267
268 selectedWidget = 0; 268 selectedWidget = 0;
269} 269}
270 270
271void DateBookDay::dateChanged( int y, int m, int d ) 271void DateBookDay::dateChanged( int y, int m, int d )
272{ 272{
273 QDate date( y, m, d ); 273 QDate date( y, m, d );
274 if ( currDate == date ) 274 if ( currDate == date )
275 return; 275 return;
276 currDate.setYMD( y, m, d ); 276 currDate.setYMD( y, m, d );
277 relayoutPage(); 277 relayoutPage();
278 dayView()->clearSelection(); 278 dayView()->clearSelection();
279 QTableSelection ts; 279 QTableSelection ts;
280 280
281 if (jumpToCurTime && this->date() == QDate::currentDate()) 281 if (jumpToCurTime && this->date() == QDate::currentDate())
282 { 282 {
283 ts.init( QTime::currentTime().hour(), 0); 283 ts.init( QTime::currentTime().hour(), 0);
284 ts.expandTo( QTime::currentTime().hour(), 0); 284 ts.expandTo( QTime::currentTime().hour(), 0);
285 } else 285 } else
286 { 286 {
287 ts.init( startTime, 0 ); 287 ts.init( startTime, 0 );
288 ts.expandTo( startTime, 0 ); 288 ts.expandTo( startTime, 0 );
289 } 289 }
290 290
291 dayView()->addSelection( ts ); 291 dayView()->addSelection( ts );
292 292
293 selectedWidget = 0; 293 selectedWidget = 0;
294 294
295} 295}
296 296
297void DateBookDay::redraw() 297void DateBookDay::redraw()
298{ 298{
299 if ( isUpdatesEnabled() ) 299 if ( isUpdatesEnabled() )
300 relayoutPage(); 300 relayoutPage();
301} 301}
302 302
303void DateBookDay::getEvents() 303void DateBookDay::getEvents()
304{ 304{
305 widgetList.clear(); 305 widgetList.clear();
306 306
307 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, 307 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate,
308 currDate ); 308 currDate );
309 QValueListIterator<EffectiveEvent> it; 309 QValueListIterator<EffectiveEvent> it;
310 for ( it = eventList.begin(); it != eventList.end(); ++it ) { 310 for ( it = eventList.begin(); it != eventList.end(); ++it ) {
311 DateBookDayWidget* w = new DateBookDayWidget( *it, this ); 311 DateBookDayWidget* w = new DateBookDayWidget( *it, this );
312 connect( w, SIGNAL( deleteMe( const Event & ) ), 312 connect( w, SIGNAL( deleteMe( const Event & ) ),
313 this, SIGNAL( removeEvent( const Event & ) ) ); 313 this, SIGNAL( removeEvent( const Event & ) ) );
314 connect( w, SIGNAL( editMe( const Event & ) ), 314 connect( w, SIGNAL( editMe( const Event & ) ),
315 this, SIGNAL( editEvent( const Event & ) ) ); 315 this, SIGNAL( editEvent( const Event & ) ) );
316 connect( w, SIGNAL( beamMe( const Event & ) ), 316 connect( w, SIGNAL( beamMe( const Event & ) ),
317 this, SIGNAL( beamEvent( const Event & ) ) ); 317 this, SIGNAL( beamEvent( const Event & ) ) );
318 widgetList.append( w ); 318 widgetList.append( w );
319 } 319 }
320 320
321} 321}
322 322
323static int place( const DateBookDayWidget *item, bool *used, int maxn ) 323static int place( const DateBookDayWidget *item, bool *used, int maxn )
324{ 324{
325 int place = 0; 325 int place = 0;
326 int start = item->event().start().hour(); 326 int start = item->event().start().hour();
327 QTime e = item->event().end(); 327 QTime e = item->event().end();
328 int end = e.hour(); 328 int end = e.hour();
329 if ( e.minute() < 5 ) 329 if ( e.minute() < 5 )
330 end--; 330 end--;
331 if ( end < start ) 331 if ( end < start )
332 end = start; 332 end = start;
333 while ( place < maxn ) { 333 while ( place < maxn ) {
334 bool free = TRUE; 334 bool free = TRUE;
335 int s = start; 335 int s = start;
336 while( s <= end ) { 336 while( s <= end ) {
337 if ( used[10*s+place] ) { 337 if ( used[10*s+place] ) {
338 free = FALSE; 338 free = FALSE;
339 break; 339 break;
340 } 340 }
341 s++; 341 s++;
342 } 342 }
343 if ( free ) break; 343 if ( free ) break;
344 place++; 344 place++;
345 } 345 }
346 if ( place == maxn ) { 346 if ( place == maxn ) {
347 return -1; 347 return -1;
348 } 348 }
349 while( start <= end ) { 349 while( start <= end ) {
350 used[10*start+place] = TRUE; 350 used[10*start+place] = TRUE;
351 start++; 351 start++;
352 } 352 }
353 return place; 353 return place;
354} 354}
355 355
356 356
357void DateBookDay::relayoutPage( bool fromResize ) 357void DateBookDay::relayoutPage( bool fromResize )
358{ 358{
359 setUpdatesEnabled( FALSE ); 359 setUpdatesEnabled( FALSE );
360 if ( !fromResize ) 360 if ( !fromResize )
361 getEvents(); // no need we already have them! 361 getEvents(); // no need we already have them!
362 362
363 widgetList.sort(); 363 widgetList.sort();
364 //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning 364 //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning
365 //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view 365 //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view
366 366
367 int wCount = widgetList.count(); 367 int wCount = widgetList.count();
368 int wid = view->columnWidth(0)-1; 368 int wid = view->columnWidth(0)-1;
369 int wd; 369 int wd;
370 int n = 1; 370 int n = 1;
371 371
372 QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget 372 QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget
373 373
374 for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); 374 for (int i = 0; i<wCount; anzIntersect[i] = 1, i++);
375 375
376 if ( wCount < 20 ) { 376 if ( wCount < 20 ) {
377 377
378 QArray<QRect> geometries(wCount); 378 QArray<QRect> geometries(wCount);
379 for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector 379 for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector
380 380
381 for ( int i = 0; i < wCount; i++) 381 for ( int i = 0; i < wCount; i++)
382 { 382 {
383 QValueList<int> intersectedWidgets; 383 QValueList<int> intersectedWidgets;
384 384
385 //find all widgets intersecting with widgetList.at(i) 385 //find all widgets intersecting with widgetList.at(i)
386 for ( int j = 0; j < wCount; j++) 386 for ( int j = 0; j < wCount; j++)
387 if (i != j) 387 if (i != j)
388 if (geometries[j].intersects(geometries[i])) 388 if (geometries[j].intersects(geometries[i]))
389 intersectedWidgets.append(j); 389 intersectedWidgets.append(j);
390 390
391 //for each of these intersecting widgets find out how many widgets are they intersecting with 391 //for each of these intersecting widgets find out how many widgets are they intersecting with
392 for ( uint j = 0; j < intersectedWidgets.count(); j++) 392 for ( uint j = 0; j < intersectedWidgets.count(); j++)
393 { 393 {
394 QArray<int> inter(wCount); 394 QArray<int> inter(wCount);
395 inter[j]=1; 395 inter[j]=1;
396 396
397 if (intersectedWidgets[j] != -1) 397 if (intersectedWidgets[j] != -1)
398 for ( uint k = j; k < intersectedWidgets.count(); k++) 398 for ( uint k = j; k < intersectedWidgets.count(); k++)
399 if (j != k && intersectedWidgets[k] != -1) 399 if (j != k && intersectedWidgets[k] != -1)
400 if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) 400 if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]]))
401 { 401 {
402 inter[j]++; 402 inter[j]++;
403 intersectedWidgets[k] = -1; 403 intersectedWidgets[k] = -1;
404 } 404 }
405 if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; 405 if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1;
406 } 406 }
407 407
408 if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; 408 if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++;
409 } 409 }
410 410
411 411
412 for ( int i = 0; i < wCount; i++) { 412 for ( int i = 0; i < wCount; i++) {
413 DateBookDayWidget *w = widgetList.at(i); 413 DateBookDayWidget *w = widgetList.at(i);
414 QRect geom = w->geometry(); 414 QRect geom = w->geometry();
415 415
416 geom.setX( 0 ); 416 geom.setX( 0 );
417 417
418 wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); 418 wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0);
419 419
420 geom.setWidth( wd ); 420 geom.setWidth( wd );
421 421
422 while ( intersects( w, geom ) ) { 422 while ( intersects( w, geom ) ) {
423 geom.moveBy( wd + 2 + 1, 0 ); 423 geom.moveBy( wd + 2 + 1, 0 );
424 } 424 }
425 w->setGeometry( geom ); 425 w->setGeometry( geom );
426 } 426 }
427 427
428 if (jumpToCurTime && this->date() == QDate::currentDate()) 428 if (jumpToCurTime && this->date() == QDate::currentDate())
429 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour 429 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour
430 else 430 else
431 view->setContentsPos( 0, startTime * view->rowHeight(0) ); 431 view->setContentsPos( 0, startTime * view->rowHeight(0) );
432 432
433 433
434 } else { 434 } else {
435 435
436 436
437 int hours[24]; 437 int hours[24];
438 memset( hours, 0, 24*sizeof( int ) ); 438 memset( hours, 0, 24*sizeof( int ) );
439 bool overFlow = FALSE; 439 bool overFlow = FALSE;
440 for ( int i = 0; i < wCount; i++ ) { 440 for ( int i = 0; i < wCount; i++ ) {
441 DateBookDayWidget *w = widgetList.at(i); 441 DateBookDayWidget *w = widgetList.at(i);
442 int start = w->event().start().hour(); 442 int start = w->event().start().hour();
443 QTime e = w->event().end(); 443 QTime e = w->event().end();
444 int end = e.hour(); 444 int end = e.hour();
445 if ( e.minute() < 5 ) 445 if ( e.minute() < 5 )
446 end--; 446 end--;
447 if ( end < start ) 447 if ( end < start )
448 end = start; 448 end = start;
449 while( start <= end ) { 449 while( start <= end ) {
450 hours[start]++; 450 hours[start]++;
451 if ( hours[start] >= 10 ) 451 if ( hours[start] >= 10 )
452 overFlow = TRUE; 452 overFlow = TRUE;
453 ++start; 453 ++start;
454 } 454 }
455 if ( overFlow ) 455 if ( overFlow )
456 break; 456 break;
457 } 457 }
458 for ( int i = 0; i < 24; i++ ) { 458 for ( int i = 0; i < 24; i++ ) {
459 n = QMAX( n, hours[i] ); 459 n = QMAX( n, hours[i] );
460 } 460 }
461 wid = ( view->columnWidth(0)-1 ) / n; 461 wid = ( view->columnWidth(0)-1 ) / n;
462 462
463 bool used[24*10]; 463 bool used[24*10];
464 memset( used, FALSE, 24*10*sizeof( bool ) ); 464 memset( used, FALSE, 24*10*sizeof( bool ) );
465 465
466 for ( int i = 0; i < wCount; i++ ) { 466 for ( int i = 0; i < wCount; i++ ) {
467 DateBookDayWidget *w = widgetList.at(i); 467 DateBookDayWidget *w = widgetList.at(i);
468 int xp = place( w, used, n ); 468 int xp = place( w, used, n );
469 if ( xp != -1 ) { 469 if ( xp != -1 ) {
470 QRect geom = w->geometry(); 470 QRect geom = w->geometry();
471 geom.setX( xp*(wid+2) ); 471 geom.setX( xp*(wid+2) );
472 geom.setWidth( wid ); 472 geom.setWidth( wid );
473 w->setGeometry( geom ); 473 w->setGeometry( geom );
474 } 474 }
475 } 475 }
476 476
477 if (jumpToCurTime && this->date() == QDate::currentDate()) 477 if (jumpToCurTime && this->date() == QDate::currentDate())
478 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour 478 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour
479 else 479 else
480 view->setContentsPos( 0, startTime * view->rowHeight(0) ); 480 view->setContentsPos( 0, startTime * view->rowHeight(0) );
481 } 481 }
482 482
483 timeMarker->setTime( QTime::currentTime() );//display timeMarker 483 timeMarker->setTime( QTime::currentTime() );//display timeMarker
484 timeMarker->raise(); //on top of all widgets 484 timeMarker->raise(); //on top of all widgets
485 if (this->date() == QDate::currentDate()) //only show timeMarker on current day 485 if (this->date() == QDate::currentDate()) //only show timeMarker on current day
486 timeMarker->show(); else timeMarker->hide(); 486 timeMarker->show(); else timeMarker->hide();
487 487
488 setUpdatesEnabled( TRUE ); 488 setUpdatesEnabled( TRUE );
489 return; 489 return;
490} 490}
491 491
492DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) 492DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom )
493{ 493{
494 int i = 0; 494 int i = 0;
495 DateBookDayWidget *w = widgetList.at(i); 495 DateBookDayWidget *w = widgetList.at(i);
496 int wCount = widgetList.count(); 496 int wCount = widgetList.count();
497 while ( i < wCount && w != item ) { 497 while ( i < wCount && w != item ) {
498 if ( w->geometry().intersects( geom ) ) { 498 if ( w->geometry().intersects( geom ) ) {
499 return w; 499 return w;
500 } 500 }
501 w = widgetList.at(++i); 501 w = widgetList.at(++i);
502 } 502 }
503 503
504 return 0; 504 return 0;
505} 505}
506 506
507 507
508QDate DateBookDay::date() const 508QDate DateBookDay::date() const
509{ 509{
510 return currDate; 510 return currDate;
511} 511}
512 512
513void DateBookDay::setStartViewTime( int startHere ) 513void DateBookDay::setStartViewTime( int startHere )
514{ 514{
515 startTime = startHere; 515 startTime = startHere;
516 dayView()->clearSelection(); 516 dayView()->clearSelection();
517 QTableSelection ts; 517 QTableSelection ts;
518 518
519 if (jumpToCurTime && this->date() == QDate::currentDate())//this should probably be in datebook.cpp where it's called? 519 if (jumpToCurTime && this->date() == QDate::currentDate())//this should probably be in datebook.cpp where it's called?
520 { 520 {
521 ts.init( QTime::currentTime().hour(), 0); 521 ts.init( QTime::currentTime().hour(), 0);
522 ts.expandTo( QTime::currentTime().hour(), 0); 522 ts.expandTo( QTime::currentTime().hour(), 0);
523 } else 523 } else
524 { 524 {
525 ts.init( startTime, 0 ); 525 ts.init( startTime, 0 );
526 ts.expandTo( startTime, 0 ); 526 ts.expandTo( startTime, 0 );
527 } 527 }
528 528
529 dayView()->addSelection( ts ); 529 dayView()->addSelection( ts );
530} 530}
531 531
532int DateBookDay::startViewTime() const 532int DateBookDay::startViewTime() const
533{ 533{
534 return startTime; 534 return startTime;
535} 535}
536 536
537void DateBookDay::slotWeekChanged( bool bStartOnMonday ) 537void DateBookDay::slotWeekChanged( bool bStartOnMonday )
538{ 538{
539 header->setStartOfWeek( bStartOnMonday ); 539 header->setStartOfWeek( bStartOnMonday );
540 // redraw(); 540 // redraw();
541} 541}
542 542
543void DateBookDay::keyPressEvent(QKeyEvent *e) 543void DateBookDay::keyPressEvent(QKeyEvent *e)
544{ 544{
545 switch(e->key()) { 545 switch(e->key()) {
546 case Key_Up: 546 case Key_Up:
547 view->moveUp(); 547 view->moveUp();
548 break; 548 break;
549 case Key_Down: 549 case Key_Down:
550 view->moveDown(); 550 view->moveDown();
551 break; 551 break;
552 case Key_Left: 552 case Key_Left:
553 setDate(QDate(currDate).addDays(-1)); 553 setDate(QDate(currDate).addDays(-1));
554 break; 554 break;
555 case Key_Right: 555 case Key_Right:
556 setDate(QDate(currDate).addDays(1)); 556 setDate(QDate(currDate).addDays(1));
557 break; 557 break;
558 default: 558 default:
559 e->ignore(); 559 e->ignore();
560 } 560 }
561} 561}
562 562
563//=========================================================================== 563//===========================================================================
564 564
565DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, 565DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e,
566 DateBookDay *db ) 566 DateBookDay *db )
567 : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db ) 567 : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db )
568{ 568{
569 bool whichClock = db->dayView()->whichClock(); 569
570 570
571 // why would someone use "<"? Oh well, fix it up... 571 // why would someone use "<"? Oh well, fix it up...
572 // I wonder what other things may be messed up... 572 // I wonder what other things may be messed up...
573 QString strDesc = ev.description(); 573 QString strDesc = ev.description();
574 int where = strDesc.find( "<" ); 574 int where = strDesc.find( "<" );
575 while ( where != -1 ) { 575 while ( where != -1 ) {
576 strDesc.remove( where, 1 ); 576 strDesc.remove( where, 1 );
577 strDesc.insert( where, "&#60;" ); 577 strDesc.insert( where, "&#60;" );
578 where = strDesc.find( "<", where ); 578 where = strDesc.find( "<", where );
579 } 579 }
580 580
581 QString strCat; 581 QString strCat;
582 // ### Fix later... 582 // ### Fix later...
583// QString strCat = ev.category(); 583// QString strCat = ev.category();
584// where = strCat.find( "<" ); 584// where = strCat.find( "<" );
585// while ( where != -1 ) { 585// while ( where != -1 ) {
586 // strCat.remove( where, 1 ); 586 // strCat.remove( where, 1 );
587 // strCat.insert( where, "&#60;" ); 587 // strCat.insert( where, "&#60;" );
588 // where = strCat.find( "<", where ); 588 // where = strCat.find( "<", where );
589// } 589// }
590 590
591 QString strNote = ev.notes(); 591 QString strNote = ev.notes();
592 where = strNote.find( "<" ); 592 where = strNote.find( "<" );
593 while ( where != -1 ) { 593 while ( where != -1 ) {
594 strNote.remove( where, 1 ); 594 strNote.remove( where, 1 );
595 strNote.insert( where, "&#60;" ); 595 strNote.insert( where, "&#60;" );
596 where = strNote.find( "<", where ); 596 where = strNote.find( "<", where );
597 } 597 }
598 598
599 text = "<b>" + strDesc + "</b><br>" + "<i>" 599 text = "<b>" + strDesc + "</b><br>" + "<i>"
600 + strCat + "</i>" 600 + strCat + "</i><br>";
601 + "<br><b>" + tr("Start") + "</b>: "; 601 if (ev.event().type() == Event::Normal )
602 602 setEventText( text );
603 603 else
604 if ( e.startDate() != ev.date() ) { 604 setAllDayText( text );
605 // multi-day event. Show start date
606 text += TimeString::longDateString( e.startDate() );
607 } else {
608 // Show start time.
609 text += TimeString::timeString( ev.start(), whichClock, FALSE );
610 }
611 605
612 text += "<br><b>" + tr("End") + "</b>: ";
613 if ( e.endDate() != ev.date() ) {
614 // multi-day event. Show end date
615 text += TimeString::longDateString( e.endDate() );
616 } else {
617 // Show end time.
618 text += TimeString::timeString( ev.end(), whichClock, FALSE );
619 }
620 text += "<br><br>" + strNote; 606 text += "<br><br>" + strNote;
607
621 setBackgroundMode( PaletteBase ); 608 setBackgroundMode( PaletteBase );
622 609
623 QTime start = ev.start(); 610 QTime start = ev.start();
624 QTime end = ev.end(); 611 QTime end = ev.end();
625 int y = start.hour()*60+start.minute(); 612 int y = start.hour()*60+start.minute();
626 int h = end.hour()*60+end.minute()-y; 613 int h = end.hour()*60+end.minute()-y;
627 int rh = dateBook->dayView()->rowHeight(0); 614 int rh = dateBook->dayView()->rowHeight(0);
628 y = y*rh/60; 615 y = y*rh/60;
629 h = h*rh/60; 616 h = h*rh/60;
630 if ( h < 3 ) 617 if ( h < 3 )
631 h = 3; 618 h = 3;
632 geom.setY( y ); 619 geom.setY( y );
633 geom.setHeight( h ); 620 geom.setHeight( h );
634 geom.setX( 0 ); 621 geom.setX( 0 );
635 geom.setWidth(dateBook->dayView()->columnWidth(0)-1); 622 geom.setWidth(dateBook->dayView()->columnWidth(0)-1);
636 623
637} 624}
625void DateBookDayWidget::setAllDayText( QString &text ) {
626 text += "<b>" + tr("This is an all day event.") + "</b><br>";
627}
628void DateBookDayWidget::setEventText( QString& text ) {
629 bool whichClock = dateBook->dayView()->whichClock();
630 text += "<b>" + tr("Start") + "</b>: ";
631 if ( ev.startDate() != ev.date() ) {
632 // multi-day event. Show start date
633 text += TimeString::longDateString( ev.startDate() );
634 } else {
635 // Show start time.
636 text += TimeString::timeString( ev.start(), whichClock, FALSE );
637 }
638
639 text += "<br><b>" + tr("End") + "</b>: ";
640 if ( ev.endDate() != ev.date() ) {
641 // multi-day event. Show end date
642 text += TimeString::longDateString( ev.endDate() );
643 } else {
644 // Show end time.
645 text += TimeString::timeString( ev.end(), whichClock, FALSE );
646 }
647
648}
638 649
639DateBookDayWidget::~DateBookDayWidget() 650DateBookDayWidget::~DateBookDayWidget()
640{ 651{
641} 652}
642 653
643void DateBookDayWidget::paintEvent( QPaintEvent *e ) 654void DateBookDayWidget::paintEvent( QPaintEvent *e )
644{ 655{
645 QPainter p( this ); 656 QPainter p( this );
646 657
647 if (dateBook->getSelectedWidget() == this) 658 if (dateBook->getSelectedWidget() == this)
648 { 659 {
649 p.setBrush( QColor( 155, 240, 230 ) ); // selected item 660 p.setBrush( QColor( 155, 240, 230 ) ); // selected item
650 } else 661 } else
651 { 662 {
652 if (dateBook->date() == QDate::currentDate()) 663 if (dateBook->date() == QDate::currentDate())
653 { 664 {
654 QTime curTime = QTime::currentTime(); 665 QTime curTime = QTime::currentTime();
655 666
656 if (ev.end() < curTime) 667 if (ev.end() < curTime)
657 { 668 {
658 p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive 669 p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive
659 } else 670 } else
660 { 671 {
661 //change color in dependence of the time till the event starts 672 //change color in dependence of the time till the event starts
662 int duration = curTime.secsTo(ev.start()); 673 int duration = curTime.secsTo(ev.start());
663 if (duration < 0) duration = 0; 674 if (duration < 0) duration = 0;
664 int colChange = duration*160/86400; //86400: secs per day, 160: max color shift 675 int colChange = duration*160/86400; //86400: secs per day, 160: max color shift
665 676
666 p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue 677 p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue
667 } 678 }
668 } else 679 } else
669 { 680 {
670 p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date) 681 p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date)
671 //perhaps make a distinction between future/past dates 682 //perhaps make a distinction between future/past dates
672 } 683 }
673 } 684 }
674 685
675 p.setPen( QColor(100, 100, 100) ); 686 p.setPen( QColor(100, 100, 100) );
676 p.drawRect(rect()); 687 p.drawRect(rect());
677 688
678 // p.drawRect(0,0, 5, height()); 689 // p.drawRect(0,0, 5, height());
679 690
680 int y = 0; 691 int y = 0;
681 int d = 0; 692 int d = 0;
682 693
683 if ( ev.event().hasAlarm() ) { 694 if ( ev.event().hasAlarm() ) {
684 p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); 695 p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) );
685 y = 20; 696 y = 20;
686 d = 20; 697 d = 20;
687 } 698 }
688 699
689 if ( ev.event().hasRepeat() ) { 700 if ( ev.event().hasRepeat() ) {
690 p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); 701 p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) );
691 d = 20; 702 d = 20;
703 y += 20;
692 } 704 }
693 705
694 QSimpleRichText rt( text, font() ); 706 QSimpleRichText rt( text, font() );
695 rt.setWidth( geom.width() - d - 6 ); 707 rt.setWidth( geom.width() - d - 6 );
696 rt.draw( &p, 7, 0, e->region(), colorGroup() ); 708 rt.draw( &p, 7, 0, e->region(), colorGroup() );
697} 709}
698 710
699void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) 711void DateBookDayWidget::mousePressEvent( QMouseEvent *e )
700{ 712{
701 DateBookDayWidget *item; 713 DateBookDayWidget *item;
702 714
703 item = dateBook->getSelectedWidget(); 715 item = dateBook->getSelectedWidget();
704 if (item) item->update(); 716 if (item) item->update();
705 717
706 dateBook->setSelectedWidget(this); 718 dateBook->setSelectedWidget(this);
707 update(); 719 update();
708 dateBook->repaint(); 720 dateBook->repaint();
709 721
710 QPopupMenu m; 722 QPopupMenu m;
711 m.insertItem( tr( "Edit" ), 1 ); 723 m.insertItem( tr( "Edit" ), 1 );
712 m.insertItem( tr( "Delete" ), 2 ); 724 m.insertItem( tr( "Delete" ), 2 );
713 m.insertItem( tr( "Beam" ), 3 ); 725 m.insertItem( tr( "Beam" ), 3 );
714 int r = m.exec( e->globalPos() ); 726 int r = m.exec( e->globalPos() );
715 if ( r == 1 ) { 727 if ( r == 1 ) {
716 emit editMe( ev.event() ); 728 emit editMe( ev.event() );
717 } else if ( r == 2 ) { 729 } else if ( r == 2 ) {
718 emit deleteMe( ev.event() ); 730 emit deleteMe( ev.event() );
719 } else if ( r == 3 ) { 731 } else if ( r == 3 ) {
720 emit beamMe( ev.event() ); 732 emit beamMe( ev.event() );
721 } 733 }
722} 734}
723 735
724void DateBookDayWidget::setGeometry( const QRect &r ) 736void DateBookDayWidget::setGeometry( const QRect &r )
725{ 737{
726 geom = r; 738 geom = r;
727 setFixedSize( r.width()+1, r.height()+1 ); 739 setFixedSize( r.width()+1, r.height()+1 );
728 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); 740 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 );
729 show(); 741 show();
730} 742}
731 743
732 744
733//--------------------------------------------------------------------------------------------- 745//---------------------------------------------------------------------------------------------
734//--------------------------------------------------------------------------------------------- 746//---------------------------------------------------------------------------------------------
735 747
736 748
737DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) 749DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db )
738 : QWidget( db->dayView()->viewport() ), dateBook( db ) 750 : QWidget( db->dayView()->viewport() ), dateBook( db )
739{ 751{
740 setBackgroundMode( PaletteBase ); 752 setBackgroundMode( PaletteBase );
741} 753}
742 754
743DateBookDayTimeMarker::~DateBookDayTimeMarker() 755DateBookDayTimeMarker::~DateBookDayTimeMarker()
744{ 756{
745} 757}
746 758
747void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ ) 759void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ )
748{ 760{
749 QPainter p( this ); 761 QPainter p( this );
750 p.setBrush( QColor( 255, 0, 0 ) ); 762 p.setBrush( QColor( 255, 0, 0 ) );
751 763
752 QPen pen; 764 QPen pen;
753 pen.setStyle(NoPen); 765 pen.setStyle(NoPen);
754 766
755 p.setPen( pen ); 767 p.setPen( pen );
756 p.drawRect(rect()); 768 p.drawRect(rect());
757} 769}
758 770
759void DateBookDayTimeMarker::setTime( const QTime &t ) 771void DateBookDayTimeMarker::setTime( const QTime &t )
760{ 772{
761 int y = t.hour()*60+t.minute(); 773 int y = t.hour()*60+t.minute();
762 int rh = dateBook->dayView()->rowHeight(0); 774 int rh = dateBook->dayView()->rowHeight(0);
763 y = y*rh/60; 775 y = y*rh/60;
764 776
765 geom.setX( 0 ); 777 geom.setX( 0 );
766 778
767 int x = dateBook->dayView()->columnWidth(0)-1; 779 int x = dateBook->dayView()->columnWidth(0)-1;
768 geom.setWidth( x ); 780 geom.setWidth( x );
769 781
770 geom.setY( y ); 782 geom.setY( y );
771 geom.setHeight( 1 ); 783 geom.setHeight( 1 );
772 784
773 setGeometry( geom ); 785 setGeometry( geom );
774 786
775 time = t; 787 time = t;
776} 788}
777 789
778void DateBookDayTimeMarker::setGeometry( const QRect &r ) 790void DateBookDayTimeMarker::setGeometry( const QRect &r )
779{ 791{
780 geom = r; 792 geom = r;
781 setFixedSize( r.width()+1, r.height()+1 ); 793 setFixedSize( r.width()+1, r.height()+1 );
782 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); 794 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 );
783 show(); 795 show();
784} 796}
diff --git a/core/pim/datebook/datebookday.h b/core/pim/datebook/datebookday.h
index be7cc45..db1cd04 100644
--- a/core/pim/datebook/datebookday.h
+++ b/core/pim/datebook/datebookday.h
@@ -1,194 +1,205 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef DATEBOOKDAY_H 20#ifndef DATEBOOKDAY_H
21#define DATEBOOKDAY_H 21#define DATEBOOKDAY_H
22 22
23#include <qpe/event.h> 23#include <qpe/event.h>
24 24
25#include <qdatetime.h> 25#include <qdatetime.h>
26#include <qtable.h> 26#include <qtable.h>
27#include <qvbox.h> 27#include <qvbox.h>
28#include <qlist.h> 28#include <qlist.h>
29 29
30class DateBookDayHeader; 30class DateBookDayHeader;
31class DateBookDB; 31class DateBookDB;
32class QDateTime; 32class QDateTime;
33class QMouseEvent; 33class QMouseEvent;
34class QPaintEvent; 34class QPaintEvent;
35class QResizeEvent; 35class QResizeEvent;
36 36
37class DateBookDayView : public QTable 37class DateBookDayView : public QTable
38{ 38{
39 Q_OBJECT 39 Q_OBJECT
40public: 40public:
41 DateBookDayView( bool hourClock, QWidget *parent, const char *name ); 41 DateBookDayView( bool hourClock, QWidget *parent, const char *name );
42 bool whichClock() const; 42 bool whichClock() const;
43 43
44 void setRowStyle( int style ); 44 void setRowStyle( int style );
45 45
46public slots: 46public slots:
47 void moveUp(); 47 void moveUp();
48 void moveDown(); 48 void moveDown();
49 49
50signals: 50signals:
51 void sigColWidthChanged(); 51 void sigColWidthChanged();
52 void sigCapturedKey( const QString &txt ); 52 void sigCapturedKey( const QString &txt );
53protected slots: 53protected slots:
54 void slotChangeClock( bool ); 54 void slotChangeClock( bool );
55protected: 55protected:
56 virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected ); 56 virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected );
57 virtual void paintFocus( QPainter *p, const QRect &cr ); 57 virtual void paintFocus( QPainter *p, const QRect &cr );
58 58
59 virtual void resizeEvent( QResizeEvent *e ); 59 virtual void resizeEvent( QResizeEvent *e );
60 void keyPressEvent( QKeyEvent *e ); 60 void keyPressEvent( QKeyEvent *e );
61 void initHeader(); 61 void initHeader();
62private: 62private:
63 bool ampm; 63 bool ampm;
64}; 64};
65 65
66class DateBookDay; 66class DateBookDay;
67class DateBookDayWidget : public QWidget 67class DateBookDayWidget : public QWidget
68{ 68{
69 Q_OBJECT 69 Q_OBJECT
70 70
71public: 71public:
72 DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db ); 72 DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db );
73 ~DateBookDayWidget(); 73 ~DateBookDayWidget();
74 74
75 const QRect &geometry() { return geom; } 75 const QRect &geometry() { return geom; }
76 void setGeometry( const QRect &r ); 76 void setGeometry( const QRect &r );
77 77
78 const EffectiveEvent &event() const { return ev; } 78 const EffectiveEvent &event() const { return ev; }
79 79
80signals: 80signals:
81 void deleteMe( const Event &e ); 81 void deleteMe( const Event &e );
82 void editMe( const Event &e ); 82 void editMe( const Event &e );
83 void beamMe( const Event &e ); 83 void beamMe( const Event &e );
84 84
85protected: 85protected:
86 void paintEvent( QPaintEvent *e ); 86 void paintEvent( QPaintEvent *e );
87 void mousePressEvent( QMouseEvent *e ); 87 void mousePressEvent( QMouseEvent *e );
88 88
89private: 89private:
90 /**
91 * Sets the text for an all day Event
92 * All day events have no time associated
93 */
94 void setAllDayText( QString& text );
95
96 /**
97 * Sets the EventText
98 * it got a start and an end Time
99 */
100 void setEventText( QString& text );
90 const EffectiveEvent ev; 101 const EffectiveEvent ev;
91 DateBookDay *dateBook; 102 DateBookDay *dateBook;
92 QString text; 103 QString text;
93 QRect geom; 104 QRect geom;
94}; 105};
95 106
96//Marker for current time in the dayview 107//Marker for current time in the dayview
97class DateBookDayTimeMarker : public QWidget 108class DateBookDayTimeMarker : public QWidget
98{ 109{
99 Q_OBJECT 110 Q_OBJECT
100 111
101public: 112public:
102 DateBookDayTimeMarker( DateBookDay *db ); 113 DateBookDayTimeMarker( DateBookDay *db );
103 ~DateBookDayTimeMarker(); 114 ~DateBookDayTimeMarker();
104 115
105 const QRect &geometry() { return geom; } 116 const QRect &geometry() { return geom; }
106 void setGeometry( const QRect &r ); 117 void setGeometry( const QRect &r );
107 void setTime( const QTime &t ); 118 void setTime( const QTime &t );
108 119
109signals: 120signals:
110 121
111protected: 122protected:
112 void paintEvent( QPaintEvent *e ); 123 void paintEvent( QPaintEvent *e );
113 124
114private: 125private:
115 QRect geom; 126 QRect geom;
116 QTime time; 127 QTime time;
117 DateBookDay *dateBook; 128 DateBookDay *dateBook;
118}; 129};
119 130
120//reimplemented the compareItems function so that it sorts DayWidgets by geometry heights 131//reimplemented the compareItems function so that it sorts DayWidgets by geometry heights
121class WidgetListClass : public QList<DateBookDayWidget> 132class WidgetListClass : public QList<DateBookDayWidget>
122 { 133{
123 private: 134 private:
124 135
125 int compareItems( QCollection::Item s1, QCollection::Item s2 ) 136 int compareItems( QCollection::Item s1, QCollection::Item s2 )
126 { 137 {
127 //hmm, don't punish me for that ;) 138 //hmm, don't punish me for that ;)
128 if (reinterpret_cast<DateBookDayWidget*>(s1)->geometry().height() > reinterpret_cast<DateBookDayWidget*>(s2)->geometry().height()) 139 if (reinterpret_cast<DateBookDayWidget*>(s1)->geometry().height() > reinterpret_cast<DateBookDayWidget*>(s2)->geometry().height())
129 { 140 {
130 return -1; 141 return -1;
131 } else 142 } else
132 { 143 {
133 return 1; 144 return 1;
134 } 145 }
135 } 146 }
136 147
137 148
138}; 149};
139 150
140class DateBookDay : public QVBox 151class DateBookDay : public QVBox
141{ 152{
142 Q_OBJECT 153 Q_OBJECT
143 154
144public: 155public:
145 DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, 156 DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb,
146 QWidget *parent, const char *name ); 157 QWidget *parent, const char *name );
147 void selectedDates( QDateTime &start, QDateTime &end ); 158 void selectedDates( QDateTime &start, QDateTime &end );
148 QDate date() const; 159 QDate date() const;
149 DateBookDayView *dayView() const { return view; } 160 DateBookDayView *dayView() const { return view; }
150 void setStartViewTime( int startHere ); 161 void setStartViewTime( int startHere );
151 int startViewTime() const; 162 int startViewTime() const;
152 void setSelectedWidget( DateBookDayWidget * ); 163 void setSelectedWidget( DateBookDayWidget * );
153 DateBookDayWidget * getSelectedWidget( void ); 164 DateBookDayWidget * getSelectedWidget( void );
154 void setJumpToCurTime( bool bJump ); 165 void setJumpToCurTime( bool bJump );
155 void setRowStyle( int style ); 166 void setRowStyle( int style );
156 167
157public slots: 168public slots:
158 void setDate( int y, int m, int d ); 169 void setDate( int y, int m, int d );
159 void setDate( QDate ); 170 void setDate( QDate );
160 void redraw(); 171 void redraw();
161 void slotWeekChanged( bool bStartOnMonday ); 172 void slotWeekChanged( bool bStartOnMonday );
162 void updateView();//updates TimeMarker and DayWidget-colors 173 void updateView();//updates TimeMarker and DayWidget-colors
163 174
164signals: 175signals:
165 void removeEvent( const Event& ); 176 void removeEvent( const Event& );
166 void editEvent( const Event& ); 177 void editEvent( const Event& );
167 void beamEvent( const Event& ); 178 void beamEvent( const Event& );
168 void newEvent(); 179 void newEvent();
169 void sigNewEvent( const QString & ); 180 void sigNewEvent( const QString & );
170 181
171protected slots: 182protected slots:
172 void keyPressEvent(QKeyEvent *); 183 void keyPressEvent(QKeyEvent *);
173 184
174private slots: 185private slots:
175 void dateChanged( int y, int m, int d ); 186 void dateChanged( int y, int m, int d );
176 void slotColWidthChanged() { relayoutPage(); }; 187 void slotColWidthChanged() { relayoutPage(); };
177 188
178private: 189private:
179 void getEvents(); 190 void getEvents();
180 void relayoutPage( bool fromResize = false ); 191 void relayoutPage( bool fromResize = false );
181 DateBookDayWidget *intersects( const DateBookDayWidget *item, const QRect &geom ); 192 DateBookDayWidget *intersects( const DateBookDayWidget *item, const QRect &geom );
182 QDate currDate; 193 QDate currDate;
183 DateBookDayView *view; 194 DateBookDayView *view;
184 DateBookDayHeader *header; 195 DateBookDayHeader *header;
185 DateBookDB *db; 196 DateBookDB *db;
186 WidgetListClass widgetList;//reimplemented QList for sorting widgets by height 197 WidgetListClass widgetList;//reimplemented QList for sorting widgets by height
187 int startTime; 198 int startTime;
188 bool jumpToCurTime;//should we jump to current time in dayview? 199 bool jumpToCurTime;//should we jump to current time in dayview?
189 int rowStyle; 200 int rowStyle;
190 DateBookDayWidget *selectedWidget; //actual selected widget (obviously) 201 DateBookDayWidget *selectedWidget; //actual selected widget (obviously)
191 DateBookDayTimeMarker *timeMarker;//marker for current time 202 DateBookDayTimeMarker *timeMarker;//marker for current time
192}; 203};
193 204
194#endif 205#endif
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp
index 6532ba4..e16f516 100644
--- a/core/pim/datebook/datebookweek.cpp
+++ b/core/pim/datebook/datebookweek.cpp
@@ -1,687 +1,703 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "datebookweek.h" 20#include "datebookweek.h"
21#include "datebookweekheaderimpl.h" 21#include "datebookweekheaderimpl.h"
22 22
23#include <qpe/calendar.h> 23#include <qpe/calendar.h>
24#include <qpe/datebookdb.h> 24#include <qpe/datebookdb.h>
25#include <qpe/event.h> 25#include <qpe/event.h>
26#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
27#include <qpe/timestring.h> 27#include <qpe/timestring.h>
28 28
29#include <qdatetime.h> 29#include <qdatetime.h>
30#include <qheader.h> 30#include <qheader.h>
31#include <qlabel.h> 31#include <qlabel.h>
32#include <qlayout.h> 32#include <qlayout.h>
33#include <qpainter.h> 33#include <qpainter.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qtimer.h> 35#include <qtimer.h>
36#include <qspinbox.h> 36#include <qspinbox.h>
37#include <qstyle.h> 37#include <qstyle.h>
38 38
39//----------------------------------------------------------------- 39//-----------------------------------------------------------------
40 40
41 41
42DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) 42DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e )
43 : ev( e ) 43 : ev( e )
44{ 44{
45 // with the current implementation change the color for all day events 45 // with the current implementation change the color for all day events
46 if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { 46 if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) {
47 c = Qt::green; 47 c = Qt::green;
48 } else { 48 } else {
49 c = ev.event().hasAlarm() ? Qt::red : Qt::blue; 49 c = ev.event().hasAlarm() ? Qt::red : Qt::blue;
50 } 50 }
51} 51}
52 52
53void DateBookWeekItem::setGeometry( int x, int y, int w, int h ) 53void DateBookWeekItem::setGeometry( int x, int y, int w, int h )
54{ 54{
55 r.setRect( x, y, w, h ); 55 r.setRect( x, y, w, h );
56} 56}
57 57
58 58
59//------------------=--------------------------------------------- 59//------------------=---------------------------------------------
60 60
61DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, 61DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday,
62 QWidget *parent, const char *name ) 62 QWidget *parent, const char *name )
63 : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), 63 : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ),
64 showingEvent( false ) 64 showingEvent( false )
65{ 65{
66 items.setAutoDelete( true ); 66 items.setAutoDelete( true );
67 67
68 viewport()->setBackgroundMode( PaletteBase ); 68 viewport()->setBackgroundMode( PaletteBase );
69 69
70 header = new QHeader( this ); 70 header = new QHeader( this );
71 header->addLabel( "" ); 71 header->addLabel( "" );
72 72
73 header->setMovingEnabled( false ); 73 header->setMovingEnabled( false );
74 header->setResizeEnabled( false ); 74 header->setResizeEnabled( false );
75 header->setClickEnabled( false, 0 ); 75 header->setClickEnabled( false, 0 );
76 initNames(); 76 initNames();
77 77
78 78
79 connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); 79 connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) );
80 80
81 QObject::connect(qApp, SIGNAL(clockChanged(bool)), 81 QObject::connect(qApp, SIGNAL(clockChanged(bool)),
82 this, SLOT(slotChangeClock(bool))); 82 this, SLOT(slotChangeClock(bool)));
83 83
84 QFontMetrics fm( font() ); 84 QFontMetrics fm( font() );
85 rowHeight = fm.height()+2; 85 rowHeight = fm.height()+2;
86 86
87 resizeContents( width(), 24*rowHeight ); 87 resizeContents( width(), 24*rowHeight );
88} 88}
89 89
90void DateBookWeekView::initNames() 90void DateBookWeekView::initNames()
91{ 91{
92 static bool bFirst = true; 92 static bool bFirst = true;
93 if ( bFirst ) { 93 if ( bFirst ) {
94 if ( bOnMonday ) { 94 if ( bOnMonday ) {
95 header->addLabel( tr("M", "Monday" ) ); 95 header->addLabel( tr("M", "Monday" ) );
96 header->addLabel( tr("T", "Tuesday") ); 96 header->addLabel( tr("T", "Tuesday") );
97 header->addLabel( tr("W", "Wednesday" ) ); 97 header->addLabel( tr("W", "Wednesday" ) );
98 header->addLabel( tr("T", "Thursday" ) ); 98 header->addLabel( tr("T", "Thursday" ) );
99 header->addLabel( tr("F", "Friday" ) ); 99 header->addLabel( tr("F", "Friday" ) );
100 header->addLabel( tr("S", "Saturday" ) ); 100 header->addLabel( tr("S", "Saturday" ) );
101 header->addLabel( tr("S", "Sunday" ) ); 101 header->addLabel( tr("S", "Sunday" ) );
102 } else { 102 } else {
103 header->addLabel( tr("S", "Sunday" ) ); 103 header->addLabel( tr("S", "Sunday" ) );
104 header->addLabel( tr("M", "Monday") ); 104 header->addLabel( tr("M", "Monday") );
105 header->addLabel( tr("T", "Tuesday") ); 105 header->addLabel( tr("T", "Tuesday") );
106 header->addLabel( tr("W", "Wednesday" ) ); 106 header->addLabel( tr("W", "Wednesday" ) );
107 header->addLabel( tr("T", "Thursday" ) ); 107 header->addLabel( tr("T", "Thursday" ) );
108 header->addLabel( tr("F", "Friday" ) ); 108 header->addLabel( tr("F", "Friday" ) );
109 header->addLabel( tr("S", "Saturday" ) ); 109 header->addLabel( tr("S", "Saturday" ) );
110 } 110 }
111 bFirst = false; 111 bFirst = false;
112 } else { 112 } else {
113 // we are change things... 113 // we are change things...
114 if ( bOnMonday ) { 114 if ( bOnMonday ) {
115 header->setLabel( 1, tr("M", "Monday") ); 115 header->setLabel( 1, tr("M", "Monday") );
116 header->setLabel( 2, tr("T", "Tuesday") ); 116 header->setLabel( 2, tr("T", "Tuesday") );
117 header->setLabel( 3, tr("W", "Wednesday" ) ); 117 header->setLabel( 3, tr("W", "Wednesday" ) );
118 header->setLabel( 4, tr("T", "Thursday" ) ); 118 header->setLabel( 4, tr("T", "Thursday" ) );
119 header->setLabel( 5, tr("F", "Friday" ) ); 119 header->setLabel( 5, tr("F", "Friday" ) );
120 header->setLabel( 6, tr("S", "Saturday" ) ); 120 header->setLabel( 6, tr("S", "Saturday" ) );
121 header->setLabel( 7, tr("S", "Sunday" ) ); 121 header->setLabel( 7, tr("S", "Sunday" ) );
122 } else { 122 } else {
123 header->setLabel( 1, tr("S", "Sunday" ) ); 123 header->setLabel( 1, tr("S", "Sunday" ) );
124 header->setLabel( 2, tr("M", "Monday") ); 124 header->setLabel( 2, tr("M", "Monday") );
125 header->setLabel( 3, tr("T", "Tuesday") ); 125 header->setLabel( 3, tr("T", "Tuesday") );
126 header->setLabel( 4, tr("W", "Wednesday" ) ); 126 header->setLabel( 4, tr("W", "Wednesday" ) );
127 header->setLabel( 5, tr("T", "Thursday" ) ); 127 header->setLabel( 5, tr("T", "Thursday" ) );
128 header->setLabel( 6, tr("F", "Friday" ) ); 128 header->setLabel( 6, tr("F", "Friday" ) );
129 header->setLabel( 7, tr("S", "Saturday" ) ); 129 header->setLabel( 7, tr("S", "Saturday" ) );
130 } 130 }
131 } 131 }
132} 132}
133 133
134 134
135 135
136void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) 136void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev )
137{ 137{
138 items.clear(); 138 items.clear();
139 QValueListIterator<EffectiveEvent> it; 139 QValueListIterator<EffectiveEvent> it;
140 for ( it = ev.begin(); it != ev.end(); ++it ) { 140 for ( it = ev.begin(); it != ev.end(); ++it ) {
141 DateBookWeekItem *i = new DateBookWeekItem( *it ); 141 DateBookWeekItem *i = new DateBookWeekItem( *it );
142 positionItem( i ); 142 positionItem( i );
143 items.append( i ); 143 items.append( i );
144 } 144 }
145 viewport()->update(); 145 viewport()->update();
146} 146}
147 147
148void DateBookWeekView::moveToHour( int h ) 148void DateBookWeekView::moveToHour( int h )
149{ 149{
150 int offset = h*rowHeight; 150 int offset = h*rowHeight;
151 setContentsPos( 0, offset ); 151 setContentsPos( 0, offset );
152} 152}
153 153
154void DateBookWeekView::keyPressEvent( QKeyEvent *e ) 154void DateBookWeekView::keyPressEvent( QKeyEvent *e )
155{ 155{
156 e->ignore(); 156 e->ignore();
157} 157}
158 158
159void DateBookWeekView::slotChangeClock( bool c ) 159void DateBookWeekView::slotChangeClock( bool c )
160{ 160{
161 ampm = c; 161 ampm = c;
162 viewport()->update(); 162 viewport()->update();
163} 163}
164 164
165static inline int db_round30min( int m ) 165static inline int db_round30min( int m )
166{ 166{
167 if ( m < 15 ) 167 if ( m < 15 )
168 m = 0; 168 m = 0;
169 else if ( m < 45 ) 169 else if ( m < 45 )
170 m = 1; 170 m = 1;
171 else 171 else
172 m = 2; 172 m = 2;
173 173
174 return m; 174 return m;
175} 175}
176 176
177void DateBookWeekView::alterDay( int day ) 177void DateBookWeekView::alterDay( int day )
178{ 178{
179 if ( !bOnMonday ) { 179 if ( !bOnMonday ) {
180 day--; 180 day--;
181 } 181 }
182 emit showDay( day ); 182 emit showDay( day );
183} 183}
184 184
185void DateBookWeekView::positionItem( DateBookWeekItem *i ) 185void DateBookWeekView::positionItem( DateBookWeekItem *i )
186{ 186{
187 const int Width = 8; 187 const int Width = 8;
188 const EffectiveEvent ev = i->event(); 188 const EffectiveEvent ev = i->event();
189 189
190 // 30 minute intervals 190 // 30 minute intervals
191 int y = ev.start().hour() * 2; 191 int y = ev.start().hour() * 2;
192 y += db_round30min( ev.start().minute() ); 192 y += db_round30min( ev.start().minute() );
193 if ( y > 47 ) 193 if ( y > 47 )
194 y = 47; 194 y = 47;
195 y = y * rowHeight / 2; 195 y = y * rowHeight / 2;
196 196
197 int h; 197 int h;
198 if ( ev.event().type() == Event::AllDay ) { 198 if ( ev.event().type() == Event::AllDay ) {
199 h = 48; 199 h = 48;
200 y = 0; 200 y = 0;
201 } else { 201 } else {
202 h = ( ev.end().hour() - ev.start().hour() ) * 2; 202 h = ( ev.end().hour() - ev.start().hour() ) * 2;
203 h += db_round30min( ev.end().minute() - ev.start().minute() ); 203 h += db_round30min( ev.end().minute() - ev.start().minute() );
204 if ( h < 1 ) h = 1; 204 if ( h < 1 ) h = 1;
205 } 205 }
206 h = h * rowHeight / 2; 206 h = h * rowHeight / 2;
207 207
208 int dow = ev.date().dayOfWeek(); 208 int dow = ev.date().dayOfWeek();
209 if ( !bOnMonday ) { 209 if ( !bOnMonday ) {
210 if ( dow == 7 ) 210 if ( dow == 7 )
211 dow = 1; 211 dow = 1;
212 else 212 else
213 dow++; 213 dow++;
214 } 214 }
215 int x = header->sectionPos( dow ) - 1; 215 int x = header->sectionPos( dow ) - 1;
216 int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); 216 int xlim = header->sectionPos( dow ) + header->sectionSize( dow );
217 DateBookWeekItem *isect = 0; 217 DateBookWeekItem *isect = 0;
218 do { 218 do {
219 i->setGeometry( x, y, Width, h ); 219 i->setGeometry( x, y, Width, h );
220 isect = intersects( i ); 220 isect = intersects( i );
221 x += Width - 1; 221 x += Width - 1;
222 } while ( isect && x < xlim ); 222 } while ( isect && x < xlim );
223} 223}
224 224
225DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) 225DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item )
226{ 226{
227 QRect geom = item->geometry(); 227 QRect geom = item->geometry();
228 228
229 // We allow the edges to overlap 229 // We allow the edges to overlap
230 geom.moveBy( 1, 1 ); 230 geom.moveBy( 1, 1 );
231 geom.setSize( geom.size()-QSize(2,2) ); 231 geom.setSize( geom.size()-QSize(2,2) );
232 232
233 QListIterator<DateBookWeekItem> it(items); 233 QListIterator<DateBookWeekItem> it(items);
234 for ( ; it.current(); ++it ) { 234 for ( ; it.current(); ++it ) {
235 DateBookWeekItem *i = it.current(); 235 DateBookWeekItem *i = it.current();
236 if ( i != item ) { 236 if ( i != item ) {
237 if ( i->geometry().intersects( geom ) ) { 237 if ( i->geometry().intersects( geom ) ) {
238 return i; 238 return i;
239 } 239 }
240 } 240 }
241 } 241 }
242 242
243 return 0; 243 return 0;
244} 244}
245 245
246void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) 246void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e )
247{ 247{
248 QListIterator<DateBookWeekItem> it(items); 248 QListIterator<DateBookWeekItem> it(items);
249 for ( ; it.current(); ++it ) { 249 for ( ; it.current(); ++it ) {
250 DateBookWeekItem *i = it.current(); 250 DateBookWeekItem *i = it.current();
251 if ( i->geometry().contains( e->pos() ) ) { 251 if ( i->geometry().contains( e->pos() ) ) {
252 showingEvent = true; 252 showingEvent = true;
253 emit signalShowEvent( i->event() ); 253 emit signalShowEvent( i->event() );
254 break; 254 break;
255 } 255 }
256 } 256 }
257} 257}
258 258
259void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) 259void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e )
260{ 260{
261 if ( showingEvent ) { 261 if ( showingEvent ) {
262 showingEvent = false; 262 showingEvent = false;
263 emit signalHideEvent(); 263 emit signalHideEvent();
264 } else { 264 } else {
265 int d = header->sectionAt( e->pos().x() ); 265 int d = header->sectionAt( e->pos().x() );
266 if ( d > 0 ) { 266 if ( d > 0 ) {
267 // if ( !bOnMonday ) 267 // if ( !bOnMonday )
268 // d--; 268 // d--;
269 emit showDay( d ); 269 emit showDay( d );
270 } 270 }
271 } 271 }
272} 272}
273 273
274void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) 274void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
275{ 275{
276 QRect ur( cx, cy, cw, ch ); 276 QRect ur( cx, cy, cw, ch );
277 p->setPen( lightGray ); 277 p->setPen( lightGray );
278 for ( int i = 1; i <= 7; i++ ) 278 for ( int i = 1; i <= 7; i++ )
279 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); 279 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch );
280 280
281 p->setPen( black ); 281 p->setPen( black );
282 for ( int t = 0; t < 24; t++ ) { 282 for ( int t = 0; t < 24; t++ ) {
283 int y = t*rowHeight; 283 int y = t*rowHeight;
284 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { 284 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) {
285 QString s; 285 QString s;
286 if ( ampm ) { 286 if ( ampm ) {
287 if ( t == 0 ) 287 if ( t == 0 )
288 s = QString::number( 12 ); 288 s = QString::number( 12 );
289 else if ( t == 12 ) 289 else if ( t == 12 )
290 s = QString::number(12) + tr( "p" ); 290 s = QString::number(12) + tr( "p" );
291 else if ( t > 12 ) { 291 else if ( t > 12 ) {
292 if ( t - 12 < 10 ) 292 if ( t - 12 < 10 )
293 s = " "; 293 s = " ";
294 else 294 else
295 s = ""; 295 s = "";
296 s += QString::number( t - 12 ) + tr("p"); 296 s += QString::number( t - 12 ) + tr("p");
297 } else { 297 } else {
298 if ( 12 - t < 3 ) 298 if ( 12 - t < 3 )
299 s = ""; 299 s = "";
300 else 300 else
301 s = " "; 301 s = " ";
302 s += QString::number( t ); 302 s += QString::number( t );
303 } 303 }
304 } else { 304 } else {
305 s = QString::number( t ); 305 s = QString::number( t );
306 if ( s.length() == 1 ) 306 if ( s.length() == 1 )
307 s.prepend( "0" ); 307 s.prepend( "0" );
308 } 308 }
309 p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); 309 p->drawText( 1, y+p->fontMetrics().ascent()+1, s );
310 } 310 }
311 } 311 }
312 312
313 QListIterator<DateBookWeekItem> it(items); 313 QListIterator<DateBookWeekItem> it(items);
314 for ( ; it.current(); ++it ) { 314 for ( ; it.current(); ++it ) {
315 DateBookWeekItem *i = it.current(); 315 DateBookWeekItem *i = it.current();
316 if ( i->geometry().intersects( ur ) ) { 316 if ( i->geometry().intersects( ur ) ) {
317 p->setBrush( i->color() ); 317 p->setBrush( i->color() );
318 p->drawRect( i->geometry() ); 318 p->drawRect( i->geometry() );
319 } 319 }
320 } 320 }
321} 321}
322 322
323void DateBookWeekView::resizeEvent( QResizeEvent *e ) 323void DateBookWeekView::resizeEvent( QResizeEvent *e )
324{ 324{
325 const int hourWidth = 20; 325 const int hourWidth = 20;
326 QScrollView::resizeEvent( e ); 326 QScrollView::resizeEvent( e );
327 int avail = width()-qApp->style().scrollBarExtent().width()-1; 327 int avail = width()-qApp->style().scrollBarExtent().width()-1;
328 header->setGeometry( 0, 0, avail, header->sizeHint().height() ); 328 header->setGeometry( 0, 0, avail, header->sizeHint().height() );
329 setMargins( 0, header->height(), 0, 0 ); 329 setMargins( 0, header->height(), 0, 0 );
330 header->resizeSection( 0, hourWidth ); 330 header->resizeSection( 0, hourWidth );
331 int sw = (avail - hourWidth) / 7; 331 int sw = (avail - hourWidth) / 7;
332 for ( int i = 1; i < 7; i++ ) 332 for ( int i = 1; i < 7; i++ )
333 header->resizeSection( i, sw ); 333 header->resizeSection( i, sw );
334 header->resizeSection( 7, avail - hourWidth - sw*6 ); 334 header->resizeSection( 7, avail - hourWidth - sw*6 );
335} 335}
336 336
337void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) 337void DateBookWeekView::setStartOfWeek( bool bStartOnMonday )
338{ 338{
339 bOnMonday = bStartOnMonday; 339 bOnMonday = bStartOnMonday;
340 initNames(); 340 initNames();
341} 341}
342 342
343//------------------------------------------------------------------- 343//-------------------------------------------------------------------
344 344
345DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, 345DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB,
346 QWidget *parent, const char *name ) 346 QWidget *parent, const char *name )
347 : QWidget( parent, name ), 347 : QWidget( parent, name ),
348 db( newDB ), 348 db( newDB ),
349 startTime( 0 ), 349 startTime( 0 ),
350 ampm( ap ), 350 ampm( ap ),
351 bStartOnMonday( startOnMonday ) 351 bStartOnMonday( startOnMonday )
352{ 352{
353 setFocusPolicy(StrongFocus); 353 setFocusPolicy(StrongFocus);
354 QVBoxLayout *vb = new QVBoxLayout( this ); 354 QVBoxLayout *vb = new QVBoxLayout( this );
355 header = new DateBookWeekHeader( bStartOnMonday, this ); 355 header = new DateBookWeekHeader( bStartOnMonday, this );
356 view = new DateBookWeekView( ampm, startOnMonday, this ); 356 view = new DateBookWeekView( ampm, startOnMonday, this );
357 vb->addWidget( header ); 357 vb->addWidget( header );
358 vb->addWidget( view ); 358 vb->addWidget( view );
359 359
360 lblDesc = new QLabel( this, "event label" ); 360 lblDesc = new QLabel( this, "event label" );
361 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); 361 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box );
362 lblDesc->setBackgroundColor( yellow ); 362 lblDesc->setBackgroundColor( yellow );
363 lblDesc->hide(); 363 lblDesc->hide();
364 364
365 tHide = new QTimer( this ); 365 tHide = new QTimer( this );
366 366
367 connect( view, SIGNAL( showDay( int ) ), 367 connect( view, SIGNAL( showDay( int ) ),
368 this, SLOT( showDay( int ) ) ); 368 this, SLOT( showDay( int ) ) );
369 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), 369 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)),
370 this, SLOT(slotShowEvent(const EffectiveEvent&)) ); 370 this, SLOT(slotShowEvent(const EffectiveEvent&)) );
371 connect( view, SIGNAL(signalHideEvent()), 371 connect( view, SIGNAL(signalHideEvent()),
372 this, SLOT(slotHideEvent()) ); 372 this, SLOT(slotHideEvent()) );
373 connect( header, SIGNAL( dateChanged( int, int ) ), 373 connect( header, SIGNAL( dateChanged( int, int ) ),
374 this, SLOT( dateChanged( int, int ) ) ); 374 this, SLOT( dateChanged( int, int ) ) );
375 connect( tHide, SIGNAL( timeout() ), 375 connect( tHide, SIGNAL( timeout() ),
376 lblDesc, SLOT( hide() ) ); 376 lblDesc, SLOT( hide() ) );
377 connect( header->spinYear, SIGNAL(valueChanged(int)), 377 connect( header->spinYear, SIGNAL(valueChanged(int)),
378 this, SLOT(slotYearChanged(int)) ); 378 this, SLOT(slotYearChanged(int)) );
379 connect( qApp, SIGNAL(weekChanged(bool)), 379 connect( qApp, SIGNAL(weekChanged(bool)),
380 this, SLOT(slotWeekChanged(bool)) ); 380 this, SLOT(slotWeekChanged(bool)) );
381 connect( qApp, SIGNAL(clockChanged(bool)), 381 connect( qApp, SIGNAL(clockChanged(bool)),
382 this, SLOT(slotClockChanged(bool))); 382 this, SLOT(slotClockChanged(bool)));
383 setDate(QDate::currentDate()); 383 setDate(QDate::currentDate());
384 384
385} 385}
386 386
387void DateBookWeek::keyPressEvent(QKeyEvent *e) 387void DateBookWeek::keyPressEvent(QKeyEvent *e)
388{ 388{
389 switch(e->key()) { 389 switch(e->key()) {
390 case Key_Up: 390 case Key_Up:
391 view->scrollBy(0, -20); 391 view->scrollBy(0, -20);
392 break; 392 break;
393 case Key_Down: 393 case Key_Down:
394 view->scrollBy(0, 20); 394 view->scrollBy(0, 20);
395 break; 395 break;
396 case Key_Left: 396 case Key_Left:
397 setDate(date().addDays(-7)); 397 setDate(date().addDays(-7));
398 break; 398 break;
399 case Key_Right: 399 case Key_Right:
400 setDate(date().addDays(7)); 400 setDate(date().addDays(7));
401 break; 401 break;
402 default: 402 default:
403 e->ignore(); 403 e->ignore();
404 } 404 }
405} 405}
406 406
407void DateBookWeek::showDay( int day ) 407void DateBookWeek::showDay( int day )
408{ 408{
409 QDate d; 409 QDate d;
410 d = dateFromWeek( _week, year, bStartOnMonday ); 410 d = dateFromWeek( _week, year, bStartOnMonday );
411 day--; 411 day--;
412 d = d.addDays( day ); 412 d = d.addDays( day );
413 emit showDate( d.year(), d.month(), d.day() ); 413 emit showDate( d.year(), d.month(), d.day() );
414} 414}
415 415
416void DateBookWeek::setDate( int y, int m, int d ) 416void DateBookWeek::setDate( int y, int m, int d )
417{ 417{
418 QDate date; 418 QDate date;
419 date.setYMD( y, m, d ); 419 date.setYMD( y, m, d );
420 setDate(QDate(y, m, d)); 420 setDate(QDate(y, m, d));
421} 421}
422 422
423void DateBookWeek::setDate(QDate date) 423void DateBookWeek::setDate(QDate date)
424{ 424{
425 dow = date.dayOfWeek(); 425 dow = date.dayOfWeek();
426 int w, y; 426 int w, y;
427 calcWeek( date, w, y, bStartOnMonday ); 427 calcWeek( date, w, y, bStartOnMonday );
428 header->setDate( y, w ); 428 header->setDate( y, w );
429} 429}
430 430
431void DateBookWeek::dateChanged( int y, int w ) 431void DateBookWeek::dateChanged( int y, int w )
432{ 432{
433 year = y; 433 year = y;
434 _week = w; 434 _week = w;
435 getEvents(); 435 getEvents();
436} 436}
437 437
438QDate DateBookWeek::date() const 438QDate DateBookWeek::date() const
439{ 439{
440 QDate d; 440 QDate d;
441 d = dateFromWeek( _week - 1, year, bStartOnMonday ); 441 d = dateFromWeek( _week - 1, year, bStartOnMonday );
442 if ( bStartOnMonday ) 442 if ( bStartOnMonday )
443 d = d.addDays( 7 + dow - 1 ); 443 d = d.addDays( 7 + dow - 1 );
444 else { 444 else {
445 if ( dow == 7 ) 445 if ( dow == 7 )
446 d = d.addDays( dow ); 446 d = d.addDays( dow );
447 else 447 else
448 d = d.addDays( 7 + dow ); 448 d = d.addDays( 7 + dow );
449 } 449 }
450 return d; 450 return d;
451} 451}
452 452
453void DateBookWeek::getEvents() 453void DateBookWeek::getEvents()
454{ 454{
455 QDate startWeek = weekDate(); 455 QDate startWeek = weekDate();
456 456
457 QDate endWeek = startWeek.addDays( 6 ); 457 QDate endWeek = startWeek.addDays( 6 );
458 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, 458 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek,
459 endWeek); 459 endWeek);
460 view->showEvents( eventList ); 460 view->showEvents( eventList );
461 view->moveToHour( startTime ); 461 view->moveToHour( startTime );
462} 462}
463 463
464void DateBookWeek::generateAllDayTooltext( QString& text ) {
465 text += "<b>" + tr("This is an all day event.") + "</b><br>";
466}
467
468void DateBookWeek::generateNormalTooltext( QString& str,
469 const EffectiveEvent &ev ) {
470 str += "<b>" + QObject::tr("Start") + "</b>: ";
471
472 if ( ev.startDate() != ev.date() ) {
473 // multi-day event. Show start date
474 str += TimeString::longDateString( ev.startDate() );
475 } else {
476 // Show start time.
477 str += TimeString::timeString(ev.start(), ampm, FALSE );
478 }
479
480
481 str += "<br><b>" + QObject::tr("End") + "</b>: ";
482 if ( ev.endDate() != ev.date() ) {
483 // multi-day event. Show end date
484 str += TimeString::longDateString( ev.endDate() );
485 } else {
486 // Show end time.
487 str += TimeString::timeString( ev.end(), ampm, FALSE );
488 }
489}
490
464void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) 491void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
465{ 492{
466 if ( tHide->isActive() ) 493 if ( tHide->isActive() )
467 tHide->stop(); 494 tHide->stop();
468 495
469 // why would someone use "<"? Oh well, fix it up... 496 // why would someone use "<"? Oh well, fix it up...
470 // I wonder what other things may be messed up... 497 // I wonder what other things may be messed up...
471 QString strDesc = ev.description(); 498 QString strDesc = ev.description();
472 int where = strDesc.find( "<" ); 499 int where = strDesc.find( "<" );
473 while ( where != -1 ) { 500 while ( where != -1 ) {
474 strDesc.remove( where, 1 ); 501 strDesc.remove( where, 1 );
475 strDesc.insert( where, "&#60;" ); 502 strDesc.insert( where, "&#60;" );
476 where = strDesc.find( "<", where ); 503 where = strDesc.find( "<", where );
477 } 504 }
478 505
479 QString strCat; 506 QString strCat;
480 // ### FIX later... 507 // ### FIX later...
481// QString strCat = ev.category(); 508// QString strCat = ev.category();
482// where = strCat.find( "<" ); 509// where = strCat.find( "<" );
483// while ( where != -1 ) { 510// while ( where != -1 ) {
484 // strCat.remove( where, 1 ); 511 // strCat.remove( where, 1 );
485 // strCat.insert( where, "&#60;" ); 512 // strCat.insert( where, "&#60;" );
486 // where = strCat.find( "<", where ); 513 // where = strCat.find( "<", where );
487// } 514// }
488 515
489 QString strNote = ev.notes(); 516 QString strNote = ev.notes();
490 where = strNote.find( "<" ); 517 where = strNote.find( "<" );
491 while ( where != -1 ) { 518 while ( where != -1 ) {
492 strNote.remove( where, 1 ); 519 strNote.remove( where, 1 );
493 strNote.insert( where, "&#60;" ); 520 strNote.insert( where, "&#60;" );
494 where = strNote.find( "<", where ); 521 where = strNote.find( "<", where );
495 } 522 }
496 523
497 QString str = "<b>" + strDesc + "</b><br>" + "<i>" 524 QString str = "<b>" + strDesc + "</b><br>" + "<i>"
498 + strCat + "</i>" 525 + strCat + "</i>"
499 + "<br>" + TimeString::longDateString( ev.date() ) 526 + "<br>" + TimeString::longDateString( ev.date() )
500 + "<br><b>" + QObject::tr("Start") + "</b>: "; 527 + "<br>";
501 528
502 if ( ev.startDate() != ev.date() ) { 529 if (ev.event().type() == Event::Normal )
503 // multi-day event. Show start date 530 generateNormalTooltext( str, ev );
504 str += TimeString::longDateString( ev.startDate() ); 531 else
505 } else { 532 generateAllDayTooltext( str );
506 // Show start time.
507 str += TimeString::timeString(ev.start(), ampm, FALSE );
508 }
509 533
510 str += "<br><b>" + QObject::tr("End") + "</b>: ";
511 if ( ev.endDate() != ev.date() ) {
512 // multi-day event. Show end date
513 str += TimeString::longDateString( ev.endDate() );
514 } else {
515 // Show end time.
516 str += TimeString::timeString( ev.end(), ampm, FALSE );
517 }
518 str += "<br><br>" + strNote; 534 str += "<br><br>" + strNote;
519 535
520 lblDesc->setText( str ); 536 lblDesc->setText( str );
521 lblDesc->resize( lblDesc->sizeHint() ); 537 lblDesc->resize( lblDesc->sizeHint() );
522 // move the label so it is "centerd" horizontally... 538 // move the label so it is "centerd" horizontally...
523 lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 ); 539 lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 );
524 lblDesc->show(); 540 lblDesc->show();
525} 541}
526 542
527void DateBookWeek::slotHideEvent() 543void DateBookWeek::slotHideEvent()
528{ 544{
529 tHide->start( 2000, true ); 545 tHide->start( 2000, true );
530} 546}
531 547
532void DateBookWeek::setStartViewTime( int startHere ) 548void DateBookWeek::setStartViewTime( int startHere )
533{ 549{
534 startTime = startHere; 550 startTime = startHere;
535 view->moveToHour( startTime ); 551 view->moveToHour( startTime );
536} 552}
537 553
538int DateBookWeek::startViewTime() const 554int DateBookWeek::startViewTime() const
539{ 555{
540 return startTime; 556 return startTime;
541} 557}
542 558
543void DateBookWeek::redraw() 559void DateBookWeek::redraw()
544{ 560{
545 getEvents(); 561 getEvents();
546} 562}
547 563
548void DateBookWeek::slotYearChanged( int y ) 564void DateBookWeek::slotYearChanged( int y )
549{ 565{
550 int totWeek; 566 int totWeek;
551 QDate d( y, 12, 31 ); 567 QDate d( y, 12, 31 );
552 int throwAway; 568 int throwAway;
553 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 569 calcWeek( d, totWeek, throwAway, bStartOnMonday );
554 while ( totWeek == 1 ) { 570 while ( totWeek == 1 ) {
555 d = d.addDays( -1 ); 571 d = d.addDays( -1 );
556 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 572 calcWeek( d, totWeek, throwAway, bStartOnMonday );
557 } 573 }
558 if ( totWeek != totalWeeks() ) 574 if ( totWeek != totalWeeks() )
559 setTotalWeeks( totWeek ); 575 setTotalWeeks( totWeek );
560} 576}
561 577
562 578
563void DateBookWeek::setTotalWeeks( int numWeeks ) 579void DateBookWeek::setTotalWeeks( int numWeeks )
564{ 580{
565 header->spinWeek->setMaxValue( numWeeks ); 581 header->spinWeek->setMaxValue( numWeeks );
566} 582}
567 583
568int DateBookWeek::totalWeeks() const 584int DateBookWeek::totalWeeks() const
569{ 585{
570 return header->spinWeek->maxValue(); 586 return header->spinWeek->maxValue();
571} 587}
572 588
573void DateBookWeek::slotWeekChanged( bool onMonday ) 589void DateBookWeek::slotWeekChanged( bool onMonday )
574{ 590{
575 bStartOnMonday = onMonday; 591 bStartOnMonday = onMonday;
576 view->setStartOfWeek( bStartOnMonday ); 592 view->setStartOfWeek( bStartOnMonday );
577 header->setStartOfWeek( bStartOnMonday ); 593 header->setStartOfWeek( bStartOnMonday );
578 redraw(); 594 redraw();
579} 595}
580 596
581void DateBookWeek::slotClockChanged( bool ap ) 597void DateBookWeek::slotClockChanged( bool ap )
582{ 598{
583 ampm = ap; 599 ampm = ap;
584} 600}
585 601
586// return the date at the beginning of the week... 602// return the date at the beginning of the week...
587QDate DateBookWeek::weekDate() const 603QDate DateBookWeek::weekDate() const
588{ 604{
589 return dateFromWeek( _week, year, bStartOnMonday ); 605 return dateFromWeek( _week, year, bStartOnMonday );
590} 606}
591 607
592// this used to only be needed by datebook.cpp, but now we need it inside 608// this used to only be needed by datebook.cpp, but now we need it inside
593// week view since 609// week view since
594// we need to be able to figure out our total number of weeks on the fly... 610// we need to be able to figure out our total number of weeks on the fly...
595// this is probably the best place to put it.. 611// this is probably the best place to put it..
596 612
597// For Weeks that start on Monday... (EASY!) 613// For Weeks that start on Monday... (EASY!)
598// At the moment we will use ISO 8601 method for computing 614// At the moment we will use ISO 8601 method for computing
599// the week. Granted, other countries use other methods, 615// the week. Granted, other countries use other methods,
600// bet we aren't doing any Locale stuff at the moment. So, 616// bet we aren't doing any Locale stuff at the moment. So,
601// this should pass. This Algorithim is public domain and 617// this should pass. This Algorithim is public domain and
602// available at: 618// available at:
603// http://personal.ecu.edu/mccartyr/ISOwdALG.txt 619// http://personal.ecu.edu/mccartyr/ISOwdALG.txt
604// the week number is return, and the year number is returned in year 620// the week number is return, and the year number is returned in year
605// for Instance 2001/12/31 is actually the first week in 2002. 621// for Instance 2001/12/31 is actually the first week in 2002.
606// There is a more mathematical definition, but I will implement it when 622// There is a more mathematical definition, but I will implement it when
607// we are pass our deadline. 623// we are pass our deadline.
608 624
609// For Weeks that start on Sunday... (ahh... home rolled) 625// For Weeks that start on Sunday... (ahh... home rolled)
610// okay, if Jan 1 is on Friday or Saturday, 626// okay, if Jan 1 is on Friday or Saturday,
611// it will go to the pervious 627// it will go to the pervious
612// week... 628// week...
613 629
614bool calcWeek( const QDate &d, int &week, int &year, 630bool calcWeek( const QDate &d, int &week, int &year,
615 bool startOnMonday ) 631 bool startOnMonday )
616{ 632{
617 int weekNumber; 633 int weekNumber;
618 int yearNumber; 634 int yearNumber;
619 635
620 // remove a pesky warning, (Optimizations on g++) 636 // remove a pesky warning, (Optimizations on g++)
621 weekNumber = -1; 637 weekNumber = -1;
622 int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); 638 int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek();
623 int dayOfWeek = d.dayOfWeek(); 639 int dayOfWeek = d.dayOfWeek();
624 640
625 if ( !d.isValid() ) 641 if ( !d.isValid() )
626 return false; 642 return false;
627 643
628 if ( startOnMonday ) { 644 if ( startOnMonday ) {
629 // find the Jan1Weekday; 645 // find the Jan1Weekday;
630 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { 646 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) {
631 yearNumber = d.year() - 1; 647 yearNumber = d.year() - 1;
632 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) 648 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) )
633 weekNumber = 53; 649 weekNumber = 53;
634 else 650 else
635 weekNumber = 52; 651 weekNumber = 52;
636 } else 652 } else
637 yearNumber = d.year(); 653 yearNumber = d.year();
638 if ( yearNumber == d.year() ) { 654 if ( yearNumber == d.year() ) {
639 int totalDays = 365; 655 int totalDays = 365;
640 if ( QDate::leapYear(yearNumber) ) 656 if ( QDate::leapYear(yearNumber) )
641 totalDays++; 657 totalDays++;
642 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) 658 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) )
643 || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { 659 || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) {
644 yearNumber++; 660 yearNumber++;
645 weekNumber = 1; 661 weekNumber = 1;
646 } 662 }
647 } 663 }
648 if ( yearNumber == d.year() ) { 664 if ( yearNumber == d.year() ) {
649 int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); 665 int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 );
650 weekNumber = j / 7; 666 weekNumber = j / 7;
651 if ( jan1WeekDay > 4 ) 667 if ( jan1WeekDay > 4 )
652 weekNumber--; 668 weekNumber--;
653 } 669 }
654 } else { 670 } else {
655 // it's better to keep these cases separate... 671 // it's better to keep these cases separate...
656 if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 672 if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4
657 && jan1WeekDay != 7 ) { 673 && jan1WeekDay != 7 ) {
658 yearNumber = d.year() - 1; 674 yearNumber = d.year() - 1;
659 if ( jan1WeekDay == 6 675 if ( jan1WeekDay == 6
660 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { 676 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) {
661 weekNumber = 53; 677 weekNumber = 53;
662 }else 678 }else
663 weekNumber = 52; 679 weekNumber = 52;
664 } else 680 } else
665 yearNumber = d.year(); 681 yearNumber = d.year();
666 if ( yearNumber == d.year() ) { 682 if ( yearNumber == d.year() ) {
667 int totalDays = 365; 683 int totalDays = 365;
668 if ( QDate::leapYear( yearNumber ) ) 684 if ( QDate::leapYear( yearNumber ) )
669 totalDays++; 685 totalDays++;
670 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { 686 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) {
671 yearNumber++; 687 yearNumber++;
672 weekNumber = 1; 688 weekNumber = 1;
673 } 689 }
674 } 690 }
675 if ( yearNumber == d.year() ) { 691 if ( yearNumber == d.year() ) {
676 int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); 692 int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 );
677 weekNumber = j / 7; 693 weekNumber = j / 7;
678 if ( jan1WeekDay > 4 ) { 694 if ( jan1WeekDay > 4 ) {
679 weekNumber--; 695 weekNumber--;
680 } 696 }
681 } 697 }
682 } 698 }
683 year = yearNumber; 699 year = yearNumber;
684 week = weekNumber; 700 week = weekNumber;
685 return true; 701 return true;
686} 702}
687 703
diff --git a/core/pim/datebook/datebookweek.h b/core/pim/datebook/datebookweek.h
index 6e675f1..acbc2c7 100644
--- a/core/pim/datebook/datebookweek.h
+++ b/core/pim/datebook/datebookweek.h
@@ -1,152 +1,168 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef DATEBOOKWEEK 20#ifndef DATEBOOKWEEK
21#define DATEBOOKWEEK 21#define DATEBOOKWEEK
22 22
23#include <qpe/event.h> 23#include <qpe/event.h>
24 24
25#include <qlist.h> 25#include <qlist.h>
26#include <qscrollview.h> 26#include <qscrollview.h>
27#include <qstring.h> 27#include <qstring.h>
28#include <qvaluelist.h> 28#include <qvaluelist.h>
29 29
30class DateBookDB; 30class DateBookDB;
31class DateBookWeekHeader; 31class DateBookWeekHeader;
32class QDate; 32class QDate;
33class QLabel; 33class QLabel;
34class QResizeEvent; 34class QResizeEvent;
35class QSpinBox; 35class QSpinBox;
36class QTimer; 36class QTimer;
37class QHeader; 37class QHeader;
38 38
39class DateBookWeekItem 39class DateBookWeekItem
40{ 40{
41public: 41public:
42 DateBookWeekItem( const EffectiveEvent e ); 42 DateBookWeekItem( const EffectiveEvent e );
43 43
44 void setGeometry( int x, int y, int w, int h ); 44 void setGeometry( int x, int y, int w, int h );
45 QRect geometry() const { return r; } 45 QRect geometry() const { return r; }
46 46
47 const QColor &color() const { return c; } 47 const QColor &color() const { return c; }
48 const EffectiveEvent event() const { return ev; } 48 const EffectiveEvent event() const { return ev; }
49 49
50private: 50private:
51 const EffectiveEvent ev; 51 const EffectiveEvent ev;
52 QRect r; 52 QRect r;
53 QColor c; 53 QColor c;
54}; 54};
55 55
56class DateBookWeekView : public QScrollView 56class DateBookWeekView : public QScrollView
57{ 57{
58 Q_OBJECT 58 Q_OBJECT
59public: 59public:
60 DateBookWeekView( bool ampm, bool weekOnMonday, QWidget *parent = 0, 60 DateBookWeekView( bool ampm, bool weekOnMonday, QWidget *parent = 0,
61 const char *name = 0 ); 61 const char *name = 0 );
62 62
63 bool whichClock() const; 63 bool whichClock() const;
64 void showEvents( QValueList<EffectiveEvent> &ev ); 64 void showEvents( QValueList<EffectiveEvent> &ev );
65 void moveToHour( int h ); 65 void moveToHour( int h );
66 void setStartOfWeek( bool bOnMonday ); 66 void setStartOfWeek( bool bOnMonday );
67 67
68signals: 68signals:
69 void showDay( int d ); 69 void showDay( int d );
70 void signalShowEvent( const EffectiveEvent & ); 70 void signalShowEvent( const EffectiveEvent & );
71 void signalHideEvent(); 71 void signalHideEvent();
72 72
73protected slots: 73protected slots:
74 void keyPressEvent(QKeyEvent *); 74 void keyPressEvent(QKeyEvent *);
75 75
76private slots: 76private slots:
77 void slotChangeClock( bool ); 77 void slotChangeClock( bool );
78 void alterDay( int ); 78 void alterDay( int );
79 79
80private: 80private:
81 void positionItem( DateBookWeekItem *i ); 81 void positionItem( DateBookWeekItem *i );
82 DateBookWeekItem *intersects( const DateBookWeekItem * ); 82 DateBookWeekItem *intersects( const DateBookWeekItem * );
83 void drawContents( QPainter *p, int cx, int cy, int cw, int ch ); 83 void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
84 void contentsMousePressEvent( QMouseEvent * ); 84 void contentsMousePressEvent( QMouseEvent * );
85 void contentsMouseReleaseEvent( QMouseEvent * ); 85 void contentsMouseReleaseEvent( QMouseEvent * );
86 void resizeEvent( QResizeEvent * ); 86 void resizeEvent( QResizeEvent * );
87 void initNames(); 87 void initNames();
88 88
89private: 89private:
90 bool ampm; 90 bool ampm;
91 bool bOnMonday; 91 bool bOnMonday;
92 QHeader *header; 92 QHeader *header;
93 QList<DateBookWeekItem> items; 93 QList<DateBookWeekItem> items;
94 int rowHeight; 94 int rowHeight;
95 bool showingEvent; 95 bool showingEvent;
96}; 96};
97 97
98class DateBookWeek : public QWidget 98class DateBookWeek : public QWidget
99{ 99{
100 Q_OBJECT 100 Q_OBJECT
101 101
102public: 102public:
103 DateBookWeek( bool ampm, bool weekOnMonday, DateBookDB *newDB, 103 DateBookWeek( bool ampm, bool weekOnMonday, DateBookDB *newDB,
104 QWidget *parent = 0, const char *name = 0 ); 104 QWidget *parent = 0, const char *name = 0 );
105 void setDate( int y, int m, int d ); 105 void setDate( int y, int m, int d );
106 void setDate( QDate d ); 106 void setDate( QDate d );
107 QDate date() const; 107 QDate date() const;
108 DateBookWeekView *weekView() const { return view; } 108 DateBookWeekView *weekView() const { return view; }
109 void setStartViewTime( int startHere ); 109 void setStartViewTime( int startHere );
110 int startViewTime() const; 110 int startViewTime() const;
111 int week() const { return _week; }; 111 int week() const { return _week; };
112 void setTotalWeeks( int totalWeeks ); 112 void setTotalWeeks( int totalWeeks );
113 int totalWeeks() const; 113 int totalWeeks() const;
114 QDate weekDate() const; 114 QDate weekDate() const;
115 115
116public slots: 116public slots:
117 void redraw(); 117 void redraw();
118 void slotWeekChanged( bool bStartOnMonday ); 118 void slotWeekChanged( bool bStartOnMonday );
119 void slotClockChanged( bool a ); 119 void slotClockChanged( bool a );
120 120
121signals: 121signals:
122 void showDate( int y, int m, int d ); 122 void showDate( int y, int m, int d );
123 123
124protected slots: 124protected slots:
125 void keyPressEvent(QKeyEvent *); 125 void keyPressEvent(QKeyEvent *);
126 126
127private slots: 127private slots:
128 void showDay( int day ); 128 void showDay( int day );
129 void dateChanged( int y, int w ); 129 void dateChanged( int y, int w );
130 void slotShowEvent( const EffectiveEvent & ); 130 void slotShowEvent( const EffectiveEvent & );
131 void slotHideEvent(); 131 void slotHideEvent();
132 void slotYearChanged( int ); 132 void slotYearChanged( int );
133 133
134private: 134private:
135 void getEvents(); 135 void getEvents();
136
137 /**
138 * Wow that's a hell lot of code duplication
139 * in datebook. I vote for a common base class
140 * but never the less. This add a note
141 * that the Event is an all day event
142 *
143 */
144 void generateAllDayTooltext( QString& text );
145
146 /**
147 * This will add the times to the text
148 * It will be shown in the Tooltip bubble
149 */
150 void generateNormalTooltext( QString& text,
151 const EffectiveEvent &ev);
136 int year; 152 int year;
137 int _week; 153 int _week;
138 int dow; 154 int dow;
139 DateBookWeekHeader *header; 155 DateBookWeekHeader *header;
140 DateBookWeekView *view; 156 DateBookWeekView *view;
141 DateBookDB *db; 157 DateBookDB *db;
142 QLabel *lblDesc; 158 QLabel *lblDesc;
143 QTimer *tHide; 159 QTimer *tHide;
144 int startTime; 160 int startTime;
145 bool ampm; 161 bool ampm;
146 bool bStartOnMonday; 162 bool bStartOnMonday;
147}; 163};
148 164
149 165
150bool calcWeek( const QDate &d, int &week, int &year, 166bool calcWeek( const QDate &d, int &week, int &year,
151 bool startOnMonday = false ); 167 bool startOnMonday = false );
152#endif 168#endif
diff --git a/core/pim/datebook/datebookweeklst.cpp b/core/pim/datebook/datebookweeklst.cpp
index 29519c1..5eefc27 100644
--- a/core/pim/datebook/datebookweeklst.cpp
+++ b/core/pim/datebook/datebookweeklst.cpp
@@ -1,373 +1,376 @@
1#include "datebookweeklst.h" 1#include "datebookweeklst.h"
2 2
3#include "datebookweekheaderimpl.h" 3#include "datebookweekheaderimpl.h"
4 4
5#include <qpe/calendar.h> 5#include <qpe/calendar.h>
6#include <qpe/datebookdb.h> 6#include <qpe/datebookdb.h>
7#include <qpe/event.h> 7#include <qpe/event.h>
8#include <qpe/qpeapplication.h> 8#include <qpe/qpeapplication.h>
9#include <qpe/timestring.h> 9#include <qpe/timestring.h>
10#include <qpe/datebookmonth.h> 10#include <qpe/datebookmonth.h>
11#include <qpe/config.h> 11#include <qpe/config.h>
12 12
13#include <qdatetime.h> 13#include <qdatetime.h>
14#include <qheader.h> 14#include <qheader.h>
15#include <qlabel.h> 15#include <qlabel.h>
16#include <qlayout.h> 16#include <qlayout.h>
17#include <qpainter.h> 17#include <qpainter.h>
18#include <qpopupmenu.h> 18#include <qpopupmenu.h>
19#include <qtimer.h> 19#include <qtimer.h>
20#include <qstyle.h> 20#include <qstyle.h>
21#include <qtoolbutton.h> 21#include <qtoolbutton.h>
22#include <qvbox.h> 22#include <qvbox.h>
23#include <qsizepolicy.h> 23#include <qsizepolicy.h>
24#include <qabstractlayout.h> 24#include <qabstractlayout.h>
25#include <qtl.h> 25#include <qtl.h>
26 26
27bool calcWeek(const QDate &d, int &week, int &year, 27bool calcWeek(const QDate &d, int &week, int &year,
28 bool startOnMonday = false); 28 bool startOnMonday = false);
29 29
30DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, 30DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent,
31 const char* name, WFlags fl) 31 const char* name, WFlags fl)
32 : DateBookWeekLstHeaderBase(parent, name, fl) 32 : DateBookWeekLstHeaderBase(parent, name, fl)
33{ 33{
34 setBackgroundMode( PaletteButton ); 34 setBackgroundMode( PaletteButton );
35 labelDate->setBackgroundMode( PaletteButton ); 35 labelDate->setBackgroundMode( PaletteButton );
36 labelWeek->setBackgroundMode( PaletteButton ); 36 labelWeek->setBackgroundMode( PaletteButton );
37 forward->setBackgroundMode( PaletteButton ); 37 forward->setBackgroundMode( PaletteButton );
38 back->setBackgroundMode( PaletteButton ); 38 back->setBackgroundMode( PaletteButton );
39 DateBookWeekLstHeaderBaseLayout->setSpacing(0); 39 DateBookWeekLstHeaderBaseLayout->setSpacing(0);
40 DateBookWeekLstHeaderBaseLayout->setMargin(0); 40 DateBookWeekLstHeaderBaseLayout->setMargin(0);
41 //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); 41 //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding));
42 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 42 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
43 43
44 connect(back, SIGNAL(clicked()), this, SLOT(prevWeek())); 44 connect(back, SIGNAL(clicked()), this, SLOT(prevWeek()));
45 connect(forward, SIGNAL(clicked()), this, SLOT(nextWeek())); 45 connect(forward, SIGNAL(clicked()), this, SLOT(nextWeek()));
46 connect(labelWeek, SIGNAL(clicked()), this, SLOT(pickDate())); 46 connect(labelWeek, SIGNAL(clicked()), this, SLOT(pickDate()));
47 connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); 47 connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool)));
48 onMonday=onM; 48 onMonday=onM;
49} 49}
50DateBookWeekLstHeader::~DateBookWeekLstHeader(){} 50DateBookWeekLstHeader::~DateBookWeekLstHeader(){}
51void DateBookWeekLstHeader::setDate(const QDate &d) { 51void DateBookWeekLstHeader::setDate(const QDate &d) {
52 date=d; 52 date=d;
53 53
54 int year,week; 54 int year,week;
55 calcWeek(d,week,year,onMonday); 55 calcWeek(d,week,year,onMonday);
56 labelWeek->setText("W: " + QString::number(week)); 56 labelWeek->setText("W: " + QString::number(week));
57 57
58 QDate start=date; 58 QDate start=date;
59 QDate stop=start.addDays(6); 59 QDate stop=start.addDays(6);
60 labelDate->setText( QString::number(start.day()) + " " + 60 labelDate->setText( QString::number(start.day()) + " " +
61 start.monthName(start.month()) + " - " + 61 start.monthName(start.month()) + " - " +
62 QString::number(stop.day()) + " " + 62 QString::number(stop.day()) + " " +
63 start.monthName(stop.month()) ); 63 start.monthName(stop.month()) );
64 emit dateChanged(year,week); 64 emit dateChanged(year,week);
65} 65}
66void DateBookWeekLstHeader::pickDate() { 66void DateBookWeekLstHeader::pickDate() {
67 static QPopupMenu *m1 = 0; 67 static QPopupMenu *m1 = 0;
68 static DateBookMonth *picker = 0; 68 static DateBookMonth *picker = 0;
69 if ( !m1 ) { 69 if ( !m1 ) {
70 m1 = new QPopupMenu( this ); 70 m1 = new QPopupMenu( this );
71 picker = new DateBookMonth( m1, 0, TRUE ); 71 picker = new DateBookMonth( m1, 0, TRUE );
72 m1->insertItem( picker ); 72 m1->insertItem( picker );
73 connect( picker, SIGNAL( dateClicked( int, int, int ) ), 73 connect( picker, SIGNAL( dateClicked( int, int, int ) ),
74 this, SLOT( setDate( int, int, int ) ) ); 74 this, SLOT( setDate( int, int, int ) ) );
75 //connect( m1, SIGNAL( aboutToHide() ), 75 //connect( m1, SIGNAL( aboutToHide() ),
76 //this, SLOT( gotHide() ) ); 76 //this, SLOT( gotHide() ) );
77 } 77 }
78 picker->setDate( date.year(), date.month(), date.day() ); 78 picker->setDate( date.year(), date.month(), date.day() );
79 m1->popup(mapToGlobal(labelWeek->pos()+QPoint(0,labelWeek->height()))); 79 m1->popup(mapToGlobal(labelWeek->pos()+QPoint(0,labelWeek->height())));
80 picker->setFocus(); 80 picker->setFocus();
81} 81}
82void DateBookWeekLstHeader::setDate(int y, int m, int d) { 82void DateBookWeekLstHeader::setDate(int y, int m, int d) {
83 QDate new_date(y,m,d); 83 QDate new_date(y,m,d);
84 setDate(new_date); 84 setDate(new_date);
85} 85}
86 86
87void DateBookWeekLstHeader::nextWeek() { 87void DateBookWeekLstHeader::nextWeek() {
88 setDate(date.addDays(7)); 88 setDate(date.addDays(7));
89} 89}
90void DateBookWeekLstHeader::prevWeek() { 90void DateBookWeekLstHeader::prevWeek() {
91 setDate(date.addDays(-7)); 91 setDate(date.addDays(-7));
92} 92}
93 93
94DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/, 94DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/,
95 QWidget* parent, 95 QWidget* parent,
96 const char* name, 96 const char* name,
97 WFlags fl ) 97 WFlags fl )
98 : DateBookWeekLstDayHdrBase(parent, name, fl) { 98 : DateBookWeekLstDayHdrBase(parent, name, fl) {
99 99
100 date=d; 100 date=d;
101 101
102 static const char *wdays="MTWTFSS"; 102 static const char *wdays="MTWTFSS";
103 char day=wdays[d.dayOfWeek()-1]; 103 char day=wdays[d.dayOfWeek()-1];
104 104
105 label->setText( QString(QChar(day)) + " " + 105 label->setText( QString(QChar(day)) + " " +
106 QString::number(d.day()) ); 106 QString::number(d.day()) );
107 add->setText("+"); 107 add->setText("+");
108 108
109 if (d == QDate::currentDate()) { 109 if (d == QDate::currentDate()) {
110 QPalette pal=label->palette(); 110 QPalette pal=label->palette();
111 pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); 111 pal.setColor(QColorGroup::Foreground, QColor(0,0,255));
112 label->setPalette(pal); 112 label->setPalette(pal);
113 113
114 /* 114 /*
115 QFont f=label->font(); 115 QFont f=label->font();
116 f.setItalic(true); 116 f.setItalic(true);
117 label->setFont(f); 117 label->setFont(f);
118 label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); 118 label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor()));
119 */ 119 */
120 } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday 120 } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday
121 QPalette pal=label->palette(); 121 QPalette pal=label->palette();
122 pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); 122 pal.setColor(QColorGroup::Foreground, QColor(255,0,0));
123 label->setPalette(pal); 123 label->setPalette(pal);
124 } 124 }
125 125
126 126
127 connect (label, SIGNAL(clicked()), this, SLOT(showDay())); 127 connect (label, SIGNAL(clicked()), this, SLOT(showDay()));
128 connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); 128 connect (add, SIGNAL(clicked()), this, SLOT(newEvent()));
129} 129}
130 130
131void DateBookWeekLstDayHdr::showDay() { 131void DateBookWeekLstDayHdr::showDay() {
132 emit showDate(date.year(), date.month(), date.day()); 132 emit showDate(date.year(), date.month(), date.day());
133} 133}
134void DateBookWeekLstDayHdr::newEvent() { 134void DateBookWeekLstDayHdr::newEvent() {
135 QDateTime start, stop; 135 QDateTime start, stop;
136 start=stop=date; 136 start=stop=date;
137 start.setTime(QTime(10,0)); 137 start.setTime(QTime(10,0));
138 stop.setTime(QTime(12,0)); 138 stop.setTime(QTime(12,0));
139 139
140 emit addEvent(start,stop,""); 140 emit addEvent(start,stop,"");
141} 141}
142DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev, 142DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev,
143 QWidget* parent, 143 QWidget* parent,
144 const char* name, 144 const char* name,
145 WFlags fl) : 145 WFlags fl) :
146 OClickableLabel(parent,name,fl), 146 OClickableLabel(parent,name,fl),
147 event(ev) 147 event(ev)
148{ 148{
149 char s[10]; 149 char s[10];
150 if ( ev.startDate() != ev.date() ) { // multiday event (not first day) 150 if ( ev.startDate() != ev.date() ) { // multiday event (not first day)
151 if ( ev.endDate() == ev.date() ) { // last day 151 if ( ev.endDate() == ev.date() ) { // last day
152 strcpy(s, "__|__"); 152 strcpy(s, "__|__");
153 } else { 153 } else {
154 strcpy(s, " |---"); 154 strcpy(s, " |---");
155 } 155 }
156 } else { 156 } else {
157 sprintf(s,"%.2d:%.2d",ev.start().hour(),ev.start().minute()); 157 if(ev.event().type() == Event::Normal )
158 sprintf(s,"%.2d:%.2d",ev.start().hour(),ev.start().minute());
159 else
160 sprintf(s," ");
158 } 161 }
159 setText(QString(s) + " " + ev.description()); 162 setText(QString(s) + " " + ev.description());
160 connect(this, SIGNAL(clicked()), this, SLOT(editMe())); 163 connect(this, SIGNAL(clicked()), this, SLOT(editMe()));
161 setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); 164 setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) );
162} 165}
163void DateBookWeekLstEvent::editMe() { 166void DateBookWeekLstEvent::editMe() {
164 emit editEvent(event.event()); 167 emit editEvent(event.event());
165} 168}
166 169
167 170
168DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, 171DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev,
169 const QDate &d, bool onM, 172 const QDate &d, bool onM,
170 QWidget* parent, 173 QWidget* parent,
171 const char* name, WFlags fl) 174 const char* name, WFlags fl)
172 : QWidget( parent, name, fl ) 175 : QWidget( parent, name, fl )
173{ 176{
174 onMonday=onM; 177 onMonday=onM;
175 setPalette(white); 178 setPalette(white);
176 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); 179 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
177 180
178 QVBoxLayout *layout = new QVBoxLayout( this ); 181 QVBoxLayout *layout = new QVBoxLayout( this );
179 182
180 qBubbleSort(ev); 183 qBubbleSort(ev);
181 QValueListIterator<EffectiveEvent> it; 184 QValueListIterator<EffectiveEvent> it;
182 it=ev.begin(); 185 it=ev.begin();
183 186
184 int dayOrder[7]; 187 int dayOrder[7];
185 if (onMonday) 188 if (onMonday)
186 for (int d=0; d<7; d++) dayOrder[d]=d+1; 189 for (int d=0; d<7; d++) dayOrder[d]=d+1;
187 else { 190 else {
188 for (int d=0; d<7; d++) dayOrder[d]=d; 191 for (int d=0; d<7; d++) dayOrder[d]=d;
189 dayOrder[0]=7; 192 dayOrder[0]=7;
190 } 193 }
191 194
192 for (int i=0; i<7; i++) { 195 for (int i=0; i<7; i++) {
193 // Header 196 // Header
194 DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i), 197 DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i),
195 onMonday,this); 198 onMonday,this);
196 connect(hdr, SIGNAL(showDate(int,int,int)), 199 connect(hdr, SIGNAL(showDate(int,int,int)),
197 this, SIGNAL(showDate(int,int,int))); 200 this, SIGNAL(showDate(int,int,int)));
198 connect(hdr, SIGNAL(addEvent(const QDateTime &, 201 connect(hdr, SIGNAL(addEvent(const QDateTime &,
199 const QDateTime &, 202 const QDateTime &,
200 const QString &)), 203 const QString &)),
201 this, SIGNAL(addEvent(const QDateTime &, 204 this, SIGNAL(addEvent(const QDateTime &,
202 const QDateTime &, 205 const QDateTime &,
203 const QString &))); 206 const QString &)));
204 layout->addWidget(hdr); 207 layout->addWidget(hdr);
205 208
206 // Events 209 // Events
207 while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { 210 while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) {
208 DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,this); 211 DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,this);
209 layout->addWidget(l); 212 layout->addWidget(l);
210 connect (l, SIGNAL(editEvent(const Event &)), 213 connect (l, SIGNAL(editEvent(const Event &)),
211 this, SIGNAL(editEvent(const Event &))); 214 this, SIGNAL(editEvent(const Event &)));
212 it++; 215 it++;
213 } 216 }
214 217
215 layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); 218 layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding));
216 } 219 }
217} 220}
218DateBookWeekLstView::~DateBookWeekLstView(){} 221DateBookWeekLstView::~DateBookWeekLstView(){}
219void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} 222void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();}
220 223
221DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, 224DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1,
222 QValueList<EffectiveEvent> &ev2, 225 QValueList<EffectiveEvent> &ev2,
223 QDate &d, bool onM, 226 QDate &d, bool onM,
224 QWidget* parent, 227 QWidget* parent,
225 const char* name, WFlags fl) 228 const char* name, WFlags fl)
226 : QWidget( parent, name, fl ) 229 : QWidget( parent, name, fl )
227{ 230{
228 QHBoxLayout *layout = new QHBoxLayout( this ); 231 QHBoxLayout *layout = new QHBoxLayout( this );
229 232
230 DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this); 233 DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this);
231 layout->addWidget(w); 234 layout->addWidget(w);
232 connect (w, SIGNAL(editEvent(const Event &)), 235 connect (w, SIGNAL(editEvent(const Event &)),
233 this, SIGNAL(editEvent(const Event &))); 236 this, SIGNAL(editEvent(const Event &)));
234 connect (w, SIGNAL(showDate(int,int,int)), 237 connect (w, SIGNAL(showDate(int,int,int)),
235 this, SIGNAL(showDate(int,int,int))); 238 this, SIGNAL(showDate(int,int,int)));
236 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, 239 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &,
237 const QString &)), 240 const QString &)),
238 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, 241 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &,
239 const QString &))); 242 const QString &)));
240 243
241 244
242 w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); 245 w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this);
243 layout->addWidget(w); 246 layout->addWidget(w);
244 connect (w, SIGNAL(editEvent(const Event &)), 247 connect (w, SIGNAL(editEvent(const Event &)),
245 this, SIGNAL(editEvent(const Event &))); 248 this, SIGNAL(editEvent(const Event &)));
246 connect (w, SIGNAL(showDate(int,int,int)), 249 connect (w, SIGNAL(showDate(int,int,int)),
247 this, SIGNAL(showDate(int,int,int))); 250 this, SIGNAL(showDate(int,int,int)));
248 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, 251 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &,
249 const QString &)), 252 const QString &)),
250 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, 253 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &,
251 const QString &))); 254 const QString &)));
252} 255}
253 256
254DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, 257DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB,
255 QWidget *parent, 258 QWidget *parent,
256 const char *name ) 259 const char *name )
257 : QWidget( parent, name ), 260 : QWidget( parent, name ),
258 db( newDB ), 261 db( newDB ),
259 startTime( 0 ), 262 startTime( 0 ),
260 ampm( ap ), 263 ampm( ap ),
261 onMonday(onM) 264 onMonday(onM)
262{ 265{
263 setFocusPolicy(StrongFocus); 266 setFocusPolicy(StrongFocus);
264 layout = new QVBoxLayout( this ); 267 layout = new QVBoxLayout( this );
265 layout->setMargin(0); 268 layout->setMargin(0);
266 269
267 header=new DateBookWeekLstHeader(onM, this); 270 header=new DateBookWeekLstHeader(onM, this);
268 layout->addWidget( header ); 271 layout->addWidget( header );
269 connect(header, SIGNAL(dateChanged(int,int)), 272 connect(header, SIGNAL(dateChanged(int,int)),
270 this, SLOT(dateChanged(int,int))); 273 this, SLOT(dateChanged(int,int)));
271 connect(header, SIGNAL(setDbl(bool)), 274 connect(header, SIGNAL(setDbl(bool)),
272 this, SLOT(setDbl(bool))); 275 this, SLOT(setDbl(bool)));
273 276
274 scroll=new QScrollView(this); 277 scroll=new QScrollView(this);
275 //scroll->setVScrollBarMode(QScrollView::AlwaysOn); 278 //scroll->setVScrollBarMode(QScrollView::AlwaysOn);
276 //scroll->setHScrollBarMode(QScrollView::AlwaysOff); 279 //scroll->setHScrollBarMode(QScrollView::AlwaysOff);
277 scroll->setResizePolicy(QScrollView::AutoOneFit); 280 scroll->setResizePolicy(QScrollView::AutoOneFit);
278 layout->addWidget(scroll); 281 layout->addWidget(scroll);
279 282
280 view=NULL; 283 view=NULL;
281 Config config("DateBook"); 284 Config config("DateBook");
282 config.setGroup("Main"); 285 config.setGroup("Main");
283 dbl=config.readBoolEntry("weeklst_dbl", false); 286 dbl=config.readBoolEntry("weeklst_dbl", false);
284 header->dbl->setOn(dbl); 287 header->dbl->setOn(dbl);
285} 288}
286DateBookWeekLst::~DateBookWeekLst(){ 289DateBookWeekLst::~DateBookWeekLst(){
287 Config config("DateBook"); 290 Config config("DateBook");
288 config.setGroup("Main"); 291 config.setGroup("Main");
289 config.writeEntry("weeklst_dbl", dbl); 292 config.writeEntry("weeklst_dbl", dbl);
290} 293}
291 294
292void DateBookWeekLst::setDate(const QDate &d) { 295void DateBookWeekLst::setDate(const QDate &d) {
293 int w,y; 296 int w,y;
294 calcWeek(d,w,y,onMonday); 297 calcWeek(d,w,y,onMonday);
295 year=y; 298 year=y;
296 _week=w; 299 _week=w;
297 header->setDate(date()); 300 header->setDate(date());
298} 301}
299void DateBookWeekLst::setDbl(bool on) { 302void DateBookWeekLst::setDbl(bool on) {
300 dbl=on; 303 dbl=on;
301 redraw(); 304 redraw();
302} 305}
303void DateBookWeekLst::redraw() {getEvents();} 306void DateBookWeekLst::redraw() {getEvents();}
304 307
305QDate DateBookWeekLst::date() const { 308QDate DateBookWeekLst::date() const {
306 QDate d; 309 QDate d;
307 d.setYMD(year,1,1); 310 d.setYMD(year,1,1);
308 311
309 int dow= d.dayOfWeek(); 312 int dow= d.dayOfWeek();
310 if (!onMonday) 313 if (!onMonday)
311 if (dow==7) dow=1; 314 if (dow==7) dow=1;
312 else dow++; 315 else dow++;
313 316
314 d=d.addDays( (_week-1)*7 - dow + 1 ); 317 d=d.addDays( (_week-1)*7 - dow + 1 );
315 return d; 318 return d;
316} 319}
317 320
318void DateBookWeekLst::getEvents() { 321void DateBookWeekLst::getEvents() {
319 QDate start = date(); 322 QDate start = date();
320 QDate stop = start.addDays(6); 323 QDate stop = start.addDays(6);
321 QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); 324 QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop);
322 325
323 if (view) delete view; 326 if (view) delete view;
324 if (dbl) { 327 if (dbl) {
325 QDate start2=start.addDays(7); 328 QDate start2=start.addDays(7);
326 stop=start2.addDays(6); 329 stop=start2.addDays(6);
327 QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); 330 QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop);
328 331
329 view=new DateBookWeekLstDblView(el,el2,start,onMonday,scroll); 332 view=new DateBookWeekLstDblView(el,el2,start,onMonday,scroll);
330 } else { 333 } else {
331 view=new DateBookWeekLstView(el,start,onMonday,scroll); 334 view=new DateBookWeekLstView(el,start,onMonday,scroll);
332 } 335 }
333 336
334 connect (view, SIGNAL(editEvent(const Event &)), 337 connect (view, SIGNAL(editEvent(const Event &)),
335 this, SIGNAL(editEvent(const Event &))); 338 this, SIGNAL(editEvent(const Event &)));
336 connect (view, SIGNAL(showDate(int,int,int)), 339 connect (view, SIGNAL(showDate(int,int,int)),
337 this, SIGNAL(showDate(int,int,int))); 340 this, SIGNAL(showDate(int,int,int)));
338 connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &, 341 connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &,
339 const QString &)), 342 const QString &)),
340 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, 343 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &,
341 const QString &))); 344 const QString &)));
342 345
343 scroll->addChild(view); 346 scroll->addChild(view);
344 view->show(); 347 view->show();
345 scroll->updateScrollBars(); 348 scroll->updateScrollBars();
346} 349}
347 350
348void DateBookWeekLst::dateChanged(int y, int w) { 351void DateBookWeekLst::dateChanged(int y, int w) {
349 year=y; 352 year=y;
350 _week=w; 353 _week=w;
351 getEvents(); 354 getEvents();
352} 355}
353 356
354void DateBookWeekLst::keyPressEvent(QKeyEvent *e) 357void DateBookWeekLst::keyPressEvent(QKeyEvent *e)
355{ 358{
356 switch(e->key()) { 359 switch(e->key()) {
357 case Key_Up: 360 case Key_Up:
358 scroll->scrollBy(0, -20); 361 scroll->scrollBy(0, -20);
359 break; 362 break;
360 case Key_Down: 363 case Key_Down:
361 scroll->scrollBy(0, 20); 364 scroll->scrollBy(0, 20);
362 break; 365 break;
363 case Key_Left: 366 case Key_Left:
364 header->prevWeek(); 367 header->prevWeek();
365 break; 368 break;
366 case Key_Right: 369 case Key_Right:
367 header->nextWeek(); 370 header->nextWeek();
368 break; 371 break;
369 default: 372 default:
370 e->ignore(); 373 e->ignore();
371 } 374 }
372} 375}
373 376