kplato

kpttaskdefaultpanel.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation;
00007    version 2 of the License.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kpttaskdefaultpanel.h"
00021 #include "kpttask.h"
00022 #include "kptcommand.h"
00023 #include "kptduration.h"
00024 #include "kptdurationwidget.h"
00025 #include "kptcalendar.h"
00026 #include "kptdatetime.h"
00027 #include "kptconfig.h"
00028 #include "kptpart.h"
00029 
00030 #include <kmessagebox.h>
00031 #include <klineedit.h>
00032 #include <ktextedit.h>
00033 #include <kcombobox.h>
00034 #include <kdatetimewidget.h>
00035 #include <klocale.h>
00036 #include <kcommand.h>
00037 #include <kabc/addressee.h>
00038 #include <kabc/addresseedialog.h>
00039 #include <kdatewidget.h>
00040 
00041 #include <qlayout.h>
00042 #include <qlabel.h>
00043 #include <qdatetime.h> 
00044 #include <qdatetimeedit.h> 
00045 #include <qgroupbox.h>
00046 #include <qpushbutton.h>
00047 #include <qspinbox.h>
00048 
00049 #include <kdebug.h>
00050 
00051 namespace KPlato
00052 {
00053 
00054 TaskDefaultPanel::TaskDefaultPanel(Task &task, StandardWorktime *workTime, QWidget *parent, const char *n)
00055     : ConfigTaskPanelImpl(parent, n),
00056       m_task(task),
00057       m_dayLength(24)
00058 {
00059     setStartValues(task, workTime);
00060 }
00061 
00062 void TaskDefaultPanel::setStartValues(Task &task, StandardWorktime *workTime) {
00063     m_effort = m_duration = task.effort()->expected();
00064     leaderfield->setText(task.leader());
00065     descriptionfield->setText(task.description());
00066     
00067     setEstimateFields(DurationWidget::Days|DurationWidget::Hours|DurationWidget::Minutes);
00068     if (workTime) {
00069         //kdDebug()<<k_funcinfo<<"daylength="<<workTime->day()<<endl;
00070         m_dayLength = workTime->day();
00071         if (task.effort()->type() == Effort::Type_Effort) {
00072             setEstimateScales(m_dayLength);
00073         }
00074     }
00075     setEstimateFieldUnit(0, i18n("days", "d"));
00076     setEstimateFieldUnit(1, i18n("hours", "h"));
00077     setEstimateFieldUnit(2, i18n("minutes", "m"));
00078     setEstimateType(task.effort()->type());
00079     
00080     setSchedulingType(task.constraint());
00081     if (task.constraintStartTime().isValid()) {
00082         setStartDateTime(task.constraintStartTime());
00083     } else {
00084         QDate date = QDate::currentDate();
00085         setStartDateTime(QDateTime(date, QTime())); 
00086     }
00087     if (task.constraintEndTime().isValid()) {
00088         setEndDateTime(task.constraintEndTime());
00089     } else {
00090         setEndDateTime(QDateTime(startDate().addDays(1), QTime())); 
00091     }
00092     //kdDebug()<<k_funcinfo<<"Effort: "<<task.effort()->expected().toString()<<endl;
00093     setEstimate(task.effort()->expected()); 
00094     setOptimistic(task.effort()->optimisticRatio());
00095     setPessimistic(task.effort()->pessimisticRatio());
00096     
00097     leaderfield->setFocus();
00098 }
00099 
00100 KMacroCommand *TaskDefaultPanel::buildCommand(Part *part) {
00101     KMacroCommand *cmd = new KMacroCommand(i18n("Modify Default Task"));
00102     bool modified = false;
00103 
00104     Duration dt = Duration();
00105 
00106     if (m_task.leader() != leaderfield->text()) {
00107         cmd->addCommand(new NodeModifyLeaderCmd(part, m_task, leaderfield->text()));
00108         modified = true;
00109     }
00110     if (m_task.description() != descriptionfield->text()) {
00111         cmd->addCommand(new NodeModifyDescriptionCmd(part, m_task, descriptionfield->text()));
00112         modified = true;
00113     }
00114     Node::ConstraintType c = (Node::ConstraintType)schedulingType();
00115     if (c != m_task.constraint()) {
00116         cmd->addCommand(new NodeModifyConstraintCmd(part, m_task, c));
00117         modified = true;
00118     }
00119     if (startDateTime() != m_task.constraintStartTime() &&
00120         (c == Node::FixedInterval || c == Node::StartNotEarlier || c == Node::MustStartOn)) {
00121         cmd->addCommand(new NodeModifyConstraintStartTimeCmd(part, m_task, startDateTime()));
00122         modified = true;
00123     }
00124     if (endDateTime() != m_task.constraintEndTime() &&
00125         (c == Node::FinishNotLater || c == Node::FixedInterval || c == Node::MustFinishOn)) {
00126         cmd->addCommand(new NodeModifyConstraintEndTimeCmd(part, m_task, endDateTime()));
00127         modified = true;
00128     }
00129     int et = estimationType();
00130     if (et != m_task.effort()->type()) {
00131         cmd->addCommand(new ModifyEffortTypeCmd(part, m_task,  m_task.effort()->type(), et));
00132         modified = true;
00133     }
00134     dt = estimationValue();
00135     kdDebug()<<k_funcinfo<<"Estimate: "<<dt.toString()<<endl;
00136     bool expchanged = dt != m_task.effort()->expected();
00137     if ( expchanged ) {
00138         cmd->addCommand(new ModifyEffortCmd(part, m_task, m_task.effort()->expected(), dt));
00139         modified = true;
00140     }
00141     int x = optimistic();
00142     if ( x != m_task.effort()->optimisticRatio() || expchanged) {
00143         cmd->addCommand(new EffortModifyOptimisticRatioCmd(part, m_task, m_task.effort()->optimisticRatio(), x));
00144         modified = true;
00145     }
00146     x = pessimistic();
00147     if ( x != m_task.effort()->pessimisticRatio() || expchanged) {
00148         cmd->addCommand(new EffortModifyPessimisticRatioCmd(part, m_task, m_task.effort()->pessimisticRatio(), x));
00149         modified = true;
00150     }
00151     if (!modified) {
00152         delete cmd;
00153         return 0;
00154     }
00155     return cmd;
00156 }
00157 
00158 bool TaskDefaultPanel::ok() {
00159     return true;
00160 }
00161 
00162 void TaskDefaultPanel::estimationTypeChanged(int type) {
00163     if (type == 0 /*Effort*/) {
00164         Duration d = estimationValue();
00165         setEstimateScales(m_dayLength);
00166         //setEstimate(d);
00167     } else {
00168         Duration d = estimationValue();
00169         setEstimateScales(24);
00170         //setEstimate(d);
00171     }
00172     ConfigTaskPanelImpl::estimationTypeChanged(type);
00173 }
00174 
00175 void TaskDefaultPanel::scheduleTypeChanged(int value)
00176 {
00177     if (value == 6 /*Fixed interval*/) { 
00178         if (estimateType->currentItem() == 1/*duration*/){
00179             setEstimateScales(24);
00180             //estimate->setEnabled(false);
00181             //setEstimate(DateTime(endDateTime()) - DateTime(startDateTime()));
00182         }
00183     } else {
00184         setEstimateScales(m_dayLength);
00185         estimate->setEnabled(true);
00186     }
00187     ConfigTaskPanelImpl::scheduleTypeChanged(value);
00188 }
00189 
00190 
00191 //-----------------------------
00192 ConfigTaskPanelImpl::ConfigTaskPanelImpl(QWidget *p, const char *n)
00193     : ConfigTaskPanelBase(p, n) {
00194     
00195     connect(leaderfield, SIGNAL(textChanged(const QString &)), SLOT(checkAllFieldsFilled()));
00196     connect(chooseLeader, SIGNAL(clicked()), SLOT(changeLeader()));
00197     connect(estimateType, SIGNAL(activated(int)), SLOT(estimationTypeChanged(int)));
00198     connect(scheduleType, SIGNAL(activated(int)), SLOT(scheduleTypeChanged(int)));
00199     connect(scheduleStartDate, SIGNAL(changed(QDate)), SLOT(startDateChanged()));
00200     connect(scheduleStartTime, SIGNAL(valueChanged(const QTime&)), SLOT(startTimeChanged(const QTime&)));
00201     connect(scheduleEndDate, SIGNAL(changed(QDate)), SLOT(endDateChanged()));
00202     connect(scheduleEndTime, SIGNAL(valueChanged(const QTime&)), SLOT(endTimeChanged(const QTime&)));
00203     connect(estimate, SIGNAL(valueChanged()), SLOT(checkAllFieldsFilled()));
00204     connect(optimisticValue, SIGNAL(valueChanged(int)), SLOT(checkAllFieldsFilled()));
00205     connect(pessimisticValue, SIGNAL(valueChanged(int)), SLOT(checkAllFieldsFilled()));
00206     connect(descriptionfield, SIGNAL(textChanged()), SLOT(checkAllFieldsFilled()));
00207 }
00208 
00209 void ConfigTaskPanelImpl::setSchedulingType(int type)
00210 {
00211     enableDateTime(type);
00212     scheduleType->setCurrentItem(type);
00213     emit schedulingTypeChanged(type);
00214 }
00215 
00216 int ConfigTaskPanelImpl::schedulingType() const 
00217 {
00218     return scheduleType->currentItem();
00219 }
00220 
00221 void ConfigTaskPanelImpl::changeLeader()
00222 {
00223     KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this);
00224     if (!a.isEmpty())
00225     {
00226         leaderfield->setText(a.fullEmail());
00227     }
00228 }
00229 
00230 void ConfigTaskPanelImpl::setEstimationType( int type )
00231 {
00232     estimateType->setCurrentItem(type);
00233 }
00234 
00235 int ConfigTaskPanelImpl::estimationType() const
00236 {
00237     return estimateType->currentItem();
00238 }
00239 
00240 void ConfigTaskPanelImpl::setOptimistic( int value )
00241 {
00242     optimisticValue->setValue(value);
00243 }
00244 
00245 void ConfigTaskPanelImpl::setPessimistic( int value )
00246 {
00247     pessimisticValue->setValue(value);
00248 }
00249 
00250 int ConfigTaskPanelImpl::optimistic() const
00251 {
00252     return optimisticValue->value();
00253 }
00254 
00255 int ConfigTaskPanelImpl::pessimistic()
00256 {
00257     return pessimisticValue->value();
00258 }
00259 
00260 void ConfigTaskPanelImpl::enableDateTime( int /*scheduleType*/ )
00261 {
00262     scheduleStartTime->setEnabled(true);
00263     scheduleEndTime->setEnabled(true);
00264     scheduleStartDate->setEnabled(true);
00265     scheduleEndDate->setEnabled(true);
00266 /*    switch (scheduleType)
00267     {
00268     case 0: //ASAP
00269     case 1: //ALAP
00270         break;
00271     case 2: //Must start on
00272     case 4: // Start not earlier
00273         if (useTime) {
00274             scheduleStartTime->setEnabled(true);
00275             scheduleEndTime->setEnabled(false);
00276         }
00277         scheduleStartDate->setEnabled(true);
00278         scheduleEndDate->setEnabled(false);
00279         break;
00280     case 3: //Must finish on
00281     case 5: // Finish not later
00282         if (useTime) {
00283             scheduleStartTime->setEnabled(false);
00284             scheduleEndTime->setEnabled(true);
00285         }
00286         scheduleStartDate->setEnabled(false);
00287         scheduleEndDate->setEnabled(true);
00288         break;
00289     case 6: //Fixed interval
00290         if (useTime) {
00291             scheduleStartTime->setEnabled(true);
00292             scheduleEndTime->setEnabled(true);
00293         }
00294         scheduleStartDate->setEnabled(true);
00295         scheduleEndDate->setEnabled(true);
00296         break;
00297     default:
00298         break;
00299     }*/
00300 }
00301 
00302 
00303 void ConfigTaskPanelImpl::estimationTypeChanged( int /*type*/ )
00304 {
00305     checkAllFieldsFilled();
00306 }
00307 
00308 
00309 
00310 void ConfigTaskPanelImpl::setEstimate( const Duration & duration)
00311 {
00312     estimate->setValue( duration );
00313 }
00314 
00315 
00316 void ConfigTaskPanelImpl::setEstimateType( int type)
00317 {
00318     estimateType->setCurrentItem(type);
00319 }
00320 
00321 
00322 void ConfigTaskPanelImpl::checkAllFieldsFilled()
00323 {
00324     emit changed();
00325     emit obligatedFieldsFilled(true);
00326 }
00327 
00328 
00329 Duration ConfigTaskPanelImpl::estimationValue()
00330 {
00331     return estimate->value();
00332 }
00333 
00334 
00335 void ConfigTaskPanelImpl::setEstimateFields( int mask )
00336 {
00337     estimate->setVisibleFields(mask);
00338 }
00339 
00340 
00341 void ConfigTaskPanelImpl::setEstimateScales( double day )
00342 {
00343     estimate->setFieldScale(0, day);
00344     estimate->setFieldRightscale(0, day);
00345     
00346     estimate->setFieldLeftscale(1, day);
00347 }
00348 
00349 
00350 void ConfigTaskPanelImpl::setEstimateFieldUnit( int field, QString unit )
00351 {
00352     estimate->setFieldUnit(field, unit);
00353 }
00354 
00355 void ConfigTaskPanelImpl::startDateChanged()
00356 {
00357     if (!scheduleStartDate->isEnabled()) {
00358         return;
00359     }
00360     QDate date = startDate();
00361     if (startDateTime() > endDateTime()) 
00362     {
00363         scheduleEndTime->blockSignals(true);
00364         scheduleEndDate->blockSignals(true);
00365         setEndDate(date);
00366         setEndTime(startTime());
00367         scheduleEndTime->blockSignals(false);
00368         scheduleEndDate->blockSignals(false);
00369     }
00370     if (scheduleType->currentItem() == 6 /*FixedInterval*/)
00371     {
00372         estimationTypeChanged(estimateType->currentItem());
00373     }
00374     checkAllFieldsFilled();
00375 }
00376 
00377 void ConfigTaskPanelImpl::startTimeChanged( const QTime &time )
00378 {
00379     if (!scheduleStartTime->isEnabled()) {
00380         return;
00381     }
00382     if (startDateTime() > endDateTime()) 
00383     {
00384         scheduleEndTime->blockSignals(true);
00385         setEndTime(time);
00386         scheduleEndTime->blockSignals(false);
00387     }
00388     if (scheduleType->currentItem() == 6 /*FixedInterval*/)
00389     {
00390         estimationTypeChanged(estimateType->currentItem());
00391     }
00392     checkAllFieldsFilled();
00393 }
00394 
00395 
00396 void ConfigTaskPanelImpl::endDateChanged()
00397 {
00398     if (!scheduleEndDate->isEnabled()) {
00399         return;
00400     }
00401     QDate date = endDate();
00402     if (endDateTime() < startDateTime()) 
00403     {
00404         scheduleStartTime->blockSignals(true);
00405         scheduleStartDate->blockSignals(true);
00406         setStartDate(date);
00407         setStartTime(endTime());
00408         scheduleStartTime->blockSignals(false);
00409         scheduleStartDate->blockSignals(false);
00410     }
00411     
00412     if (scheduleType->currentItem() == 6 /*FixedInterval*/)
00413     {
00414         estimationTypeChanged(estimateType->currentItem());
00415     }
00416     checkAllFieldsFilled();
00417 }
00418 
00419 void ConfigTaskPanelImpl::endTimeChanged( const QTime &time )
00420 {
00421     if (!scheduleEndTime->isEnabled()) {
00422         return;
00423     }
00424     if (endDateTime() < startDateTime()) 
00425     {
00426         scheduleStartTime->blockSignals(true);
00427         setStartTime(time);
00428         scheduleStartTime->blockSignals(false);
00429     }
00430     
00431     if (scheduleType->currentItem() == 6 /*FixedInterval*/)
00432     {
00433         estimationTypeChanged(estimateType->currentItem());
00434     }
00435     checkAllFieldsFilled();
00436 }
00437 
00438 void ConfigTaskPanelImpl::scheduleTypeChanged( int value )
00439 {
00440      estimationTypeChanged(estimateType->currentItem());
00441      enableDateTime(value);
00442      checkAllFieldsFilled();
00443 }
00444 
00445 
00446 QDateTime ConfigTaskPanelImpl::startDateTime()
00447 {
00448     return QDateTime(startDate(), startTime());
00449 }
00450 
00451 
00452 QDateTime ConfigTaskPanelImpl::endDateTime()
00453 {
00454     return QDateTime(endDate(), endTime());
00455 }
00456 
00457 void ConfigTaskPanelImpl::setStartTime( const QTime &time )
00458 {
00459     scheduleStartTime->setTime(time);
00460 }
00461 
00462 void ConfigTaskPanelImpl::setEndTime( const QTime &time )
00463 {
00464     scheduleEndTime->setTime(time);
00465 }
00466 
00467 QTime ConfigTaskPanelImpl::startTime() const
00468 {
00469     return scheduleStartTime->time();
00470 }
00471 
00472 QTime ConfigTaskPanelImpl::endTime()
00473 {
00474     return scheduleEndTime->time();
00475 }
00476 
00477 QDate ConfigTaskPanelImpl::startDate()
00478 {
00479     return scheduleStartDate->date();
00480 }
00481 
00482 
00483 QDate ConfigTaskPanelImpl::endDate()
00484 {
00485     return scheduleEndDate->date();
00486 }
00487 
00488 void ConfigTaskPanelImpl::setStartDateTime( const QDateTime &dt )
00489 {
00490     setStartDate(dt.date());
00491     setStartTime(dt.time());
00492 }
00493 
00494 
00495 void ConfigTaskPanelImpl::setEndDateTime( const QDateTime &dt )
00496 {
00497     setEndDate(dt.date());
00498     setEndTime(dt.time());
00499 }
00500 
00501 void ConfigTaskPanelImpl::setStartDate( const QDate &date )
00502 {
00503     scheduleStartDate->setDate(date);
00504 }
00505 
00506 
00507 void ConfigTaskPanelImpl::setEndDate( const QDate &date )
00508 {
00509     scheduleEndDate->setDate(date);
00510 }
00511 
00512 
00513 }  //KPlato namespace
00514 
00515 #include "kpttaskdefaultpanel.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys