F:/KPlato/koffice/kplato/kptrelationdialog.cc

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2003, 2004 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation;
00007    version 2 of the License.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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     //connect(m_panel->relationType, SIGNAL(clicked(int)), SLOT(typeClicked(int)));
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     //kDebug()<<k_funcinfo<<ch<<endl;
00096     if (ch && m_relation->type() != Relation::FinishStart)
00097         enableButtonOk(true);
00098 }
00099 void AddRelationDialog::slotFinishFinishToggled(bool ch) {
00100     //kDebug()<<k_funcinfo<<ch<<endl;
00101     if (ch && m_relation->type() != Relation::FinishFinish)
00102         enableButtonOk(true);
00103 }
00104 void AddRelationDialog::slotStartStartToggled(bool ch) {
00105     //kDebug()<<k_funcinfo<<ch<<endl;
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 // Delete
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         //kDebug()<<k_funcinfo<<m_panel->relationType->selectedId()<<endl;
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 }  //KPlato namespace
00164 
00165 #include "kptrelationdialog.moc"

Généré le Wed Nov 22 23:40:57 2006 pour KPlato par  doxygen 1.5.1-p1