00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kptmainprojectpanel.h"
00021
00022 #include <qcheckbox.h>
00023 #include <qbuttongroup.h>
00024 #include <qdatetime.h>
00025 #include <qdatetimeedit.h>
00026 #include <qradiobutton.h>
00027 #include <qpushbutton.h>
00028
00029 #include <qlabel.h>
00030 #include <klineedit.h>
00031 #include <ktextedit.h>
00032 #include <kdatewidget.h>
00033 #include <klocale.h>
00034 #include <kmessagebox.h>
00035 #include <kcommand.h>
00036 #include <kabc/addressee.h>
00037 #include <kabc/addresseedialog.h>
00038
00039 #include <kdebug.h>
00040
00041 #include "kptproject.h"
00042 #include "kptcommand.h"
00043 #include "kptschedule.h"
00044
00045 namespace KPlato
00046 {
00047
00048 MainProjectPanel::MainProjectPanel(Project &p, QWidget *parent, const char *name)
00049 : MainProjectPanelImpl(parent, name),
00050 project(p)
00051 {
00052 namefield->setText(project.name());
00053 idfield->setText(project.id());
00054 leaderfield->setText(project.leader());
00055 descriptionfield->setText(project.description());
00056 wbs->setText(project.wbs());
00057
00058
00059
00060 QDateTime st = project.constraintStartTime();
00061 QDateTime et = project.constraintEndTime();
00062 QString s = i18n("Scheduling");
00063 Schedule *sch = project.currentSchedule();
00064 if (sch) {
00065 s = i18n("Scheduling (%1)").arg(sch->typeToString(true));
00066 }
00067 schedulingGroup->setTitle(s);
00068 if (project.constraint() == Node::MustStartOn) {
00069 schedulingGroup->setButton(0);
00070 if (sch)
00071 et = project.endTime();
00072 } else if (project.constraint() == Node::MustFinishOn) {
00073 schedulingGroup->setButton(1);
00074 if (sch)
00075 st = project.startTime();
00076 } else {
00077 kdWarning()<<k_funcinfo<<"Illegal constraint: "<<project.constraint()<<endl;
00078 schedulingGroup->setButton(0);
00079 if (sch)
00080 et = project.endTime();
00081 }
00082 startDate->setDate(st.date());
00083 startTime->setTime(st.time());
00084 endDate->setDate(et.date());
00085 endTime->setTime(et.time());
00086 enableDateTime();
00087
00088 namefield->setFocus();
00089 }
00090
00091
00092 bool MainProjectPanel::ok() {
00093 if (idfield->text() != project.id() && project.findNode(idfield->text())) {
00094 KMessageBox::sorry(this, i18n("Project id must be unique"));
00095 idfield->setFocus();
00096 return false;
00097 }
00098 return true;
00099 }
00100
00101 KCommand *MainProjectPanel::buildCommand(Part *part) {
00102 KMacroCommand *m = 0;
00103 QString c = i18n("Modify main project");
00104 if (project.name() != namefield->text()) {
00105 if (!m) m = new KMacroCommand(c);
00106 m->addCommand(new NodeModifyNameCmd(part, project, namefield->text()));
00107 }
00108 if (project.id() != idfield->text()) {
00109 if (!m) m = new KMacroCommand(c);
00110 m->addCommand(new NodeModifyIdCmd(part, project, idfield->text()));
00111 }
00112 if (project.leader() != leaderfield->text()) {
00113 if (!m) m = new KMacroCommand(c);
00114 m->addCommand(new NodeModifyLeaderCmd(part, project, leaderfield->text()));
00115 }
00116 if (project.description() != descriptionfield->text()) {
00117 if (!m) m = new KMacroCommand(c);
00118 m->addCommand(new NodeModifyDescriptionCmd(part, project, descriptionfield->text()));
00119 }
00120
00121
00122
00123
00124
00125 if (bStartDate->state() && project.constraint() != Node::MustStartOn) {
00126 if (!m) m = new KMacroCommand(c);
00127 m->addCommand(new ProjectModifyConstraintCmd(part, project, Node::MustStartOn));
00128 }
00129 if (bEndDate->state() && project.constraint() != Node::MustFinishOn) {
00130 if (!m) m = new KMacroCommand(c);
00131 m->addCommand(new ProjectModifyConstraintCmd(part, project, Node::MustFinishOn));
00132 }
00133 if (bStartDate->state() && startDateTime() != project.constraintStartTime()) {
00134 if (!m) m = new KMacroCommand(c);
00135 m->addCommand(new ProjectModifyStartTimeCmd(part, project, startDateTime()));
00136 }
00137 if (bEndDate->state() && endDateTime() != project.constraintEndTime()) {
00138 if (!m) m = new KMacroCommand(c);
00139 m->addCommand(new ProjectModifyEndTimeCmd(part, project, endDateTime()));
00140 }
00141 return m;
00142 }
00143
00144
00145 MainProjectPanelImpl::MainProjectPanelImpl(QWidget *parent, const char *name)
00146 : MainProjectPanelBase(parent, name) {
00147
00148
00149 connect( bStartDate, SIGNAL( clicked() ), this, SLOT( slotStartDateClicked() ) );
00150 connect( bEndDate, SIGNAL( clicked() ), this, SLOT( slotEndDateClicked() ) );
00151 connect( bStartDate, SIGNAL( clicked() ), this, SLOT( slotCheckAllFieldsFilled() ) );
00152 connect( bEndDate, SIGNAL( clicked() ), this, SLOT( slotCheckAllFieldsFilled() ) );
00153 connect( descriptionfield, SIGNAL( textChanged() ), this, SLOT( slotCheckAllFieldsFilled() ) );
00154 connect( endDate, SIGNAL( changed(QDate) ), this, SLOT( slotCheckAllFieldsFilled() ) );
00155 connect( endTime, SIGNAL( valueChanged(const QTime&) ), this, SLOT( slotCheckAllFieldsFilled() ) );
00156 connect( startDate, SIGNAL( changed(QDate) ), this, SLOT( slotCheckAllFieldsFilled() ) );
00157 connect( startTime, SIGNAL( valueChanged(const QTime&) ), this, SLOT( slotCheckAllFieldsFilled() ) );
00158
00159 connect( namefield, SIGNAL( textChanged(const QString&) ), this, SLOT( slotCheckAllFieldsFilled() ) );
00160 connect( idfield, SIGNAL( textChanged(const QString&) ), this, SLOT( slotCheckAllFieldsFilled() ) );
00161 connect( leaderfield, SIGNAL( textChanged(const QString&) ), this, SLOT( slotCheckAllFieldsFilled() ) );
00162
00163 connect( chooseLeader, SIGNAL( clicked() ), this, SLOT( slotChooseLeader() ) );
00164 }
00165
00166 void MainProjectPanelImpl::slotCheckAllFieldsFilled()
00167 {
00168 emit changed();
00169 emit obligatedFieldsFilled(!namefield->text().isEmpty() && !idfield->text().isEmpty() && !leaderfield->text().isEmpty());
00170 }
00171
00172
00173 void MainProjectPanelImpl::slotChooseLeader()
00174 {
00175 KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this);
00176 if (!a.isEmpty())
00177 {
00178 leaderfield->setText(a.fullEmail());
00179 }
00180 }
00181
00182
00183 void MainProjectPanelImpl::slotStartDateClicked()
00184 {
00185 enableDateTime();
00186 }
00187
00188
00189 void MainProjectPanelImpl::slotEndDateClicked()
00190 {
00191 enableDateTime();
00192 }
00193
00194
00195
00196 void MainProjectPanelImpl::enableDateTime()
00197 {
00198 if (schedulingGroup->selected() == bStartDate)
00199 {
00200 startTime->setEnabled(true);
00201 startDate->setEnabled(true);
00202 endTime->setEnabled(false);
00203 endDate->setEnabled(false);
00204 }
00205 if (schedulingGroup->selected() == bEndDate)
00206 {
00207 startTime->setEnabled(false);
00208 startDate->setEnabled(false);
00209 endTime->setEnabled(true);
00210 endDate->setEnabled(true);
00211 }
00212 }
00213
00214
00215 QDateTime MainProjectPanelImpl::startDateTime()
00216 {
00217 return QDateTime(startDate->date(), startTime->time());
00218 }
00219
00220
00221 QDateTime MainProjectPanelImpl::endDateTime()
00222 {
00223 return QDateTime(endDate->date(), endTime->time());
00224 }
00225
00226
00227 void MainProjectPanelImpl::slotBaseline()
00228 {
00229 bool b = false;
00230
00231 namefield->setReadOnly(b);
00232 idfield->setReadOnly(b);
00233 leaderfield->setReadOnly(b);
00234 chooseLeader->setEnabled(!b);
00235 schedulingGroup->setEnabled(!b);
00236 }
00237
00238 }
00239
00240 #include "kptmainprojectpanel.moc"