20#include "kpttaskgeneralpanel.h"
21#include "kpttaskdialog.h"
23#include "kptcommand.h"
24#include "kptduration.h"
25#include "kptdurationwidget.h"
26#include "kptcalendar.h"
27#include "kptdatetime.h"
31#include <tdemessagebox.h>
35#include <kdatetimewidget.h>
38#include <tdeabc/addressee.h>
39#include <tdeabc/addresseedialog.h>
40#include <kdatewidget.h>
44#include <tqdatetime.h>
45#include <tqdatetimeedit.h>
46#include <tqgroupbox.h>
47#include <tqpushbutton.h>
55TaskGeneralPanel::TaskGeneralPanel(Task &task, StandardWorktime *workTime,
bool , TQWidget *p,
const char *n)
56 : TaskGeneralPanelImpl(p, n),
61 setStartValues(task, workTime);
71void TaskGeneralPanel::setStartValues(Task &task, StandardWorktime *workTime) {
72 m_effort = m_duration = task.effort()->expected();
73 namefield->setText(task.name());
74 leaderfield->setText(task.leader());
75 descriptionfield->setText(task.description());
76 idfield->setText(task.id());
77 wbsfield->setText(task.wbs());
79 setEstimateFields(DurationWidget::Days|DurationWidget::Hours|DurationWidget::Minutes);
82 m_dayLength = workTime->day();
83 if (task.effort()->type() == Effort::Type_Effort) {
84 setEstimateScales(m_dayLength);
87 setEstimateFieldUnit(0, i18n(
"days",
"d"));
88 setEstimateFieldUnit(1, i18n(
"hours",
"h"));
89 setEstimateFieldUnit(2, i18n(
"minutes",
"m"));
90 setEstimateType(task.effort()->type());
92 setSchedulingType(task.constraint());
93 if (task.constraintStartTime().isValid()) {
94 setStartDateTime(task.constraintStartTime());
96 TQDate date = TQDate::currentDate();
97 setStartDateTime(TQDateTime(date, TQTime()));
99 if (task.constraintEndTime().isValid()) {
100 setEndDateTime(task.constraintEndTime());
102 setEndDateTime(TQDateTime(startDate().addDays(1), TQTime()));
105 setEstimate(task.effort()->expected());
106 setOptimistic(task.effort()->optimisticRatio());
107 setPessimistic(task.effort()->pessimisticRatio());
108 setRisktype(task.effort()->risktype());
109 namefield->setFocus();
112KMacroCommand *TaskGeneralPanel::buildCommand(Part *part) {
113 KMacroCommand *cmd =
new KMacroCommand(i18n(
"Modify Task"));
114 bool modified =
false;
116 Duration dt = Duration();
118 if (!namefield->isHidden() && m_task.name() != namefield->text()) {
119 cmd->addCommand(
new NodeModifyNameCmd(part, m_task, namefield->text()));
122 if (!leaderfield->isHidden() && m_task.leader() != leaderfield->text()) {
123 cmd->addCommand(
new NodeModifyLeaderCmd(part, m_task, leaderfield->text()));
126 if (!descriptionfield->isHidden() &&
127 m_task.description() != descriptionfield->text()) {
128 cmd->addCommand(
new NodeModifyDescriptionCmd(part, m_task, descriptionfield->text()));
131 Node::ConstraintType c = (Node::ConstraintType)schedulingType();
132 if (c != m_task.constraint()) {
133 cmd->addCommand(
new NodeModifyConstraintCmd(part, m_task, c));
136 if (startDateTime() != m_task.constraintStartTime() &&
137 (c == Node::FixedInterval || c == Node::StartNotEarlier || c == Node::MustStartOn)) {
138 cmd->addCommand(
new NodeModifyConstraintStartTimeCmd(part, m_task, startDateTime()));
141 if (endDateTime() != m_task.constraintEndTime() &&
142 (c == Node::FinishNotLater || c == Node::FixedInterval || c == Node::MustFinishOn)) {
143 cmd->addCommand(
new NodeModifyConstraintEndTimeCmd(part, m_task, endDateTime()));
146 if (!idfield->isHidden() && idfield->text() != m_task.id()) {
148 cmd->addCommand(
new NodeModifyIdCmd(part, m_task, idfield->text()));
151 int et = estimationType();
152 if (et != m_task.effort()->type()) {
153 cmd->addCommand(
new ModifyEffortTypeCmd(part, m_task, m_task.effort()->type(), et));
156 dt = estimationValue();
157 kdDebug()<<k_funcinfo<<
"Estimate: "<<dt.toString()<<endl;
158 bool expchanged = dt != m_task.effort()->expected();
160 cmd->addCommand(
new ModifyEffortCmd(part, m_task, m_task.effort()->expected(), dt));
163 int x = optimistic();
164 if ( x != m_task.effort()->optimisticRatio() || expchanged) {
165 cmd->addCommand(
new EffortModifyOptimisticRatioCmd(part, m_task, m_task.effort()->optimisticRatio(), x));
169 if ( x != m_task.effort()->pessimisticRatio() || expchanged) {
170 cmd->addCommand(
new EffortModifyPessimisticRatioCmd(part, m_task, m_task.effort()->pessimisticRatio(), x));
173 if (m_task.effort()->risktype() != risktype()) {
174 cmd->addCommand(
new EffortModifyRiskCmd(part, m_task, m_task.effort()->risktype(), risktype()));
184bool TaskGeneralPanel::ok() {
185 if (idfield->text() != m_task.id() && m_task.findNode(idfield->text())) {
186 KMessageBox::sorry(
this, i18n(
"Task id must be unique"));
193void TaskGeneralPanel::estimationTypeChanged(
int type) {
195 Duration d = estimationValue();
196 setEstimateScales(m_dayLength);
198 estimate->setEnabled(
true);
200 Duration d = estimationValue();
201 setEstimateScales(24);
203 if (schedulingType() == 6) {
204 estimate->setEnabled(
false);
206 estimate->setEnabled(
true);
210 TaskGeneralPanelImpl::estimationTypeChanged(type);
213void TaskGeneralPanel::scheduleTypeChanged(
int value)
216 if (estimateType->currentItem() == 1){
217 setEstimateScales(24);
218 estimate->setEnabled(
false);
219 setEstimate(DateTime(endDateTime()) - DateTime(startDateTime()));
222 setEstimateScales(m_dayLength);
223 estimate->setEnabled(
true);
225 TaskGeneralPanelImpl::scheduleTypeChanged(value);
229TaskGeneralPanelImpl::TaskGeneralPanelImpl(TQWidget *p,
const char *n)
230 : TaskGeneralPanelBase(p, n) {
232 connect(idfield, TQ_SIGNAL(textChanged(
const TQString &)), TQ_SLOT(checkAllFieldsFilled()));
233 connect(namefield, TQ_SIGNAL(textChanged(
const TQString &)), TQ_SLOT(checkAllFieldsFilled()));
234 connect(leaderfield, TQ_SIGNAL(textChanged(
const TQString &)), TQ_SLOT(checkAllFieldsFilled()));
235 connect(chooseLeader, TQ_SIGNAL(clicked()), TQ_SLOT(changeLeader()));
236 connect(estimateType, TQ_SIGNAL(activated(
int)), TQ_SLOT(estimationTypeChanged(
int)));
237 connect(scheduleType, TQ_SIGNAL(activated(
int)), TQ_SLOT(scheduleTypeChanged(
int)));
238 connect(scheduleStartDate, TQ_SIGNAL(changed(TQDate)), TQ_SLOT(startDateChanged()));
239 connect(scheduleStartTime, TQ_SIGNAL(valueChanged(
const TQTime&)), TQ_SLOT(startTimeChanged(
const TQTime&)));
240 connect(scheduleEndDate, TQ_SIGNAL(changed(TQDate)), TQ_SLOT(endDateChanged()));
241 connect(scheduleEndTime, TQ_SIGNAL(valueChanged(
const TQTime&)), TQ_SLOT(endTimeChanged(
const TQTime&)));
242 connect(estimate, TQ_SIGNAL(valueChanged()), TQ_SLOT(checkAllFieldsFilled()));
243 connect(optimisticValue, TQ_SIGNAL(valueChanged(
int)), TQ_SLOT(checkAllFieldsFilled()));
244 connect(pessimisticValue, TQ_SIGNAL(valueChanged(
int)), TQ_SLOT(checkAllFieldsFilled()));
245 connect(descriptionfield, TQ_SIGNAL(textChanged()), TQ_SLOT(checkAllFieldsFilled()));
246 connect(risk, TQ_SIGNAL(activated(
int)), TQ_SLOT(checkAllFieldsFilled()));
249void TaskGeneralPanelImpl::setSchedulingType(
int type)
251 enableDateTime(type);
252 scheduleType->setCurrentItem(type);
253 emit schedulingTypeChanged(type);
256int TaskGeneralPanelImpl::schedulingType()
const
258 return scheduleType->currentItem();
261void TaskGeneralPanelImpl::changeLeader()
263 TDEABC::Addressee a = TDEABC::AddresseeDialog::getAddressee(
this);
266 leaderfield->setText(a.fullEmail());
270void TaskGeneralPanelImpl::setEstimationType(
int type )
272 estimateType->setCurrentItem(type);
275int TaskGeneralPanelImpl::estimationType()
const
277 return estimateType->currentItem();
280void TaskGeneralPanelImpl::setOptimistic(
int value )
282 optimisticValue->setValue(value);
285void TaskGeneralPanelImpl::setPessimistic(
int value )
287 pessimisticValue->setValue(value);
290int TaskGeneralPanelImpl::optimistic()
const
292 return optimisticValue->value();
295int TaskGeneralPanelImpl::pessimistic()
297 return pessimisticValue->value();
300void TaskGeneralPanelImpl::enableDateTime(
int scheduleType )
302 scheduleStartTime->setEnabled(
false);
303 scheduleEndTime->setEnabled(
false);
304 scheduleStartDate->setEnabled(
false);
305 scheduleEndDate->setEnabled(
false);
306 switch (scheduleType)
314 scheduleStartTime->setEnabled(
true);
315 scheduleEndTime->setEnabled(
false);
317 scheduleStartDate->setEnabled(
true);
318 scheduleEndDate->setEnabled(
false);
323 scheduleStartTime->setEnabled(
false);
324 scheduleEndTime->setEnabled(
true);
326 scheduleStartDate->setEnabled(
false);
327 scheduleEndDate->setEnabled(
true);
331 scheduleStartTime->setEnabled(
true);
332 scheduleEndTime->setEnabled(
true);
334 scheduleStartDate->setEnabled(
true);
335 scheduleEndDate->setEnabled(
true);
343void TaskGeneralPanelImpl::estimationTypeChanged(
int )
345 checkAllFieldsFilled();
350void TaskGeneralPanelImpl::setEstimate(
const Duration & duration)
352 estimate->setValue( duration );
356void TaskGeneralPanelImpl::setEstimateType(
int type)
358 estimateType->setCurrentItem(type);
362void TaskGeneralPanelImpl::checkAllFieldsFilled()
365 emit obligatedFieldsFilled(!namefield->text().isEmpty() && !idfield->text().isEmpty());
369Duration TaskGeneralPanelImpl::estimationValue()
371 return estimate->value();
375void TaskGeneralPanelImpl::setEstimateFields(
int mask )
377 estimate->setVisibleFields(mask);
381void TaskGeneralPanelImpl::setEstimateScales(
double day )
383 estimate->setFieldScale(0, day);
384 estimate->setFieldRightscale(0, day);
386 estimate->setFieldLeftscale(1, day);
390void TaskGeneralPanelImpl::setEstimateFieldUnit(
int field, TQString unit )
392 estimate->setFieldUnit(field, unit);
395void TaskGeneralPanelImpl::startDateChanged()
397 if (!scheduleStartDate->isEnabled()) {
400 TQDate date = startDate();
401 if (startDateTime() > endDateTime())
403 scheduleEndTime->blockSignals(
true);
404 scheduleEndDate->blockSignals(
true);
406 setEndTime(startTime());
407 scheduleEndTime->blockSignals(
false);
408 scheduleEndDate->blockSignals(
false);
410 if (scheduleType->currentItem() == 6 )
412 estimationTypeChanged(estimateType->currentItem());
414 checkAllFieldsFilled();
417void TaskGeneralPanelImpl::startTimeChanged(
const TQTime &time )
419 if (!scheduleStartTime->isEnabled()) {
422 if (startDateTime() > endDateTime())
424 scheduleEndTime->blockSignals(
true);
426 scheduleEndTime->blockSignals(
false);
428 if (scheduleType->currentItem() == 6 )
430 estimationTypeChanged(estimateType->currentItem());
432 checkAllFieldsFilled();
436void TaskGeneralPanelImpl::endDateChanged()
438 if (!scheduleEndDate->isEnabled()) {
441 TQDate date = endDate();
442 if (endDateTime() < startDateTime())
444 scheduleStartTime->blockSignals(
true);
445 scheduleStartDate->blockSignals(
true);
447 setStartTime(endTime());
448 scheduleStartTime->blockSignals(
false);
449 scheduleStartDate->blockSignals(
false);
452 if (scheduleType->currentItem() == 6 )
454 estimationTypeChanged(estimateType->currentItem());
456 checkAllFieldsFilled();
459void TaskGeneralPanelImpl::endTimeChanged(
const TQTime &time )
461 if (!scheduleEndTime->isEnabled()) {
464 if (endDateTime() < startDateTime())
466 scheduleStartTime->blockSignals(
true);
468 scheduleStartTime->blockSignals(
false);
471 if (scheduleType->currentItem() == 6 )
473 estimationTypeChanged(estimateType->currentItem());
475 checkAllFieldsFilled();
478void TaskGeneralPanelImpl::scheduleTypeChanged(
int value )
480 estimationTypeChanged(estimateType->currentItem());
481 enableDateTime(value);
482 checkAllFieldsFilled();
486TQDateTime TaskGeneralPanelImpl::startDateTime()
488 return TQDateTime(startDate(), startTime());
492TQDateTime TaskGeneralPanelImpl::endDateTime()
494 return TQDateTime(endDate(), endTime());
497void TaskGeneralPanelImpl::setStartTime(
const TQTime &time )
499 scheduleStartTime->setTime(time);
502void TaskGeneralPanelImpl::setEndTime(
const TQTime &time )
504 scheduleEndTime->setTime(time);
507TQTime TaskGeneralPanelImpl::startTime()
const
509 return scheduleStartTime->time();
512TQTime TaskGeneralPanelImpl::endTime()
514 return scheduleEndTime->time();
517TQDate TaskGeneralPanelImpl::startDate()
519 return scheduleStartDate->date();
523TQDate TaskGeneralPanelImpl::endDate()
525 return scheduleEndDate->date();
528void TaskGeneralPanelImpl::setStartDateTime(
const TQDateTime &dt )
530 setStartDate(dt.date());
531 setStartTime(dt.time());
535void TaskGeneralPanelImpl::setEndDateTime(
const TQDateTime &dt )
537 setEndDate(dt.date());
538 setEndTime(dt.time());
541void TaskGeneralPanelImpl::setStartDate(
const TQDate &date )
543 scheduleStartDate->setDate(date);
547void TaskGeneralPanelImpl::setEndDate(
const TQDate &date )
549 scheduleEndDate->setDate(date);
552void TaskGeneralPanelImpl::setRisktype(
int r )
554 risk->setCurrentItem(r);
557int TaskGeneralPanelImpl::risktype()
const
559 return risk->currentItem();
566#include "kpttaskgeneralpanel.moc"