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