Diffstat (limited to 'core/pim/datebook/dateentryimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/dateentryimpl.cpp | 97 |
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 | |||
@@ -39,6 +39,8 @@ | |||
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> |
@@ -60,18 +62,22 @@ DateEntry::DateEntry( bool startOnMonday, const QDateTime &start, | |||
60 | { | 62 | { |
61 | init(); | 63 | init(); |
62 | setDates(start,end); | 64 | setDates(start,end); |
63 | setFocusProxy(comboDescription); | 65 | setFocusProxy(comboDescription); |
64 | } | 66 | } |
65 | 67 | ||
66 | static void addOrPick( QComboBox* combo, const QString& t ) | 68 | static 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 | ||
77 | DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, | 83 | DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, |
@@ -103,45 +109,50 @@ DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, | |||
103 | 109 | ||
104 | void DateEntry::setDates( const QDateTime& s, const QDateTime& e ) | 110 | void 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 | |||
121 | void 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 | ||
147 | void DateEntry::init() | 158 | void DateEntry::init() |
@@ -171,6 +182,10 @@ void DateEntry::init() | |||
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 | /* |
@@ -240,8 +255,12 @@ void DateEntry::endTimeChanged( const QString &s ) | |||
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 | |||
263 | void DateEntry::endTimeChanged( const QTime &t ) { | ||
245 | } | 264 | } |
246 | 265 | ||
247 | /* | 266 | /* |
@@ -270,12 +289,25 @@ void DateEntry::startDateChanged( int y, int m, int d ) | |||
270 | /* | 289 | /* |
271 | * public slot | 290 | * public slot |
272 | */ | 291 | */ |
273 | void DateEntry::startTimeChanged( int index ) | 292 | void 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 | |||
300 | void DateEntry::startTimeChanged( const QTime &t ) | ||
301 | { | ||
302 | int duration=startTime.secsTo(endTime); | ||
303 | startTime = t; | ||
304 | endTime=t.addSecs(duration); | ||
305 | } | ||
306 | void DateEntry::startTimePicked( const QTime &t ) { | ||
307 | startTimeChanged(t); | ||
308 | updateTimeEdit(true,true); | ||
309 | } | ||
310 | |||
279 | /* | 311 | /* |
280 | * public slot | 312 | * public slot |
281 | */ | 313 | */ |
@@ -286,16 +318,6 @@ void DateEntry::typeChanged( const QString &s ) | |||
286 | comboStart->setEnabled( b ); | 318 | comboStart->setEnabled( b ); |
287 | comboEnd->setEnabled( b ); | 319 | comboEnd->setEnabled( b ); |
288 | } | 320 | } |
289 | /* | ||
290 | * public slot | ||
291 | */ | ||
292 | void 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 | ||
300 | void DateEntry::slotRepeat() | 322 | void DateEntry::slotRepeat() |
301 | { | 323 | { |
@@ -336,8 +358,11 @@ Event DateEntry::event() | |||
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; |
@@ -427,6 +452,7 @@ void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundT | |||
427 | 452 | ||
428 | void DateEntry::initCombos() | 453 | void DateEntry::initCombos() |
429 | { | 454 | { |
455 | /* | ||
430 | comboStart->clear(); | 456 | comboStart->clear(); |
431 | comboEnd->clear(); | 457 | comboEnd->clear(); |
432 | if ( ampm ) { | 458 | if ( ampm ) { |
@@ -472,6 +498,7 @@ void DateEntry::initCombos() | |||
472 | } | 498 | } |
473 | } | 499 | } |
474 | } | 500 | } |
501 | */ | ||
475 | } | 502 | } |
476 | 503 | ||
477 | void DateEntry::slotChangeClock( bool whichClock ) | 504 | void DateEntry::slotChangeClock( bool whichClock ) |