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