summaryrefslogtreecommitdiff
authorleseb <leseb>2002-06-05 19:04:52 (UTC)
committer leseb <leseb>2002-06-05 19:04:52 (UTC)
commit7e61a0450682589c5ec5a8009df3b6ec36dbb5a0 (patch) (unidiff)
tree7888efc836878563834513a94af13969f1edc433
parent91398d550495cb82445457b59e472a58ad0a296a (diff)
downloadopie-7e61a0450682589c5ec5a8009df3b6ec36dbb5a0.zip
opie-7e61a0450682589c5ec5a8009df3b6ec36dbb5a0.tar.gz
opie-7e61a0450682589c5ec5a8009df3b6ec36dbb5a0.tar.bz2
Correction of bug #394
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/datebookmonth.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp
index b2074e6..f4b3e6b 100644
--- a/library/datebookmonth.cpp
+++ b/library/datebookmonth.cpp
@@ -1,713 +1,713 @@
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 "config.h" 20#include "config.h"
21#include "datebookmonth.h" 21#include "datebookmonth.h"
22#include "datebookdb.h" 22#include "datebookdb.h"
23#include <qpe/event.h> 23#include <qpe/event.h>
24#include "resource.h" 24#include "resource.h"
25#include "qpeapplication.h" 25#include "qpeapplication.h"
26#include "timestring.h" 26#include "timestring.h"
27 27
28#include <qtoolbutton.h> 28#include <qtoolbutton.h>
29#include <qspinbox.h> 29#include <qspinbox.h>
30#include <qcombobox.h> 30#include <qcombobox.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qpainter.h> 32#include <qpainter.h>
33#include <qpopupmenu.h> 33#include <qpopupmenu.h>
34 34
35 35
36DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name ) 36DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name )
37 : QHBox( parent, name ) 37 : QHBox( parent, name )
38{ 38{
39 setBackgroundMode( PaletteButton ); 39 setBackgroundMode( PaletteButton );
40 40
41 begin = new QToolButton( this ); 41 begin = new QToolButton( this );
42 begin->setFocusPolicy(NoFocus); 42 begin->setFocusPolicy(NoFocus);
43 begin->setPixmap( Resource::loadPixmap( "start" ) ); 43 begin->setPixmap( Resource::loadPixmap( "start" ) );
44 begin->setAutoRaise( TRUE ); 44 begin->setAutoRaise( TRUE );
45 begin->setFixedSize( begin->sizeHint() ); 45 begin->setFixedSize( begin->sizeHint() );
46 46
47 back = new QToolButton( this ); 47 back = new QToolButton( this );
48 back->setFocusPolicy(NoFocus); 48 back->setFocusPolicy(NoFocus);
49 back->setPixmap( Resource::loadPixmap( "back" ) ); 49 back->setPixmap( Resource::loadPixmap( "back" ) );
50 back->setAutoRaise( TRUE ); 50 back->setAutoRaise( TRUE );
51 back->setFixedSize( back->sizeHint() ); 51 back->setFixedSize( back->sizeHint() );
52 52
53 month = new QComboBox( FALSE, this ); 53 month = new QComboBox( FALSE, this );
54 for ( int i = 0; i < 12; ++i ) 54 for ( int i = 0; i < 12; ++i )
55 month->insertItem( Calendar::nameOfMonth( i + 1 ) ); 55 month->insertItem( Calendar::nameOfMonth( i + 1 ) );
56 56
57 year = new QSpinBox( 1970, 2037, 1, this ); 57 year = new QSpinBox( 1752, 8000, 1, this );
58 58
59 next = new QToolButton( this ); 59 next = new QToolButton( this );
60 next->setFocusPolicy(NoFocus); 60 next->setFocusPolicy(NoFocus);
61 next->setPixmap( Resource::loadPixmap( "forward" ) ); 61 next->setPixmap( Resource::loadPixmap( "forward" ) );
62 next->setAutoRaise( TRUE ); 62 next->setAutoRaise( TRUE );
63 next->setFixedSize( next->sizeHint() ); 63 next->setFixedSize( next->sizeHint() );
64 64
65 end = new QToolButton( this ); 65 end = new QToolButton( this );
66 end->setFocusPolicy(NoFocus); 66 end->setFocusPolicy(NoFocus);
67 end->setPixmap( Resource::loadPixmap( "finish" ) ); 67 end->setPixmap( Resource::loadPixmap( "finish" ) );
68 end->setAutoRaise( TRUE ); 68 end->setAutoRaise( TRUE );
69 end->setFixedSize( end->sizeHint() ); 69 end->setFixedSize( end->sizeHint() );
70 70
71 connect( month, SIGNAL( activated( int ) ), 71 connect( month, SIGNAL( activated( int ) ),
72 this, SLOT( updateDate() ) ); 72 this, SLOT( updateDate() ) );
73 connect( year, SIGNAL( valueChanged( int ) ), 73 connect( year, SIGNAL( valueChanged( int ) ),
74 this, SLOT( updateDate() ) ); 74 this, SLOT( updateDate() ) );
75 connect( begin, SIGNAL( clicked() ), 75 connect( begin, SIGNAL( clicked() ),
76 this, SLOT( firstMonth() ) ); 76 this, SLOT( firstMonth() ) );
77 connect( end, SIGNAL( clicked() ), 77 connect( end, SIGNAL( clicked() ),
78 this, SLOT( lastMonth() ) ); 78 this, SLOT( lastMonth() ) );
79 connect( back, SIGNAL( clicked() ), 79 connect( back, SIGNAL( clicked() ),
80 this, SLOT( monthBack() ) ); 80 this, SLOT( monthBack() ) );
81 connect( next, SIGNAL( clicked() ), 81 connect( next, SIGNAL( clicked() ),
82 this, SLOT( monthForward() ) ); 82 this, SLOT( monthForward() ) );
83 back->setAutoRepeat( TRUE ); 83 back->setAutoRepeat( TRUE );
84 next->setAutoRepeat( TRUE ); 84 next->setAutoRepeat( TRUE );
85} 85}
86 86
87 87
88DateBookMonthHeader::~DateBookMonthHeader() 88DateBookMonthHeader::~DateBookMonthHeader()
89{ 89{
90 90
91} 91}
92 92
93void DateBookMonthHeader::updateDate() 93void DateBookMonthHeader::updateDate()
94{ 94{
95 emit dateChanged( year->value(), month->currentItem() + 1 ); 95 emit dateChanged( year->value(), month->currentItem() + 1 );
96} 96}
97 97
98void DateBookMonthHeader::firstMonth() 98void DateBookMonthHeader::firstMonth()
99{ 99{
100 emit dateChanged( year->value(), 1 ); 100 emit dateChanged( year->value(), 1 );
101 month->setCurrentItem( 0 ); 101 month->setCurrentItem( 0 );
102} 102}
103 103
104void DateBookMonthHeader::lastMonth() 104void DateBookMonthHeader::lastMonth()
105{ 105{
106 emit dateChanged( year->value(), 12 ); 106 emit dateChanged( year->value(), 12 );
107 month->setCurrentItem( 11 ); 107 month->setCurrentItem( 11 );
108} 108}
109 109
110void DateBookMonthHeader::monthBack() 110void DateBookMonthHeader::monthBack()
111{ 111{
112 if ( month->currentItem() > 0 ) { 112 if ( month->currentItem() > 0 ) {
113 emit dateChanged( year->value(), month->currentItem() ); 113 emit dateChanged( year->value(), month->currentItem() );
114 month->setCurrentItem( month->currentItem() - 1 ); 114 month->setCurrentItem( month->currentItem() - 1 );
115 } else { 115 } else {
116 emit dateChanged( year->value() - 1, 12 ); 116 emit dateChanged( year->value() - 1, 12 );
117 // we have a signal set to a changed value in year so we only need to change 117 // we have a signal set to a changed value in year so we only need to change
118 // year to get the result... 118 // year to get the result...
119 month->setCurrentItem( 11 ); 119 month->setCurrentItem( 11 );
120 year->setValue( year->value() - 1 ); 120 year->setValue( year->value() - 1 );
121 } 121 }
122} 122}
123 123
124void DateBookMonthHeader::monthForward() 124void DateBookMonthHeader::monthForward()
125{ 125{
126 if ( month->currentItem() < 11 ) { 126 if ( month->currentItem() < 11 ) {
127 emit dateChanged( year->value(), month->currentItem() + 2 ); 127 emit dateChanged( year->value(), month->currentItem() + 2 );
128 month->setCurrentItem( month->currentItem() + 1 ); 128 month->setCurrentItem( month->currentItem() + 1 );
129 } else { 129 } else {
130 // we have a signal set to a changed value in year so we only need to change 130 // we have a signal set to a changed value in year so we only need to change
131 // year to get the result... 131 // year to get the result...
132 month->setCurrentItem( 0 ); 132 month->setCurrentItem( 0 );
133 year->setValue( year->value() + 1 ); 133 year->setValue( year->value() + 1 );
134 } 134 }
135} 135}
136 136
137void DateBookMonthHeader::setDate( int y, int m ) 137void DateBookMonthHeader::setDate( int y, int m )
138{ 138{
139 year->setValue( y ); 139 year->setValue( y );
140 month->setCurrentItem( m - 1 ); 140 month->setCurrentItem( m - 1 );
141} 141}
142 142
143//--------------------------------------------------------------------------- 143//---------------------------------------------------------------------------
144 144
145class DateBookMonthTablePrivate 145class DateBookMonthTablePrivate
146{ 146{
147public: 147public:
148 DateBookMonthTablePrivate() {}; 148 DateBookMonthTablePrivate() {};
149 ~DateBookMonthTablePrivate() { mMonthEvents.clear(); }; 149 ~DateBookMonthTablePrivate() { mMonthEvents.clear(); };
150 150
151 QValueList<EffectiveEvent> mMonthEvents; 151 QValueList<EffectiveEvent> mMonthEvents;
152 bool onMonday; 152 bool onMonday;
153}; 153};
154 154
155DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name, 155DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name,
156 DateBookDB *newDb ) 156 DateBookDB *newDb )
157 : QTable( 6, 7, parent, name ), 157 : QTable( 6, 7, parent, name ),
158 db( newDb ) 158 db( newDb )
159{ 159{
160 d = new DateBookMonthTablePrivate(); 160 d = new DateBookMonthTablePrivate();
161 selYear = -1; 161 selYear = -1;
162 selMonth = -1; 162 selMonth = -1;
163 selDay = -1; 163 selDay = -1;
164 164
165 Config cfg( "qpe" ); 165 Config cfg( "qpe" );
166 cfg.setGroup( "Time" ); 166 cfg.setGroup( "Time" );
167 d->onMonday = cfg.readBoolEntry( "MONDAY" ); 167 d->onMonday = cfg.readBoolEntry( "MONDAY" );
168 168
169 horizontalHeader()->setResizeEnabled( FALSE ); 169 horizontalHeader()->setResizeEnabled( FALSE );
170 // we have to do this here... or suffer the consequences later... 170 // we have to do this here... or suffer the consequences later...
171 for ( int i = 0; i < 7; i++ ){ 171 for ( int i = 0; i < 7; i++ ){
172 horizontalHeader()->resizeSection( i, 30 ); 172 horizontalHeader()->resizeSection( i, 30 );
173 setColumnStretchable( i, TRUE ); 173 setColumnStretchable( i, TRUE );
174 } 174 }
175 setupLabels(); 175 setupLabels();
176 176
177 verticalHeader()->hide(); 177 verticalHeader()->hide();
178 setLeftMargin( 0 ); 178 setLeftMargin( 0 );
179 for ( int i = 0; i < 6; ++i ) 179 for ( int i = 0; i < 6; ++i )
180 setRowStretchable( i, TRUE ); 180 setRowStretchable( i, TRUE );
181 181
182 setSelectionMode( NoSelection ); 182 setSelectionMode( NoSelection );
183 183
184 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), 184 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ),
185 this, SLOT( dayClicked( int, int ) ) ); 185 this, SLOT( dayClicked( int, int ) ) );
186 connect( this, SIGNAL( currentChanged( int, int ) ), 186 connect( this, SIGNAL( currentChanged( int, int ) ),
187 this, SLOT( dragDay( int, int ) ) ); 187 this, SLOT( dragDay( int, int ) ) );
188 setVScrollBarMode( AlwaysOff ); 188 setVScrollBarMode( AlwaysOff );
189 setHScrollBarMode( AlwaysOff ); 189 setHScrollBarMode( AlwaysOff );
190} 190}
191 191
192DateBookMonthTable::~DateBookMonthTable() 192DateBookMonthTable::~DateBookMonthTable()
193{ 193{
194 monthsEvents.clear(); 194 monthsEvents.clear();
195 delete d; 195 delete d;
196} 196}
197 197
198void DateBookMonthTable::setDate(int y, int m, int d) 198void DateBookMonthTable::setDate(int y, int m, int d)
199{ 199{
200 if (month == m && year == y) { 200 if (month == m && year == y) {
201 if ( selYear == -1 ) 201 if ( selYear == -1 )
202 year = selYear; 202 year = selYear;
203 if ( selMonth == -1 ) 203 if ( selMonth == -1 )
204 month = selMonth; 204 month = selMonth;
205 int r1, c1, r2, c2; 205 int r1, c1, r2, c2;
206 findDay(selDay, r1, c1); 206 findDay(selDay, r1, c1);
207 selDay = day = d; 207 selDay = day = d;
208 findDay(selDay, r2, c2); 208 findDay(selDay, r2, c2);
209 setCurrentCell( r2, c2 ); 209 setCurrentCell( r2, c2 );
210 //updateCell(r1,c1); 210 //updateCell(r1,c1);
211 //updateCell(r2,c2); 211 //updateCell(r2,c2);
212 } else { 212 } else {
213 selYear = year = y; 213 selYear = year = y;
214 selMonth = month = m; 214 selMonth = month = m;
215 selDay = day = d; 215 selDay = day = d;
216 setupTable(); 216 setupTable();
217 } 217 }
218} 218}
219 219
220void DateBookMonthTable::redraw() 220void DateBookMonthTable::redraw()
221{ 221{
222 setupLabels(); 222 setupLabels();
223 setupTable(); 223 setupTable();
224} 224}
225 225
226void DateBookMonthTable::setWeekStart( bool onMonday ) 226void DateBookMonthTable::setWeekStart( bool onMonday )
227{ 227{
228 d->onMonday = onMonday; 228 d->onMonday = onMonday;
229 setupLabels(); 229 setupLabels();
230 setupTable(); 230 setupTable();
231} 231}
232 232
233void DateBookMonthTable::setupTable() 233void DateBookMonthTable::setupTable()
234{ 234{
235 QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday ); 235 QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday );
236 QValueList<Calendar::Day>::Iterator it = days.begin(); 236 QValueList<Calendar::Day>::Iterator it = days.begin();
237 int row = 0, col = 0; 237 int row = 0, col = 0;
238 int crow = 0; 238 int crow = 0;
239 int ccol = 0; 239 int ccol = 0;
240 for ( ; it != days.end(); ++it ) { 240 for ( ; it != days.end(); ++it ) {
241 DayItemMonth *i = (DayItemMonth *)item( row, col ); 241 DayItemMonth *i = (DayItemMonth *)item( row, col );
242 if ( !i ) { 242 if ( !i ) {
243 i = new DayItemMonth( this, QTableItem::Never, "" ); 243 i = new DayItemMonth( this, QTableItem::Never, "" );
244 setItem( row, col, i ); 244 setItem( row, col, i );
245 } 245 }
246 Calendar::Day calDay = *it; 246 Calendar::Day calDay = *it;
247 i->clearEffEvents(); 247 i->clearEffEvents();
248 i->setDay( calDay.date ); 248 i->setDay( calDay.date );
249 i->setType( calDay.type ); 249 i->setType( calDay.type );
250 if ( i->day() == day && calDay.type == Calendar::Day::ThisMonth ) { 250 if ( i->day() == day && calDay.type == Calendar::Day::ThisMonth ) {
251 crow = row; 251 crow = row;
252 ccol = col; 252 ccol = col;
253 } 253 }
254 254
255 updateCell( row, col ); 255 updateCell( row, col );
256 256
257 if ( col == 6 ) { 257 if ( col == 6 ) {
258 ++row; 258 ++row;
259 col = 0; 259 col = 0;
260 } else { 260 } else {
261 ++col; 261 ++col;
262 } 262 }
263 } 263 }
264 setCurrentCell( crow, ccol ); 264 setCurrentCell( crow, ccol );
265 getEvents(); 265 getEvents();
266} 266}
267 267
268void DateBookMonthTable::findDay( int day, int &row, int &col ) 268void DateBookMonthTable::findDay( int day, int &row, int &col )
269{ 269{
270 QDate dtBegin( year, month, 1 ); 270 QDate dtBegin( year, month, 1 );
271 int skips = dtBegin.dayOfWeek(); 271 int skips = dtBegin.dayOfWeek();
272 int effective_day = day + skips - 1; // row/columns begin at 0 272 int effective_day = day + skips - 1; // row/columns begin at 0
273 // make an extra adjustment if we start on Mondays. 273 // make an extra adjustment if we start on Mondays.
274 if ( d->onMonday ) 274 if ( d->onMonday )
275 effective_day--; 275 effective_day--;
276 row = effective_day / 7; 276 row = effective_day / 7;
277 col = effective_day % 7; 277 col = effective_day % 7;
278} 278}
279 279
280void DateBookMonthTable::dayClicked( int row, int col ) 280void DateBookMonthTable::dayClicked( int row, int col )
281{ 281{
282 changeDaySelection( row, col ); 282 changeDaySelection( row, col );
283 emit dateClicked( selYear, selMonth, selDay ); 283 emit dateClicked( selYear, selMonth, selDay );
284} 284}
285 285
286void DateBookMonthTable::dragDay( int row, int col ) 286void DateBookMonthTable::dragDay( int row, int col )
287{ 287{
288 changeDaySelection( row, col ); 288 changeDaySelection( row, col );
289} 289}
290 290
291void DateBookMonthTable::changeDaySelection( int row, int col ) 291void DateBookMonthTable::changeDaySelection( int row, int col )
292{ 292{
293 DayItemMonth *i = (DayItemMonth*)item( row, col ); 293 DayItemMonth *i = (DayItemMonth*)item( row, col );
294 if ( !i ) 294 if ( !i )
295 return; 295 return;
296 switch ( i->type() ) { 296 switch ( i->type() ) {
297 case Calendar::Day::ThisMonth: 297 case Calendar::Day::ThisMonth:
298 selMonth = month; 298 selMonth = month;
299 break; 299 break;
300 case Calendar::Day::PrevMonth: 300 case Calendar::Day::PrevMonth:
301 selMonth = month-1; 301 selMonth = month-1;
302 break; 302 break;
303 default: 303 default:
304 selMonth = month+1; 304 selMonth = month+1;
305 } 305 }
306 306
307 selYear = year; 307 selYear = year;
308 if ( selMonth <= 0 ) { 308 if ( selMonth <= 0 ) {
309 selMonth = 12; 309 selMonth = 12;
310 selYear--; 310 selYear--;
311 } else if ( selMonth > 12 ) { 311 } else if ( selMonth > 12 ) {
312 selMonth = 1; 312 selMonth = 1;
313 selYear++; 313 selYear++;
314 } 314 }
315 selDay = i->day(); 315 selDay = i->day();
316} 316}
317 317
318 318
319void DateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * ) 319void DateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * )
320{ 320{
321 dayClicked( currentRow(), currentColumn() ); 321 dayClicked( currentRow(), currentColumn() );
322} 322}
323 323
324void DateBookMonthTable::getEvents() 324void DateBookMonthTable::getEvents()
325{ 325{
326 if ( !db ) 326 if ( !db )
327 return; 327 return;
328 328
329 QDate dtStart( year, month, 1 ); 329 QDate dtStart( year, month, 1 );
330 d->mMonthEvents = db->getEffectiveEvents( dtStart, 330 d->mMonthEvents = db->getEffectiveEvents( dtStart,
331 QDate( year, month, 331 QDate( year, month,
332 dtStart.daysInMonth() ) ); 332 dtStart.daysInMonth() ) );
333 QValueListIterator<EffectiveEvent> it = d->mMonthEvents.begin(); 333 QValueListIterator<EffectiveEvent> it = d->mMonthEvents.begin();
334 // now that the events are sorted, basically go through the list, make 334 // now that the events are sorted, basically go through the list, make
335 // a small list for every day and set it for each item... 335 // a small list for every day and set it for each item...
336 // clear all the items... 336 // clear all the items...
337 while ( it != d->mMonthEvents.end() ) { 337 while ( it != d->mMonthEvents.end() ) {
338 QValueList<EffectiveEvent> dayEvent; 338 QValueList<EffectiveEvent> dayEvent;
339 EffectiveEvent e = *it; 339 EffectiveEvent e = *it;
340 ++it; 340 ++it;
341 dayEvent.append( e ); 341 dayEvent.append( e );
342 while ( it != d->mMonthEvents.end() 342 while ( it != d->mMonthEvents.end()
343 && e.date() == (*it).date() ) { 343 && e.date() == (*it).date() ) {
344 dayEvent.append( *it ); 344 dayEvent.append( *it );
345 ++it; 345 ++it;
346 } 346 }
347 int row, col; 347 int row, col;
348 findDay( e.date().day(), row, col ); 348 findDay( e.date().day(), row, col );
349 DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) ); 349 DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) );
350 w->setEvents( dayEvent ); 350 w->setEvents( dayEvent );
351 updateCell( row, col ); 351 updateCell( row, col );
352 dayEvent.clear(); 352 dayEvent.clear();
353 } 353 }
354} 354}
355 355
356 356
357void DateBookMonthTable::setupLabels() 357void DateBookMonthTable::setupLabels()
358{ 358{
359 for ( int i = 0; i < 7; ++i ) { 359 for ( int i = 0; i < 7; ++i ) {
360 // horizontalHeader()->resizeSection( i, 30 ); 360 // horizontalHeader()->resizeSection( i, 30 );
361 // setColumnStretchable( i, TRUE ); 361 // setColumnStretchable( i, TRUE );
362 if ( d->onMonday ) 362 if ( d->onMonday )
363 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i + 1 ) ); 363 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i + 1 ) );
364 else { 364 else {
365 if ( i == 0 ) 365 if ( i == 0 )
366 horizontalHeader()->setLabel( i, Calendar::nameOfDay( 7 ) ); 366 horizontalHeader()->setLabel( i, Calendar::nameOfDay( 7 ) );
367 else 367 else
368 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i ) ); 368 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i ) );
369 } 369 }
370 } 370 }
371} 371}
372 372
373 373
374//--------------------------------------------------------------------------- 374//---------------------------------------------------------------------------
375 375
376DateBookMonth::DateBookMonth( QWidget *parent, const char *name, bool ac, 376DateBookMonth::DateBookMonth( QWidget *parent, const char *name, bool ac,
377 DateBookDB *data ) 377 DateBookDB *data )
378 : QVBox( parent, name ), 378 : QVBox( parent, name ),
379 autoClose( ac ) 379 autoClose( ac )
380{ 380{
381 setFocusPolicy(StrongFocus); 381 setFocusPolicy(StrongFocus);
382 year = QDate::currentDate().year(); 382 year = QDate::currentDate().year();
383 month = QDate::currentDate().month(); 383 month = QDate::currentDate().month();
384 day = QDate::currentDate().day(); 384 day = QDate::currentDate().day();
385 header = new DateBookMonthHeader( this, "DateBookMonthHeader" ); 385 header = new DateBookMonthHeader( this, "DateBookMonthHeader" );
386 table = new DateBookMonthTable( this, "DateBookMonthTable", data ); 386 table = new DateBookMonthTable( this, "DateBookMonthTable", data );
387 header->setDate( year, month ); 387 header->setDate( year, month );
388 table->setDate( year, month, QDate::currentDate().day() ); 388 table->setDate( year, month, QDate::currentDate().day() );
389 header->setFocusPolicy(NoFocus); 389 header->setFocusPolicy(NoFocus);
390 table->setFocusPolicy(NoFocus); 390 table->setFocusPolicy(NoFocus);
391 connect( header, SIGNAL( dateChanged( int, int ) ), 391 connect( header, SIGNAL( dateChanged( int, int ) ),
392 this, SLOT( setDate( int, int ) ) ); 392 this, SLOT( setDate( int, int ) ) );
393 connect( table, SIGNAL( dateClicked( int, int, int ) ), 393 connect( table, SIGNAL( dateClicked( int, int, int ) ),
394 this, SLOT( finalDate(int, int, int) ) ); 394 this, SLOT( finalDate(int, int, int) ) );
395 connect( qApp, SIGNAL(weekChanged(bool)), this, 395 connect( qApp, SIGNAL(weekChanged(bool)), this,
396 SLOT(slotWeekChange(bool)) ); 396 SLOT(slotWeekChange(bool)) );
397 table->setFocus(); 397 table->setFocus();
398} 398}
399 399
400DateBookMonth::~DateBookMonth() 400DateBookMonth::~DateBookMonth()
401{ 401{
402 402
403} 403}
404 404
405void DateBookMonth::setDate( int y, int m ) 405void DateBookMonth::setDate( int y, int m )
406{ 406{
407 /* only change the date if this is a different date, 407 /* only change the date if this is a different date,
408 * other wise we may mistakenly overide the day */ 408 * other wise we may mistakenly overide the day */
409 if ( (y != year) || (m != month) ) { 409 if ( (y != year) || (m != month) ) {
410 year = y; 410 year = y;
411 month = m; 411 month = m;
412 QDate nd( y, m, 1 ); 412 QDate nd( y, m, 1 );
413 if ( nd.daysInMonth() < day ) 413 if ( nd.daysInMonth() < day )
414 day = nd.daysInMonth(); 414 day = nd.daysInMonth();
415 table->setDate( year, month, day ); 415 table->setDate( year, month, day );
416 } 416 }
417} 417}
418 418
419void DateBookMonth::setDate( int y, int m, int d ) 419void DateBookMonth::setDate( int y, int m, int d )
420{ 420{
421 header->setDate( y, m); 421 header->setDate( y, m);
422 table->setDate( y, m, d); 422 table->setDate( y, m, d);
423 year = y; 423 year = y;
424 month = m; 424 month = m;
425 day = d; 425 day = d;
426} 426}
427 427
428/* called when we wish to close or pass back the date */ 428/* called when we wish to close or pass back the date */
429void DateBookMonth::finalDate(int y, int m, int d) 429void DateBookMonth::finalDate(int y, int m, int d)
430{ 430{
431 setDate( y, m, d ); 431 setDate( y, m, d );
432 432
433 emit dateClicked(y, m, d); 433 emit dateClicked(y, m, d);
434 // emit dateClicked(QDate(y, m, d).toString()); 434 // emit dateClicked(QDate(y, m, d).toString());
435 435
436 if ( autoClose && parentWidget() ) 436 if ( autoClose && parentWidget() )
437 parentWidget()->close(); 437 parentWidget()->close();
438} 438}
439 439
440void DateBookMonth::setDate( QDate d) 440void DateBookMonth::setDate( QDate d)
441{ 441{
442 setDate(d.year(), d.month(), d.day()); 442 setDate(d.year(), d.month(), d.day());
443} 443}
444 444
445void DateBookMonth::redraw() 445void DateBookMonth::redraw()
446{ 446{
447 table->setDate( year, month, day ); 447 table->setDate( year, month, day );
448 table->redraw(); 448 table->redraw();
449} 449}
450 450
451QDate DateBookMonth::selectedDate() const 451QDate DateBookMonth::selectedDate() const
452{ 452{
453 if ( !table ) 453 if ( !table )
454 return QDate::currentDate(); 454 return QDate::currentDate();
455 int y, m, d; 455 int y, m, d;
456 table->getDate( y, m, d ); 456 table->getDate( y, m, d );
457 qDebug( "got %d %d %d", y, m, d ); 457 qDebug( "got %d %d %d", y, m, d );
458 return QDate( y, m, d ); 458 return QDate( y, m, d );
459} 459}
460 460
461void DateBookMonth::slotWeekChange( bool startOnMonday ) 461void DateBookMonth::slotWeekChange( bool startOnMonday )
462{ 462{
463 table->setWeekStart( startOnMonday ); 463 table->setWeekStart( startOnMonday );
464} 464}
465 465
466void DateBookMonth::keyPressEvent( QKeyEvent *e ) 466void DateBookMonth::keyPressEvent( QKeyEvent *e )
467{ 467{
468 switch(e->key()) { 468 switch(e->key()) {
469 case Key_Up: 469 case Key_Up:
470 setDate(QDate(year, month, day).addDays(-7)); 470 setDate(QDate(year, month, day).addDays(-7));
471 break; 471 break;
472 case Key_Down: 472 case Key_Down:
473 setDate(QDate(year, month, day).addDays(7)); 473 setDate(QDate(year, month, day).addDays(7));
474 break; 474 break;
475 case Key_Left: 475 case Key_Left:
476 setDate(QDate(year, month, day).addDays(-1)); 476 setDate(QDate(year, month, day).addDays(-1));
477 break; 477 break;
478 case Key_Right: 478 case Key_Right:
479 setDate(QDate(year, month, day).addDays(1)); 479 setDate(QDate(year, month, day).addDays(1));
480 break; 480 break;
481 case Key_Space: 481 case Key_Space:
482 qWarning("space"); 482 qWarning("space");
483 emit dateClicked(year, month, day); 483 emit dateClicked(year, month, day);
484 if ( autoClose && parentWidget() ) 484 if ( autoClose && parentWidget() )
485 parentWidget()->close(); 485 parentWidget()->close();
486 break; 486 break;
487 default: 487 default:
488 qWarning("ignore"); 488 qWarning("ignore");
489 e->ignore(); 489 e->ignore();
490 break; 490 break;
491 } 491 }
492} 492}
493 493
494//--------------------------------------------------------------------------- 494//---------------------------------------------------------------------------
495class DayItemMonthPrivate 495class DayItemMonthPrivate
496{ 496{
497public: 497public:
498 DayItemMonthPrivate() {}; 498 DayItemMonthPrivate() {};
499 ~DayItemMonthPrivate() { mDayEvents.clear(); }; 499 ~DayItemMonthPrivate() { mDayEvents.clear(); };
500 QValueList<EffectiveEvent> mDayEvents; 500 QValueList<EffectiveEvent> mDayEvents;
501}; 501};
502 502
503DayItemMonth::DayItemMonth( QTable *table, EditType et, const QString &t ) 503DayItemMonth::DayItemMonth( QTable *table, EditType et, const QString &t )
504 : QTableItem( table, et, t ) 504 : QTableItem( table, et, t )
505{ 505{
506 d = new DayItemMonthPrivate(); 506 d = new DayItemMonthPrivate();
507} 507}
508 508
509DayItemMonth::~DayItemMonth() 509DayItemMonth::~DayItemMonth()
510{ 510{
511 daysEvents.clear(); 511 daysEvents.clear();
512 delete d; 512 delete d;
513} 513}
514 514
515void DayItemMonth::setEvents( const QValueList<EffectiveEvent> &effEv ) 515void DayItemMonth::setEvents( const QValueList<EffectiveEvent> &effEv )
516{ 516{
517 d->mDayEvents = effEv; 517 d->mDayEvents = effEv;
518} 518}
519 519
520void DayItemMonth::clearEffEvents() 520void DayItemMonth::clearEffEvents()
521{ 521{
522 d->mDayEvents.clear(); 522 d->mDayEvents.clear();
523} 523}
524 524
525void DayItemMonth::paint( QPainter *p, const QColorGroup &cg, 525void DayItemMonth::paint( QPainter *p, const QColorGroup &cg,
526 const QRect &cr, bool selected ) 526 const QRect &cr, bool selected )
527{ 527{
528 QColorGroup g( cg ); 528 QColorGroup g( cg );
529 g.setBrush( QColorGroup::Base, back ); 529 g.setBrush( QColorGroup::Base, back );
530 g.setColor( QColorGroup::Text, forg ); 530 g.setColor( QColorGroup::Text, forg );
531 p->fillRect( 0, 0, cr.width(), cr.height(), selected ? g.brush( QColorGroup::Highlight ) : g.brush( QColorGroup::Base ) ); 531 p->fillRect( 0, 0, cr.width(), cr.height(), selected ? g.brush( QColorGroup::Highlight ) : g.brush( QColorGroup::Base ) );
532 532
533 if ( selected ) 533 if ( selected )
534 p->setPen( g.highlightedText() ); 534 p->setPen( g.highlightedText() );
535 else 535 else
536 p->setPen( g.text() ); 536 p->setPen( g.text() );
537 537
538 p->save(); 538 p->save();
539 QFont f = p->font(); 539 QFont f = p->font();
540 f.setPointSize( ( f.pointSize() / 3 ) * 2 ); 540 f.setPointSize( ( f.pointSize() / 3 ) * 2 );
541 p->setFont( f ); 541 p->setFont( f );
542 QFontMetrics fm( f ); 542 QFontMetrics fm( f );
543 p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) ); 543 p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) );
544 p->restore(); 544 p->restore();
545 // Put indicators for something like this, (similar to PalmOS) 545 // Put indicators for something like this, (similar to PalmOS)
546 // Before noon: item at top of the day 546 // Before noon: item at top of the day
547 // At noon: put a small item at the middle 547 // At noon: put a small item at the middle
548 // After noon: put an indicator at the bottom of the day 548 // After noon: put an indicator at the bottom of the day
549 // an all day event: mark with a circle in the middle (a la DateBook+) 549 // an all day event: mark with a circle in the middle (a la DateBook+)
550 bool beforeNoon = false; 550 bool beforeNoon = false;
551 bool atNoon = false; 551 bool atNoon = false;
552 bool afterNoon = false; 552 bool afterNoon = false;
553 bool bAllDay = false; 553 bool bAllDay = false;
554 bool bRepeatAfter = false; 554 bool bRepeatAfter = false;
555 bool bRepeatBefore = false; 555 bool bRepeatBefore = false;
556 bool bRepeatNoon = false; 556 bool bRepeatNoon = false;
557 bool straddleAfter = false; 557 bool straddleAfter = false;
558 bool straddleBefore = false; 558 bool straddleBefore = false;
559 QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin(); 559 QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin();
560 for ( ; itDays != d->mDayEvents.end(); ++itDays ) { 560 for ( ; itDays != d->mDayEvents.end(); ++itDays ) {
561 if ( (*itDays).event().type() == Event::AllDay ) 561 if ( (*itDays).event().type() == Event::AllDay )
562 bAllDay = TRUE; 562 bAllDay = TRUE;
563 else if ( (*itDays).start().hour() < 12 ) { 563 else if ( (*itDays).start().hour() < 12 ) {
564 beforeNoon = TRUE; 564 beforeNoon = TRUE;
565 if ( (*itDays).end().hour() > 12 ) { 565 if ( (*itDays).end().hour() > 12 ) {
566 atNoon = TRUE; 566 atNoon = TRUE;
567 straddleBefore = TRUE; 567 straddleBefore = TRUE;
568 } 568 }
569 if ( (*itDays).end().hour() > 14 || 569 if ( (*itDays).end().hour() > 14 ||
570 (*itDays).end().hour() == 14 && (*itDays).end().minute() > 0 ) { 570 (*itDays).end().hour() == 14 && (*itDays).end().minute() > 0 ) {
571 afterNoon = TRUE; 571 afterNoon = TRUE;
572 straddleAfter = TRUE; 572 straddleAfter = TRUE;
573 } 573 }
574 if ( (*itDays).event().hasRepeat() ) 574 if ( (*itDays).event().hasRepeat() )
575 bRepeatBefore = TRUE; 575 bRepeatBefore = TRUE;
576 } else if ( (*itDays).start().hour() == 12 ) { 576 } else if ( (*itDays).start().hour() == 12 ) {
577 if ( !atNoon ) 577 if ( !atNoon )
578 atNoon = TRUE; 578 atNoon = TRUE;
579 if ( (*itDays).event().hasRepeat() ) 579 if ( (*itDays).event().hasRepeat() )
580 bRepeatNoon = TRUE; 580 bRepeatNoon = TRUE;
581 if ( (*itDays).end().hour() > 14 || 581 if ( (*itDays).end().hour() > 14 ||
582 (*itDays).end().hour() == 14 && (*itDays).end().minute() > 0 ) { 582 (*itDays).end().hour() == 14 && (*itDays).end().minute() > 0 ) {
583 afterNoon = TRUE; 583 afterNoon = TRUE;
584 straddleAfter = TRUE; 584 straddleAfter = TRUE;
585 } 585 }
586 } else if ( (*itDays).start().hour() > 12 ) { 586 } else if ( (*itDays).start().hour() > 12 ) {
587 afterNoon = TRUE; 587 afterNoon = TRUE;
588 if ( (*itDays).event().hasRepeat() ) 588 if ( (*itDays).event().hasRepeat() )
589 bRepeatAfter = TRUE; 589 bRepeatAfter = TRUE;
590 } 590 }
591 } 591 }
592 int x = cr.width() - 13; 592 int x = cr.width() - 13;
593 if ( beforeNoon ) { 593 if ( beforeNoon ) {
594 p->setBrush( blue ); 594 p->setBrush( blue );
595 p->drawRect( x, 2, 10, 10 ); 595 p->drawRect( x, 2, 10, 10 );
596 if ( bRepeatBefore ) 596 if ( bRepeatBefore )
597 p->fillRect( x + 5, 4, 3, 3, white ); 597 p->fillRect( x + 5, 4, 3, 3, white );
598 } 598 }
599 if ( atNoon ) { 599 if ( atNoon ) {
600 p->setBrush( blue ); 600 p->setBrush( blue );
601 p->drawRect( x, 14, 10, 5 ); 601 p->drawRect( x, 14, 10, 5 );
602 if ( bRepeatNoon ) 602 if ( bRepeatNoon )
603 p->fillRect( x + 5, 16, 3, 2, white ); 603 p->fillRect( x + 5, 16, 3, 2, white );
604 } 604 }
605 if ( straddleBefore ) { 605 if ( straddleBefore ) {
606 p->drawLine( x, 11, x, 14 ); 606 p->drawLine( x, 11, x, 14 );
607 p->fillRect( x + 1, 11, 8, 4, blue ); 607 p->fillRect( x + 1, 11, 8, 4, blue );
608 p->drawLine( x + 9, 11, x + 9, 14 ); 608 p->drawLine( x + 9, 11, x + 9, 14 );
609 } 609 }
610 if ( afterNoon ) { 610 if ( afterNoon ) {
611 p->setBrush( blue ); 611 p->setBrush( blue );
612 p->drawRect( x, 21, 10, 10 ); 612 p->drawRect( x, 21, 10, 10 );
613 if ( bRepeatAfter ) 613 if ( bRepeatAfter )
614 p->fillRect( x + 5, 23, 3, 3, white ); 614 p->fillRect( x + 5, 23, 3, 3, white );
615 } 615 }
616 if ( straddleAfter ) { 616 if ( straddleAfter ) {
617 p->drawLine( x, 18, x, 21 ); 617 p->drawLine( x, 18, x, 21 );
618 p->fillRect( x + 1, 18, 8, 4, blue ); 618 p->fillRect( x + 1, 18, 8, 4, blue );
619 p->drawLine( x + 9, 18, x + 9, 21 ); 619 p->drawLine( x + 9, 18, x + 9, 21 );
620 } 620 }
621 if ( bAllDay ) { 621 if ( bAllDay ) {
622 p->setBrush( green ); 622 p->setBrush( green );
623 p->drawEllipse( cr.width() / 2 - 7, cr.height() / 2 - 5, 10, 10 ); 623 p->drawEllipse( cr.width() / 2 - 7, cr.height() / 2 - 5, 10, 10 );
624 } 624 }
625} 625}
626 626
627 627
628 628
629void DayItemMonth::setType( Calendar::Day::Type t ) 629void DayItemMonth::setType( Calendar::Day::Type t )
630{ 630{
631 switch ( t ) { 631 switch ( t ) {
632 case Calendar::Day::PrevMonth: 632 case Calendar::Day::PrevMonth:
633 case Calendar::Day::NextMonth: 633 case Calendar::Day::NextMonth:
634 back = QBrush( QColor( 224, 224, 224 ) ); 634 back = QBrush( QColor( 224, 224, 224 ) );
635 forg = black; 635 forg = black;
636 break; 636 break;
637 case Calendar::Day::ThisMonth: 637 case Calendar::Day::ThisMonth:
638 back = QBrush( white ); 638 back = QBrush( white );
639 forg = black; 639 forg = black;
640 break; 640 break;
641 } 641 }
642 typ = t; 642 typ = t;
643} 643}
644 644
645 645
646 646
647DateButton::DateButton( bool longDate, QWidget *parent, const char * name ) 647DateButton::DateButton( bool longDate, QWidget *parent, const char * name )
648 :QPushButton( parent, name ) 648 :QPushButton( parent, name )
649{ 649{
650 longFormat = longDate; 650 longFormat = longDate;
651 df = DateFormat('/', DateFormat::MonthDayYear, DateFormat::MonthDayYear); 651 df = DateFormat('/', DateFormat::MonthDayYear, DateFormat::MonthDayYear);
652 setDate( QDate::currentDate() ); 652 setDate( QDate::currentDate() );
653 653
654 connect(this,SIGNAL(pressed()),this,SLOT(pickDate())); 654 connect(this,SIGNAL(pressed()),this,SLOT(pickDate()));
655 655
656 656
657} 657}
658 658
659 659
660void DateButton::pickDate() 660void DateButton::pickDate()
661{ 661{
662 static QPopupMenu *m1 = 0; 662 static QPopupMenu *m1 = 0;
663 static DateBookMonth *picker = 0; 663 static DateBookMonth *picker = 0;
664 if ( !m1 ) { 664 if ( !m1 ) {
665 m1 = new QPopupMenu( this ); 665 m1 = new QPopupMenu( this );
666 picker = new DateBookMonth( m1, 0, TRUE ); 666 picker = new DateBookMonth( m1, 0, TRUE );
667 m1->insertItem( picker ); 667 m1->insertItem( picker );
668 connect( picker, SIGNAL( dateClicked( int, int, int ) ), 668 connect( picker, SIGNAL( dateClicked( int, int, int ) ),
669 this, SLOT( setDate( int, int, int ) ) ); 669 this, SLOT( setDate( int, int, int ) ) );
670 connect( picker, SIGNAL( dateClicked( int, int, int ) ), 670 connect( picker, SIGNAL( dateClicked( int, int, int ) ),
671 this, SIGNAL( dateSelected( int, int, int ) ) ); 671 this, SIGNAL( dateSelected( int, int, int ) ) );
672 connect( m1, SIGNAL( aboutToHide() ), 672 connect( m1, SIGNAL( aboutToHide() ),
673 this, SLOT( gotHide() ) ); 673 this, SLOT( gotHide() ) );
674 } 674 }
675 picker->slotWeekChange( weekStartsMonday ); 675 picker->slotWeekChange( weekStartsMonday );
676 picker->setDate( currDate.year(), currDate.month(), currDate.day() ); 676 picker->setDate( currDate.year(), currDate.month(), currDate.day() );
677 m1->popup(mapToGlobal(QPoint(0,height()))); 677 m1->popup(mapToGlobal(QPoint(0,height())));
678 picker->setFocus(); 678 picker->setFocus();
679} 679}
680 680
681 681
682void DateButton::gotHide() 682void DateButton::gotHide()
683{ 683{
684 // we have to redo the button... 684 // we have to redo the button...
685 setDown( false ); 685 setDown( false );
686} 686}
687 687
688 688
689// void dateSelected( int year, int month, int day ); 689// void dateSelected( int year, int month, int day );
690 690
691void DateButton::setWeekStartsMonday( int b ) 691void DateButton::setWeekStartsMonday( int b )
692{ 692{
693 weekStartsMonday = b; 693 weekStartsMonday = b;
694} 694}
695 695
696void DateButton::setDate( int y, int m, int d ) 696void DateButton::setDate( int y, int m, int d )
697{ 697{
698 setDate( QDate( y,m,d) ); 698 setDate( QDate( y,m,d) );
699} 699}
700 700
701void DateButton::setDate( QDate d ) 701void DateButton::setDate( QDate d )
702{ 702{
703 currDate = d; 703 currDate = d;
704 setText( longFormat ? TimeString::longDateString( d, df ) : 704 setText( longFormat ? TimeString::longDateString( d, df ) :
705 TimeString::shortDate( d, df ) ); 705 TimeString::shortDate( d, df ) );
706 706
707} 707}
708 708
709void DateButton::setDateFormat( DateFormat f ) 709void DateButton::setDateFormat( DateFormat f )
710{ 710{
711 df = f; 711 df = f;
712 setDate( currDate ); 712 setDate( currDate );
713} 713}