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