summaryrefslogtreecommitdiff
path: root/core/pim/datebook/datebookday.cpp
authorzecke <zecke>2002-06-23 18:18:27 (UTC)
committer zecke <zecke>2002-06-23 18:18:27 (UTC)
commitf0e656b51a2dcee1dec594636cbc1ba8d4b11eef (patch) (unidiff)
tree1eb83b120f8ce404324575799d75c32d4056d1f6 /core/pim/datebook/datebookday.cpp
parent6fd46f6d23538ec6e0f48209f6c0f0d939a2effe (diff)
downloadopie-f0e656b51a2dcee1dec594636cbc1ba8d4b11eef.zip
opie-f0e656b51a2dcee1dec594636cbc1ba8d4b11eef.tar.gz
opie-f0e656b51a2dcee1dec594636cbc1ba8d4b11eef.tar.bz2
Patch by <tboc@gmx.de> to configure the size
of the row of the dayview Adds an option to jump to the current time in the dayview and some small fixes ( zecke )
Diffstat (limited to 'core/pim/datebook/datebookday.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/datebook/datebookday.cpp53
1 files changed, 49 insertions, 4 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp
index c15ccef..9cc5fcd 100644
--- a/core/pim/datebook/datebookday.cpp
+++ b/core/pim/datebook/datebookday.cpp
@@ -51,25 +51,25 @@ DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent,
51 setColumnStretchable( 0, TRUE ); 51 setColumnStretchable( 0, TRUE );
52 setHScrollBarMode( QScrollView::AlwaysOff ); 52 setHScrollBarMode( QScrollView::AlwaysOff );
53 verticalHeader()->setPalette(white); 53 verticalHeader()->setPalette(white);
54 verticalHeader()->setResizeEnabled(FALSE); 54 verticalHeader()->setResizeEnabled(FALSE);
55 setSelectionMode( Single ); 55 setSelectionMode( Single );
56 56
57 // get rid of being able to edit things... 57 // get rid of being able to edit things...
58 QTableItem *tmp; 58 QTableItem *tmp;
59 int row; 59 int row;
60 for ( row = 0; row < numRows(); row++ ) { 60 for ( row = 0; row < numRows(); row++ ) {
61 tmp = new QTableItem( this, QTableItem::Never, QString::null); 61 tmp = new QTableItem( this, QTableItem::Never, QString::null);
62 setItem( row, 0, tmp ); 62 setItem( row, 0, tmp );
63 setRowHeight( row, 40); 63 //setRowHeight( row, 40);
64 } 64 }
65 initHeader(); 65 initHeader();
66 QObject::connect( qApp, SIGNAL(clockChanged(bool)), 66 QObject::connect( qApp, SIGNAL(clockChanged(bool)),
67 this, SLOT(slotChangeClock(bool)) ); 67 this, SLOT(slotChangeClock(bool)) );
68} 68}
69 69
70void DateBookDayView::initHeader() 70void DateBookDayView::initHeader()
71{ 71{
72 QString strTmp; 72 QString strTmp;
73 for ( int i = 0; i < 24; ++i ) { 73 for ( int i = 0; i < 24; ++i ) {
74 if ( ampm ) { 74 if ( ampm ) {
75 if ( i == 0 ) 75 if ( i == 0 )
@@ -150,58 +150,78 @@ void DateBookDayView::keyPressEvent( QKeyEvent *e )
150{ 150{
151 QString txt = e->text(); 151 QString txt = e->text();
152 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { 152 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) {
153 // we this is some sort of thing we know about... 153 // we this is some sort of thing we know about...
154 e->accept(); 154 e->accept();
155 emit sigCapturedKey( txt ); 155 emit sigCapturedKey( txt );
156 } else { 156 } else {
157 // I don't know what this key is, do you? 157 // I don't know what this key is, do you?
158 e->ignore(); 158 e->ignore();
159 } 159 }
160} 160}
161 161
162void DateBookDayView::setRowStyle( int style )
163{
164 if (style<0) style = 0;
165
166 for (int i=0; i<numRows(); i++)
167 setRowHeight(i, style*10+20);
168}
162 169
163//=========================================================================== 170//===========================================================================
164 171
165DateBookDay::DateBookDay( bool ampm, bool startOnMonday, 172DateBookDay::DateBookDay( bool ampm, bool startOnMonday,
166 DateBookDB *newDb, QWidget *parent, 173 DateBookDB *newDb, QWidget *parent,
167 const char *name ) 174 const char *name )
168 : QVBox( parent, name ), 175 : QVBox( parent, name ),
169 currDate( QDate::currentDate() ), 176 currDate( QDate::currentDate() ),
170 db( newDb ), 177 db( newDb ),
171 startTime( 0 ) 178 startTime( 0 )
172{ 179{
173 widgetList.setAutoDelete( true ); 180 widgetList.setAutoDelete( true );
174 header = new DateBookDayHeader( startOnMonday, this, "day header" ); 181 header = new DateBookDayHeader( startOnMonday, this, "day header" );
175 header->setDate( currDate.year(), currDate.month(), currDate.day() ); 182 header->setDate( currDate.year(), currDate.month(), currDate.day() );
176 view = new DateBookDayView( ampm, this, "day view" ); 183 view = new DateBookDayView( ampm, this, "day view" );
184
177 connect( header, SIGNAL( dateChanged( int, int, int ) ), 185 connect( header, SIGNAL( dateChanged( int, int, int ) ),
178 this, SLOT( dateChanged( int, int, int ) ) ); 186 this, SLOT( dateChanged( int, int, int ) ) );
179 connect( view, SIGNAL( sigColWidthChanged() ), 187 connect( view, SIGNAL( sigColWidthChanged() ),
180 this, SLOT( slotColWidthChanged() ) ); 188 this, SLOT( slotColWidthChanged() ) );
181 connect( qApp, SIGNAL(weekChanged(bool)), 189 connect( qApp, SIGNAL(weekChanged(bool)),
182 this, SLOT(slotWeekChanged(bool)) ); 190 this, SLOT(slotWeekChanged(bool)) );
183 connect( view, SIGNAL(sigCapturedKey(const QString &)), 191 connect( view, SIGNAL(sigCapturedKey(const QString &)),
184 this, SIGNAL(sigNewEvent(const QString&)) ); 192 this, SIGNAL(sigNewEvent(const QString&)) );
185 193
186 QTimer *timer = new QTimer( this ); 194 QTimer *timer = new QTimer( this );
187 195
188 connect( timer, SIGNAL(timeout()), 196 connect( timer, SIGNAL(timeout()),
189 this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors 197 this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors
190 timer->start( 1000*60*5, FALSE ); //update every 5min 198 timer->start( 1000*60*5, FALSE ); //update every 5min
191 199
192 selectedWidget = 0; 200 selectedWidget = 0;
193 201
194 timeMarker = new DateBookDayTimeMarker( this ); 202 timeMarker = new DateBookDayTimeMarker( this );
195 timeMarker->setTime( QTime::currentTime() ); 203 timeMarker->setTime( QTime::currentTime() );
204 rowStyle = -1; // initialize with bogus values
205}
206
207void DateBookDay::setJumpToCurTime( bool bJump )
208{
209 jumpToCurTime = bJump;
210}
211
212void DateBookDay::setRowStyle( int style )
213{
214 if (rowStyle != style) view->setRowStyle( style );
215 rowStyle = style;
196} 216}
197 217
198void DateBookDay::updateView( void ) 218void DateBookDay::updateView( void )
199{ 219{
200 timeMarker->setTime( QTime::currentTime() ); 220 timeMarker->setTime( QTime::currentTime() );
201 //need to find a way to update all DateBookDayWidgets 221 //need to find a way to update all DateBookDayWidgets
202} 222}
203 223
204void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) 224void DateBookDay::setSelectedWidget( DateBookDayWidget *w )
205{ 225{
206 selectedWidget = w; 226 selectedWidget = w;
207} 227}
@@ -248,33 +268,39 @@ void DateBookDay::setDate( QDate d)
248 selectedWidget = 0; 268 selectedWidget = 0;
249} 269}
250 270
251void DateBookDay::dateChanged( int y, int m, int d ) 271void DateBookDay::dateChanged( int y, int m, int d )
252{ 272{
253 QDate date( y, m, d ); 273 QDate date( y, m, d );
254 if ( currDate == date ) 274 if ( currDate == date )
255 return; 275 return;
256 currDate.setYMD( y, m, d ); 276 currDate.setYMD( y, m, d );
257 relayoutPage(); 277 relayoutPage();
258 dayView()->clearSelection(); 278 dayView()->clearSelection();
259 QTableSelection ts; 279 QTableSelection ts;
280
281 if (jumpToCurTime && this->date() == QDate::currentDate())
282 {
283 ts.init( QTime::currentTime().hour(), 0);
284 ts.expandTo( QTime::currentTime().hour(), 0);
285 } else
286 {
260 ts.init( startTime, 0 ); 287 ts.init( startTime, 0 );
261 ts.expandTo( startTime, 0 ); 288 ts.expandTo( startTime, 0 );
289 }
290
262 dayView()->addSelection( ts ); 291 dayView()->addSelection( ts );
263 292
264 selectedWidget = 0; 293 selectedWidget = 0;
265 294
266 if (this->date() == QDate::currentDate())
267 timeMarker->show(); else timeMarker->hide();
268
269} 295}
270 296
271void DateBookDay::redraw() 297void DateBookDay::redraw()
272{ 298{
273 if ( isUpdatesEnabled() ) 299 if ( isUpdatesEnabled() )
274 relayoutPage(); 300 relayoutPage();
275} 301}
276 302
277void DateBookDay::getEvents() 303void DateBookDay::getEvents()
278{ 304{
279 widgetList.clear(); 305 widgetList.clear();
280 306
@@ -390,24 +416,27 @@ void DateBookDay::relayoutPage( bool fromResize )
390 geom.setX( 0 ); 416 geom.setX( 0 );
391 417
392 wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); 418 wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0);
393 419
394 geom.setWidth( wd ); 420 geom.setWidth( wd );
395 421
396 while ( intersects( w, geom ) ) { 422 while ( intersects( w, geom ) ) {
397 geom.moveBy( wd + 2 + 1, 0 ); 423 geom.moveBy( wd + 2 + 1, 0 );
398 } 424 }
399 w->setGeometry( geom ); 425 w->setGeometry( geom );
400 } 426 }
401 427
428 if (jumpToCurTime && this->date() == QDate::currentDate())
429 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour
430 else
402 view->setContentsPos( 0, startTime * view->rowHeight(0) ); 431 view->setContentsPos( 0, startTime * view->rowHeight(0) );
403 432
404 433
405 } else { 434 } else {
406 435
407 436
408 int hours[24]; 437 int hours[24];
409 memset( hours, 0, 24*sizeof( int ) ); 438 memset( hours, 0, 24*sizeof( int ) );
410 bool overFlow = FALSE; 439 bool overFlow = FALSE;
411 for ( int i = 0; i < wCount; i++ ) { 440 for ( int i = 0; i < wCount; i++ ) {
412 DateBookDayWidget *w = widgetList.at(i); 441 DateBookDayWidget *w = widgetList.at(i);
413 int start = w->event().start().hour(); 442 int start = w->event().start().hour();
@@ -435,29 +464,36 @@ void DateBookDay::relayoutPage( bool fromResize )
435 memset( used, FALSE, 24*10*sizeof( bool ) ); 464 memset( used, FALSE, 24*10*sizeof( bool ) );
436 465
437 for ( int i = 0; i < wCount; i++ ) { 466 for ( int i = 0; i < wCount; i++ ) {
438 DateBookDayWidget *w = widgetList.at(i); 467 DateBookDayWidget *w = widgetList.at(i);
439 int xp = place( w, used, n ); 468 int xp = place( w, used, n );
440 if ( xp != -1 ) { 469 if ( xp != -1 ) {
441 QRect geom = w->geometry(); 470 QRect geom = w->geometry();
442 geom.setX( xp*(wid+2) ); 471 geom.setX( xp*(wid+2) );
443 geom.setWidth( wid ); 472 geom.setWidth( wid );
444 w->setGeometry( geom ); 473 w->setGeometry( geom );
445 } 474 }
446 } 475 }
476
477 if (jumpToCurTime && this->date() == QDate::currentDate())
478 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour
479 else
447 view->setContentsPos( 0, startTime * view->rowHeight(0) ); 480 view->setContentsPos( 0, startTime * view->rowHeight(0) );
448 } 481 }
449 482
450 timeMarker->setTime( QTime::currentTime() );//display timeMarker 483 timeMarker->setTime( QTime::currentTime() );//display timeMarker
451 timeMarker->raise(); //on top of all widgets 484 timeMarker->raise(); //on top of all widgets
485 if (this->date() == QDate::currentDate()) //only show timeMarker on current day
486 timeMarker->show(); else timeMarker->hide();
487
452 setUpdatesEnabled( TRUE ); 488 setUpdatesEnabled( TRUE );
453 return; 489 return;
454} 490}
455 491
456DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) 492DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom )
457{ 493{
458 int i = 0; 494 int i = 0;
459 DateBookDayWidget *w = widgetList.at(i); 495 DateBookDayWidget *w = widgetList.at(i);
460 int wCount = widgetList.count(); 496 int wCount = widgetList.count();
461 while ( i < wCount && w != item ) { 497 while ( i < wCount && w != item ) {
462 if ( w->geometry().intersects( geom ) ) { 498 if ( w->geometry().intersects( geom ) ) {
463 return w; 499 return w;
@@ -470,26 +506,35 @@ DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const
470 506
471 507
472QDate DateBookDay::date() const 508QDate DateBookDay::date() const
473{ 509{
474 return currDate; 510 return currDate;
475} 511}
476 512
477void DateBookDay::setStartViewTime( int startHere ) 513void DateBookDay::setStartViewTime( int startHere )
478{ 514{
479 startTime = startHere; 515 startTime = startHere;
480 dayView()->clearSelection(); 516 dayView()->clearSelection();
481 QTableSelection ts; 517 QTableSelection ts;
518
519 if (jumpToCurTime && this->date() == QDate::currentDate())//this should probably be in datebook.cpp where it's called?
520 {
521 ts.init( QTime::currentTime().hour(), 0);
522 ts.expandTo( QTime::currentTime().hour(), 0);
523 } else
524 {
482 ts.init( startTime, 0 ); 525 ts.init( startTime, 0 );
483 ts.expandTo( startTime, 0 ); 526 ts.expandTo( startTime, 0 );
527 }
528
484 dayView()->addSelection( ts ); 529 dayView()->addSelection( ts );
485} 530}
486 531
487int DateBookDay::startViewTime() const 532int DateBookDay::startViewTime() const
488{ 533{
489 return startTime; 534 return startTime;
490} 535}
491 536
492void DateBookDay::slotWeekChanged( bool bStartOnMonday ) 537void DateBookDay::slotWeekChanged( bool bStartOnMonday )
493{ 538{
494 header->setStartOfWeek( bStartOnMonday ); 539 header->setStartOfWeek( bStartOnMonday );
495 // redraw(); 540 // redraw();