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