F:/KPlato/koffice/kplato/kpttaskdefaultpanel.cc

Aller à la documentation de ce fichier.
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>
00042 #include <QLabel>
00043 #include <qdatetime.h>
00044 #include <q3datetimeedit.h>
00045 #include <q3groupbox.h>
00046 #include <QPushButton>
00047 #include <QSpinBox>
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         //kDebug()<<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, i18nc("days", "d"));
00076     setEstimateFieldUnit(1, i18nc("hours", "h"));
00077     setEstimateFieldUnit(2, i18nc("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     //kDebug()<<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     kDebug()<<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->currentIndex() == 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     : QWidget(p) {
00194 
00195     setObjectName(n);
00196     setupUi(this);
00197     estimate = new DurationWidget(durationHolder);
00198     if (durationHolder->layout()) 
00199         durationHolder->layout()->addWidget(estimate);
00200 
00201     connect(leaderfield, SIGNAL(textChanged(const QString &)), SLOT(checkAllFieldsFilled()));
00202     connect(chooseLeader, SIGNAL(clicked()), SLOT(changeLeader()));
00203     connect(estimateType, SIGNAL(activated(int)), SLOT(estimationTypeChanged(int)));
00204     connect(scheduleType, SIGNAL(activated(int)), SLOT(scheduleTypeChanged(int)));
00205     connect(scheduleStartDate, SIGNAL(changed(QDate)), SLOT(startDateChanged()));
00206     connect(scheduleStartTime, SIGNAL(valueChanged(const QTime&)), SLOT(startTimeChanged(const QTime&)));
00207     connect(scheduleEndDate, SIGNAL(changed(QDate)), SLOT(endDateChanged()));
00208     connect(scheduleEndTime, SIGNAL(valueChanged(const QTime&)), SLOT(endTimeChanged(const QTime&)));
00209     connect(estimate, SIGNAL(valueChanged()), SLOT(checkAllFieldsFilled()));
00210     connect(optimisticValue, SIGNAL(valueChanged(int)), SLOT(checkAllFieldsFilled()));
00211     connect(pessimisticValue, SIGNAL(valueChanged(int)), SLOT(checkAllFieldsFilled()));
00212     connect(descriptionfield, SIGNAL(textChanged()), SLOT(checkAllFieldsFilled()));
00213 }
00214 
00215 void ConfigTaskPanelImpl::setSchedulingType(int type)
00216 {
00217     enableDateTime(type);
00218     scheduleType->setCurrentIndex(type);
00219     emit schedulingTypeChanged(type);
00220 }
00221 
00222 int ConfigTaskPanelImpl::schedulingType() const
00223 {
00224     return scheduleType->currentIndex();
00225 }
00226 
00227 void ConfigTaskPanelImpl::changeLeader()
00228 {
00229     KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this);
00230     if (!a.isEmpty())
00231     {
00232         leaderfield->setText(a.fullEmail());
00233     }
00234 }
00235 
00236 void ConfigTaskPanelImpl::setEstimationType( int type )
00237 {
00238     estimateType->setCurrentIndex(type);
00239 }
00240 
00241 int ConfigTaskPanelImpl::estimationType() const
00242 {
00243     return estimateType->currentIndex();
00244 }
00245 
00246 void ConfigTaskPanelImpl::setOptimistic( int value )
00247 {
00248     optimisticValue->setValue(value);
00249 }
00250 
00251 void ConfigTaskPanelImpl::setPessimistic( int value )
00252 {
00253     pessimisticValue->setValue(value);
00254 }
00255 
00256 int ConfigTaskPanelImpl::optimistic() const
00257 {
00258     return optimisticValue->value();
00259 }
00260 
00261 int ConfigTaskPanelImpl::pessimistic()
00262 {
00263     return pessimisticValue->value();
00264 }
00265 
00266 void ConfigTaskPanelImpl::enableDateTime( int /*scheduleType*/ )
00267 {
00268     scheduleStartTime->setEnabled(true);
00269     scheduleEndTime->setEnabled(true);
00270     scheduleStartDate->setEnabled(true);
00271     scheduleEndDate->setEnabled(true);
00272 /*    switch (scheduleType)
00273     {
00274     case 0: //ASAP
00275     case 1: //ALAP
00276         break;
00277     case 2: //Must start on
00278     case 4: // Start not earlier
00279         if (useTime) {
00280             scheduleStartTime->setEnabled(true);
00281             scheduleEndTime->setEnabled(false);
00282         }
00283         scheduleStartDate->setEnabled(true);
00284         scheduleEndDate->setEnabled(false);
00285         break;
00286     case 3: //Must finish on
00287     case 5: // Finish not later
00288         if (useTime) {
00289             scheduleStartTime->setEnabled(false);
00290             scheduleEndTime->setEnabled(true);
00291         }
00292         scheduleStartDate->setEnabled(false);
00293         scheduleEndDate->setEnabled(true);
00294         break;
00295     case 6: //Fixed interval
00296         if (useTime) {
00297             scheduleStartTime->setEnabled(true);
00298             scheduleEndTime->setEnabled(true);
00299         }
00300         scheduleStartDate->setEnabled(true);
00301         scheduleEndDate->setEnabled(true);
00302         break;
00303     default:
00304         break;
00305     }*/
00306 }
00307 
00308 
00309 void ConfigTaskPanelImpl::estimationTypeChanged( int /*type*/ )
00310 {
00311     checkAllFieldsFilled();
00312 }
00313 
00314 
00315 
00316 void ConfigTaskPanelImpl::setEstimate( const Duration & duration)
00317 {
00318     estimate->setValue( duration );
00319 }
00320 
00321 
00322 void ConfigTaskPanelImpl::setEstimateType( int type)
00323 {
00324     estimateType->setCurrentIndex(type);
00325 }
00326 
00327 
00328 void ConfigTaskPanelImpl::checkAllFieldsFilled()
00329 {
00330     emit changed();
00331     emit obligatedFieldsFilled(true);
00332 }
00333 
00334 
00335 Duration ConfigTaskPanelImpl::estimationValue()
00336 {
00337     return estimate->value();
00338 }
00339 
00340 
00341 void ConfigTaskPanelImpl::setEstimateFields( int mask )
00342 {
00343     estimate->setVisibleFields(mask);
00344 }
00345 
00346 
00347 void ConfigTaskPanelImpl::setEstimateScales( double day )
00348 {
00349     estimate->setFieldScale(0, day);
00350     estimate->setFieldRightscale(0, day);
00351 
00352     estimate->setFieldLeftscale(1, day);
00353 }
00354 
00355 
00356 void ConfigTaskPanelImpl::setEstimateFieldUnit( int field, QString unit )
00357 {
00358     estimate->setFieldUnit(field, unit);
00359 }
00360 
00361 void ConfigTaskPanelImpl::startDateChanged()
00362 {
00363     if (!scheduleStartDate->isEnabled()) {
00364         return;
00365     }
00366     QDate date = startDate();
00367     if (startDateTime() > endDateTime())
00368     {
00369         scheduleEndTime->blockSignals(true);
00370         scheduleEndDate->blockSignals(true);
00371         setEndDate(date);
00372         setEndTime(startTime());
00373         scheduleEndTime->blockSignals(false);
00374         scheduleEndDate->blockSignals(false);
00375     }
00376     if (scheduleType->currentIndex() == 6 /*FixedInterval*/)
00377     {
00378         estimationTypeChanged(estimateType->currentIndex());
00379     }
00380     checkAllFieldsFilled();
00381 }
00382 
00383 void ConfigTaskPanelImpl::startTimeChanged( const QTime &time )
00384 {
00385     if (!scheduleStartTime->isEnabled()) {
00386         return;
00387     }
00388     if (startDateTime() > endDateTime())
00389     {
00390         scheduleEndTime->blockSignals(true);
00391         setEndTime(time);
00392         scheduleEndTime->blockSignals(false);
00393     }
00394     if (scheduleType->currentIndex() == 6 /*FixedInterval*/)
00395     {
00396         estimationTypeChanged(estimateType->currentIndex());
00397     }
00398     checkAllFieldsFilled();
00399 }
00400 
00401 
00402 void ConfigTaskPanelImpl::endDateChanged()
00403 {
00404     if (!scheduleEndDate->isEnabled()) {
00405         return;
00406     }
00407     QDate date = endDate();
00408     if (endDateTime() < startDateTime())
00409     {
00410         scheduleStartTime->blockSignals(true);
00411         scheduleStartDate->blockSignals(true);
00412         setStartDate(date);
00413         setStartTime(endTime());
00414         scheduleStartTime->blockSignals(false);
00415         scheduleStartDate->blockSignals(false);
00416     }
00417 
00418     if (scheduleType->currentIndex() == 6 /*FixedInterval*/)
00419     {
00420         estimationTypeChanged(estimateType->currentIndex());
00421     }
00422     checkAllFieldsFilled();
00423 }
00424 
00425 void ConfigTaskPanelImpl::endTimeChanged( const QTime &time )
00426 {
00427     if (!scheduleEndTime->isEnabled()) {
00428         return;
00429     }
00430     if (endDateTime() < startDateTime())
00431     {
00432         scheduleStartTime->blockSignals(true);
00433         setStartTime(time);
00434         scheduleStartTime->blockSignals(false);
00435     }
00436 
00437     if (scheduleType->currentIndex() == 6 /*FixedInterval*/)
00438     {
00439         estimationTypeChanged(estimateType->currentIndex());
00440     }
00441     checkAllFieldsFilled();
00442 }
00443 
00444 void ConfigTaskPanelImpl::scheduleTypeChanged( int value )
00445 {
00446      estimationTypeChanged(estimateType->currentIndex());
00447      enableDateTime(value);
00448      checkAllFieldsFilled();
00449 }
00450 
00451 
00452 QDateTime ConfigTaskPanelImpl::startDateTime()
00453 {
00454     return QDateTime(startDate(), startTime());
00455 }
00456 
00457 
00458 QDateTime ConfigTaskPanelImpl::endDateTime()
00459 {
00460     return QDateTime(endDate(), endTime());
00461 }
00462 
00463 void ConfigTaskPanelImpl::setStartTime( const QTime &time )
00464 {
00465     scheduleStartTime->setTime(time);
00466 }
00467 
00468 void ConfigTaskPanelImpl::setEndTime( const QTime &time )
00469 {
00470     scheduleEndTime->setTime(time);
00471 }
00472 
00473 QTime ConfigTaskPanelImpl::startTime() const
00474 {
00475     return scheduleStartTime->time();
00476 }
00477 
00478 QTime ConfigTaskPanelImpl::endTime()
00479 {
00480     return scheduleEndTime->time();
00481 }
00482 
00483 QDate ConfigTaskPanelImpl::startDate()
00484 {
00485     return scheduleStartDate->date();
00486 }
00487 
00488 
00489 QDate ConfigTaskPanelImpl::endDate()
00490 {
00491     return scheduleEndDate->date();
00492 }
00493 
00494 void ConfigTaskPanelImpl::setStartDateTime( const QDateTime &dt )
00495 {
00496     setStartDate(dt.date());
00497     setStartTime(dt.time());
00498 }
00499 
00500 
00501 void ConfigTaskPanelImpl::setEndDateTime( const QDateTime &dt )
00502 {
00503     setEndDate(dt.date());
00504     setEndTime(dt.time());
00505 }
00506 
00507 void ConfigTaskPanelImpl::setStartDate( const QDate &date )
00508 {
00509     scheduleStartDate->setDate(date);
00510 }
00511 
00512 
00513 void ConfigTaskPanelImpl::setEndDate( const QDate &date )
00514 {
00515     scheduleEndDate->setDate(date);
00516 }
00517 
00518 
00519 }  //KPlato namespace
00520 
00521 #include "kpttaskdefaultpanel.moc"

Généré le Wed Nov 22 23:40:58 2006 pour KPlato par  doxygen 1.5.1-p1