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