kplato

kptrelationdialog.cc

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 #include "relationpanel.h"
00027 
00028 #include <qlayout.h>
00029 #include <qvbox.h>
00030 #include <qlabel.h>
00031 #include <qbuttongroup.h>
00032 #include <qradiobutton.h>
00033 
00034 #include <kmessagebox.h>
00035 #include <klocale.h>
00036 #include <kcommand.h>
00037 #include <kdebug.h>
00038 
00039 namespace KPlato
00040 {
00041 
00042 AddRelationDialog::AddRelationDialog(Relation *rel, QWidget *p, QString caption, int buttons, const char *n)
00043     : KDialogBase(Swallow, caption, buttons, Ok, p, n, true, true)
00044 {
00045     if (caption.isEmpty())
00046         setCaption(i18n("Add Relationship"));
00047     m_relation = rel;
00048     m_panel = new RelationPanel(this);
00049     setMainWidget(m_panel);
00050     m_panel->setActiveWindow();
00051     
00052     m_panel->fromName->setText(rel->parent()->name());
00053     m_panel->toName->setText(rel->child()->name());
00054     m_panel->relationType->setButton(rel->type());
00055     
00056     m_panel->lag->setVisibleFields(DurationWidget::Days|DurationWidget::Hours|DurationWidget::Minutes);
00057     m_panel->lag->setFieldUnit(0, i18n("days", "d"));
00058     m_panel->lag->setFieldUnit(1, i18n("hours", "h"));
00059     m_panel->lag->setFieldUnit(2, i18n("minutes", "m"));
00060     m_panel->lag->setValue(rel->lag());
00061     
00062     m_panel->relationType->setFocus();
00063     enableButtonOK(true);
00064     connect(m_panel->relationType, SIGNAL(clicked(int)), SLOT(typeClicked(int)));
00065     connect(m_panel->lag, SIGNAL(valueChanged()), SLOT(lagChanged()));
00066 }
00067 
00068 KCommand *AddRelationDialog::buildCommand(Part *part) {
00069     return new AddRelationCmd(part, m_relation, i18n("Add Relation"));
00070 }
00071 
00072 void AddRelationDialog::slotOk() {
00073     if ( m_panel->relationType->selected() == 0 ) {
00074         KMessageBox::sorry(this, i18n("You must select a relationship type"));
00075         return;
00076     }
00077     accept();
00078 }
00079 
00080 void AddRelationDialog::lagChanged() {
00081     enableButtonOK(true);
00082 }
00083 
00084 void AddRelationDialog::typeClicked(int id) {
00085     if (id != m_relation->type())
00086         enableButtonOK(true);
00087 }
00088 
00090 
00091 ModifyRelationDialog::ModifyRelationDialog(Relation *rel, QWidget *p, const char *n)
00092     : AddRelationDialog(rel, p, i18n("Edit Relationship"), Ok|Cancel|User1, n)
00093 {
00094     setButtonText( KDialogBase::User1, i18n("Delete") );
00095     m_deleted = false;
00096     enableButtonOK(false);
00097 }
00098 
00099 // Delete
00100 void ModifyRelationDialog::slotUser1() {
00101     m_deleted = true;
00102     accept();
00103 }
00104 
00105 KCommand *ModifyRelationDialog::buildCommand(Part *part) {
00106     KMacroCommand *cmd=0;
00107     if (m_panel->relationType->selectedId() != m_relation->type()) {
00108         if (cmd == 0)
00109             cmd = new KMacroCommand(i18n("Modify Relation"));
00110         cmd->addCommand(new ModifyRelationTypeCmd(part, m_relation, (Relation::Type)m_panel->relationType->selectedId()));
00111     }
00112     if (m_relation->lag() != m_panel->lag->value()) {
00113         if (cmd == 0)
00114             cmd = new KMacroCommand(i18n("Modify Relation"));
00115         cmd->addCommand(new ModifyRelationLagCmd(part, m_relation, m_panel->lag->value()));
00116     }
00117     return cmd;
00118 }
00119 
00120 }  //KPlato namespace
00121 
00122 #include "kptrelationdialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys