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
@@ -36,12 +36,14 @@
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
@@ -57,24 +59,28 @@ DateEntry::DateEntry( bool startOnMonday, const QDateTime &start,
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 ),
@@ -100,51 +106,56 @@ DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock,
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);
@@ -168,12 +179,16 @@ void DateEntry::init()
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()
@@ -237,14 +252,18 @@ void 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 )
@@ -267,38 +286,41 @@ void DateEntry::startDateChanged( int y, int m, int 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
@@ -333,14 +355,17 @@ Event DateEntry::event()
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
@@ -424,12 +449,13 @@ void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundT
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" );
@@ -469,12 +495,13 @@ void DateEntry::initCombos()
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();