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