Diffstat (limited to 'korganizer/koeditorrecurrence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/koeditorrecurrence.cpp | 125 |
1 files changed, 74 insertions, 51 deletions
diff --git a/korganizer/koeditorrecurrence.cpp b/korganizer/koeditorrecurrence.cpp index 98356fe..ffc0fac 100644 --- a/korganizer/koeditorrecurrence.cpp +++ b/korganizer/koeditorrecurrence.cpp @@ -283,113 +283,112 @@ int RecurMonthly::weekday() /////////////////////////// RecurYearly /////////////////////////////// RecurYearly::RecurYearly( QWidget *parent, const char *name ) : RecurBase( parent, name ) { QBoxLayout *topLayout = new QVBoxLayout( this ); topLayout->setSpacing( KDialog::spacingHint() ); QBoxLayout *freqLayout = new QHBoxLayout( topLayout ); QLabel *preLabel = new QLabel( i18n("every"), this ); freqLayout->addWidget( preLabel ); freqLayout->addWidget( frequencyEdit() ); QLabel *postLabel = new QLabel( i18n("year(s)"), this ); freqLayout->addWidget( postLabel ); QButtonGroup *buttonGroup = new QButtonGroup( this ); buttonGroup->setFrameStyle( QFrame::NoFrame ); topLayout->addWidget( buttonGroup, 1, AlignVCenter ); - QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 3, 2 ); - - QString recurInMonthText; - if ( !KOPrefs::instance()->mCompactDialogs ) { - recurInMonthText = i18n("Recur in the month of"); - } - - mByMonthRadio = new QRadioButton( recurInMonthText, buttonGroup); - buttonLayout->addWidget( mByMonthRadio, 0, 0 ); + QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 2, 3 ); + mByMonthRadio = new QRadioButton( i18n("On day "), buttonGroup); + buttonLayout->addWidget( mByMonthRadio, 0, 0 , Qt::AlignRight); + mByDayLabel = new QLabel( i18n(" 1 of "), buttonGroup ); + + buttonLayout->addWidget( mByDayLabel, 0, 1 ); mByMonthCombo = new QComboBox( buttonGroup ); mByMonthCombo->insertItem( i18n("January") ); mByMonthCombo->insertItem( i18n("February") ); mByMonthCombo->insertItem( i18n("March") ); mByMonthCombo->insertItem( i18n("April") ); mByMonthCombo->insertItem( i18n("May") ); mByMonthCombo->insertItem( i18n("June") ); mByMonthCombo->insertItem( i18n("July") ); mByMonthCombo->insertItem( i18n("August") ); mByMonthCombo->insertItem( i18n("September") ); mByMonthCombo->insertItem( i18n("October") ); mByMonthCombo->insertItem( i18n("November") ); mByMonthCombo->insertItem( i18n("December") ); - buttonLayout->addWidget( mByMonthCombo, 0, 1 ); - - mByMonthCombo->setSizeLimit( 6 ); - - buttonLayout->setRowStretch( 1, 1 ); - - QString recurOnDayText; - if ( KOPrefs::instance()->mCompactDialogs ) { - recurOnDayText = i18n("This day"); - } else { - recurOnDayText = i18n("Recur on this day"); - } - - mByDayRadio = new QRadioButton( recurOnDayText, buttonGroup); - buttonLayout->addMultiCellWidget( mByDayRadio, 2, 2, 0, 1 ); + buttonLayout->addWidget( mByMonthCombo, 0, 2,Qt::AlignLeft ); + if ( QApplication::desktop()->width() <= 640 ) { + mByMonthCombo->setSizeLimit( 6 ); + } + + mByDayRadio = new QRadioButton( i18n("On day "), buttonGroup); + buttonLayout->addWidget( mByDayRadio, 1, 0 , Qt::AlignRight); + mDayOfLabel = new QLabel( i18n("1 of the year"), buttonGroup ); + buttonLayout->addMultiCellWidget( mDayOfLabel, 1, 1, 1,3 ); + } -void RecurYearly::setByDay() +void RecurYearly::setByDay( int doy ) { mByDayRadio->setChecked( true ); + mDayOfLabel->setText(i18n("%1 of the year").arg( doy ) ); } -void RecurYearly::setByMonth( int month ) +void RecurYearly::setByMonth( int month, int day ) { mByMonthRadio->setChecked( true ); mByMonthCombo->setCurrentItem( month - 1 ); + mByDayLabel->setText(i18n("%1 of ").arg( day ) ); + mDay = day; } bool RecurYearly::byMonth() { return mByMonthRadio->isChecked(); } bool RecurYearly::byDay() { return mByDayRadio->isChecked(); } int RecurYearly::month() { return mByMonthCombo->currentItem() + 1; } +int RecurYearly::day() +{ + return mDay;//mByDayCombo->currentItem() + 1; +} //////////////////////////// ExceptionsWidget ////////////////////////// ExceptionsWidget::ExceptionsWidget( QWidget *parent, const char *name ) : QWidget( parent, name ) { QBoxLayout *topLayout = new QVBoxLayout( this ); QGroupBox *groupBox = new QGroupBox( 1, Horizontal, i18n("Exceptions"), this ); topLayout->addWidget( groupBox ); QWidget *box = new QWidget( groupBox ); QGridLayout *boxLayout = new QGridLayout( box ); mExceptionDateEdit = new KDateEdit( box ); boxLayout->addWidget( mExceptionDateEdit, 0, 0 ); QPushButton *addExceptionButton = new QPushButton( i18n("Add"), box ); boxLayout->addWidget( addExceptionButton, 1, 0 ); QPushButton *changeExceptionButton = new QPushButton( i18n("Change"), box ); boxLayout->addWidget( changeExceptionButton, 2, 0 ); QPushButton *deleteExceptionButton = new QPushButton( i18n("Delete"), box ); @@ -823,48 +822,49 @@ KOEditorRecurrence::KOEditorRecurrence( QWidget* parent, const char *name ) : mRecurrenceRangeButton = 0; topLayout->addWidget( mRecurrenceRangeWidget, 3, 0 ); mExceptionsWidget = new ExceptionsWidget( this ); mExceptionsDialog = 0; mExceptions = mExceptionsWidget; mExceptionsButton = 0; topLayout->addWidget( mExceptionsWidget, 3, 1 ); } } KOEditorRecurrence::~KOEditorRecurrence() { } void KOEditorRecurrence::setEnabled( bool enabled ) { // kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl; mTimeGroupBox->setEnabled( enabled ); if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled ); if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled ); if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled ); if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled ); + mRuleBox->setEnabled( enabled ); } void KOEditorRecurrence::showCurrentRule( int current ) { switch ( current ) { case Daily: mRuleStack->raiseWidget( mDaily ); break; case Weekly: mRuleStack->raiseWidget( mWeekly ); break; case Monthly: mRuleStack->raiseWidget( mMonthly ); break; default: case Yearly: mRuleStack->raiseWidget( mYearly ); break; } } void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end ) { // kdDebug() << "KOEditorRecurrence::setDateTimes" << endl; @@ -874,59 +874,61 @@ void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end ) } void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to, bool ) { // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() ); setDateTimes( from, to ); bool enabled = false; mEnabledCheck->setChecked( enabled ); setEnabled( enabled ); mExceptions->setDefaults( to ); mRecurrenceRange->setDefaults( to ); mRecurrenceChooser->setType( RecurrenceChooser::Weekly ); showCurrentRule( mRecurrenceChooser->type() ); mDaily->setFrequency( 1 ); mWeekly->setFrequency( 1 ); QBitArray days( 7 ); days.fill( 0 ); + days.setBit( from.date().dayOfWeek()- 1); mWeekly->setDays( days ); - mMonthly->setFrequency( 1 ); + mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 ); mMonthly->setByDay( from.date().day()-1 ); - mYearly->setFrequency( 1 ); - mYearly->setByDay(); + mYearly->setByDay( from.date().dayOfYear() ); + mYearly->setByMonth( from.date().month(), from.date().day() ); } void KOEditorRecurrence::readEvent(Event *event) { + setDefaults( event->dtStart(), event->dtEnd(), true ); QBitArray rDays( 7 ); QPtrList<Recurrence::rMonthPos> rmp; QPtrList<int> rmd; int day = 0; int count = 0; int month = 0; setDateTimes( event->dtStart(), event->dtEnd() ); Recurrence *r = event->recurrence(); int f = r->frequency(); int recurs = r->doesRecur(); mEnabledCheck->setChecked( recurs ); setEnabled( recurs ); int recurrenceType = RecurrenceChooser::Weekly; switch ( recurs ) { case Recurrence::rNone: setDefaults( event->dtStart(), event->dtEnd(), true ); break; case Recurrence::rDaily: recurrenceType = RecurrenceChooser::Daily; @@ -945,61 +947,79 @@ void KOEditorRecurrence::readEvent(Event *event) rmp = r->monthPositions(); if ( rmp.first()->negative ) count = 5 - rmp.first()->rPos - 1; else count = rmp.first()->rPos - 1; day = 0; while ( !rmp.first()->rDays.testBit( day ) ) ++day; mMonthly->setByPos( count, day ); mMonthly->setFrequency( f ); break; case Recurrence::rMonthlyDay: recurrenceType = RecurrenceChooser::Monthly; rmd = r->monthDays(); day = *rmd.first() - 1; mMonthly->setByDay( day ); mMonthly->setFrequency( f ); break; case Recurrence::rYearlyMonth: - case Recurrence::rYearlyDay: - recurrenceType = RecurrenceChooser::Yearly; - - rmd = r->yearNums(); - month = *rmd.first(); - if ( month == event->dtStart().date().month() ) { - mYearly->setByDay(); - } else { - mYearly->setByMonth( month ); - } + { + recurrenceType = RecurrenceChooser::Yearly; + qDebug("Recurrence::rYearlyMonth: "); + day = event->dtStart().date().day(); + rmd = r->yearNums(); + if ( rmd.count() > 0 ) + month = *rmd.first(); + else + month = event->dtStart().date().month() ; + mYearly->setByMonth( month, day ); +#if 0 + qDebug("2day = %d ",day ); + QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions(); + int month; + if ( !monthlist.isEmpty() ) { + month = monthlist.first()->rPos ; + } else { + month = event->dtStart().date().month() ; + } + mYearly->setByMonth( day, month ); +#endif + mYearly->setFrequency( f ); + } - mYearly->setFrequency( f ); break; + case Recurrence::rYearlyDay: + qDebug("Recurrence::rYearlyDay: "); + recurrenceType = RecurrenceChooser::Yearly; + mYearly->setByDay( event->dtStart().date().dayOfYear() ); + mYearly->setFrequency( f ); + break; default: setDefaults( event->dtStart(), event->dtEnd(), true ); break; } mRecurrenceChooser->setType( recurrenceType ); showCurrentRule( recurrenceType ); mRecurrenceRange->setDateTimes( event->dtStart() ); if ( r->doesRecur() ) { mRecurrenceRange->setDuration( r->duration() ); if ( r->duration() == 0 ) { if ( r->endDate() < event->dtStart().date() ) mRecurrenceRange->setEndDate( event->dtStart().date() ); else mRecurrenceRange->setEndDate( r->endDate() ); } else mRecurrenceRange->setEndDate( event->dtStart().date() ); } mExceptions->setDates( event->exDates() ); } @@ -1041,63 +1061,66 @@ void KOEditorRecurrence::writeEvent( Event *event ) if ( mMonthly->byPos() ) { int pos = mMonthly->count(); QBitArray days( 7 ); days.fill( false ); days.setBit( mMonthly->weekday() ); if ( duration != 0 ) r->setMonthly( Recurrence::rMonthlyPos, freq, duration ); else r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); r->addMonthlyPos( pos, days ); } else { // it's by day int day = mMonthly->day(); if ( duration != 0 ) { r->setMonthly( Recurrence::rMonthlyDay, freq, duration ); } else { r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); } r->addMonthlyDay( day ); } } else if ( recurrenceType == RecurrenceChooser::Yearly ) { + qDebug("RecurrenceChooser::Yearly "); int freq = mYearly->frequency(); - - int month; - if ( mYearly->byMonth() ) { - month = mYearly->month(); - } else { - month = event->dtStart().date().month(); - } - if ( duration != 0 ) { - r->setYearly( Recurrence::rYearlyMonth, freq, duration ); + if ( mYearly->byDay() ) { + if ( duration != 0 ) { + r->setYearly( Recurrence::rYearlyDay, freq, duration ); + } else { + r->setYearly( Recurrence::rYearlyDay, freq, endDate ); + } + r->addYearlyNum( event->dtStart().date().dayOfYear() ); } else { - r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); + if ( duration != 0 ) { + r->setYearly( Recurrence::rYearlyMonth, freq, duration ); + } else { + r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); + } + r->addYearlyNum( mYearly->month() ); } - r->addYearlyNum( month ); } event->setExDates( mExceptions->dates() ); } } void KOEditorRecurrence::setDateTimeStr( const QString &str ) { mDateTimeLabel->setText( str ); } bool KOEditorRecurrence::validateInput() { // Check input here return true; } void KOEditorRecurrence::showExceptionsDialog() { DateList dates = mExceptions->dates(); int result = mExceptionsDialog->exec(); if ( result == QDialog::Rejected ) mExceptions->setDates( dates ); } |