kplato

kpttaskprogresspanel.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 - 2005 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 "kpttaskprogresspanel.h"
00021 
00022 #include <qbuttongroup.h>
00023 #include <qradiobutton.h>
00024 #include <qcheckbox.h>
00025 
00026 #include <klineedit.h>
00027 #include <ktextedit.h>
00028 #include <kdatetimewidget.h>
00029 #include <knuminput.h>
00030 #include <klocale.h>
00031 #include <kmessagebox.h>
00032 #include <kcommand.h>
00033 
00034 #include <kdebug.h>
00035 
00036 #include "kpttask.h"
00037 #include "kptcommand.h"
00038 #include "kptdurationwidget.h"
00039 #include "kptcalendar.h"
00040 
00041 namespace KPlato
00042 {
00043 
00044 TaskProgressPanel::TaskProgressPanel(Task &task, StandardWorktime *workTime, QWidget *parent, const char *name)
00045     : TaskProgressPanelImpl(parent, name),
00046       m_task(task),
00047       m_dayLength(24)
00048 {
00049     kdDebug()<<k_funcinfo<<endl;
00050     m_progress = task.progress();
00051     started->setChecked(m_progress.started);
00052     finished->setChecked(m_progress.finished);
00053     startTime->setDateTime(m_progress.startTime);
00054     finishTime->setDateTime(m_progress.finishTime);
00055     
00056     percentFinished->setValue(m_progress.percentFinished);
00057     
00058     if (workTime) {
00059         kdDebug()<<k_funcinfo<<"daylength="<<workTime->durationDay().hours()<<endl;
00060         m_dayLength = workTime->durationDay().hours();
00061         setEstimateScales(m_dayLength);
00062     }
00063     remainingEffort->setValue(m_progress.remainingEffort);
00064     remainingEffort->setVisibleFields(DurationWidget::Days | DurationWidget::Hours | DurationWidget::Minutes);
00065     remainingEffort->setFieldUnit(0, i18n("day", "d"));
00066     remainingEffort->setFieldUnit(1, i18n("hour", "h"));
00067     remainingEffort->setFieldUnit(2, i18n("minute", "m"));
00068 
00069     m_progress.totalPerformed = task.actualEffort(); //FIXME
00070     actualEffort->setValue(m_progress.totalPerformed);
00071     actualEffort->setVisibleFields(DurationWidget::Days | DurationWidget::Hours | DurationWidget::Minutes);
00072     actualEffort->setFieldUnit(0, i18n("day", "d"));
00073     actualEffort->setFieldUnit(1, i18n("hour", "h"));
00074     actualEffort->setFieldUnit(2, i18n("minute", "m"));
00075     
00076     scheduledStart->setDateTime(task.startTime());
00077     scheduledFinish->setDateTime(task.endTime());
00078     scheduledEffort->setValue(task.effort()->expected());
00079     scheduledEffort->setVisibleFields(DurationWidget::Days | DurationWidget::Hours | DurationWidget::Minutes);
00080     scheduledEffort->setFieldUnit(0, i18n("day", "d"));
00081     scheduledEffort->setFieldUnit(1, i18n("hour", "h"));
00082     scheduledEffort->setFieldUnit(2, i18n("minute", "m"));
00083     
00084     enableWidgets();
00085     started->setFocus();
00086     
00087 }
00088 
00089 
00090 bool TaskProgressPanel::ok() {
00091     m_progress.started = started->isChecked();
00092     m_progress.finished = finished->isChecked();
00093     m_progress.startTime = startTime->dateTime();
00094     m_progress.finishTime = finishTime->dateTime();
00095     m_progress.percentFinished = percentFinished->value();
00096     m_progress.remainingEffort = remainingEffort->value();
00097     m_progress.totalPerformed = actualEffort->value();
00098     return true;
00099 }
00100 
00101 KCommand *TaskProgressPanel::buildCommand(Part *part) {
00102     KCommand *cmd = 0;
00103     QString c = i18n("Modify progress");
00104     if (m_task.progress() != m_progress) {
00105         cmd = new TaskModifyProgressCmd(part, m_task, m_progress, c);
00106     }
00107     return cmd;
00108 }
00109 
00110 void TaskProgressPanel::setEstimateScales( int day )
00111 {
00112     remainingEffort->setFieldScale(0, day);
00113     remainingEffort->setFieldRightscale(0, day);
00114     remainingEffort->setFieldLeftscale(1, day);
00115 
00116     actualEffort->setFieldScale(0, day);
00117     actualEffort->setFieldRightscale(0, day);
00118     actualEffort->setFieldLeftscale(1, day);
00119 
00120     scheduledEffort->setFieldScale(0, day);
00121     scheduledEffort->setFieldRightscale(0, day);
00122     scheduledEffort->setFieldLeftscale(1, day);
00123 }
00124 
00125 //-------------------------------------
00126 
00127 TaskProgressPanelImpl::TaskProgressPanelImpl(QWidget *parent, const char *name, WFlags f)
00128     : TaskProgressPanelBase(parent, name, f) {
00129     
00130     connect(started, SIGNAL(toggled(bool)), SLOT(slotStartedChanged(bool)));
00131     connect(finished, SIGNAL(toggled(bool)), SLOT(slotFinishedChanged(bool)));
00132 
00133     connect(percentFinished, SIGNAL(valueChanged(int)), SLOT(slotPercentFinishedChanged(int)));
00134     connect(percentFinished, SIGNAL(valueChanged(int)), SLOT(slotChanged()));
00135     
00136     connect(startTime, SIGNAL(valueChanged(const QDateTime &)), SLOT(slotChanged()));
00137     connect(finishTime, SIGNAL(valueChanged(const QDateTime &)), SLOT(slotChanged()));
00138     
00139     connect(remainingEffort, SIGNAL(valueChanged()), SLOT(slotChanged()));
00140     connect(actualEffort, SIGNAL(valueChanged()), SLOT(slotChanged()));
00141 
00142 }
00143 
00144 void TaskProgressPanelImpl::slotChanged() {
00145     emit changed();
00146 }
00147 
00148 void TaskProgressPanelImpl::slotStartedChanged(bool state) {
00149     if (state) {
00150         startTime->setDateTime(QDateTime::currentDateTime());
00151         percentFinished->setValue(0);
00152     }
00153     enableWidgets();
00154 }
00155 
00156 
00157 void TaskProgressPanelImpl::slotFinishedChanged(bool state) {
00158     if (state) {
00159         percentFinished->setValue(100);
00160         if (!finishTime->dateTime().isValid()) {
00161             finishTime->setDateTime(QDateTime::currentDateTime());
00162         }
00163     }   
00164     enableWidgets();
00165 }
00166 
00167 
00168 void TaskProgressPanelImpl::enableWidgets() {
00169     started->setEnabled(!finished->isChecked());
00170     finished->setEnabled(started->isChecked());
00171     finishTime->setEnabled(started->isChecked());
00172     startTime->setEnabled(started->isChecked() && !finished->isChecked());
00173     performedGroup->setEnabled(started->isChecked() && !finished->isChecked());
00174     
00175     scheduledStart->setEnabled(false);
00176     scheduledFinish->setEnabled(false);
00177     scheduledEffort->setEnabled(false);
00178 }
00179 
00180 
00181 void TaskProgressPanelImpl::slotPercentFinishedChanged( int value ) {
00182     if (value == 100) {
00183         //remainingEffort->setValue(Duration::zeroDuration); //FIXME
00184     }
00185 }
00186 
00187 
00188 }  //KPlato namespace
00189 
00190 #include "kpttaskprogresspanel.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys