kplato

kpttaskdefaultpanel.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Dag Andersen <danders@get2net.dk>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation;
7 version 2 of the License.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kpttaskdefaultpanel.h"
21#include "kpttask.h"
22#include "kptcommand.h"
23#include "kptduration.h"
24#include "kptdurationwidget.h"
25#include "kptcalendar.h"
26#include "kptdatetime.h"
27#include "kptconfig.h"
28#include "kptpart.h"
29
30#include <tdemessagebox.h>
31#include <klineedit.h>
32#include <ktextedit.h>
33#include <kcombobox.h>
34#include <kdatetimewidget.h>
35#include <tdelocale.h>
36#include <kcommand.h>
37#include <tdeabc/addressee.h>
38#include <tdeabc/addresseedialog.h>
39#include <kdatewidget.h>
40
41#include <tqlayout.h>
42#include <tqlabel.h>
43#include <tqdatetime.h>
44#include <tqdatetimeedit.h>
45#include <tqgroupbox.h>
46#include <tqpushbutton.h>
47#include <tqspinbox.h>
48
49#include <kdebug.h>
50
51namespace KPlato
52{
53
54TaskDefaultPanel::TaskDefaultPanel(Task &task, StandardWorktime *workTime, TQWidget *parent, const char *n)
55 : ConfigTaskPanelImpl(parent, n),
56 m_task(task),
57 m_dayLength(24)
58{
59 setStartValues(task, workTime);
60}
61
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());
66
67 setEstimateFields(DurationWidget::Days|DurationWidget::Hours|DurationWidget::Minutes);
68 if (workTime) {
69 //kdDebug()<<k_funcinfo<<"daylength="<<workTime->day()<<endl;
70 m_dayLength = workTime->day();
71 if (task.effort()->type() == Effort::Type_Effort) {
72 setEstimateScales(m_dayLength);
73 }
74 }
75 setEstimateFieldUnit(0, i18n("days", "d"));
76 setEstimateFieldUnit(1, i18n("hours", "h"));
77 setEstimateFieldUnit(2, i18n("minutes", "m"));
78 setEstimateType(task.effort()->type());
79
80 setSchedulingType(task.constraint());
81 if (task.constraintStartTime().isValid()) {
82 setStartDateTime(task.constraintStartTime());
83 } else {
84 TQDate date = TQDate::currentDate();
85 setStartDateTime(TQDateTime(date, TQTime()));
86 }
87 if (task.constraintEndTime().isValid()) {
88 setEndDateTime(task.constraintEndTime());
89 } else {
90 setEndDateTime(TQDateTime(startDate().addDays(1), TQTime()));
91 }
92 //kdDebug()<<k_funcinfo<<"Effort: "<<task.effort()->expected().toString()<<endl;
93 setEstimate(task.effort()->expected());
94 setOptimistic(task.effort()->optimisticRatio());
95 setPessimistic(task.effort()->pessimisticRatio());
96
97 leaderfield->setFocus();
98}
99
100KMacroCommand *TaskDefaultPanel::buildCommand(Part *part) {
101 KMacroCommand *cmd = new KMacroCommand(i18n("Modify Default Task"));
102 bool modified = false;
103
104 Duration dt = Duration();
105
106 if (m_task.leader() != leaderfield->text()) {
107 cmd->addCommand(new NodeModifyLeaderCmd(part, m_task, leaderfield->text()));
108 modified = true;
109 }
110 if (m_task.description() != descriptionfield->text()) {
111 cmd->addCommand(new NodeModifyDescriptionCmd(part, m_task, descriptionfield->text()));
112 modified = true;
113 }
114 Node::ConstraintType c = (Node::ConstraintType)schedulingType();
115 if (c != m_task.constraint()) {
116 cmd->addCommand(new NodeModifyConstraintCmd(part, m_task, c));
117 modified = true;
118 }
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()));
122 modified = true;
123 }
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()));
127 modified = true;
128 }
129 int et = estimationType();
130 if (et != m_task.effort()->type()) {
131 cmd->addCommand(new ModifyEffortTypeCmd(part, m_task, m_task.effort()->type(), et));
132 modified = true;
133 }
134 dt = estimationValue();
135 kdDebug()<<k_funcinfo<<"Estimate: "<<dt.toString()<<endl;
136 bool expchanged = dt != m_task.effort()->expected();
137 if ( expchanged ) {
138 cmd->addCommand(new ModifyEffortCmd(part, m_task, m_task.effort()->expected(), dt));
139 modified = true;
140 }
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));
144 modified = true;
145 }
146 x = pessimistic();
147 if ( x != m_task.effort()->pessimisticRatio() || expchanged) {
148 cmd->addCommand(new EffortModifyPessimisticRatioCmd(part, m_task, m_task.effort()->pessimisticRatio(), x));
149 modified = true;
150 }
151 if (!modified) {
152 delete cmd;
153 return 0;
154 }
155 return cmd;
156}
157
158bool TaskDefaultPanel::ok() {
159 return true;
160}
161
162void TaskDefaultPanel::estimationTypeChanged(int type) {
163 if (type == 0 /*Effort*/) {
164 Duration d = estimationValue();
165 setEstimateScales(m_dayLength);
166 //setEstimate(d);
167 } else {
168 Duration d = estimationValue();
169 setEstimateScales(24);
170 //setEstimate(d);
171 }
172 ConfigTaskPanelImpl::estimationTypeChanged(type);
173}
174
175void TaskDefaultPanel::scheduleTypeChanged(int value)
176{
177 if (value == 6 /*Fixed interval*/) {
178 if (estimateType->currentItem() == 1/*duration*/){
179 setEstimateScales(24);
180 //estimate->setEnabled(false);
181 //setEstimate(DateTime(endDateTime()) - DateTime(startDateTime()));
182 }
183 } else {
184 setEstimateScales(m_dayLength);
185 estimate->setEnabled(true);
186 }
187 ConfigTaskPanelImpl::scheduleTypeChanged(value);
188}
189
190
191//-----------------------------
192ConfigTaskPanelImpl::ConfigTaskPanelImpl(TQWidget *p, const char *n)
193 : ConfigTaskPanelBase(p, n) {
194
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()));
207}
208
209void ConfigTaskPanelImpl::setSchedulingType(int type)
210{
211 enableDateTime(type);
212 scheduleType->setCurrentItem(type);
213 emit schedulingTypeChanged(type);
214}
215
216int ConfigTaskPanelImpl::schedulingType() const
217{
218 return scheduleType->currentItem();
219}
220
221void ConfigTaskPanelImpl::changeLeader()
222{
223 TDEABC::Addressee a = TDEABC::AddresseeDialog::getAddressee(this);
224 if (!a.isEmpty())
225 {
226 leaderfield->setText(a.fullEmail());
227 }
228}
229
230void ConfigTaskPanelImpl::setEstimationType( int type )
231{
232 estimateType->setCurrentItem(type);
233}
234
235int ConfigTaskPanelImpl::estimationType() const
236{
237 return estimateType->currentItem();
238}
239
240void ConfigTaskPanelImpl::setOptimistic( int value )
241{
242 optimisticValue->setValue(value);
243}
244
245void ConfigTaskPanelImpl::setPessimistic( int value )
246{
247 pessimisticValue->setValue(value);
248}
249
250int ConfigTaskPanelImpl::optimistic() const
251{
252 return optimisticValue->value();
253}
254
255int ConfigTaskPanelImpl::pessimistic()
256{
257 return pessimisticValue->value();
258}
259
260void ConfigTaskPanelImpl::enableDateTime( int /*scheduleType*/ )
261{
262 scheduleStartTime->setEnabled(true);
263 scheduleEndTime->setEnabled(true);
264 scheduleStartDate->setEnabled(true);
265 scheduleEndDate->setEnabled(true);
266/* switch (scheduleType)
267 {
268 case 0: //ASAP
269 case 1: //ALAP
270 break;
271 case 2: //Must start on
272 case 4: // Start not earlier
273 if (useTime) {
274 scheduleStartTime->setEnabled(true);
275 scheduleEndTime->setEnabled(false);
276 }
277 scheduleStartDate->setEnabled(true);
278 scheduleEndDate->setEnabled(false);
279 break;
280 case 3: //Must finish on
281 case 5: // Finish not later
282 if (useTime) {
283 scheduleStartTime->setEnabled(false);
284 scheduleEndTime->setEnabled(true);
285 }
286 scheduleStartDate->setEnabled(false);
287 scheduleEndDate->setEnabled(true);
288 break;
289 case 6: //Fixed interval
290 if (useTime) {
291 scheduleStartTime->setEnabled(true);
292 scheduleEndTime->setEnabled(true);
293 }
294 scheduleStartDate->setEnabled(true);
295 scheduleEndDate->setEnabled(true);
296 break;
297 default:
298 break;
299 }*/
300}
301
302
303void ConfigTaskPanelImpl::estimationTypeChanged( int /*type*/ )
304{
305 checkAllFieldsFilled();
306}
307
308
309
310void ConfigTaskPanelImpl::setEstimate( const Duration & duration)
311{
312 estimate->setValue( duration );
313}
314
315
316void ConfigTaskPanelImpl::setEstimateType( int type)
317{
318 estimateType->setCurrentItem(type);
319}
320
321
322void ConfigTaskPanelImpl::checkAllFieldsFilled()
323{
324 emit changed();
325 emit obligatedFieldsFilled(true);
326}
327
328
329Duration ConfigTaskPanelImpl::estimationValue()
330{
331 return estimate->value();
332}
333
334
335void ConfigTaskPanelImpl::setEstimateFields( int mask )
336{
337 estimate->setVisibleFields(mask);
338}
339
340
341void ConfigTaskPanelImpl::setEstimateScales( double day )
342{
343 estimate->setFieldScale(0, day);
344 estimate->setFieldRightscale(0, day);
345
346 estimate->setFieldLeftscale(1, day);
347}
348
349
350void ConfigTaskPanelImpl::setEstimateFieldUnit( int field, TQString unit )
351{
352 estimate->setFieldUnit(field, unit);
353}
354
355void ConfigTaskPanelImpl::startDateChanged()
356{
357 if (!scheduleStartDate->isEnabled()) {
358 return;
359 }
360 TQDate date = startDate();
361 if (startDateTime() > endDateTime())
362 {
363 scheduleEndTime->blockSignals(true);
364 scheduleEndDate->blockSignals(true);
365 setEndDate(date);
366 setEndTime(startTime());
367 scheduleEndTime->blockSignals(false);
368 scheduleEndDate->blockSignals(false);
369 }
370 if (scheduleType->currentItem() == 6 /*FixedInterval*/)
371 {
372 estimationTypeChanged(estimateType->currentItem());
373 }
374 checkAllFieldsFilled();
375}
376
377void ConfigTaskPanelImpl::startTimeChanged( const TQTime &time )
378{
379 if (!scheduleStartTime->isEnabled()) {
380 return;
381 }
382 if (startDateTime() > endDateTime())
383 {
384 scheduleEndTime->blockSignals(true);
385 setEndTime(time);
386 scheduleEndTime->blockSignals(false);
387 }
388 if (scheduleType->currentItem() == 6 /*FixedInterval*/)
389 {
390 estimationTypeChanged(estimateType->currentItem());
391 }
392 checkAllFieldsFilled();
393}
394
395
396void ConfigTaskPanelImpl::endDateChanged()
397{
398 if (!scheduleEndDate->isEnabled()) {
399 return;
400 }
401 TQDate date = endDate();
402 if (endDateTime() < startDateTime())
403 {
404 scheduleStartTime->blockSignals(true);
405 scheduleStartDate->blockSignals(true);
406 setStartDate(date);
407 setStartTime(endTime());
408 scheduleStartTime->blockSignals(false);
409 scheduleStartDate->blockSignals(false);
410 }
411
412 if (scheduleType->currentItem() == 6 /*FixedInterval*/)
413 {
414 estimationTypeChanged(estimateType->currentItem());
415 }
416 checkAllFieldsFilled();
417}
418
419void ConfigTaskPanelImpl::endTimeChanged( const TQTime &time )
420{
421 if (!scheduleEndTime->isEnabled()) {
422 return;
423 }
424 if (endDateTime() < startDateTime())
425 {
426 scheduleStartTime->blockSignals(true);
427 setStartTime(time);
428 scheduleStartTime->blockSignals(false);
429 }
430
431 if (scheduleType->currentItem() == 6 /*FixedInterval*/)
432 {
433 estimationTypeChanged(estimateType->currentItem());
434 }
435 checkAllFieldsFilled();
436}
437
438void ConfigTaskPanelImpl::scheduleTypeChanged( int value )
439{
440 estimationTypeChanged(estimateType->currentItem());
441 enableDateTime(value);
442 checkAllFieldsFilled();
443}
444
445
446TQDateTime ConfigTaskPanelImpl::startDateTime()
447{
448 return TQDateTime(startDate(), startTime());
449}
450
451
452TQDateTime ConfigTaskPanelImpl::endDateTime()
453{
454 return TQDateTime(endDate(), endTime());
455}
456
457void ConfigTaskPanelImpl::setStartTime( const TQTime &time )
458{
459 scheduleStartTime->setTime(time);
460}
461
462void ConfigTaskPanelImpl::setEndTime( const TQTime &time )
463{
464 scheduleEndTime->setTime(time);
465}
466
467TQTime ConfigTaskPanelImpl::startTime() const
468{
469 return scheduleStartTime->time();
470}
471
472TQTime ConfigTaskPanelImpl::endTime()
473{
474 return scheduleEndTime->time();
475}
476
477TQDate ConfigTaskPanelImpl::startDate()
478{
479 return scheduleStartDate->date();
480}
481
482
483TQDate ConfigTaskPanelImpl::endDate()
484{
485 return scheduleEndDate->date();
486}
487
488void ConfigTaskPanelImpl::setStartDateTime( const TQDateTime &dt )
489{
490 setStartDate(dt.date());
491 setStartTime(dt.time());
492}
493
494
495void ConfigTaskPanelImpl::setEndDateTime( const TQDateTime &dt )
496{
497 setEndDate(dt.date());
498 setEndTime(dt.time());
499}
500
501void ConfigTaskPanelImpl::setStartDate( const TQDate &date )
502{
503 scheduleStartDate->setDate(date);
504}
505
506
507void ConfigTaskPanelImpl::setEndDate( const TQDate &date )
508{
509 scheduleEndDate->setDate(date);
510}
511
512
513} //KPlato namespace
514
515#include "kpttaskdefaultpanel.moc"
A task in the scheduling software is represented by this class.
Definition kpttask.h:40