kplato

kpttaskprogresspanel.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 - 2005 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 "kpttaskprogresspanel.h"
21
22#include <tqbuttongroup.h>
23#include <tqradiobutton.h>
24#include <tqcheckbox.h>
25
26#include <klineedit.h>
27#include <ktextedit.h>
28#include <kdatetimewidget.h>
29#include <knuminput.h>
30#include <tdelocale.h>
31#include <tdemessagebox.h>
32#include <kcommand.h>
33
34#include <kdebug.h>
35
36#include "kpttask.h"
37#include "kptcommand.h"
38#include "kptdurationwidget.h"
39#include "kptcalendar.h"
40
41namespace KPlato
42{
43
44TaskProgressPanel::TaskProgressPanel(Task &task, StandardWorktime *workTime, TQWidget *parent, const char *name)
45 : TaskProgressPanelImpl(parent, name),
46 m_task(task),
47 m_dayLength(24)
48{
49 kdDebug()<<k_funcinfo<<endl;
50 m_progress = task.progress();
51 started->setChecked(m_progress.started);
52 finished->setChecked(m_progress.finished);
53 startTime->setDateTime(m_progress.startTime);
54 finishTime->setDateTime(m_progress.finishTime);
55
56 percentFinished->setValue(m_progress.percentFinished);
57
58 if (workTime) {
59 kdDebug()<<k_funcinfo<<"daylength="<<workTime->durationDay().hours()<<endl;
60 m_dayLength = workTime->durationDay().hours();
61 setEstimateScales(m_dayLength);
62 }
63 remainingEffort->setValue(m_progress.remainingEffort);
64 remainingEffort->setVisibleFields(DurationWidget::Days | DurationWidget::Hours | DurationWidget::Minutes);
65 remainingEffort->setFieldUnit(0, i18n("day", "d"));
66 remainingEffort->setFieldUnit(1, i18n("hour", "h"));
67 remainingEffort->setFieldUnit(2, i18n("minute", "m"));
68
69 m_progress.totalPerformed = task.actualEffort(); //FIXME
70 actualEffort->setValue(m_progress.totalPerformed);
71 actualEffort->setVisibleFields(DurationWidget::Days | DurationWidget::Hours | DurationWidget::Minutes);
72 actualEffort->setFieldUnit(0, i18n("day", "d"));
73 actualEffort->setFieldUnit(1, i18n("hour", "h"));
74 actualEffort->setFieldUnit(2, i18n("minute", "m"));
75
76 scheduledStart->setDateTime(task.startTime());
77 scheduledFinish->setDateTime(task.endTime());
78 scheduledEffort->setValue(task.effort()->expected());
79 scheduledEffort->setVisibleFields(DurationWidget::Days | DurationWidget::Hours | DurationWidget::Minutes);
80 scheduledEffort->setFieldUnit(0, i18n("day", "d"));
81 scheduledEffort->setFieldUnit(1, i18n("hour", "h"));
82 scheduledEffort->setFieldUnit(2, i18n("minute", "m"));
83
84 enableWidgets();
85 started->setFocus();
86
87}
88
89
90bool TaskProgressPanel::ok() {
91 m_progress.started = started->isChecked();
92 m_progress.finished = finished->isChecked();
93 m_progress.startTime = startTime->dateTime();
94 m_progress.finishTime = finishTime->dateTime();
95 m_progress.percentFinished = percentFinished->value();
96 m_progress.remainingEffort = remainingEffort->value();
97 m_progress.totalPerformed = actualEffort->value();
98 return true;
99}
100
101KCommand *TaskProgressPanel::buildCommand(Part *part) {
102 KCommand *cmd = 0;
103 TQString c = i18n("Modify progress");
104 if (m_task.progress() != m_progress) {
105 cmd = new TaskModifyProgressCmd(part, m_task, m_progress, c);
106 }
107 return cmd;
108}
109
110void TaskProgressPanel::setEstimateScales( int day )
111{
112 remainingEffort->setFieldScale(0, day);
113 remainingEffort->setFieldRightscale(0, day);
114 remainingEffort->setFieldLeftscale(1, day);
115
116 actualEffort->setFieldScale(0, day);
117 actualEffort->setFieldRightscale(0, day);
118 actualEffort->setFieldLeftscale(1, day);
119
120 scheduledEffort->setFieldScale(0, day);
121 scheduledEffort->setFieldRightscale(0, day);
122 scheduledEffort->setFieldLeftscale(1, day);
123}
124
125//-------------------------------------
126
127TaskProgressPanelImpl::TaskProgressPanelImpl(TQWidget *parent, const char *name, WFlags f)
128 : TaskProgressPanelBase(parent, name, f) {
129
130 connect(started, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotStartedChanged(bool)));
131 connect(finished, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotFinishedChanged(bool)));
132
133 connect(percentFinished, TQ_SIGNAL(valueChanged(int)), TQ_SLOT(slotPercentFinishedChanged(int)));
134 connect(percentFinished, TQ_SIGNAL(valueChanged(int)), TQ_SLOT(slotChanged()));
135
136 connect(startTime, TQ_SIGNAL(valueChanged(const TQDateTime &)), TQ_SLOT(slotChanged()));
137 connect(finishTime, TQ_SIGNAL(valueChanged(const TQDateTime &)), TQ_SLOT(slotChanged()));
138
139 connect(remainingEffort, TQ_SIGNAL(valueChanged()), TQ_SLOT(slotChanged()));
140 connect(actualEffort, TQ_SIGNAL(valueChanged()), TQ_SLOT(slotChanged()));
141
142}
143
144void TaskProgressPanelImpl::slotChanged() {
145 emit changed();
146}
147
148void TaskProgressPanelImpl::slotStartedChanged(bool state) {
149 if (state) {
150 startTime->setDateTime(TQDateTime::currentDateTime());
151 percentFinished->setValue(0);
152 }
153 enableWidgets();
154}
155
156
157void TaskProgressPanelImpl::slotFinishedChanged(bool state) {
158 if (state) {
159 percentFinished->setValue(100);
160 if (!finishTime->dateTime().isValid()) {
161 finishTime->setDateTime(TQDateTime::currentDateTime());
162 }
163 }
164 enableWidgets();
165}
166
167
168void TaskProgressPanelImpl::enableWidgets() {
169 started->setEnabled(!finished->isChecked());
170 finished->setEnabled(started->isChecked());
171 finishTime->setEnabled(started->isChecked());
172 startTime->setEnabled(started->isChecked() && !finished->isChecked());
173 performedGroup->setEnabled(started->isChecked() && !finished->isChecked());
174
175 scheduledStart->setEnabled(false);
176 scheduledFinish->setEnabled(false);
177 scheduledEffort->setEnabled(false);
178}
179
180
181void TaskProgressPanelImpl::slotPercentFinishedChanged( int value ) {
182 if (value == 100) {
183 //remainingEffort->setValue(Duration::zeroDuration); //FIXME
184 }
185}
186
187
188} //KPlato namespace
189
190#include "kpttaskprogresspanel.moc"