summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp7
-rw-r--r--core/pim/datebook/datebook.h3
-rw-r--r--core/pim/datebook/datebookday.cpp863
-rw-r--r--core/pim/datebook/datebookday.h25
4 files changed, 469 insertions, 429 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 4fbcb10..6dd8918 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -385,2 +385,9 @@ void DateBook::viewMonth() {
385 385
386void DateBook::insertEvent( const Event &e )
387{
388 qWarning("Adding Event!");
389 db->addEvent(e);
390 emit newEvent();
391}
392
386void DateBook::duplicateEvent( const Event &e ) 393void DateBook::duplicateEvent( const Event &e )
diff --git a/core/pim/datebook/datebook.h b/core/pim/datebook/datebook.h
index 5216770..3f57d4a 100644
--- a/core/pim/datebook/datebook.h
+++ b/core/pim/datebook/datebook.h
@@ -90,3 +90,4 @@ private slots:
90 90
91 void editEvent( const Event &e ); 91 void insertEvent( const Event &e );
92 void editEvent( const Event &e );
92 void duplicateEvent( const Event &e ); 93 void duplicateEvent( const Event &e );
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp
index db4c2fd..0a40ea9 100644
--- a/core/pim/datebook/datebookday.cpp
+++ b/core/pim/datebook/datebookday.cpp
@@ -40,30 +40,30 @@
40 40
41#include <qlineedit.h>
42
41#include <qtimer.h> 43#include <qtimer.h>
42 44
43DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, 45DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, const char *name )
44 const char *name ) 46 : QTable( 24, 1, parent, name ), ampm( whichClock ), currDate( QDate::currentDate() )
45 : QTable( 24, 1, parent, name ), 47{
46 ampm( whichClock ) 48 enableClipper(TRUE);
47{ 49 setTopMargin( 0 );
48 enableClipper(TRUE); 50 horizontalHeader()->hide();
49 setTopMargin( 0 ); 51 setLeftMargin(38);
50 horizontalHeader()->hide(); 52 setColumnStretchable( 0, TRUE );
51 setLeftMargin(38); 53 setHScrollBarMode( QScrollView::AlwaysOff );
52 setColumnStretchable( 0, TRUE ); 54 verticalHeader()->setPalette(white);
53 setHScrollBarMode( QScrollView::AlwaysOff ); 55 verticalHeader()->setResizeEnabled(FALSE);
54 verticalHeader()->setPalette(white); 56 setSelectionMode( Single );
55 verticalHeader()->setResizeEnabled(FALSE); 57
56 setSelectionMode( Single ); 58 // get rid of being able to edit things...
57 59 QTableItem *tmp;
58 // get rid of being able to edit things... 60 int row;
59 QTableItem *tmp; 61 for ( row = 0; row < numRows(); row++ ) {
60 int row; 62 tmp = new QTableItem( this, QTableItem::Never, QString::null);
61 for ( row = 0; row < numRows(); row++ ) { 63 setItem( row, 0, tmp );
62 tmp = new QTableItem( this, QTableItem::Never, QString::null); 64 //setRowHeight( row, 40);
63 setItem( row, 0, tmp ); 65 }
64 //setRowHeight( row, 40); 66
65 } 67 initHeader();
66 initHeader(); 68 QObject::connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotChangeClock(bool)) );
67 QObject::connect( qApp, SIGNAL(clockChanged(bool)),
68 this, SLOT(slotChangeClock(bool)) );
69} 69}
@@ -72,23 +72,28 @@ void DateBookDayView::initHeader()
72{ 72{
73 QString strTmp; 73 QString strTmp;
74 for ( int i = 0; i < 24; ++i ) { 74 for ( int i = 0; i < 24; ++i ) {
75 if ( ampm ) { 75 if ( ampm ) {
76 if ( i == 0 ) 76 if ( i == 0 )
77 strTmp = QString::number(12) + ":00"; 77 strTmp = QString::number(12) + ":00";
78 else if ( i == 12 ) 78 else if ( i == 12 )
79 strTmp = QString::number(12) + tr(":00p"); 79 strTmp = QString::number(12) + tr(":00p");
80 else if ( i > 12 ) 80 else if ( i > 12 )
81 strTmp = QString::number( i - 12 ) + tr(":00p"); 81 strTmp = QString::number( i - 12 ) + tr(":00p");
82 else 82 else
83 strTmp = QString::number(i) + ":00"; 83 strTmp = QString::number(i) + ":00";
84 } else { 84 } else {
85 if ( i < 10 ) 85 if ( i < 10 )
86 strTmp = "0" + QString::number(i) + ":00"; 86 strTmp = "0" + QString::number(i) + ":00";
87 else 87 else
88 strTmp = QString::number(i) + ":00"; 88 strTmp = QString::number(i) + ":00";
89 }
90 strTmp = strTmp.rightJustify( 6, ' ' );
91 verticalHeader()->setLabel( i, strTmp );
92 setRowStretchable( i, FALSE );
89 } 93 }
90 strTmp = strTmp.rightJustify( 6, ' ' ); 94}
91 verticalHeader()->setLabel( i, strTmp ); 95
92 setRowStretchable( i, FALSE ); 96void DateBookDayView::slotDateChanged( int y, int m, int d )
93 } 97{
98 currDate.setYMD(y,m,d);
94} 99}
@@ -97,4 +102,4 @@ void DateBookDayView::slotChangeClock( bool newClock )
97{ 102{
98 ampm = newClock; 103 ampm = newClock;
99 initHeader(); 104 initHeader();
100} 105}
@@ -103,3 +108,3 @@ bool DateBookDayView::whichClock() const
103{ 108{
104 return ampm; 109 return ampm;
105} 110}
@@ -108,3 +113,3 @@ void DateBookDayView::moveUp()
108{ 113{
109 scrollBy(0, -20); 114 scrollBy(0, -20);
110} 115}
@@ -113,3 +118,3 @@ void DateBookDayView::moveDown()
113{ 118{
114 scrollBy(0, 20); 119 scrollBy(0, 20);
115} 120}
@@ -118,18 +123,18 @@ void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool )
118{ 123{
119 int w = cr.width(); 124 int w = cr.width();
120 int h = cr.height(); 125 int h = cr.height();
121 p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); 126 p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) );
122 if ( showGrid() ) { 127 if ( showGrid() ) {
123 // Draw our lines 128 // Draw our lines
124 int x2 = w - 1; 129 int x2 = w - 1;
125 int y2 = h - 1; 130 int y2 = h - 1;
126 QPen pen( p->pen() ); 131 QPen pen( p->pen() );
127 p->setPen( colorGroup().dark() ); 132 p->setPen( colorGroup().dark() );
128 p->drawLine( x2, 0, x2, y2 ); 133 p->drawLine( x2, 0, x2, y2 );
129 p->drawLine( 0, y2, x2, y2 ); 134 p->drawLine( 0, y2, x2, y2 );
130 135
131 p->setPen( colorGroup().midlight() ); 136 p->setPen( colorGroup().midlight() );
132 p->drawLine( 0, y2 - h/2, x2, y2 - h/2); 137 p->drawLine( 0, y2 - h/2, x2, y2 - h/2);
133 138
134 p->setPen( pen ); 139 p->setPen( pen );
135 } 140 }
@@ -141,8 +146,7 @@ void DateBookDayView::paintFocus( QPainter *, const QRect & )
141 146
142
143void DateBookDayView::resizeEvent( QResizeEvent *e ) 147void DateBookDayView::resizeEvent( QResizeEvent *e )
144{ 148{
145 QTable::resizeEvent( e ); 149 QTable::resizeEvent( e );
146 columnWidthChanged( 0 ); 150 columnWidthChanged( 0 );
147 emit sigColWidthChanged(); 151 emit sigColWidthChanged();
148} 152}
@@ -151,11 +155,11 @@ void DateBookDayView::keyPressEvent( QKeyEvent *e )
151{ 155{
152 QString txt = e->text(); 156 QString txt = e->text();
153 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { 157 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) {
154 // we this is some sort of thing we know about... 158 // we this is some sort of thing we know about...
155 e->accept(); 159 e->accept();
156 emit sigCapturedKey( txt ); 160 emit sigCapturedKey( txt );
157 } else { 161 } else {
158 // I don't know what this key is, do you? 162 // I don't know what this key is, do you?
159 e->ignore(); 163 e->ignore();
160 } 164 }
161} 165}
@@ -170,37 +174,66 @@ void DateBookDayView::setRowStyle( int style )
170 174
175void DateBookDayView::contentsMouseReleaseEvent( QMouseEvent *e )
176{
177 int y=e->y();
178 int diff=y%(this->rowHeight(0));
179 int hour=y/this->rowHeight(0);
180 quickLineEdit=new DateBookDayViewQuickLineEdit(QDateTime(currDate,QTime(hour,0,0,0)),QDateTime(currDate,QTime(hour,59,0,0)),this->viewport(),"quickedit");
181 quickLineEdit->setGeometry(0,0,this->columnWidth(0)-1,this->rowHeight(0));
182 this->moveChild(quickLineEdit,0,y-diff);
183 quickLineEdit->setFocus();
184 quickLineEdit->show();
185}
186
171//=========================================================================== 187//===========================================================================
172 188
173DateBookDay::DateBookDay( bool ampm, bool startOnMonday, 189DateBookDayViewQuickLineEdit::DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name=0) : QLineEdit(parent,name)
174 DateBookDB *newDb, QWidget *parent,
175 const char *name )
176 : QVBox( parent, name ),
177 currDate( QDate::currentDate() ),
178 db( newDb ),
179 startTime( 0 )
180{ 190{
181 widgetList.setAutoDelete( true ); 191 active=1;
182 header = new DateBookDayHeader( startOnMonday, this, "day header" ); 192 quickEvent.setStart(start);
183 header->setDate( currDate.year(), currDate.month(), currDate.day() ); 193 quickEvent.setEnd(end);
184 view = new DateBookDayView( ampm, this, "day view" ); 194 connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed()));
195}
185 196
186 connect( header, SIGNAL( dateChanged( int, int, int ) ), 197void DateBookDayViewQuickLineEdit::slotReturnPressed()
187 this, SLOT( dateChanged( int, int, int ) ) ); 198{
188 connect( view, SIGNAL( sigColWidthChanged() ), 199 if(active && (!this->text().isEmpty())) {// Fix to avoid having this event beeing added multiple times.
189 this, SLOT( slotColWidthChanged() ) ); 200 quickEvent.setDescription(this->text());
190 connect( qApp, SIGNAL(weekChanged(bool)), 201 connect(this,SIGNAL(insertEvent(const Event &)),this->topLevelWidget(),SLOT(insertEvent(const Event &)));
191 this, SLOT(slotWeekChanged(bool)) ); 202 emit(insertEvent(quickEvent));
192 connect( view, SIGNAL(sigCapturedKey(const QString &)), 203 active=0;
193 this, SIGNAL(sigNewEvent(const QString&)) ); 204 }
205 this->close(true);// Close and also delete this widget
206}
194 207
195 QTimer *timer = new QTimer( this ); 208void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent * e )
209{
210 slotReturnPressed(); // Reuse code to add event and close this widget.
211}
196 212
197 connect( timer, SIGNAL(timeout()), 213//===========================================================================
198 this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors
199 timer->start( 1000*60*5, FALSE ); //update every 5min
200 214
201 selectedWidget = 0; 215DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name )
216 : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 )
217{
218 widgetList.setAutoDelete( true );
219 header = new DateBookDayHeader( startOnMonday, this, "day header" );
220 header->setDate( currDate.year(), currDate.month(), currDate.day() );
221 view = new DateBookDayView( ampm, this, "day view" );
222
223 connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( int, int, int ) ) );
224 connect( header, SIGNAL( dateChanged( int, int, int ) ), view, SLOT( slotDateChanged( int, int, int ) ) );
225 connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) );
226 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) );
227 connect( view, SIGNAL(sigCapturedKey(const QString &)), this, SIGNAL(sigNewEvent(const QString&)) );
228
229 QTimer *timer = new QTimer( this );
230
231 connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors
232 timer->start( 1000*60*5, FALSE ); //update every 5min
202 233
203 timeMarker = new DateBookDayTimeMarker( this ); 234 selectedWidget = 0;
204 timeMarker->setTime( QTime::currentTime() ); 235
205 rowStyle = -1; // initialize with bogus values 236 timeMarker = new DateBookDayTimeMarker( this );
237 timeMarker->setTime( QTime::currentTime() );
238 rowStyle = -1; // initialize with bogus values
206} 239}
@@ -236,21 +269,22 @@ void DateBookDay::selectedDates( QDateTime &start, QDateTime &end )
236{ 269{
237 start.setDate( currDate ); 270 start.setDate( currDate );
238 end.setDate( currDate ); 271 end.setDate( currDate );
239 272
240 int sh=99,eh=-1; 273 int sh=99,eh=-1;
241 274
242 int n = dayView()->numSelections(); 275 int n = dayView()->numSelections();
243 276
244 for (int i=0; i<n; i++) { 277 for (int i=0; i<n; i++) {
245 QTableSelection sel = dayView()->selection( i ); 278 QTableSelection sel = dayView()->selection( i );
246 sh = QMIN(sh,sel.topRow()); 279 sh = QMIN(sh,sel.topRow());
247 eh = QMAX(sh,sel.bottomRow()+1); 280 eh = QMAX(sh,sel.bottomRow()+1);
248 } 281 }
249 if (sh > 23 || eh < 1) { 282
250 sh=8; 283 if (sh > 23 || eh < 1) {
251 eh=9; 284 sh=8;
252 } 285 eh=9;
286 }
253 287
254 start.setTime( QTime( sh, 0, 0 ) ); 288 start.setTime( QTime( sh, 0, 0 ) );
255 end.setTime( QTime( eh, 0, 0 ) ); 289 end.setTime( QTime( eh, 0, 0 ) );
256} 290}
@@ -259,5 +293,4 @@ void DateBookDay::setDate( int y, int m, int d )
259{ 293{
260 header->setDate( y, m, d ); 294 header->setDate( y, m, d );
261 295 selectedWidget = 0;
262 selectedWidget = 0;
263} 296}
@@ -266,5 +299,4 @@ void DateBookDay::setDate( QDate d)
266{ 299{
267 header->setDate( d.year(), d.month(), d.day() ); 300 header->setDate( d.year(), d.month(), d.day() );
268 301 selectedWidget = 0;
269 selectedWidget = 0;
270} 302}
@@ -273,24 +305,21 @@ void DateBookDay::dateChanged( int y, int m, int d )
273{ 305{
274 QDate date( y, m, d ); 306 QDate date( y, m, d );
275 if ( currDate == date ) 307 if ( currDate == date )
276 return; 308 return;
277 currDate.setYMD( y, m, d ); 309 currDate.setYMD( y, m, d );
278 relayoutPage(); 310 relayoutPage();
279 dayView()->clearSelection(); 311 dayView()->clearSelection();
280 QTableSelection ts; 312 QTableSelection ts;
281
282 if (jumpToCurTime && this->date() == QDate::currentDate())
283 {
284 ts.init( QTime::currentTime().hour(), 0);
285 ts.expandTo( QTime::currentTime().hour(), 0);
286 } else
287 {
288 ts.init( startTime, 0 );
289 ts.expandTo( startTime, 0 );
290 }
291
292 dayView()->addSelection( ts );
293 313
294 selectedWidget = 0; 314 if (jumpToCurTime && this->date() == QDate::currentDate())
315 {
316 ts.init( QTime::currentTime().hour(), 0);
317 ts.expandTo( QTime::currentTime().hour(), 0);
318 } else {
319 ts.init( startTime, 0 );
320 ts.expandTo( startTime, 0 );
321 }
295 322
323 dayView()->addSelection( ts );
324 selectedWidget = 0;
296} 325}
@@ -299,4 +328,4 @@ void DateBookDay::redraw()
299{ 328{
300 if ( isUpdatesEnabled() ) 329 if ( isUpdatesEnabled() )
301 relayoutPage(); 330 relayoutPage();
302} 331}
@@ -313,14 +342,9 @@ void DateBookDay::getEvents()
313 DateBookDayWidget* w = new DateBookDayWidget( *it, this ); 342 DateBookDayWidget* w = new DateBookDayWidget( *it, this );
314 connect( w, SIGNAL( deleteMe( const Event & ) ), 343 connect( w, SIGNAL( deleteMe( const Event & ) ), this, SIGNAL( removeEvent( const Event & ) ) );
315 this, SIGNAL( removeEvent( const Event & ) ) ); 344 connect( w, SIGNAL( duplicateMe( const Event & ) ), this, SIGNAL( duplicateEvent( const Event & ) ) );
316 connect( w, SIGNAL( duplicateMe( const Event & ) ), 345 connect( w, SIGNAL( editMe( const Event & ) ), this, SIGNAL( editEvent( const Event & ) ) );
317 this, SIGNAL( duplicateEvent( const Event & ) ) ); 346 connect( w, SIGNAL( beamMe( const Event & ) ), this, SIGNAL( beamEvent( const Event & ) ) );
318 connect( w, SIGNAL( editMe( const Event & ) ),
319 this, SIGNAL( editEvent( const Event & ) ) );
320 connect( w, SIGNAL( beamMe( const Event & ) ),
321 this, SIGNAL( beamEvent( const Event & ) ) );
322 widgetList.append( w ); 347 widgetList.append( w );
323 } 348 }
324 } 349 }
325
326} 350}
@@ -329,31 +353,32 @@ static int place( const DateBookDayWidget *item, bool *used, int maxn )
329{ 353{
330 int place = 0; 354 int place = 0;
331 int start = item->event().start().hour(); 355 int start = item->event().start().hour();
332 QTime e = item->event().end(); 356 QTime e = item->event().end();
333 int end = e.hour(); 357 int end = e.hour();
334 if ( e.minute() < 5 ) 358 if ( e.minute() < 5 )
335 end--; 359 end--;
336 if ( end < start ) 360 if ( end < start )
337 end = start; 361 end = start;
338 while ( place < maxn ) { 362 while ( place < maxn ) {
339 bool free = TRUE; 363 bool free = TRUE;
340 int s = start; 364 int s = start;
341 while( s <= end ) { 365 while( s <= end ) {
342 if ( used[10*s+place] ) { 366 if ( used[10*s+place] ) {
343 free = FALSE; 367 free = FALSE;
344 break; 368 break;
345 } 369 }
346 s++; 370 s++;
371 }
372 if ( free )
373 break;
374 place++;
347 } 375 }
348 if ( free ) break; 376 if ( place == maxn ) {
349 place++; 377 return -1;
350 } 378 }
351 if ( place == maxn ) { 379 while( start <= end ) {
352 return -1; 380 used[10*start+place] = TRUE;
353 } 381 start++;
354 while( start <= end ) { 382 }
355 used[10*start+place] = TRUE; 383 return place;
356 start++;
357 }
358 return place;
359} 384}
@@ -363,133 +388,126 @@ void DateBookDay::relayoutPage( bool fromResize )
363{ 388{
364 setUpdatesEnabled( FALSE ); 389 setUpdatesEnabled( FALSE );
365 if ( !fromResize ) 390 if ( !fromResize )
366 getEvents(); // no need we already have them! 391 getEvents(); // no need we already have them!
367 392
368 widgetList.sort(); 393 widgetList.sort();
369 //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning 394 //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning
370 //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view 395 //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view
371 396
372 int wCount = widgetList.count(); 397 int wCount = widgetList.count();
373 int wid = view->columnWidth(0)-1; 398 int wid = view->columnWidth(0)-1;
374 int wd; 399 int wd;
375 int n = 1; 400 int n = 1;
376 401
377 QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget 402 QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget
378 403
379 for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); 404 for (int i = 0; i<wCount; anzIntersect[i] = 1, i++);
380 405
381 if ( wCount < 20 ) { 406 if ( wCount < 20 ) {
382 407
383 QArray<QRect> geometries(wCount); 408 QArray<QRect> geometries(wCount);
384 for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector 409 for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector
385 410
386 for ( int i = 0; i < wCount; i++) 411 for ( int i = 0; i < wCount; i++) {
387 { 412 QValueList<int> intersectedWidgets;
388 QValueList<int> intersectedWidgets; 413
389 414 //find all widgets intersecting with widgetList.at(i)
390 //find all widgets intersecting with widgetList.at(i) 415 for ( int j = 0; j < wCount; j++) {
391 for ( int j = 0; j < wCount; j++) 416 if (i != j)
392 if (i != j) 417 if (geometries[j].intersects(geometries[i]))
393 if (geometries[j].intersects(geometries[i])) 418 intersectedWidgets.append(j);
394 intersectedWidgets.append(j); 419 }
395 420
396 //for each of these intersecting widgets find out how many widgets are they intersecting with 421 //for each of these intersecting widgets find out how many widgets are they intersecting with
397 for ( uint j = 0; j < intersectedWidgets.count(); j++) 422 for ( uint j = 0; j < intersectedWidgets.count(); j++)
398 { 423 {
399 QArray<int> inter(wCount); 424 QArray<int> inter(wCount);
400 inter[j]=1; 425 inter[j]=1;
401 426
402 if (intersectedWidgets[j] != -1) 427 if (intersectedWidgets[j] != -1)
403 for ( uint k = j; k < intersectedWidgets.count(); k++) 428 for ( uint k = j; k < intersectedWidgets.count(); k++) {
404 if (j != k && intersectedWidgets[k] != -1) 429 if (j != k && intersectedWidgets[k] != -1)
405 if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) 430 if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) {
406 { 431 inter[j]++;
407 inter[j]++; 432 intersectedWidgets[k] = -1;
408 intersectedWidgets[k] = -1; 433 }
409 } 434 if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1;
410 if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; 435 }
436 }
437 if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++;
411 } 438 }
412 439
413 if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++;
414 }
415
416
417 for ( int i = 0; i < wCount; i++) {
418 DateBookDayWidget *w = widgetList.at(i);
419 QRect geom = w->geometry();
420
421 geom.setX( 0 );
422
423 wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0);
424 440
425 geom.setWidth( wd ); 441 for ( int i = 0; i < wCount; i++) {
426 442 DateBookDayWidget *w = widgetList.at(i);
427 while ( intersects( w, geom ) ) { 443 QRect geom = w->geometry();
428 geom.moveBy( wd + 2 + 1, 0 ); 444 geom.setX( 0 );
429 } 445 wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0);
430 w->setGeometry( geom ); 446 geom.setWidth( wd );
431 } 447 while ( intersects( w, geom ) ) {
432 448 geom.moveBy( wd + 2 + 1, 0 );
433 if (jumpToCurTime && this->date() == QDate::currentDate()) 449 }
434 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour 450 w->setGeometry( geom );
435 else 451 }
436 view->setContentsPos( 0, startTime * view->rowHeight(0) );
437
438
439 } else {
440 452
453 if (jumpToCurTime && this->date() == QDate::currentDate()) {
454 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour
455 } else {
456 view->setContentsPos( 0, startTime * view->rowHeight(0) );
457 }
458 } else {
459 int hours[24];
460 memset( hours, 0, 24*sizeof( int ) );
461 bool overFlow = FALSE;
462 for ( int i = 0; i < wCount; i++ ) {
463 DateBookDayWidget *w = widgetList.at(i);
464 int start = w->event().start().hour();
465 QTime e = w->event().end();
466 int end = e.hour();
467 if ( e.minute() < 5 )
468 end--;
469 if ( end < start )
470 end = start;
471 while( start <= end ) {
472 hours[start]++;
473 if ( hours[start] >= 10 )
474 overFlow = TRUE;
475 ++start;
476 }
477 if ( overFlow )
478 break;
479 }
480 for ( int i = 0; i < 24; i++ ) {
481 n = QMAX( n, hours[i] );
482 }
483 wid = ( view->columnWidth(0)-1 ) / n;
484
485 bool used[24*10];
486 memset( used, FALSE, 24*10*sizeof( bool ) );
487
488 for ( int i = 0; i < wCount; i++ ) {
489 DateBookDayWidget *w = widgetList.at(i);
490 int xp = place( w, used, n );
491 if ( xp != -1 ) {
492 QRect geom = w->geometry();
493 geom.setX( xp*(wid+2) );
494 geom.setWidth( wid );
495 w->setGeometry( geom );
496 }
497 }
441 498
442 int hours[24]; 499 if (jumpToCurTime && this->date() == QDate::currentDate()) {
443 memset( hours, 0, 24*sizeof( int ) ); 500 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour
444 bool overFlow = FALSE; 501 } else {
445 for ( int i = 0; i < wCount; i++ ) { 502 view->setContentsPos( 0, startTime * view->rowHeight(0) );
446 DateBookDayWidget *w = widgetList.at(i); 503 }
447 int start = w->event().start().hour();
448 QTime e = w->event().end();
449 int end = e.hour();
450 if ( e.minute() < 5 )
451 end--;
452 if ( end < start )
453 end = start;
454 while( start <= end ) {
455 hours[start]++;
456 if ( hours[start] >= 10 )
457 overFlow = TRUE;
458 ++start;
459 }
460 if ( overFlow )
461 break;
462 }
463 for ( int i = 0; i < 24; i++ ) {
464 n = QMAX( n, hours[i] );
465 }
466 wid = ( view->columnWidth(0)-1 ) / n;
467
468 bool used[24*10];
469 memset( used, FALSE, 24*10*sizeof( bool ) );
470
471 for ( int i = 0; i < wCount; i++ ) {
472 DateBookDayWidget *w = widgetList.at(i);
473 int xp = place( w, used, n );
474 if ( xp != -1 ) {
475 QRect geom = w->geometry();
476 geom.setX( xp*(wid+2) );
477 geom.setWidth( wid );
478 w->setGeometry( geom );
479 }
480 } 504 }
481 505
482 if (jumpToCurTime && this->date() == QDate::currentDate()) 506 timeMarker->setTime( QTime::currentTime() );//display timeMarker
483 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour 507 timeMarker->raise(); //on top of all widgets
484 else 508 if (this->date() == QDate::currentDate()) //only show timeMarker on current day
485 view->setContentsPos( 0, startTime * view->rowHeight(0) ); 509 timeMarker->show(); else timeMarker->hide();
486 }
487
488 timeMarker->setTime( QTime::currentTime() );//display timeMarker
489 timeMarker->raise(); //on top of all widgets
490 if (this->date() == QDate::currentDate()) //only show timeMarker on current day
491 timeMarker->show(); else timeMarker->hide();
492 510
493 setUpdatesEnabled( TRUE ); 511 setUpdatesEnabled( TRUE );
494 return; 512 return;
495} 513}
@@ -498,13 +516,13 @@ DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const
498{ 516{
499 int i = 0; 517 int i = 0;
500 DateBookDayWidget *w = widgetList.at(i); 518 DateBookDayWidget *w = widgetList.at(i);
501 int wCount = widgetList.count(); 519 int wCount = widgetList.count();
502 while ( i < wCount && w != item ) { 520 while ( i < wCount && w != item ) {
503 if ( w->geometry().intersects( geom ) ) { 521 if ( w->geometry().intersects( geom ) ) {
504 return w; 522 return w;
523 }
524 w = widgetList.at(++i);
505 } 525 }
506 w = widgetList.at(++i);
507 }
508 526
509 return 0; 527 return 0;
510} 528}
@@ -514,3 +532,3 @@ QDate DateBookDay::date() const
514{ 532{
515 return currDate; 533 return currDate;
516} 534}
@@ -519,17 +537,15 @@ void DateBookDay::setStartViewTime( int startHere )
519{ 537{
520 startTime = startHere; 538 startTime = startHere;
521 dayView()->clearSelection(); 539 dayView()->clearSelection();
522 QTableSelection ts; 540 QTableSelection ts;
523 541
524 if (jumpToCurTime && this->date() == QDate::currentDate())//this should probably be in datebook.cpp where it's called? 542 if (jumpToCurTime && this->date() == QDate::currentDate()) {//this should probably be in datebook.cpp where it's called?
525 { 543 ts.init( QTime::currentTime().hour(), 0);
526 ts.init( QTime::currentTime().hour(), 0); 544 ts.expandTo( QTime::currentTime().hour(), 0);
527 ts.expandTo( QTime::currentTime().hour(), 0); 545 } else {
528 } else 546 ts.init( startTime, 0 );
529 { 547 ts.expandTo( startTime, 0 );
530 ts.init( startTime, 0 ); 548 }
531 ts.expandTo( startTime, 0 );
532 }
533 549
534 dayView()->addSelection( ts ); 550 dayView()->addSelection( ts );
535} 551}
@@ -538,3 +554,3 @@ int DateBookDay::startViewTime() const
538{ 554{
539 return startTime; 555 return startTime;
540} 556}
@@ -543,4 +559,4 @@ void DateBookDay::slotWeekChanged( bool bStartOnMonday )
543{ 559{
544 header->setStartOfWeek( bStartOnMonday ); 560 header->setStartOfWeek( bStartOnMonday );
545 // redraw(); 561 //redraw();
546} 562}
@@ -549,18 +565,18 @@ void DateBookDay::keyPressEvent(QKeyEvent *e)
549{ 565{
550 switch(e->key()) { 566 switch(e->key()) {
551 case Key_Up: 567 case Key_Up:
552 view->moveUp(); 568 view->moveUp();
553 break; 569 break;
554 case Key_Down: 570 case Key_Down:
555 view->moveDown(); 571 view->moveDown();
556 break; 572 break;
557 case Key_Left: 573 case Key_Left:
558 setDate(QDate(currDate).addDays(-1)); 574 setDate(QDate(currDate).addDays(-1));
559 break; 575 break;
560 case Key_Right: 576 case Key_Right:
561 setDate(QDate(currDate).addDays(1)); 577 setDate(QDate(currDate).addDays(1));
562 break; 578 break;
563 default: 579 default:
564 e->ignore(); 580 e->ignore();
565 } 581 }
566} 582}
@@ -569,20 +585,17 @@ void DateBookDay::keyPressEvent(QKeyEvent *e)
569 585
570DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, 586DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db )
571 DateBookDay *db ) 587 : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db )
572 : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db )
573{ 588{
574
575
576 // why would someone use "<"? Oh well, fix it up... 589 // why would someone use "<"? Oh well, fix it up...
577 // I wonder what other things may be messed up... 590 // I wonder what other things may be messed up...
578 QString strDesc = ev.description(); 591 QString strDesc = ev.description();
579 int where = strDesc.find( "<" ); 592 int where = strDesc.find( "<" );
580 while ( where != -1 ) { 593 while ( where != -1 ) {
581 strDesc.remove( where, 1 ); 594 strDesc.remove( where, 1 );
582 strDesc.insert( where, "&#60;" ); 595 strDesc.insert( where, "&#60;" );
583 where = strDesc.find( "<", where ); 596 where = strDesc.find( "<", where );
584 } 597 }
585 598
586 QString strCat; 599 QString strCat;
587 // ### Fix later... 600// ### Fix later...
588// QString strCat = ev.category(); 601// QString strCat = ev.category();
@@ -607,10 +620,11 @@ DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e,
607 } 620 }
608 if (ev.event().type() == Event::Normal ) 621 if (ev.event().type() == Event::Normal ) {
609 setEventText( text ); 622 setEventText( text );
610 else 623 } else {
611 setAllDayText( text ); 624 setAllDayText( text );
625 }
612 626
613 text += "<br><br>" + strNote; 627 text += "<br><br>" + strNote;
614 628
615 setBackgroundMode( PaletteBase ); 629 setBackgroundMode( PaletteBase );
616 630
@@ -632,5 +646,7 @@ DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e,
632} 646}
647
633void DateBookDayWidget::setAllDayText( QString &text ) { 648void DateBookDayWidget::setAllDayText( QString &text ) {
634 text += "<b>" + tr("This is an all day event.") + "</b>"; 649 text += "<b>" + tr("This is an all day event.") + "</b>";
635} 650}
651
636void DateBookDayWidget::setEventText( QString& text ) { 652void DateBookDayWidget::setEventText( QString& text ) {
@@ -658,34 +674,26 @@ void DateBookDayWidget::paintEvent( QPaintEvent *e )
658{ 674{
659 QPainter p( this ); 675 QPainter p( this );
660 676
661 if (dateBook->getSelectedWidget() == this) 677 if (dateBook->getSelectedWidget() == this) {
662 { 678 p.setBrush( QColor( 155, 240, 230 ) ); // selected item
663 p.setBrush( QColor( 155, 240, 230 ) ); // selected item 679 } else {
664 } else 680 if (dateBook->date() == QDate::currentDate()) {
665 { 681 QTime curTime = QTime::currentTime();
666 if (dateBook->date() == QDate::currentDate()) 682 if (ev.end() < curTime) {
667 { 683 p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive
668 QTime curTime = QTime::currentTime(); 684 } else {
669 685 //change color in dependence of the time till the event starts
670 if (ev.end() < curTime) 686 int duration = curTime.secsTo(ev.start());
671 { 687 if (duration < 0) duration = 0;
672 p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive 688 int colChange = duration*160/86400; //86400: secs per day, 160: max color shift
673 } else 689 p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue
674 { 690 }
675 //change color in dependence of the time till the event starts 691 } else {
676 int duration = curTime.secsTo(ev.start()); 692 p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date)
677 if (duration < 0) duration = 0; 693 //perhaps make a distinction between future/past dates
678 int colChange = duration*160/86400; //86400: secs per day, 160: max color shift 694 }
679 695 }
680 p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue
681 }
682 } else
683 {
684 p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date)
685 //perhaps make a distinction between future/past dates
686 }
687 }
688 696
689 p.setPen( QColor(100, 100, 100) ); 697 p.setPen( QColor(100, 100, 100) );
690 p.drawRect(rect()); 698 p.drawRect(rect());
691 699
@@ -693,20 +701,20 @@ void DateBookDayWidget::paintEvent( QPaintEvent *e )
693 701
694 int y = 0; 702 int y = 0;
695 int d = 0; 703 int d = 0;
696 704
697 if ( ev.event().hasAlarm() ) { 705 if ( ev.event().hasAlarm() ) {
698 p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); 706 p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) );
699 y = 20; 707 y = 20;
700 d = 20; 708 d = 20;
701 } 709 }
702 710
703 if ( ev.event().hasRepeat() ) { 711 if ( ev.event().hasRepeat() ) {
704 p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); 712 p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) );
705 d = 20; 713 d = 20;
706 y += 20; 714 y += 20;
707 } 715 }
708 716
709 QSimpleRichText rt( text, font() ); 717 QSimpleRichText rt( text, font() );
710 rt.setWidth( geom.width() - d - 6 ); 718 rt.setWidth( geom.width() - d - 6 );
711 rt.draw( &p, 7, 0, e->region(), colorGroup() ); 719 rt.draw( &p, 7, 0, e->region(), colorGroup() );
712} 720}
@@ -718,3 +726,4 @@ void DateBookDayWidget::mousePressEvent( QMouseEvent *e )
718 item = dateBook->getSelectedWidget(); 726 item = dateBook->getSelectedWidget();
719 if (item) item->update(); 727 if (item)
728 item->update();
720 729
@@ -743,6 +752,6 @@ void DateBookDayWidget::setGeometry( const QRect &r )
743{ 752{
744 geom = r; 753 geom = r;
745 setFixedSize( r.width()+1, r.height()+1 ); 754 setFixedSize( r.width()+1, r.height()+1 );
746 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); 755 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 );
747 show(); 756 show();
748} 757}
@@ -755,3 +764,3 @@ void DateBookDayWidget::setGeometry( const QRect &r )
755DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) 764DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db )
756 : QWidget( db->dayView()->viewport() ), dateBook( db ) 765 : QWidget( db->dayView()->viewport() ), dateBook( db )
757{ 766{
@@ -797,6 +806,6 @@ void DateBookDayTimeMarker::setGeometry( const QRect &r )
797{ 806{
798 geom = r; 807 geom = r;
799 setFixedSize( r.width()+1, r.height()+1 ); 808 setFixedSize( r.width()+1, r.height()+1 );
800 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); 809 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 );
801 show(); 810 show();
802} 811}
diff --git a/core/pim/datebook/datebookday.h b/core/pim/datebook/datebookday.h
index 2faf24e..961f60f 100644
--- a/core/pim/datebook/datebookday.h
+++ b/core/pim/datebook/datebookday.h
@@ -29,2 +29,5 @@
29 29
30#include "datebook.h"
31#include <qlineedit.h>
32
30class DateBookDayHeader; 33class DateBookDayHeader;
@@ -36,2 +39,18 @@ class QResizeEvent;
36 39
40class DateBookDayViewQuickLineEdit : public QLineEdit
41{
42 Q_OBJECT
43public:
44 DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name=0);
45protected:
46 Event quickEvent;
47 int active;
48 void focusOutEvent( QFocusEvent *e );
49protected slots:
50 void slotReturnPressed(void);
51signals:
52 void insertEvent(const Event &e);
53};
54
55
37class DateBookDayView : public QTable 56class DateBookDayView : public QTable
@@ -48,2 +67,3 @@ public slots:
48 void moveDown(); 67 void moveDown();
68 void slotDateChanged( int year, int month, int day );
49 69
@@ -53,3 +73,3 @@ signals:
53protected slots: 73protected slots:
54 void slotChangeClock( bool ); 74 void slotChangeClock( bool );
55protected: 75protected:
@@ -60,2 +80,3 @@ protected:
60 void keyPressEvent( QKeyEvent *e ); 80 void keyPressEvent( QKeyEvent *e );
81 void contentsMouseReleaseEvent( QMouseEvent *e );
61 void initHeader(); 82 void initHeader();
@@ -63,2 +84,4 @@ private:
63 bool ampm; 84 bool ampm;
85 QDate currDate;
86 DateBookDayViewQuickLineEdit *quickLineEdit;
64}; 87};