kplato

kptrelationdialog.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003, 2004 Dag Andersen <danders@get2net.dk>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation;
7 version 2 of the License.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kptrelationdialog.h"
21#include "kptrelation.h"
22#include "kptnode.h"
23#include "kptpart.h"
24#include "kptcommand.h"
25#include "kptdurationwidget.h"
26#include "relationpanel.h"
27
28#include <tqlayout.h>
29#include <tqvbox.h>
30#include <tqlabel.h>
31#include <tqbuttongroup.h>
32#include <tqradiobutton.h>
33
34#include <tdemessagebox.h>
35#include <tdelocale.h>
36#include <kcommand.h>
37#include <kdebug.h>
38
39namespace KPlato
40{
41
42AddRelationDialog::AddRelationDialog(Relation *rel, TQWidget *p, TQString caption, int buttons, const char *n)
43 : KDialogBase(Swallow, caption, buttons, Ok, p, n, true, true)
44{
45 if (caption.isEmpty())
46 setCaption(i18n("Add Relationship"));
47 m_relation = rel;
48 m_panel = new RelationPanel(this);
49 setMainWidget(m_panel);
50 m_panel->setActiveWindow();
51
52 m_panel->fromName->setText(rel->parent()->name());
53 m_panel->toName->setText(rel->child()->name());
54 m_panel->relationType->setButton(rel->type());
55
56 m_panel->lag->setVisibleFields(DurationWidget::Days|DurationWidget::Hours|DurationWidget::Minutes);
57 m_panel->lag->setFieldUnit(0, i18n("days", "d"));
58 m_panel->lag->setFieldUnit(1, i18n("hours", "h"));
59 m_panel->lag->setFieldUnit(2, i18n("minutes", "m"));
60 m_panel->lag->setValue(rel->lag());
61
62 m_panel->relationType->setFocus();
63 enableButtonOK(true);
64 connect(m_panel->relationType, TQ_SIGNAL(clicked(int)), TQ_SLOT(typeClicked(int)));
65 connect(m_panel->lag, TQ_SIGNAL(valueChanged()), TQ_SLOT(lagChanged()));
66}
67
68KCommand *AddRelationDialog::buildCommand(Part *part) {
69 return new AddRelationCmd(part, m_relation, i18n("Add Relation"));
70}
71
72void AddRelationDialog::slotOk() {
73 if ( m_panel->relationType->selected() == 0 ) {
74 KMessageBox::sorry(this, i18n("You must select a relationship type"));
75 return;
76 }
77 accept();
78}
79
80void AddRelationDialog::lagChanged() {
81 enableButtonOK(true);
82}
83
84void AddRelationDialog::typeClicked(int id) {
85 if (id != m_relation->type())
86 enableButtonOK(true);
87}
88
90
91ModifyRelationDialog::ModifyRelationDialog(Relation *rel, TQWidget *p, const char *n)
92 : AddRelationDialog(rel, p, i18n("Edit Relationship"), Ok|Cancel|User1, n)
93{
94 setButtonText( KDialogBase::User1, i18n("Delete") );
95 m_deleted = false;
96 enableButtonOK(false);
97}
98
99// Delete
100void ModifyRelationDialog::slotUser1() {
101 m_deleted = true;
102 accept();
103}
104
105KCommand *ModifyRelationDialog::buildCommand(Part *part) {
106 KMacroCommand *cmd=0;
107 if (m_panel->relationType->selectedId() != m_relation->type()) {
108 if (cmd == 0)
109 cmd = new KMacroCommand(i18n("Modify Relation"));
110 cmd->addCommand(new ModifyRelationTypeCmd(part, m_relation, (Relation::Type)m_panel->relationType->selectedId()));
111 }
112 if (m_relation->lag() != m_panel->lag->value()) {
113 if (cmd == 0)
114 cmd = new KMacroCommand(i18n("Modify Relation"));
115 cmd->addCommand(new ModifyRelationLagCmd(part, m_relation, m_panel->lag->value()));
116 }
117 return cmd;
118}
119
120} //KPlato namespace
121
122#include "kptrelationdialog.moc"