~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kplato/kpttaskprogresspanel.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-04-20 21:38:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060420213853-j5lxluqvymxt2zny
Tags: 1:1.5.0-0ubuntu2
UbuntuĀ uploadĀ 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <qbuttongroup.h>
 
23
#include <qradiobutton.h>
 
24
#include <qcheckbox.h>
 
25
 
 
26
#include <klineedit.h>
 
27
#include <ktextedit.h>
 
28
#include <kdatetimewidget.h>
 
29
#include <knuminput.h>
 
30
#include <klocale.h>
 
31
#include <kmessagebox.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
 
 
41
namespace KPlato
 
42
{
 
43
 
 
44
TaskProgressPanel::TaskProgressPanel(Task &task, StandardWorktime *workTime, QWidget *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
 
 
90
bool 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
 
 
101
KCommand *TaskProgressPanel::buildCommand(Part *part) {
 
102
    KCommand *cmd = 0;
 
103
    QString 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
 
 
110
void 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
 
 
127
TaskProgressPanelImpl::TaskProgressPanelImpl(QWidget *parent, const char *name, WFlags f)
 
128
    : TaskProgressPanelBase(parent, name, f) {
 
129
    
 
130
    connect(started, SIGNAL(toggled(bool)), SLOT(slotStartedChanged(bool)));
 
131
    connect(finished, SIGNAL(toggled(bool)), SLOT(slotFinishedChanged(bool)));
 
132
 
 
133
    connect(percentFinished, SIGNAL(valueChanged(int)), SLOT(slotPercentFinishedChanged(int)));
 
134
    connect(percentFinished, SIGNAL(valueChanged(int)), SLOT(slotChanged()));
 
135
    
 
136
    connect(startTime, SIGNAL(valueChanged(const QDateTime &)), SLOT(slotChanged()));
 
137
    connect(finishTime, SIGNAL(valueChanged(const QDateTime &)), SLOT(slotChanged()));
 
138
    
 
139
    connect(remainingEffort, SIGNAL(valueChanged()), SLOT(slotChanged()));
 
140
    connect(actualEffort, SIGNAL(valueChanged()), SLOT(slotChanged()));
 
141
 
 
142
}
 
143
 
 
144
void TaskProgressPanelImpl::slotChanged() {
 
145
    emit changed();
 
146
}
 
147
 
 
148
void TaskProgressPanelImpl::slotStartedChanged(bool state) {
 
149
    if (state) {
 
150
        startTime->setDateTime(QDateTime::currentDateTime());
 
151
        percentFinished->setValue(0);
 
152
    }
 
153
    enableWidgets();
 
154
}
 
155
 
 
156
 
 
157
void TaskProgressPanelImpl::slotFinishedChanged(bool state) {
 
158
    if (state) {
 
159
        percentFinished->setValue(100);
 
160
        if (!finishTime->dateTime().isValid()) {
 
161
            finishTime->setDateTime(QDateTime::currentDateTime());
 
162
        }
 
163
    }   
 
164
    enableWidgets();
 
165
}
 
166
 
 
167
 
 
168
void 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
 
 
181
void 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"