summaryrefslogtreecommitdiff
path: root/core/pim/datebook/dateentryimpl.cpp
Unidiff
Diffstat (limited to 'core/pim/datebook/dateentryimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/dateentryimpl.cpp97
1 files changed, 62 insertions, 35 deletions
diff --git a/core/pim/datebook/dateentryimpl.cpp b/core/pim/datebook/dateentryimpl.cpp
index b2e3e3a..1c43363 100644
--- a/core/pim/datebook/dateentryimpl.cpp
+++ b/core/pim/datebook/dateentryimpl.cpp
@@ -30,57 +30,63 @@
30#include <qpe/tzselect.h> 30#include <qpe/tzselect.h>
31 31
32#include <qcheckbox.h> 32#include <qcheckbox.h>
33#include <qcombobox.h> 33#include <qcombobox.h>
34#include <qlayout.h> 34#include <qlayout.h>
35#include <qlineedit.h> 35#include <qlineedit.h>
36#include <qmultilineedit.h> 36#include <qmultilineedit.h>
37#include <qpopupmenu.h> 37#include <qpopupmenu.h>
38#include <qscrollview.h> 38#include <qscrollview.h>
39#include <qspinbox.h> 39#include <qspinbox.h>
40#include <qtoolbutton.h> 40#include <qtoolbutton.h>
41 41
42#include "timepicker.h"
43
42#include <stdlib.h> 44#include <stdlib.h>
43 45
44#include <stdiostream.h> 46#include <stdiostream.h>
45 47
46/* 48/*
47 * Constructs a DateEntry which is a child of 'parent', with the 49 * Constructs a DateEntry which is a child of 'parent', with the
48 * name 'name' and widget flags set to 'f' 50 * name 'name' and widget flags set to 'f'
49 * 51 *
50 * The dialog will by default be modeless, unless you set 'modal' to 52 * The dialog will by default be modeless, unless you set 'modal' to
51 * TRUE to construct a modal dialog. 53 * TRUE to construct a modal dialog.
52 */ 54 */
53 55
54DateEntry::DateEntry( bool startOnMonday, const QDateTime &start, 56DateEntry::DateEntry( bool startOnMonday, const QDateTime &start,
55 const QDateTime &end, bool whichClock, QWidget* parent, 57 const QDateTime &end, bool whichClock, QWidget* parent,
56 const char* name ) 58 const char* name )
57 : DateEntryBase( parent, name ), 59 : DateEntryBase( parent, name ),
58 ampm( whichClock ), 60 ampm( whichClock ),
59 startWeekOnMonday( startOnMonday ) 61 startWeekOnMonday( startOnMonday )
60{ 62{
61 init(); 63 init();
62 setDates(start,end); 64 setDates(start,end);
63 setFocusProxy(comboDescription); 65 setFocusProxy(comboDescription);
64} 66}
65 67
66static void addOrPick( QComboBox* combo, const QString& t ) 68static void addOrPick( QComboBox* combo, const QString& t )
67{ 69{
70 // Pick an item if one excists
68 for (int i=0; i<combo->count(); i++) { 71 for (int i=0; i<combo->count(); i++) {
69 if ( combo->text(i) == t ) { 72 if ( combo->text(i) == t ) {
70 combo->setCurrentItem(i); 73 combo->setCurrentItem(i);
71 return; 74 return;
72 } 75 }
73 } 76 }
74 combo->setEditText(t); 77
78 // Else add one
79 combo->insertItem(t);
80 combo->setCurrentItem(combo->count()-1);
75} 81}
76 82
77DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, 83DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock,
78 QWidget* parent, const char* name ) 84 QWidget* parent, const char* name )
79 : DateEntryBase( parent, name ), 85 : DateEntryBase( parent, name ),
80 ampm( whichClock ), 86 ampm( whichClock ),
81 startWeekOnMonday( startOnMonday ) 87 startWeekOnMonday( startOnMonday )
82{ 88{
83 init(); 89 init();
84 setDates(event.start(),event.end()); 90 setDates(event.start(),event.end());
85 comboCategory->setCategories( event.categories(), "Calendar", tr("Calendar") ); 91 comboCategory->setCategories( event.categories(), "Calendar", tr("Calendar") );
86 if(!event.description().isEmpty()) 92 if(!event.description().isEmpty())
@@ -94,63 +100,68 @@ DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock,
94 spinAlarm->setValue(event.alarmTime()); 100 spinAlarm->setValue(event.alarmTime());
95 if ( event.alarmSound() != Event::Silent ) 101 if ( event.alarmSound() != Event::Silent )
96 comboSound->setCurrentItem( 1 ); 102 comboSound->setCurrentItem( 1 );
97 if ( event.hasRepeat() ) { 103 if ( event.hasRepeat() ) {
98 rp = event.repeatPattern(); 104 rp = event.repeatPattern();
99 cmdRepeat->setText( tr("Repeat...") ); 105 cmdRepeat->setText( tr("Repeat...") );
100 } 106 }
101 setRepeatLabel(); 107 setRepeatLabel();
102} 108}
103 109
104void DateEntry::setDates( const QDateTime& s, const QDateTime& e ) 110void DateEntry::setDates( const QDateTime& s, const QDateTime& e )
105{ 111{
106 int shour,
107 ehour;
108 QString strStart,
109 strEnd;
110 startDate = s.date(); 112 startDate = s.date();
111 endDate = e.date(); 113 endDate = e.date();
112 startTime = s.time(); 114 startTime = s.time();
113 endTime = e.time(); 115 endTime = e.time();
114 startDateChanged( s.date().year(), s.date().month(), s.date().day() ); 116 startDateChanged( s.date().year(), s.date().month(), s.date().day() );
117 endDateChanged( e.date().year(), e.date().month(), e.date().day() );
118 updateTimeEdit(true,true);
119}
120
121void DateEntry::updateTimeEdit(bool s, bool e) {
122
123 // Comboboxes
124 QString strStart, strEnd;
125 int shour, ehour;
115 if ( ampm ) { 126 if ( ampm ) {
116 shour = s.time().hour(); 127 shour = startTime.hour();
117 ehour = e.time().hour(); 128 ehour = endTime.hour();
118 if ( shour >= 12 ) { 129 if ( shour >= 12 ) {
119 if ( shour > 12 ) 130 if ( shour > 12 )
120 shour -= 12; 131 shour -= 12;
121 strStart.sprintf( "%d:%02d PM", shour, s.time().minute() ); 132 strStart.sprintf( "%d:%02d PM", shour, startTime.minute() );
122 } else { 133 } else {
123 if ( shour == 0 ) 134 if ( shour == 0 )
124 shour = 12; 135 shour = 12;
125 strStart.sprintf( "%d:%02d AM", shour, s.time().minute() ); 136 strStart.sprintf( "%d:%02d AM", shour, startTime.minute() );
126 } 137 }
127 if ( ehour == 24 && e.time().minute() == 0 ) { 138 if ( ehour == 24 && endTime.minute() == 0 ) {
128 strEnd = "11:59 PM"; // or "midnight" 139 strEnd = "11:59 PM"; // or "midnight"
129 } else if ( ehour >= 12 ) { 140 } else if ( ehour >= 12 ) {
130 if ( ehour > 12 ) 141 if ( ehour > 12 )
131 ehour -= 12; 142 ehour -= 12;
132 strEnd.sprintf( "%d:%02d PM", ehour, e.time().minute() ); 143 strEnd.sprintf( "%d:%02d PM", ehour, endTime.minute() );
133 } else { 144 } else {
134 if ( ehour == 0 ) 145 if ( ehour == 0 )
135 ehour = 12; 146 ehour = 12;
136 strEnd.sprintf( "%d:%02d AM", ehour, e.time().minute() ); 147 strEnd.sprintf( "%d:%02d AM", ehour, endTime.minute() );
137 } 148 }
138 } else { 149 } else {
139 strStart.sprintf( "%02d:%02d", s.time().hour(), s.time().minute() ); 150 strStart.sprintf( "%02d:%02d", startTime.hour(), startTime.minute() );
140 strEnd.sprintf( "%02d:%02d", e.time().hour(), e.time().minute() ); 151 strEnd.sprintf( "%02d:%02d", endTime.hour(), endTime.minute() );
141 } 152 }
142 addOrPick(comboStart, strStart ); 153
143 endDateChanged( e.date().year(), e.date().month(), e.date().day() ); 154 if (s) comboStart->setText(strStart);
144 addOrPick(comboEnd, strEnd ); 155 if (e) comboEnd->setText(strEnd);
145} 156}
146 157
147void DateEntry::init() 158void DateEntry::init()
148{ 159{
149 comboDescription->setInsertionPolicy(QComboBox::AtCurrent); 160 comboDescription->setInsertionPolicy(QComboBox::AtCurrent);
150 comboLocation->setInsertionPolicy(QComboBox::AtCurrent); 161 comboLocation->setInsertionPolicy(QComboBox::AtCurrent);
151 162
152 initCombos(); 163 initCombos();
153 QPopupMenu *m1 = new QPopupMenu( this ); 164 QPopupMenu *m1 = new QPopupMenu( this );
154 startPicker = new DateBookMonth( m1, 0, TRUE ); 165 startPicker = new DateBookMonth( m1, 0, TRUE );
155 m1->insertItem( startPicker ); 166 m1->insertItem( startPicker );
156 buttonStart->setPopup( m1 ); 167 buttonStart->setPopup( m1 );
@@ -162,24 +173,28 @@ void DateEntry::init()
162 this, SLOT( endDateChanged( int, int, int ) ) ); 173 this, SLOT( endDateChanged( int, int, int ) ) );
163 connect( qApp, SIGNAL( clockChanged( bool ) ), 174 connect( qApp, SIGNAL( clockChanged( bool ) ),
164 this, SLOT( slotChangeClock( bool ) ) ); 175 this, SLOT( slotChangeClock( bool ) ) );
165 connect( qApp, SIGNAL(weekChanged(bool)), 176 connect( qApp, SIGNAL(weekChanged(bool)),
166 this, SLOT(slotChangeStartOfWeek(bool)) ); 177 this, SLOT(slotChangeStartOfWeek(bool)) );
167 178
168 QPopupMenu *m2 = new QPopupMenu( this ); 179 QPopupMenu *m2 = new QPopupMenu( this );
169 endPicker = new DateBookMonth( m2, 0, TRUE ); 180 endPicker = new DateBookMonth( m2, 0, TRUE );
170 m2->insertItem( endPicker ); 181 m2->insertItem( endPicker );
171 buttonEnd->setPopup( m2 ); 182 buttonEnd->setPopup( m2 );
172 connect( endPicker, SIGNAL( dateClicked( int, int, int ) ), 183 connect( endPicker, SIGNAL( dateClicked( int, int, int ) ),
173 this, SLOT( endDateChanged( int, int, int ) ) ); 184 this, SLOT( endDateChanged( int, int, int ) ) );
185
186 connect(timePickerStart, SIGNAL( timeChanged(const QTime &) ),
187 this, SLOT( startTimePicked(const QTime &) ));
188 editNote->setFixedVisibleLines(3);
174} 189}
175 190
176/* 191/*
177 * Destroys the object and frees any allocated resources 192 * Destroys the object and frees any allocated resources
178 */ 193 */
179DateEntry::~DateEntry() 194DateEntry::~DateEntry()
180{ 195{
181 // no need to delete child widgets, Qt does it all for us 196 // no need to delete child widgets, Qt does it all for us
182 //cout << "Del: " << comboStart->currentText() << endl; 197 //cout << "Del: " << comboStart->currentText() << endl;
183} 198}
184 199
185/* 200/*
@@ -231,26 +246,30 @@ static QTime parseTime( const QString& s, bool ampm )
231} 246}
232 247
233/* 248/*
234 * public slot 249 * public slot
235 */ 250 */
236void DateEntry::endTimeChanged( const QString &s ) 251void DateEntry::endTimeChanged( const QString &s )
237{ 252{
238 QTime tmpTime = parseTime(s,ampm); 253 QTime tmpTime = parseTime(s,ampm);
239 if ( endDate > startDate || tmpTime >= startTime ) { 254 if ( endDate > startDate || tmpTime >= startTime ) {
240 endTime = tmpTime; 255 endTime = tmpTime;
241 } else { 256 } else {
242 endTime = startTime; 257 endTime = startTime;
243 comboEnd->setCurrentItem( comboStart->currentItem() ); 258 //comboEnd->setCurrentItem( comboStart->currentItem() );
244 } 259 }
260
261}
262
263void DateEntry::endTimeChanged( const QTime &t ) {
245} 264}
246 265
247/* 266/*
248 * public slot 267 * public slot
249 */ 268 */
250void DateEntry::startDateChanged( int y, int m, int d ) 269void DateEntry::startDateChanged( int y, int m, int d )
251{ 270{
252 QDate prev = startDate; 271 QDate prev = startDate;
253 startDate.setYMD( y, m, d ); 272 startDate.setYMD( y, m, d );
254 if ( rp.type == Event::Weekly && 273 if ( rp.type == Event::Weekly &&
255 startDate.dayOfWeek() != prev.dayOfWeek() ) { 274 startDate.dayOfWeek() != prev.dayOfWeek() ) {
256 // if we change the start of a weekly repeating event 275 // if we change the start of a weekly repeating event
@@ -261,50 +280,53 @@ void DateEntry::startDateChanged( int y, int m, int d )
261 } 280 }
262 281
263 buttonStart->setText( TimeString::shortDate( startDate ) ); 282 buttonStart->setText( TimeString::shortDate( startDate ) );
264 283
265 // our pickers must be reset... 284 // our pickers must be reset...
266 startPicker->setDate( y, m, d ); 285 startPicker->setDate( y, m, d );
267 endPicker->setDate( y, m, d ); 286 endPicker->setDate( y, m, d );
268} 287}
269 288
270/* 289/*
271 * public slot 290 * public slot
272 */ 291 */
273void DateEntry::startTimeChanged( int index ) 292void DateEntry::startTimeEdited( const QString &s )
274{ 293{
275 startTime = parseTime(comboStart->text(index),ampm); 294 startTimeChanged(parseTime(s,ampm));
276 changeEndCombo( index ); 295 updateTimeEdit(false,true);
277 //cout << "Start: " << comboStart->currentText() << endl; 296 timePickerStart->setHour(startTime.hour());
297 timePickerStart->setMinute(startTime.minute());
278} 298}
299
300void DateEntry::startTimeChanged( const QTime &t )
301{
302 int duration=startTime.secsTo(endTime);
303 startTime = t;
304 endTime=t.addSecs(duration);
305}
306void DateEntry::startTimePicked( const QTime &t ) {
307 startTimeChanged(t);
308 updateTimeEdit(true,true);
309}
310
279/* 311/*
280 * public slot 312 * public slot
281 */ 313 */
282void DateEntry::typeChanged( const QString &s ) 314void DateEntry::typeChanged( const QString &s )
283{ 315{
284 bool b = s != "All Day"; 316 bool b = s != "All Day";
285 buttonStart->setEnabled( b ); 317 buttonStart->setEnabled( b );
286 comboStart->setEnabled( b ); 318 comboStart->setEnabled( b );
287 comboEnd->setEnabled( b ); 319 comboEnd->setEnabled( b );
288} 320}
289/*
290 * public slot
291 */
292void DateEntry::changeEndCombo( int change )
293{
294 if ( change + 2 < comboEnd->count() )
295 change += 2;
296 comboEnd->setCurrentItem( change );
297 endTimeChanged( comboEnd->currentText() );
298}
299 321
300void DateEntry::slotRepeat() 322void DateEntry::slotRepeat()
301{ 323{
302 // Work around for compiler Bug.. 324 // Work around for compiler Bug..
303 RepeatEntry *e; 325 RepeatEntry *e;
304 326
305 // it is better in my opinion to just grab this from the mother, 327 // it is better in my opinion to just grab this from the mother,
306 // since, this dialog doesn't need to keep track of it... 328 // since, this dialog doesn't need to keep track of it...
307 if ( rp.type != Event::NoRepeat ) 329 if ( rp.type != Event::NoRepeat )
308 e = new RepeatEntry( startWeekOnMonday, rp, startDate, this); 330 e = new RepeatEntry( startWeekOnMonday, rp, startDate, this);
309 else 331 else
310 e = new RepeatEntry( startWeekOnMonday, startDate, this ); 332 e = new RepeatEntry( startWeekOnMonday, startDate, this );
@@ -327,26 +349,29 @@ Event DateEntry::event()
327{ 349{
328 Event ev; 350 Event ev;
329 Event::SoundTypeChoice st; 351 Event::SoundTypeChoice st;
330 ev.setDescription( comboDescription->currentText() ); 352 ev.setDescription( comboDescription->currentText() );
331 ev.setLocation( comboLocation->currentText() ); 353 ev.setLocation( comboLocation->currentText() );
332 ev.setCategories( comboCategory->currentCategories() ); 354 ev.setCategories( comboCategory->currentCategories() );
333 ev.setType( checkAllDay->isChecked() ? Event::AllDay : Event::Normal ); 355 ev.setType( checkAllDay->isChecked() ? Event::AllDay : Event::Normal );
334 if ( startDate > endDate ) { 356 if ( startDate > endDate ) {
335 QDate tmp = endDate; 357 QDate tmp = endDate;
336 endDate = startDate; 358 endDate = startDate;
337 startDate = tmp; 359 startDate = tmp;
338 } 360 }
339 startTime = parseTime( comboStart->currentText(), ampm ); 361
340 endTime = parseTime( comboEnd->currentText(), ampm ); 362 // This is now done in the changed slots
363 // startTime = parseTime( comboStart->text(), ampm );
364 //endTime = parseTime( comboEnd->text(), ampm );
365
341 if ( startTime > endTime && endDate == startDate ) { 366 if ( startTime > endTime && endDate == startDate ) {
342 QTime tmp = endTime; 367 QTime tmp = endTime;
343 endTime = startTime; 368 endTime = startTime;
344 startTime = tmp; 369 startTime = tmp;
345 } 370 }
346 // don't set the time if theres no need too 371 // don't set the time if theres no need too
347 if ( ev.type() == Event::AllDay ) { 372 if ( ev.type() == Event::AllDay ) {
348 startTime.setHMS( 0, 0, 0 ); 373 startTime.setHMS( 0, 0, 0 );
349 endTime.setHMS( 23, 59, 59 ); 374 endTime.setHMS( 23, 59, 59 );
350 } 375 }
351 376
352 // adjust start and end times based on timezone 377 // adjust start and end times based on timezone
@@ -418,24 +443,25 @@ void DateEntry::setRepeatLabel()
418void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundTypeChoice sound ) 443void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundTypeChoice sound )
419{ 444{
420 checkAlarm->setChecked( alarmPreset ); 445 checkAlarm->setChecked( alarmPreset );
421 spinAlarm->setValue( presetTime ); 446 spinAlarm->setValue( presetTime );
422 if ( sound != Event::Silent ) 447 if ( sound != Event::Silent )
423 comboSound->setCurrentItem( 1 ); 448 comboSound->setCurrentItem( 1 );
424 else 449 else
425 comboSound->setCurrentItem( 0 ); 450 comboSound->setCurrentItem( 0 );
426} 451}
427 452
428void DateEntry::initCombos() 453void DateEntry::initCombos()
429{ 454{
455 /*
430 comboStart->clear(); 456 comboStart->clear();
431 comboEnd->clear(); 457 comboEnd->clear();
432 if ( ampm ) { 458 if ( ampm ) {
433 for ( int i = 0; i < 24; i++ ) { 459 for ( int i = 0; i < 24; i++ ) {
434 if ( i == 0 ) { 460 if ( i == 0 ) {
435 comboStart->insertItem( "12:00 AM" ); 461 comboStart->insertItem( "12:00 AM" );
436 comboStart->insertItem( "12:30 AM" ); 462 comboStart->insertItem( "12:30 AM" );
437 comboEnd->insertItem( "12:00 AM" ); 463 comboEnd->insertItem( "12:00 AM" );
438 comboEnd->insertItem( "12:30 AM" ); 464 comboEnd->insertItem( "12:30 AM" );
439 } else if ( i == 12 ) { 465 } else if ( i == 12 ) {
440 comboStart->insertItem( "12:00 PM" ); 466 comboStart->insertItem( "12:00 PM" );
441 comboStart->insertItem( "12:30 PM" ); 467 comboStart->insertItem( "12:30 PM" );
@@ -463,20 +489,21 @@ void DateEntry::initCombos()
463 comboEnd->insertItem( QString("0") 489 comboEnd->insertItem( QString("0")
464 + QString::number(i) + ":00" ); 490 + QString::number(i) + ":00" );
465 comboEnd->insertItem( QString("0") 491 comboEnd->insertItem( QString("0")
466 + QString::number(i) + ":30" ); 492 + QString::number(i) + ":30" );
467 } else { 493 } else {
468 comboStart->insertItem( QString::number(i) + ":00" ); 494 comboStart->insertItem( QString::number(i) + ":00" );
469 comboStart->insertItem( QString::number(i) + ":30" ); 495 comboStart->insertItem( QString::number(i) + ":30" );
470 comboEnd->insertItem( QString::number(i) + ":00" ); 496 comboEnd->insertItem( QString::number(i) + ":00" );
471 comboEnd->insertItem( QString::number(i) + ":30" ); 497 comboEnd->insertItem( QString::number(i) + ":30" );
472 } 498 }
473 } 499 }
474 } 500 }
501 */
475} 502}
476 503
477void DateEntry::slotChangeClock( bool whichClock ) 504void DateEntry::slotChangeClock( bool whichClock )
478{ 505{
479 ampm = whichClock; 506 ampm = whichClock;
480 initCombos(); 507 initCombos();
481 setDates( QDateTime( startDate, startTime ), QDateTime( endDate, endTime ) ); 508 setDates( QDateTime( startDate, startTime ), QDateTime( endDate, endTime ) );
482} 509}