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