summaryrefslogtreecommitdiff
authorumopapisdn <umopapisdn>2003-03-23 19:55:23 (UTC)
committer umopapisdn <umopapisdn>2003-03-23 19:55:23 (UTC)
commitdfa17505b14011b50822d50c925cc6aa0299b1b4 (patch) (unidiff)
tree1445d0e8dcc4762cc93d666007564af0525aac37
parent46c09d5732bcac4de2be5dfbf17bee054aba9478 (diff)
downloadopie-dfa17505b14011b50822d50c925cc6aa0299b1b4.zip
opie-dfa17505b14011b50822d50c925cc6aa0299b1b4.tar.gz
opie-dfa17505b14011b50822d50c925cc6aa0299b1b4.tar.bz2
Bugfix: (bug #0000211) Events ending at midnight shouldn't be displayed at the following day. Fix for weekview.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebookweek.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp
index e30c776..5bbf86a 100644
--- a/core/pim/datebook/datebookweek.cpp
+++ b/core/pim/datebook/datebookweek.cpp
@@ -1,657 +1,659 @@
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 if(!(i->event().end().hour()==i->event().start().hour() && i->event().end().minute()==i->event().start().minute())) {// Skip effective events with no duration. (i.e ending at 00:00)
143 items.append( i ); 143 positionItem( i );
144 } 144 items.append( i );
145 viewport()->update(); 145 }
146 }
147 viewport()->update();
146} 148}
147 149
148void DateBookWeekView::moveToHour( int h ) 150void DateBookWeekView::moveToHour( int h )
149{ 151{
150 int offset = h*rowHeight; 152 int offset = h*rowHeight;
151 setContentsPos( 0, offset ); 153 setContentsPos( 0, offset );
152} 154}
153 155
154void DateBookWeekView::keyPressEvent( QKeyEvent *e ) 156void DateBookWeekView::keyPressEvent( QKeyEvent *e )
155{ 157{
156 e->ignore(); 158 e->ignore();
157} 159}
158 160
159void DateBookWeekView::slotChangeClock( bool c ) 161void DateBookWeekView::slotChangeClock( bool c )
160{ 162{
161 ampm = c; 163 ampm = c;
162 viewport()->update(); 164 viewport()->update();
163} 165}
164 166
165static inline int db_round30min( int m ) 167static inline int db_round30min( int m )
166{ 168{
167 if ( m < 15 ) 169 if ( m < 15 )
168 m = 0; 170 m = 0;
169 else if ( m < 45 ) 171 else if ( m < 45 )
170 m = 1; 172 m = 1;
171 else 173 else
172 m = 2; 174 m = 2;
173 175
174 return m; 176 return m;
175} 177}
176 178
177void DateBookWeekView::alterDay( int day ) 179void DateBookWeekView::alterDay( int day )
178{ 180{
179 if ( !bOnMonday ) { 181 if ( !bOnMonday ) {
180 day--; 182 day--;
181 } 183 }
182 emit showDay( day ); 184 emit showDay( day );
183} 185}
184 186
185void DateBookWeekView::positionItem( DateBookWeekItem *i ) 187void DateBookWeekView::positionItem( DateBookWeekItem *i )
186{ 188{
187 const int Width = 8; 189 const int Width = 8;
188 const EffectiveEvent ev = i->event(); 190 const EffectiveEvent ev = i->event();
189 191
190 // 30 minute intervals 192 // 30 minute intervals
191 int y = ev.start().hour() * 2; 193 int y = ev.start().hour() * 2;
192 y += db_round30min( ev.start().minute() ); 194 y += db_round30min( ev.start().minute() );
193 int y2 = ev.end().hour() * 2; 195 int y2 = ev.end().hour() * 2;
194 y2 += db_round30min( ev.end().minute() ); 196 y2 += db_round30min( ev.end().minute() );
195 if ( y > 47 ) 197 if ( y > 47 )
196 y = 47; 198 y = 47;
197 if ( y2 > 48 ) 199 if ( y2 > 48 )
198 y2 = 48; 200 y2 = 48;
199 y = y * rowHeight / 2; 201 y = y * rowHeight / 2;
200 y2 = y2 * rowHeight / 2; 202 y2 = y2 * rowHeight / 2;
201 203
202 int h; 204 int h;
203 if ( ev.event().type() == Event::AllDay ) { 205 if ( ev.event().type() == Event::AllDay ) {
204 h = 48 * rowHeight / 2; 206 h = 48 * rowHeight / 2;
205 y = 0; 207 y = 0;
206 } else { 208 } else {
207 h=y2-y; 209 h=y2-y;
208 if ( h < 1 ) h = 1; 210 if ( h < 1 ) h = 1;
209 } 211 }
210 212
211 int dow = ev.date().dayOfWeek(); 213 int dow = ev.date().dayOfWeek();
212 if ( !bOnMonday ) { 214 if ( !bOnMonday ) {
213 if ( dow == 7 ) 215 if ( dow == 7 )
214 dow = 1; 216 dow = 1;
215 else 217 else
216 dow++; 218 dow++;
217 } 219 }
218 int x = header->sectionPos( dow ) - 1; 220 int x = header->sectionPos( dow ) - 1;
219 int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); 221 int xlim = header->sectionPos( dow ) + header->sectionSize( dow );
220 DateBookWeekItem *isect = 0; 222 DateBookWeekItem *isect = 0;
221 do { 223 do {
222 i->setGeometry( x, y, Width, h ); 224 i->setGeometry( x, y, Width, h );
223 isect = intersects( i ); 225 isect = intersects( i );
224 x += Width - 1; 226 x += Width - 1;
225 } while ( isect && x < xlim ); 227 } while ( isect && x < xlim );
226} 228}
227 229
228DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) 230DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item )
229{ 231{
230 QRect geom = item->geometry(); 232 QRect geom = item->geometry();
231 233
232 // We allow the edges to overlap 234 // We allow the edges to overlap
233 geom.moveBy( 1, 1 ); 235 geom.moveBy( 1, 1 );
234 geom.setSize( geom.size()-QSize(2,2) ); 236 geom.setSize( geom.size()-QSize(2,2) );
235 237
236 QListIterator<DateBookWeekItem> it(items); 238 QListIterator<DateBookWeekItem> it(items);
237 for ( ; it.current(); ++it ) { 239 for ( ; it.current(); ++it ) {
238 DateBookWeekItem *i = it.current(); 240 DateBookWeekItem *i = it.current();
239 if ( i != item ) { 241 if ( i != item ) {
240 if ( i->geometry().intersects( geom ) ) { 242 if ( i->geometry().intersects( geom ) ) {
241 return i; 243 return i;
242 } 244 }
243 } 245 }
244 } 246 }
245 247
246 return 0; 248 return 0;
247} 249}
248 250
249void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) 251void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e )
250{ 252{
251 QListIterator<DateBookWeekItem> it(items); 253 QListIterator<DateBookWeekItem> it(items);
252 for ( ; it.current(); ++it ) { 254 for ( ; it.current(); ++it ) {
253 DateBookWeekItem *i = it.current(); 255 DateBookWeekItem *i = it.current();
254 if ( i->geometry().contains( e->pos() ) ) { 256 if ( i->geometry().contains( e->pos() ) ) {
255 showingEvent = true; 257 showingEvent = true;
256 emit signalShowEvent( i->event() ); 258 emit signalShowEvent( i->event() );
257 break; 259 break;
258 } 260 }
259 } 261 }
260} 262}
261 263
262void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) 264void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e )
263{ 265{
264 if ( showingEvent ) { 266 if ( showingEvent ) {
265 showingEvent = false; 267 showingEvent = false;
266 emit signalHideEvent(); 268 emit signalHideEvent();
267 } else { 269 } else {
268 int d = header->sectionAt( e->pos().x() ); 270 int d = header->sectionAt( e->pos().x() );
269 if ( d > 0 ) { 271 if ( d > 0 ) {
270 // if ( !bOnMonday ) 272 // if ( !bOnMonday )
271 // d--; 273 // d--;
272 emit showDay( d ); 274 emit showDay( d );
273 } 275 }
274 } 276 }
275} 277}
276 278
277void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) 279void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
278{ 280{
279 QRect ur( cx, cy, cw, ch ); 281 QRect ur( cx, cy, cw, ch );
280 p->setPen( lightGray ); 282 p->setPen( lightGray );
281 for ( int i = 1; i <= 7; i++ ) 283 for ( int i = 1; i <= 7; i++ )
282 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); 284 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch );
283 285
284 p->setPen( black ); 286 p->setPen( black );
285 for ( int t = 0; t < 24; t++ ) { 287 for ( int t = 0; t < 24; t++ ) {
286 int y = t*rowHeight; 288 int y = t*rowHeight;
287 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { 289 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) {
288 QString s; 290 QString s;
289 if ( ampm ) { 291 if ( ampm ) {
290 if ( t == 0 ) 292 if ( t == 0 )
291 s = QString::number( 12 ); 293 s = QString::number( 12 );
292 else if ( t == 12 ) 294 else if ( t == 12 )
293 s = QString::number(12) + tr( "p" ); 295 s = QString::number(12) + tr( "p" );
294 else if ( t > 12 ) { 296 else if ( t > 12 ) {
295 if ( t - 12 < 10 ) 297 if ( t - 12 < 10 )
296 s = " "; 298 s = " ";
297 else 299 else
298 s = ""; 300 s = "";
299 s += QString::number( t - 12 ) + tr("p"); 301 s += QString::number( t - 12 ) + tr("p");
300 } else { 302 } else {
301 if ( 12 - t < 3 ) 303 if ( 12 - t < 3 )
302 s = ""; 304 s = "";
303 else 305 else
304 s = " "; 306 s = " ";
305 s += QString::number( t ); 307 s += QString::number( t );
306 } 308 }
307 } else { 309 } else {
308 s = QString::number( t ); 310 s = QString::number( t );
309 if ( s.length() == 1 ) 311 if ( s.length() == 1 )
310 s.prepend( "0" ); 312 s.prepend( "0" );
311 } 313 }
312 p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); 314 p->drawText( 1, y+p->fontMetrics().ascent()+1, s );
313 } 315 }
314 } 316 }
315 317
316 QListIterator<DateBookWeekItem> it(items); 318 QListIterator<DateBookWeekItem> it(items);
317 for ( ; it.current(); ++it ) { 319 for ( ; it.current(); ++it ) {
318 DateBookWeekItem *i = it.current(); 320 DateBookWeekItem *i = it.current();
319 if ( i->geometry().intersects( ur ) ) { 321 if ( i->geometry().intersects( ur ) ) {
320 p->setBrush( i->color() ); 322 p->setBrush( i->color() );
321 p->drawRect( i->geometry() ); 323 p->drawRect( i->geometry() );
322 } 324 }
323 } 325 }
324} 326}
325 327
326void DateBookWeekView::resizeEvent( QResizeEvent *e ) 328void DateBookWeekView::resizeEvent( QResizeEvent *e )
327{ 329{
328 const int hourWidth = 20; 330 const int hourWidth = 20;
329 QScrollView::resizeEvent( e ); 331 QScrollView::resizeEvent( e );
330 int avail = width()-qApp->style().scrollBarExtent().width()-1; 332 int avail = width()-qApp->style().scrollBarExtent().width()-1;
331 header->setGeometry( 0, 0, avail, header->sizeHint().height() ); 333 header->setGeometry( 0, 0, avail, header->sizeHint().height() );
332 setMargins( 0, header->height(), 0, 0 ); 334 setMargins( 0, header->height(), 0, 0 );
333 header->resizeSection( 0, hourWidth ); 335 header->resizeSection( 0, hourWidth );
334 int sw = (avail - hourWidth) / 7; 336 int sw = (avail - hourWidth) / 7;
335 for ( int i = 1; i < 7; i++ ) 337 for ( int i = 1; i < 7; i++ )
336 header->resizeSection( i, sw ); 338 header->resizeSection( i, sw );
337 header->resizeSection( 7, avail - hourWidth - sw*6 ); 339 header->resizeSection( 7, avail - hourWidth - sw*6 );
338} 340}
339 341
340void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) 342void DateBookWeekView::setStartOfWeek( bool bStartOnMonday )
341{ 343{
342 bOnMonday = bStartOnMonday; 344 bOnMonday = bStartOnMonday;
343 initNames(); 345 initNames();
344} 346}
345 347
346//------------------------------------------------------------------- 348//-------------------------------------------------------------------
347 349
348DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, 350DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB,
349 QWidget *parent, const char *name ) 351 QWidget *parent, const char *name )
350 : QWidget( parent, name ), 352 : QWidget( parent, name ),
351 db( newDB ), 353 db( newDB ),
352 startTime( 0 ), 354 startTime( 0 ),
353 ampm( ap ), 355 ampm( ap ),
354 bStartOnMonday( startOnMonday ) 356 bStartOnMonday( startOnMonday )
355{ 357{
356 setFocusPolicy(StrongFocus); 358 setFocusPolicy(StrongFocus);
357 QVBoxLayout *vb = new QVBoxLayout( this ); 359 QVBoxLayout *vb = new QVBoxLayout( this );
358 header = new DateBookWeekHeader( bStartOnMonday, this ); 360 header = new DateBookWeekHeader( bStartOnMonday, this );
359 view = new DateBookWeekView( ampm, startOnMonday, this ); 361 view = new DateBookWeekView( ampm, startOnMonday, this );
360 vb->addWidget( header ); 362 vb->addWidget( header );
361 vb->addWidget( view ); 363 vb->addWidget( view );
362 364
363 lblDesc = new QLabel( this, "event label" ); 365 lblDesc = new QLabel( this, "event label" );
364 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); 366 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box );
365 lblDesc->setBackgroundColor( yellow ); 367 lblDesc->setBackgroundColor( yellow );
366 lblDesc->hide(); 368 lblDesc->hide();
367 369
368 tHide = new QTimer( this ); 370 tHide = new QTimer( this );
369 371
370 connect( view, SIGNAL( showDay( int ) ), 372 connect( view, SIGNAL( showDay( int ) ),
371 this, SLOT( showDay( int ) ) ); 373 this, SLOT( showDay( int ) ) );
372 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), 374 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)),
373 this, SLOT(slotShowEvent(const EffectiveEvent&)) ); 375 this, SLOT(slotShowEvent(const EffectiveEvent&)) );
374 connect( view, SIGNAL(signalHideEvent()), 376 connect( view, SIGNAL(signalHideEvent()),
375 this, SLOT(slotHideEvent()) ); 377 this, SLOT(slotHideEvent()) );
376 connect( header, SIGNAL( dateChanged( int, int ) ), 378 connect( header, SIGNAL( dateChanged( int, int ) ),
377 this, SLOT( dateChanged( int, int ) ) ); 379 this, SLOT( dateChanged( int, int ) ) );
378 connect( tHide, SIGNAL( timeout() ), 380 connect( tHide, SIGNAL( timeout() ),
379 lblDesc, SLOT( hide() ) ); 381 lblDesc, SLOT( hide() ) );
380 connect( header->spinYear, SIGNAL(valueChanged(int)), 382 connect( header->spinYear, SIGNAL(valueChanged(int)),
381 this, SLOT(slotYearChanged(int)) ); 383 this, SLOT(slotYearChanged(int)) );
382 connect( qApp, SIGNAL(weekChanged(bool)), 384 connect( qApp, SIGNAL(weekChanged(bool)),
383 this, SLOT(slotWeekChanged(bool)) ); 385 this, SLOT(slotWeekChanged(bool)) );
384 connect( qApp, SIGNAL(clockChanged(bool)), 386 connect( qApp, SIGNAL(clockChanged(bool)),
385 this, SLOT(slotClockChanged(bool))); 387 this, SLOT(slotClockChanged(bool)));
386 setDate(QDate::currentDate()); 388 setDate(QDate::currentDate());
387 389
388} 390}
389 391
390void DateBookWeek::keyPressEvent(QKeyEvent *e) 392void DateBookWeek::keyPressEvent(QKeyEvent *e)
391{ 393{
392 switch(e->key()) { 394 switch(e->key()) {
393 case Key_Up: 395 case Key_Up:
394 view->scrollBy(0, -20); 396 view->scrollBy(0, -20);
395 break; 397 break;
396 case Key_Down: 398 case Key_Down:
397 view->scrollBy(0, 20); 399 view->scrollBy(0, 20);
398 break; 400 break;
399 case Key_Left: 401 case Key_Left:
400 setDate(date().addDays(-7)); 402 setDate(date().addDays(-7));
401 break; 403 break;
402 case Key_Right: 404 case Key_Right:
403 setDate(date().addDays(7)); 405 setDate(date().addDays(7));
404 break; 406 break;
405 default: 407 default:
406 e->ignore(); 408 e->ignore();
407 } 409 }
408} 410}
409 411
410void DateBookWeek::showDay( int day ) 412void DateBookWeek::showDay( int day )
411{ 413{
412 QDate d; 414 QDate d;
413 d = dateFromWeek( _week, year, bStartOnMonday ); 415 d = dateFromWeek( _week, year, bStartOnMonday );
414 day--; 416 day--;
415 d = d.addDays( day ); 417 d = d.addDays( day );
416 emit showDate( d.year(), d.month(), d.day() ); 418 emit showDate( d.year(), d.month(), d.day() );
417} 419}
418 420
419void DateBookWeek::setDate( int y, int m, int d ) 421void DateBookWeek::setDate( int y, int m, int d )
420{ 422{
421 QDate date; 423 QDate date;
422 date.setYMD( y, m, d ); 424 date.setYMD( y, m, d );
423 setDate(QDate(y, m, d)); 425 setDate(QDate(y, m, d));
424} 426}
425 427
426void DateBookWeek::setDate(QDate date) 428void DateBookWeek::setDate(QDate date)
427{ 429{
428 dow = date.dayOfWeek(); 430 dow = date.dayOfWeek();
429 int w, y; 431 int w, y;
430 calcWeek( date, w, y, bStartOnMonday ); 432 calcWeek( date, w, y, bStartOnMonday );
431 header->setDate( y, w ); 433 header->setDate( y, w );
432} 434}
433 435
434void DateBookWeek::dateChanged( int y, int w ) 436void DateBookWeek::dateChanged( int y, int w )
435{ 437{
436 year = y; 438 year = y;
437 _week = w; 439 _week = w;
438 getEvents(); 440 getEvents();
439} 441}
440 442
441QDate DateBookWeek::date() const 443QDate DateBookWeek::date() const
442{ 444{
443 QDate d; 445 QDate d;
444 d = dateFromWeek( _week - 1, year, bStartOnMonday ); 446 d = dateFromWeek( _week - 1, year, bStartOnMonday );
445 if ( bStartOnMonday ) 447 if ( bStartOnMonday )
446 d = d.addDays( 7 + dow - 1 ); 448 d = d.addDays( 7 + dow - 1 );
447 else { 449 else {
448 if ( dow == 7 ) 450 if ( dow == 7 )
449 d = d.addDays( dow ); 451 d = d.addDays( dow );
450 else 452 else
451 d = d.addDays( 7 + dow ); 453 d = d.addDays( 7 + dow );
452 } 454 }
453 return d; 455 return d;
454} 456}
455 457
456void DateBookWeek::getEvents() 458void DateBookWeek::getEvents()
457{ 459{
458 QDate startWeek = weekDate(); 460 QDate startWeek = weekDate();
459 461
460 QDate endWeek = startWeek.addDays( 6 ); 462 QDate endWeek = startWeek.addDays( 6 );
461 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, 463 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek,
462 endWeek); 464 endWeek);
463 view->showEvents( eventList ); 465 view->showEvents( eventList );
464 view->moveToHour( startTime ); 466 view->moveToHour( startTime );
465} 467}
466 468
467void DateBookWeek::generateAllDayTooltext( QString& text ) { 469void DateBookWeek::generateAllDayTooltext( QString& text ) {
468 text += "<b>" + tr("This is an all day event.") + "</b><br>"; 470 text += "<b>" + tr("This is an all day event.") + "</b><br>";
469} 471}
470 472
471void DateBookWeek::generateNormalTooltext( QString& str, 473void DateBookWeek::generateNormalTooltext( QString& str,
472 const EffectiveEvent &ev ) { 474 const EffectiveEvent &ev ) {
473 str += "<b>" + QObject::tr("Start") + "</b>: "; 475 str += "<b>" + QObject::tr("Start") + "</b>: ";
474 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); 476 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE );
475 if( ev.startDate()!=ev.endDate() ) { 477 if( ev.startDate()!=ev.endDate() ) {
476 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; 478 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>";
477 } 479 }
478 str += "<br>"; 480 str += "<br>";
479 str += "<b>" + QObject::tr("End") + "</b>: "; 481 str += "<b>" + QObject::tr("End") + "</b>: ";
480 str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); 482 str += TimeString::timeString( ev.event().end().time(), ampm, FALSE );
481 if( ev.startDate()!=ev.endDate() ) { 483 if( ev.startDate()!=ev.endDate() ) {
482 str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; 484 str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>";
483 } 485 }
484} 486}
485 487
486void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) 488void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
487{ 489{
488 if ( tHide->isActive() ) 490 if ( tHide->isActive() )
489 tHide->stop(); 491 tHide->stop();
490 492
491 // why would someone use "<"? Oh well, fix it up... 493 // why would someone use "<"? Oh well, fix it up...
492 // I wonder what other things may be messed up... 494 // I wonder what other things may be messed up...
493 QString strDesc = ev.description(); 495 QString strDesc = ev.description();
494 int where = strDesc.find( "<" ); 496 int where = strDesc.find( "<" );
495 while ( where != -1 ) { 497 while ( where != -1 ) {
496 strDesc.remove( where, 1 ); 498 strDesc.remove( where, 1 );
497 strDesc.insert( where, "&#60;" ); 499 strDesc.insert( where, "&#60;" );
498 where = strDesc.find( "<", where ); 500 where = strDesc.find( "<", where );
499 } 501 }
500 502
501 QString strCat; 503 QString strCat;
502 // ### FIX later... 504 // ### FIX later...
503// QString strCat = ev.category(); 505// QString strCat = ev.category();
504// where = strCat.find( "<" ); 506// where = strCat.find( "<" );
505// while ( where != -1 ) { 507// while ( where != -1 ) {
506 // strCat.remove( where, 1 ); 508 // strCat.remove( where, 1 );
507 // strCat.insert( where, "&#60;" ); 509 // strCat.insert( where, "&#60;" );
508 // where = strCat.find( "<", where ); 510 // where = strCat.find( "<", where );
509// } 511// }
510 512
511 QString strLocation = ev.location(); 513 QString strLocation = ev.location();
512 while ( where != -1 ) { 514 while ( where != -1 ) {
513 strLocation.remove( where, 1 ); 515 strLocation.remove( where, 1 );
514 strLocation.insert( where, "&#60;" ); 516 strLocation.insert( where, "&#60;" );
515 where = strLocation.find( "<", where ); 517 where = strLocation.find( "<", where );
516 } 518 }
517 519
518 QString strNote = ev.notes(); 520 QString strNote = ev.notes();
519 where = strNote.find( "<" ); 521 where = strNote.find( "<" );
520 while ( where != -1 ) { 522 while ( where != -1 ) {
521 strNote.remove( where, 1 ); 523 strNote.remove( where, 1 );
522 strNote.insert( where, "&#60;" ); 524 strNote.insert( where, "&#60;" );
523 where = strNote.find( "<", where ); 525 where = strNote.find( "<", where );
524 } 526 }
525 527
526 QString str = "<b>" + strDesc + "</b><br>" 528 QString str = "<b>" + strDesc + "</b><br>"
527 + strLocation + "<br>" 529 + strLocation + "<br>"
528 + "<i>" + strCat + "</i>" 530 + "<i>" + strCat + "</i>"
529 + "<br>" + TimeString::longDateString( ev.date() ) 531 + "<br>" + TimeString::longDateString( ev.date() )
530 + "<br>"; 532 + "<br>";
531 533
532 if (ev.event().type() == Event::Normal ) 534 if (ev.event().type() == Event::Normal )
533 generateNormalTooltext( str, ev ); 535 generateNormalTooltext( str, ev );
534 else 536 else
535 generateAllDayTooltext( str ); 537 generateAllDayTooltext( str );
536 538
537 str += "<br><br>" + strNote; 539 str += "<br><br>" + strNote;
538 540
539 lblDesc->setText( str ); 541 lblDesc->setText( str );
540 lblDesc->resize( lblDesc->sizeHint() ); 542 lblDesc->resize( lblDesc->sizeHint() );
541 // move the label so it is "centerd" horizontally... 543 // move the label so it is "centerd" horizontally...
542 lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 ); 544 lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 );
543 lblDesc->show(); 545 lblDesc->show();
544} 546}
545 547
546void DateBookWeek::slotHideEvent() 548void DateBookWeek::slotHideEvent()
547{ 549{
548 tHide->start( 2000, true ); 550 tHide->start( 2000, true );
549} 551}
550 552
551void DateBookWeek::setStartViewTime( int startHere ) 553void DateBookWeek::setStartViewTime( int startHere )
552{ 554{
553 startTime = startHere; 555 startTime = startHere;
554 view->moveToHour( startTime ); 556 view->moveToHour( startTime );
555} 557}
556 558
557int DateBookWeek::startViewTime() const 559int DateBookWeek::startViewTime() const
558{ 560{
559 return startTime; 561 return startTime;
560} 562}
561 563
562void DateBookWeek::redraw() 564void DateBookWeek::redraw()
563{ 565{
564 getEvents(); 566 getEvents();
565} 567}
566 568
567void DateBookWeek::slotYearChanged( int y ) 569void DateBookWeek::slotYearChanged( int y )
568{ 570{
569 int totWeek; 571 int totWeek;
570 QDate d( y, 12, 31 ); 572 QDate d( y, 12, 31 );
571 int throwAway; 573 int throwAway;
572 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 574 calcWeek( d, totWeek, throwAway, bStartOnMonday );
573 while ( totWeek == 1 ) { 575 while ( totWeek == 1 ) {
574 d = d.addDays( -1 ); 576 d = d.addDays( -1 );
575 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 577 calcWeek( d, totWeek, throwAway, bStartOnMonday );
576 } 578 }
577 if ( totWeek != totalWeeks() ) 579 if ( totWeek != totalWeeks() )
578 setTotalWeeks( totWeek ); 580 setTotalWeeks( totWeek );
579} 581}
580 582
581 583
582void DateBookWeek::setTotalWeeks( int numWeeks ) 584void DateBookWeek::setTotalWeeks( int numWeeks )
583{ 585{
584 header->spinWeek->setMaxValue( numWeeks ); 586 header->spinWeek->setMaxValue( numWeeks );
585} 587}
586 588
587int DateBookWeek::totalWeeks() const 589int DateBookWeek::totalWeeks() const
588{ 590{
589 return header->spinWeek->maxValue(); 591 return header->spinWeek->maxValue();
590} 592}
591 593
592void DateBookWeek::slotWeekChanged( bool onMonday ) 594void DateBookWeek::slotWeekChanged( bool onMonday )
593{ 595{
594 bStartOnMonday = onMonday; 596 bStartOnMonday = onMonday;
595 view->setStartOfWeek( bStartOnMonday ); 597 view->setStartOfWeek( bStartOnMonday );
596 header->setStartOfWeek( bStartOnMonday ); 598 header->setStartOfWeek( bStartOnMonday );
597 redraw(); 599 redraw();
598} 600}
599 601
600void DateBookWeek::slotClockChanged( bool ap ) 602void DateBookWeek::slotClockChanged( bool ap )
601{ 603{
602 ampm = ap; 604 ampm = ap;
603} 605}
604 606
605// return the date at the beginning of the week... 607// return the date at the beginning of the week...
606QDate DateBookWeek::weekDate() const 608QDate DateBookWeek::weekDate() const
607{ 609{
608 return dateFromWeek( _week, year, bStartOnMonday ); 610 return dateFromWeek( _week, year, bStartOnMonday );
609} 611}
610 612
611// this used to only be needed by datebook.cpp, but now we need it inside 613// this used to only be needed by datebook.cpp, but now we need it inside
612// week view since 614// week view since
613// we need to be able to figure out our total number of weeks on the fly... 615// we need to be able to figure out our total number of weeks on the fly...
614// this is probably the best place to put it.. 616// this is probably the best place to put it..
615 617
616// For Weeks that start on Monday... (EASY!) 618// For Weeks that start on Monday... (EASY!)
617// At the moment we will use ISO 8601 method for computing 619// At the moment we will use ISO 8601 method for computing
618// the week. Granted, other countries use other methods, 620// the week. Granted, other countries use other methods,
619// bet we aren't doing any Locale stuff at the moment. So, 621// bet we aren't doing any Locale stuff at the moment. So,
620// this should pass. This Algorithim is public domain and 622// this should pass. This Algorithim is public domain and
621// available at: 623// available at:
622// http://personal.ecu.edu/mccartyr/ISOwdALG.txt 624// http://personal.ecu.edu/mccartyr/ISOwdALG.txt
623// the week number is return, and the year number is returned in year 625// the week number is return, and the year number is returned in year
624// for Instance 2001/12/31 is actually the first week in 2002. 626// for Instance 2001/12/31 is actually the first week in 2002.
625// There is a more mathematical definition, but I will implement it when 627// There is a more mathematical definition, but I will implement it when
626// we are pass our deadline. 628// we are pass our deadline.
627 629
628// For Weeks that start on Sunday... (ahh... home rolled) 630// For Weeks that start on Sunday... (ahh... home rolled)
629// okay, if Jan 1 is on Friday or Saturday, 631// okay, if Jan 1 is on Friday or Saturday,
630// it will go to the pervious 632// it will go to the pervious
631// week... 633// week...
632 634
633bool calcWeek( const QDate &d, int &week, int &year, 635bool calcWeek( const QDate &d, int &week, int &year,
634 bool startOnMonday ) 636 bool startOnMonday )
635{ 637{
636 int weekNumber; 638 int weekNumber;
637 int yearNumber; 639 int yearNumber;
638 640
639 // remove a pesky warning, (Optimizations on g++) 641 // remove a pesky warning, (Optimizations on g++)
640 weekNumber = -1; 642 weekNumber = -1;
641 int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); 643 int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek();
642 int dayOfWeek = d.dayOfWeek(); 644 int dayOfWeek = d.dayOfWeek();
643 645
644 if ( !d.isValid() ) 646 if ( !d.isValid() )
645 return false; 647 return false;
646 648
647 if ( startOnMonday ) { 649 if ( startOnMonday ) {
648 // find the Jan1Weekday; 650 // find the Jan1Weekday;
649 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { 651 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) {
650 yearNumber = d.year() - 1; 652 yearNumber = d.year() - 1;
651 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) 653 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) )
652 weekNumber = 53; 654 weekNumber = 53;
653 else 655 else
654 weekNumber = 52; 656 weekNumber = 52;
655 } else 657 } else
656 yearNumber = d.year(); 658 yearNumber = d.year();
657 if ( yearNumber == d.year() ) { 659 if ( yearNumber == d.year() ) {