summaryrefslogtreecommitdiffabout
path: root/korganizer/koeditorgeneraltodo.cpp
Side-by-side diff
Diffstat (limited to 'korganizer/koeditorgeneraltodo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koeditorgeneraltodo.cpp52
1 files changed, 42 insertions, 10 deletions
diff --git a/korganizer/koeditorgeneraltodo.cpp b/korganizer/koeditorgeneraltodo.cpp
index b9a028b..ce0d7a9 100644
--- a/korganizer/koeditorgeneraltodo.cpp
+++ b/korganizer/koeditorgeneraltodo.cpp
@@ -87,139 +87,152 @@ void KOEditorGeneralTodo::initTime(QWidget *parent,QBoxLayout *topLayout)
QGroupBox *timeGroupBox = new QGroupBox(1,QGroupBox::Horizontal,
i18n("Date && Time"),parent);
timeLayout->addWidget(timeGroupBox);
timeGroupBox->layout()->setSpacing( 0 );
timeGroupBox->layout()->setMargin( 5 );
QFrame *timeBoxFrame = new QFrame(timeGroupBox);
QGridLayout *layoutTimeBox = new QGridLayout(timeBoxFrame,3,3);
layoutTimeBox->setSpacing(topLayout->spacing());
layoutTimeBox->setColStretch( 1, 1 );
mDueCheck = new QCheckBox(i18n("Due:"),timeBoxFrame);
layoutTimeBox->addWidget(mDueCheck,0,0);
connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(enableDueEdit(bool)));
connect(mDueCheck,SIGNAL(toggled(bool)),SLOT(showAlarm()));
mDueDateEdit = new KDateEdit(timeBoxFrame);
layoutTimeBox->addWidget(mDueDateEdit,0,1);
mDueTimeEdit = new KOTimeEdit(timeBoxFrame);
layoutTimeBox->addWidget(mDueTimeEdit,0,2);
mStartCheck = new QCheckBox(i18n("Start:"),timeBoxFrame);
layoutTimeBox->addWidget(mStartCheck,1,0);
connect(mStartCheck,SIGNAL(toggled(bool)),SLOT(enableStartEdit(bool)));
mStartDateEdit = new KDateEdit(timeBoxFrame);
layoutTimeBox->addWidget(mStartDateEdit,1,1);
mStartTimeEdit = new KOTimeEdit(timeBoxFrame);
layoutTimeBox->addWidget(mStartTimeEdit,1,2);
mTimeButton = new QCheckBox(i18n("Time associated"),timeBoxFrame);
layoutTimeBox->addMultiCellWidget(mTimeButton,2,2,0,1);
connect(mTimeButton,SIGNAL(toggled(bool)),SLOT(enableTimeEdits(bool)));
// some more layouting
//layoutTimeBox->setColStretch(3,1);
}
void KOEditorGeneralTodo::initCompletion(QWidget *parent, QBoxLayout *topLayout)
{
mCompletedCombo = new QComboBox(parent);
// xgettext:no-c-format
mCompletedCombo->insertItem(i18n(" 0 %"));
// xgettext:no-c-format
mCompletedCombo->insertItem(i18n(" 20 %"));
// xgettext:no-c-format
mCompletedCombo->insertItem(i18n(" 40 %"));
// xgettext:no-c-format
mCompletedCombo->insertItem(i18n(" 60 %"));
// xgettext:no-c-format
mCompletedCombo->insertItem(i18n(" 80 %"));
// xgettext:no-c-format
mCompletedCombo->insertItem(i18n("100 %"));
connect(mCompletedCombo,SIGNAL(activated(int)),SLOT(completedChanged(int)));
topLayout->addWidget(mCompletedCombo);
mCompletedLabel = new QLabel(i18n("completed"),parent);
- topLayout->addWidget(mCompletedLabel);
+ topLayout->addWidget(mCompletedLabel);
+
+ mCompleteDateEdit = new KDateEdit(parent);
+ topLayout->addWidget(mCompleteDateEdit );
+
+ mCompleteTimeEdit = new KOTimeEdit(parent);
+ topLayout->addWidget( mCompleteTimeEdit);
+
+ mCompletedCombo->setSizePolicy( QSizePolicy( QSizePolicy::Preferred,QSizePolicy::Preferred) );
+ mCompletedLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,QSizePolicy::Preferred) );
+
+ if ( QApplication::desktop()->width() < 320 ) {
+ mCompleteDateEdit->setMaximumWidth( 85 );
+ topLayout->setSpacing( 0 );
+ }
}
void KOEditorGeneralTodo::initPriority(QWidget *parent, QBoxLayout *topLayout)
{
QHBox* h = new QHBox ( parent );
topLayout->addWidget( h );
QLabel *priorityLabel = new QLabel(i18n("Priority:"), h);
// topLayout->addWidget(priorityLabel);
-
mPriorityCombo = new QComboBox( h );
mPriorityCombo->insertItem(i18n("1 (high)"));
mPriorityCombo->insertItem(i18n("2"));
mPriorityCombo->insertItem(i18n("3"));
mPriorityCombo->insertItem(i18n("4"));
mPriorityCombo->insertItem(i18n("5 (low)"));
//topLayout->addWidget(mPriorityCombo);
}
void KOEditorGeneralTodo::initStatus(QWidget *parent,QBoxLayout *topLayout)
{
QBoxLayout *statusLayout = new QHBoxLayout(topLayout);
initCompletion( parent, statusLayout );
statusLayout->addStretch( 1 );
initPriority( parent, statusLayout );
}
void KOEditorGeneralTodo::setDefaults(QDateTime due,bool allDay)
{
mSummaryEdit->load(KOLocationBox::SUMMARYTODO);
mLocationEdit->load(KOLocationBox::LOCATION);
KOEditorGeneral::setDefaults(allDay);
mTimeButton->setChecked( !allDay );
if(mTimeButton->isChecked()) {
mTimeButton->setEnabled(true);
}
else {
mTimeButton->setEnabled(false);
}
enableTimeEdits( !allDay );
if ( due.isValid() ) {
mDueCheck->setChecked(true);
enableDueEdit(true);
} else {
mDueCheck->setChecked(false);
enableDueEdit(false);
due = QDateTime::currentDateTime().addDays(7);
}
alarmDisable(true);
mStartCheck->setChecked(false);
enableStartEdit(false);
mDueDateEdit->setDate(due.date());
mDueTimeEdit->setTime(due.time());
due = due.addDays(-7);
mStartDateEdit->setDate(due.date());
mStartTimeEdit->setTime(due.time());
mPriorityCombo->setCurrentItem(2);
mCompletedLabel->setText(i18n("completed"));;
mCompletedCombo->setCurrentItem(0);
}
void KOEditorGeneralTodo::readTodo(Todo *todo)
{
@@ -251,209 +264,228 @@ void KOEditorGeneralTodo::readTodo(Todo *todo)
} else {
mStartDateEdit->setEnabled(false);
mStartTimeEdit->setEnabled(false);
mStartDateEdit->setDate(QDate::currentDate());
mStartTimeEdit->setTime(QTime::currentTime());
mStartCheck->setChecked(false);
}
mTimeButton->setChecked( !todo->doesFloat() );
mCompletedCombo->setCurrentItem(todo->percentComplete() / 20);
if (todo->isCompleted() && todo->hasCompletedDate()) {
mCompleted = todo->completed();
}
setCompletedDate();
mPriorityCombo->setCurrentItem(todo->priority()-1);
}
void KOEditorGeneralTodo::writeTodo(Todo *todo)
{
KOEditorGeneral::writeIncidence(todo);
// temp. until something better happens.
QString tmpStr;
todo->setHasDueDate(mDueCheck->isChecked());
todo->setHasStartDate(mStartCheck->isChecked());
QDate tmpDate;
QTime tmpTime;
QDateTime tmpDT;
if ( mTimeButton->isChecked() ) {
todo->setFloats(false);
// set due date/time
tmpDate = mDueDateEdit->date();
tmpTime = mDueTimeEdit->getTime();
tmpDT.setDate(tmpDate);
tmpDT.setTime(tmpTime);
todo->setDtDue(tmpDT);
// set start date/time
tmpDate = mStartDateEdit->date();
tmpTime = mStartTimeEdit->getTime();
tmpDT.setDate(tmpDate);
tmpDT.setTime(tmpTime);
todo->setDtStart(tmpDT);
} else {
todo->setFloats(true);
// need to change this.
tmpDate = mDueDateEdit->date();
tmpTime.setHMS(0,0,0);
tmpDT.setDate(tmpDate);
tmpDT.setTime(tmpTime);
todo->setDtDue(tmpDT);
tmpDate = mStartDateEdit->date();
tmpTime.setHMS(0,0,0);
tmpDT.setDate(tmpDate);
tmpDT.setTime(tmpTime);
todo->setDtStart(tmpDT);
}
-
todo->setPriority(mPriorityCombo->currentItem()+1);
// set completion state
- todo->setPercentComplete(mCompletedCombo->currentItem() * 20);
-
- if (mCompletedCombo->currentItem() == 5 && mCompleted.isValid()) {
- todo->setCompleted(mCompleted);
+ if ( mCompletedCombo->currentItem() == 5 ) {
+ QDateTime comp ( mCompleteDateEdit->date(), mCompleteTimeEdit->getTime() );
+ if ( comp.isValid () ) {
+ todo->setPercentComplete(0);
+ todo->setPercentComplete(100);
+ todo->setCompleted(comp);
+ } else {
+ todo->setPercentComplete( 100 );
+ if ( mCompleted.isValid() )
+ todo->setCompleted(mCompleted);
+ }
+ } else {
+ todo->setPercentComplete(mCompletedCombo->currentItem() * 20);
}
+
mSummaryEdit->save(KOLocationBox::SUMMARYTODO);
}
void KOEditorGeneralTodo::enableDueEdit(bool enable)
{
mDueDateEdit->setEnabled( enable );
if(mDueCheck->isChecked() || mStartCheck->isChecked()) {
mTimeButton->setEnabled(true);
}
else {
mTimeButton->setEnabled(false);
mTimeButton->setChecked(false);
}
if (enable) {
mDueTimeEdit->setEnabled( mTimeButton->isChecked() );
} else {
mDueTimeEdit->setEnabled( false );
}
}
void KOEditorGeneralTodo::enableStartEdit( bool enable )
{
mStartDateEdit->setEnabled( enable );
if(mDueCheck->isChecked() || mStartCheck->isChecked()) {
mTimeButton->setEnabled(true);
}
else {
mTimeButton->setEnabled(false);
mTimeButton->setChecked(false);
}
if (enable) {
mStartTimeEdit->setEnabled( mTimeButton->isChecked() );
} else {
mStartTimeEdit->setEnabled( false );
}
}
void KOEditorGeneralTodo::enableTimeEdits(bool enable)
{
if(mStartCheck->isChecked()) {
mStartTimeEdit->setEnabled( enable );
}
if(mDueCheck->isChecked()) {
mDueTimeEdit->setEnabled( enable );
}
}
void KOEditorGeneralTodo::showAlarm()
{
if ( mDueCheck->isChecked() ) {
alarmDisable(false);
}
else {
alarmDisable(true);
}
}
bool KOEditorGeneralTodo::validateInput()
{
if (mDueCheck->isChecked()) {
if (!mDueDateEdit->inputIsValid()) {
KMessageBox::sorry(0,i18n("Please specify a valid due date."));
return false;
}
}
if (mStartCheck->isChecked()) {
if (!mStartDateEdit->inputIsValid()) {
KMessageBox::sorry(0,i18n("Please specify a valid start date."));
return false;
}
}
if (mStartCheck->isChecked() && mDueCheck->isChecked()) {
QDateTime startDate;
QDateTime dueDate;
startDate.setDate(mStartDateEdit->date());
dueDate.setDate(mDueDateEdit->date());
if (mTimeButton->isChecked()) {
startDate.setTime(mStartTimeEdit->getTime());
dueDate.setTime(mDueTimeEdit->getTime());
}
if (startDate > dueDate) {
KMessageBox::sorry(0,
i18n("The start date cannot be after the due date."));
return false;
}
}
return KOEditorGeneral::validateInput();
}
void KOEditorGeneralTodo::completedChanged(int index)
{
if (index == 5) {
- mCompleted = QDateTime::currentDateTime();
+ //get rid of milli sec
+ mCompleted = QDateTime::currentDateTime();
}
setCompletedDate();
}
void KOEditorGeneralTodo::setCompletedDate()
{
if (mCompletedCombo->currentItem() == 5 && mCompleted.isValid()) {
- mCompletedLabel->setText(i18n("completed on %1")
- .arg(KGlobal::locale()->formatDateTime(mCompleted)));
+ if ( QApplication::desktop()->width() < 480 ) {
+ mCompletedLabel->setText(i18n(" on"));
+ }
+ else
+ mCompletedLabel->setText(i18n(" completed on "));
+ mCompleteDateEdit->show();
+ mCompleteTimeEdit->show();
+ mCompleteTimeEdit->setTime( mCompleted.time() );
+ mCompleteDateEdit->setDate( mCompleted.date() );
} else {
mCompletedLabel->setText(i18n("completed"));
+ mCompleteDateEdit->hide();
+ mCompleteTimeEdit->hide();
}
}
void KOEditorGeneralTodo::modified (Todo* todo, int modification)
{
switch (modification) {
case KOGlobals::PRIORITY_MODIFIED:
mPriorityCombo->setCurrentItem(todo->priority()-1);
break;
case KOGlobals::COMPLETION_MODIFIED:
mCompletedCombo->setCurrentItem(todo->percentComplete() / 20);
if (todo->isCompleted() && todo->hasCompletedDate()) {
mCompleted = todo->completed();
}
setCompletedDate();
break;
case KOGlobals::CATEGORY_MODIFIED:
setCategories (todo->categoriesStr ());
break;
case KOGlobals::UNKNOWN_MODIFIED: // fall through
default:
readTodo( todo );
break;
}
}