kplato

kptmainprojectpanel.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 "kptmainprojectpanel.h"
21
22#include <tqcheckbox.h>
23#include <tqbuttongroup.h>
24#include <tqdatetime.h>
25#include <tqdatetimeedit.h>
26#include <tqradiobutton.h>
27#include <tqpushbutton.h>
28
29#include <tqlabel.h>
30#include <klineedit.h>
31#include <ktextedit.h>
32#include <kdatewidget.h>
33#include <tdelocale.h>
34#include <tdemessagebox.h>
35#include <kcommand.h>
36#include <tdeabc/addressee.h>
37#include <tdeabc/addresseedialog.h>
38
39#include <kdebug.h>
40
41#include "kptproject.h"
42#include "kptcommand.h"
43#include "kptschedule.h"
44
45namespace KPlato
46{
47
48MainProjectPanel::MainProjectPanel(Project &p, TQWidget *parent, const char *name)
49 : MainProjectPanelImpl(parent, name),
50 project(p)
51{
52 namefield->setText(project.name());
53 idfield->setText(project.id());
54 leaderfield->setText(project.leader());
55 descriptionfield->setText(project.description());
56 wbs->setText(project.wbs());
57
58 //baseline->setChecked(project.isBaselined()); FIXME: Removed for this release
59
60 TQDateTime st = project.constraintStartTime();
61 TQDateTime et = project.constraintEndTime();
62 TQString s = i18n("Scheduling");
63 Schedule *sch = project.currentSchedule();
64 if (sch) {
65 s = i18n("Scheduling (%1)").arg(sch->typeToString(true));
66 }
67 schedulingGroup->setTitle(s);
68 if (project.constraint() == Node::MustStartOn) {
69 schedulingGroup->setButton(0);
70 if (sch)
71 et = project.endTime();
72 } else if (project.constraint() == Node::MustFinishOn) {
73 schedulingGroup->setButton(1);
74 if (sch)
75 st = project.startTime();
76 } else {
77 kdWarning()<<k_funcinfo<<"Illegal constraint: "<<project.constraint()<<endl;
78 schedulingGroup->setButton(0);
79 if (sch)
80 et = project.endTime();
81 }
82 startDate->setDate(st.date());
83 startTime->setTime(st.time());
84 endDate->setDate(et.date());
85 endTime->setTime(et.time());
86 enableDateTime();
87 //slotBaseline();
88 namefield->setFocus();
89}
90
91
92bool MainProjectPanel::ok() {
93 if (idfield->text() != project.id() && project.findNode(idfield->text())) {
94 KMessageBox::sorry(this, i18n("Project id must be unique"));
95 idfield->setFocus();
96 return false;
97 }
98 return true;
99}
100
101KCommand *MainProjectPanel::buildCommand(Part *part) {
102 KMacroCommand *m = 0;
103 TQString c = i18n("Modify main project");
104 if (project.name() != namefield->text()) {
105 if (!m) m = new KMacroCommand(c);
106 m->addCommand(new NodeModifyNameCmd(part, project, namefield->text()));
107 }
108 if (project.id() != idfield->text()) {
109 if (!m) m = new KMacroCommand(c);
110 m->addCommand(new NodeModifyIdCmd(part, project, idfield->text()));
111 }
112 if (project.leader() != leaderfield->text()) {
113 if (!m) m = new KMacroCommand(c);
114 m->addCommand(new NodeModifyLeaderCmd(part, project, leaderfield->text()));
115 }
116 if (project.description() != descriptionfield->text()) {
117 if (!m) m = new KMacroCommand(c);
118 m->addCommand(new NodeModifyDescriptionCmd(part, project, descriptionfield->text()));
119 }
120/* FIXME: Removed for this release
121 if (baseline->isChecked() != project.isBaselined()) {
122 if (!m) m = new KMacroCommand(c);
123 m->addCommand(new ProjectModifyBaselineCmd(part, project, baseline->isChecked()));
124 } */
125 if (bStartDate->state() && project.constraint() != Node::MustStartOn) {
126 if (!m) m = new KMacroCommand(c);
127 m->addCommand(new ProjectModifyConstraintCmd(part, project, Node::MustStartOn));
128 }
129 if (bEndDate->state() && project.constraint() != Node::MustFinishOn) {
130 if (!m) m = new KMacroCommand(c);
131 m->addCommand(new ProjectModifyConstraintCmd(part, project, Node::MustFinishOn));
132 }
133 if (bStartDate->state() && startDateTime() != project.constraintStartTime()) {
134 if (!m) m = new KMacroCommand(c);
135 m->addCommand(new ProjectModifyStartTimeCmd(part, project, startDateTime()));
136 }
137 if (bEndDate->state() && endDateTime() != project.constraintEndTime()) {
138 if (!m) m = new KMacroCommand(c);
139 m->addCommand(new ProjectModifyEndTimeCmd(part, project, endDateTime()));
140 }
141 return m;
142}
143
144//-------------------------------------------------------------------
145MainProjectPanelImpl::MainProjectPanelImpl(TQWidget *parent, const char *name)
146 : MainProjectPanelBase(parent, name) {
147
148 // signals and slots connections
149 connect( bStartDate, TQ_SIGNAL( clicked() ), this, TQ_SLOT( slotStartDateClicked() ) );
150 connect( bEndDate, TQ_SIGNAL( clicked() ), this, TQ_SLOT( slotEndDateClicked() ) );
151 connect( bStartDate, TQ_SIGNAL( clicked() ), this, TQ_SLOT( slotCheckAllFieldsFilled() ) );
152 connect( bEndDate, TQ_SIGNAL( clicked() ), this, TQ_SLOT( slotCheckAllFieldsFilled() ) );
153 connect( descriptionfield, TQ_SIGNAL( textChanged() ), this, TQ_SLOT( slotCheckAllFieldsFilled() ) );
154 connect( endDate, TQ_SIGNAL( changed(TQDate) ), this, TQ_SLOT( slotCheckAllFieldsFilled() ) );
155 connect( endTime, TQ_SIGNAL( valueChanged(const TQTime&) ), this, TQ_SLOT( slotCheckAllFieldsFilled() ) );
156 connect( startDate, TQ_SIGNAL( changed(TQDate) ), this, TQ_SLOT( slotCheckAllFieldsFilled() ) );
157 connect( startTime, TQ_SIGNAL( valueChanged(const TQTime&) ), this, TQ_SLOT( slotCheckAllFieldsFilled() ) );
158 //connect( baseline, TQ_SIGNAL( toggled(bool) ), this, TQ_SLOT( slotCheckAllFieldsFilled() ) ); FIXME: Removed for this release
159 connect( namefield, TQ_SIGNAL( textChanged(const TQString&) ), this, TQ_SLOT( slotCheckAllFieldsFilled() ) );
160 connect( idfield, TQ_SIGNAL( textChanged(const TQString&) ), this, TQ_SLOT( slotCheckAllFieldsFilled() ) );
161 connect( leaderfield, TQ_SIGNAL( textChanged(const TQString&) ), this, TQ_SLOT( slotCheckAllFieldsFilled() ) );
162 //connect( baseline, TQ_SIGNAL( toggled(bool) ), this, TQ_SLOT( slotBaseline() ) ); FIXME: Removed for this release
163 connect( chooseLeader, TQ_SIGNAL( clicked() ), this, TQ_SLOT( slotChooseLeader() ) );
164}
165
166void MainProjectPanelImpl::slotCheckAllFieldsFilled()
167{
168 emit changed();
169 emit obligatedFieldsFilled(!namefield->text().isEmpty() && !idfield->text().isEmpty() && !leaderfield->text().isEmpty());
170}
171
172
173void MainProjectPanelImpl::slotChooseLeader()
174{
175 TDEABC::Addressee a = TDEABC::AddresseeDialog::getAddressee(this);
176 if (!a.isEmpty())
177 {
178 leaderfield->setText(a.fullEmail());
179 }
180}
181
182
183void MainProjectPanelImpl::slotStartDateClicked()
184{
185 enableDateTime();
186}
187
188
189void MainProjectPanelImpl::slotEndDateClicked()
190{
191 enableDateTime();
192}
193
194
195
196void MainProjectPanelImpl::enableDateTime()
197{
198 if (schedulingGroup->selected() == bStartDate)
199 {
200 startTime->setEnabled(true);
201 startDate->setEnabled(true);
202 endTime->setEnabled(false);
203 endDate->setEnabled(false);
204 }
205 if (schedulingGroup->selected() == bEndDate)
206 {
207 startTime->setEnabled(false);
208 startDate->setEnabled(false);
209 endTime->setEnabled(true);
210 endDate->setEnabled(true);
211 }
212}
213
214
215TQDateTime MainProjectPanelImpl::startDateTime()
216{
217 return TQDateTime(startDate->date(), startTime->time());
218}
219
220
221TQDateTime MainProjectPanelImpl::endDateTime()
222{
223 return TQDateTime(endDate->date(), endTime->time());
224}
225
226
227void MainProjectPanelImpl::slotBaseline()
228{
229 bool b = false;
230 //b = baseline->isChecked(); FIXME: Removed for this release
231 namefield->setReadOnly(b);
232 idfield->setReadOnly(b);
233 leaderfield->setReadOnly(b);
234 chooseLeader->setEnabled(!b);
235 schedulingGroup->setEnabled(!b);
236}
237
238} //KPlato namespace
239
240#include "kptmainprojectpanel.moc"
Project is the main node in a project, it contains child nodes and possibly sub-projects.
Definition kptproject.h:52