Diffstat (limited to 'core/pim/datebook/dateentryimpl.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/pim/datebook/dateentryimpl.cpp | 95 |
1 files changed, 61 insertions, 34 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 @@ #include <qmultilineedit.h> #include <qpopupmenu.h> #include <qscrollview.h> #include <qspinbox.h> #include <qtoolbutton.h> +#include "timepicker.h" + #include <stdlib.h> #include <stdiostream.h> /* * Constructs a DateEntry which is a child of 'parent', with the @@ -62,19 +64,23 @@ DateEntry::DateEntry( bool startOnMonday, const QDateTime &start, setDates(start,end); setFocusProxy(comboDescription); } static void addOrPick( QComboBox* combo, const QString& t ) { + // Pick an item if one excists for (int i=0; i<combo->count(); i++) { if ( combo->text(i) == t ) { combo->setCurrentItem(i); return; } } - combo->setEditText(t); + + // Else add one + combo->insertItem(t); + combo->setCurrentItem(combo->count()-1); } DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, QWidget* parent, const char* name ) : DateEntryBase( parent, name ), ampm( whichClock ), @@ -100,51 +106,56 @@ DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, } setRepeatLabel(); } void DateEntry::setDates( const QDateTime& s, const QDateTime& e ) { - int shour, - ehour; - QString strStart, - strEnd; startDate = s.date(); endDate = e.date(); startTime = s.time(); endTime = e.time(); startDateChanged( s.date().year(), s.date().month(), s.date().day() ); + endDateChanged( e.date().year(), e.date().month(), e.date().day() ); + updateTimeEdit(true,true); +} + +void DateEntry::updateTimeEdit(bool s, bool e) { + + // Comboboxes + QString strStart, strEnd; + int shour, ehour; if ( ampm ) { - shour = s.time().hour(); - ehour = e.time().hour(); + shour = startTime.hour(); + ehour = endTime.hour(); if ( shour >= 12 ) { if ( shour > 12 ) shour -= 12; - strStart.sprintf( "%d:%02d PM", shour, s.time().minute() ); + strStart.sprintf( "%d:%02d PM", shour, startTime.minute() ); } else { if ( shour == 0 ) shour = 12; - strStart.sprintf( "%d:%02d AM", shour, s.time().minute() ); + strStart.sprintf( "%d:%02d AM", shour, startTime.minute() ); } - if ( ehour == 24 && e.time().minute() == 0 ) { + if ( ehour == 24 && endTime.minute() == 0 ) { strEnd = "11:59 PM"; // or "midnight" } else if ( ehour >= 12 ) { if ( ehour > 12 ) ehour -= 12; - strEnd.sprintf( "%d:%02d PM", ehour, e.time().minute() ); + strEnd.sprintf( "%d:%02d PM", ehour, endTime.minute() ); } else { if ( ehour == 0 ) ehour = 12; - strEnd.sprintf( "%d:%02d AM", ehour, e.time().minute() ); + strEnd.sprintf( "%d:%02d AM", ehour, endTime.minute() ); } } else { - strStart.sprintf( "%02d:%02d", s.time().hour(), s.time().minute() ); - strEnd.sprintf( "%02d:%02d", e.time().hour(), e.time().minute() ); + strStart.sprintf( "%02d:%02d", startTime.hour(), startTime.minute() ); + strEnd.sprintf( "%02d:%02d", endTime.hour(), endTime.minute() ); } - addOrPick(comboStart, strStart ); - endDateChanged( e.date().year(), e.date().month(), e.date().day() ); - addOrPick(comboEnd, strEnd ); + + if (s) comboStart->setText(strStart); + if (e) comboEnd->setText(strEnd); } void DateEntry::init() { comboDescription->setInsertionPolicy(QComboBox::AtCurrent); comboLocation->setInsertionPolicy(QComboBox::AtCurrent); @@ -168,12 +179,16 @@ void DateEntry::init() QPopupMenu *m2 = new QPopupMenu( this ); endPicker = new DateBookMonth( m2, 0, TRUE ); m2->insertItem( endPicker ); buttonEnd->setPopup( m2 ); connect( endPicker, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( endDateChanged( int, int, int ) ) ); + + connect(timePickerStart, SIGNAL( timeChanged(const QTime &) ), + this, SLOT( startTimePicked(const QTime &) )); + editNote->setFixedVisibleLines(3); } /* * Destroys the object and frees any allocated resources */ DateEntry::~DateEntry() @@ -237,14 +252,18 @@ void DateEntry::endTimeChanged( const QString &s ) { QTime tmpTime = parseTime(s,ampm); if ( endDate > startDate || tmpTime >= startTime ) { endTime = tmpTime; } else { endTime = startTime; - comboEnd->setCurrentItem( comboStart->currentItem() ); + //comboEnd->setCurrentItem( comboStart->currentItem() ); } + +} + +void DateEntry::endTimeChanged( const QTime &t ) { } /* * public slot */ void DateEntry::startDateChanged( int y, int m, int d ) @@ -267,38 +286,41 @@ void DateEntry::startDateChanged( int y, int m, int d ) endPicker->setDate( y, m, d ); } /* * public slot */ -void DateEntry::startTimeChanged( int index ) +void DateEntry::startTimeEdited( const QString &s ) { - startTime = parseTime(comboStart->text(index),ampm); - changeEndCombo( index ); - //cout << "Start: " << comboStart->currentText() << endl; + startTimeChanged(parseTime(s,ampm)); + updateTimeEdit(false,true); + timePickerStart->setHour(startTime.hour()); + timePickerStart->setMinute(startTime.minute()); } + +void DateEntry::startTimeChanged( const QTime &t ) +{ + int duration=startTime.secsTo(endTime); + startTime = t; + endTime=t.addSecs(duration); +} +void DateEntry::startTimePicked( const QTime &t ) { + startTimeChanged(t); + updateTimeEdit(true,true); +} + /* * public slot */ void DateEntry::typeChanged( const QString &s ) { bool b = s != "All Day"; buttonStart->setEnabled( b ); comboStart->setEnabled( b ); comboEnd->setEnabled( b ); } -/* - * public slot - */ -void DateEntry::changeEndCombo( int change ) -{ - if ( change + 2 < comboEnd->count() ) - change += 2; - comboEnd->setCurrentItem( change ); - endTimeChanged( comboEnd->currentText() ); -} void DateEntry::slotRepeat() { // Work around for compiler Bug.. RepeatEntry *e; @@ -333,14 +355,17 @@ Event DateEntry::event() ev.setType( checkAllDay->isChecked() ? Event::AllDay : Event::Normal ); if ( startDate > endDate ) { QDate tmp = endDate; endDate = startDate; startDate = tmp; } - startTime = parseTime( comboStart->currentText(), ampm ); - endTime = parseTime( comboEnd->currentText(), ampm ); + + // This is now done in the changed slots + // startTime = parseTime( comboStart->text(), ampm ); + //endTime = parseTime( comboEnd->text(), ampm ); + if ( startTime > endTime && endDate == startDate ) { QTime tmp = endTime; endTime = startTime; startTime = tmp; } // don't set the time if theres no need too @@ -424,12 +449,13 @@ void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundT else comboSound->setCurrentItem( 0 ); } void DateEntry::initCombos() { + /* comboStart->clear(); comboEnd->clear(); if ( ampm ) { for ( int i = 0; i < 24; i++ ) { if ( i == 0 ) { comboStart->insertItem( "12:00 AM" ); @@ -469,12 +495,13 @@ void DateEntry::initCombos() comboStart->insertItem( QString::number(i) + ":30" ); comboEnd->insertItem( QString::number(i) + ":00" ); comboEnd->insertItem( QString::number(i) + ":30" ); } } } + */ } void DateEntry::slotChangeClock( bool whichClock ) { ampm = whichClock; initCombos(); |