summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-16 21:32:58 (UTC)
committer zecke <zecke>2004-02-16 21:32:58 (UTC)
commite228f4aa24ce73a49dde349544e55689cb0eccba (patch) (unidiff)
tree5b9be29793b2a72f9260cb1325751d31e40c18f0
parent38d601a7d2a975bc0cbcc4cc933844f5572ec4fa (diff)
downloadopie-e228f4aa24ce73a49dde349544e55689cb0eccba.zip
opie-e228f4aa24ce73a49dde349544e55689cb0eccba.tar.gz
opie-e228f4aa24ce73a49dde349544e55689cb0eccba.tar.bz2
Take care of the lifetime of the EffectiveEvent/Occurence
Make sure not to keep reference on non existing objects
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebookday.cpp10
-rw-r--r--core/pim/datebook/datebookday.h2
-rw-r--r--core/pim/datebook/datebookdayallday.cpp11
-rw-r--r--core/pim/datebook/datebookweek.cpp4
4 files changed, 13 insertions, 14 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp
index 4d64099..751a1da 100644
--- a/core/pim/datebook/datebookday.cpp
+++ b/core/pim/datebook/datebookday.cpp
@@ -1,933 +1,935 @@
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 20
21#include "datebookday.h" 21#include "datebookday.h"
22#include "datebookdayheaderimpl.h" 22#include "datebookdayheaderimpl.h"
23#include "datebookdayallday.h" 23#include "datebookdayallday.h"
24 24
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
27#include <qpe/ir.h> 27#include <qpe/ir.h>
28 28
29#include <qsimplerichtext.h> 29#include <qsimplerichtext.h>
30#include <qpopupmenu.h> 30#include <qpopupmenu.h>
31 31
32 32
33#include <qtimer.h> 33#include <qtimer.h>
34 34
35DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, const char *name ) 35DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, const char *name )
36 : QTable( 24, 1, parent, name ), ampm( whichClock ), currDate( QDate::currentDate() ) 36 : QTable( 24, 1, parent, name ), ampm( whichClock ), currDate( QDate::currentDate() )
37{ 37{
38 enableClipper(TRUE); 38 enableClipper(TRUE);
39 setTopMargin( 0 ); 39 setTopMargin( 0 );
40 horizontalHeader()->hide(); 40 horizontalHeader()->hide();
41 setLeftMargin(38); 41 setLeftMargin(38);
42 setColumnStretchable( 0, TRUE ); 42 setColumnStretchable( 0, TRUE );
43 setHScrollBarMode( QScrollView::AlwaysOff ); 43 setHScrollBarMode( QScrollView::AlwaysOff );
44 verticalHeader()->setPalette(white); 44 verticalHeader()->setPalette(white);
45 verticalHeader()->setResizeEnabled(FALSE); 45 verticalHeader()->setResizeEnabled(FALSE);
46 setSelectionMode( Single ); 46 setSelectionMode( Single );
47 47
48 // get rid of being able to edit things... 48 // get rid of being able to edit things...
49 QTableItem *tmp; 49 QTableItem *tmp;
50 int row; 50 int row;
51 for ( row = 0; row < numRows(); row++ ) { 51 for ( row = 0; row < numRows(); row++ ) {
52 tmp = new QTableItem( this, QTableItem::Never, QString::null); 52 tmp = new QTableItem( this, QTableItem::Never, QString::null);
53 setItem( row, 0, tmp ); 53 setItem( row, 0, tmp );
54 //setRowHeight( row, 40); 54 //setRowHeight( row, 40);
55 } 55 }
56 56
57 initHeader(); 57 initHeader();
58 QObject::connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotChangeClock(bool)) ); 58 QObject::connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotChangeClock(bool)) );
59} 59}
60 60
61void DateBookDayView::initHeader() 61void DateBookDayView::initHeader()
62{ 62{
63 QString strTmp; 63 QString strTmp;
64 int preferredWidth = 0; 64 int preferredWidth = 0;
65 for ( int i = 0; i < 24; ++i ) { 65 for ( int i = 0; i < 24; ++i ) {
66 if ( ampm ) { 66 if ( ampm ) {
67 if ( i == 0 ) 67 if ( i == 0 )
68 strTmp = QString::number(12) + ":00"; 68 strTmp = QString::number(12) + ":00";
69 else if ( i == 12 ) 69 else if ( i == 12 )
70 strTmp = QString::number(12) + tr(":00p"); 70 strTmp = QString::number(12) + tr(":00p");
71 else if ( i > 12 ) 71 else if ( i > 12 )
72 strTmp = QString::number( i - 12 ) + tr(":00p"); 72 strTmp = QString::number( i - 12 ) + tr(":00p");
73 else 73 else
74 strTmp = QString::number(i) + ":00"; 74 strTmp = QString::number(i) + ":00";
75 } else { 75 } else {
76 if ( i < 10 ) 76 if ( i < 10 )
77 strTmp = "0" + QString::number(i) + ":00"; 77 strTmp = "0" + QString::number(i) + ":00";
78 else 78 else
79 strTmp = QString::number(i) + ":00"; 79 strTmp = QString::number(i) + ":00";
80 } 80 }
81 strTmp = strTmp.rightJustify( 6, ' ' ); 81 strTmp = strTmp.rightJustify( 6, ' ' );
82 verticalHeader()->setLabel( i, strTmp ); 82 verticalHeader()->setLabel( i, strTmp );
83 83
84 // Compute correct width for current Font (Add some space right) 84 // Compute correct width for current Font (Add some space right)
85 int actWidth = QFontMetrics( QFont::defaultFont() ).width( strTmp + QString(" ") ); 85 int actWidth = QFontMetrics( QFont::defaultFont() ).width( strTmp + QString(" ") );
86 if ( preferredWidth < actWidth ) 86 if ( preferredWidth < actWidth )
87 preferredWidth = actWidth; 87 preferredWidth = actWidth;
88 setRowStretchable( i, FALSE ); 88 setRowStretchable( i, FALSE );
89 } 89 }
90 90
91 // It seems as if the header has a bug. It does not resize 91 // It seems as if the header has a bug. It does not resize
92 // correct horizontally if it is used vertical.. 92 // correct horizontally if it is used vertical..
93 // Thus, we do it manually.. 93 // Thus, we do it manually..
94 setLeftMargin( preferredWidth ); 94 setLeftMargin( preferredWidth );
95} 95}
96 96
97void DateBookDayView::slotDateChanged( int y, int m, int d ) 97void DateBookDayView::slotDateChanged( int y, int m, int d )
98{ 98{
99 currDate.setYMD(y,m,d); 99 currDate.setYMD(y,m,d);
100} 100}
101 101
102void DateBookDayView::slotChangeClock( bool newClock ) 102void DateBookDayView::slotChangeClock( bool newClock )
103{ 103{
104 ampm = newClock; 104 ampm = newClock;
105 initHeader(); 105 initHeader();
106} 106}
107 107
108bool DateBookDayView::whichClock() const 108bool DateBookDayView::whichClock() const
109{ 109{
110 return ampm; 110 return ampm;
111} 111}
112 112
113void DateBookDayView::moveUp() 113void DateBookDayView::moveUp()
114{ 114{
115 scrollBy(0, -20); 115 scrollBy(0, -20);
116} 116}
117 117
118void DateBookDayView::moveDown() 118void DateBookDayView::moveDown()
119{ 119{
120 scrollBy(0, 20); 120 scrollBy(0, 20);
121} 121}
122 122
123void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) 123void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool )
124{ 124{
125 int w = cr.width(); 125 int w = cr.width();
126 int h = cr.height(); 126 int h = cr.height();
127 p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); 127 p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) );
128 if ( showGrid() ) { 128 if ( showGrid() ) {
129 // Draw our lines 129 // Draw our lines
130 int x2 = w - 1; 130 int x2 = w - 1;
131 int y2 = h - 1; 131 int y2 = h - 1;
132 QPen pen( p->pen() ); 132 QPen pen( p->pen() );
133 p->setPen( colorGroup().dark() ); 133 p->setPen( colorGroup().dark() );
134 p->drawLine( x2, 0, x2, y2 ); 134 p->drawLine( x2, 0, x2, y2 );
135 p->drawLine( 0, y2, x2, y2 ); 135 p->drawLine( 0, y2, x2, y2 );
136 136
137 p->setPen( colorGroup().midlight() ); 137 p->setPen( colorGroup().midlight() );
138 p->drawLine( 0, y2 - h/2, x2, y2 - h/2); 138 p->drawLine( 0, y2 - h/2, x2, y2 - h/2);
139 139
140 p->setPen( pen ); 140 p->setPen( pen );
141 } 141 }
142} 142}
143 143
144void DateBookDayView::paintFocus( QPainter *, const QRect & ) 144void DateBookDayView::paintFocus( QPainter *, const QRect & )
145{ 145{
146} 146}
147 147
148void DateBookDayView::resizeEvent( QResizeEvent *e ) 148void DateBookDayView::resizeEvent( QResizeEvent *e )
149{ 149{
150 QTable::resizeEvent( e ); 150 QTable::resizeEvent( e );
151 columnWidthChanged( 0 ); 151 columnWidthChanged( 0 );
152 emit sigColWidthChanged(); 152 emit sigColWidthChanged();
153} 153}
154 154
155void DateBookDayView::keyPressEvent( QKeyEvent *e ) 155void DateBookDayView::keyPressEvent( QKeyEvent *e )
156{ 156{
157 QString txt = e->text(); 157 QString txt = e->text();
158 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { 158 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) {
159 // we this is some sort of thing we know about... 159 // we this is some sort of thing we know about...
160 e->accept(); 160 e->accept();
161 emit sigCapturedKey( txt ); 161 emit sigCapturedKey( txt );
162 } else { 162 } else {
163 // I don't know what this key is, do you? 163 // I don't know what this key is, do you?
164 e->ignore(); 164 e->ignore();
165 } 165 }
166} 166}
167 167
168void DateBookDayView::setRowStyle( int style ) 168void DateBookDayView::setRowStyle( int style )
169{ 169{
170 if (style<0) style = 0; 170 if (style<0) style = 0;
171 171
172 for (int i=0; i<numRows(); i++) 172 for (int i=0; i<numRows(); i++)
173 setRowHeight(i, style*10+20); 173 setRowHeight(i, style*10+20);
174} 174}
175 175
176void DateBookDayView::contentsMouseReleaseEvent( QMouseEvent* /* e */ ) 176void DateBookDayView::contentsMouseReleaseEvent( QMouseEvent* /* e */ )
177{ 177{
178 int sh=99,eh=-1; 178 int sh=99,eh=-1;
179 179
180 for(int i=0;i<this->numSelections();i++) { 180 for(int i=0;i<this->numSelections();i++) {
181 QTableSelection sel = this->selection( i ); 181 QTableSelection sel = this->selection( i );
182 sh = QMIN(sh,sel.topRow()); 182 sh = QMIN(sh,sel.topRow());
183 eh = QMAX(sh,sel.bottomRow()+1); 183 eh = QMAX(sh,sel.bottomRow()+1);
184 } 184 }
185 if (sh > 23 || eh < 1) { 185 if (sh > 23 || eh < 1) {
186 sh=8; 186 sh=8;
187 eh=9; 187 eh=9;
188 } 188 }
189 189
190 quickLineEdit=new DateBookDayViewQuickLineEdit(QDateTime(currDate,QTime(sh,0,0,0)),QDateTime(currDate,QTime(eh,0,0,0)),this->viewport(),"quickedit"); 190 quickLineEdit=new DateBookDayViewQuickLineEdit(QDateTime(currDate,QTime(sh,0,0,0)),QDateTime(currDate,QTime(eh,0,0,0)),this->viewport(),"quickedit");
191 quickLineEdit->setGeometry(0,0,this->columnWidth(0)-1,this->rowHeight(0)); 191 quickLineEdit->setGeometry(0,0,this->columnWidth(0)-1,this->rowHeight(0));
192 this->moveChild(quickLineEdit,0,sh*this->rowHeight(0)); 192 this->moveChild(quickLineEdit,0,sh*this->rowHeight(0));
193 quickLineEdit->setFocus(); 193 quickLineEdit->setFocus();
194 quickLineEdit->show(); 194 quickLineEdit->show();
195} 195}
196 196
197//=========================================================================== 197//===========================================================================
198 198
199DateBookDayViewQuickLineEdit::DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name) : QLineEdit(parent,name) 199DateBookDayViewQuickLineEdit::DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name) : QLineEdit(parent,name)
200{ 200{
201 active=1; 201 active=1;
202 quickEvent.setStart(start); 202 quickEvent.setStart(start);
203 quickEvent.setEnd(end); 203 quickEvent.setEnd(end);
204 connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed())); 204 connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed()));
205} 205}
206 206
207void DateBookDayViewQuickLineEdit::slotReturnPressed() 207void DateBookDayViewQuickLineEdit::slotReturnPressed()
208{ 208{
209 if(active && (!this->text().isEmpty())) {// Fix to avoid having this event beeing added multiple times. 209 if(active && (!this->text().isEmpty())) {// Fix to avoid having this event beeing added multiple times.
210 quickEvent.setDescription(this->text()); 210 quickEvent.setDescription(this->text());
211 connect(this,SIGNAL(insertEvent(const Event &)),this->topLevelWidget(),SLOT(insertEvent(const Event &))); 211 connect(this,SIGNAL(insertEvent(const Event &)),this->topLevelWidget(),SLOT(insertEvent(const Event &)));
212 emit(insertEvent(quickEvent)); 212 emit(insertEvent(quickEvent));
213 active=0; 213 active=0;
214 } 214 }
215 /* we need to return to this object.. */ 215 /* we need to return to this object.. */
216 QTimer::singleShot(500, this, SLOT(finallyCallClose()) );// Close and also delete this widget 216 QTimer::singleShot(500, this, SLOT(finallyCallClose()) );// Close and also delete this widget
217} 217}
218void DateBookDayViewQuickLineEdit::finallyCallClose() { 218void DateBookDayViewQuickLineEdit::finallyCallClose() {
219 close(true); // also deletes this widget... 219 close(true); // also deletes this widget...
220} 220}
221 221
222void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent* /* e */) 222void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent* /* e */)
223{ 223{
224 slotReturnPressed(); // Reuse code to add event and close this widget. 224 slotReturnPressed(); // Reuse code to add event and close this widget.
225} 225}
226 226
227//=========================================================================== 227//===========================================================================
228 228
229DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name ) 229DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name )
230 : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 ) 230 : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 )
231{ 231{
232 widgetList.setAutoDelete( true ); 232 widgetList.setAutoDelete( true );
233 header = new DateBookDayHeader( startOnMonday, this, "day header" ); 233 header = new DateBookDayHeader( startOnMonday, this, "day header" );
234 header->setDate( currDate.year(), currDate.month(), currDate.day() ); 234 header->setDate( currDate.year(), currDate.month(), currDate.day() );
235 235
236 m_allDays = new DatebookdayAllday(newDb, this, "all day event list" ); 236 m_allDays = new DatebookdayAllday(newDb, this, "all day event list" );
237 m_allDays->hide(); 237 m_allDays->hide();
238 238
239 view = new DateBookDayView( ampm, this, "day view" ); 239 view = new DateBookDayView( ampm, this, "day view" );
240 240
241 connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( int, int, int ) ) ); 241 connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( int, int, int ) ) );
242 connect( header, SIGNAL( dateChanged( int, int, int ) ), view, SLOT( slotDateChanged( int, int, int ) ) ); 242 connect( header, SIGNAL( dateChanged( int, int, int ) ), view, SLOT( slotDateChanged( int, int, int ) ) );
243 connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) ); 243 connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) );
244 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); 244 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) );
245 connect( view, SIGNAL(sigCapturedKey(const QString &)), this, SIGNAL(sigNewEvent(const QString&)) ); 245 connect( view, SIGNAL(sigCapturedKey(const QString &)), this, SIGNAL(sigNewEvent(const QString&)) );
246 246
247 QTimer *timer = new QTimer( this ); 247 QTimer *timer = new QTimer( this );
248 248
249 connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors 249 connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors
250 timer->start( 1000*60*5, FALSE ); //update every 5min 250 timer->start( 1000*60*5, FALSE ); //update every 5min
251 251
252 selectedWidget = 0; 252 selectedWidget = 0;
253 253
254 timeMarker = new DateBookDayTimeMarker( this ); 254 timeMarker = new DateBookDayTimeMarker( this );
255 timeMarker->setTime( QTime::currentTime() ); 255 timeMarker->setTime( QTime::currentTime() );
256 rowStyle = -1; // initialize with bogus values 256 rowStyle = -1; // initialize with bogus values
257 jumpToCurTime = false; 257 jumpToCurTime = false;
258} 258}
259 259
260void DateBookDay::setJumpToCurTime( bool bJump ) 260void DateBookDay::setJumpToCurTime( bool bJump )
261{ 261{
262 jumpToCurTime = bJump; 262 jumpToCurTime = bJump;
263} 263}
264 264
265void DateBookDay::setRowStyle( int style ) 265void DateBookDay::setRowStyle( int style )
266{ 266{
267 if (rowStyle != style) view->setRowStyle( style ); 267 if (rowStyle != style) view->setRowStyle( style );
268 rowStyle = style; 268 rowStyle = style;
269} 269}
270 270
271void DateBookDay::updateView( void ) 271void DateBookDay::updateView( void )
272{ 272{
273 timeMarker->setTime( QTime::currentTime() ); 273 timeMarker->setTime( QTime::currentTime() );
274 //need to find a way to update all DateBookDayWidgets 274 //need to find a way to update all DateBookDayWidgets
275} 275}
276 276
277void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) 277void DateBookDay::setSelectedWidget( DateBookDayWidget *w )
278{ 278{
279 selectedWidget = w; 279 selectedWidget = w;
280} 280}
281 281
282DateBookDayWidget * DateBookDay::getSelectedWidget( void ) 282DateBookDayWidget * DateBookDay::getSelectedWidget( void )
283{ 283{
284 return selectedWidget; 284 return selectedWidget;
285} 285}
286 286
287void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) 287void DateBookDay::selectedDates( QDateTime &start, QDateTime &end )
288{ 288{
289 start.setDate( currDate ); 289 start.setDate( currDate );
290 end.setDate( currDate ); 290 end.setDate( currDate );
291 291
292 int sh=99,eh=-1; 292 int sh=99,eh=-1;
293 293
294 int n = dayView()->numSelections(); 294 int n = dayView()->numSelections();
295 295
296 for (int i=0; i<n; i++) { 296 for (int i=0; i<n; i++) {
297 QTableSelection sel = dayView()->selection( i ); 297 QTableSelection sel = dayView()->selection( i );
298 sh = QMIN(sh,sel.topRow()); 298 sh = QMIN(sh,sel.topRow());
299 eh = QMAX(sh,sel.bottomRow()+1); 299 eh = QMAX(sh,sel.bottomRow()+1);
300 } 300 }
301 301
302 if (sh > 23 || eh < 1) { 302 if (sh > 23 || eh < 1) {
303 sh=8; 303 sh=8;
304 eh=9; 304 eh=9;
305 } 305 }
306 306
307 start.setTime( QTime( sh, 0, 0 ) ); 307 start.setTime( QTime( sh, 0, 0 ) );
308 end.setTime( QTime( eh, 0, 0 ) ); 308 end.setTime( QTime( eh, 0, 0 ) );
309} 309}
310 310
311void DateBookDay::setDate( int y, int m, int d ) 311void DateBookDay::setDate( int y, int m, int d )
312{ 312{
313 header->setDate( y, m, d ); 313 header->setDate( y, m, d );
314 selectedWidget = 0; 314 selectedWidget = 0;
315} 315}
316 316
317void DateBookDay::setDate( QDate d) 317void DateBookDay::setDate( QDate d)
318{ 318{
319 header->setDate( d.year(), d.month(), d.day() ); 319 header->setDate( d.year(), d.month(), d.day() );
320 selectedWidget = 0; 320 selectedWidget = 0;
321} 321}
322 322
323void DateBookDay::dateChanged( int y, int m, int d ) 323void DateBookDay::dateChanged( int y, int m, int d )
324{ 324{
325 QDate date( y, m, d ); 325 QDate date( y, m, d );
326 if ( currDate == date ) 326 if ( currDate == date )
327 return; 327 return;
328 currDate.setYMD( y, m, d ); 328 currDate.setYMD( y, m, d );
329 relayoutPage(); 329 relayoutPage();
330 dayView()->clearSelection(); 330 dayView()->clearSelection();
331 QTableSelection ts; 331 QTableSelection ts;
332 332
333 if (jumpToCurTime && this->date() == QDate::currentDate()) 333 if (jumpToCurTime && this->date() == QDate::currentDate())
334 { 334 {
335 ts.init( QTime::currentTime().hour(), 0); 335 ts.init( QTime::currentTime().hour(), 0);
336 ts.expandTo( QTime::currentTime().hour(), 0); 336 ts.expandTo( QTime::currentTime().hour(), 0);
337 } else { 337 } else {
338 ts.init( startTime, 0 ); 338 ts.init( startTime, 0 );
339 ts.expandTo( startTime, 0 ); 339 ts.expandTo( startTime, 0 );
340 } 340 }
341 341
342 dayView()->addSelection( ts ); 342 dayView()->addSelection( ts );
343 selectedWidget = 0; 343 selectedWidget = 0;
344} 344}
345 345
346void DateBookDay::redraw() 346void DateBookDay::redraw()
347{ 347{
348 if ( isUpdatesEnabled() ) 348 if ( isUpdatesEnabled() )
349 relayoutPage(); 349 relayoutPage();
350} 350}
351 351
352void DateBookDay::getEvents() 352void DateBookDay::getEvents()
353{ 353{
354 widgetList.clear(); 354 widgetList.clear();
355 355
356 /* clear the AllDay List */ 356 /* clear the AllDay List */
357 m_allDays->hide(); // just in case 357 m_allDays->hide(); // just in case
358 m_allDays->removeAllEvents(); 358 m_allDays->removeAllEvents();
359 359
360 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); 360 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate );
361 QValueListIterator<EffectiveEvent> it; 361 QValueListIterator<EffectiveEvent> it;
362 QObject* object = 0; 362 QObject* object = 0;
363 for ( it = eventList.begin(); it != eventList.end(); ++it ) { 363 for ( it = eventList.begin(); it != eventList.end(); ++it ) {
364 EffectiveEvent ev=*it; 364 EffectiveEvent ev=*it;
365 if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) {// Skip events ending at 00:00 starting at another day. 365 if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) {// Skip events ending at 00:00 starting at another day.
366 if (ev.event().type() == Event::AllDay ) { 366 if (ev.event().type() == Event::AllDay ) {
367 object = m_allDays->addEvent( ev ); 367 object = m_allDays->addEvent( ev );
368 if (!object) 368 if (!object)
369 continue; 369 continue;
370 }else { 370 }else {
371 DateBookDayWidget* w = new DateBookDayWidget( *it, this ); 371 DateBookDayWidget* w = new DateBookDayWidget( *it, this );
372 widgetList.append( w ); 372 widgetList.append( w );
373 object = w; 373 object = w;
374 } 374 }
375 375
376 connect( object, SIGNAL( deleteMe( const Event & ) ), this, SIGNAL( removeEvent( const Event & ) ) ); 376 connect( object, SIGNAL( deleteMe( const Event & ) ), this, SIGNAL( removeEvent( const Event & ) ) );
377 connect( object, SIGNAL( duplicateMe( const Event & ) ), this, SIGNAL( duplicateEvent( const Event & ) ) ); 377 connect( object, SIGNAL( duplicateMe( const Event & ) ), this, SIGNAL( duplicateEvent( const Event & ) ) );
378 connect( object, SIGNAL( editMe( const Event & ) ), this, SIGNAL( editEvent( const Event & ) ) ); 378 connect( object, SIGNAL( editMe( const Event & ) ), this, SIGNAL( editEvent( const Event & ) ) );
379 connect( object, SIGNAL( beamMe( const Event & ) ), this, SIGNAL( beamEvent( const Event & ) ) ); 379 connect( object, SIGNAL( beamMe( const Event & ) ), this, SIGNAL( beamEvent( const Event & ) ) );
380 380
381 } 381 }
382 } 382 }
383} 383}
384 384
385static int place( const DateBookDayWidget *item, bool *used, int maxn ) 385static int place( const DateBookDayWidget *item, bool *used, int maxn )
386{ 386{
387 int place = 0; 387 int place = 0;
388 int start = item->event().start().hour(); 388 int start = item->event().start().hour();
389 QTime e = item->event().end(); 389 QTime e = item->event().end();
390 int end = e.hour(); 390 int end = e.hour();
391 if ( e.minute() < 5 ) 391 if ( e.minute() < 5 )
392 end--; 392 end--;
393 if ( end < start ) 393 if ( end < start )
394 end = start; 394 end = start;
395 while ( place < maxn ) { 395 while ( place < maxn ) {
396 bool free = TRUE; 396 bool free = TRUE;
397 int s = start; 397 int s = start;
398 while( s <= end ) { 398 while( s <= end ) {
399 if ( used[10*s+place] ) { 399 if ( used[10*s+place] ) {
400 free = FALSE; 400 free = FALSE;
401 break; 401 break;
402 } 402 }
403 s++; 403 s++;
404 } 404 }
405 if ( free ) 405 if ( free )
406 break; 406 break;
407 place++; 407 place++;
408 } 408 }
409 if ( place == maxn ) { 409 if ( place == maxn ) {
410 return -1; 410 return -1;
411 } 411 }
412 while( start <= end ) { 412 while( start <= end ) {
413 used[10*start+place] = TRUE; 413 used[10*start+place] = TRUE;
414 start++; 414 start++;
415 } 415 }
416 return place; 416 return place;
417} 417}
418 418
419 419
420void DateBookDay::relayoutPage( bool fromResize ) 420void DateBookDay::relayoutPage( bool fromResize )
421{ 421{
422 setUpdatesEnabled( FALSE ); 422 setUpdatesEnabled( FALSE );
423 if ( !fromResize ) { 423 if ( !fromResize ) {
424 getEvents(); // no need we already have them! 424 getEvents(); // no need we already have them!
425 425
426 if (m_allDays->items() > 0 ) 426 if (m_allDays->items() > 0 )
427 m_allDays->show(); 427 m_allDays->show();
428 /* 428 /*
429 * else if ( m_allDays->items() == 0 ) already hide in getEvents 429 * else if ( m_allDays->items() == 0 ) already hide in getEvents
430 */ 430 */
431 } 431 }
432 432
433 widgetList.sort(); 433 widgetList.sort();
434 //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning 434 //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning
435 //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view 435 //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view
436 436
437 int wCount = widgetList.count(); 437 int wCount = widgetList.count();
438 int wid = view->columnWidth(0)-1; 438 int wid = view->columnWidth(0)-1;
439 int wd; 439 int wd;
440 int n = 1; 440 int n = 1;
441 441
442 QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget 442 QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget
443 443
444 for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); 444 for (int i = 0; i<wCount; anzIntersect[i] = 1, i++);
445 445
446 if ( wCount < 20 ) { 446 if ( wCount < 20 ) {
447 447
448 QArray<QRect> geometries(wCount); 448 QArray<QRect> geometries(wCount);
449 for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector 449 for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector
450 450
451 for ( int i = 0; i < wCount; i++) { 451 for ( int i = 0; i < wCount; i++) {
452 QValueList<int> intersectedWidgets; 452 QValueList<int> intersectedWidgets;
453 453
454 //find all widgets intersecting with widgetList.at(i) 454 //find all widgets intersecting with widgetList.at(i)
455 for ( int j = 0; j < wCount; j++) { 455 for ( int j = 0; j < wCount; j++) {
456 if (i != j) 456 if (i != j)
457 if (geometries[j].intersects(geometries[i])) 457 if (geometries[j].intersects(geometries[i]))
458 intersectedWidgets.append(j); 458 intersectedWidgets.append(j);
459 } 459 }
460 460
461 //for each of these intersecting widgets find out how many widgets are they intersecting with 461 //for each of these intersecting widgets find out how many widgets are they intersecting with
462 for ( uint j = 0; j < intersectedWidgets.count(); j++) 462 for ( uint j = 0; j < intersectedWidgets.count(); j++)
463 { 463 {
464 QArray<int> inter(wCount); 464 QArray<int> inter(wCount);
465 inter[j]=1; 465 inter[j]=1;
466 466
467 if (intersectedWidgets[j] != -1) 467 if (intersectedWidgets[j] != -1)
468 for ( uint k = j; k < intersectedWidgets.count(); k++) { 468 for ( uint k = j; k < intersectedWidgets.count(); k++) {
469 if (j != k && intersectedWidgets[k] != -1) 469 if (j != k && intersectedWidgets[k] != -1)
470 if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) { 470 if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) {
471 inter[j]++; 471 inter[j]++;
472 intersectedWidgets[k] = -1; 472 intersectedWidgets[k] = -1;
473 } 473 }
474 if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; 474 if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1;
475 } 475 }
476 } 476 }
477 if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; 477 if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++;
478 } 478 }
479 479
480 480
481 for ( int i = 0; i < wCount; i++) { 481 for ( int i = 0; i < wCount; i++) {
482 DateBookDayWidget *w = widgetList.at(i); 482 DateBookDayWidget *w = widgetList.at(i);
483 QRect geom = w->geometry(); 483 QRect geom = w->geometry();
484 geom.setX( 0 ); 484 geom.setX( 0 );
485 wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); 485 wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0);
486 geom.setWidth( wd ); 486 geom.setWidth( wd );
487 while ( intersects( w, geom ) ) { 487 while ( intersects( w, geom ) ) {
488 geom.moveBy( wd + 2 + 1, 0 ); 488 geom.moveBy( wd + 2 + 1, 0 );
489 } 489 }
490 w->setGeometry( geom ); 490 w->setGeometry( geom );
491 } 491 }
492 492
493 if (jumpToCurTime && this->date() == QDate::currentDate()) { 493 if (jumpToCurTime && this->date() == QDate::currentDate()) {
494 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour 494 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour
495 } else { 495 } else {
496 view->setContentsPos( 0, startTime * view->rowHeight(0) ); 496 view->setContentsPos( 0, startTime * view->rowHeight(0) );
497 } 497 }
498 } else { 498 } else {
499 int hours[24]; 499 int hours[24];
500 memset( hours, 0, 24*sizeof( int ) ); 500 memset( hours, 0, 24*sizeof( int ) );
501 bool overFlow = FALSE; 501 bool overFlow = FALSE;
502 for ( int i = 0; i < wCount; i++ ) { 502 for ( int i = 0; i < wCount; i++ ) {
503 DateBookDayWidget *w = widgetList.at(i); 503 DateBookDayWidget *w = widgetList.at(i);
504 int start = w->event().start().hour(); 504 int start = w->event().start().hour();
505 QTime e = w->event().end(); 505 QTime e = w->event().end();
506 int end = e.hour(); 506 int end = e.hour();
507 if ( e.minute() < 5 ) 507 if ( e.minute() < 5 )
508 end--; 508 end--;
509 if ( end < start ) 509 if ( end < start )
510 end = start; 510 end = start;
511 while( start <= end ) { 511 while( start <= end ) {
512 hours[start]++; 512 hours[start]++;
513 if ( hours[start] >= 10 ) 513 if ( hours[start] >= 10 )
514 overFlow = TRUE; 514 overFlow = TRUE;
515 ++start; 515 ++start;
516 } 516 }
517 if ( overFlow ) 517 if ( overFlow )
518 break; 518 break;
519 } 519 }
520 for ( int i = 0; i < 24; i++ ) { 520 for ( int i = 0; i < 24; i++ ) {
521 n = QMAX( n, hours[i] ); 521 n = QMAX( n, hours[i] );
522 } 522 }
523 wid = ( view->columnWidth(0)-1 ) / n; 523 wid = ( view->columnWidth(0)-1 ) / n;
524 524
525 bool used[24*10]; 525 bool used[24*10];
526 memset( used, FALSE, 24*10*sizeof( bool ) ); 526 memset( used, FALSE, 24*10*sizeof( bool ) );
527 527
528 for ( int i = 0; i < wCount; i++ ) { 528 for ( int i = 0; i < wCount; i++ ) {
529 DateBookDayWidget *w = widgetList.at(i); 529 DateBookDayWidget *w = widgetList.at(i);
530 int xp = place( w, used, n ); 530 int xp = place( w, used, n );
531 if ( xp != -1 ) { 531 if ( xp != -1 ) {
532 QRect geom = w->geometry(); 532 QRect geom = w->geometry();
533 geom.setX( xp*(wid+2) ); 533 geom.setX( xp*(wid+2) );
534 geom.setWidth( wid ); 534 geom.setWidth( wid );
535 w->setGeometry( geom ); 535 w->setGeometry( geom );
536 } 536 }
537 } 537 }
538 538
539 if (jumpToCurTime && this->date() == QDate::currentDate()) { 539 if (jumpToCurTime && this->date() == QDate::currentDate()) {
540 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour 540 view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour
541 } else { 541 } else {
542 view->setContentsPos( 0, startTime * view->rowHeight(0) ); 542 view->setContentsPos( 0, startTime * view->rowHeight(0) );
543 } 543 }
544 } 544 }
545 545
546 timeMarker->setTime( QTime::currentTime() );//display timeMarker 546 timeMarker->setTime( QTime::currentTime() );//display timeMarker
547 timeMarker->raise(); //on top of all widgets 547 timeMarker->raise(); //on top of all widgets
548 if (this->date() == QDate::currentDate()) { //only show timeMarker on current day 548 if (this->date() == QDate::currentDate()) { //only show timeMarker on current day
549 timeMarker->show(); 549 timeMarker->show();
550 } else { 550 } else {
551 timeMarker->hide(); 551 timeMarker->hide();
552 } 552 }
553 setUpdatesEnabled( TRUE ); 553 setUpdatesEnabled( TRUE );
554 return; 554 return;
555} 555}
556 556
557DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) 557DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom )
558{ 558{
559 int i = 0; 559 int i = 0;
560 DateBookDayWidget *w = widgetList.at(i); 560 DateBookDayWidget *w = widgetList.at(i);
561 int wCount = widgetList.count(); 561 int wCount = widgetList.count();
562 while ( i < wCount && w != item ) { 562 while ( i < wCount && w != item ) {
563 if ( w->geometry().intersects( geom ) ) { 563 if ( w->geometry().intersects( geom ) ) {
564 return w; 564 return w;
565 } 565 }
566 w = widgetList.at(++i); 566 w = widgetList.at(++i);
567 } 567 }
568 568
569 return 0; 569 return 0;
570} 570}
571 571
572 572
573QDate DateBookDay::date() const 573QDate DateBookDay::date() const
574{ 574{
575 return currDate; 575 return currDate;
576} 576}
577 577
578void DateBookDay::setStartViewTime( int startHere ) 578void DateBookDay::setStartViewTime( int startHere )
579{ 579{
580 startTime = startHere; 580 startTime = startHere;
581 dayView()->clearSelection(); 581 dayView()->clearSelection();
582 QTableSelection ts; 582 QTableSelection ts;
583 583
584 if (jumpToCurTime && this->date() == QDate::currentDate()) {//this should probably be in datebook.cpp where it's called? 584 if (jumpToCurTime && this->date() == QDate::currentDate()) {//this should probably be in datebook.cpp where it's called?
585 ts.init( QTime::currentTime().hour(), 0); 585 ts.init( QTime::currentTime().hour(), 0);
586 ts.expandTo( QTime::currentTime().hour(), 0); 586 ts.expandTo( QTime::currentTime().hour(), 0);
587 } else { 587 } else {
588 ts.init( startTime, 0 ); 588 ts.init( startTime, 0 );
589 ts.expandTo( startTime, 0 ); 589 ts.expandTo( startTime, 0 );
590 } 590 }
591 591
592 dayView()->addSelection( ts ); 592 dayView()->addSelection( ts );
593} 593}
594 594
595int DateBookDay::startViewTime() const 595int DateBookDay::startViewTime() const
596{ 596{
597 return startTime; 597 return startTime;
598} 598}
599 599
600void DateBookDay::slotWeekChanged( bool bStartOnMonday ) 600void DateBookDay::slotWeekChanged( bool bStartOnMonday )
601{ 601{
602 header->setStartOfWeek( bStartOnMonday ); 602 header->setStartOfWeek( bStartOnMonday );
603 //redraw(); 603 //redraw();
604} 604}
605 605
606void DateBookDay::keyPressEvent(QKeyEvent *e) 606void DateBookDay::keyPressEvent(QKeyEvent *e)
607{ 607{
608 switch(e->key()) { 608 switch(e->key()) {
609 case Key_Up: 609 case Key_Up:
610 view->moveUp(); 610 view->moveUp();
611 break; 611 break;
612 case Key_Down: 612 case Key_Down:
613 view->moveDown(); 613 view->moveDown();
614 break; 614 break;
615 case Key_Left: 615 case Key_Left:
616 setDate(QDate(currDate).addDays(-1)); 616 setDate(QDate(currDate).addDays(-1));
617 break; 617 break;
618 case Key_Right: 618 case Key_Right:
619 setDate(QDate(currDate).addDays(1)); 619 setDate(QDate(currDate).addDays(1));
620 break; 620 break;
621 default: 621 default:
622 e->ignore(); 622 e->ignore();
623 } 623 }
624} 624}
625 625
626//=========================================================================== 626//===========================================================================
627 627
628DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db ) 628DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db )
629 : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db ) 629 : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db )
630{ 630{
631 // why would someone use "<"? Oh well, fix it up... 631 // why would someone use "<"? Oh well, fix it up...
632 // I wonder what other things may be messed up... 632 // I wonder what other things may be messed up...
633 QString strDesc = ev.description(); 633 QString strDesc = ev.description();
634 int where = strDesc.find( "<" ); 634 int where = strDesc.find( "<" );
635 while ( where != -1 ) { 635 while ( where != -1 ) {
636 strDesc.remove( where, 1 ); 636 strDesc.remove( where, 1 );
637 strDesc.insert( where, "&#60;" ); 637 strDesc.insert( where, "&#60;" );
638 where = strDesc.find( "<", where ); 638 where = strDesc.find( "<", where );
639 } 639 }
640 640
641 QString strCat; 641 QString strCat;
642// ### Fix later... 642// ### Fix later...
643// QString strCat = ev.category(); 643// QString strCat = ev.category();
644// where = strCat.find( "<" ); 644// where = strCat.find( "<" );
645// while ( where != -1 ) { 645// while ( where != -1 ) {
646 // strCat.remove( where, 1 ); 646 // strCat.remove( where, 1 );
647 // strCat.insert( where, "&#60;" ); 647 // strCat.insert( where, "&#60;" );
648 // where = strCat.find( "<", where ); 648 // where = strCat.find( "<", where );
649// } 649// }
650 650
651 QString strNote = ev.notes(); 651 QString strNote = ev.notes();
652 where = strNote.find( "<" ); 652 where = strNote.find( "<" );
653 while ( where != -1 ) { 653 while ( where != -1 ) {
654 strNote.remove( where, 1 ); 654 strNote.remove( where, 1 );
655 strNote.insert( where, "&#60;" ); 655 strNote.insert( where, "&#60;" );
656 where = strNote.find( "<", where ); 656 where = strNote.find( "<", where );
657 } 657 }
658 658
659 text = "<b>" + strDesc + "</b><br>" + "<i>"; 659 text = "<b>" + strDesc + "</b><br>" + "<i>";
660 if ( !strCat.isEmpty() ) { 660 if ( !strCat.isEmpty() ) {
661 text += strCat + "</i><br>"; 661 text += strCat + "</i><br>";
662 } 662 }
663 if (ev.event().type() == Event::Normal ) { 663 if (ev.event().type() == Event::Normal ) {
664 setEventText( text ); 664 setEventText( text );
665 } else { 665 } else {
666 setAllDayText( text ); 666 setAllDayText( text );
667 } 667 }
668 668
669 text += "<br><br>" + strNote; 669 text += "<br><br>" + strNote;
670 670
671 setBackgroundMode( PaletteBase ); 671 setBackgroundMode( PaletteBase );
672 672
673 QTime start = ev.start(); 673 QTime start = ev.start();
674 QTime end = ev.end(); 674 QTime end = ev.end();
675 int y = start.hour()*60+start.minute(); 675 int y = start.hour()*60+start.minute();
676 int h = end.hour()*60+end.minute()-y; 676 int h = end.hour()*60+end.minute()-y;
677 int rh = dateBook->dayView()->rowHeight(0); 677 int rh = dateBook->dayView()->rowHeight(0);
678 y = y*rh/60; 678 y = y*rh/60;
679 h = h*rh/60; 679 h = h*rh/60;
680 680
681 if ( h < 12 ) h = 12;// Make sure the widget is no smaller than 12 pixels high, so that it's possible to read atleast the first line. 681 if ( h < 12 ) h = 12;// Make sure the widget is no smaller than 12 pixels high, so that it's possible to read atleast the first line.
682 if ( y > ((24*rh)-12) ) y=(24*rh)-12;// Make sure the widget fits inside the dayview. 682 if ( y > ((24*rh)-12) ) y=(24*rh)-12;// Make sure the widget fits inside the dayview.
683 geom.setY( y ); 683 geom.setY( y );
684 geom.setHeight( h ); 684 geom.setHeight( h );
685 geom.setX( 0 ); 685 geom.setX( 0 );
686 geom.setWidth(dateBook->dayView()->columnWidth(0)-1); 686 geom.setWidth(dateBook->dayView()->columnWidth(0)-1);
687 687
688} 688}
689 689
690void DateBookDayWidget::setAllDayText( QString &text ) { 690void DateBookDayWidget::setAllDayText( QString &text ) {
691 text += "<b>" + tr("This is an all day event.") + "</b>"; 691 text += "<b>" + tr("This is an all day event.") + "</b>";
692} 692}
693 693
694void DateBookDayWidget::setEventText( QString& text ) { 694void DateBookDayWidget::setEventText( QString& text ) {
695 bool whichClock = dateBook->dayView()->whichClock(); 695 bool whichClock = dateBook->dayView()->whichClock();
696 if ( ev.startDate() != ev.endDate() ) { 696 if ( ev.startDate() != ev.endDate() ) {
697 text += "<b>" + tr("Start") + "</b>: "; 697 text += "<b>" + tr("Start") + "</b>: ";
698 text += TimeString::timeString( ev.event().start().time(), whichClock, FALSE ); 698 text += TimeString::timeString( ev.event().start().time(), whichClock, FALSE );
699 text += " - " + TimeString::longDateString( ev.startDate() ) + "<br>"; 699 text += " - " + TimeString::longDateString( ev.startDate() ) + "<br>";
700 text += "<b>" + tr("End") + "</b>: "; 700 text += "<b>" + tr("End") + "</b>: ";
701 text += TimeString::timeString( ev.event().end().time(), whichClock, FALSE ); 701 text += TimeString::timeString( ev.event().end().time(), whichClock, FALSE );
702 text += " - " + TimeString::longDateString( ev.endDate() ); 702 text += " - " + TimeString::longDateString( ev.endDate() );
703 } else { 703 } else {
704 text += "<b>" + tr("Time") + "</b>: "; 704 text += "<b>" + tr("Time") + "</b>: ";
705 text += TimeString::timeString( ev.start(), whichClock, FALSE ); 705 text += TimeString::timeString( ev.start(), whichClock, FALSE );
706 text += "<b>" + tr(" - ") + "</b>"; 706 text += "<b>" + tr(" - ") + "</b>";
707 text += TimeString::timeString( ev.end(), whichClock, FALSE ); 707 text += TimeString::timeString( ev.end(), whichClock, FALSE );
708 } 708 }
709} 709}
710 710
711DateBookDayWidget::~DateBookDayWidget() 711DateBookDayWidget::~DateBookDayWidget()
712{ 712{
713} 713}
714 714
715void DateBookDayWidget::paintEvent( QPaintEvent *e ) 715void DateBookDayWidget::paintEvent( QPaintEvent *e )
716{ 716{
717 QPainter p( this ); 717 QPainter p( this );
718 718
719 if (dateBook->getSelectedWidget() == this) { 719 if (dateBook->getSelectedWidget() == this) {
720 p.setBrush( QColor( 155, 240, 230 ) ); // selected item 720 p.setBrush( QColor( 155, 240, 230 ) ); // selected item
721 } else { 721 } else {
722 if (dateBook->date() == QDate::currentDate()) { 722 if (dateBook->date() == QDate::currentDate()) {
723 QTime curTime = QTime::currentTime(); 723 QTime curTime = QTime::currentTime();
724 if (ev.end() < curTime) { 724 if (ev.end() < curTime) {
725 p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive 725 p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive
726 } else { 726 } else {
727 //change color in dependence of the time till the event starts 727 //change color in dependence of the time till the event starts
728 int duration = curTime.secsTo(ev.start()); 728 int duration = curTime.secsTo(ev.start());
729 if (duration < 0) duration = 0; 729 if (duration < 0) duration = 0;
730 int colChange = duration*160/86400; //86400: secs per day, 160: max color shift 730 int colChange = duration*160/86400; //86400: secs per day, 160: max color shift
731 p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue 731 p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue
732 } 732 }
733 } else { 733 } else {
734 p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date) 734 p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date)
735 //perhaps make a distinction between future/past dates 735 //perhaps make a distinction between future/past dates
736 } 736 }
737 } 737 }
738 738
739 p.setPen( QColor(100, 100, 100) ); 739 p.setPen( QColor(100, 100, 100) );
740 p.drawRect(rect()); 740 p.drawRect(rect());
741 741
742 // p.drawRect(0,0, 5, height()); 742 // p.drawRect(0,0, 5, height());
743 743
744 int y = 0; 744 int y = 0;
745 int d = 0; 745 int d = 0;
746 746
747 if ( ev.event().hasAlarm() ) { 747 if ( ev.event().hasAlarm() ) {
748 p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); 748 p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) );
749 y = 20; 749 y = 20;
750 d = 20; 750 d = 20;
751 } 751 }
752 752
753 if ( ev.event().hasRepeat() ) { 753 if ( ev.event().hasRepeat() ) {
754 p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); 754 p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) );
755 d = 20; 755 d = 20;
756 y += 20; 756 y += 20;
757 } 757 }
758 758
759 QSimpleRichText rt( text, font() ); 759 QSimpleRichText rt( text, font() );
760 rt.setWidth( geom.width() - d - 6 ); 760 rt.setWidth( geom.width() - d - 6 );
761 rt.draw( &p, 7, 0, e->region(), colorGroup() ); 761 rt.draw( &p, 7, 0, e->region(), colorGroup() );
762} 762}
763 763
764/* 764/*
765 * we need to find the real start date for a uid 765 * we need to find the real start date for a uid
766 * we need to check from one day to another... 766 * we need to check from one day to another...
767 */ 767 */
768QDate DateBookDay::findRealStart( int uid, const QDate& isIncluded , DateBookDB* db) { 768QDate DateBookDay::findRealStart( int uid, const QDate& isIncluded , DateBookDB* db) {
769 QDate dt( isIncluded ); 769 QDate dt( isIncluded );
770 QDate fnd = dt; 770 QDate fnd = dt;
771 771
772 bool doAgain = true; 772 bool doAgain = true;
773 do{ 773 do{
774 dt = dt.addDays( -1 ); 774 dt = dt.addDays( -1 );
775 QValueList<EffectiveEvent> events = db->getEffectiveEvents( dt, dt ); 775 QValueList<EffectiveEvent> events = db->getEffectiveEvents( dt, dt );
776 for (QValueList<EffectiveEvent>::Iterator it = events.begin(); it != events.end(); ++it ) { 776 for (QValueList<EffectiveEvent>::Iterator it = events.begin(); it != events.end(); ++it ) {
777 EffectiveEvent ev = (*it); 777 EffectiveEvent ev = (*it);
778 if ( uid == ev.event().uid() && ev.start() != QTime(0, 0, 0 ) ) 778 if ( uid == ev.event().uid() && ev.start() != QTime(0, 0, 0 ) )
779 return ev.date(); 779 return ev.date();
780 } 780 }
781 }while (doAgain ); 781 }while (doAgain );
782 782
783 return fnd; 783 return fnd;
784} 784}
785 785
786void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) 786void DateBookDayWidget::mousePressEvent( QMouseEvent *e )
787{ 787{
788 DateBookDayWidget *item; 788 DateBookDayWidget *item;
789 789
790 item = dateBook->getSelectedWidget(); 790 item = dateBook->getSelectedWidget();
791 if (item) 791 if (item)
792 item->update(); 792 item->update();
793 793
794 dateBook->setSelectedWidget(this); 794 dateBook->setSelectedWidget(this);
795 update(); 795 update();
796 dateBook->repaint(); 796 dateBook->repaint();
797 797
798 Event eve = ev.event();
799
798 QPopupMenu m; 800 QPopupMenu m;
799 m.insertItem( tr( "Edit" ), 1 ); 801 m.insertItem( tr( "Edit" ), 1 );
800 m.insertItem( tr( "Duplicate" ), 4 ); 802 m.insertItem( tr( "Duplicate" ), 4 );
801 m.insertItem( tr( "Delete" ), 2 ); 803 m.insertItem( tr( "Delete" ), 2 );
802 if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); 804 if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 );
803 if(Ir::supported() && ev.event().doRepeat() ) m.insertItem( tr( "Beam this occurence"), 5 ); 805 if(Ir::supported() && ev.event().doRepeat() ) m.insertItem( tr( "Beam this occurence"), 5 );
804 int r = m.exec( e->globalPos() ); 806 int r = m.exec( e->globalPos() );
805 if ( r == 1 ) { 807 if ( r == 1 ) {
806 emit editMe( ev.event() ); 808 emit editMe( eve );
807 } else if ( r == 2 ) { 809 } else if ( r == 2 ) {
808 emit deleteMe( ev.event() ); 810 emit deleteMe( eve );
809 } else if ( r == 3 ) { 811 } else if ( r == 3 ) {
810 emit beamMe( ev.event() ); 812 emit beamMe( eve );
811 } else if ( r == 4 ) { 813 } else if ( r == 4 ) {
812 emit duplicateMe( ev.event() ); 814 emit duplicateMe( eve );
813 } else if ( r == 5 ) { 815 } else if ( r == 5 ) {
814 // create an Event and beam it... 816 // create an Event and beam it...
815 /* 817 /*
816 * Start with the easy stuff. If start and end date is the same we can just use 818 * Start with the easy stuff. If start and end date is the same we can just use
817 * the values of effective events 819 * the values of effective events
818 * If it is a multi day event we need to find the real start and end date... 820 * If it is a multi day event we need to find the real start and end date...
819 */ 821 */
820 if ( ev.event().start().date() == ev.event().end().date() ) { 822 if ( ev.event().start().date() == ev.event().end().date() ) {
821 Event event( ev.event() ); 823 Event event( ev.event() );
822 824
823 QDateTime dt( ev.date(), ev.start() ); 825 QDateTime dt( ev.date(), ev.start() );
824 event.setStart( dt ); 826 event.setStart( dt );
825 827
826 dt.setTime( ev.end() ); 828 dt.setTime( ev.end() );
827 event.setEnd( dt ); 829 event.setEnd( dt );
828 emit beamMe( event ); 830 emit beamMe( event );
829 }else { 831 }else {
830 /* 832 /*
831 * at least the the Times are right now 833 * at least the the Times are right now
832 */ 834 */
833 QDateTime start( ev.event().start() ); 835 QDateTime start( ev.event().start() );
834 QDateTime end ( ev.event().end () ); 836 QDateTime end ( ev.event().end () );
835 837
836 838
837 /* 839 /*
838 * ok we know the start date or we need to find it 840 * ok we know the start date or we need to find it
839 */ 841 */
840 if ( ev.start() != QTime( 0, 0, 0 ) ) { 842 if ( ev.start() != QTime( 0, 0, 0 ) ) {
841 start.setDate( ev.date() ); 843 start.setDate( ev.date() );
842 }else { 844 }else {
843 QDate dt = DateBookDay::findRealStart( ev.event().uid(), ev.date(), dateBook->db ); 845 QDate dt = DateBookDay::findRealStart( ev.event().uid(), ev.date(), dateBook->db );
844 start.setDate( dt ); 846 start.setDate( dt );
845 } 847 }
846 848
847 849
848 /* 850 /*
849 * ok we know now the end date... 851 * ok we know now the end date...
850 * else 852 * else
851 * get to know the offset btw the real start and real end 853 * get to know the offset btw the real start and real end
852 * and then add it to the new start date... 854 * and then add it to the new start date...
853 */ 855 */
854 if ( ev.end() != QTime(23, 59, 59 ) ) { 856 if ( ev.end() != QTime(23, 59, 59 ) ) {
855 end.setDate( ev.date() ); 857 end.setDate( ev.date() );
856 }else{ 858 }else{
857 int days = ev.event().start().date().daysTo( ev.event().end().date() ); 859 int days = ev.event().start().date().daysTo( ev.event().end().date() );
858 end.setDate( start.date().addDays( days ) ); 860 end.setDate( start.date().addDays( days ) );
859 } 861 }
860 862
861 863
862 864
863 Event event( ev.event() ); 865 Event event( ev.event() );
864 event.setStart( start ); 866 event.setStart( start );
865 event.setEnd ( end ); 867 event.setEnd ( end );
866 868
867 869
868 emit beamMe( event ); 870 emit beamMe( event );
869 } 871 }
870 } 872 }
871} 873}
872 874
873void DateBookDayWidget::setGeometry( const QRect &r ) 875void DateBookDayWidget::setGeometry( const QRect &r )
874{ 876{
875 geom = r; 877 geom = r;
876 setFixedSize( r.width()+1, r.height()+1 ); 878 setFixedSize( r.width()+1, r.height()+1 );
877 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); 879 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 );
878 show(); 880 show();
879} 881}
880 882
881 883
882//--------------------------------------------------------------------------------------------- 884//---------------------------------------------------------------------------------------------
883//--------------------------------------------------------------------------------------------- 885//---------------------------------------------------------------------------------------------
884 886
885 887
886DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) 888DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db )
887 : QWidget( db->dayView()->viewport() ), dateBook( db ) 889 : QWidget( db->dayView()->viewport() ), dateBook( db )
888{ 890{
889 setBackgroundMode( PaletteBase ); 891 setBackgroundMode( PaletteBase );
890} 892}
891 893
892DateBookDayTimeMarker::~DateBookDayTimeMarker() 894DateBookDayTimeMarker::~DateBookDayTimeMarker()
893{ 895{
894} 896}
895 897
896void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ ) 898void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ )
897{ 899{
898 QPainter p( this ); 900 QPainter p( this );
899 p.setBrush( QColor( 255, 0, 0 ) ); 901 p.setBrush( QColor( 255, 0, 0 ) );
900 902
901 QPen pen; 903 QPen pen;
902 pen.setStyle(NoPen); 904 pen.setStyle(NoPen);
903 905
904 p.setPen( pen ); 906 p.setPen( pen );
905 p.drawRect(rect()); 907 p.drawRect(rect());
906} 908}
907 909
908void DateBookDayTimeMarker::setTime( const QTime &t ) 910void DateBookDayTimeMarker::setTime( const QTime &t )
909{ 911{
910 int y = t.hour()*60+t.minute(); 912 int y = t.hour()*60+t.minute();
911 int rh = dateBook->dayView()->rowHeight(0); 913 int rh = dateBook->dayView()->rowHeight(0);
912 y = y*rh/60; 914 y = y*rh/60;
913 915
914 geom.setX( 0 ); 916 geom.setX( 0 );
915 917
916 int x = dateBook->dayView()->columnWidth(0)-1; 918 int x = dateBook->dayView()->columnWidth(0)-1;
917 geom.setWidth( x ); 919 geom.setWidth( x );
918 920
919 geom.setY( y ); 921 geom.setY( y );
920 geom.setHeight( 1 ); 922 geom.setHeight( 1 );
921 923
922 setGeometry( geom ); 924 setGeometry( geom );
923 925
924 time = t; 926 time = t;
925} 927}
926 928
927void DateBookDayTimeMarker::setGeometry( const QRect &r ) 929void DateBookDayTimeMarker::setGeometry( const QRect &r )
928{ 930{
929 geom = r; 931 geom = r;
930 setFixedSize( r.width()+1, r.height()+1 ); 932 setFixedSize( r.width()+1, r.height()+1 );
931 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); 933 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 );
932 show(); 934 show();
933} 935}
diff --git a/core/pim/datebook/datebookday.h b/core/pim/datebook/datebookday.h
index 3898cbc..c8cb26b 100644
--- a/core/pim/datebook/datebookday.h
+++ b/core/pim/datebook/datebookday.h
@@ -1,236 +1,236 @@
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#ifndef DATEBOOKDAY_H 20#ifndef DATEBOOKDAY_H
21#define DATEBOOKDAY_H 21#define DATEBOOKDAY_H
22 22
23#include <qpe/event.h> 23#include <qpe/event.h>
24 24
25#include <qdatetime.h> 25#include <qdatetime.h>
26#include <qtable.h> 26#include <qtable.h>
27#include <qvbox.h> 27#include <qvbox.h>
28#include <qlist.h> 28#include <qlist.h>
29 29
30#include "datebook.h" 30#include "datebook.h"
31#include <qlineedit.h> 31#include <qlineedit.h>
32 32
33class DateBookDayHeader; 33class DateBookDayHeader;
34class DateBookDB; 34class DateBookDB;
35class DatebookdayAllday; 35class DatebookdayAllday;
36class QDateTime; 36class QDateTime;
37class QMouseEvent; 37class QMouseEvent;
38class QPaintEvent; 38class QPaintEvent;
39class QResizeEvent; 39class QResizeEvent;
40 40
41class DateBookDayViewQuickLineEdit : public QLineEdit 41class DateBookDayViewQuickLineEdit : public QLineEdit
42{ 42{
43 Q_OBJECT 43 Q_OBJECT
44public: 44public:
45 DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name=0); 45 DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name=0);
46protected: 46protected:
47 Event quickEvent; 47 Event quickEvent;
48 int active; 48 int active;
49 void focusOutEvent( QFocusEvent *e ); 49 void focusOutEvent( QFocusEvent *e );
50protected slots: 50protected slots:
51 void slotReturnPressed(void); 51 void slotReturnPressed(void);
52 void finallyCallClose(); 52 void finallyCallClose();
53signals: 53signals:
54 void insertEvent(const Event &e); 54 void insertEvent(const Event &e);
55}; 55};
56 56
57 57
58class DateBookDayView : public QTable 58class DateBookDayView : public QTable
59{ 59{
60 Q_OBJECT 60 Q_OBJECT
61public: 61public:
62 DateBookDayView( bool hourClock, QWidget *parent, const char *name ); 62 DateBookDayView( bool hourClock, QWidget *parent, const char *name );
63 bool whichClock() const; 63 bool whichClock() const;
64 64
65 void setRowStyle( int style ); 65 void setRowStyle( int style );
66 66
67public slots: 67public slots:
68 void moveUp(); 68 void moveUp();
69 void moveDown(); 69 void moveDown();
70 void slotDateChanged( int year, int month, int day ); 70 void slotDateChanged( int year, int month, int day );
71 71
72signals: 72signals:
73 void sigColWidthChanged(); 73 void sigColWidthChanged();
74 void sigCapturedKey( const QString &txt ); 74 void sigCapturedKey( const QString &txt );
75protected slots: 75protected slots:
76 void slotChangeClock( bool ); 76 void slotChangeClock( bool );
77protected: 77protected:
78 virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected ); 78 virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected );
79 virtual void paintFocus( QPainter *p, const QRect &cr ); 79 virtual void paintFocus( QPainter *p, const QRect &cr );
80 80
81 virtual void resizeEvent( QResizeEvent *e ); 81 virtual void resizeEvent( QResizeEvent *e );
82 void keyPressEvent( QKeyEvent *e ); 82 void keyPressEvent( QKeyEvent *e );
83 void contentsMouseReleaseEvent( QMouseEvent *e ); 83 void contentsMouseReleaseEvent( QMouseEvent *e );
84 void initHeader(); 84 void initHeader();
85private: 85private:
86 bool ampm; 86 bool ampm;
87 QDate currDate; 87 QDate currDate;
88 DateBookDayViewQuickLineEdit *quickLineEdit; 88 DateBookDayViewQuickLineEdit *quickLineEdit;
89}; 89};
90 90
91class DateBookDay; 91class DateBookDay;
92class DateBookDayWidget : public QWidget 92class DateBookDayWidget : public QWidget
93{ 93{
94 Q_OBJECT 94 Q_OBJECT
95 95
96public: 96public:
97 DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db ); 97 DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db );
98 ~DateBookDayWidget(); 98 ~DateBookDayWidget();
99 99
100 const QRect &geometry() { return geom; } 100 const QRect &geometry() { return geom; }
101 void setGeometry( const QRect &r ); 101 void setGeometry( const QRect &r );
102 102
103 const EffectiveEvent &event() const { return ev; } 103 const EffectiveEvent &event() const { return ev; }
104 104
105signals: 105signals:
106 void deleteMe( const Event &e ); 106 void deleteMe( const Event &e );
107 void duplicateMe( const Event &e ); 107 void duplicateMe( const Event &e );
108 void editMe( const Event &e ); 108 void editMe( const Event &e );
109 void beamMe( const Event &e ); 109 void beamMe( const Event &e );
110 110
111protected: 111protected:
112 void paintEvent( QPaintEvent *e ); 112 void paintEvent( QPaintEvent *e );
113 void mousePressEvent( QMouseEvent *e ); 113 void mousePressEvent( QMouseEvent *e );
114 114
115private: 115private:
116 /** 116 /**
117 * Sets the text for an all day Event 117 * Sets the text for an all day Event
118 * All day events have no time associated 118 * All day events have no time associated
119 */ 119 */
120 void setAllDayText( QString& text ); 120 void setAllDayText( QString& text );
121 121
122 /** 122 /**
123 * Sets the EventText 123 * Sets the EventText
124 * it got a start and an end Time 124 * it got a start and an end Time
125 */ 125 */
126 void setEventText( QString& text ); 126 void setEventText( QString& text );
127 const EffectiveEvent ev; 127 EffectiveEvent ev;
128 DateBookDay *dateBook; 128 DateBookDay *dateBook;
129 QString text; 129 QString text;
130 QRect geom; 130 QRect geom;
131}; 131};
132 132
133//Marker for current time in the dayview 133//Marker for current time in the dayview
134class DateBookDayTimeMarker : public QWidget 134class DateBookDayTimeMarker : public QWidget
135{ 135{
136 Q_OBJECT 136 Q_OBJECT
137 137
138public: 138public:
139 DateBookDayTimeMarker( DateBookDay *db ); 139 DateBookDayTimeMarker( DateBookDay *db );
140 ~DateBookDayTimeMarker(); 140 ~DateBookDayTimeMarker();
141 141
142 const QRect &geometry() { return geom; } 142 const QRect &geometry() { return geom; }
143 void setGeometry( const QRect &r ); 143 void setGeometry( const QRect &r );
144 void setTime( const QTime &t ); 144 void setTime( const QTime &t );
145 145
146signals: 146signals:
147 147
148protected: 148protected:
149 void paintEvent( QPaintEvent *e ); 149 void paintEvent( QPaintEvent *e );
150 150
151private: 151private:
152 QRect geom; 152 QRect geom;
153 QTime time; 153 QTime time;
154 DateBookDay *dateBook; 154 DateBookDay *dateBook;
155}; 155};
156 156
157//reimplemented the compareItems function so that it sorts DayWidgets by geometry heights 157//reimplemented the compareItems function so that it sorts DayWidgets by geometry heights
158class WidgetListClass : public QList<DateBookDayWidget> 158class WidgetListClass : public QList<DateBookDayWidget>
159{ 159{
160 private: 160 private:
161 161
162 int compareItems( QCollection::Item s1, QCollection::Item s2 ) 162 int compareItems( QCollection::Item s1, QCollection::Item s2 )
163 { 163 {
164 //hmm, don't punish me for that ;) 164 //hmm, don't punish me for that ;)
165 if (reinterpret_cast<DateBookDayWidget*>(s1)->geometry().height() > reinterpret_cast<DateBookDayWidget*>(s2)->geometry().height()) 165 if (reinterpret_cast<DateBookDayWidget*>(s1)->geometry().height() > reinterpret_cast<DateBookDayWidget*>(s2)->geometry().height())
166 { 166 {
167 return -1; 167 return -1;
168 } else 168 } else
169 { 169 {
170 return 1; 170 return 1;
171 } 171 }
172 } 172 }
173 173
174 174
175}; 175};
176 176
177class DateBookDay : public QVBox 177class DateBookDay : public QVBox
178{ 178{
179 Q_OBJECT 179 Q_OBJECT
180 180
181 friend class DateBookDayWidget; // for beam this occurence and access to DateBookDB 181 friend class DateBookDayWidget; // for beam this occurence and access to DateBookDB
182public: 182public:
183 DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, 183 DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb,
184 QWidget *parent, const char *name ); 184 QWidget *parent, const char *name );
185 void selectedDates( QDateTime &start, QDateTime &end ); 185 void selectedDates( QDateTime &start, QDateTime &end );
186 QDate date() const; 186 QDate date() const;
187 DateBookDayView *dayView() const { return view; } 187 DateBookDayView *dayView() const { return view; }
188 void setStartViewTime( int startHere ); 188 void setStartViewTime( int startHere );
189 int startViewTime() const; 189 int startViewTime() const;
190 void setSelectedWidget( DateBookDayWidget * ); 190 void setSelectedWidget( DateBookDayWidget * );
191 DateBookDayWidget * getSelectedWidget( void ); 191 DateBookDayWidget * getSelectedWidget( void );
192 void setJumpToCurTime( bool bJump ); 192 void setJumpToCurTime( bool bJump );
193 void setRowStyle( int style ); 193 void setRowStyle( int style );
194 static QDate findRealStart( int uid, const QDate& isIncluded, 194 static QDate findRealStart( int uid, const QDate& isIncluded,
195 DateBookDB* ); 195 DateBookDB* );
196 196
197public slots: 197public slots:
198 void setDate( int y, int m, int d ); 198 void setDate( int y, int m, int d );
199 void setDate( QDate ); 199 void setDate( QDate );
200 void redraw(); 200 void redraw();
201 void slotWeekChanged( bool bStartOnMonday ); 201 void slotWeekChanged( bool bStartOnMonday );
202 void updateView();//updates TimeMarker and DayWidget-colors 202 void updateView();//updates TimeMarker and DayWidget-colors
203 203
204signals: 204signals:
205 void removeEvent( const Event& ); 205 void removeEvent( const Event& );
206 void editEvent( const Event& ); 206 void editEvent( const Event& );
207 void duplicateEvent( const Event& ); 207 void duplicateEvent( const Event& );
208 void beamEvent( const Event& ); 208 void beamEvent( const Event& );
209 void newEvent(); 209 void newEvent();
210 void sigNewEvent( const QString & ); 210 void sigNewEvent( const QString & );
211 211
212protected slots: 212protected slots:
213 void keyPressEvent(QKeyEvent *); 213 void keyPressEvent(QKeyEvent *);
214 214
215private slots: 215private slots:
216 void dateChanged( int y, int m, int d ); 216 void dateChanged( int y, int m, int d );
217 void slotColWidthChanged() { relayoutPage(); }; 217 void slotColWidthChanged() { relayoutPage(); };
218 218
219private: 219private:
220 void getEvents(); 220 void getEvents();
221 void relayoutPage( bool fromResize = false ); 221 void relayoutPage( bool fromResize = false );
222 DateBookDayWidget *intersects( const DateBookDayWidget *item, const QRect &geom ); 222 DateBookDayWidget *intersects( const DateBookDayWidget *item, const QRect &geom );
223 QDate currDate; 223 QDate currDate;
224 DateBookDayView *view; 224 DateBookDayView *view;
225 DateBookDayHeader *header; 225 DateBookDayHeader *header;
226 DatebookdayAllday *m_allDays; 226 DatebookdayAllday *m_allDays;
227 DateBookDB *db; 227 DateBookDB *db;
228 WidgetListClass widgetList;//reimplemented QList for sorting widgets by height 228 WidgetListClass widgetList;//reimplemented QList for sorting widgets by height
229 int startTime; 229 int startTime;
230 bool jumpToCurTime;//should we jump to current time in dayview? 230 bool jumpToCurTime;//should we jump to current time in dayview?
231 int rowStyle; 231 int rowStyle;
232 DateBookDayWidget *selectedWidget; //actual selected widget (obviously) 232 DateBookDayWidget *selectedWidget; //actual selected widget (obviously)
233 DateBookDayTimeMarker *timeMarker;//marker for current time 233 DateBookDayTimeMarker *timeMarker;//marker for current time
234}; 234};
235 235
236#endif 236#endif
diff --git a/core/pim/datebook/datebookdayallday.cpp b/core/pim/datebook/datebookdayallday.cpp
index 2294f3c..1244fd3 100644
--- a/core/pim/datebook/datebookdayallday.cpp
+++ b/core/pim/datebook/datebookdayallday.cpp
@@ -1,235 +1,236 @@
1/**************************************************************************** 1/****************************************************************************
2** GPL by Rajko Albrecht 2** GPL by Rajko Albrecht
3** 3**
4** 4**
5** 5**
6** 6**
7** 7**
8****************************************************************************/ 8****************************************************************************/
9#include "datebookdayallday.h" 9#include "datebookdayallday.h"
10 10
11#include <qpushbutton.h> 11#include <qpushbutton.h>
12#include <qlayout.h> 12#include <qlayout.h>
13#include <qvariant.h> 13#include <qvariant.h>
14#include <qtooltip.h> 14#include <qtooltip.h>
15#include <qwhatsthis.h> 15#include <qwhatsthis.h>
16#include <qobjectlist.h> 16#include <qobjectlist.h>
17#include <qpe/event.h> 17#include <qpe/event.h>
18#include <qpe/ir.h> 18#include <qpe/ir.h>
19#include <qpe/datebookdb.h> 19#include <qpe/datebookdb.h>
20#include <qpe/resource.h> 20#include <qpe/resource.h>
21#include <qpopupmenu.h> 21#include <qpopupmenu.h>
22#include <qtimer.h> 22#include <qtimer.h>
23#include <qregexp.h> 23#include <qregexp.h>
24#include <qdatetime.h> 24#include <qdatetime.h>
25 25
26#include "datebookday.h" 26#include "datebookday.h"
27 27
28/* 28/*
29 * Constructs a DatebookdayAllday which is a child of 'parent', with the 29 * Constructs a DatebookdayAllday which is a child of 'parent', with the
30 * name 'name' and widget flags set to 'f' 30 * name 'name' and widget flags set to 'f'
31 */ 31 */
32DatebookdayAllday::DatebookdayAllday(DateBookDB* db, QWidget* parent, const char* name, WFlags ) 32DatebookdayAllday::DatebookdayAllday(DateBookDB* db, QWidget* parent, const char* name, WFlags )
33 : QScrollView( parent, name ),item_count(0),dateBook(db) 33 : QScrollView( parent, name ),item_count(0),dateBook(db)
34{ 34{
35 if ( !name ) 35 if ( !name )
36 setName( "DatebookdayAllday" ); 36 setName( "DatebookdayAllday" );
37 setMinimumSize( QSize( 0, 0 ) ); 37 setMinimumSize( QSize( 0, 0 ) );
38 setMaximumHeight(3* (QFontMetrics(font()).height()+4) ); 38 setMaximumHeight(3* (QFontMetrics(font()).height()+4) );
39 39
40 m_MainFrame = new QFrame(viewport()); 40 m_MainFrame = new QFrame(viewport());
41 m_MainFrame->setFrameStyle(QFrame::NoFrame|QFrame::Plain); 41 m_MainFrame->setFrameStyle(QFrame::NoFrame|QFrame::Plain);
42 setFrameStyle(QFrame::NoFrame|QFrame::Plain); 42 setFrameStyle(QFrame::NoFrame|QFrame::Plain);
43 setResizePolicy( QScrollView::Default ); 43 setResizePolicy( QScrollView::Default );
44 setHScrollBarMode( AlwaysOff ); 44 setHScrollBarMode( AlwaysOff );
45 addChild(m_MainFrame); 45 addChild(m_MainFrame);
46 46
47 datebookdayalldayLayout = new QVBoxLayout( m_MainFrame ); 47 datebookdayalldayLayout = new QVBoxLayout( m_MainFrame );
48 datebookdayalldayLayout->setSpacing( 0 ); 48 datebookdayalldayLayout->setSpacing( 0 );
49 datebookdayalldayLayout->setMargin( 0 ); 49 datebookdayalldayLayout->setMargin( 0 );
50 50
51 lblDesc = new DatebookEventDesc(parent->parentWidget(),""); 51 lblDesc = new DatebookEventDesc(parent->parentWidget(),"");
52 lblDesc->setBackgroundColor(Qt::yellow); 52 lblDesc->setBackgroundColor(Qt::yellow);
53 lblDesc->hide(); 53 lblDesc->hide();
54 subWidgets.setAutoDelete(true); 54 subWidgets.setAutoDelete(true);
55} 55}
56 56
57/* 57/*
58 * Destroys the object and frees any allocated resources 58 * Destroys the object and frees any allocated resources
59 */ 59 */
60DatebookdayAllday::~DatebookdayAllday() 60DatebookdayAllday::~DatebookdayAllday()
61{ 61{
62 // no need to delete child widgets, Qt does it all for us 62 // no need to delete child widgets, Qt does it all for us
63} 63}
64 64
65DatebookAlldayDisp* DatebookdayAllday::addEvent(const EffectiveEvent&ev) 65DatebookAlldayDisp* DatebookdayAllday::addEvent(const EffectiveEvent&ev)
66{ 66{
67 DatebookAlldayDisp * lb; 67 DatebookAlldayDisp * lb;
68 lb = new DatebookAlldayDisp(dateBook,ev,m_MainFrame,NULL); 68 lb = new DatebookAlldayDisp(dateBook,ev,m_MainFrame,NULL);
69 lb->show(); 69 lb->show();
70 datebookdayalldayLayout->addWidget(lb); 70 datebookdayalldayLayout->addWidget(lb);
71 subWidgets.append(lb); 71 subWidgets.append(lb);
72 72
73 connect(lb,SIGNAL(displayMe(const Event &)),lblDesc,SLOT(disp_event(const Event&))); 73 connect(lb,SIGNAL(displayMe(const Event &)),lblDesc,SLOT(disp_event(const Event&)));
74 ++item_count; 74 ++item_count;
75 75
76 return lb; 76 return lb;
77} 77}
78 78
79void DatebookdayAllday::removeAllEvents() 79void DatebookdayAllday::removeAllEvents()
80{ 80{
81 subWidgets.clear(); 81 subWidgets.clear();
82 item_count = 0; 82 item_count = 0;
83} 83}
84 84
85DatebookAlldayDisp::DatebookAlldayDisp(DateBookDB *db,const EffectiveEvent& ev, 85DatebookAlldayDisp::DatebookAlldayDisp(DateBookDB *db,const EffectiveEvent& ev,
86 QWidget* parent,const char* name,WFlags f) 86 QWidget* parent,const char* name,WFlags f)
87 : QLabel(parent,name,f),m_Ev(ev),dateBook(db) 87 : QLabel(parent,name,f),m_Ev(ev),dateBook(db)
88{ 88{
89 QString strDesc = m_Ev.description(); 89 QString strDesc = m_Ev.description();
90 strDesc = strDesc.replace(QRegExp("<"),"&#60;"); 90 strDesc = strDesc.replace(QRegExp("<"),"&#60;");
91 setBackgroundColor(yellow); 91 setBackgroundColor(yellow);
92 setText(strDesc); 92 setText(strDesc);
93 setFrameStyle(QFrame::Raised|QFrame::Panel); 93 setFrameStyle(QFrame::Raised|QFrame::Panel);
94 94
95 int s = QFontMetrics(font()).height()+4; 95 int s = QFontMetrics(font()).height()+4;
96 setMaximumHeight( s ); 96 setMaximumHeight( s );
97 setMinimumSize( QSize( 0, s ) ); 97 setMinimumSize( QSize( 0, s ) );
98} 98}
99 99
100DatebookAlldayDisp::~DatebookAlldayDisp() 100DatebookAlldayDisp::~DatebookAlldayDisp()
101{ 101{
102} 102}
103 103
104void DatebookAlldayDisp::beam_single_event() 104void DatebookAlldayDisp::beam_single_event()
105{ 105{
106 // create an Event and beam it... 106 // create an Event and beam it...
107 /* 107 /*
108 * Start with the easy stuff. If start and end date is the same we can just use 108 * Start with the easy stuff. If start and end date is the same we can just use
109 * the values of effective m_Events 109 * the values of effective m_Events
110 * If it is a multi day m_Event we need to find the real start and end date... 110 * If it is a multi day m_Event we need to find the real start and end date...
111 */ 111 */
112 if ( m_Ev.event().start().date() == m_Ev.event().end().date() ) { 112 if ( m_Ev.event().start().date() == m_Ev.event().end().date() ) {
113 Event m_Event( m_Ev.event() ); 113 Event m_Event( m_Ev.event() );
114 114
115 QDateTime dt( m_Ev.date(), m_Ev.start() ); 115 QDateTime dt( m_Ev.date(), m_Ev.start() );
116 m_Event.setStart( dt ); 116 m_Event.setStart( dt );
117 117
118 dt.setTime( m_Ev.end() ); 118 dt.setTime( m_Ev.end() );
119 m_Event.setEnd( dt ); 119 m_Event.setEnd( dt );
120 emit beamMe( m_Event ); 120 emit beamMe( m_Event );
121 }else { 121 }else {
122 /* 122 /*
123 * at least the the Times are right now 123 * at least the the Times are right now
124 */ 124 */
125 QDateTime start( m_Ev.event().start() ); 125 QDateTime start( m_Ev.event().start() );
126 QDateTime end ( m_Ev.event().end () ); 126 QDateTime end ( m_Ev.event().end () );
127 127
128 /* 128 /*
129 * ok we know the start date or we need to find it 129 * ok we know the start date or we need to find it
130 */ 130 */
131 if ( m_Ev.start() != QTime( 0, 0, 0 ) ) { 131 if ( m_Ev.start() != QTime( 0, 0, 0 ) ) {
132 start.setDate( m_Ev.date() ); 132 start.setDate( m_Ev.date() );
133 }else { 133 }else {
134 QDate dt = DateBookDay::findRealStart( m_Ev.event().uid(), m_Ev.date(), dateBook ); 134 QDate dt = DateBookDay::findRealStart( m_Ev.event().uid(), m_Ev.date(), dateBook );
135 start.setDate( dt ); 135 start.setDate( dt );
136 } 136 }
137 137
138 /* 138 /*
139 * ok we know now the end date... 139 * ok we know now the end date...
140 * else 140 * else
141 * get to know the offset btw the real start and real end 141 * get to know the offset btw the real start and real end
142 * and then add it to the new start date... 142 * and then add it to the new start date...
143 */ 143 */
144 if ( m_Ev.end() != QTime(23, 59, 59 ) ) { 144 if ( m_Ev.end() != QTime(23, 59, 59 ) ) {
145 end.setDate( m_Ev.date() ); 145 end.setDate( m_Ev.date() );
146 }else{ 146 }else{
147 int days = m_Ev.event().start().date().daysTo( m_Ev.event().end().date() ); 147 int days = m_Ev.event().start().date().daysTo( m_Ev.event().end().date() );
148 end.setDate( start.date().addDays( days ) ); 148 end.setDate( start.date().addDays( days ) );
149 } 149 }
150 Event m_Event( m_Ev.event() ); 150 Event m_Event( m_Ev.event() );
151 m_Event.setStart( start ); 151 m_Event.setStart( start );
152 m_Event.setEnd ( end ); 152 m_Event.setEnd ( end );
153 emit beamMe( m_Event ); 153 emit beamMe( m_Event );
154 } 154 }
155} 155}
156 156
157void DatebookAlldayDisp::mousePressEvent(QMouseEvent*e) 157void DatebookAlldayDisp::mousePressEvent(QMouseEvent*e)
158{ 158{
159 Event ev = m_Ev.event();
159 QColor b = backgroundColor(); 160 QColor b = backgroundColor();
160 setBackgroundColor(green); 161 setBackgroundColor(green);
161 update(); 162 update();
162 QPopupMenu m; 163 QPopupMenu m;
163 m.insertItem( DateBookDayWidget::tr( "Edit" ), 1 ); 164 m.insertItem( DateBookDayWidget::tr( "Edit" ), 1 );
164 m.insertItem( DateBookDayWidget::tr( "Duplicate" ), 4 ); 165 m.insertItem( DateBookDayWidget::tr( "Duplicate" ), 4 );
165 m.insertItem( DateBookDayWidget::tr( "Delete" ), 2 ); 166 m.insertItem( DateBookDayWidget::tr( "Delete" ), 2 );
166 if(Ir::supported()) m.insertItem( DateBookDayWidget::tr( "Beam" ), 3 ); 167 if(Ir::supported()) m.insertItem( DateBookDayWidget::tr( "Beam" ), 3 );
167 if(Ir::supported() && m_Ev.event().doRepeat() ) m.insertItem( DateBookDayWidget::tr( "Beam this occurence"), 5 ); 168 if(Ir::supported() && m_Ev.event().doRepeat() ) m.insertItem( DateBookDayWidget::tr( "Beam this occurence"), 5 );
168 m.insertItem( tr( "Info"),6); 169 m.insertItem( tr( "Info"),6);
169 int r = m.exec( e->globalPos() ); 170 int r = m.exec( e->globalPos() );
170 setBackgroundColor(b); 171 setBackgroundColor(b);
171 update(); 172 update();
172 switch (r) { 173 switch (r) {
173 case 1: 174 case 1:
174 emit editMe( m_Ev.event() ); 175 emit editMe( ev );
175 break; 176 break;
176 case 2: 177 case 2:
177 emit deleteMe( m_Ev.event() ); 178 emit deleteMe( ev );
178 break; 179 break;
179 case 3: 180 case 3:
180 emit beamMe( m_Ev.event() ); 181 emit beamMe( ev );
181 break; 182 break;
182 case 4: 183 case 4:
183 emit duplicateMe( m_Ev.event() ); 184 emit duplicateMe( ev );
184 break; 185 break;
185 case 5: 186 case 5:
186 beam_single_event(); 187 beam_single_event();
187 break; 188 break;
188 case 6: 189 case 6:
189 emit displayMe( m_Ev.event() ); 190 emit displayMe( ev );
190 break; 191 break;
191 default: 192 default:
192 break; 193 break;
193 } 194 }
194} 195}
195 196
196DatebookEventDesc::DatebookEventDesc(QWidget*parent,const char*name) 197DatebookEventDesc::DatebookEventDesc(QWidget*parent,const char*name)
197 :QLabel(parent,name) 198 :QLabel(parent,name)
198{ 199{
199 m_Timer=new QTimer(this); 200 m_Timer=new QTimer(this);
200 connect(m_Timer,SIGNAL(timeout()),this,SLOT(hide())); 201 connect(m_Timer,SIGNAL(timeout()),this,SLOT(hide()));
201 setFrameStyle(QFrame::Sunken|QFrame::Panel); 202 setFrameStyle(QFrame::Sunken|QFrame::Panel);
202 setTextFormat(RichText); 203 setTextFormat(RichText);
203} 204}
204 205
205DatebookEventDesc::~DatebookEventDesc() 206DatebookEventDesc::~DatebookEventDesc()
206{ 207{
207} 208}
208 209
209void DatebookEventDesc::mousePressEvent(QMouseEvent*) 210void DatebookEventDesc::mousePressEvent(QMouseEvent*)
210{ 211{
211 hide(); 212 hide();
212 if (m_Timer->isActive()) m_Timer->stop(); 213 if (m_Timer->isActive()) m_Timer->stop();
213} 214}
214 215
215void DatebookEventDesc::disp_event(const Event&e) 216void DatebookEventDesc::disp_event(const Event&e)
216{ 217{
217 if (m_Timer->isActive()) m_Timer->stop(); 218 if (m_Timer->isActive()) m_Timer->stop();
218 QString text; 219 QString text;
219 text = "<b><i>"+e.description()+"</i></b><br>"; 220 text = "<b><i>"+e.description()+"</i></b><br>";
220 if (e.notes().length()>0) { 221 if (e.notes().length()>0) {
221 text+="<b>"+e.notes()+"</b><br>"; 222 text+="<b>"+e.notes()+"</b><br>";
222 } 223 }
223 if (e.location().length()>0) { 224 if (e.location().length()>0) {
224 text+="<i>"+e.location()+"</i><br>"; 225 text+="<i>"+e.location()+"</i><br>";
225 } 226 }
226 text = text.replace(QRegExp("\n"),"<br>"); 227 text = text.replace(QRegExp("\n"),"<br>");
227 setText(text); 228 setText(text);
228 QSize s = sizeHint(); 229 QSize s = sizeHint();
229 s+=QSize(10,10); 230 s+=QSize(10,10);
230 resize(s); 231 resize(s);
231 move( QMAX(0,(parentWidget()->width()-width()) / 2), 232 move( QMAX(0,(parentWidget()->width()-width()) / 2),
232 (parentWidget()->height()-height())/2 ); 233 (parentWidget()->height()-height())/2 );
233 show(); 234 show();
234 m_Timer->start(2000,true); 235 m_Timer->start(2000,true);
235} 236}
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp
index 8435132..933e191 100644
--- a/core/pim/datebook/datebookweek.cpp
+++ b/core/pim/datebook/datebookweek.cpp
@@ -1,679 +1,675 @@
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)
86
87 // Ok, I am Mr. Pedantic, but shouldn't we count until 6 instead of 7, if bOnMonday is false ? (eilers)
88 85
89 static bool bFirst = true; 86 static bool bFirst = true;
90 if ( bFirst ) { 87 if ( bFirst ) {
91 if ( bOnMonday ) { 88 if ( bOnMonday ) {
92 for ( int i = 1; i<=7; i++ ) { 89 for ( int i = 1; i<=7; i++ ) {
93 header->addLabel( Calendar::nameOfDay( i ) ); 90 header->addLabel( Calendar::nameOfDay( i ) );
94 } 91 }
95 92
96 } else { 93 } else {
97 header->addLabel( Calendar::nameOfDay( 7 ) ); 94 header->addLabel( Calendar::nameOfDay( 7 ) );
98 for ( int i = 1; i<7; i++ ) { 95 for ( int i = 1; i<7; i++ ) {
99 header->addLabel( Calendar::nameOfDay( i ) ); 96 header->addLabel( Calendar::nameOfDay( i ) );
100 } 97 }
101 } 98 }
102 bFirst = false; 99 bFirst = false;
103 } else { 100 } else {
104 // we are change things... 101 // we are change things...
105 if ( bOnMonday ) { 102 if ( bOnMonday ) {
106 for ( int i = 1; i<=7; i++ ) { 103 for ( int i = 1; i<=7; i++ ) {
107 header->setLabel( i, Calendar::nameOfDay( i ) ); 104 header->setLabel( i, Calendar::nameOfDay( i ) );
108 } 105 }
109 106
110 } else { 107 } else {
111 header->setLabel( 1, Calendar::nameOfDay( 7 ) ); 108 header->setLabel( 1, Calendar::nameOfDay( 7 ) );
112 for ( int i = 1; i<7; i++ ) { 109 for ( int i = 1; i<7; i++ ) {
113 header->setLabel( i+1, Calendar::nameOfDay( i ) ); 110 header->setLabel( i+1, Calendar::nameOfDay( i ) );
114 } 111 }
115 112
116 } 113 }
117 } 114 }
118} 115}
119 116
120 117
121 118
122void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) 119void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev )
123{ 120{
124 items.clear(); 121 items.clear();
125 QValueListIterator<EffectiveEvent> it; 122 QValueListIterator<EffectiveEvent> it;
126 for ( it = ev.begin(); it != ev.end(); ++it ) { 123 for ( it = ev.begin(); it != ev.end(); ++it ) {
127 DateBookWeekItem *i = new DateBookWeekItem( *it ); 124 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. 125 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 ); 126 positionItem( i );
130 items.append( i ); 127 items.append( i );
131 } 128 }
132 } 129 }
133 viewport()->update(); 130 viewport()->update();
134} 131}
135 132
136void DateBookWeekView::moveToHour( int h ) 133void DateBookWeekView::moveToHour( int h )
137{ 134{
138 int offset = h*rowHeight; 135 int offset = h*rowHeight;
139 setContentsPos( 0, offset ); 136 setContentsPos( 0, offset );
140} 137}
141 138
142void DateBookWeekView::keyPressEvent( QKeyEvent *e ) 139void DateBookWeekView::keyPressEvent( QKeyEvent *e )
143{ 140{
144 e->ignore(); 141 e->ignore();
145} 142}
146 143
147void DateBookWeekView::slotChangeClock( bool c ) 144void DateBookWeekView::slotChangeClock( bool c )
148{ 145{
149 ampm = c; 146 ampm = c;
150 viewport()->update(); 147 viewport()->update();
151} 148}
152 149
153static inline int db_round30min( int m ) 150static inline int db_round30min( int m )
154{ 151{
155 if ( m < 15 ) 152 if ( m < 15 )
156 m = 0; 153 m = 0;
157 else if ( m < 45 ) 154 else if ( m < 45 )
158 m = 1; 155 m = 1;
159 else 156 else
160 m = 2; 157 m = 2;
161 158
162 return m; 159 return m;
163} 160}
164 161
165void DateBookWeekView::alterDay( int day ) 162void DateBookWeekView::alterDay( int day )
166{ 163{
167 if ( !bOnMonday ) { 164 if ( !bOnMonday ) {
168 day--; 165 day--;
169 } 166 }
170 emit showDay( day ); 167 emit showDay( day );
171} 168}
172 169
173void DateBookWeekView::positionItem( DateBookWeekItem *i ) 170void DateBookWeekView::positionItem( DateBookWeekItem *i )
174{ 171{
175 const int Width = 8; 172 const int Width = 8;
176 const EffectiveEvent ev = i->event(); 173 const EffectiveEvent ev = i->event();
177 174
178 // 30 minute intervals 175 // 30 minute intervals
179 int y = ev.start().hour() * 2; 176 int y = ev.start().hour() * 2;
180 y += db_round30min( ev.start().minute() ); 177 y += db_round30min( ev.start().minute() );
181 int y2 = ev.end().hour() * 2; 178 int y2 = ev.end().hour() * 2;
182 y2 += db_round30min( ev.end().minute() ); 179 y2 += db_round30min( ev.end().minute() );
183 if ( y > 47 ) y = 47; 180 if ( y > 47 ) y = 47;
184 if ( y2 > 48 ) y2 = 48; 181 if ( y2 > 48 ) y2 = 48;
185 y = (y * rowHeight) / 2; 182 y = (y * rowHeight) / 2;
186 y2 = (y2 * rowHeight) / 2; 183 y2 = (y2 * rowHeight) / 2;
187 184
188 int h; 185 int h;
189 if ( ev.event().type() == Event::AllDay ) { 186 if ( ev.event().type() == Event::AllDay ) {
190 h = (48 * rowHeight) / 2; 187 h = (48 * rowHeight) / 2;
191 y = 0; 188 y = 0;
192 } else { 189 } else {
193 h=y2-y; 190 h=y2-y;
194 if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2; 191 if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2;
195 } 192 }
196 193
197 int dow = ev.date().dayOfWeek(); 194 int dow = ev.date().dayOfWeek();
198 if ( !bOnMonday ) { 195 if ( !bOnMonday ) {
199 if ( dow == 7 ) 196 if ( dow == 7 )
200 dow = 1; 197 dow = 1;
201 else 198 else
202 dow++; 199 dow++;
203 } 200 }
204 int x = header->sectionPos( dow ) - 1; 201 int x = header->sectionPos( dow ) - 1;
205 int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); 202 int xlim = header->sectionPos( dow ) + header->sectionSize( dow );
206 DateBookWeekItem *isect = 0; 203 DateBookWeekItem *isect = 0;
207 do { 204 do {
208 i->setGeometry( x, y, Width, h ); 205 i->setGeometry( x, y, Width, h );
209 isect = intersects( i ); 206 isect = intersects( i );
210 x += Width - 1; 207 x += Width - 1;
211 } while ( isect && x < xlim ); 208 } while ( isect && x < xlim );
212} 209}
213 210
214DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) 211DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item )
215{ 212{
216 QRect geom = item->geometry(); 213 QRect geom = item->geometry();
217 214
218 // We allow the edges to overlap 215 // We allow the edges to overlap
219 geom.moveBy( 1, 1 ); 216 geom.moveBy( 1, 1 );
220 geom.setSize( geom.size()-QSize(2,2) ); 217 geom.setSize( geom.size()-QSize(2,2) );
221 218
222 QListIterator<DateBookWeekItem> it(items); 219 QListIterator<DateBookWeekItem> it(items);
223 for ( ; it.current(); ++it ) { 220 for ( ; it.current(); ++it ) {
224 DateBookWeekItem *i = it.current(); 221 DateBookWeekItem *i = it.current();
225 if ( i != item ) { 222 if ( i != item ) {
226 if ( i->geometry().intersects( geom ) ) { 223 if ( i->geometry().intersects( geom ) ) {
227 return i; 224 return i;
228 } 225 }
229 } 226 }
230 } 227 }
231 228
232 return 0; 229 return 0;
233} 230}
234 231
235void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) 232void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e )
236{ 233{
237 QListIterator<DateBookWeekItem> it(items); 234 QListIterator<DateBookWeekItem> it(items);
238 for ( ; it.current(); ++it ) { 235 for ( ; it.current(); ++it ) {
239 DateBookWeekItem *i = it.current(); 236 DateBookWeekItem *i = it.current();
240 if ( i->geometry().contains( e->pos() ) ) { 237 if ( i->geometry().contains( e->pos() ) ) {
241 showingEvent = true; 238 showingEvent = true;
242 emit signalShowEvent( i->event() ); 239 emit signalShowEvent( i->event() );
243 break; 240 break;
244 } 241 }
245 } 242 }
246} 243}
247 244
248void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) 245void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e )
249{ 246{
250 if ( showingEvent ) { 247 if ( showingEvent ) {
251 showingEvent = false; 248 showingEvent = false;
252 emit signalHideEvent(); 249 emit signalHideEvent();
253 } else { 250 } else {
254 int d = header->sectionAt( e->pos().x() ); 251 int d = header->sectionAt( e->pos().x() );
255 if ( d > 0 ) { 252 if ( d > 0 ) {
256 // if ( !bOnMonday ) 253 // if ( !bOnMonday )
257 // d--; 254 // d--;
258 emit showDay( d ); 255 emit showDay( d );
259 } 256 }
260 } 257 }
261} 258}
262 259
263void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) 260void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
264{ 261{
265 QRect ur( cx, cy, cw, ch ); 262 QRect ur( cx, cy, cw, ch );
266 p->setPen( lightGray ); 263 p->setPen( lightGray );
267 for ( int i = 1; i <= 7; i++ ) 264 for ( int i = 1; i <= 7; i++ )
268 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); 265 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch );
269 266
270 p->setPen( black ); 267 p->setPen( black );
271 for ( int t = 0; t < 24; t++ ) { 268 for ( int t = 0; t < 24; t++ ) {
272 int y = t*rowHeight; 269 int y = t*rowHeight;
273 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { 270 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) {
274 QString s; 271 QString s;
275 if ( ampm ) { 272 if ( ampm ) {
276 if ( t == 0 ) 273 if ( t == 0 )
277 s = QString::number( 12 ); 274 s = QString::number( 12 );
278 else if ( t == 12 ) 275 else if ( t == 12 )
279 s = QString::number(12) + tr( "p" ); 276 s = QString::number(12) + tr( "p" );
280 else if ( t > 12 ) { 277 else if ( t > 12 ) {
281 if ( t - 12 < 10 ) 278 if ( t - 12 < 10 )
282 s = " "; 279 s = " ";
283 else 280 else
284 s = ""; 281 s = "";
285 s += QString::number( t - 12 ) + tr("p"); 282 s += QString::number( t - 12 ) + tr("p");
286 } else { 283 } else {
287 if ( 12 - t < 3 ) 284 if ( 12 - t < 3 )
288 s = ""; 285 s = "";
289 else 286 else
290 s = " "; 287 s = " ";
291 s += QString::number( t ); 288 s += QString::number( t );
292 } 289 }
293 } else { 290 } else {
294 s = QString::number( t ); 291 s = QString::number( t );
295 if ( s.length() == 1 ) 292 if ( s.length() == 1 )
296 s.prepend( "0" ); 293 s.prepend( "0" );
297 } 294 }
298 p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); 295 p->drawText( 1, y+p->fontMetrics().ascent()+1, s );
299 } 296 }
300 } 297 }
301 298
302 QListIterator<DateBookWeekItem> it(items); 299 QListIterator<DateBookWeekItem> it(items);
303 for ( ; it.current(); ++it ) { 300 for ( ; it.current(); ++it ) {
304 DateBookWeekItem *i = it.current(); 301 DateBookWeekItem *i = it.current();
305 if ( i->geometry().intersects( ur ) ) { 302 if ( i->geometry().intersects( ur ) ) {
306 p->setBrush( i->color() ); 303 p->setBrush( i->color() );
307 p->drawRect( i->geometry() ); 304 p->drawRect( i->geometry() );
308 } 305 }
309 } 306 }
310} 307}
311 308
312void DateBookWeekView::resizeEvent( QResizeEvent *e ) 309void DateBookWeekView::resizeEvent( QResizeEvent *e )
313{ 310{
314 const int hourWidth = 20; 311 const int hourWidth = 20;
315 QScrollView::resizeEvent( e ); 312 QScrollView::resizeEvent( e );
316 313
317#warning check the geometry i have choosen BRANCH_1_0 (waspe)
318 314
319 //HEAD 315 //HEAD
320 /* 316 /*
321 int avail = visibleWidth(); 317 int avail = visibleWidth();
322 header->setGeometry( leftMargin()+frameWidth()+frameRect().left() , frameWidth(), 318 header->setGeometry( leftMargin()+frameWidth()+frameRect().left() , frameWidth(),
323 visibleWidth(), header->sizeHint().height() ); 319 visibleWidth(), header->sizeHint().height() );
324 setMargins( 0, header->sizeHint().height(), 0, 0 ); 320 setMargins( 0, header->sizeHint().height(), 0, 0 );
325 */ 321 */
326 //BRANCH_1_0 322 //BRANCH_1_0
327 int avail = width()-qApp->style().scrollBarExtent().width()-1; 323 int avail = width()-qApp->style().scrollBarExtent().width()-1;
328 header->setGeometry( 0, 0, avail, header->sizeHint().height() ); 324 header->setGeometry( 0, 0, avail, header->sizeHint().height() );
329 setMargins( 0, header->height(), 0, 0 ); 325 setMargins( 0, header->height(), 0, 0 );
330 326
331 327
332 header->resizeSection( 0, hourWidth ); 328 header->resizeSection( 0, hourWidth );
333 int sw = (avail - hourWidth) / 7; 329 int sw = (avail - hourWidth) / 7;
334 for ( int i = 1; i < 7; i++ ) 330 for ( int i = 1; i < 7; i++ )
335 header->resizeSection( i, sw ); 331 header->resizeSection( i, sw );
336 header->resizeSection( 7, avail - hourWidth - sw*6 ); 332 header->resizeSection( 7, avail - hourWidth - sw*6 );
337} 333}
338 334
339void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) 335void DateBookWeekView::setStartOfWeek( bool bStartOnMonday )
340{ 336{
341 bOnMonday = bStartOnMonday; 337 bOnMonday = bStartOnMonday;
342 initNames(); 338 initNames();
343} 339}
344 340
345//------------------------------------------------------------------- 341//-------------------------------------------------------------------
346 342
347DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, 343DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB,
348 QWidget *parent, const char *name ) 344 QWidget *parent, const char *name )
349 : QWidget( parent, name ), 345 : QWidget( parent, name ),
350 db( newDB ), 346 db( newDB ),
351 startTime( 0 ), 347 startTime( 0 ),
352 ampm( ap ), 348 ampm( ap ),
353 bStartOnMonday( startOnMonday ) 349 bStartOnMonday( startOnMonday )
354{ 350{
355 setFocusPolicy(StrongFocus); 351 setFocusPolicy(StrongFocus);
356 QVBoxLayout *vb = new QVBoxLayout( this ); 352 QVBoxLayout *vb = new QVBoxLayout( this );
357 header = new DateBookWeekHeader( bStartOnMonday, this ); 353 header = new DateBookWeekHeader( bStartOnMonday, this );
358 view = new DateBookWeekView( ampm, startOnMonday, this ); 354 view = new DateBookWeekView( ampm, startOnMonday, this );
359 vb->addWidget( header ); 355 vb->addWidget( header );
360 vb->addWidget( view ); 356 vb->addWidget( view );
361 357
362 lblDesc = new QLabel( this, "event label" ); 358 lblDesc = new QLabel( this, "event label" );
363 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); 359 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box );
364 lblDesc->setBackgroundColor( yellow ); 360 lblDesc->setBackgroundColor( yellow );
365 lblDesc->hide(); 361 lblDesc->hide();
366 362
367 tHide = new QTimer( this ); 363 tHide = new QTimer( this );
368 364
369 connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); 365 connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) );
370 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); 366 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) );
371 connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); 367 connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) );
372 connect( header, SIGNAL( dateChanged( QDate &) ), this, SLOT( dateChanged( QDate &) ) ); 368 connect( header, SIGNAL( dateChanged( QDate &) ), this, SLOT( dateChanged( QDate &) ) );
373 connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); 369 connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) );
374 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); 370 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) );
375 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); 371 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool)));
376 setDate(QDate::currentDate()); 372 setDate(QDate::currentDate());
377} 373}
378 374
379void DateBookWeek::keyPressEvent(QKeyEvent *e) 375void DateBookWeek::keyPressEvent(QKeyEvent *e)
380{ 376{
381 switch(e->key()) { 377 switch(e->key()) {
382 case Key_Up: 378 case Key_Up:
383 view->scrollBy(0, -20); 379 view->scrollBy(0, -20);
384 break; 380 break;
385 case Key_Down: 381 case Key_Down:
386 view->scrollBy(0, 20); 382 view->scrollBy(0, 20);
387 break; 383 break;
388 case Key_Left: 384 case Key_Left:
389 setDate(date().addDays(-7)); 385 setDate(date().addDays(-7));
390 break; 386 break;
391 case Key_Right: 387 case Key_Right:
392 setDate(date().addDays(7)); 388 setDate(date().addDays(7));
393 break; 389 break;
394 default: 390 default:
395 e->ignore(); 391 e->ignore();
396 } 392 }
397} 393}
398 394
399void DateBookWeek::showDay( int day ) 395void DateBookWeek::showDay( int day )
400{ 396{
401 QDate d=bdate; 397 QDate d=bdate;
402 398
403 // Calculate offset to first day of week. 399 // Calculate offset to first day of week.
404 int dayoffset=d.dayOfWeek() % 7; 400 int dayoffset=d.dayOfWeek() % 7;
405 401
406 if(bStartOnMonday) dayoffset--; 402 if(bStartOnMonday) dayoffset--;
407 403
408 day--; 404 day--;
409 d=d.addDays(day-dayoffset); 405 d=d.addDays(day-dayoffset);
410 emit showDate( d.year(), d.month(), d.day() ); 406 emit showDate( d.year(), d.month(), d.day() );
411} 407}
412 408
413void DateBookWeek::setDate( int y, int m, int d ) 409void DateBookWeek::setDate( int y, int m, int d )
414{ 410{
415 setDate(QDate(y, m, d)); 411 setDate(QDate(y, m, d));
416} 412}
417 413
418void DateBookWeek::setDate(QDate newdate) 414void DateBookWeek::setDate(QDate newdate)
419{ 415{
420 bdate=newdate; 416 bdate=newdate;
421 dow = newdate.dayOfWeek(); 417 dow = newdate.dayOfWeek();
422 header->setDate( newdate ); 418 header->setDate( newdate );
423} 419}
424 420
425void DateBookWeek::dateChanged( QDate &newdate ) 421void DateBookWeek::dateChanged( QDate &newdate )
426{ 422{
427 bdate=newdate; 423 bdate=newdate;
428 getEvents(); 424 getEvents();
429} 425}
430 426
431QDate DateBookWeek::date() const 427QDate DateBookWeek::date() const
432{ 428{
433 return bdate; 429 return bdate;
434} 430}
435 431
436void DateBookWeek::getEvents() 432void DateBookWeek::getEvents()
437{ 433{
438 QDate startWeek = weekDate(); 434 QDate startWeek = weekDate();
439 435
440 QDate endWeek = startWeek.addDays( 6 ); 436 QDate endWeek = startWeek.addDays( 6 );
441 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); 437 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek);
442 view->showEvents( eventList ); 438 view->showEvents( eventList );
443 view->moveToHour( startTime ); 439 view->moveToHour( startTime );
444} 440}
445 441
446void DateBookWeek::generateAllDayTooltext( QString& text ) { 442void DateBookWeek::generateAllDayTooltext( QString& text ) {
447 text += "<b>" + tr("This is an all day event.") + "</b><br>"; 443 text += "<b>" + tr("This is an all day event.") + "</b><br>";
448} 444}
449 445
450void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { 446void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) {
451 str += "<b>" + QObject::tr("Start") + "</b>: "; 447 str += "<b>" + QObject::tr("Start") + "</b>: ";
452 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); 448 str += TimeString::timeString( ev.event().start().time(), ampm, FALSE );
453 if( ev.startDate()!=ev.endDate() ) { 449 if( ev.startDate()!=ev.endDate() ) {
454 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; 450 str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>";
455 } 451 }
456 str += "<br>"; 452 str += "<br>";
457 str += "<b>" + QObject::tr("End") + "</b>: "; 453 str += "<b>" + QObject::tr("End") + "</b>: ";
458 str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); 454 str += TimeString::timeString( ev.event().end().time(), ampm, FALSE );
459 if( ev.startDate()!=ev.endDate() ) { 455 if( ev.startDate()!=ev.endDate() ) {
460 str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; 456 str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>";
461 } 457 }
462} 458}
463 459
464void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) 460void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
465{ 461{
466 if ( tHide->isActive() ) 462 if ( tHide->isActive() )
467 tHide->stop(); 463 tHide->stop();
468 464
469 // why would someone use "<"? Oh well, fix it up... 465 // why would someone use "<"? Oh well, fix it up...
470 // I wonder what other things may be messed up... 466 // I wonder what other things may be messed up...
471 QString strDesc = ev.description(); 467 QString strDesc = ev.description();
472 int where = strDesc.find( "<" ); 468 int where = strDesc.find( "<" );
473 while ( where != -1 ) { 469 while ( where != -1 ) {
474 strDesc.remove( where, 1 ); 470 strDesc.remove( where, 1 );
475 strDesc.insert( where, "&#60;" ); 471 strDesc.insert( where, "&#60;" );
476 where = strDesc.find( "<", where ); 472 where = strDesc.find( "<", where );
477 } 473 }
478 474
479 QString strCat; 475 QString strCat;
480 // ### FIX later... 476 // ### FIX later...
481// QString strCat = ev.category(); 477// QString strCat = ev.category();
482// where = strCat.find( "<" ); 478// where = strCat.find( "<" );
483// while ( where != -1 ) { 479// while ( where != -1 ) {
484 // strCat.remove( where, 1 ); 480 // strCat.remove( where, 1 );
485 // strCat.insert( where, "&#60;" ); 481 // strCat.insert( where, "&#60;" );
486 // where = strCat.find( "<", where ); 482 // where = strCat.find( "<", where );
487// } 483// }
488 484
489 QString strLocation = ev.location(); 485 QString strLocation = ev.location();
490 while ( where != -1 ) { 486 while ( where != -1 ) {
491 strLocation.remove( where, 1 ); 487 strLocation.remove( where, 1 );
492 strLocation.insert( where, "&#60;" ); 488 strLocation.insert( where, "&#60;" );
493 where = strLocation.find( "<", where ); 489 where = strLocation.find( "<", where );
494 } 490 }
495 491
496 QString strNote = ev.notes(); 492 QString strNote = ev.notes();
497 where = strNote.find( "<" ); 493 where = strNote.find( "<" );
498 while ( where != -1 ) { 494 while ( where != -1 ) {
499 strNote.remove( where, 1 ); 495 strNote.remove( where, 1 );
500 strNote.insert( where, "&#60;" ); 496 strNote.insert( where, "&#60;" );
501 where = strNote.find( "<", where ); 497 where = strNote.find( "<", where );
502 } 498 }
503 499
504 QString str = "<b>" + strDesc + "</b><br>" 500 QString str = "<b>" + strDesc + "</b><br>"
505 + strLocation + "<br>" 501 + strLocation + "<br>"
506 + "<i>" + strCat + "</i>" 502 + "<i>" + strCat + "</i>"
507 + "<br>" + TimeString::longDateString( ev.date() ) 503 + "<br>" + TimeString::longDateString( ev.date() )
508 + "<br>"; 504 + "<br>";
509 505
510 if (ev.event().type() == Event::Normal ) 506 if (ev.event().type() == Event::Normal )
511 generateNormalTooltext( str, ev ); 507 generateNormalTooltext( str, ev );
512 else 508 else
513 generateAllDayTooltext( str ); 509 generateAllDayTooltext( str );
514 510
515 str += "<br><br>" + strNote; 511 str += "<br><br>" + strNote;
516 512
517 lblDesc->setText( str ); 513 lblDesc->setText( str );
518 lblDesc->resize( lblDesc->sizeHint() ); 514 lblDesc->resize( lblDesc->sizeHint() );
519 // move the label so it is "centerd" horizontally... 515 // move the label so it is "centerd" horizontally...
520 lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 ); 516 lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 );
521 lblDesc->show(); 517 lblDesc->show();
522} 518}
523 519
524void DateBookWeek::slotHideEvent() 520void DateBookWeek::slotHideEvent()
525{ 521{
526 tHide->start( 2000, true ); 522 tHide->start( 2000, true );
527} 523}
528 524
529void DateBookWeek::setStartViewTime( int startHere ) 525void DateBookWeek::setStartViewTime( int startHere )
530{ 526{
531 startTime = startHere; 527 startTime = startHere;
532 view->moveToHour( startTime ); 528 view->moveToHour( startTime );
533} 529}
534 530
535int DateBookWeek::startViewTime() const 531int DateBookWeek::startViewTime() const
536{ 532{
537 return startTime; 533 return startTime;
538} 534}
539 535
540void DateBookWeek::redraw() 536void DateBookWeek::redraw()
541{ 537{
542 getEvents(); 538 getEvents();
543} 539}
544 540
545void DateBookWeek::slotYearChanged( int y ) 541void DateBookWeek::slotYearChanged( int y )
546{ 542{
547 int totWeek; 543 int totWeek;
548 QDate d( y, 12, 31 ); 544 QDate d( y, 12, 31 );
549 int throwAway; 545 int throwAway;
550 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 546 calcWeek( d, totWeek, throwAway, bStartOnMonday );
551 while ( totWeek == 1 ) { 547 while ( totWeek == 1 ) {
552 d = d.addDays( -1 ); 548 d = d.addDays( -1 );
553 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 549 calcWeek( d, totWeek, throwAway, bStartOnMonday );
554 } 550 }
555} 551}
556 552
557void DateBookWeek::slotWeekChanged( bool onMonday ) 553void DateBookWeek::slotWeekChanged( bool onMonday )
558{ 554{
559 bStartOnMonday = onMonday; 555 bStartOnMonday = onMonday;
560 view->setStartOfWeek( bStartOnMonday ); 556 view->setStartOfWeek( bStartOnMonday );
561 header->setStartOfWeek( bStartOnMonday ); 557 header->setStartOfWeek( bStartOnMonday );
562 redraw(); 558 redraw();
563} 559}
564 560
565void DateBookWeek::slotClockChanged( bool ap ) 561void DateBookWeek::slotClockChanged( bool ap )
566{ 562{
567 ampm = ap; 563 ampm = ap;
568} 564}
569 565
570// return the date at the beginning of the week... 566// return the date at the beginning of the week...
571QDate DateBookWeek::weekDate() const 567QDate DateBookWeek::weekDate() const
572{ 568{
573 QDate d=bdate; 569 QDate d=bdate;
574 570
575 // Calculate offset to first day of week. 571 // Calculate offset to first day of week.
576 int dayoffset=d.dayOfWeek(); 572 int dayoffset=d.dayOfWeek();
577 if(bStartOnMonday) dayoffset--; 573 if(bStartOnMonday) dayoffset--;
578 else if( dayoffset == 7 ) 574 else if( dayoffset == 7 )
579 dayoffset = 0; 575 dayoffset = 0;
580 576
581 return d.addDays(-dayoffset); 577 return d.addDays(-dayoffset);
582} 578}
583 579
584// this used to only be needed by datebook.cpp, but now we need it inside 580// this used to only be needed by datebook.cpp, but now we need it inside
585// week view since 581// week view since
586// we need to be able to figure out our total number of weeks on the fly... 582// we need to be able to figure out our total number of weeks on the fly...
587// this is probably the best place to put it.. 583// this is probably the best place to put it..
588 584
589// For Weeks that start on Monday... (EASY!) 585// For Weeks that start on Monday... (EASY!)
590// At the moment we will use ISO 8601 method for computing 586// At the moment we will use ISO 8601 method for computing
591// the week. Granted, other countries use other methods, 587// the week. Granted, other countries use other methods,
592// bet we aren't doing any Locale stuff at the moment. So, 588// bet we aren't doing any Locale stuff at the moment. So,
593// this should pass. This Algorithim is public domain and 589// this should pass. This Algorithim is public domain and
594// available at: 590// available at:
595// http://personal.ecu.edu/mccartyr/ISOwdALG.txt 591// http://personal.ecu.edu/mccartyr/ISOwdALG.txt
596// the week number is return, and the year number is returned in year 592// the week number is return, and the year number is returned in year
597// for Instance 2001/12/31 is actually the first week in 2002. 593// for Instance 2001/12/31 is actually the first week in 2002.
598// There is a more mathematical definition, but I will implement it when 594// There is a more mathematical definition, but I will implement it when
599// we are pass our deadline. 595// we are pass our deadline.
600 596
601// For Weeks that start on Sunday... (ahh... home rolled) 597// For Weeks that start on Sunday... (ahh... home rolled)
602// okay, if Jan 1 is on Friday or Saturday, 598// okay, if Jan 1 is on Friday or Saturday,
603// it will go to the pervious 599// it will go to the pervious
604// week... 600// week...
605 601
606bool calcWeek( const QDate &d, int &week, int &year, 602bool calcWeek( const QDate &d, int &week, int &year,
607 bool startOnMonday ) 603 bool startOnMonday )
608{ 604{
609 int weekNumber; 605 int weekNumber;
610 int yearNumber; 606 int yearNumber;
611 607
612 // remove a pesky warning, (Optimizations on g++) 608 // remove a pesky warning, (Optimizations on g++)
613 weekNumber = -1; 609 weekNumber = -1;
614 int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); 610 int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek();
615 int dayOfWeek = d.dayOfWeek(); 611 int dayOfWeek = d.dayOfWeek();
616 612
617 if ( !d.isValid() ) 613 if ( !d.isValid() )
618 return false; 614 return false;
619 615
620 if ( startOnMonday ) { 616 if ( startOnMonday ) {
621 // find the Jan1Weekday; 617 // find the Jan1Weekday;
622 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { 618 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) {
623 yearNumber = d.year() - 1; 619 yearNumber = d.year() - 1;
624 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) 620 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) )
625 weekNumber = 53; 621 weekNumber = 53;
626 else 622 else
627 weekNumber = 52; 623 weekNumber = 52;
628 } else 624 } else
629 yearNumber = d.year(); 625 yearNumber = d.year();
630 if ( yearNumber == d.year() ) { 626 if ( yearNumber == d.year() ) {
631 int totalDays = 365; 627 int totalDays = 365;
632 if ( QDate::leapYear(yearNumber) ) 628 if ( QDate::leapYear(yearNumber) )
633 totalDays++; 629 totalDays++;
634 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) 630 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) )
635 || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { 631 || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) {
636 yearNumber++; 632 yearNumber++;
637 weekNumber = 1; 633 weekNumber = 1;
638 } 634 }
639 } 635 }
640 if ( yearNumber == d.year() ) { 636 if ( yearNumber == d.year() ) {
641 int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); 637 int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 );
642 weekNumber = j / 7; 638 weekNumber = j / 7;
643 if ( jan1WeekDay > 4 ) 639 if ( jan1WeekDay > 4 )
644 weekNumber--; 640 weekNumber--;
645 } 641 }
646 } else { 642 } else {
647 // it's better to keep these cases separate... 643 // it's better to keep these cases separate...
648 if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 644 if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4
649 && jan1WeekDay != 7 ) { 645 && jan1WeekDay != 7 ) {
650 yearNumber = d.year() - 1; 646 yearNumber = d.year() - 1;
651 if ( jan1WeekDay == 6 647 if ( jan1WeekDay == 6
652 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { 648 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) {
653 weekNumber = 53; 649 weekNumber = 53;
654 }else 650 }else
655 weekNumber = 52; 651 weekNumber = 52;
656 } else 652 } else
657 yearNumber = d.year(); 653 yearNumber = d.year();
658 if ( yearNumber == d.year() ) { 654 if ( yearNumber == d.year() ) {
659 int totalDays = 365; 655 int totalDays = 365;
660 if ( QDate::leapYear( yearNumber ) ) 656 if ( QDate::leapYear( yearNumber ) )
661 totalDays++; 657 totalDays++;
662 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { 658 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) {
663 yearNumber++; 659 yearNumber++;
664 weekNumber = 1; 660 weekNumber = 1;
665 } 661 }
666 } 662 }
667 if ( yearNumber == d.year() ) { 663 if ( yearNumber == d.year() ) {
668 int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); 664 int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 );
669 weekNumber = j / 7; 665 weekNumber = j / 7;
670 if ( jan1WeekDay > 4 ) { 666 if ( jan1WeekDay > 4 ) {
671 weekNumber--; 667 weekNumber--;
672 } 668 }
673 } 669 }
674 } 670 }
675 year = yearNumber; 671 year = yearNumber;
676 week = weekNumber; 672 week = weekNumber;
677 return true; 673 return true;
678} 674}
679 675