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