You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
923 lines
27 KiB
923 lines
27 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2003 - 2004 Dag Andersen <danders@get2net.dk>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation;
|
||
|
version 2 of the License.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kpttask.h"
|
||
|
#include "kptcanvasitem.h"
|
||
|
#include "kptrelation.h"
|
||
|
#include "kptpertcanvas.h"
|
||
|
#include "kptganttview.h"
|
||
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
14 years ago
|
#include <tqpainter.h>
|
||
|
#include <tqpointarray.h>
|
||
|
#include <tqptrlist.h>
|
||
|
#include <tqpoint.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
namespace KPlato
|
||
|
{
|
||
|
|
||
|
PertNodeItem::PertNodeItem( PertCanvas *view, Node &node, int row, int col )
|
||
14 years ago
|
: TQCanvasPolygon(view->canvas()),
|
||
15 years ago
|
m_node(node),
|
||
|
m_row(row),
|
||
|
m_col(col)
|
||
|
{
|
||
|
m_x = m_y = 0;
|
||
|
m_wgap = view->verticalGap();
|
||
|
m_hgap = view->horizontalGap();
|
||
|
m_width = view->itemSize().width();
|
||
|
m_height = view->itemSize().height();
|
||
|
|
||
14 years ago
|
m_name = new TQCanvasText(node.name(), view->canvas());
|
||
15 years ago
|
m_childRelations.setAutoDelete(true);
|
||
|
}
|
||
|
|
||
|
PertNodeItem::~PertNodeItem()
|
||
|
{
|
||
14 years ago
|
TQCanvasItemList list = canvas()->allItems();
|
||
|
TQCanvasItemList::Iterator it = list.begin();
|
||
15 years ago
|
for (; it != list.end(); ++it)
|
||
|
{
|
||
|
if ( *it == m_name )
|
||
|
m_name->hide();
|
||
|
if ( *it == m_leader )
|
||
|
m_leader->hide();
|
||
|
}
|
||
|
hide();
|
||
|
}
|
||
|
|
||
|
int PertNodeItem::rtti() const { return RTTI; }
|
||
|
int PertNodeItem::RTTI = 2000;
|
||
|
|
||
|
void PertNodeItem::setVisible(bool yes)
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<m_node.name()<<endl;
|
||
13 years ago
|
TQCanvasPolygon::setVisible(yes);
|
||
14 years ago
|
TQCanvasItemList list = canvas()->allItems();
|
||
|
TQCanvasItemList::Iterator it = list.begin();
|
||
15 years ago
|
for (; it != list.end(); ++it)
|
||
|
{
|
||
|
if ( *it == m_name )
|
||
13 years ago
|
m_name->setVisible(yes);
|
||
15 years ago
|
if ( *it == m_leader )
|
||
13 years ago
|
m_leader->setVisible(yes);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void PertNodeItem::move(PertCanvas *view, int row, int col)
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
m_row = row; m_col = col;
|
||
|
view->mapNode(this);
|
||
|
|
||
13 years ago
|
// Now map my children
|
||
14 years ago
|
TQPtrListIterator<PertNodeRelation> it(m_childRelations);
|
||
15 years ago
|
for (; it.current(); ++it)
|
||
|
{
|
||
|
view->mapChildNode(this, it.current()->childItem, it.current()->relation->type());
|
||
|
}
|
||
|
|
||
|
// now move the item on the canvas
|
||
|
m_x = x(col); m_y = y(row);
|
||
14 years ago
|
m_left = TQPoint(m_x, m_y + m_height/2);
|
||
|
m_right = TQPoint(m_x + m_width, m_y + m_height/2);
|
||
|
TQCanvasPolygon::move(m_x, m_y);
|
||
15 years ago
|
if (m_name)
|
||
|
m_name->move(m_x+5, m_y+2);
|
||
|
|
||
|
setVisible(true);
|
||
|
//kdDebug()<<k_funcinfo<<m_node.name()<<" moved to row,col=("<<m_row<<","<<m_col<<")"<<endl;
|
||
|
}
|
||
|
|
||
14 years ago
|
void PertNodeItem::drawShape(TQPainter &p)
|
||
15 years ago
|
{
|
||
14 years ago
|
//TQPen pen(pen());
|
||
15 years ago
|
if (isSelected())
|
||
14 years ago
|
p.setPen(TQPen(TQt::red, 2));
|
||
|
TQPointArray a = poly;
|
||
15 years ago
|
int size = a.size()-1;
|
||
|
for(int i = 0; i < size; ++i)
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<" draw["<<i<<"]: "<<a[i].x()<<","<<a[i].y()<<" to "<<a[i+1].x()<<","<<a[i+1].y()<<endl;
|
||
|
p.drawLine(a[i], a[i+1]);
|
||
|
}
|
||
|
//setPen(pen);
|
||
|
}
|
||
|
|
||
14 years ago
|
TQPoint PertNodeItem::exitPoint(Relation::Type type) const
|
||
15 years ago
|
{
|
||
14 years ago
|
TQPoint ret;
|
||
15 years ago
|
switch(type)
|
||
|
{
|
||
|
case Relation::FinishStart:
|
||
|
case Relation::FinishFinish:
|
||
14 years ago
|
ret = m_right + TQPoint(pen().width(), 0);
|
||
15 years ago
|
break;
|
||
|
case Relation::StartStart:
|
||
14 years ago
|
ret = m_left + TQPoint(0, 4);
|
||
15 years ago
|
break;
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQPoint PertNodeItem::entryPoint(Relation::Type type) const
|
||
15 years ago
|
{
|
||
14 years ago
|
TQPoint ret;
|
||
15 years ago
|
switch(type)
|
||
|
{
|
||
|
case Relation::FinishStart:
|
||
14 years ago
|
ret = m_left - TQPoint(pen().width(), 0);
|
||
15 years ago
|
break;
|
||
|
case Relation::FinishFinish:
|
||
14 years ago
|
ret = m_right - TQPoint(pen().width(), 4);
|
||
15 years ago
|
break;
|
||
|
case Relation::StartStart:
|
||
14 years ago
|
ret = m_left - TQPoint(pen().width(), 0);
|
||
15 years ago
|
break;
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
#ifndef NDEBUG
|
||
|
void PertNodeItem::printDebug( int /*info*/ )
|
||
|
{
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
//////////////////// PertProjectItem //////////////////////////
|
||
|
|
||
|
PertProjectItem::PertProjectItem(PertCanvas *view, Node &node, int row, int col)
|
||
|
: PertNodeItem(view, node, row, col)
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<"Node="<<node.name()<<" ("<<row<<","<<col<<")"<<endl;
|
||
|
|
||
14 years ago
|
TQPointArray a;
|
||
15 years ago
|
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);
|
||
|
setPoints(a);
|
||
|
|
||
14 years ago
|
setPen(TQPen(TQt::cyan, 2));
|
||
15 years ago
|
}
|
||
|
|
||
|
PertProjectItem::~PertProjectItem()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
int PertProjectItem::rtti() const { return RTTI; }
|
||
|
int PertProjectItem::RTTI = 2001;
|
||
|
|
||
|
#ifndef NDEBUG
|
||
|
void PertProjectItem::printDebug( int /*info*/ )
|
||
|
{
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
|
||
|
//////////////////// PertTaskItem //////////////////////////
|
||
|
|
||
|
PertTaskItem::PertTaskItem(PertCanvas *view, Node &node, int row, int col)
|
||
|
: PertNodeItem(view, node, row, col)
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<"Node="<<node.name()<<" ("<<row<<","<<col<<")"<<endl;
|
||
14 years ago
|
TQPointArray a;
|
||
15 years ago
|
if (node.type() == Node::Type_Summarytask)
|
||
|
{
|
||
|
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);
|
||
14 years ago
|
setPen(TQPen(TQt::cyan, 2));
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
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);
|
||
14 years ago
|
setPen(TQPen(TQt::green, 2));
|
||
15 years ago
|
}
|
||
|
setPoints(a);
|
||
|
|
||
|
}
|
||
|
|
||
|
PertTaskItem::~PertTaskItem()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
int PertTaskItem::rtti() const { return RTTI; }
|
||
|
int PertTaskItem::RTTI = 2002;
|
||
|
|
||
|
|
||
|
#ifndef NDEBUG
|
||
|
void PertTaskItem::printDebug( int /*info*/ )
|
||
|
{
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
|
||
|
//////////////////// PertMilestoneItem //////////////////////////
|
||
|
|
||
|
PertMilestoneItem::PertMilestoneItem(PertCanvas *view, Node &node, int row, int col)
|
||
|
: PertNodeItem(view, node, row, col)
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<"Node="<<node.name()<<" ("<<row<<","<<col<<")"<<endl;
|
||
|
|
||
14 years ago
|
TQPointArray a;
|
||
15 years ago
|
a.putPoints(0, 7,
|
||
|
m_x, m_y+m_height/2,
|
||
|
m_x+6, m_y,
|
||
|
m_x+m_width-6, m_y,
|
||
|
m_x+m_width, m_y+m_height/2,
|
||
|
m_x+m_width-6, m_y+m_height,
|
||
|
m_x+6, m_y+m_height,
|
||
|
m_x, m_y+m_height/2);
|
||
|
|
||
|
setPoints(a);
|
||
|
|
||
14 years ago
|
setPen(TQPen(TQt::blue, 2));
|
||
15 years ago
|
}
|
||
|
|
||
|
PertMilestoneItem::~PertMilestoneItem()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
int PertMilestoneItem::rtti() const { return RTTI; }
|
||
|
int PertMilestoneItem::RTTI = 2003;
|
||
|
|
||
|
#ifndef NDEBUG
|
||
|
void PertMilestoneItem::printDebug( int /*info*/ )
|
||
|
{
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
|
||
|
//////////////////// PertRelationItem //////////////////////////
|
||
|
|
||
13 years ago
|
PertRelationItem::PertRelationItem( PertCanvas *view, PertNodeItem *parent, PertNodeItem *child, Relation *rel)
|
||
14 years ago
|
: TQCanvasPolygon(view->canvas()),
|
||
15 years ago
|
m_view(view),
|
||
|
m_rel(rel),
|
||
13 years ago
|
m_parentItem(parent),
|
||
15 years ago
|
m_childItem(child)
|
||
|
{
|
||
13 years ago
|
//kdDebug()<<k_funcinfo<<"Parent="<<parent->node().name()<<" Child="<<child->node().name()<<endl;
|
||
15 years ago
|
draw();
|
||
13 years ago
|
setVisible(true);
|
||
15 years ago
|
}
|
||
|
|
||
|
PertRelationItem::~PertRelationItem()
|
||
|
{
|
||
|
hide();
|
||
|
}
|
||
|
|
||
|
int PertRelationItem::rtti() const { return RTTI; }
|
||
|
int PertRelationItem::RTTI = 2020;
|
||
|
|
||
|
void PertRelationItem::draw()
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
// Some "rules":
|
||
13 years ago
|
// a) Relation::FinishStart: child column > parent column
|
||
|
// b) Relation::FinishFinish: child column >= parent column
|
||
|
// c) Relation::StartStart: child column >= parent column
|
||
|
// d) Child row can be >= parent row
|
||
15 years ago
|
|
||
|
wgap = m_view->verticalGap();
|
||
|
hgap = m_view->horizontalGap();
|
||
|
|
||
|
// could not use ...rect() here, don't know why
|
||
14 years ago
|
parentTop = (int)(m_parentItem->y());
|
||
|
parentBottom = parentTop + (int)(m_parentItem->height());
|
||
15 years ago
|
childTop = (int)(m_childItem->y());
|
||
|
|
||
|
childRow = m_childItem->row();
|
||
|
childCol = m_childItem->column();
|
||
14 years ago
|
parentRow = m_parentItem->row();
|
||
|
parentCol = m_parentItem->column();
|
||
|
//kdDebug()<<k_funcinfo<<"Parent="<<m_parentItem->node().name()<<" ("<<parentRow<<","<<parentCol<<") Child="<<m_childItem->node().name()<<" ("<<childRow<<","<<childCol<<")"<<endl;
|
||
15 years ago
|
|
||
|
switch (type())
|
||
|
{
|
||
|
case Relation::FinishStart:
|
||
|
setFinishStartPoints();
|
||
|
break;
|
||
|
case Relation::FinishFinish:
|
||
|
setFinishFinishPoints();
|
||
|
break;
|
||
|
case Relation::StartStart:
|
||
|
setStartStartPoints();
|
||
|
break;
|
||
|
}
|
||
14 years ago
|
TQPointArray a = poly;
|
||
15 years ago
|
left = right = a[0].x();
|
||
|
top = bottom = a[0].y();
|
||
|
for (uint i = 0; i < a.size(); i++)
|
||
|
{
|
||
14 years ago
|
left = TQMIN(a[i].x(), left);
|
||
|
top = TQMIN(a[i].y(), top);
|
||
|
right = TQMAX(a[i].x(), right);
|
||
|
bottom = TQMAX(a[i].y(), bottom);
|
||
15 years ago
|
}
|
||
|
top -= 3;
|
||
|
bottom += 3;
|
||
|
|
||
14 years ago
|
setPen(TQt::black);
|
||
15 years ago
|
setZ(45);
|
||
|
|
||
|
/*#ifndef NDEBUG
|
||
13 years ago
|
kdDebug()<<" PertNodeRelation from parent: "<<m_rel->parent()->name()<<" to child: "<<m_rel->child()->name()<<endl;
|
||
14 years ago
|
TQPointArray pa = poly;
|
||
15 years ago
|
for (int i = 0; i < pa.size(); ++i)
|
||
|
kdDebug()<<" pa["<<i<<"]="<<pa[i].x()<<","<<pa[i].y()<<endl;
|
||
|
#endif*/
|
||
|
|
||
|
}
|
||
|
|
||
|
void PertRelationItem::setFinishStartPoints()
|
||
|
{
|
||
14 years ago
|
TQPoint parentPoint = m_parentItem->exitPoint(Relation::FinishStart);
|
||
14 years ago
|
TQPoint childPoint = m_childItem->entryPoint(Relation::FinishStart);
|
||
15 years ago
|
|
||
14 years ago
|
TQPointArray a;
|
||
14 years ago
|
a.putPoints(0, 1, parentPoint.x(), parentPoint.y());
|
||
15 years ago
|
|
||
14 years ago
|
if ( parentRow == childRow )
|
||
15 years ago
|
{
|
||
14 years ago
|
if (parentCol == childCol - 1 || rowFree(parentRow, parentCol+1, childCol-1))
|
||
15 years ago
|
{
|
||
|
a.putPoints(1, 1, childPoint.x(), childPoint.y());
|
||
|
}
|
||
|
else // go around below
|
||
|
{
|
||
|
a.putPoints(1, 9,
|
||
14 years ago
|
parentPoint.x()+(wgap/2)-3, parentPoint.y(), // stop short
|
||
|
parentPoint.x()+(wgap/2), parentPoint.y()+3, // right/down
|
||
|
parentPoint.x()+(wgap/2), parentBottom+(hgap/2)-3, // stop short
|
||
|
parentPoint.x()+(wgap/2)+3, parentBottom+(hgap/2), // right/down
|
||
|
childPoint.x()-(wgap/2)-3, parentBottom+(hgap/2), // stop short
|
||
|
childPoint.x()-(wgap/2), parentBottom+(hgap/2)-3, // right/up
|
||
15 years ago
|
childPoint.x()-(wgap/2), childPoint.y()+3, // stop short
|
||
|
childPoint.x()-(wgap/2)+3, childPoint.y(), // right/up
|
||
|
childPoint.x(), childPoint.y());
|
||
|
}
|
||
|
}
|
||
14 years ago
|
else if ( parentRow > childRow )
|
||
15 years ago
|
{
|
||
14 years ago
|
if (parentCol == childCol - 1)
|
||
15 years ago
|
{
|
||
|
a.putPoints(1, 5,
|
||
14 years ago
|
parentPoint.x()+(wgap/2)-3, parentPoint.y(),
|
||
|
parentPoint.x()+(wgap/2), parentPoint.y()-3,
|
||
|
parentPoint.x()+wgap/2, childPoint.y()+3,
|
||
|
parentPoint.x()+(wgap/2)+3, childPoint.y(),
|
||
15 years ago
|
childPoint.x(), childPoint.y());
|
||
|
}
|
||
|
else // go around above
|
||
|
{
|
||
|
a.putPoints(1, 9,
|
||
14 years ago
|
parentPoint.x()+(wgap/2)-3, parentPoint.y(),
|
||
|
parentPoint.x()+(wgap/2), parentPoint.y()-3,
|
||
|
parentPoint.x()+wgap/2, parentTop-(hgap/2)+3,
|
||
|
parentPoint.x()+(wgap/2)+3, parentTop-(hgap/2),
|
||
|
childPoint.x()-(wgap/2)-3, parentTop-hgap/2,
|
||
|
childPoint.x()-(wgap/2), parentTop-(hgap/2)-3,
|
||
15 years ago
|
childPoint.x()-wgap/2, childPoint.y()+3,
|
||
|
childPoint.x()-(wgap/2)+3, childPoint.y(),
|
||
|
childPoint.x(), childPoint.y());
|
||
|
}
|
||
|
}
|
||
14 years ago
|
else if ( parentRow < childRow )
|
||
15 years ago
|
{
|
||
14 years ago
|
if (parentCol == childCol - 1)
|
||
15 years ago
|
{
|
||
|
a.putPoints(1, 5,
|
||
14 years ago
|
parentPoint.x()+(wgap/2)-3, parentPoint.y(),
|
||
|
parentPoint.x()+(wgap/2), parentPoint.y()+3,
|
||
|
parentPoint.x()+wgap/2, childPoint.y()-3,
|
||
|
parentPoint.x()+(wgap/2)+3, childPoint.y(),
|
||
15 years ago
|
childPoint.x(), childPoint.y());
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
a.putPoints(1, 9,
|
||
14 years ago
|
parentPoint.x()+(wgap/2)-3, parentPoint.y(),
|
||
|
parentPoint.x()+(wgap/2), parentPoint.y()+3,
|
||
|
parentPoint.x()+wgap/2, childTop-(hgap/2)-3,
|
||
|
parentPoint.x()+(wgap/2)+3, childTop-(hgap/2),
|
||
15 years ago
|
childPoint.x()-(wgap/2)-3, childTop-(hgap/2),
|
||
|
childPoint.x()-(wgap/2), childTop-(hgap/2)+3,
|
||
|
childPoint.x()-wgap/2, childPoint.y()-3,
|
||
|
childPoint.x()-wgap/2+3, childPoint.y(),
|
||
|
childPoint.x(), childPoint.y());
|
||
|
}
|
||
|
}
|
||
|
setPoints(a);
|
||
|
}
|
||
|
|
||
|
void PertRelationItem::setFinishFinishPoints()
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
14 years ago
|
TQPoint parentPoint = m_parentItem->exitPoint(Relation::FinishFinish);
|
||
14 years ago
|
TQPoint childPoint = m_childItem->entryPoint(Relation::FinishFinish);
|
||
15 years ago
|
|
||
14 years ago
|
TQPointArray a;
|
||
14 years ago
|
a.putPoints(0, 1, parentPoint.x(), parentPoint.y());
|
||
15 years ago
|
|
||
|
|
||
14 years ago
|
if ( parentRow >= childRow )
|
||
15 years ago
|
{
|
||
14 years ago
|
if (parentCol == childCol)
|
||
15 years ago
|
{
|
||
|
a.putPoints(1, 5,
|
||
14 years ago
|
childPoint.x()+(wgap/2)-3, parentPoint.y(),
|
||
|
childPoint.x()+(wgap/2), parentPoint.y()-3,
|
||
15 years ago
|
childPoint.x()+wgap/2, childPoint.y()+3,
|
||
|
childPoint.x()+(wgap/2)-3, childPoint.y(),
|
||
|
childPoint.x(), childPoint.y());
|
||
|
}
|
||
14 years ago
|
else if (parentCol < childCol)
|
||
15 years ago
|
{
|
||
|
a.putPoints(1, 9,
|
||
14 years ago
|
parentPoint.x()+(wgap/2)-3, parentPoint.y(), // stop short
|
||
|
parentPoint.x()+(wgap/2), parentPoint.y()+3, // right/down
|
||
|
parentPoint.x()+(wgap/2), parentBottom+(hgap/2)-3, // stop short
|
||
|
parentPoint.x()+(wgap/2)+3, parentBottom+(hgap/2), // right/down
|
||
|
childPoint.x()+(wgap/2)-3, parentBottom+(hgap/2), // stop short
|
||
|
childPoint.x()+(wgap/2), parentBottom+(hgap/2)-3, // right/up
|
||
15 years ago
|
childPoint.x()+(wgap/2), childPoint.y()+3, // stop short
|
||
|
childPoint.x()+(wgap/2)-3, childPoint.y(), // left/up
|
||
|
childPoint.x(), childPoint.y());
|
||
|
}
|
||
|
}
|
||
14 years ago
|
else // parentRow < choldRow
|
||
15 years ago
|
{
|
||
14 years ago
|
if (parentCol == childCol)
|
||
15 years ago
|
{
|
||
|
a.putPoints(1, 5,
|
||
14 years ago
|
parentPoint.x()+(wgap/2)-3, parentPoint.y(),
|
||
|
parentPoint.x()+(wgap/2), parentPoint.y()+3,
|
||
|
parentPoint.x()+wgap/2, childPoint.y()-3,
|
||
|
parentPoint.x()+(wgap/2)-3, childPoint.y(),
|
||
15 years ago
|
childPoint.x(), childPoint.y());
|
||
|
}
|
||
14 years ago
|
else if (parentCol < childCol)
|
||
15 years ago
|
{
|
||
14 years ago
|
if (rowFree(parentRow, parentCol+1, childCol))
|
||
15 years ago
|
a.putPoints(1, 5,
|
||
14 years ago
|
childPoint.x()+(wgap/2)-3, parentPoint.y(),
|
||
|
childPoint.x()+(wgap/2), parentPoint.y()+3,
|
||
15 years ago
|
childPoint.x()+(wgap/2), childPoint.y()-3,
|
||
|
childPoint.x()+(wgap/2)-3, childPoint.y(),
|
||
|
childPoint.x(), childPoint.y());
|
||
|
else
|
||
|
a.putPoints(1, 9,
|
||
14 years ago
|
parentPoint.x()+(wgap/2)-3, parentPoint.y(),
|
||
|
parentPoint.x()+(wgap/2), parentPoint.y()+3,
|
||
|
parentPoint.x()+wgap/2, childTop-(hgap/2)-3,
|
||
|
parentPoint.x()+(wgap/2)+3, childTop-(hgap/2),
|
||
15 years ago
|
childPoint.x()+(wgap/2)-3, childTop-(hgap/2),
|
||
|
childPoint.x()+(wgap/2), childTop-(hgap/2)+3,
|
||
|
childPoint.x()+(wgap/2), childPoint.y()-3,
|
||
|
childPoint.x()+(wgap/2)-3, childPoint.y(),
|
||
|
childPoint.x(), childPoint.y());
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
a.putPoints(1, 9,
|
||
14 years ago
|
parentPoint.x()+(wgap/2)-3, parentPoint.y(),
|
||
|
parentPoint.x()+(wgap/2), parentPoint.y()+3,
|
||
|
parentPoint.x()+wgap/2, childTop-(hgap/2)-3,
|
||
|
parentPoint.x()+(wgap/2)+3, childTop-(hgap/2),
|
||
15 years ago
|
childPoint.x()+(wgap/2)-3, childTop-(hgap/2),
|
||
|
childPoint.x()+(wgap/2), childTop-(hgap/2)+3,
|
||
|
childPoint.x()+wgap/2, childPoint.y()-3,
|
||
|
childPoint.x()+wgap/2-3, childPoint.y(),
|
||
|
childPoint.x(), childPoint.y());
|
||
|
}
|
||
|
}
|
||
|
setPoints(a);
|
||
|
}
|
||
|
|
||
|
void PertRelationItem::setStartStartPoints()
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
14 years ago
|
TQPoint parentPoint = m_parentItem->exitPoint(Relation::StartStart);
|
||
14 years ago
|
TQPoint childPoint = m_childItem->entryPoint(Relation::StartStart);
|
||
15 years ago
|
|
||
14 years ago
|
TQPointArray a;
|
||
14 years ago
|
a.putPoints(0, 1, parentPoint.x(), parentPoint.y());
|
||
15 years ago
|
|
||
14 years ago
|
if ( parentRow > childRow )
|
||
15 years ago
|
{
|
||
14 years ago
|
if (parentCol == childCol) // go up
|
||
15 years ago
|
{
|
||
|
a.putPoints(1, 4,
|
||
14 years ago
|
parentPoint.x()-(wgap/2)+3, parentPoint.y(),
|
||
|
parentPoint.x()-(wgap/2), parentPoint.y()-3,
|
||
|
parentPoint.x()-(wgap/2), childPoint.y()+3,
|
||
|
parentPoint.x()-(wgap/2)+3, childPoint.y());
|
||
15 years ago
|
}
|
||
|
else // go above myself
|
||
|
{
|
||
|
a.putPoints(1, 8,
|
||
14 years ago
|
parentPoint.x()-(wgap/2)+3, parentPoint.y(),
|
||
|
parentPoint.x()-(wgap/2), parentPoint.y()-3,
|
||
|
parentPoint.x()-(wgap/2), parentTop-(hgap/2)+3,
|
||
|
parentPoint.x()-(wgap/2)+3, parentTop-(hgap/2),
|
||
|
childPoint.x()-(wgap/2)-3, parentTop-(hgap/2),
|
||
|
childPoint.x()-(wgap/2), parentTop-(hgap/2)-3,
|
||
15 years ago
|
childPoint.x()-(wgap/2), childPoint.y()+3,
|
||
|
childPoint.x()-(wgap/2)+3, childPoint.y());
|
||
|
}
|
||
|
}
|
||
|
else // go left/down
|
||
|
{
|
||
|
a.putPoints(1, 2,
|
||
14 years ago
|
parentPoint.x()-(wgap/2)+3, parentPoint.y(),
|
||
|
parentPoint.x()-(wgap/2), parentPoint.y()+3);
|
||
15 years ago
|
|
||
14 years ago
|
if (parentCol == childCol)
|
||
15 years ago
|
{
|
||
|
a.putPoints(3, 2,
|
||
14 years ago
|
parentPoint.x()-(wgap/2), childPoint.y()-3,
|
||
|
parentPoint.x()-(wgap/2)+3, childPoint.y());
|
||
15 years ago
|
}
|
||
|
else // go below myself
|
||
|
{
|
||
14 years ago
|
if (parentRow == childRow) // go up
|
||
15 years ago
|
{
|
||
|
a.putPoints(3, 6,
|
||
14 years ago
|
parentPoint.x()-(wgap/2), parentBottom+hgap/2-3,
|
||
|
parentPoint.x()-(wgap/2)+3, parentBottom+hgap/2,
|
||
|
childPoint.x()-(wgap/2)-3, parentBottom+hgap/2,
|
||
|
childPoint.x()-(wgap/2), parentBottom+hgap/2-3,
|
||
15 years ago
|
childPoint.x()-(wgap/2), childPoint.y()+3,
|
||
|
childPoint.x()-(wgap/2)+3, childPoint.y());
|
||
|
}
|
||
|
else // go down
|
||
|
{
|
||
|
a.putPoints(3, 6,
|
||
14 years ago
|
parentPoint.x()-(wgap/2), childTop-(hgap/2)-3,
|
||
|
parentPoint.x()-(wgap/2)+3, childTop-hgap/2,
|
||
15 years ago
|
childPoint.x()-(wgap/2)-3, childTop-hgap/2,
|
||
|
childPoint.x()-(wgap/2), childTop-(hgap/2)+3,
|
||
|
childPoint.x()-(wgap/2), childPoint.y()-3,
|
||
|
childPoint.x()-(wgap/2)+3, childPoint.y());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
a.putPoints(a.size(), 1, childPoint.x(), childPoint.y());
|
||
|
setPoints(a);
|
||
|
}
|
||
|
|
||
14 years ago
|
void PertRelationItem::drawShape(TQPainter &p)
|
||
15 years ago
|
{
|
||
13 years ago
|
//kdDebug()<<k_funcinfo<<" "<<m_rel->parent()->name()<<" to "<<m_rel->child()->name()<<endl;
|
||
15 years ago
|
// cannot use polygon's drawShape() as it doesn't use the pen
|
||
|
setBrush(Qt::NoBrush);
|
||
14 years ago
|
TQPointArray a = poly;
|
||
15 years ago
|
int size = a.size()-1;
|
||
|
for(int i = 0; i < size; ++i)
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<" draw["<<i<<"]: "<<a[i].x()<<","<<a[i].y()<<" to "<<a[i+1].x()<<","<<a[i+1].y()<<endl;
|
||
|
p.drawLine(a[i], a[i+1]);
|
||
|
}
|
||
|
// Draw arrow
|
||
|
int pos = a.size()-1;
|
||
|
int xoffset = -3;
|
||
|
if ( pos > 1&& a[pos-1].x() > a[pos].x())
|
||
|
xoffset = 3;
|
||
14 years ago
|
TQPoint pnt(a[pos].x()+xoffset, a[pos].y()-3);
|
||
15 years ago
|
p.drawLine(a[pos], pnt);
|
||
|
pnt.setY(a[pos].y()+3);
|
||
|
p.drawLine(a[pos], pnt);
|
||
|
}
|
||
|
|
||
14 years ago
|
TQPointArray PertRelationItem::areaPoints () const
|
||
15 years ago
|
{
|
||
14 years ago
|
TQPointArray pa(4);
|
||
15 years ago
|
int pw = (pen().width()+1)/2;
|
||
|
if ( pw < 1 ) pw = 1;
|
||
14 years ago
|
if ( pen() == Qt::NoPen ) pw = 0;
|
||
|
pa[0] = TQPoint(left-pw,top-pw);
|
||
|
pa[1] = pa[0] + TQPoint(right-left+pw*2,0);
|
||
|
pa[2] = pa[1] + TQPoint(0,bottom-top+pw*2);
|
||
|
pa[3] = pa[0] + TQPoint(0,bottom-top+pw*2);
|
||
13 years ago
|
/* kdDebug()<<k_funcinfo<<" areaPoints: "<<m_rel->parent()->name()<<" to "<<m_rel->child()->name()<<endl;
|
||
15 years ago
|
kdDebug()<<" "<<pa[0].x()<<","<<pa[0].y()<<" "<<pa[1].x()<<","<<pa[1].y()<<endl;
|
||
|
kdDebug()<<" "<<pa[2].x()<<","<<pa[2].y()<<" "<<pa[3].x()<<","<<pa[3].y()<<endl;*/
|
||
|
return pa;
|
||
|
}
|
||
|
|
||
|
bool PertRelationItem::rowFree(int row, int startCol, int endCol)
|
||
|
{
|
||
14 years ago
|
TQCanvasItemList list = canvas()->allItems();
|
||
|
TQCanvasItemList::Iterator it = list.begin();
|
||
15 years ago
|
for (; it != list.end(); ++it)
|
||
|
{
|
||
|
if ( (*it)->rtti() == PertProjectItem::RTTI ||
|
||
|
(*it)->rtti() == PertTaskItem::RTTI ||
|
||
|
(*it)->rtti() == PertMilestoneItem::RTTI )
|
||
|
{
|
||
|
PertNodeItem *item = (PertNodeItem *)(*it);
|
||
|
if ( item->row() == row )
|
||
|
{
|
||
|
int col = item->column();
|
||
|
if (col >= startCol && col <= endCol)
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<"Hit on row,col="<<row<<","<<col<<endl;
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
#ifndef NDEBUG
|
||
|
void PertRelationItem::printDebug( int /*info*/ )
|
||
|
{
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
//////////////////// ItemBase //////////////////////////
|
||
|
KDGanttViewTaskLink::LinkType ItemBase::kdLinkType(int relationType) {
|
||
|
switch (relationType) {
|
||
|
case Relation::FinishStart:
|
||
|
return KDGanttViewTaskLink::FinishStart;
|
||
|
break;
|
||
|
case Relation::FinishFinish:
|
||
|
return KDGanttViewTaskLink::FinishFinish;
|
||
|
break;
|
||
|
case Relation::StartStart:
|
||
|
return KDGanttViewTaskLink::StartStart;
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
return KDGanttViewTaskLink::None;
|
||
|
}
|
||
|
|
||
|
//////////////////// GanttViewSummaryItem //////////////////////////
|
||
|
|
||
|
|
||
13 years ago
|
GanttViewSummaryItem::GanttViewSummaryItem(KDGanttView *parent, Node *node)
|
||
|
: KDGanttViewSummaryItem(parent, node->name()),
|
||
15 years ago
|
m_node(node),
|
||
13 years ago
|
m_view(parent)
|
||
15 years ago
|
{
|
||
|
setExpandable(true);
|
||
|
setOpen(true);
|
||
|
}
|
||
|
|
||
13 years ago
|
GanttViewSummaryItem::GanttViewSummaryItem(KDGanttViewItem *parent, Node *node)
|
||
|
: KDGanttViewSummaryItem(parent, node->name()),
|
||
15 years ago
|
m_node(node),
|
||
|
m_view(0)
|
||
|
{
|
||
|
m_drawn = false;
|
||
13 years ago
|
GanttViewSummaryItem *p = dynamic_cast<GanttViewSummaryItem*>(parent);
|
||
15 years ago
|
if (p)
|
||
|
m_view = p->ganttView();
|
||
|
setExpandable(true);
|
||
|
setOpen(true);
|
||
|
}
|
||
|
|
||
|
void GanttViewSummaryItem::insertRelations(GanttView *view)
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
|
||
14 years ago
|
TQPtrListIterator<Relation> it(m_node->dependChildNodes());
|
||
15 years ago
|
for (; it.current(); ++it)
|
||
|
{
|
||
14 years ago
|
KDGanttViewItem *child = find(m_view->firstChild(), it.current()->child());
|
||
15 years ago
|
if (child)
|
||
|
{
|
||
|
KDGanttViewTaskLink *link = new KDGanttViewTaskLink(this, child, kdLinkType(it.current()->type()));
|
||
|
//TODO i18n
|
||
13 years ago
|
TQString t = i18n("From: %1").arg(this->listViewText(0));
|
||
|
t += "\n" + i18n("To: %1").arg(child->listViewText(0));
|
||
15 years ago
|
if (it.current()->lag() > Duration::zeroDuration) {
|
||
13 years ago
|
t += "\n" + i18n("Lag: %1").arg(it.current()->lag().toString(Duration::Format_i18nDayTime));
|
||
15 years ago
|
}
|
||
|
link->setTooltipText(t);
|
||
|
view->addTaskLink(link);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
KDGanttViewItem *GanttViewSummaryItem::find(Node *node)
|
||
15 years ago
|
{
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
if (m_node == node)
|
||
|
return this;
|
||
|
|
||
14 years ago
|
KDGanttViewItem *item = find(firstChild(), node);
|
||
15 years ago
|
if (item)
|
||
|
return item;
|
||
|
|
||
14 years ago
|
return find(nextSibling(), node);
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
KDGanttViewItem *GanttViewSummaryItem::find(KDGanttViewItem *item, Node *node)
|
||
15 years ago
|
{
|
||
|
if (!item)
|
||
|
return 0;
|
||
|
|
||
|
if (item->type() == Event)
|
||
|
{
|
||
|
GanttViewEventItem *i = static_cast<GanttViewEventItem *>(item);
|
||
14 years ago
|
return i->find(node);
|
||
15 years ago
|
}
|
||
|
else if (item->type() == Task)
|
||
|
{
|
||
|
GanttViewTaskItem *i = static_cast<GanttViewTaskItem *>(item);
|
||
14 years ago
|
return i->find(node);
|
||
15 years ago
|
}
|
||
|
else if (item->type() == Summary)
|
||
|
{
|
||
|
GanttViewSummaryItem *i = static_cast<GanttViewSummaryItem *>(item);
|
||
14 years ago
|
return i->find(node);
|
||
15 years ago
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
//////////////////// GanttViewTaskItem //////////////////////////
|
||
|
|
||
|
|
||
13 years ago
|
GanttViewTaskItem::GanttViewTaskItem(KDGanttView *parent, KPlato::Task *task)
|
||
|
: KDGanttViewTaskItem(parent, task->name()),
|
||
15 years ago
|
m_task(task),
|
||
13 years ago
|
m_view(parent)
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
13 years ago
|
GanttViewTaskItem::GanttViewTaskItem(KDGanttViewItem *parent, KPlato::Task *task)
|
||
|
: KDGanttViewTaskItem(parent, task->name()),
|
||
15 years ago
|
m_task(task),
|
||
|
m_view()
|
||
|
{
|
||
|
m_drawn = false;
|
||
13 years ago
|
GanttViewSummaryItem *p = dynamic_cast<GanttViewSummaryItem*>(parent);
|
||
15 years ago
|
if (p)
|
||
|
m_view = p->ganttView();
|
||
|
}
|
||
|
|
||
|
void GanttViewTaskItem::insertRelations(GanttView *view)
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
|
||
14 years ago
|
TQPtrListIterator<Relation> it(m_task->dependChildNodes());
|
||
15 years ago
|
for (; it.current(); ++it)
|
||
|
{
|
||
14 years ago
|
KDGanttViewItem *child = find(m_view->firstChild(), it.current()->child());
|
||
15 years ago
|
if (child)
|
||
|
{
|
||
|
KDGanttViewTaskLink *link = new KDGanttViewTaskLink(this, child, kdLinkType(it.current()->type()));
|
||
|
//TODO i18n
|
||
13 years ago
|
TQString t = i18n("From: %1").arg(this->listViewText(0));
|
||
|
t += "\n" + i18n("To: %1").arg(child->listViewText(0));
|
||
15 years ago
|
if (it.current()->lag() > Duration::zeroDuration) {
|
||
13 years ago
|
t += "\n" + i18n("Lag: %1").arg(it.current()->lag().toString(Duration::Format_i18nDayTime));
|
||
15 years ago
|
}
|
||
|
link->setTooltipText(t);
|
||
|
view->addTaskLink(link);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
KDGanttViewItem *GanttViewTaskItem::find(Node *node)
|
||
15 years ago
|
{
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
if (m_task == node)
|
||
|
return this;
|
||
|
|
||
14 years ago
|
KDGanttViewItem *item = find(firstChild(), node);
|
||
15 years ago
|
if (item)
|
||
|
return item;
|
||
|
|
||
14 years ago
|
return find(nextSibling(), node);
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
KDGanttViewItem *GanttViewTaskItem::find(KDGanttViewItem *item, Node *node)
|
||
15 years ago
|
{
|
||
|
if (!item)
|
||
|
return 0;
|
||
|
|
||
|
if (item->type() == Event)
|
||
|
{
|
||
|
GanttViewEventItem *i = static_cast<GanttViewEventItem *>(item);
|
||
14 years ago
|
return i->find(node);
|
||
15 years ago
|
}
|
||
|
else if (item->type() == Task)
|
||
|
{
|
||
|
GanttViewTaskItem *i= static_cast<GanttViewTaskItem *>(item);
|
||
14 years ago
|
return i->find(node);
|
||
15 years ago
|
}
|
||
|
else if (item->type() == Summary)
|
||
|
{
|
||
|
GanttViewSummaryItem *i = static_cast<GanttViewSummaryItem *>(item);
|
||
14 years ago
|
return i->find(node);
|
||
15 years ago
|
}
|
||
|
return 0; // avoid warning
|
||
|
}
|
||
|
|
||
|
//////////////////// GanttViewEventItem //////////////////////////
|
||
|
|
||
|
|
||
13 years ago
|
GanttViewEventItem::GanttViewEventItem(KDGanttView *parent, KPlato::Task *task)
|
||
|
: KDGanttViewEventItem(parent, task->name()),
|
||
15 years ago
|
m_task(task),
|
||
13 years ago
|
m_view(parent)
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
13 years ago
|
GanttViewEventItem::GanttViewEventItem(KDGanttViewItem *parent, KPlato::Task *task)
|
||
|
: KDGanttViewEventItem(parent, task->name()),
|
||
15 years ago
|
m_task(task),
|
||
|
m_view()
|
||
|
{
|
||
|
m_drawn = false;
|
||
13 years ago
|
GanttViewSummaryItem *p = dynamic_cast<GanttViewSummaryItem*>(parent);
|
||
15 years ago
|
if (p)
|
||
|
m_view = p->ganttView();
|
||
|
}
|
||
|
|
||
|
|
||
|
void GanttViewEventItem::insertRelations(GanttView *view)
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
|
||
14 years ago
|
TQPtrListIterator<Relation> it(m_task->dependChildNodes());
|
||
15 years ago
|
for (; it.current(); ++it)
|
||
|
{
|
||
14 years ago
|
KDGanttViewItem *child = find(m_view->firstChild(), it.current()->child());
|
||
15 years ago
|
if (child)
|
||
|
{
|
||
|
KDGanttViewTaskLink *link = new KDGanttViewTaskLink(this, child, kdLinkType(it.current()->type()));
|
||
|
|
||
13 years ago
|
TQString t = i18n("From: %1").arg(this->listViewText(0));
|
||
|
t += "\n" + i18n("To: %1").arg(child->listViewText(0));
|
||
15 years ago
|
if (it.current()->lag() > Duration::zeroDuration) {
|
||
13 years ago
|
t += "\n" + i18n("Lag: %1").arg(it.current()->lag().toString(Duration::Format_i18nDayTime));
|
||
15 years ago
|
}
|
||
|
link->setTooltipText(t);
|
||
|
view->addTaskLink(link);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
KDGanttViewItem *GanttViewEventItem::find(Node *node)
|
||
15 years ago
|
{
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
if (m_task == node)
|
||
|
return this;
|
||
|
|
||
14 years ago
|
KDGanttViewItem *item = find(firstChild(), node);
|
||
15 years ago
|
if (item)
|
||
|
return item;
|
||
|
|
||
14 years ago
|
return find(nextSibling(), node);
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
KDGanttViewItem *GanttViewEventItem::find(KDGanttViewItem *item, Node *node)
|
||
15 years ago
|
{
|
||
|
if (!item)
|
||
|
return 0;
|
||
|
|
||
|
if (item->type() == Event)
|
||
|
{
|
||
|
GanttViewEventItem *i = static_cast<GanttViewEventItem *>(item);
|
||
14 years ago
|
return i->find(node);
|
||
15 years ago
|
}
|
||
|
else if (item->type() == Task)
|
||
|
{
|
||
|
GanttViewTaskItem *i = static_cast<GanttViewTaskItem *>(item);
|
||
14 years ago
|
return i->find(node);
|
||
15 years ago
|
}
|
||
|
else if (item->type() == Summary)
|
||
|
{
|
||
|
GanttViewSummaryItem *i = static_cast<GanttViewSummaryItem *>(item);
|
||
14 years ago
|
return i->find(node);
|
||
15 years ago
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
} //KPlato namespace
|