kplato

kptcanvasitem.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 "kpttask.h"
21#include "kptcanvasitem.h"
22#include "kptrelation.h"
23#include "kptpertcanvas.h"
24#include "kptganttview.h"
25
26#include <tdelocale.h>
27#include <tqpainter.h>
28#include <tqpointarray.h>
29#include <tqptrlist.h>
30#include <tqpoint.h>
31
32#include <kdebug.h>
33
34namespace KPlato
35{
36
37PertNodeItem::PertNodeItem( PertCanvas *view, Node &node, int row, int col )
38 : TQCanvasPolygon(view->canvas()),
39 m_node(node),
40 m_row(row),
41 m_col(col)
42{
43 m_x = m_y = 0;
44 m_wgap = view->verticalGap();
45 m_hgap = view->horizontalGap();
46 m_width = view->itemSize().width();
47 m_height = view->itemSize().height();
48
49 m_name = new TQCanvasText(node.name(), view->canvas());
50 m_childRelations.setAutoDelete(true);
51}
52
53PertNodeItem::~PertNodeItem()
54{
55 TQCanvasItemList list = canvas()->allItems();
56 TQCanvasItemList::Iterator it = list.begin();
57 for (; it != list.end(); ++it)
58 {
59 if ( *it == m_name )
60 m_name->hide();
61 if ( *it == m_leader )
62 m_leader->hide();
63 }
64 hide();
65 }
66
67int PertNodeItem::rtti() const { return RTTI; }
68int PertNodeItem::RTTI = 2000;
69
70void PertNodeItem::setVisible(bool yes)
71{
72 //kdDebug()<<k_funcinfo<<m_node.name()<<endl;
73 TQCanvasPolygon::setVisible(yes);
74 TQCanvasItemList list = canvas()->allItems();
75 TQCanvasItemList::Iterator it = list.begin();
76 for (; it != list.end(); ++it)
77 {
78 if ( *it == m_name )
79 m_name->setVisible(yes);
80 if ( *it == m_leader )
81 m_leader->setVisible(yes);
82 }
83}
84
85void PertNodeItem::move(PertCanvas *view, int row, int col)
86{
87 //kdDebug()<<k_funcinfo<<endl;
88 m_row = row; m_col = col;
89 view->mapNode(this);
90
91 // Now map my children
92 TQPtrListIterator<PertNodeRelation> it(m_childRelations);
93 for (; it.current(); ++it)
94 {
95 view->mapChildNode(this, it.current()->childItem, it.current()->relation->type());
96 }
97
98 // now move the item on the canvas
99 m_x = x(col); m_y = y(row);
100 m_left = TQPoint(m_x, m_y + m_height/2);
101 m_right = TQPoint(m_x + m_width, m_y + m_height/2);
102 TQCanvasPolygon::move(m_x, m_y);
103 if (m_name)
104 m_name->move(m_x+5, m_y+2);
105
106 setVisible(true);
107 //kdDebug()<<k_funcinfo<<m_node.name()<<" moved to row,col=("<<m_row<<","<<m_col<<")"<<endl;
108}
109
110void PertNodeItem::drawShape(TQPainter &p)
111{
112 //TQPen pen(pen());
113 if (isSelected())
114 p.setPen(TQPen(TQt::red, 2));
115 TQPointArray a = poly;
116 int size = a.size()-1;
117 for(int i = 0; i < size; ++i)
118 {
119 //kdDebug()<<k_funcinfo<<" draw["<<i<<"]: "<<a[i].x()<<","<<a[i].y()<<" to "<<a[i+1].x()<<","<<a[i+1].y()<<endl;
120 p.drawLine(a[i], a[i+1]);
121 }
122 //setPen(pen);
123}
124
125TQPoint PertNodeItem::exitPoint(Relation::Type type) const
126{
127 TQPoint ret;
128 switch(type)
129 {
130 case Relation::FinishStart:
131 case Relation::FinishFinish:
132 ret = m_right + TQPoint(pen().width(), 0);
133 break;
134 case Relation::StartStart:
135 ret = m_left + TQPoint(0, 4);
136 break;
137 }
138 return ret;
139}
140
141TQPoint PertNodeItem::entryPoint(Relation::Type type) const
142{
143 TQPoint ret;
144 switch(type)
145 {
146 case Relation::FinishStart:
147 ret = m_left - TQPoint(pen().width(), 0);
148 break;
149 case Relation::FinishFinish:
150 ret = m_right - TQPoint(pen().width(), 4);
151 break;
152 case Relation::StartStart:
153 ret = m_left - TQPoint(pen().width(), 0);
154 break;
155 }
156 return ret;
157}
158
159#ifndef NDEBUG
160void PertNodeItem::printDebug( int /*info*/ )
161{
162}
163#endif
164
166
167PertProjectItem::PertProjectItem(PertCanvas *view, Node &node, int row, int col)
168 : PertNodeItem(view, node, row, col)
169{
170 //kdDebug()<<k_funcinfo<<"Node="<<node.name()<<" ("<<row<<","<<col<<")"<<endl;
171
172 TQPointArray a;
173 a.putPoints(0, 5,
174 m_x+6, m_y, m_x+m_width, m_y, m_x+m_width-6, m_y+m_height, m_x, m_y+m_height, m_x+6, m_y);
175 setPoints(a);
176
177 setPen(TQPen(TQt::cyan, 2));
178}
179
180PertProjectItem::~PertProjectItem()
181{
182}
183
184int PertProjectItem::rtti() const { return RTTI; }
185int PertProjectItem::RTTI = 2001;
186
187#ifndef NDEBUG
188void PertProjectItem::printDebug( int /*info*/ )
189{
190}
191#endif
192
193
195
196PertTaskItem::PertTaskItem(PertCanvas *view, Node &node, int row, int col)
197 : PertNodeItem(view, node, row, col)
198{
199 //kdDebug()<<k_funcinfo<<"Node="<<node.name()<<" ("<<row<<","<<col<<")"<<endl;
200 TQPointArray a;
201 if (node.type() == Node::Type_Summarytask)
202 {
203 a.putPoints(0, 5, m_x+6, m_y, m_x+m_width, m_y, m_x+m_width-6, m_y+m_height, m_x, m_y+m_height, m_x+6, m_y);
204 setPen(TQPen(TQt::cyan, 2));
205 }
206 else
207 {
208 a.putPoints(0, 5, m_x, m_y, m_x+m_width, m_y, m_x+m_width, m_y+m_height, m_x, m_y+m_height, m_x, m_y);
209 setPen(TQPen(TQt::green, 2));
210 }
211 setPoints(a);
212
213}
214
215PertTaskItem::~PertTaskItem()
216{
217}
218
219int PertTaskItem::rtti() const { return RTTI; }
220int PertTaskItem::RTTI = 2002;
221
222
223#ifndef NDEBUG
224void PertTaskItem::printDebug( int /*info*/ )
225{
226}
227#endif
228
229
231
232PertMilestoneItem::PertMilestoneItem(PertCanvas *view, Node &node, int row, int col)
233 : PertNodeItem(view, node, row, col)
234{
235 //kdDebug()<<k_funcinfo<<"Node="<<node.name()<<" ("<<row<<","<<col<<")"<<endl;
236
237 TQPointArray a;
238 a.putPoints(0, 7,
239 m_x, m_y+m_height/2,
240 m_x+6, m_y,
241 m_x+m_width-6, m_y,
242 m_x+m_width, m_y+m_height/2,
243 m_x+m_width-6, m_y+m_height,
244 m_x+6, m_y+m_height,
245 m_x, m_y+m_height/2);
246
247 setPoints(a);
248
249 setPen(TQPen(TQt::blue, 2));
250}
251
252PertMilestoneItem::~PertMilestoneItem()
253{
254}
255
256int PertMilestoneItem::rtti() const { return RTTI; }
257int PertMilestoneItem::RTTI = 2003;
258
259#ifndef NDEBUG
260void PertMilestoneItem::printDebug( int /*info*/ )
261{
262}
263#endif
264
265
267
268PertRelationItem::PertRelationItem( PertCanvas *view, PertNodeItem *parent, PertNodeItem *child, Relation *rel)
269 : TQCanvasPolygon(view->canvas()),
270 m_view(view),
271 m_rel(rel),
272 m_parentItem(parent),
273 m_childItem(child)
274{
275 //kdDebug()<<k_funcinfo<<"Parent="<<parent->node().name()<<" Child="<<child->node().name()<<endl;
276 draw();
277 setVisible(true);
278}
279
280PertRelationItem::~PertRelationItem()
281{
282 hide();
283}
284
285int PertRelationItem::rtti() const { return RTTI; }
286int PertRelationItem::RTTI = 2020;
287
288void PertRelationItem::draw()
289{
290 //kdDebug()<<k_funcinfo<<endl;
291 // Some "rules":
292 // a) Relation::FinishStart: child column > parent column
293 // b) Relation::FinishFinish: child column >= parent column
294 // c) Relation::StartStart: child column >= parent column
295 // d) Child row can be >= parent row
296
297 wgap = m_view->verticalGap();
298 hgap = m_view->horizontalGap();
299
300 // could not use ...rect() here, don't know why
301 parentTop = (int)(m_parentItem->y());
302 parentBottom = parentTop + (int)(m_parentItem->height());
303 childTop = (int)(m_childItem->y());
304
305 childRow = m_childItem->row();
306 childCol = m_childItem->column();
307 parentRow = m_parentItem->row();
308 parentCol = m_parentItem->column();
309 //kdDebug()<<k_funcinfo<<"Parent="<<m_parentItem->node().name()<<" ("<<parentRow<<","<<parentCol<<") Child="<<m_childItem->node().name()<<" ("<<childRow<<","<<childCol<<")"<<endl;
310
311 switch (type())
312 {
313 case Relation::FinishStart:
314 setFinishStartPoints();
315 break;
316 case Relation::FinishFinish:
317 setFinishFinishPoints();
318 break;
319 case Relation::StartStart:
320 setStartStartPoints();
321 break;
322 }
323 TQPointArray a = poly;
324 left = right = a[0].x();
325 top = bottom = a[0].y();
326 for (uint i = 0; i < a.size(); i++)
327 {
328 left = TQMIN(a[i].x(), left);
329 top = TQMIN(a[i].y(), top);
330 right = TQMAX(a[i].x(), right);
331 bottom = TQMAX(a[i].y(), bottom);
332 }
333 top -= 3;
334 bottom += 3;
335
336 setPen(TQt::black);
337 setZ(45);
338
339/*#ifndef NDEBUG
340 kdDebug()<<" PertNodeRelation from parent: "<<m_rel->parent()->name()<<" to child: "<<m_rel->child()->name()<<endl;
341 TQPointArray pa = poly;
342 for (int i = 0; i < pa.size(); ++i)
343 kdDebug()<<" pa["<<i<<"]="<<pa[i].x()<<","<<pa[i].y()<<endl;
344#endif*/
345
346}
347
348void PertRelationItem::setFinishStartPoints()
349{
350 TQPoint parentPoint = m_parentItem->exitPoint(Relation::FinishStart);
351 TQPoint childPoint = m_childItem->entryPoint(Relation::FinishStart);
352
353 TQPointArray a;
354 a.putPoints(0, 1, parentPoint.x(), parentPoint.y());
355
356 if ( parentRow == childRow )
357 {
358 if (parentCol == childCol - 1 || rowFree(parentRow, parentCol+1, childCol-1))
359 {
360 a.putPoints(1, 1, childPoint.x(), childPoint.y());
361 }
362 else // go around below
363 {
364 a.putPoints(1, 9,
365 parentPoint.x()+(wgap/2)-3, parentPoint.y(), // stop short
366 parentPoint.x()+(wgap/2), parentPoint.y()+3, // right/down
367 parentPoint.x()+(wgap/2), parentBottom+(hgap/2)-3, // stop short
368 parentPoint.x()+(wgap/2)+3, parentBottom+(hgap/2), // right/down
369 childPoint.x()-(wgap/2)-3, parentBottom+(hgap/2), // stop short
370 childPoint.x()-(wgap/2), parentBottom+(hgap/2)-3, // right/up
371 childPoint.x()-(wgap/2), childPoint.y()+3, // stop short
372 childPoint.x()-(wgap/2)+3, childPoint.y(), // right/up
373 childPoint.x(), childPoint.y());
374 }
375 }
376 else if ( parentRow > childRow )
377 {
378 if (parentCol == childCol - 1)
379 {
380 a.putPoints(1, 5,
381 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
382 parentPoint.x()+(wgap/2), parentPoint.y()-3,
383 parentPoint.x()+wgap/2, childPoint.y()+3,
384 parentPoint.x()+(wgap/2)+3, childPoint.y(),
385 childPoint.x(), childPoint.y());
386 }
387 else // go around above
388 {
389 a.putPoints(1, 9,
390 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
391 parentPoint.x()+(wgap/2), parentPoint.y()-3,
392 parentPoint.x()+wgap/2, parentTop-(hgap/2)+3,
393 parentPoint.x()+(wgap/2)+3, parentTop-(hgap/2),
394 childPoint.x()-(wgap/2)-3, parentTop-hgap/2,
395 childPoint.x()-(wgap/2), parentTop-(hgap/2)-3,
396 childPoint.x()-wgap/2, childPoint.y()+3,
397 childPoint.x()-(wgap/2)+3, childPoint.y(),
398 childPoint.x(), childPoint.y());
399 }
400 }
401 else if ( parentRow < childRow )
402 {
403 if (parentCol == childCol - 1)
404 {
405 a.putPoints(1, 5,
406 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
407 parentPoint.x()+(wgap/2), parentPoint.y()+3,
408 parentPoint.x()+wgap/2, childPoint.y()-3,
409 parentPoint.x()+(wgap/2)+3, childPoint.y(),
410 childPoint.x(), childPoint.y());
411
412 }
413 else
414 {
415 a.putPoints(1, 9,
416 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
417 parentPoint.x()+(wgap/2), parentPoint.y()+3,
418 parentPoint.x()+wgap/2, childTop-(hgap/2)-3,
419 parentPoint.x()+(wgap/2)+3, childTop-(hgap/2),
420 childPoint.x()-(wgap/2)-3, childTop-(hgap/2),
421 childPoint.x()-(wgap/2), childTop-(hgap/2)+3,
422 childPoint.x()-wgap/2, childPoint.y()-3,
423 childPoint.x()-wgap/2+3, childPoint.y(),
424 childPoint.x(), childPoint.y());
425 }
426 }
427 setPoints(a);
428}
429
430void PertRelationItem::setFinishFinishPoints()
431{
432 //kdDebug()<<k_funcinfo<<endl;
433 TQPoint parentPoint = m_parentItem->exitPoint(Relation::FinishFinish);
434 TQPoint childPoint = m_childItem->entryPoint(Relation::FinishFinish);
435
436 TQPointArray a;
437 a.putPoints(0, 1, parentPoint.x(), parentPoint.y());
438
439
440 if ( parentRow >= childRow )
441 {
442 if (parentCol == childCol)
443 {
444 a.putPoints(1, 5,
445 childPoint.x()+(wgap/2)-3, parentPoint.y(),
446 childPoint.x()+(wgap/2), parentPoint.y()-3,
447 childPoint.x()+wgap/2, childPoint.y()+3,
448 childPoint.x()+(wgap/2)-3, childPoint.y(),
449 childPoint.x(), childPoint.y());
450 }
451 else if (parentCol < childCol)
452 {
453 a.putPoints(1, 9,
454 parentPoint.x()+(wgap/2)-3, parentPoint.y(), // stop short
455 parentPoint.x()+(wgap/2), parentPoint.y()+3, // right/down
456 parentPoint.x()+(wgap/2), parentBottom+(hgap/2)-3, // stop short
457 parentPoint.x()+(wgap/2)+3, parentBottom+(hgap/2), // right/down
458 childPoint.x()+(wgap/2)-3, parentBottom+(hgap/2), // stop short
459 childPoint.x()+(wgap/2), parentBottom+(hgap/2)-3, // right/up
460 childPoint.x()+(wgap/2), childPoint.y()+3, // stop short
461 childPoint.x()+(wgap/2)-3, childPoint.y(), // left/up
462 childPoint.x(), childPoint.y());
463 }
464 }
465 else // parentRow < choldRow
466 {
467 if (parentCol == childCol)
468 {
469 a.putPoints(1, 5,
470 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
471 parentPoint.x()+(wgap/2), parentPoint.y()+3,
472 parentPoint.x()+wgap/2, childPoint.y()-3,
473 parentPoint.x()+(wgap/2)-3, childPoint.y(),
474 childPoint.x(), childPoint.y());
475 }
476 else if (parentCol < childCol)
477 {
478 if (rowFree(parentRow, parentCol+1, childCol))
479 a.putPoints(1, 5,
480 childPoint.x()+(wgap/2)-3, parentPoint.y(),
481 childPoint.x()+(wgap/2), parentPoint.y()+3,
482 childPoint.x()+(wgap/2), childPoint.y()-3,
483 childPoint.x()+(wgap/2)-3, childPoint.y(),
484 childPoint.x(), childPoint.y());
485 else
486 a.putPoints(1, 9,
487 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
488 parentPoint.x()+(wgap/2), parentPoint.y()+3,
489 parentPoint.x()+wgap/2, childTop-(hgap/2)-3,
490 parentPoint.x()+(wgap/2)+3, childTop-(hgap/2),
491 childPoint.x()+(wgap/2)-3, childTop-(hgap/2),
492 childPoint.x()+(wgap/2), childTop-(hgap/2)+3,
493 childPoint.x()+(wgap/2), childPoint.y()-3,
494 childPoint.x()+(wgap/2)-3, childPoint.y(),
495 childPoint.x(), childPoint.y());
496 }
497 else
498 {
499 a.putPoints(1, 9,
500 parentPoint.x()+(wgap/2)-3, parentPoint.y(),
501 parentPoint.x()+(wgap/2), parentPoint.y()+3,
502 parentPoint.x()+wgap/2, childTop-(hgap/2)-3,
503 parentPoint.x()+(wgap/2)+3, childTop-(hgap/2),
504 childPoint.x()+(wgap/2)-3, childTop-(hgap/2),
505 childPoint.x()+(wgap/2), childTop-(hgap/2)+3,
506 childPoint.x()+wgap/2, childPoint.y()-3,
507 childPoint.x()+wgap/2-3, childPoint.y(),
508 childPoint.x(), childPoint.y());
509 }
510 }
511 setPoints(a);
512}
513
514void PertRelationItem::setStartStartPoints()
515{
516 //kdDebug()<<k_funcinfo<<endl;
517 TQPoint parentPoint = m_parentItem->exitPoint(Relation::StartStart);
518 TQPoint childPoint = m_childItem->entryPoint(Relation::StartStart);
519
520 TQPointArray a;
521 a.putPoints(0, 1, parentPoint.x(), parentPoint.y());
522
523 if ( parentRow > childRow )
524 {
525 if (parentCol == childCol) // go up
526 {
527 a.putPoints(1, 4,
528 parentPoint.x()-(wgap/2)+3, parentPoint.y(),
529 parentPoint.x()-(wgap/2), parentPoint.y()-3,
530 parentPoint.x()-(wgap/2), childPoint.y()+3,
531 parentPoint.x()-(wgap/2)+3, childPoint.y());
532 }
533 else // go above myself
534 {
535 a.putPoints(1, 8,
536 parentPoint.x()-(wgap/2)+3, parentPoint.y(),
537 parentPoint.x()-(wgap/2), parentPoint.y()-3,
538 parentPoint.x()-(wgap/2), parentTop-(hgap/2)+3,
539 parentPoint.x()-(wgap/2)+3, parentTop-(hgap/2),
540 childPoint.x()-(wgap/2)-3, parentTop-(hgap/2),
541 childPoint.x()-(wgap/2), parentTop-(hgap/2)-3,
542 childPoint.x()-(wgap/2), childPoint.y()+3,
543 childPoint.x()-(wgap/2)+3, childPoint.y());
544 }
545 }
546 else // go left/down
547 {
548 a.putPoints(1, 2,
549 parentPoint.x()-(wgap/2)+3, parentPoint.y(),
550 parentPoint.x()-(wgap/2), parentPoint.y()+3);
551
552 if (parentCol == childCol)
553 {
554 a.putPoints(3, 2,
555 parentPoint.x()-(wgap/2), childPoint.y()-3,
556 parentPoint.x()-(wgap/2)+3, childPoint.y());
557 }
558 else // go below myself
559 {
560 if (parentRow == childRow) // go up
561 {
562 a.putPoints(3, 6,
563 parentPoint.x()-(wgap/2), parentBottom+hgap/2-3,
564 parentPoint.x()-(wgap/2)+3, parentBottom+hgap/2,
565 childPoint.x()-(wgap/2)-3, parentBottom+hgap/2,
566 childPoint.x()-(wgap/2), parentBottom+hgap/2-3,
567 childPoint.x()-(wgap/2), childPoint.y()+3,
568 childPoint.x()-(wgap/2)+3, childPoint.y());
569 }
570 else // go down
571 {
572 a.putPoints(3, 6,
573 parentPoint.x()-(wgap/2), childTop-(hgap/2)-3,
574 parentPoint.x()-(wgap/2)+3, childTop-hgap/2,
575 childPoint.x()-(wgap/2)-3, childTop-hgap/2,
576 childPoint.x()-(wgap/2), childTop-(hgap/2)+3,
577 childPoint.x()-(wgap/2), childPoint.y()-3,
578 childPoint.x()-(wgap/2)+3, childPoint.y());
579 }
580 }
581 }
582 a.putPoints(a.size(), 1, childPoint.x(), childPoint.y());
583 setPoints(a);
584}
585
586void PertRelationItem::drawShape(TQPainter &p)
587{
588 //kdDebug()<<k_funcinfo<<" "<<m_rel->parent()->name()<<" to "<<m_rel->child()->name()<<endl;
589 // cannot use polygon's drawShape() as it doesn't use the pen
590 setBrush(TQt::NoBrush);
591 TQPointArray a = poly;
592 int size = a.size()-1;
593 for(int i = 0; i < size; ++i)
594 {
595 //kdDebug()<<k_funcinfo<<" draw["<<i<<"]: "<<a[i].x()<<","<<a[i].y()<<" to "<<a[i+1].x()<<","<<a[i+1].y()<<endl;
596 p.drawLine(a[i], a[i+1]);
597 }
598 // Draw arrow
599 int pos = a.size()-1;
600 int xoffset = -3;
601 if ( pos > 1&& a[pos-1].x() > a[pos].x())
602 xoffset = 3;
603 TQPoint pnt(a[pos].x()+xoffset, a[pos].y()-3);
604 p.drawLine(a[pos], pnt);
605 pnt.setY(a[pos].y()+3);
606 p.drawLine(a[pos], pnt);
607}
608
609TQPointArray PertRelationItem::areaPoints () const
610{
611 TQPointArray pa(4);
612 int pw = (pen().width()+1)/2;
613 if ( pw < 1 ) pw = 1;
614 if ( pen() == TQt::NoPen ) pw = 0;
615 pa[0] = TQPoint(left-pw,top-pw);
616 pa[1] = pa[0] + TQPoint(right-left+pw*2,0);
617 pa[2] = pa[1] + TQPoint(0,bottom-top+pw*2);
618 pa[3] = pa[0] + TQPoint(0,bottom-top+pw*2);
619/* kdDebug()<<k_funcinfo<<" areaPoints: "<<m_rel->parent()->name()<<" to "<<m_rel->child()->name()<<endl;
620 kdDebug()<<" "<<pa[0].x()<<","<<pa[0].y()<<" "<<pa[1].x()<<","<<pa[1].y()<<endl;
621 kdDebug()<<" "<<pa[2].x()<<","<<pa[2].y()<<" "<<pa[3].x()<<","<<pa[3].y()<<endl;*/
622 return pa;
623}
624
625bool PertRelationItem::rowFree(int row, int startCol, int endCol)
626{
627 TQCanvasItemList list = canvas()->allItems();
628 TQCanvasItemList::Iterator it = list.begin();
629 for (; it != list.end(); ++it)
630 {
631 if ( (*it)->rtti() == PertProjectItem::RTTI ||
632 (*it)->rtti() == PertTaskItem::RTTI ||
633 (*it)->rtti() == PertMilestoneItem::RTTI )
634 {
635 PertNodeItem *item = (PertNodeItem *)(*it);
636 if ( item->row() == row )
637 {
638 int col = item->column();
639 if (col >= startCol && col <= endCol)
640 {
641 //kdDebug()<<k_funcinfo<<"Hit on row,col="<<row<<","<<col<<endl;
642 return false;
643 }
644 }
645 }
646 }
647 return true;
648}
649
650#ifndef NDEBUG
651void PertRelationItem::printDebug( int /*info*/ )
652{
653}
654#endif
655
657KDGanttViewTaskLink::LinkType ItemBase::kdLinkType(int relationType) {
658 switch (relationType) {
659 case Relation::FinishStart:
660 return KDGanttViewTaskLink::FinishStart;
661 break;
662 case Relation::FinishFinish:
663 return KDGanttViewTaskLink::FinishFinish;
664 break;
665 case Relation::StartStart:
666 return KDGanttViewTaskLink::StartStart;
667 break;
668 default:
669 break;
670 }
671 return KDGanttViewTaskLink::None;
672}
673
675
676
677GanttViewSummaryItem::GanttViewSummaryItem(KDGanttView *parent, Node *node)
678 : KDGanttViewSummaryItem(parent, node->name()),
679 m_node(node),
680 m_view(parent)
681{
682 setExpandable(true);
683 setOpen(true);
684}
685
686GanttViewSummaryItem::GanttViewSummaryItem(KDGanttViewItem *parent, Node *node)
687 : KDGanttViewSummaryItem(parent, node->name()),
688 m_node(node),
689 m_view(0)
690{
691 m_drawn = false;
692 GanttViewSummaryItem *p = dynamic_cast<GanttViewSummaryItem*>(parent);
693 if (p)
694 m_view = p->ganttView();
695 setExpandable(true);
696 setOpen(true);
697}
698
699void GanttViewSummaryItem::insertRelations(GanttView *view)
700{
701 //kdDebug()<<k_funcinfo<<endl;
702
703 TQPtrListIterator<Relation> it(m_node->dependChildNodes());
704 for (; it.current(); ++it)
705 {
706 KDGanttViewItem *child = find(m_view->firstChild(), it.current()->child());
707 if (child)
708 {
709 KDGanttViewTaskLink *link = new KDGanttViewTaskLink(this, child, kdLinkType(it.current()->type()));
710 //TODO i18n
711 TQString t = i18n("From: %1").arg(this->listViewText(0));
712 t += "\n" + i18n("To: %1").arg(child->listViewText(0));
713 if (it.current()->lag() > Duration::zeroDuration) {
714 t += "\n" + i18n("Lag: %1").arg(it.current()->lag().toString(Duration::Format_i18nDayTime));
715 }
716 link->setTooltipText(t);
717 view->addTaskLink(link);
718 }
719 }
720}
721
722KDGanttViewItem *GanttViewSummaryItem::find(Node *node)
723{
724 //kdDebug()<<k_funcinfo<<endl;
725 if (m_node == node)
726 return this;
727
728 KDGanttViewItem *item = find(firstChild(), node);
729 if (item)
730 return item;
731
732 return find(nextSibling(), node);
733}
734
735
736KDGanttViewItem *GanttViewSummaryItem::find(KDGanttViewItem *item, Node *node)
737{
738 if (!item)
739 return 0;
740
741 if (item->type() == Event)
742 {
743 GanttViewEventItem *i = static_cast<GanttViewEventItem *>(item);
744 return i->find(node);
745 }
746 else if (item->type() == Task)
747 {
748 GanttViewTaskItem *i = static_cast<GanttViewTaskItem *>(item);
749 return i->find(node);
750 }
751 else if (item->type() == Summary)
752 {
753 GanttViewSummaryItem *i = static_cast<GanttViewSummaryItem *>(item);
754 return i->find(node);
755 }
756 return 0;
757}
758
760
761
762GanttViewTaskItem::GanttViewTaskItem(KDGanttView *parent, KPlato::Task *task)
763 : KDGanttViewTaskItem(parent, task->name()),
764 m_task(task),
765 m_view(parent)
766{
767}
768
769GanttViewTaskItem::GanttViewTaskItem(KDGanttViewItem *parent, KPlato::Task *task)
770 : KDGanttViewTaskItem(parent, task->name()),
771 m_task(task),
772 m_view()
773{
774 m_drawn = false;
775 GanttViewSummaryItem *p = dynamic_cast<GanttViewSummaryItem*>(parent);
776 if (p)
777 m_view = p->ganttView();
778}
779
780void GanttViewTaskItem::insertRelations(GanttView *view)
781{
782 //kdDebug()<<k_funcinfo<<endl;
783
784 TQPtrListIterator<Relation> it(m_task->dependChildNodes());
785 for (; it.current(); ++it)
786 {
787 KDGanttViewItem *child = find(m_view->firstChild(), it.current()->child());
788 if (child)
789 {
790 KDGanttViewTaskLink *link = new KDGanttViewTaskLink(this, child, kdLinkType(it.current()->type()));
791 //TODO i18n
792 TQString t = i18n("From: %1").arg(this->listViewText(0));
793 t += "\n" + i18n("To: %1").arg(child->listViewText(0));
794 if (it.current()->lag() > Duration::zeroDuration) {
795 t += "\n" + i18n("Lag: %1").arg(it.current()->lag().toString(Duration::Format_i18nDayTime));
796 }
797 link->setTooltipText(t);
798 view->addTaskLink(link);
799 }
800 }
801}
802
803KDGanttViewItem *GanttViewTaskItem::find(Node *node)
804{
805 //kdDebug()<<k_funcinfo<<endl;
806 if (m_task == node)
807 return this;
808
809 KDGanttViewItem *item = find(firstChild(), node);
810 if (item)
811 return item;
812
813 return find(nextSibling(), node);
814}
815
816
817KDGanttViewItem *GanttViewTaskItem::find(KDGanttViewItem *item, Node *node)
818{
819 if (!item)
820 return 0;
821
822 if (item->type() == Event)
823 {
824 GanttViewEventItem *i = static_cast<GanttViewEventItem *>(item);
825 return i->find(node);
826 }
827 else if (item->type() == Task)
828 {
829 GanttViewTaskItem *i= static_cast<GanttViewTaskItem *>(item);
830 return i->find(node);
831 }
832 else if (item->type() == Summary)
833 {
834 GanttViewSummaryItem *i = static_cast<GanttViewSummaryItem *>(item);
835 return i->find(node);
836 }
837 return 0; // avoid warning
838}
839
841
842
843GanttViewEventItem::GanttViewEventItem(KDGanttView *parent, KPlato::Task *task)
844 : KDGanttViewEventItem(parent, task->name()),
845 m_task(task),
846 m_view(parent)
847{
848}
849
850GanttViewEventItem::GanttViewEventItem(KDGanttViewItem *parent, KPlato::Task *task)
851 : KDGanttViewEventItem(parent, task->name()),
852 m_task(task),
853 m_view()
854{
855 m_drawn = false;
856 GanttViewSummaryItem *p = dynamic_cast<GanttViewSummaryItem*>(parent);
857 if (p)
858 m_view = p->ganttView();
859}
860
861
862void GanttViewEventItem::insertRelations(GanttView *view)
863{
864 //kdDebug()<<k_funcinfo<<endl;
865
866 TQPtrListIterator<Relation> it(m_task->dependChildNodes());
867 for (; it.current(); ++it)
868 {
869 KDGanttViewItem *child = find(m_view->firstChild(), it.current()->child());
870 if (child)
871 {
872 KDGanttViewTaskLink *link = new KDGanttViewTaskLink(this, child, kdLinkType(it.current()->type()));
873
874 TQString t = i18n("From: %1").arg(this->listViewText(0));
875 t += "\n" + i18n("To: %1").arg(child->listViewText(0));
876 if (it.current()->lag() > Duration::zeroDuration) {
877 t += "\n" + i18n("Lag: %1").arg(it.current()->lag().toString(Duration::Format_i18nDayTime));
878 }
879 link->setTooltipText(t);
880 view->addTaskLink(link);
881 }
882 }
883}
884
885KDGanttViewItem *GanttViewEventItem::find(Node *node)
886{
887 //kdDebug()<<k_funcinfo<<endl;
888 if (m_task == node)
889 return this;
890
891 KDGanttViewItem *item = find(firstChild(), node);
892 if (item)
893 return item;
894
895 return find(nextSibling(), node);
896}
897
898
899KDGanttViewItem *GanttViewEventItem::find(KDGanttViewItem *item, Node *node)
900{
901 if (!item)
902 return 0;
903
904 if (item->type() == Event)
905 {
906 GanttViewEventItem *i = static_cast<GanttViewEventItem *>(item);
907 return i->find(node);
908 }
909 else if (item->type() == Task)
910 {
911 GanttViewTaskItem *i = static_cast<GanttViewTaskItem *>(item);
912 return i->find(node);
913 }
914 else if (item->type() == Summary)
915 {
916 GanttViewSummaryItem *i = static_cast<GanttViewSummaryItem *>(item);
917 return i->find(node);
918 }
919 return 0;
920}
921
922} //KPlato namespace
A task in the scheduling software is represented by this class.
Definition kpttask.h:40