00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kptrelationdialog.h"
00021 #include "kptrelation.h"
00022 #include "kptnode.h"
00023 #include "kptpart.h"
00024 #include "kptcommand.h"
00025 #include "kptdurationwidget.h"
00026
00027 #include <QLayout>
00028 #include <QLabel>
00029
00030 #include <kmessagebox.h>
00031 #include <klocale.h>
00032 #include <kcommand.h>
00033 #include <kdebug.h>
00034
00035 namespace KPlato
00036 {
00037
00038 RelationPanel::RelationPanel(QWidget *parent)
00039 : QWidget(parent)
00040 {
00041 setupUi(this);
00042 lag = new DurationWidget(durationHolder);
00043 QLayout *l = durationHolder->layout();
00044 if (l)
00045 l->addWidget(lag);
00046 }
00047
00048 AddRelationDialog::AddRelationDialog(Relation *rel, QWidget *p, QString caption, ButtonCodes buttons, const char *n)
00049 : KDialog(p)
00050 {
00051 setCaption( caption );
00052 setButtons( buttons );
00053 setDefaultButton( Ok );
00054 showButtonSeparator( true );
00055 if (caption.isEmpty())
00056 setCaption(i18n("Add Relationship"));
00057 m_relation = rel;
00058 m_panel = new RelationPanel(this);
00059 setMainWidget(m_panel);
00060 m_panel->setActiveWindow();
00061
00062 m_panel->fromName->setText(rel->parent()->name());
00063 m_panel->toName->setText(rel->child()->name());
00064 if (rel->type() == Relation::FinishStart) {
00065 m_panel->bFinishStart->setChecked(true);
00066 } else if (rel->type() == Relation::FinishFinish) {
00067 m_panel->bFinishFinish->setChecked(true);
00068 } else if (rel->type() == Relation::StartStart) {
00069 m_panel->bStartStart->setChecked(true);
00070 }
00071
00072 m_panel->lag->setVisibleFields(DurationWidget::Days|DurationWidget::Hours|DurationWidget::Minutes);
00073 m_panel->lag->setFieldUnit(0, i18nc("days", "d"));
00074 m_panel->lag->setFieldUnit(1, i18nc("hours", "h"));
00075 m_panel->lag->setFieldUnit(2, i18nc("minutes", "m"));
00076 m_panel->lag->setValue(rel->lag());
00077
00078 m_panel->relationType->setFocus();
00079 enableButtonOk(true);
00080
00081 connect(m_panel->bFinishStart, SIGNAL(toggled(bool)), SLOT(slotFinishStartToggled(bool)));
00082 connect(m_panel->bFinishFinish, SIGNAL(toggled(bool)), SLOT(slotFinishFinishToggled(bool)));
00083 connect(m_panel->bStartStart, SIGNAL(toggled(bool)), SLOT(slotStartStartToggled(bool)));
00084 connect(m_panel->lag, SIGNAL(valueChanged()), SLOT(lagChanged()));
00085 }
00086
00087 KCommand *AddRelationDialog::buildCommand(Part *part) {
00088 return new AddRelationCmd(part, m_relation, i18n("Add Relation"));
00089 }
00090
00091 void AddRelationDialog::slotOk() {
00092 accept();
00093 }
00094 void AddRelationDialog::slotFinishStartToggled(bool ch) {
00095
00096 if (ch && m_relation->type() != Relation::FinishStart)
00097 enableButtonOk(true);
00098 }
00099 void AddRelationDialog::slotFinishFinishToggled(bool ch) {
00100
00101 if (ch && m_relation->type() != Relation::FinishFinish)
00102 enableButtonOk(true);
00103 }
00104 void AddRelationDialog::slotStartStartToggled(bool ch) {
00105
00106 if (ch && m_relation->type() != Relation::StartStart)
00107 enableButtonOk(true);
00108 }
00109
00110 void AddRelationDialog::lagChanged() {
00111 enableButtonOk(true);
00112 }
00113
00114 void AddRelationDialog::typeClicked(int id) {
00115 if (id != m_relation->type())
00116 enableButtonOk(true);
00117 }
00118
00119 int AddRelationDialog::selectedRelationType() const {
00120 if (m_panel->bStartStart->isChecked())
00121 return Relation::StartStart;
00122 else if (m_panel->bFinishFinish->isChecked())
00123 return Relation::FinishFinish;
00124
00125 return Relation::FinishStart;
00126 }
00127
00129
00130 ModifyRelationDialog::ModifyRelationDialog(Relation *rel, QWidget *p, const char *n)
00131 : AddRelationDialog(rel, p, i18n("Edit Relationship"), Ok|Cancel|User1, n)
00132 {
00133 setButtonText( KDialog::User1, i18n("Delete") );
00134 m_deleted = false;
00135 enableButtonOk(false);
00136
00137 connect(this, SIGNAL(user1Clicked()), SLOT(slotUser1()));
00138 }
00139
00140
00141 void ModifyRelationDialog::slotUser1() {
00142 m_deleted = true;
00143 accept();
00144 }
00145
00146 KCommand *ModifyRelationDialog::buildCommand(Part *part) {
00147 KMacroCommand *cmd=0;
00148 if (selectedRelationType() != m_relation->type()) {
00149 if (cmd == 0)
00150 cmd = new KMacroCommand(i18n("Modify Relation"));
00151 cmd->addCommand(new ModifyRelationTypeCmd(part, m_relation, (Relation::Type)(selectedRelationType())));
00152
00153
00154 }
00155 if (m_relation->lag() != m_panel->lag->value()) {
00156 if (cmd == 0)
00157 cmd = new KMacroCommand(i18n("Modify Relation"));
00158 cmd->addCommand(new ModifyRelationLagCmd(part, m_relation, m_panel->lag->value()));
00159 }
00160 return cmd;
00161 }
00162
00163 }
00164
00165 #include "kptrelationdialog.moc"