20#include "kpttaskdefaultpanel.h"
22#include "kptcommand.h"
23#include "kptduration.h"
24#include "kptdurationwidget.h"
25#include "kptcalendar.h"
26#include "kptdatetime.h"
30#include <tdemessagebox.h>
34#include <kdatetimewidget.h>
37#include <tdeabc/addressee.h>
38#include <tdeabc/addresseedialog.h>
39#include <kdatewidget.h>
43#include <tqdatetime.h>
44#include <tqdatetimeedit.h>
45#include <tqgroupbox.h>
46#include <tqpushbutton.h>
54TaskDefaultPanel::TaskDefaultPanel(
Task &task, StandardWorktime *workTime, TQWidget *parent,
const char *n)
55 : ConfigTaskPanelImpl(parent, n),
59 setStartValues(task, workTime);
62void TaskDefaultPanel::setStartValues(Task &task, StandardWorktime *workTime) {
63 m_effort = m_duration = task.effort()->expected();
64 leaderfield->setText(task.leader());
65 descriptionfield->setText(task.description());
67 setEstimateFields(DurationWidget::Days|DurationWidget::Hours|DurationWidget::Minutes);
70 m_dayLength = workTime->day();
71 if (task.effort()->type() == Effort::Type_Effort) {
72 setEstimateScales(m_dayLength);
75 setEstimateFieldUnit(0, i18n(
"days",
"d"));
76 setEstimateFieldUnit(1, i18n(
"hours",
"h"));
77 setEstimateFieldUnit(2, i18n(
"minutes",
"m"));
78 setEstimateType(task.effort()->type());
80 setSchedulingType(task.constraint());
81 if (task.constraintStartTime().isValid()) {
82 setStartDateTime(task.constraintStartTime());
84 TQDate date = TQDate::currentDate();
85 setStartDateTime(TQDateTime(date, TQTime()));
87 if (task.constraintEndTime().isValid()) {
88 setEndDateTime(task.constraintEndTime());
90 setEndDateTime(TQDateTime(startDate().addDays(1), TQTime()));
93 setEstimate(task.effort()->expected());
94 setOptimistic(task.effort()->optimisticRatio());
95 setPessimistic(task.effort()->pessimisticRatio());
97 leaderfield->setFocus();
100KMacroCommand *TaskDefaultPanel::buildCommand(Part *part) {
101 KMacroCommand *cmd =
new KMacroCommand(i18n(
"Modify Default Task"));
102 bool modified =
false;
104 Duration dt = Duration();
106 if (m_task.leader() != leaderfield->text()) {
107 cmd->addCommand(
new NodeModifyLeaderCmd(part, m_task, leaderfield->text()));
110 if (m_task.description() != descriptionfield->text()) {
111 cmd->addCommand(
new NodeModifyDescriptionCmd(part, m_task, descriptionfield->text()));
114 Node::ConstraintType c = (Node::ConstraintType)schedulingType();
115 if (c != m_task.constraint()) {
116 cmd->addCommand(
new NodeModifyConstraintCmd(part, m_task, c));
119 if (startDateTime() != m_task.constraintStartTime() &&
120 (c == Node::FixedInterval || c == Node::StartNotEarlier || c == Node::MustStartOn)) {
121 cmd->addCommand(
new NodeModifyConstraintStartTimeCmd(part, m_task, startDateTime()));
124 if (endDateTime() != m_task.constraintEndTime() &&
125 (c == Node::FinishNotLater || c == Node::FixedInterval || c == Node::MustFinishOn)) {
126 cmd->addCommand(
new NodeModifyConstraintEndTimeCmd(part, m_task, endDateTime()));
129 int et = estimationType();
130 if (et != m_task.effort()->type()) {
131 cmd->addCommand(
new ModifyEffortTypeCmd(part, m_task, m_task.effort()->type(), et));
134 dt = estimationValue();
135 kdDebug()<<k_funcinfo<<
"Estimate: "<<dt.toString()<<endl;
136 bool expchanged = dt != m_task.effort()->expected();
138 cmd->addCommand(
new ModifyEffortCmd(part, m_task, m_task.effort()->expected(), dt));
141 int x = optimistic();
142 if ( x != m_task.effort()->optimisticRatio() || expchanged) {
143 cmd->addCommand(
new EffortModifyOptimisticRatioCmd(part, m_task, m_task.effort()->optimisticRatio(), x));
147 if ( x != m_task.effort()->pessimisticRatio() || expchanged) {
148 cmd->addCommand(
new EffortModifyPessimisticRatioCmd(part, m_task, m_task.effort()->pessimisticRatio(), x));
158bool TaskDefaultPanel::ok() {
162void TaskDefaultPanel::estimationTypeChanged(
int type) {
164 Duration d = estimationValue();
165 setEstimateScales(m_dayLength);
168 Duration d = estimationValue();
169 setEstimateScales(24);
172 ConfigTaskPanelImpl::estimationTypeChanged(type);
175void TaskDefaultPanel::scheduleTypeChanged(
int value)
178 if (estimateType->currentItem() == 1){
179 setEstimateScales(24);
184 setEstimateScales(m_dayLength);
185 estimate->setEnabled(
true);
187 ConfigTaskPanelImpl::scheduleTypeChanged(value);
192ConfigTaskPanelImpl::ConfigTaskPanelImpl(TQWidget *p,
const char *n)
193 : ConfigTaskPanelBase(p, n) {
195 connect(leaderfield, TQ_SIGNAL(textChanged(
const TQString &)), TQ_SLOT(checkAllFieldsFilled()));
196 connect(chooseLeader, TQ_SIGNAL(clicked()), TQ_SLOT(changeLeader()));
197 connect(estimateType, TQ_SIGNAL(activated(
int)), TQ_SLOT(estimationTypeChanged(
int)));
198 connect(scheduleType, TQ_SIGNAL(activated(
int)), TQ_SLOT(scheduleTypeChanged(
int)));
199 connect(scheduleStartDate, TQ_SIGNAL(changed(TQDate)), TQ_SLOT(startDateChanged()));
200 connect(scheduleStartTime, TQ_SIGNAL(valueChanged(
const TQTime&)), TQ_SLOT(startTimeChanged(
const TQTime&)));
201 connect(scheduleEndDate, TQ_SIGNAL(changed(TQDate)), TQ_SLOT(endDateChanged()));
202 connect(scheduleEndTime, TQ_SIGNAL(valueChanged(
const TQTime&)), TQ_SLOT(endTimeChanged(
const TQTime&)));
203 connect(estimate, TQ_SIGNAL(valueChanged()), TQ_SLOT(checkAllFieldsFilled()));
204 connect(optimisticValue, TQ_SIGNAL(valueChanged(
int)), TQ_SLOT(checkAllFieldsFilled()));
205 connect(pessimisticValue, TQ_SIGNAL(valueChanged(
int)), TQ_SLOT(checkAllFieldsFilled()));
206 connect(descriptionfield, TQ_SIGNAL(textChanged()), TQ_SLOT(checkAllFieldsFilled()));
209void ConfigTaskPanelImpl::setSchedulingType(
int type)
211 enableDateTime(type);
212 scheduleType->setCurrentItem(type);
213 emit schedulingTypeChanged(type);
216int ConfigTaskPanelImpl::schedulingType()
const
218 return scheduleType->currentItem();
221void ConfigTaskPanelImpl::changeLeader()
223 TDEABC::Addressee a = TDEABC::AddresseeDialog::getAddressee(
this);
226 leaderfield->setText(a.fullEmail());
230void ConfigTaskPanelImpl::setEstimationType(
int type )
232 estimateType->setCurrentItem(type);
235int ConfigTaskPanelImpl::estimationType()
const
237 return estimateType->currentItem();
240void ConfigTaskPanelImpl::setOptimistic(
int value )
242 optimisticValue->setValue(value);
245void ConfigTaskPanelImpl::setPessimistic(
int value )
247 pessimisticValue->setValue(value);
250int ConfigTaskPanelImpl::optimistic()
const
252 return optimisticValue->value();
255int ConfigTaskPanelImpl::pessimistic()
257 return pessimisticValue->value();
260void ConfigTaskPanelImpl::enableDateTime(
int )
262 scheduleStartTime->setEnabled(
true);
263 scheduleEndTime->setEnabled(
true);
264 scheduleStartDate->setEnabled(
true);
265 scheduleEndDate->setEnabled(
true);
303void ConfigTaskPanelImpl::estimationTypeChanged(
int )
305 checkAllFieldsFilled();
310void ConfigTaskPanelImpl::setEstimate(
const Duration & duration)
312 estimate->setValue( duration );
316void ConfigTaskPanelImpl::setEstimateType(
int type)
318 estimateType->setCurrentItem(type);
322void ConfigTaskPanelImpl::checkAllFieldsFilled()
325 emit obligatedFieldsFilled(
true);
329Duration ConfigTaskPanelImpl::estimationValue()
331 return estimate->value();
335void ConfigTaskPanelImpl::setEstimateFields(
int mask )
337 estimate->setVisibleFields(mask);
341void ConfigTaskPanelImpl::setEstimateScales(
double day )
343 estimate->setFieldScale(0, day);
344 estimate->setFieldRightscale(0, day);
346 estimate->setFieldLeftscale(1, day);
350void ConfigTaskPanelImpl::setEstimateFieldUnit(
int field, TQString unit )
352 estimate->setFieldUnit(field, unit);
355void ConfigTaskPanelImpl::startDateChanged()
357 if (!scheduleStartDate->isEnabled()) {
360 TQDate date = startDate();
361 if (startDateTime() > endDateTime())
363 scheduleEndTime->blockSignals(
true);
364 scheduleEndDate->blockSignals(
true);
366 setEndTime(startTime());
367 scheduleEndTime->blockSignals(
false);
368 scheduleEndDate->blockSignals(
false);
370 if (scheduleType->currentItem() == 6 )
372 estimationTypeChanged(estimateType->currentItem());
374 checkAllFieldsFilled();
377void ConfigTaskPanelImpl::startTimeChanged(
const TQTime &time )
379 if (!scheduleStartTime->isEnabled()) {
382 if (startDateTime() > endDateTime())
384 scheduleEndTime->blockSignals(
true);
386 scheduleEndTime->blockSignals(
false);
388 if (scheduleType->currentItem() == 6 )
390 estimationTypeChanged(estimateType->currentItem());
392 checkAllFieldsFilled();
396void ConfigTaskPanelImpl::endDateChanged()
398 if (!scheduleEndDate->isEnabled()) {
401 TQDate date = endDate();
402 if (endDateTime() < startDateTime())
404 scheduleStartTime->blockSignals(
true);
405 scheduleStartDate->blockSignals(
true);
407 setStartTime(endTime());
408 scheduleStartTime->blockSignals(
false);
409 scheduleStartDate->blockSignals(
false);
412 if (scheduleType->currentItem() == 6 )
414 estimationTypeChanged(estimateType->currentItem());
416 checkAllFieldsFilled();
419void ConfigTaskPanelImpl::endTimeChanged(
const TQTime &time )
421 if (!scheduleEndTime->isEnabled()) {
424 if (endDateTime() < startDateTime())
426 scheduleStartTime->blockSignals(
true);
428 scheduleStartTime->blockSignals(
false);
431 if (scheduleType->currentItem() == 6 )
433 estimationTypeChanged(estimateType->currentItem());
435 checkAllFieldsFilled();
438void ConfigTaskPanelImpl::scheduleTypeChanged(
int value )
440 estimationTypeChanged(estimateType->currentItem());
441 enableDateTime(value);
442 checkAllFieldsFilled();
446TQDateTime ConfigTaskPanelImpl::startDateTime()
448 return TQDateTime(startDate(), startTime());
452TQDateTime ConfigTaskPanelImpl::endDateTime()
454 return TQDateTime(endDate(), endTime());
457void ConfigTaskPanelImpl::setStartTime(
const TQTime &time )
459 scheduleStartTime->setTime(time);
462void ConfigTaskPanelImpl::setEndTime(
const TQTime &time )
464 scheduleEndTime->setTime(time);
467TQTime ConfigTaskPanelImpl::startTime()
const
469 return scheduleStartTime->time();
472TQTime ConfigTaskPanelImpl::endTime()
474 return scheduleEndTime->time();
477TQDate ConfigTaskPanelImpl::startDate()
479 return scheduleStartDate->date();
483TQDate ConfigTaskPanelImpl::endDate()
485 return scheduleEndDate->date();
488void ConfigTaskPanelImpl::setStartDateTime(
const TQDateTime &dt )
490 setStartDate(dt.date());
491 setStartTime(dt.time());
495void ConfigTaskPanelImpl::setEndDateTime(
const TQDateTime &dt )
497 setEndDate(dt.date());
498 setEndTime(dt.time());
501void ConfigTaskPanelImpl::setStartDate(
const TQDate &date )
503 scheduleStartDate->setDate(date);
507void ConfigTaskPanelImpl::setEndDate(
const TQDate &date )
509 scheduleEndDate->setDate(date);
515#include "kpttaskdefaultpanel.moc"
A task in the scheduling software is represented by this class.