20#include "kptpertcanvas.h"
22#include "kptrelation.h"
23#include "kptrelationdialog.h"
24#include "kptcanvasitem.h"
28#include <tqclipboard.h>
29#include <tqprogressdialog.h>
30#include <tqobjectlist.h>
39#include <tdetempfile.h>
42#include <tdeapplication.h>
43#include <tdemessagebox.h>
45#include <tdemultipledrag.h>
46#include <tdelistview.h>
51PertCanvas::PertCanvas( TQWidget *parent )
52 : TQCanvasView( parent,
"Pert canvas" ),
59 m_canvas =
new TQCanvas(
this );
60 setCanvas( m_canvas );
63PertCanvas::~PertCanvas()
67void PertCanvas::draw(Project& project)
74 TQPtrListIterator<Node> nit(project.childNodeIterator());
75 for ( ; nit.current(); ++nit ) {
76 createChildItems(createNodeItem(nit.current()));
80 TQPtrDictIterator<PertNodeItem> it(m_nodes);
81 for(; it.current(); ++it)
83 if (!(it.current()->hasParent()) && it.current()->hasChild())
85 m_rows.append(
new TQMemArray<bool>(1));
86 it.current()->move(
this, m_rows.count()-1, 0);
90 for(it.toFirst(); it.current(); ++it)
92 if (!(it.current()->hasParent() || it.current()->hasChild()))
94 m_rows.append(
new TQMemArray<bool>(1));
95 it.current()->move(
this, m_rows.count()-1, 0);
99 TQSize s = canvasSize();
100 m_canvas->resize(s.width(), s.height());
104PertNodeItem *PertCanvas::createNodeItem(Node *node)
106 PertNodeItem *item = m_nodes.find(node);
109 if ( node->type() == Node::Type_Project)
110 kdDebug()<<k_funcinfo<<
"Project nodes should not have relations"<<endl;
111 else if (node->type() == Node::Type_Subproject)
112 item =
new PertProjectItem(
this, *node);
113 else if (node->type()== Node::Type_Summarytask)
114 item =
new PertTaskItem(
this, *node);
115 else if (node->type()== Node::Type_Task)
116 item =
new PertTaskItem(
this, *node);
117 else if (node->type() == Node::Type_Milestone)
118 item =
new PertMilestoneItem(
this, *node);
120 kdDebug()<<k_funcinfo<<
"Not implemented yet"<<endl;
123 m_nodes.insert(node, item);
128void PertCanvas::createChildItems(PertNodeItem *parentItem)
134 TQPtrListIterator<Relation> it(parentItem->node().dependChildNodes());
135 for (; it.current(); ++it)
137 PertNodeItem *childItem = createNodeItem(it.current()->child());
139 parentItem->addChildRelation(it.current(), childItem);
140 m_relations.append(it.current());
144 TQPtrListIterator<Node> nit(parentItem->node().childNodeIterator());
145 for ( ; nit.current(); ++nit ) {
146 createChildItems(createNodeItem(nit.current()));
150void PertCanvas::drawRelations()
153 TQPtrListIterator<Relation> it(m_relations);
154 for (; it.current(); ++it)
156 PertNodeItem *parentItem = m_nodes.find(it.current()->parent());
157 PertNodeItem *childItem = m_nodes.find(it.current()->child());
158 if (parentItem && childItem)
160 PertRelationItem *item =
new PertRelationItem(
this, parentItem, childItem, it.current());
166void PertCanvas::mapNode(PertNodeItem *item)
169 if (! m_rows.at(item->row()) || (item->column() >= 0 && m_rows.at(item->row())->count() <= uint(item->column())))
171 kdError()<<k_funcinfo<<item->node().name()<<
": non existing map for: ("<<item->row()<<
","<<item->column()<<
")"<<endl;
174 m_rows.at(item->row())->at(item->column()) =
true;
177void PertCanvas::mapChildNode(PertNodeItem *parentItem, PertNodeItem *childItem, Relation::Type type)
182 kdError()<<k_funcinfo<<
"No childItem"<<endl;
185 int row = parentItem->row();
186 int col = parentItem->column();
187 int chRow = childItem->row();
188 int chCol = childItem->column();
189 bool chMapped = (chRow > -1 && chCol > -1);
192 if (type == Relation::StartStart ||
193 type == Relation::FinishFinish)
198 m_rows.at(chRow)->at(chCol) =
false;
203 if (chRow >= 0 && m_rows.count() <= uint(chRow)) {
204 m_rows.append(
new TQMemArray<bool>(1));
205 chRow = m_rows.count()-1;
212 if (chCol >= 0 && m_rows.at(chRow)->count() <= uint(chCol))
213 m_rows.at(chRow)->resize(chCol+1);
221 if (!(m_rows.at(row+1)) ||
222 m_rows.at(row+1)->at(col) ==
true)
224 m_rows.append(
new TQMemArray<bool>(col+1));
226 else if (col >= 0 && m_rows.at(row+1)->count() <= uint(col))
227 m_rows.at(row)->resize(col+1);
229 chRow = m_rows.count() -1;
233 else if (type == Relation::FinishStart)
238 m_rows.at(chRow)->at(chCol) =
false;
245 if (chCol >= 0 && m_rows.at(chRow)->count() <= uint(chCol))
246 m_rows.at(chRow)->resize(chCol+1);
251 if (col >= 0 && m_rows.at(row)->count() <= uint(col))
252 m_rows.at(row)->resize(col+1);
253 else if (m_rows.at(row)->at(col) =
true)
254 m_rows.append(
new TQMemArray<bool>(col+1));
256 chRow = m_rows.count() -1;
262 kdError()<<k_funcinfo<<
"Unknow relation type"<<endl;
265 childItem->move(
this, chRow, chCol);
268TQSize PertCanvas::canvasSize()
272 TQCanvasItemList list = canvas()->allItems();
273 TQCanvasItemList::Iterator it = list.begin();
274 for (; it != list.end(); ++it)
276 TQRect r = (*it)->boundingRect();
277 s.setWidth(TQMAX(s.width(), r.right()));
278 s.setHeight(TQMAX(s.height(), r.bottom()));
280 s.setWidth(s.width()+20);
281 s.setHeight(s.height()+20);
285void PertCanvas::clear()
290 TQCanvasItemList list = canvas()->allItems();
291 TQCanvasItemList::Iterator it = list.begin();
292 for (; it != list.end(); ++it)
299void PertCanvas::contentsMousePressEvent ( TQMouseEvent * e )
304 case TQt::LeftButton:
308 case TQt::RightButton:
310 PertNodeItem *item = selectedItem();
312 item->setSelected(
false);
315 TQCanvasItemList l = canvas()->collisions(e->pos());
316 for (TQCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
318 if ( (*it)->rtti() == PertProjectItem::RTTI ||
319 (*it)->rtti() == PertTaskItem::RTTI ||
320 (*it)->rtti() == PertMilestoneItem::RTTI )
322 PertNodeItem *item = (PertNodeItem *)(*it);
324 item->setSelected(
true);
326 emit rightButtonPressed(&(item->node()), e->globalPos());
327 if (item == selectedItem()) {
329 item->setSelected(
false);
345void PertCanvas::contentsMouseReleaseEvent ( TQMouseEvent * e )
350 case TQt::LeftButton:
353 TQCanvasItemList l = canvas()->collisions(e->pos());
354 for (TQCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
356 if ( (*it)->rtti() == PertProjectItem::RTTI ||
357 (*it)->rtti() == PertTaskItem::RTTI ||
358 (*it)->rtti() == PertMilestoneItem::RTTI )
361 PertNodeItem *item = (PertNodeItem *)(*it);
362 PertNodeItem *par = selectedItem();
366 item->setSelected(
true);
370 par->setSelected(
false);
371 if (&(item->node()) == &(par->node()))
377 if (!par->node().legalToLink(&(item->node()))) {
378 KMessageBox::sorry(
this, i18n(
"Cannot link these nodes"));
380 Relation *rel = item->node().findRelation(&(par->node()));
382 emit modifyRelation(rel);
384 emit addRelation(&(par->node()), &(item->node()));
390 PertNodeItem *i = selectedItem();
391 if (i) i->setSelected(
false);
396 case TQt::RightButton:
407PertNodeItem *PertCanvas::selectedItem()
409 TQCanvasItemList list = canvas()->allItems();
410 TQCanvasItemList::Iterator it = list.begin();
411 for (; it != list.end(); ++it)
413 if ( (*it)->isSelected() )
415 if ( (*it)->rtti() == PertProjectItem::RTTI ||
416 (*it)->rtti() == PertTaskItem::RTTI ||
417 (*it)->rtti() == PertMilestoneItem::RTTI )
418 return (PertNodeItem *)(*it);
424Node *PertCanvas::selectedNode() {
425 return selectedItem() ? &(selectedItem()->node()) : 0;
429void PertCanvas::printDebug(
int )
436#include "kptpertcanvas.moc"