-rw-r--r-- | core/pim/datebook/datebookday.cpp | 2 | ||||
-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 2 | ||||
-rw-r--r-- | core/pim/datebook/datebookweeklst.cpp | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index 5d472a6..af98e06 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp | |||
@@ -56,513 +56,513 @@ DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, | |||
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 | initHeader(); | 66 | initHeader(); |
67 | QObject::connect( qApp, SIGNAL(clockChanged(bool)), | 67 | QObject::connect( qApp, SIGNAL(clockChanged(bool)), |
68 | this, SLOT(slotChangeClock(bool)) ); | 68 | this, SLOT(slotChangeClock(bool)) ); |
69 | } | 69 | } |
70 | 70 | ||
71 | void DateBookDayView::initHeader() | 71 | void DateBookDayView::initHeader() |
72 | { | 72 | { |
73 | QString strTmp; | 73 | QString strTmp; |
74 | for ( int i = 0; i < 24; ++i ) { | 74 | for ( int i = 0; i < 24; ++i ) { |
75 | if ( ampm ) { | 75 | if ( ampm ) { |
76 | if ( i == 0 ) | 76 | if ( i == 0 ) |
77 | strTmp = QString::number(12) + ":00"; | 77 | strTmp = QString::number(12) + ":00"; |
78 | else if ( i == 12 ) | 78 | else if ( i == 12 ) |
79 | strTmp = QString::number(12) + tr(":00p"); | 79 | strTmp = QString::number(12) + tr(":00p"); |
80 | else if ( i > 12 ) | 80 | else if ( i > 12 ) |
81 | strTmp = QString::number( i - 12 ) + tr(":00p"); | 81 | strTmp = QString::number( i - 12 ) + tr(":00p"); |
82 | else | 82 | else |
83 | strTmp = QString::number(i) + ":00"; | 83 | strTmp = QString::number(i) + ":00"; |
84 | } else { | 84 | } else { |
85 | if ( i < 10 ) | 85 | if ( i < 10 ) |
86 | strTmp = "0" + QString::number(i) + ":00"; | 86 | strTmp = "0" + QString::number(i) + ":00"; |
87 | else | 87 | else |
88 | strTmp = QString::number(i) + ":00"; | 88 | strTmp = QString::number(i) + ":00"; |
89 | } | 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 | ||
96 | void DateBookDayView::slotChangeClock( bool newClock ) | 96 | void DateBookDayView::slotChangeClock( bool newClock ) |
97 | { | 97 | { |
98 | ampm = newClock; | 98 | ampm = newClock; |
99 | initHeader(); | 99 | initHeader(); |
100 | } | 100 | } |
101 | 101 | ||
102 | bool DateBookDayView::whichClock() const | 102 | bool DateBookDayView::whichClock() const |
103 | { | 103 | { |
104 | return ampm; | 104 | return ampm; |
105 | } | 105 | } |
106 | 106 | ||
107 | void DateBookDayView::moveUp() | 107 | void DateBookDayView::moveUp() |
108 | { | 108 | { |
109 | scrollBy(0, -20); | 109 | scrollBy(0, -20); |
110 | } | 110 | } |
111 | 111 | ||
112 | void DateBookDayView::moveDown() | 112 | void DateBookDayView::moveDown() |
113 | { | 113 | { |
114 | scrollBy(0, 20); | 114 | scrollBy(0, 20); |
115 | } | 115 | } |
116 | 116 | ||
117 | void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) | 117 | void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) |
118 | { | 118 | { |
119 | int w = cr.width(); | 119 | int w = cr.width(); |
120 | int h = cr.height(); | 120 | int h = cr.height(); |
121 | p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); | 121 | p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); |
122 | if ( showGrid() ) { | 122 | if ( showGrid() ) { |
123 | // Draw our lines | 123 | // Draw our lines |
124 | int x2 = w - 1; | 124 | int x2 = w - 1; |
125 | int y2 = h - 1; | 125 | int y2 = h - 1; |
126 | QPen pen( p->pen() ); | 126 | QPen pen( p->pen() ); |
127 | p->setPen( colorGroup().dark() ); | 127 | p->setPen( colorGroup().dark() ); |
128 | p->drawLine( x2, 0, x2, y2 ); | 128 | p->drawLine( x2, 0, x2, y2 ); |
129 | p->drawLine( 0, y2, x2, y2 ); | 129 | p->drawLine( 0, y2, x2, y2 ); |
130 | 130 | ||
131 | p->setPen( colorGroup().midlight() ); | 131 | p->setPen( colorGroup().midlight() ); |
132 | p->drawLine( 0, y2 - h/2, x2, y2 - h/2); | 132 | p->drawLine( 0, y2 - h/2, x2, y2 - h/2); |
133 | 133 | ||
134 | p->setPen( pen ); | 134 | p->setPen( pen ); |
135 | } | 135 | } |
136 | } | 136 | } |
137 | 137 | ||
138 | void DateBookDayView::paintFocus( QPainter *, const QRect & ) | 138 | void DateBookDayView::paintFocus( QPainter *, const QRect & ) |
139 | { | 139 | { |
140 | } | 140 | } |
141 | 141 | ||
142 | 142 | ||
143 | void DateBookDayView::resizeEvent( QResizeEvent *e ) | 143 | void DateBookDayView::resizeEvent( QResizeEvent *e ) |
144 | { | 144 | { |
145 | QTable::resizeEvent( e ); | 145 | QTable::resizeEvent( e ); |
146 | columnWidthChanged( 0 ); | 146 | columnWidthChanged( 0 ); |
147 | emit sigColWidthChanged(); | 147 | emit sigColWidthChanged(); |
148 | } | 148 | } |
149 | 149 | ||
150 | void DateBookDayView::keyPressEvent( QKeyEvent *e ) | 150 | void DateBookDayView::keyPressEvent( QKeyEvent *e ) |
151 | { | 151 | { |
152 | QString txt = e->text(); | 152 | QString txt = e->text(); |
153 | if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { | 153 | if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { |
154 | // we this is some sort of thing we know about... | 154 | // we this is some sort of thing we know about... |
155 | e->accept(); | 155 | e->accept(); |
156 | emit sigCapturedKey( txt ); | 156 | emit sigCapturedKey( txt ); |
157 | } else { | 157 | } else { |
158 | // I don't know what this key is, do you? | 158 | // I don't know what this key is, do you? |
159 | e->ignore(); | 159 | e->ignore(); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | 162 | ||
163 | void DateBookDayView::setRowStyle( int style ) | 163 | void DateBookDayView::setRowStyle( int style ) |
164 | { | 164 | { |
165 | if (style<0) style = 0; | 165 | if (style<0) style = 0; |
166 | 166 | ||
167 | for (int i=0; i<numRows(); i++) | 167 | for (int i=0; i<numRows(); i++) |
168 | setRowHeight(i, style*10+20); | 168 | setRowHeight(i, style*10+20); |
169 | } | 169 | } |
170 | 170 | ||
171 | //=========================================================================== | 171 | //=========================================================================== |
172 | 172 | ||
173 | DateBookDay::DateBookDay( bool ampm, bool startOnMonday, | 173 | DateBookDay::DateBookDay( bool ampm, bool startOnMonday, |
174 | DateBookDB *newDb, QWidget *parent, | 174 | DateBookDB *newDb, QWidget *parent, |
175 | const char *name ) | 175 | const char *name ) |
176 | : QVBox( parent, name ), | 176 | : QVBox( parent, name ), |
177 | currDate( QDate::currentDate() ), | 177 | currDate( QDate::currentDate() ), |
178 | db( newDb ), | 178 | db( newDb ), |
179 | startTime( 0 ) | 179 | startTime( 0 ) |
180 | { | 180 | { |
181 | widgetList.setAutoDelete( true ); | 181 | widgetList.setAutoDelete( true ); |
182 | header = new DateBookDayHeader( startOnMonday, this, "day header" ); | 182 | header = new DateBookDayHeader( startOnMonday, this, "day header" ); |
183 | header->setDate( currDate.year(), currDate.month(), currDate.day() ); | 183 | header->setDate( currDate.year(), currDate.month(), currDate.day() ); |
184 | view = new DateBookDayView( ampm, this, "day view" ); | 184 | view = new DateBookDayView( ampm, this, "day view" ); |
185 | 185 | ||
186 | connect( header, SIGNAL( dateChanged( int, int, int ) ), | 186 | connect( header, SIGNAL( dateChanged( int, int, int ) ), |
187 | this, SLOT( dateChanged( int, int, int ) ) ); | 187 | this, SLOT( dateChanged( int, int, int ) ) ); |
188 | connect( view, SIGNAL( sigColWidthChanged() ), | 188 | connect( view, SIGNAL( sigColWidthChanged() ), |
189 | this, SLOT( slotColWidthChanged() ) ); | 189 | this, SLOT( slotColWidthChanged() ) ); |
190 | connect( qApp, SIGNAL(weekChanged(bool)), | 190 | connect( qApp, SIGNAL(weekChanged(bool)), |
191 | this, SLOT(slotWeekChanged(bool)) ); | 191 | this, SLOT(slotWeekChanged(bool)) ); |
192 | connect( view, SIGNAL(sigCapturedKey(const QString &)), | 192 | connect( view, SIGNAL(sigCapturedKey(const QString &)), |
193 | this, SIGNAL(sigNewEvent(const QString&)) ); | 193 | this, SIGNAL(sigNewEvent(const QString&)) ); |
194 | 194 | ||
195 | QTimer *timer = new QTimer( this ); | 195 | QTimer *timer = new QTimer( this ); |
196 | 196 | ||
197 | connect( timer, SIGNAL(timeout()), | 197 | connect( timer, SIGNAL(timeout()), |
198 | this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors | 198 | this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors |
199 | timer->start( 1000*60*5, FALSE ); //update every 5min | 199 | timer->start( 1000*60*5, FALSE ); //update every 5min |
200 | 200 | ||
201 | selectedWidget = 0; | 201 | selectedWidget = 0; |
202 | 202 | ||
203 | timeMarker = new DateBookDayTimeMarker( this ); | 203 | timeMarker = new DateBookDayTimeMarker( this ); |
204 | timeMarker->setTime( QTime::currentTime() ); | 204 | timeMarker->setTime( QTime::currentTime() ); |
205 | rowStyle = -1; // initialize with bogus values | 205 | rowStyle = -1; // initialize with bogus values |
206 | } | 206 | } |
207 | 207 | ||
208 | void DateBookDay::setJumpToCurTime( bool bJump ) | 208 | void DateBookDay::setJumpToCurTime( bool bJump ) |
209 | { | 209 | { |
210 | jumpToCurTime = bJump; | 210 | jumpToCurTime = bJump; |
211 | } | 211 | } |
212 | 212 | ||
213 | void DateBookDay::setRowStyle( int style ) | 213 | void DateBookDay::setRowStyle( int style ) |
214 | { | 214 | { |
215 | if (rowStyle != style) view->setRowStyle( style ); | 215 | if (rowStyle != style) view->setRowStyle( style ); |
216 | rowStyle = style; | 216 | rowStyle = style; |
217 | } | 217 | } |
218 | 218 | ||
219 | void DateBookDay::updateView( void ) | 219 | void DateBookDay::updateView( void ) |
220 | { | 220 | { |
221 | timeMarker->setTime( QTime::currentTime() ); | 221 | timeMarker->setTime( QTime::currentTime() ); |
222 | //need to find a way to update all DateBookDayWidgets | 222 | //need to find a way to update all DateBookDayWidgets |
223 | } | 223 | } |
224 | 224 | ||
225 | void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) | 225 | void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) |
226 | { | 226 | { |
227 | selectedWidget = w; | 227 | selectedWidget = w; |
228 | } | 228 | } |
229 | 229 | ||
230 | DateBookDayWidget * DateBookDay::getSelectedWidget( void ) | 230 | DateBookDayWidget * DateBookDay::getSelectedWidget( void ) |
231 | { | 231 | { |
232 | return selectedWidget; | 232 | return selectedWidget; |
233 | } | 233 | } |
234 | 234 | ||
235 | void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) | 235 | void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) |
236 | { | 236 | { |
237 | start.setDate( currDate ); | 237 | start.setDate( currDate ); |
238 | end.setDate( currDate ); | 238 | end.setDate( currDate ); |
239 | 239 | ||
240 | int sh=99,eh=-1; | 240 | int sh=99,eh=-1; |
241 | 241 | ||
242 | int n = dayView()->numSelections(); | 242 | int n = dayView()->numSelections(); |
243 | 243 | ||
244 | for (int i=0; i<n; i++) { | 244 | for (int i=0; i<n; i++) { |
245 | QTableSelection sel = dayView()->selection( i ); | 245 | QTableSelection sel = dayView()->selection( i ); |
246 | sh = QMIN(sh,sel.topRow()); | 246 | sh = QMIN(sh,sel.topRow()); |
247 | eh = QMAX(sh,sel.bottomRow()+1); | 247 | eh = QMAX(sh,sel.bottomRow()+1); |
248 | } | 248 | } |
249 | if (sh > 23 || eh < 1) { | 249 | if (sh > 23 || eh < 1) { |
250 | sh=8; | 250 | sh=8; |
251 | eh=9; | 251 | eh=9; |
252 | } | 252 | } |
253 | 253 | ||
254 | start.setTime( QTime( sh, 0, 0 ) ); | 254 | start.setTime( QTime( sh, 0, 0 ) ); |
255 | end.setTime( QTime( eh, 0, 0 ) ); | 255 | end.setTime( QTime( eh, 0, 0 ) ); |
256 | } | 256 | } |
257 | 257 | ||
258 | void DateBookDay::setDate( int y, int m, int d ) | 258 | void DateBookDay::setDate( int y, int m, int d ) |
259 | { | 259 | { |
260 | header->setDate( y, m, d ); | 260 | header->setDate( y, m, d ); |
261 | 261 | ||
262 | selectedWidget = 0; | 262 | selectedWidget = 0; |
263 | } | 263 | } |
264 | 264 | ||
265 | void DateBookDay::setDate( QDate d) | 265 | void DateBookDay::setDate( QDate d) |
266 | { | 266 | { |
267 | header->setDate( d.year(), d.month(), d.day() ); | 267 | header->setDate( d.year(), d.month(), d.day() ); |
268 | 268 | ||
269 | selectedWidget = 0; | 269 | selectedWidget = 0; |
270 | } | 270 | } |
271 | 271 | ||
272 | void DateBookDay::dateChanged( int y, int m, int d ) | 272 | void DateBookDay::dateChanged( int y, int m, int d ) |
273 | { | 273 | { |
274 | QDate date( y, m, d ); | 274 | QDate date( y, m, d ); |
275 | if ( currDate == date ) | 275 | if ( currDate == date ) |
276 | return; | 276 | return; |
277 | currDate.setYMD( y, m, d ); | 277 | currDate.setYMD( y, m, d ); |
278 | relayoutPage(); | 278 | relayoutPage(); |
279 | dayView()->clearSelection(); | 279 | dayView()->clearSelection(); |
280 | QTableSelection ts; | 280 | QTableSelection ts; |
281 | 281 | ||
282 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 282 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
283 | { | 283 | { |
284 | ts.init( QTime::currentTime().hour(), 0); | 284 | ts.init( QTime::currentTime().hour(), 0); |
285 | ts.expandTo( QTime::currentTime().hour(), 0); | 285 | ts.expandTo( QTime::currentTime().hour(), 0); |
286 | } else | 286 | } else |
287 | { | 287 | { |
288 | ts.init( startTime, 0 ); | 288 | ts.init( startTime, 0 ); |
289 | ts.expandTo( startTime, 0 ); | 289 | ts.expandTo( startTime, 0 ); |
290 | } | 290 | } |
291 | 291 | ||
292 | dayView()->addSelection( ts ); | 292 | dayView()->addSelection( ts ); |
293 | 293 | ||
294 | selectedWidget = 0; | 294 | selectedWidget = 0; |
295 | 295 | ||
296 | } | 296 | } |
297 | 297 | ||
298 | void DateBookDay::redraw() | 298 | void DateBookDay::redraw() |
299 | { | 299 | { |
300 | if ( isUpdatesEnabled() ) | 300 | if ( isUpdatesEnabled() ) |
301 | relayoutPage(); | 301 | relayoutPage(); |
302 | } | 302 | } |
303 | 303 | ||
304 | void DateBookDay::getEvents() | 304 | void DateBookDay::getEvents() |
305 | { | 305 | { |
306 | widgetList.clear(); | 306 | widgetList.clear(); |
307 | 307 | ||
308 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); | 308 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); |
309 | QValueListIterator<EffectiveEvent> it; | 309 | QValueListIterator<EffectiveEvent> it; |
310 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { | 310 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { |
311 | EffectiveEvent ev=*it; | 311 | EffectiveEvent ev=*it; |
312 | if(!(ev.end().hour()==ev.start().hour() && ev.end().minute()==ev.start().minute())) {// Skip effective events with no duration. (i.e ending at 00:00) | 312 | if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) {// Skip events ending at 00:00 starting at another day. |
313 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); | 313 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); |
314 | connect( w, SIGNAL( deleteMe( const Event & ) ), | 314 | connect( w, SIGNAL( deleteMe( const Event & ) ), |
315 | this, SIGNAL( removeEvent( const Event & ) ) ); | 315 | this, SIGNAL( removeEvent( const Event & ) ) ); |
316 | connect( w, SIGNAL( duplicateMe( const Event & ) ), | 316 | connect( w, SIGNAL( duplicateMe( const Event & ) ), |
317 | this, SIGNAL( duplicateEvent( const Event & ) ) ); | 317 | this, SIGNAL( duplicateEvent( const Event & ) ) ); |
318 | connect( w, SIGNAL( editMe( const Event & ) ), | 318 | connect( w, SIGNAL( editMe( const Event & ) ), |
319 | this, SIGNAL( editEvent( const Event & ) ) ); | 319 | this, SIGNAL( editEvent( const Event & ) ) ); |
320 | connect( w, SIGNAL( beamMe( const Event & ) ), | 320 | connect( w, SIGNAL( beamMe( const Event & ) ), |
321 | this, SIGNAL( beamEvent( const Event & ) ) ); | 321 | this, SIGNAL( beamEvent( const Event & ) ) ); |
322 | widgetList.append( w ); | 322 | widgetList.append( w ); |
323 | } | 323 | } |
324 | } | 324 | } |
325 | 325 | ||
326 | } | 326 | } |
327 | 327 | ||
328 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) | 328 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) |
329 | { | 329 | { |
330 | int place = 0; | 330 | int place = 0; |
331 | int start = item->event().start().hour(); | 331 | int start = item->event().start().hour(); |
332 | QTime e = item->event().end(); | 332 | QTime e = item->event().end(); |
333 | int end = e.hour(); | 333 | int end = e.hour(); |
334 | if ( e.minute() < 5 ) | 334 | if ( e.minute() < 5 ) |
335 | end--; | 335 | end--; |
336 | if ( end < start ) | 336 | if ( end < start ) |
337 | end = start; | 337 | end = start; |
338 | while ( place < maxn ) { | 338 | while ( place < maxn ) { |
339 | bool free = TRUE; | 339 | bool free = TRUE; |
340 | int s = start; | 340 | int s = start; |
341 | while( s <= end ) { | 341 | while( s <= end ) { |
342 | if ( used[10*s+place] ) { | 342 | if ( used[10*s+place] ) { |
343 | free = FALSE; | 343 | free = FALSE; |
344 | break; | 344 | break; |
345 | } | 345 | } |
346 | s++; | 346 | s++; |
347 | } | 347 | } |
348 | if ( free ) break; | 348 | if ( free ) break; |
349 | place++; | 349 | place++; |
350 | } | 350 | } |
351 | if ( place == maxn ) { | 351 | if ( place == maxn ) { |
352 | return -1; | 352 | return -1; |
353 | } | 353 | } |
354 | while( start <= end ) { | 354 | while( start <= end ) { |
355 | used[10*start+place] = TRUE; | 355 | used[10*start+place] = TRUE; |
356 | start++; | 356 | start++; |
357 | } | 357 | } |
358 | return place; | 358 | return place; |
359 | } | 359 | } |
360 | 360 | ||
361 | 361 | ||
362 | void DateBookDay::relayoutPage( bool fromResize ) | 362 | void DateBookDay::relayoutPage( bool fromResize ) |
363 | { | 363 | { |
364 | setUpdatesEnabled( FALSE ); | 364 | setUpdatesEnabled( FALSE ); |
365 | if ( !fromResize ) | 365 | if ( !fromResize ) |
366 | getEvents(); // no need we already have them! | 366 | getEvents(); // no need we already have them! |
367 | 367 | ||
368 | widgetList.sort(); | 368 | widgetList.sort(); |
369 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning | 369 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning |
370 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view | 370 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view |
371 | 371 | ||
372 | int wCount = widgetList.count(); | 372 | int wCount = widgetList.count(); |
373 | int wid = view->columnWidth(0)-1; | 373 | int wid = view->columnWidth(0)-1; |
374 | int wd; | 374 | int wd; |
375 | int n = 1; | 375 | int n = 1; |
376 | 376 | ||
377 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget | 377 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget |
378 | 378 | ||
379 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); | 379 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); |
380 | 380 | ||
381 | if ( wCount < 20 ) { | 381 | if ( wCount < 20 ) { |
382 | 382 | ||
383 | QArray<QRect> geometries(wCount); | 383 | QArray<QRect> geometries(wCount); |
384 | for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector | 384 | for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector |
385 | 385 | ||
386 | for ( int i = 0; i < wCount; i++) | 386 | for ( int i = 0; i < wCount; i++) |
387 | { | 387 | { |
388 | QValueList<int> intersectedWidgets; | 388 | QValueList<int> intersectedWidgets; |
389 | 389 | ||
390 | //find all widgets intersecting with widgetList.at(i) | 390 | //find all widgets intersecting with widgetList.at(i) |
391 | for ( int j = 0; j < wCount; j++) | 391 | for ( int j = 0; j < wCount; j++) |
392 | if (i != j) | 392 | if (i != j) |
393 | if (geometries[j].intersects(geometries[i])) | 393 | if (geometries[j].intersects(geometries[i])) |
394 | intersectedWidgets.append(j); | 394 | intersectedWidgets.append(j); |
395 | 395 | ||
396 | //for each of these intersecting widgets find out how many widgets are they intersecting with | 396 | //for each of these intersecting widgets find out how many widgets are they intersecting with |
397 | for ( uint j = 0; j < intersectedWidgets.count(); j++) | 397 | for ( uint j = 0; j < intersectedWidgets.count(); j++) |
398 | { | 398 | { |
399 | QArray<int> inter(wCount); | 399 | QArray<int> inter(wCount); |
400 | inter[j]=1; | 400 | inter[j]=1; |
401 | 401 | ||
402 | if (intersectedWidgets[j] != -1) | 402 | if (intersectedWidgets[j] != -1) |
403 | for ( uint k = j; k < intersectedWidgets.count(); k++) | 403 | for ( uint k = j; k < intersectedWidgets.count(); k++) |
404 | if (j != k && intersectedWidgets[k] != -1) | 404 | if (j != k && intersectedWidgets[k] != -1) |
405 | if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) | 405 | if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) |
406 | { | 406 | { |
407 | inter[j]++; | 407 | inter[j]++; |
408 | intersectedWidgets[k] = -1; | 408 | intersectedWidgets[k] = -1; |
409 | } | 409 | } |
410 | if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; | 410 | if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; |
411 | } | 411 | } |
412 | 412 | ||
413 | if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; | 413 | if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; |
414 | } | 414 | } |
415 | 415 | ||
416 | 416 | ||
417 | for ( int i = 0; i < wCount; i++) { | 417 | for ( int i = 0; i < wCount; i++) { |
418 | DateBookDayWidget *w = widgetList.at(i); | 418 | DateBookDayWidget *w = widgetList.at(i); |
419 | QRect geom = w->geometry(); | 419 | QRect geom = w->geometry(); |
420 | 420 | ||
421 | geom.setX( 0 ); | 421 | geom.setX( 0 ); |
422 | 422 | ||
423 | wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); | 423 | wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); |
424 | 424 | ||
425 | geom.setWidth( wd ); | 425 | geom.setWidth( wd ); |
426 | 426 | ||
427 | while ( intersects( w, geom ) ) { | 427 | while ( intersects( w, geom ) ) { |
428 | geom.moveBy( wd + 2 + 1, 0 ); | 428 | geom.moveBy( wd + 2 + 1, 0 ); |
429 | } | 429 | } |
430 | w->setGeometry( geom ); | 430 | w->setGeometry( geom ); |
431 | } | 431 | } |
432 | 432 | ||
433 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 433 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
434 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour | 434 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour |
435 | else | 435 | else |
436 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); | 436 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); |
437 | 437 | ||
438 | 438 | ||
439 | } else { | 439 | } else { |
440 | 440 | ||
441 | 441 | ||
442 | int hours[24]; | 442 | int hours[24]; |
443 | memset( hours, 0, 24*sizeof( int ) ); | 443 | memset( hours, 0, 24*sizeof( int ) ); |
444 | bool overFlow = FALSE; | 444 | bool overFlow = FALSE; |
445 | for ( int i = 0; i < wCount; i++ ) { | 445 | for ( int i = 0; i < wCount; i++ ) { |
446 | DateBookDayWidget *w = widgetList.at(i); | 446 | DateBookDayWidget *w = widgetList.at(i); |
447 | int start = w->event().start().hour(); | 447 | int start = w->event().start().hour(); |
448 | QTime e = w->event().end(); | 448 | QTime e = w->event().end(); |
449 | int end = e.hour(); | 449 | int end = e.hour(); |
450 | if ( e.minute() < 5 ) | 450 | if ( e.minute() < 5 ) |
451 | end--; | 451 | end--; |
452 | if ( end < start ) | 452 | if ( end < start ) |
453 | end = start; | 453 | end = start; |
454 | while( start <= end ) { | 454 | while( start <= end ) { |
455 | hours[start]++; | 455 | hours[start]++; |
456 | if ( hours[start] >= 10 ) | 456 | if ( hours[start] >= 10 ) |
457 | overFlow = TRUE; | 457 | overFlow = TRUE; |
458 | ++start; | 458 | ++start; |
459 | } | 459 | } |
460 | if ( overFlow ) | 460 | if ( overFlow ) |
461 | break; | 461 | break; |
462 | } | 462 | } |
463 | for ( int i = 0; i < 24; i++ ) { | 463 | for ( int i = 0; i < 24; i++ ) { |
464 | n = QMAX( n, hours[i] ); | 464 | n = QMAX( n, hours[i] ); |
465 | } | 465 | } |
466 | wid = ( view->columnWidth(0)-1 ) / n; | 466 | wid = ( view->columnWidth(0)-1 ) / n; |
467 | 467 | ||
468 | bool used[24*10]; | 468 | bool used[24*10]; |
469 | memset( used, FALSE, 24*10*sizeof( bool ) ); | 469 | memset( used, FALSE, 24*10*sizeof( bool ) ); |
470 | 470 | ||
471 | for ( int i = 0; i < wCount; i++ ) { | 471 | for ( int i = 0; i < wCount; i++ ) { |
472 | DateBookDayWidget *w = widgetList.at(i); | 472 | DateBookDayWidget *w = widgetList.at(i); |
473 | int xp = place( w, used, n ); | 473 | int xp = place( w, used, n ); |
474 | if ( xp != -1 ) { | 474 | if ( xp != -1 ) { |
475 | QRect geom = w->geometry(); | 475 | QRect geom = w->geometry(); |
476 | geom.setX( xp*(wid+2) ); | 476 | geom.setX( xp*(wid+2) ); |
477 | geom.setWidth( wid ); | 477 | geom.setWidth( wid ); |
478 | w->setGeometry( geom ); | 478 | w->setGeometry( geom ); |
479 | } | 479 | } |
480 | } | 480 | } |
481 | 481 | ||
482 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 482 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
483 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour | 483 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour |
484 | else | 484 | else |
485 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); | 485 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); |
486 | } | 486 | } |
487 | 487 | ||
488 | timeMarker->setTime( QTime::currentTime() );//display timeMarker | 488 | timeMarker->setTime( QTime::currentTime() );//display timeMarker |
489 | timeMarker->raise(); //on top of all widgets | 489 | timeMarker->raise(); //on top of all widgets |
490 | if (this->date() == QDate::currentDate()) //only show timeMarker on current day | 490 | if (this->date() == QDate::currentDate()) //only show timeMarker on current day |
491 | timeMarker->show(); else timeMarker->hide(); | 491 | timeMarker->show(); else timeMarker->hide(); |
492 | 492 | ||
493 | setUpdatesEnabled( TRUE ); | 493 | setUpdatesEnabled( TRUE ); |
494 | return; | 494 | return; |
495 | } | 495 | } |
496 | 496 | ||
497 | DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) | 497 | DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) |
498 | { | 498 | { |
499 | int i = 0; | 499 | int i = 0; |
500 | DateBookDayWidget *w = widgetList.at(i); | 500 | DateBookDayWidget *w = widgetList.at(i); |
501 | int wCount = widgetList.count(); | 501 | int wCount = widgetList.count(); |
502 | while ( i < wCount && w != item ) { | 502 | while ( i < wCount && w != item ) { |
503 | if ( w->geometry().intersects( geom ) ) { | 503 | if ( w->geometry().intersects( geom ) ) { |
504 | return w; | 504 | return w; |
505 | } | 505 | } |
506 | w = widgetList.at(++i); | 506 | w = widgetList.at(++i); |
507 | } | 507 | } |
508 | 508 | ||
509 | return 0; | 509 | return 0; |
510 | } | 510 | } |
511 | 511 | ||
512 | 512 | ||
513 | QDate DateBookDay::date() const | 513 | QDate DateBookDay::date() const |
514 | { | 514 | { |
515 | return currDate; | 515 | return currDate; |
516 | } | 516 | } |
517 | 517 | ||
518 | void DateBookDay::setStartViewTime( int startHere ) | 518 | void DateBookDay::setStartViewTime( int startHere ) |
519 | { | 519 | { |
520 | startTime = startHere; | 520 | startTime = startHere; |
521 | dayView()->clearSelection(); | 521 | dayView()->clearSelection(); |
522 | QTableSelection ts; | 522 | QTableSelection ts; |
523 | 523 | ||
524 | if (jumpToCurTime && this->date() == QDate::currentDate())//this should probably be in datebook.cpp where it's called? | 524 | if (jumpToCurTime && this->date() == QDate::currentDate())//this should probably be in datebook.cpp where it's called? |
525 | { | 525 | { |
526 | ts.init( QTime::currentTime().hour(), 0); | 526 | ts.init( QTime::currentTime().hour(), 0); |
527 | ts.expandTo( QTime::currentTime().hour(), 0); | 527 | ts.expandTo( QTime::currentTime().hour(), 0); |
528 | } else | 528 | } else |
529 | { | 529 | { |
530 | ts.init( startTime, 0 ); | 530 | ts.init( startTime, 0 ); |
531 | ts.expandTo( startTime, 0 ); | 531 | ts.expandTo( startTime, 0 ); |
532 | } | 532 | } |
533 | 533 | ||
534 | dayView()->addSelection( ts ); | 534 | dayView()->addSelection( ts ); |
535 | } | 535 | } |
536 | 536 | ||
537 | int DateBookDay::startViewTime() const | 537 | int DateBookDay::startViewTime() const |
538 | { | 538 | { |
539 | return startTime; | 539 | return startTime; |
540 | } | 540 | } |
541 | 541 | ||
542 | void DateBookDay::slotWeekChanged( bool bStartOnMonday ) | 542 | void DateBookDay::slotWeekChanged( bool bStartOnMonday ) |
543 | { | 543 | { |
544 | header->setStartOfWeek( bStartOnMonday ); | 544 | header->setStartOfWeek( bStartOnMonday ); |
545 | // redraw(); | 545 | // redraw(); |
546 | } | 546 | } |
547 | 547 | ||
548 | void DateBookDay::keyPressEvent(QKeyEvent *e) | 548 | void DateBookDay::keyPressEvent(QKeyEvent *e) |
549 | { | 549 | { |
550 | switch(e->key()) { | 550 | switch(e->key()) { |
551 | case Key_Up: | 551 | case Key_Up: |
552 | view->moveUp(); | 552 | view->moveUp(); |
553 | break; | 553 | break; |
554 | case Key_Down: | 554 | case Key_Down: |
555 | view->moveDown(); | 555 | view->moveDown(); |
556 | break; | 556 | break; |
557 | case Key_Left: | 557 | case Key_Left: |
558 | setDate(QDate(currDate).addDays(-1)); | 558 | setDate(QDate(currDate).addDays(-1)); |
559 | break; | 559 | break; |
560 | case Key_Right: | 560 | case Key_Right: |
561 | setDate(QDate(currDate).addDays(1)); | 561 | setDate(QDate(currDate).addDays(1)); |
562 | break; | 562 | break; |
563 | default: | 563 | default: |
564 | e->ignore(); | 564 | e->ignore(); |
565 | } | 565 | } |
566 | } | 566 | } |
567 | 567 | ||
568 | //=========================================================================== | 568 | //=========================================================================== |
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index 5bbf86a..874cf24 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp | |||
@@ -1,398 +1,398 @@ | |||
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/calendar.h> | 23 | #include <qpe/calendar.h> |
24 | #include <qpe/datebookdb.h> | 24 | #include <qpe/datebookdb.h> |
25 | #include <qpe/event.h> | 25 | #include <qpe/event.h> |
26 | #include <qpe/qpeapplication.h> | 26 | #include <qpe/qpeapplication.h> |
27 | #include <qpe/timestring.h> | 27 | #include <qpe/timestring.h> |
28 | 28 | ||
29 | #include <qdatetime.h> | 29 | #include <qdatetime.h> |
30 | #include <qheader.h> | 30 | #include <qheader.h> |
31 | #include <qlabel.h> | 31 | #include <qlabel.h> |
32 | #include <qlayout.h> | 32 | #include <qlayout.h> |
33 | #include <qpainter.h> | 33 | #include <qpainter.h> |
34 | #include <qpopupmenu.h> | 34 | #include <qpopupmenu.h> |
35 | #include <qtimer.h> | 35 | #include <qtimer.h> |
36 | #include <qspinbox.h> | 36 | #include <qspinbox.h> |
37 | #include <qstyle.h> | 37 | #include <qstyle.h> |
38 | 38 | ||
39 | //----------------------------------------------------------------- | 39 | //----------------------------------------------------------------- |
40 | 40 | ||
41 | 41 | ||
42 | DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) | 42 | DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) |
43 | : ev( e ) | 43 | : ev( e ) |
44 | { | 44 | { |
45 | // with the current implementation change the color for all day events | 45 | // with the current implementation change the color for all day events |
46 | if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { | 46 | if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { |
47 | c = Qt::green; | 47 | c = Qt::green; |
48 | } else { | 48 | } else { |
49 | c = ev.event().hasAlarm() ? Qt::red : Qt::blue; | 49 | c = ev.event().hasAlarm() ? Qt::red : Qt::blue; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | void DateBookWeekItem::setGeometry( int x, int y, int w, int h ) | 53 | void DateBookWeekItem::setGeometry( int x, int y, int w, int h ) |
54 | { | 54 | { |
55 | r.setRect( x, y, w, h ); | 55 | r.setRect( x, y, w, h ); |
56 | } | 56 | } |
57 | 57 | ||
58 | 58 | ||
59 | //------------------=--------------------------------------------- | 59 | //------------------=--------------------------------------------- |
60 | 60 | ||
61 | DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, | 61 | DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, |
62 | QWidget *parent, const char *name ) | 62 | QWidget *parent, const char *name ) |
63 | : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), | 63 | : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), |
64 | showingEvent( false ) | 64 | showingEvent( false ) |
65 | { | 65 | { |
66 | items.setAutoDelete( true ); | 66 | items.setAutoDelete( true ); |
67 | 67 | ||
68 | viewport()->setBackgroundMode( PaletteBase ); | 68 | viewport()->setBackgroundMode( PaletteBase ); |
69 | 69 | ||
70 | header = new QHeader( this ); | 70 | header = new QHeader( this ); |
71 | header->addLabel( "" ); | 71 | header->addLabel( "" ); |
72 | 72 | ||
73 | header->setMovingEnabled( false ); | 73 | header->setMovingEnabled( false ); |
74 | header->setResizeEnabled( false ); | 74 | header->setResizeEnabled( false ); |
75 | header->setClickEnabled( false, 0 ); | 75 | header->setClickEnabled( false, 0 ); |
76 | initNames(); | 76 | initNames(); |
77 | 77 | ||
78 | 78 | ||
79 | connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); | 79 | connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); |
80 | 80 | ||
81 | QObject::connect(qApp, SIGNAL(clockChanged(bool)), | 81 | QObject::connect(qApp, SIGNAL(clockChanged(bool)), |
82 | this, SLOT(slotChangeClock(bool))); | 82 | this, SLOT(slotChangeClock(bool))); |
83 | 83 | ||
84 | QFontMetrics fm( font() ); | 84 | QFontMetrics fm( font() ); |
85 | rowHeight = fm.height()+2; | 85 | rowHeight = fm.height()+2; |
86 | 86 | ||
87 | resizeContents( width(), 24*rowHeight ); | 87 | resizeContents( width(), 24*rowHeight ); |
88 | } | 88 | } |
89 | 89 | ||
90 | void DateBookWeekView::initNames() | 90 | void DateBookWeekView::initNames() |
91 | { | 91 | { |
92 | static bool bFirst = true; | 92 | static bool bFirst = true; |
93 | if ( bFirst ) { | 93 | if ( bFirst ) { |
94 | if ( bOnMonday ) { | 94 | if ( bOnMonday ) { |
95 | header->addLabel( tr("M", "Monday" ) ); | 95 | header->addLabel( tr("M", "Monday" ) ); |
96 | header->addLabel( tr("T", "Tuesday") ); | 96 | header->addLabel( tr("T", "Tuesday") ); |
97 | header->addLabel( tr("W", "Wednesday" ) ); | 97 | header->addLabel( tr("W", "Wednesday" ) ); |
98 | header->addLabel( tr("T", "Thursday" ) ); | 98 | header->addLabel( tr("T", "Thursday" ) ); |
99 | header->addLabel( tr("F", "Friday" ) ); | 99 | header->addLabel( tr("F", "Friday" ) ); |
100 | header->addLabel( tr("S", "Saturday" ) ); | 100 | header->addLabel( tr("S", "Saturday" ) ); |
101 | header->addLabel( tr("S", "Sunday" ) ); | 101 | header->addLabel( tr("S", "Sunday" ) ); |
102 | } else { | 102 | } else { |
103 | header->addLabel( tr("S", "Sunday" ) ); | 103 | header->addLabel( tr("S", "Sunday" ) ); |
104 | header->addLabel( tr("M", "Monday") ); | 104 | header->addLabel( tr("M", "Monday") ); |
105 | header->addLabel( tr("T", "Tuesday") ); | 105 | header->addLabel( tr("T", "Tuesday") ); |
106 | header->addLabel( tr("W", "Wednesday" ) ); | 106 | header->addLabel( tr("W", "Wednesday" ) ); |
107 | header->addLabel( tr("T", "Thursday" ) ); | 107 | header->addLabel( tr("T", "Thursday" ) ); |
108 | header->addLabel( tr("F", "Friday" ) ); | 108 | header->addLabel( tr("F", "Friday" ) ); |
109 | header->addLabel( tr("S", "Saturday" ) ); | 109 | header->addLabel( tr("S", "Saturday" ) ); |
110 | } | 110 | } |
111 | bFirst = false; | 111 | bFirst = false; |
112 | } else { | 112 | } else { |
113 | // we are change things... | 113 | // we are change things... |
114 | if ( bOnMonday ) { | 114 | if ( bOnMonday ) { |
115 | header->setLabel( 1, tr("M", "Monday") ); | 115 | header->setLabel( 1, tr("M", "Monday") ); |
116 | header->setLabel( 2, tr("T", "Tuesday") ); | 116 | header->setLabel( 2, tr("T", "Tuesday") ); |
117 | header->setLabel( 3, tr("W", "Wednesday" ) ); | 117 | header->setLabel( 3, tr("W", "Wednesday" ) ); |
118 | header->setLabel( 4, tr("T", "Thursday" ) ); | 118 | header->setLabel( 4, tr("T", "Thursday" ) ); |
119 | header->setLabel( 5, tr("F", "Friday" ) ); | 119 | header->setLabel( 5, tr("F", "Friday" ) ); |
120 | header->setLabel( 6, tr("S", "Saturday" ) ); | 120 | header->setLabel( 6, tr("S", "Saturday" ) ); |
121 | header->setLabel( 7, tr("S", "Sunday" ) ); | 121 | header->setLabel( 7, tr("S", "Sunday" ) ); |
122 | } else { | 122 | } else { |
123 | header->setLabel( 1, tr("S", "Sunday" ) ); | 123 | header->setLabel( 1, tr("S", "Sunday" ) ); |
124 | header->setLabel( 2, tr("M", "Monday") ); | 124 | header->setLabel( 2, tr("M", "Monday") ); |
125 | header->setLabel( 3, tr("T", "Tuesday") ); | 125 | header->setLabel( 3, tr("T", "Tuesday") ); |
126 | header->setLabel( 4, tr("W", "Wednesday" ) ); | 126 | header->setLabel( 4, tr("W", "Wednesday" ) ); |
127 | header->setLabel( 5, tr("T", "Thursday" ) ); | 127 | header->setLabel( 5, tr("T", "Thursday" ) ); |
128 | header->setLabel( 6, tr("F", "Friday" ) ); | 128 | header->setLabel( 6, tr("F", "Friday" ) ); |
129 | header->setLabel( 7, tr("S", "Saturday" ) ); | 129 | header->setLabel( 7, tr("S", "Saturday" ) ); |
130 | } | 130 | } |
131 | } | 131 | } |
132 | } | 132 | } |
133 | 133 | ||
134 | 134 | ||
135 | 135 | ||
136 | void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) | 136 | void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) |
137 | { | 137 | { |
138 | items.clear(); | 138 | items.clear(); |
139 | QValueListIterator<EffectiveEvent> it; | 139 | QValueListIterator<EffectiveEvent> it; |
140 | for ( it = ev.begin(); it != ev.end(); ++it ) { | 140 | for ( it = ev.begin(); it != ev.end(); ++it ) { |
141 | DateBookWeekItem *i = new DateBookWeekItem( *it ); | 141 | DateBookWeekItem *i = new DateBookWeekItem( *it ); |
142 | if(!(i->event().end().hour()==i->event().start().hour() && i->event().end().minute()==i->event().start().minute())) {// Skip effective events with no duration. (i.e ending at 00:00) | 142 | 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. |
143 | positionItem( i ); | 143 | positionItem( i ); |
144 | items.append( i ); | 144 | items.append( i ); |
145 | } | 145 | } |
146 | } | 146 | } |
147 | viewport()->update(); | 147 | viewport()->update(); |
148 | } | 148 | } |
149 | 149 | ||
150 | void DateBookWeekView::moveToHour( int h ) | 150 | void DateBookWeekView::moveToHour( int h ) |
151 | { | 151 | { |
152 | int offset = h*rowHeight; | 152 | int offset = h*rowHeight; |
153 | setContentsPos( 0, offset ); | 153 | setContentsPos( 0, offset ); |
154 | } | 154 | } |
155 | 155 | ||
156 | void DateBookWeekView::keyPressEvent( QKeyEvent *e ) | 156 | void DateBookWeekView::keyPressEvent( QKeyEvent *e ) |
157 | { | 157 | { |
158 | e->ignore(); | 158 | e->ignore(); |
159 | } | 159 | } |
160 | 160 | ||
161 | void DateBookWeekView::slotChangeClock( bool c ) | 161 | void DateBookWeekView::slotChangeClock( bool c ) |
162 | { | 162 | { |
163 | ampm = c; | 163 | ampm = c; |
164 | viewport()->update(); | 164 | viewport()->update(); |
165 | } | 165 | } |
166 | 166 | ||
167 | static inline int db_round30min( int m ) | 167 | static inline int db_round30min( int m ) |
168 | { | 168 | { |
169 | if ( m < 15 ) | 169 | if ( m < 15 ) |
170 | m = 0; | 170 | m = 0; |
171 | else if ( m < 45 ) | 171 | else if ( m < 45 ) |
172 | m = 1; | 172 | m = 1; |
173 | else | 173 | else |
174 | m = 2; | 174 | m = 2; |
175 | 175 | ||
176 | return m; | 176 | return m; |
177 | } | 177 | } |
178 | 178 | ||
179 | void DateBookWeekView::alterDay( int day ) | 179 | void DateBookWeekView::alterDay( int day ) |
180 | { | 180 | { |
181 | if ( !bOnMonday ) { | 181 | if ( !bOnMonday ) { |
182 | day--; | 182 | day--; |
183 | } | 183 | } |
184 | emit showDay( day ); | 184 | emit showDay( day ); |
185 | } | 185 | } |
186 | 186 | ||
187 | void DateBookWeekView::positionItem( DateBookWeekItem *i ) | 187 | void DateBookWeekView::positionItem( DateBookWeekItem *i ) |
188 | { | 188 | { |
189 | const int Width = 8; | 189 | const int Width = 8; |
190 | const EffectiveEvent ev = i->event(); | 190 | const EffectiveEvent ev = i->event(); |
191 | 191 | ||
192 | // 30 minute intervals | 192 | // 30 minute intervals |
193 | int y = ev.start().hour() * 2; | 193 | int y = ev.start().hour() * 2; |
194 | y += db_round30min( ev.start().minute() ); | 194 | y += db_round30min( ev.start().minute() ); |
195 | int y2 = ev.end().hour() * 2; | 195 | int y2 = ev.end().hour() * 2; |
196 | y2 += db_round30min( ev.end().minute() ); | 196 | y2 += db_round30min( ev.end().minute() ); |
197 | if ( y > 47 ) | 197 | if ( y > 47 ) |
198 | y = 47; | 198 | y = 47; |
199 | if ( y2 > 48 ) | 199 | if ( y2 > 48 ) |
200 | y2 = 48; | 200 | y2 = 48; |
201 | y = y * rowHeight / 2; | 201 | y = y * rowHeight / 2; |
202 | y2 = y2 * rowHeight / 2; | 202 | y2 = y2 * rowHeight / 2; |
203 | 203 | ||
204 | int h; | 204 | int h; |
205 | if ( ev.event().type() == Event::AllDay ) { | 205 | if ( ev.event().type() == Event::AllDay ) { |
206 | h = 48 * rowHeight / 2; | 206 | h = 48 * rowHeight / 2; |
207 | y = 0; | 207 | y = 0; |
208 | } else { | 208 | } else { |
209 | h=y2-y; | 209 | h=y2-y; |
210 | if ( h < 1 ) h = 1; | 210 | if ( h < 1 ) h = 1; |
211 | } | 211 | } |
212 | 212 | ||
213 | int dow = ev.date().dayOfWeek(); | 213 | int dow = ev.date().dayOfWeek(); |
214 | if ( !bOnMonday ) { | 214 | if ( !bOnMonday ) { |
215 | if ( dow == 7 ) | 215 | if ( dow == 7 ) |
216 | dow = 1; | 216 | dow = 1; |
217 | else | 217 | else |
218 | dow++; | 218 | dow++; |
219 | } | 219 | } |
220 | int x = header->sectionPos( dow ) - 1; | 220 | int x = header->sectionPos( dow ) - 1; |
221 | int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); | 221 | int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); |
222 | DateBookWeekItem *isect = 0; | 222 | DateBookWeekItem *isect = 0; |
223 | do { | 223 | do { |
224 | i->setGeometry( x, y, Width, h ); | 224 | i->setGeometry( x, y, Width, h ); |
225 | isect = intersects( i ); | 225 | isect = intersects( i ); |
226 | x += Width - 1; | 226 | x += Width - 1; |
227 | } while ( isect && x < xlim ); | 227 | } while ( isect && x < xlim ); |
228 | } | 228 | } |
229 | 229 | ||
230 | DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) | 230 | DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) |
231 | { | 231 | { |
232 | QRect geom = item->geometry(); | 232 | QRect geom = item->geometry(); |
233 | 233 | ||
234 | // We allow the edges to overlap | 234 | // We allow the edges to overlap |
235 | geom.moveBy( 1, 1 ); | 235 | geom.moveBy( 1, 1 ); |
236 | geom.setSize( geom.size()-QSize(2,2) ); | 236 | geom.setSize( geom.size()-QSize(2,2) ); |
237 | 237 | ||
238 | QListIterator<DateBookWeekItem> it(items); | 238 | QListIterator<DateBookWeekItem> it(items); |
239 | for ( ; it.current(); ++it ) { | 239 | for ( ; it.current(); ++it ) { |
240 | DateBookWeekItem *i = it.current(); | 240 | DateBookWeekItem *i = it.current(); |
241 | if ( i != item ) { | 241 | if ( i != item ) { |
242 | if ( i->geometry().intersects( geom ) ) { | 242 | if ( i->geometry().intersects( geom ) ) { |
243 | return i; | 243 | return i; |
244 | } | 244 | } |
245 | } | 245 | } |
246 | } | 246 | } |
247 | 247 | ||
248 | return 0; | 248 | return 0; |
249 | } | 249 | } |
250 | 250 | ||
251 | void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) | 251 | void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) |
252 | { | 252 | { |
253 | QListIterator<DateBookWeekItem> it(items); | 253 | QListIterator<DateBookWeekItem> it(items); |
254 | for ( ; it.current(); ++it ) { | 254 | for ( ; it.current(); ++it ) { |
255 | DateBookWeekItem *i = it.current(); | 255 | DateBookWeekItem *i = it.current(); |
256 | if ( i->geometry().contains( e->pos() ) ) { | 256 | if ( i->geometry().contains( e->pos() ) ) { |
257 | showingEvent = true; | 257 | showingEvent = true; |
258 | emit signalShowEvent( i->event() ); | 258 | emit signalShowEvent( i->event() ); |
259 | break; | 259 | break; |
260 | } | 260 | } |
261 | } | 261 | } |
262 | } | 262 | } |
263 | 263 | ||
264 | void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) | 264 | void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) |
265 | { | 265 | { |
266 | if ( showingEvent ) { | 266 | if ( showingEvent ) { |
267 | showingEvent = false; | 267 | showingEvent = false; |
268 | emit signalHideEvent(); | 268 | emit signalHideEvent(); |
269 | } else { | 269 | } else { |
270 | int d = header->sectionAt( e->pos().x() ); | 270 | int d = header->sectionAt( e->pos().x() ); |
271 | if ( d > 0 ) { | 271 | if ( d > 0 ) { |
272 | // if ( !bOnMonday ) | 272 | // if ( !bOnMonday ) |
273 | // d--; | 273 | // d--; |
274 | emit showDay( d ); | 274 | emit showDay( d ); |
275 | } | 275 | } |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) | 279 | void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) |
280 | { | 280 | { |
281 | QRect ur( cx, cy, cw, ch ); | 281 | QRect ur( cx, cy, cw, ch ); |
282 | p->setPen( lightGray ); | 282 | p->setPen( lightGray ); |
283 | for ( int i = 1; i <= 7; i++ ) | 283 | for ( int i = 1; i <= 7; i++ ) |
284 | p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); | 284 | p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); |
285 | 285 | ||
286 | p->setPen( black ); | 286 | p->setPen( black ); |
287 | for ( int t = 0; t < 24; t++ ) { | 287 | for ( int t = 0; t < 24; t++ ) { |
288 | int y = t*rowHeight; | 288 | int y = t*rowHeight; |
289 | if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { | 289 | if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { |
290 | QString s; | 290 | QString s; |
291 | if ( ampm ) { | 291 | if ( ampm ) { |
292 | if ( t == 0 ) | 292 | if ( t == 0 ) |
293 | s = QString::number( 12 ); | 293 | s = QString::number( 12 ); |
294 | else if ( t == 12 ) | 294 | else if ( t == 12 ) |
295 | s = QString::number(12) + tr( "p" ); | 295 | s = QString::number(12) + tr( "p" ); |
296 | else if ( t > 12 ) { | 296 | else if ( t > 12 ) { |
297 | if ( t - 12 < 10 ) | 297 | if ( t - 12 < 10 ) |
298 | s = " "; | 298 | s = " "; |
299 | else | 299 | else |
300 | s = ""; | 300 | s = ""; |
301 | s += QString::number( t - 12 ) + tr("p"); | 301 | s += QString::number( t - 12 ) + tr("p"); |
302 | } else { | 302 | } else { |
303 | if ( 12 - t < 3 ) | 303 | if ( 12 - t < 3 ) |
304 | s = ""; | 304 | s = ""; |
305 | else | 305 | else |
306 | s = " "; | 306 | s = " "; |
307 | s += QString::number( t ); | 307 | s += QString::number( t ); |
308 | } | 308 | } |
309 | } else { | 309 | } else { |
310 | s = QString::number( t ); | 310 | s = QString::number( t ); |
311 | if ( s.length() == 1 ) | 311 | if ( s.length() == 1 ) |
312 | s.prepend( "0" ); | 312 | s.prepend( "0" ); |
313 | } | 313 | } |
314 | p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); | 314 | p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); |
315 | } | 315 | } |
316 | } | 316 | } |
317 | 317 | ||
318 | QListIterator<DateBookWeekItem> it(items); | 318 | QListIterator<DateBookWeekItem> it(items); |
319 | for ( ; it.current(); ++it ) { | 319 | for ( ; it.current(); ++it ) { |
320 | DateBookWeekItem *i = it.current(); | 320 | DateBookWeekItem *i = it.current(); |
321 | if ( i->geometry().intersects( ur ) ) { | 321 | if ( i->geometry().intersects( ur ) ) { |
322 | p->setBrush( i->color() ); | 322 | p->setBrush( i->color() ); |
323 | p->drawRect( i->geometry() ); | 323 | p->drawRect( i->geometry() ); |
324 | } | 324 | } |
325 | } | 325 | } |
326 | } | 326 | } |
327 | 327 | ||
328 | void DateBookWeekView::resizeEvent( QResizeEvent *e ) | 328 | void DateBookWeekView::resizeEvent( QResizeEvent *e ) |
329 | { | 329 | { |
330 | const int hourWidth = 20; | 330 | const int hourWidth = 20; |
331 | QScrollView::resizeEvent( e ); | 331 | QScrollView::resizeEvent( e ); |
332 | int avail = width()-qApp->style().scrollBarExtent().width()-1; | 332 | int avail = width()-qApp->style().scrollBarExtent().width()-1; |
333 | header->setGeometry( 0, 0, avail, header->sizeHint().height() ); | 333 | header->setGeometry( 0, 0, avail, header->sizeHint().height() ); |
334 | setMargins( 0, header->height(), 0, 0 ); | 334 | setMargins( 0, header->height(), 0, 0 ); |
335 | header->resizeSection( 0, hourWidth ); | 335 | header->resizeSection( 0, hourWidth ); |
336 | int sw = (avail - hourWidth) / 7; | 336 | int sw = (avail - hourWidth) / 7; |
337 | for ( int i = 1; i < 7; i++ ) | 337 | for ( int i = 1; i < 7; i++ ) |
338 | header->resizeSection( i, sw ); | 338 | header->resizeSection( i, sw ); |
339 | header->resizeSection( 7, avail - hourWidth - sw*6 ); | 339 | header->resizeSection( 7, avail - hourWidth - sw*6 ); |
340 | } | 340 | } |
341 | 341 | ||
342 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) | 342 | void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) |
343 | { | 343 | { |
344 | bOnMonday = bStartOnMonday; | 344 | bOnMonday = bStartOnMonday; |
345 | initNames(); | 345 | initNames(); |
346 | } | 346 | } |
347 | 347 | ||
348 | //------------------------------------------------------------------- | 348 | //------------------------------------------------------------------- |
349 | 349 | ||
350 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, | 350 | DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, |
351 | QWidget *parent, const char *name ) | 351 | QWidget *parent, const char *name ) |
352 | : QWidget( parent, name ), | 352 | : QWidget( parent, name ), |
353 | db( newDB ), | 353 | db( newDB ), |
354 | startTime( 0 ), | 354 | startTime( 0 ), |
355 | ampm( ap ), | 355 | ampm( ap ), |
356 | bStartOnMonday( startOnMonday ) | 356 | bStartOnMonday( startOnMonday ) |
357 | { | 357 | { |
358 | setFocusPolicy(StrongFocus); | 358 | setFocusPolicy(StrongFocus); |
359 | QVBoxLayout *vb = new QVBoxLayout( this ); | 359 | QVBoxLayout *vb = new QVBoxLayout( this ); |
360 | header = new DateBookWeekHeader( bStartOnMonday, this ); | 360 | header = new DateBookWeekHeader( bStartOnMonday, this ); |
361 | view = new DateBookWeekView( ampm, startOnMonday, this ); | 361 | view = new DateBookWeekView( ampm, startOnMonday, this ); |
362 | vb->addWidget( header ); | 362 | vb->addWidget( header ); |
363 | vb->addWidget( view ); | 363 | vb->addWidget( view ); |
364 | 364 | ||
365 | lblDesc = new QLabel( this, "event label" ); | 365 | lblDesc = new QLabel( this, "event label" ); |
366 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); | 366 | lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); |
367 | lblDesc->setBackgroundColor( yellow ); | 367 | lblDesc->setBackgroundColor( yellow ); |
368 | lblDesc->hide(); | 368 | lblDesc->hide(); |
369 | 369 | ||
370 | tHide = new QTimer( this ); | 370 | tHide = new QTimer( this ); |
371 | 371 | ||
372 | connect( view, SIGNAL( showDay( int ) ), | 372 | connect( view, SIGNAL( showDay( int ) ), |
373 | this, SLOT( showDay( int ) ) ); | 373 | this, SLOT( showDay( int ) ) ); |
374 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), | 374 | connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), |
375 | this, SLOT(slotShowEvent(const EffectiveEvent&)) ); | 375 | this, SLOT(slotShowEvent(const EffectiveEvent&)) ); |
376 | connect( view, SIGNAL(signalHideEvent()), | 376 | connect( view, SIGNAL(signalHideEvent()), |
377 | this, SLOT(slotHideEvent()) ); | 377 | this, SLOT(slotHideEvent()) ); |
378 | connect( header, SIGNAL( dateChanged( int, int ) ), | 378 | connect( header, SIGNAL( dateChanged( int, int ) ), |
379 | this, SLOT( dateChanged( int, int ) ) ); | 379 | this, SLOT( dateChanged( int, int ) ) ); |
380 | connect( tHide, SIGNAL( timeout() ), | 380 | connect( tHide, SIGNAL( timeout() ), |
381 | lblDesc, SLOT( hide() ) ); | 381 | lblDesc, SLOT( hide() ) ); |
382 | connect( header->spinYear, SIGNAL(valueChanged(int)), | 382 | connect( header->spinYear, SIGNAL(valueChanged(int)), |
383 | this, SLOT(slotYearChanged(int)) ); | 383 | this, SLOT(slotYearChanged(int)) ); |
384 | connect( qApp, SIGNAL(weekChanged(bool)), | 384 | connect( qApp, SIGNAL(weekChanged(bool)), |
385 | this, SLOT(slotWeekChanged(bool)) ); | 385 | this, SLOT(slotWeekChanged(bool)) ); |
386 | connect( qApp, SIGNAL(clockChanged(bool)), | 386 | connect( qApp, SIGNAL(clockChanged(bool)), |
387 | this, SLOT(slotClockChanged(bool))); | 387 | this, SLOT(slotClockChanged(bool))); |
388 | setDate(QDate::currentDate()); | 388 | setDate(QDate::currentDate()); |
389 | 389 | ||
390 | } | 390 | } |
391 | 391 | ||
392 | void DateBookWeek::keyPressEvent(QKeyEvent *e) | 392 | void DateBookWeek::keyPressEvent(QKeyEvent *e) |
393 | { | 393 | { |
394 | switch(e->key()) { | 394 | switch(e->key()) { |
395 | case Key_Up: | 395 | case Key_Up: |
396 | view->scrollBy(0, -20); | 396 | view->scrollBy(0, -20); |
397 | break; | 397 | break; |
398 | case Key_Down: | 398 | case Key_Down: |
diff --git a/core/pim/datebook/datebookweeklst.cpp b/core/pim/datebook/datebookweeklst.cpp index 4ceb360..3d6a029 100644 --- a/core/pim/datebook/datebookweeklst.cpp +++ b/core/pim/datebook/datebookweeklst.cpp | |||
@@ -1,381 +1,381 @@ | |||
1 | #include "datebookweeklst.h" | 1 | #include "datebookweeklst.h" |
2 | 2 | ||
3 | #include "datebookweekheaderimpl.h" | 3 | #include "datebookweekheaderimpl.h" |
4 | 4 | ||
5 | #include <qpe/calendar.h> | 5 | #include <qpe/calendar.h> |
6 | #include <qpe/datebookdb.h> | 6 | #include <qpe/datebookdb.h> |
7 | #include <qpe/event.h> | 7 | #include <qpe/event.h> |
8 | #include <qpe/qpeapplication.h> | 8 | #include <qpe/qpeapplication.h> |
9 | #include <qpe/timestring.h> | 9 | #include <qpe/timestring.h> |
10 | #include <qpe/datebookmonth.h> | 10 | #include <qpe/datebookmonth.h> |
11 | #include <qpe/config.h> | 11 | #include <qpe/config.h> |
12 | #include <qpe/resource.h> | 12 | #include <qpe/resource.h> |
13 | 13 | ||
14 | #include <qdatetime.h> | 14 | #include <qdatetime.h> |
15 | #include <qheader.h> | 15 | #include <qheader.h> |
16 | #include <qlabel.h> | 16 | #include <qlabel.h> |
17 | #include <qlayout.h> | 17 | #include <qlayout.h> |
18 | #include <qpainter.h> | 18 | #include <qpainter.h> |
19 | #include <qpopupmenu.h> | 19 | #include <qpopupmenu.h> |
20 | #include <qtimer.h> | 20 | #include <qtimer.h> |
21 | #include <qstyle.h> | 21 | #include <qstyle.h> |
22 | #include <qtoolbutton.h> | 22 | #include <qtoolbutton.h> |
23 | #include <qvbox.h> | 23 | #include <qvbox.h> |
24 | #include <qsizepolicy.h> | 24 | #include <qsizepolicy.h> |
25 | #include <qabstractlayout.h> | 25 | #include <qabstractlayout.h> |
26 | #include <qtl.h> | 26 | #include <qtl.h> |
27 | 27 | ||
28 | bool calcWeek(const QDate &d, int &week, int &year, | 28 | bool calcWeek(const QDate &d, int &week, int &year, |
29 | bool startOnMonday = false); | 29 | bool startOnMonday = false); |
30 | 30 | ||
31 | DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, | 31 | DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, |
32 | const char* name, WFlags fl) | 32 | const char* name, WFlags fl) |
33 | : DateBookWeekLstHeaderBase(parent, name, fl) | 33 | : DateBookWeekLstHeaderBase(parent, name, fl) |
34 | { | 34 | { |
35 | setBackgroundMode( PaletteButton ); | 35 | setBackgroundMode( PaletteButton ); |
36 | labelDate->setBackgroundMode( PaletteButton ); | 36 | labelDate->setBackgroundMode( PaletteButton ); |
37 | labelWeek->setBackgroundMode( PaletteButton ); | 37 | labelWeek->setBackgroundMode( PaletteButton ); |
38 | forward->setBackgroundMode( PaletteButton ); | 38 | forward->setBackgroundMode( PaletteButton ); |
39 | forward->setPixmap( Resource::loadPixmap("forward") ); | 39 | forward->setPixmap( Resource::loadPixmap("forward") ); |
40 | back->setBackgroundMode( PaletteButton ); | 40 | back->setBackgroundMode( PaletteButton ); |
41 | back->setPixmap( Resource::loadPixmap("back") ); | 41 | back->setPixmap( Resource::loadPixmap("back") ); |
42 | DateBookWeekLstHeaderBaseLayout->setSpacing(0); | 42 | DateBookWeekLstHeaderBaseLayout->setSpacing(0); |
43 | DateBookWeekLstHeaderBaseLayout->setMargin(0); | 43 | DateBookWeekLstHeaderBaseLayout->setMargin(0); |
44 | //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); | 44 | //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); |
45 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); | 45 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); |
46 | 46 | ||
47 | connect(back, SIGNAL(clicked()), this, SLOT(prevWeek())); | 47 | connect(back, SIGNAL(clicked()), this, SLOT(prevWeek())); |
48 | connect(forward, SIGNAL(clicked()), this, SLOT(nextWeek())); | 48 | connect(forward, SIGNAL(clicked()), this, SLOT(nextWeek())); |
49 | connect(labelWeek, SIGNAL(clicked()), this, SLOT(pickDate())); | 49 | connect(labelWeek, SIGNAL(clicked()), this, SLOT(pickDate())); |
50 | connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); | 50 | connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); |
51 | onMonday=onM; | 51 | onMonday=onM; |
52 | } | 52 | } |
53 | DateBookWeekLstHeader::~DateBookWeekLstHeader(){} | 53 | DateBookWeekLstHeader::~DateBookWeekLstHeader(){} |
54 | void DateBookWeekLstHeader::setDate(const QDate &d) { | 54 | void DateBookWeekLstHeader::setDate(const QDate &d) { |
55 | date=d; | 55 | date=d; |
56 | 56 | ||
57 | int year,week; | 57 | int year,week; |
58 | calcWeek(d,week,year,onMonday); | 58 | calcWeek(d,week,year,onMonday); |
59 | labelWeek->setText(tr( "W: %1" ).arg( ( QString::number(week)) ) ); | 59 | labelWeek->setText(tr( "W: %1" ).arg( ( QString::number(week)) ) ); |
60 | 60 | ||
61 | QDate start=date; | 61 | QDate start=date; |
62 | QDate stop=start.addDays(6); | 62 | QDate stop=start.addDays(6); |
63 | labelDate->setText( QString::number(start.day()) + " " + | 63 | labelDate->setText( QString::number(start.day()) + " " + |
64 | start.monthName(start.month()) + " - " + | 64 | start.monthName(start.month()) + " - " + |
65 | QString::number(stop.day()) + " " + | 65 | QString::number(stop.day()) + " " + |
66 | start.monthName(stop.month()) ); | 66 | start.monthName(stop.month()) ); |
67 | emit dateChanged(year,week); | 67 | emit dateChanged(year,week); |
68 | } | 68 | } |
69 | void DateBookWeekLstHeader::pickDate() { | 69 | void DateBookWeekLstHeader::pickDate() { |
70 | static QPopupMenu *m1 = 0; | 70 | static QPopupMenu *m1 = 0; |
71 | static DateBookMonth *picker = 0; | 71 | static DateBookMonth *picker = 0; |
72 | if ( !m1 ) { | 72 | if ( !m1 ) { |
73 | m1 = new QPopupMenu( this ); | 73 | m1 = new QPopupMenu( this ); |
74 | picker = new DateBookMonth( m1, 0, TRUE ); | 74 | picker = new DateBookMonth( m1, 0, TRUE ); |
75 | m1->insertItem( picker ); | 75 | m1->insertItem( picker ); |
76 | connect( picker, SIGNAL( dateClicked( int, int, int ) ), | 76 | connect( picker, SIGNAL( dateClicked( int, int, int ) ), |
77 | this, SLOT( setDate( int, int, int ) ) ); | 77 | this, SLOT( setDate( int, int, int ) ) ); |
78 | //connect( m1, SIGNAL( aboutToHide() ), | 78 | //connect( m1, SIGNAL( aboutToHide() ), |
79 | //this, SLOT( gotHide() ) ); | 79 | //this, SLOT( gotHide() ) ); |
80 | } | 80 | } |
81 | picker->setDate( date.year(), date.month(), date.day() ); | 81 | picker->setDate( date.year(), date.month(), date.day() ); |
82 | m1->popup(mapToGlobal(labelWeek->pos()+QPoint(0,labelWeek->height()))); | 82 | m1->popup(mapToGlobal(labelWeek->pos()+QPoint(0,labelWeek->height()))); |
83 | picker->setFocus(); | 83 | picker->setFocus(); |
84 | } | 84 | } |
85 | void DateBookWeekLstHeader::setDate(int y, int m, int d) { | 85 | void DateBookWeekLstHeader::setDate(int y, int m, int d) { |
86 | QDate new_date(y,m,d); | 86 | QDate new_date(y,m,d); |
87 | setDate(new_date); | 87 | setDate(new_date); |
88 | } | 88 | } |
89 | 89 | ||
90 | void DateBookWeekLstHeader::nextWeek() { | 90 | void DateBookWeekLstHeader::nextWeek() { |
91 | setDate(date.addDays(7)); | 91 | setDate(date.addDays(7)); |
92 | } | 92 | } |
93 | void DateBookWeekLstHeader::prevWeek() { | 93 | void DateBookWeekLstHeader::prevWeek() { |
94 | setDate(date.addDays(-7)); | 94 | setDate(date.addDays(-7)); |
95 | } | 95 | } |
96 | 96 | ||
97 | DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/, | 97 | DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/, |
98 | QWidget* parent, | 98 | QWidget* parent, |
99 | const char* name, | 99 | const char* name, |
100 | WFlags fl ) | 100 | WFlags fl ) |
101 | : DateBookWeekLstDayHdrBase(parent, name, fl) { | 101 | : DateBookWeekLstDayHdrBase(parent, name, fl) { |
102 | 102 | ||
103 | date=d; | 103 | date=d; |
104 | 104 | ||
105 | static const char *wdays={"MTWTFSS"}; | 105 | static const char *wdays={"MTWTFSS"}; |
106 | char day=wdays[d.dayOfWeek()-1]; | 106 | char day=wdays[d.dayOfWeek()-1]; |
107 | 107 | ||
108 | label->setText( QString(QObject::tr(QString(QChar(day)))) + " " + | 108 | label->setText( QString(QObject::tr(QString(QChar(day)))) + " " + |
109 | QString::number(d.day()) ); | 109 | QString::number(d.day()) ); |
110 | add->setText("+"); | 110 | add->setText("+"); |
111 | 111 | ||
112 | if (d == QDate::currentDate()) { | 112 | if (d == QDate::currentDate()) { |
113 | QPalette pal=label->palette(); | 113 | QPalette pal=label->palette(); |
114 | pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); | 114 | pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); |
115 | label->setPalette(pal); | 115 | label->setPalette(pal); |
116 | 116 | ||
117 | /* | 117 | /* |
118 | QFont f=label->font(); | 118 | QFont f=label->font(); |
119 | f.setItalic(true); | 119 | f.setItalic(true); |
120 | label->setFont(f); | 120 | label->setFont(f); |
121 | label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); | 121 | label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); |
122 | */ | 122 | */ |
123 | } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday | 123 | } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday |
124 | QPalette pal=label->palette(); | 124 | QPalette pal=label->palette(); |
125 | pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); | 125 | pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); |
126 | label->setPalette(pal); | 126 | label->setPalette(pal); |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | connect (label, SIGNAL(clicked()), this, SLOT(showDay())); | 130 | connect (label, SIGNAL(clicked()), this, SLOT(showDay())); |
131 | connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); | 131 | connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); |
132 | } | 132 | } |
133 | 133 | ||
134 | void DateBookWeekLstDayHdr::showDay() { | 134 | void DateBookWeekLstDayHdr::showDay() { |
135 | emit showDate(date.year(), date.month(), date.day()); | 135 | emit showDate(date.year(), date.month(), date.day()); |
136 | } | 136 | } |
137 | void DateBookWeekLstDayHdr::newEvent() { | 137 | void DateBookWeekLstDayHdr::newEvent() { |
138 | QDateTime start, stop; | 138 | QDateTime start, stop; |
139 | start=stop=date; | 139 | start=stop=date; |
140 | start.setTime(QTime(10,0)); | 140 | start.setTime(QTime(10,0)); |
141 | stop.setTime(QTime(12,0)); | 141 | stop.setTime(QTime(12,0)); |
142 | 142 | ||
143 | emit addEvent(start,stop,"",0); | 143 | emit addEvent(start,stop,"",0); |
144 | } | 144 | } |
145 | DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev, | 145 | DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev, |
146 | QWidget* parent, | 146 | QWidget* parent, |
147 | const char* name, | 147 | const char* name, |
148 | WFlags fl) : | 148 | WFlags fl) : |
149 | OClickableLabel(parent,name,fl), | 149 | OClickableLabel(parent,name,fl), |
150 | event(ev) | 150 | event(ev) |
151 | { | 151 | { |
152 | char s[10]; | 152 | char s[10]; |
153 | if ( ev.startDate() != ev.date() ) { // multiday event (not first day) | 153 | if ( ev.startDate() != ev.date() ) { // multiday event (not first day) |
154 | if ( ev.endDate() == ev.date() ) { // last day | 154 | if ( ev.endDate() == ev.date() ) { // last day |
155 | strcpy(s, "__|__"); | 155 | strcpy(s, "__|__"); |
156 | } else { | 156 | } else { |
157 | strcpy(s, " |---"); | 157 | strcpy(s, " |---"); |
158 | } | 158 | } |
159 | } else { | 159 | } else { |
160 | if(ev.event().type() == Event::Normal ) | 160 | if(ev.event().type() == Event::Normal ) |
161 | sprintf(s,"%.2d:%.2d",ev.start().hour(),ev.start().minute()); | 161 | sprintf(s,"%.2d:%.2d",ev.start().hour(),ev.start().minute()); |
162 | else | 162 | else |
163 | sprintf(s," "); | 163 | sprintf(s," "); |
164 | } | 164 | } |
165 | setText(QString(s) + " " + ev.description()); | 165 | setText(QString(s) + " " + ev.description()); |
166 | connect(this, SIGNAL(clicked()), this, SLOT(editMe())); | 166 | connect(this, SIGNAL(clicked()), this, SLOT(editMe())); |
167 | setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); | 167 | setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); |
168 | } | 168 | } |
169 | void DateBookWeekLstEvent::editMe() { | 169 | void DateBookWeekLstEvent::editMe() { |
170 | emit editEvent(event.event()); | 170 | emit editEvent(event.event()); |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
174 | DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, | 174 | DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, |
175 | const QDate &d, bool onM, | 175 | const QDate &d, bool onM, |
176 | QWidget* parent, | 176 | QWidget* parent, |
177 | const char* name, WFlags fl) | 177 | const char* name, WFlags fl) |
178 | : QWidget( parent, name, fl ) | 178 | : QWidget( parent, name, fl ) |
179 | { | 179 | { |
180 | onMonday=onM; | 180 | onMonday=onM; |
181 | setPalette(white); | 181 | setPalette(white); |
182 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); | 182 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); |
183 | 183 | ||
184 | QVBoxLayout *layout = new QVBoxLayout( this ); | 184 | QVBoxLayout *layout = new QVBoxLayout( this ); |
185 | 185 | ||
186 | qBubbleSort(ev); | 186 | qBubbleSort(ev); |
187 | QValueListIterator<EffectiveEvent> it; | 187 | QValueListIterator<EffectiveEvent> it; |
188 | it=ev.begin(); | 188 | it=ev.begin(); |
189 | 189 | ||
190 | int dayOrder[7]; | 190 | int dayOrder[7]; |
191 | if (onMonday) | 191 | if (onMonday) |
192 | for (int d=0; d<7; d++) dayOrder[d]=d+1; | 192 | for (int d=0; d<7; d++) dayOrder[d]=d+1; |
193 | else { | 193 | else { |
194 | for (int d=0; d<7; d++) dayOrder[d]=d; | 194 | for (int d=0; d<7; d++) dayOrder[d]=d; |
195 | dayOrder[0]=7; | 195 | dayOrder[0]=7; |
196 | } | 196 | } |
197 | 197 | ||
198 | for (int i=0; i<7; i++) { | 198 | for (int i=0; i<7; i++) { |
199 | // Header | 199 | // Header |
200 | DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i), | 200 | DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i), |
201 | onMonday,this); | 201 | onMonday,this); |
202 | connect(hdr, SIGNAL(showDate(int,int,int)), | 202 | connect(hdr, SIGNAL(showDate(int,int,int)), |
203 | this, SIGNAL(showDate(int,int,int))); | 203 | this, SIGNAL(showDate(int,int,int))); |
204 | connect(hdr, SIGNAL(addEvent(const QDateTime &, | 204 | connect(hdr, SIGNAL(addEvent(const QDateTime &, |
205 | const QDateTime &, | 205 | const QDateTime &, |
206 | const QString &, const QString &)), | 206 | const QString &, const QString &)), |
207 | this, SIGNAL(addEvent(const QDateTime &, | 207 | this, SIGNAL(addEvent(const QDateTime &, |
208 | const QDateTime &, | 208 | const QDateTime &, |
209 | const QString &, const QString &))); | 209 | const QString &, const QString &))); |
210 | layout->addWidget(hdr); | 210 | layout->addWidget(hdr); |
211 | 211 | ||
212 | // Events | 212 | // Events |
213 | while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { | 213 | while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { |
214 | if(!((*it).end().hour()==(*it).start().hour() && (*it).end().minute()==(*it).start().minute())) {// Skip effective events with no duration. (i.e ending at 00:00) | 214 | if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) {// Skip events ending at 00:00 starting at another day. |
215 | DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,this); | 215 | DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,this); |
216 | layout->addWidget(l); | 216 | layout->addWidget(l); |
217 | connect (l, SIGNAL(editEvent(const Event &)), | 217 | connect (l, SIGNAL(editEvent(const Event &)), |
218 | this, SIGNAL(editEvent(const Event &))); | 218 | this, SIGNAL(editEvent(const Event &))); |
219 | } | 219 | } |
220 | it++; | 220 | it++; |
221 | } | 221 | } |
222 | 222 | ||
223 | layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); | 223 | layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); |
224 | } | 224 | } |
225 | } | 225 | } |
226 | DateBookWeekLstView::~DateBookWeekLstView(){} | 226 | DateBookWeekLstView::~DateBookWeekLstView(){} |
227 | void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} | 227 | void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} |
228 | 228 | ||
229 | DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, | 229 | DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, |
230 | QValueList<EffectiveEvent> &ev2, | 230 | QValueList<EffectiveEvent> &ev2, |
231 | QDate &d, bool onM, | 231 | QDate &d, bool onM, |
232 | QWidget* parent, | 232 | QWidget* parent, |
233 | const char* name, WFlags fl) | 233 | const char* name, WFlags fl) |
234 | : QWidget( parent, name, fl ) | 234 | : QWidget( parent, name, fl ) |
235 | { | 235 | { |
236 | QHBoxLayout *layout = new QHBoxLayout( this ); | 236 | QHBoxLayout *layout = new QHBoxLayout( this ); |
237 | 237 | ||
238 | DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this); | 238 | DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this); |
239 | layout->addWidget(w); | 239 | layout->addWidget(w); |
240 | connect (w, SIGNAL(editEvent(const Event &)), | 240 | connect (w, SIGNAL(editEvent(const Event &)), |
241 | this, SIGNAL(editEvent(const Event &))); | 241 | this, SIGNAL(editEvent(const Event &))); |
242 | connect (w, SIGNAL(showDate(int,int,int)), | 242 | connect (w, SIGNAL(showDate(int,int,int)), |
243 | this, SIGNAL(showDate(int,int,int))); | 243 | this, SIGNAL(showDate(int,int,int))); |
244 | connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, | 244 | connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, |
245 | const QString &,const QString &)), | 245 | const QString &,const QString &)), |
246 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, | 246 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, |
247 | const QString &, const QString &))); | 247 | const QString &, const QString &))); |
248 | 248 | ||
249 | 249 | ||
250 | w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); | 250 | w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); |
251 | layout->addWidget(w); | 251 | layout->addWidget(w); |
252 | connect (w, SIGNAL(editEvent(const Event &)), | 252 | connect (w, SIGNAL(editEvent(const Event &)), |
253 | this, SIGNAL(editEvent(const Event &))); | 253 | this, SIGNAL(editEvent(const Event &))); |
254 | connect (w, SIGNAL(showDate(int,int,int)), | 254 | connect (w, SIGNAL(showDate(int,int,int)), |
255 | this, SIGNAL(showDate(int,int,int))); | 255 | this, SIGNAL(showDate(int,int,int))); |
256 | connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, | 256 | connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, |
257 | const QString &, const QString &)), | 257 | const QString &, const QString &)), |
258 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, | 258 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, |
259 | const QString &, const QString &))); | 259 | const QString &, const QString &))); |
260 | } | 260 | } |
261 | 261 | ||
262 | DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, | 262 | DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, |
263 | QWidget *parent, | 263 | QWidget *parent, |
264 | const char *name ) | 264 | const char *name ) |
265 | : QWidget( parent, name ), | 265 | : QWidget( parent, name ), |
266 | db( newDB ), | 266 | db( newDB ), |
267 | startTime( 0 ), | 267 | startTime( 0 ), |
268 | ampm( ap ), | 268 | ampm( ap ), |
269 | onMonday(onM) | 269 | onMonday(onM) |
270 | { | 270 | { |
271 | setFocusPolicy(StrongFocus); | 271 | setFocusPolicy(StrongFocus); |
272 | layout = new QVBoxLayout( this ); | 272 | layout = new QVBoxLayout( this ); |
273 | layout->setMargin(0); | 273 | layout->setMargin(0); |
274 | 274 | ||
275 | header=new DateBookWeekLstHeader(onM, this); | 275 | header=new DateBookWeekLstHeader(onM, this); |
276 | layout->addWidget( header ); | 276 | layout->addWidget( header ); |
277 | connect(header, SIGNAL(dateChanged(int,int)), | 277 | connect(header, SIGNAL(dateChanged(int,int)), |
278 | this, SLOT(dateChanged(int,int))); | 278 | this, SLOT(dateChanged(int,int))); |
279 | connect(header, SIGNAL(setDbl(bool)), | 279 | connect(header, SIGNAL(setDbl(bool)), |
280 | this, SLOT(setDbl(bool))); | 280 | this, SLOT(setDbl(bool))); |
281 | 281 | ||
282 | scroll=new QScrollView(this); | 282 | scroll=new QScrollView(this); |
283 | //scroll->setVScrollBarMode(QScrollView::AlwaysOn); | 283 | //scroll->setVScrollBarMode(QScrollView::AlwaysOn); |
284 | //scroll->setHScrollBarMode(QScrollView::AlwaysOff); | 284 | //scroll->setHScrollBarMode(QScrollView::AlwaysOff); |
285 | scroll->setResizePolicy(QScrollView::AutoOneFit); | 285 | scroll->setResizePolicy(QScrollView::AutoOneFit); |
286 | layout->addWidget(scroll); | 286 | layout->addWidget(scroll); |
287 | 287 | ||
288 | view=NULL; | 288 | view=NULL; |
289 | Config config("DateBook"); | 289 | Config config("DateBook"); |
290 | config.setGroup("Main"); | 290 | config.setGroup("Main"); |
291 | dbl=config.readBoolEntry("weeklst_dbl", false); | 291 | dbl=config.readBoolEntry("weeklst_dbl", false); |
292 | header->dbl->setOn(dbl); | 292 | header->dbl->setOn(dbl); |
293 | } | 293 | } |
294 | DateBookWeekLst::~DateBookWeekLst(){ | 294 | DateBookWeekLst::~DateBookWeekLst(){ |
295 | Config config("DateBook"); | 295 | Config config("DateBook"); |
296 | config.setGroup("Main"); | 296 | config.setGroup("Main"); |
297 | config.writeEntry("weeklst_dbl", dbl); | 297 | config.writeEntry("weeklst_dbl", dbl); |
298 | } | 298 | } |
299 | 299 | ||
300 | void DateBookWeekLst::setDate(const QDate &d) { | 300 | void DateBookWeekLst::setDate(const QDate &d) { |
301 | int w,y; | 301 | int w,y; |
302 | calcWeek(d,w,y,onMonday); | 302 | calcWeek(d,w,y,onMonday); |
303 | year=y; | 303 | year=y; |
304 | _week=w; | 304 | _week=w; |
305 | header->setDate(date()); | 305 | header->setDate(date()); |
306 | } | 306 | } |
307 | void DateBookWeekLst::setDbl(bool on) { | 307 | void DateBookWeekLst::setDbl(bool on) { |
308 | dbl=on; | 308 | dbl=on; |
309 | redraw(); | 309 | redraw(); |
310 | } | 310 | } |
311 | void DateBookWeekLst::redraw() {getEvents();} | 311 | void DateBookWeekLst::redraw() {getEvents();} |
312 | 312 | ||
313 | QDate DateBookWeekLst::date() const { | 313 | QDate DateBookWeekLst::date() const { |
314 | QDate d; | 314 | QDate d; |
315 | d.setYMD(year,1,1); | 315 | d.setYMD(year,1,1); |
316 | 316 | ||
317 | int dow= d.dayOfWeek(); | 317 | int dow= d.dayOfWeek(); |
318 | if (!onMonday) | 318 | if (!onMonday) |
319 | if (dow==7) dow=1; | 319 | if (dow==7) dow=1; |
320 | else dow++; | 320 | else dow++; |
321 | 321 | ||
322 | d=d.addDays( (_week-1)*7 - dow + 1 ); | 322 | d=d.addDays( (_week-1)*7 - dow + 1 ); |
323 | return d; | 323 | return d; |
324 | } | 324 | } |
325 | 325 | ||
326 | void DateBookWeekLst::getEvents() { | 326 | void DateBookWeekLst::getEvents() { |
327 | QDate start = date(); | 327 | QDate start = date(); |
328 | QDate stop = start.addDays(6); | 328 | QDate stop = start.addDays(6); |
329 | QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); | 329 | QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); |
330 | 330 | ||
331 | if (view) delete view; | 331 | if (view) delete view; |
332 | if (dbl) { | 332 | if (dbl) { |
333 | QDate start2=start.addDays(7); | 333 | QDate start2=start.addDays(7); |
334 | stop=start2.addDays(6); | 334 | stop=start2.addDays(6); |
335 | QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); | 335 | QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); |
336 | 336 | ||
337 | view=new DateBookWeekLstDblView(el,el2,start,onMonday,scroll); | 337 | view=new DateBookWeekLstDblView(el,el2,start,onMonday,scroll); |
338 | } else { | 338 | } else { |
339 | view=new DateBookWeekLstView(el,start,onMonday,scroll); | 339 | view=new DateBookWeekLstView(el,start,onMonday,scroll); |
340 | } | 340 | } |
341 | 341 | ||
342 | connect (view, SIGNAL(editEvent(const Event &)), | 342 | connect (view, SIGNAL(editEvent(const Event &)), |
343 | this, SIGNAL(editEvent(const Event &))); | 343 | this, SIGNAL(editEvent(const Event &))); |
344 | connect (view, SIGNAL(showDate(int,int,int)), | 344 | connect (view, SIGNAL(showDate(int,int,int)), |
345 | this, SIGNAL(showDate(int,int,int))); | 345 | this, SIGNAL(showDate(int,int,int))); |
346 | connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &, | 346 | connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &, |
347 | const QString &, const QString &)), | 347 | const QString &, const QString &)), |
348 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, | 348 | this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, |
349 | const QString &, const QString &))); | 349 | const QString &, const QString &))); |
350 | 350 | ||
351 | scroll->addChild(view); | 351 | scroll->addChild(view); |
352 | view->show(); | 352 | view->show(); |
353 | scroll->updateScrollBars(); | 353 | scroll->updateScrollBars(); |
354 | } | 354 | } |
355 | 355 | ||
356 | void DateBookWeekLst::dateChanged(int y, int w) { | 356 | void DateBookWeekLst::dateChanged(int y, int w) { |
357 | year=y; | 357 | year=y; |
358 | _week=w; | 358 | _week=w; |
359 | getEvents(); | 359 | getEvents(); |
360 | } | 360 | } |
361 | 361 | ||
362 | void DateBookWeekLst::keyPressEvent(QKeyEvent *e) | 362 | void DateBookWeekLst::keyPressEvent(QKeyEvent *e) |
363 | { | 363 | { |
364 | switch(e->key()) { | 364 | switch(e->key()) { |
365 | case Key_Up: | 365 | case Key_Up: |
366 | scroll->scrollBy(0, -20); | 366 | scroll->scrollBy(0, -20); |
367 | break; | 367 | break; |
368 | case Key_Down: | 368 | case Key_Down: |
369 | scroll->scrollBy(0, 20); | 369 | scroll->scrollBy(0, 20); |
370 | break; | 370 | break; |
371 | case Key_Left: | 371 | case Key_Left: |
372 | header->prevWeek(); | 372 | header->prevWeek(); |
373 | break; | 373 | break; |
374 | case Key_Right: | 374 | case Key_Right: |
375 | header->nextWeek(); | 375 | header->nextWeek(); |
376 | break; | 376 | break; |
377 | default: | 377 | default: |
378 | e->ignore(); | 378 | e->ignore(); |
379 | } | 379 | } |
380 | } | 380 | } |
381 | 381 | ||