|
|
@ -51,275 +51,41 @@ static QPainterPath qt_graphicsItem_shapeFromPath(const QPainterPath &path, cons
|
|
|
|
p.addPath(path);
|
|
|
|
p.addPath(path);
|
|
|
|
return p;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
|
|
|
|
GraphicsItemNode::GraphicsItemNode(GraphicsItemZone *itemZone, QGraphicsItem *parent)
|
|
|
|
|
|
|
|
: QGraphicsObject(parent)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_itemZone = itemZone;
|
|
|
|
|
|
|
|
m_color = QColor(12, 150, 215);
|
|
|
|
|
|
|
|
//setFlag(ItemIgnoresTransformations, true);
|
|
|
|
|
|
|
|
//setFlag(ItemClipsToShape);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPropertyAnimation *animation = new QPropertyAnimation(this, "colorNode");
|
|
|
|
|
|
|
|
animation->setDuration(3000);
|
|
|
|
|
|
|
|
animation->setStartValue(QColor(10, 0, 50));
|
|
|
|
|
|
|
|
animation->setKeyValueAt(0.5, QColor(155, 255, 0));
|
|
|
|
|
|
|
|
animation->setEndValue(QColor(10, 0, 50));
|
|
|
|
|
|
|
|
animation->setLoopCount(2000);
|
|
|
|
|
|
|
|
animation->setEasingCurve(QEasingCurve::OutInExpo);
|
|
|
|
|
|
|
|
animation->start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setFlag(ItemIsSelectable);
|
|
|
|
|
|
|
|
setFlag(ItemIsMovable);
|
|
|
|
|
|
|
|
setFlag(ItemSendsScenePositionChanges);
|
|
|
|
|
|
|
|
m_type = EdgeType;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
|
|
|
|
|
|
|
|
setZValue(10000000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GraphicsItemNode::~GraphicsItemNode()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GraphicsItemNode::setColorNode(const QColor &color)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_color = color;
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GraphicsItemNode::setNodeType(NodeType nodeType)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_type = nodeType;
|
|
|
|
|
|
|
|
if (m_type == EdgeType)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
setFlag(ItemIsSelectable);
|
|
|
|
|
|
|
|
setFlag(ItemIsMovable);
|
|
|
|
|
|
|
|
setFlag(ItemSendsScenePositionChanges);
|
|
|
|
|
|
|
|
setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
|
|
|
|
|
|
|
|
setZValue(10000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (m_type == MiddleType)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
setFlag(ItemIsSelectable, false);
|
|
|
|
|
|
|
|
setFlag(ItemIsMovable, false);
|
|
|
|
|
|
|
|
setFlag(ItemSendsScenePositionChanges, false);
|
|
|
|
|
|
|
|
setAcceptedMouseButtons(Qt::LeftButton);
|
|
|
|
|
|
|
|
setZValue(10001);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QRectF GraphicsItemNode::boundingRect() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return QRectF(QPointF(0, 0), QSizeF(20, 20));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GraphicsItemNode::paint(QPainter *painter,
|
|
|
|
|
|
|
|
const QStyleOptionGraphicsItem *option,
|
|
|
|
|
|
|
|
QWidget *)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Here comes the magic:
|
|
|
|
|
|
|
|
//painter->setClipRect(option->exposedRect);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
painter->setPen(Qt::NoPen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_type == EdgeType)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
painter->setBrush(QColor(255, 0, 0));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (m_type == MiddleType)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
painter->setBrush(QColor(0, 0, 255));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option->state & QStyle::State_Selected)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
painter->setBrush(QColor(0, 255, 0));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
painter->drawRect(2, 2, 18, 18);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QVariant GraphicsItemNode::itemChange(GraphicsItemChange change,
|
|
|
|
|
|
|
|
const QVariant &value)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (change == ItemPositionHasChanged)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_itemZone->updateZone();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GraphicsItemNode::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((m_type == MiddleType) && (event->button() == Qt::LeftButton))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_itemZone->updateMiddleNode(this);
|
|
|
|
|
|
|
|
setNodeType(EdgeType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ((m_type == EdgeType) && (event->button() == Qt::RightButton))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (m_itemZone->deleteEdgePoint(this))
|
|
|
|
|
|
|
|
setNodeType(MiddleType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GraphicsItemZone::GraphicsItemZone(QGraphicsScene *scene, QGraphicsItem *parent)
|
|
|
|
|
|
|
|
: QGraphicsPolygonItem(parent)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_scene = scene;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_color = QColor(12, 150, 215);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setBrush(QBrush(QColor(100, 100, 255, 128)));
|
|
|
|
|
|
|
|
updateZone();
|
|
|
|
|
|
|
|
setZValue(100);
|
|
|
|
|
|
|
|
//setFlag(ItemClipsToShape);
|
|
|
|
|
|
|
|
//setFlag(ItemIsSelectable, true);
|
|
|
|
|
|
|
|
//setFlag(ItemIsMovable, true);
|
|
|
|
|
|
|
|
//setFlag(ItemHasNoContents, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GraphicsItemZone::~GraphicsItemZone()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GraphicsItemZone::updateMiddleNode(GraphicsItemNode *node)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.size(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (node == m_listLines.at(i).itemPoint)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LineItem oldLineItem = m_listLines[i];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GraphicsItemNode *newNode1 = new GraphicsItemNode(this);
|
|
|
|
|
|
|
|
newNode1->setPos((oldLineItem.lineNode.first->pos() + node->pos()) / 2);
|
|
|
|
|
|
|
|
newNode1->setNodeType(GraphicsItemNode::MiddleType);
|
|
|
|
|
|
|
|
m_scene->addItem(newNode1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GraphicsItemNode *newNode2 = new GraphicsItemNode(this);
|
|
|
|
|
|
|
|
newNode2->setPos((oldLineItem.lineNode.second->pos() + node->pos()) / 2);
|
|
|
|
|
|
|
|
newNode2->setNodeType(GraphicsItemNode::MiddleType);
|
|
|
|
|
|
|
|
m_scene->addItem(newNode2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LineItem newLineItem1;
|
|
|
|
|
|
|
|
newLineItem1.itemPoint = newNode1;
|
|
|
|
|
|
|
|
newLineItem1.lineNode = LineNode(oldLineItem.lineNode.first, node);
|
|
|
|
|
|
|
|
m_listLines.push_back(newLineItem1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LineItem newLineItem2;
|
|
|
|
|
|
|
|
newLineItem2.itemPoint = newNode2;
|
|
|
|
|
|
|
|
newLineItem2.lineNode = LineNode(node, oldLineItem.lineNode.second);
|
|
|
|
|
|
|
|
m_listLines.push_back(newLineItem2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_listLines.removeAt(i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int pos = m_listItems.indexOf(oldLineItem.lineNode.second);
|
|
|
|
|
|
|
|
m_listItems.insert(pos, node);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool GraphicsItemZone::deleteEdgePoint(GraphicsItemNode *node)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (m_listItems.size() < 4)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int pos = m_listItems.indexOf(node);
|
|
|
|
AbstractWorldItem::AbstractWorldItem(QGraphicsItem *parent)
|
|
|
|
m_listItems.takeAt(pos);
|
|
|
|
: QGraphicsItem(parent),
|
|
|
|
|
|
|
|
m_active(false),
|
|
|
|
LineItem newLineItem;
|
|
|
|
m_shapeChanged(false)
|
|
|
|
|
|
|
|
|
|
|
|
newLineItem.itemPoint = node;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.size(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (node == m_listLines.at(i).lineNode.first)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Saving second point for new line
|
|
|
|
|
|
|
|
newLineItem.lineNode.second = m_listLines.at(i).lineNode.second;
|
|
|
|
|
|
|
|
delete m_listLines.at(i).itemPoint;
|
|
|
|
|
|
|
|
m_listLines.removeAt(i);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.size(); ++i)
|
|
|
|
AbstractWorldItem::~AbstractWorldItem()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (node == m_listLines.at(i).lineNode.second)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
newLineItem.lineNode.first = m_listLines.at(i).lineNode.first;
|
|
|
|
|
|
|
|
delete m_listLines.at(i).itemPoint;
|
|
|
|
|
|
|
|
m_listLines.removeAt(i);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node->setPos((newLineItem.lineNode.first->pos() + newLineItem.lineNode.second->pos()) / 2);
|
|
|
|
|
|
|
|
m_listLines.push_back(newLineItem);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GraphicsItemZone::scanPolygon(const QPolygonF &polygon)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GraphicsItemNode *node1;
|
|
|
|
|
|
|
|
node1 = new GraphicsItemNode(this);
|
|
|
|
|
|
|
|
node1->setPos(*polygon.begin());
|
|
|
|
|
|
|
|
m_listItems.push_back(node1);
|
|
|
|
|
|
|
|
m_scene->addItem(node1);
|
|
|
|
|
|
|
|
for (int i = 1; i < polygon.count(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GraphicsItemNode *node2 = new GraphicsItemNode(this);
|
|
|
|
|
|
|
|
node2->setPos(polygon.at(i));
|
|
|
|
|
|
|
|
m_listItems.push_back(node2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GraphicsItemNode *node3 = new GraphicsItemNode(this);
|
|
|
|
|
|
|
|
node3->setPos((node1->pos() + node2->pos()) / 2);
|
|
|
|
|
|
|
|
node3->setNodeType(GraphicsItemNode::MiddleType);
|
|
|
|
|
|
|
|
m_scene->addItem(node3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LineItem newLineItem;
|
|
|
|
int AbstractWorldItem::type() const
|
|
|
|
newLineItem.itemPoint = node3;
|
|
|
|
|
|
|
|
newLineItem.lineNode = LineNode(node1, node2);
|
|
|
|
|
|
|
|
m_listLines.push_back(newLineItem);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
node1 = node2;
|
|
|
|
|
|
|
|
m_scene->addItem(node1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setPolygon(polygon);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GraphicsItemZone::updateZone()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QPolygonF polygon;
|
|
|
|
|
|
|
|
Q_FOREACH(GraphicsItemNode *node, m_listItems)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
polygon << node->pos();
|
|
|
|
return Type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.size(); ++i)
|
|
|
|
void AbstractWorldItem::setActived(bool actived)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_listLines.at(i).itemPoint->setPos((m_listLines.at(i).lineNode.first->pos() + m_listLines.at(i).lineNode.second->pos()) / 2);
|
|
|
|
m_active = actived;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setPolygon(polygon);
|
|
|
|
bool AbstractWorldItem::isActived() const
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AbstractWorldItem::AbstractWorldItem(QGraphicsItem *parent)
|
|
|
|
|
|
|
|
: QGraphicsItem(parent)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
return m_active;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AbstractWorldItem::~AbstractWorldItem()
|
|
|
|
void AbstractWorldItem::setShapeChanged(bool value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
m_shapeChanged = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int AbstractWorldItem::type() const
|
|
|
|
bool AbstractWorldItem::isShapeChanged() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Type;
|
|
|
|
return m_shapeChanged;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WorldItemPoint::WorldItemPoint(const QPointF &point, const qreal angle, const qreal radius,
|
|
|
|
WorldItemPoint::WorldItemPoint(const QPointF &point, const qreal angle, const qreal radius,
|
|
|
@ -360,7 +126,6 @@ WorldItemPoint::WorldItemPoint(const QPointF &point, const qreal angle, const qr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updateBoundingRect();
|
|
|
|
updateBoundingRect();
|
|
|
|
//setFlag(ItemIsSelectable);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WorldItemPoint::~WorldItemPoint()
|
|
|
|
WorldItemPoint::~WorldItemPoint()
|
|
|
@ -373,9 +138,7 @@ void WorldItemPoint::rotateOn(const QPointF &pivot, const qreal deltaAngle)
|
|
|
|
|
|
|
|
|
|
|
|
QPolygonF rotatedPolygon(m_rect);
|
|
|
|
QPolygonF rotatedPolygon(m_rect);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
rotatedPolygon.translate(pos() - pivot);
|
|
|
|
rotatedPolygon.translate(pos() - pivot);
|
|
|
|
//rotatedPolygon.translate(-pivot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QTransform trans;
|
|
|
|
QTransform trans;
|
|
|
|
trans = trans.rotate(deltaAngle);
|
|
|
|
trans = trans.rotate(deltaAngle);
|
|
|
@ -391,9 +154,7 @@ void WorldItemPoint::scaleOn(const QPointF &pivot, const QPointF &factor)
|
|
|
|
|
|
|
|
|
|
|
|
QPolygonF scaledPolygon(m_rect);
|
|
|
|
QPolygonF scaledPolygon(m_rect);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
scaledPolygon.translate(pos() - pivot);
|
|
|
|
scaledPolygon.translate(pos() - pivot);
|
|
|
|
//scaledPolygon.translate(-pivot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QTransform trans;
|
|
|
|
QTransform trans;
|
|
|
|
trans = trans.scale(factor.x(), factor.y());
|
|
|
|
trans = trans.scale(factor.x(), factor.y());
|
|
|
@ -478,7 +239,8 @@ void WorldItemPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
|
|
|
|
painter->drawLines(m_arrow);
|
|
|
|
painter->drawLines(m_arrow);
|
|
|
|
|
|
|
|
|
|
|
|
painter->setPen(Qt::NoPen);
|
|
|
|
painter->setPen(Qt::NoPen);
|
|
|
|
if (option->state & QStyle::State_Selected)
|
|
|
|
// if (option->state & QStyle::State_Selected)
|
|
|
|
|
|
|
|
if (isActived())
|
|
|
|
painter->setBrush(m_selectedBrush);
|
|
|
|
painter->setBrush(m_selectedBrush);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
painter->setBrush(m_brush);
|
|
|
|
painter->setBrush(m_brush);
|
|
|
@ -487,17 +249,10 @@ void WorldItemPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
|
|
|
|
painter->drawRect(m_rect);
|
|
|
|
painter->drawRect(m_rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant WorldItemPoint::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (change == ItemPositionHasChanged)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WorldItemPath::WorldItemPath(const QPolygonF &polygon, QGraphicsItem *parent)
|
|
|
|
WorldItemPath::WorldItemPath(const QPolygonF &polygon, QGraphicsItem *parent)
|
|
|
|
: AbstractWorldItem(parent),
|
|
|
|
: AbstractWorldItem(parent),
|
|
|
|
m_polygon(polygon)
|
|
|
|
m_polygon(polygon),
|
|
|
|
|
|
|
|
m_pointEdit(false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//setFlag(ItemIsSelectable);
|
|
|
|
//setFlag(ItemIsSelectable);
|
|
|
|
|
|
|
|
|
|
|
@ -548,17 +303,142 @@ void WorldItemPath::scaleOn(const QPointF &pivot, const QPointF &factor)
|
|
|
|
m_polygon.translate(pivot - pos());
|
|
|
|
m_polygon.translate(pivot - pos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemPath::turnOn(const qreal angle)
|
|
|
|
void WorldItemPath::setColor(const QColor &color)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
m_pen.setColor(color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemPath::radiusOn(const qreal radius)
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemPath::setEnabledSubPoints(bool enabled)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
m_pointEdit = enabled;
|
|
|
|
|
|
|
|
if (m_pointEdit)
|
|
|
|
|
|
|
|
createSubPoints();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
removeSubPoints();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemPath::setColor(const QColor &color)
|
|
|
|
void WorldItemPath::moveSubPoint(WorldItemSubPoint *subPoint)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_pen.setColor(color);
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPolygonF polygon;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update polygon
|
|
|
|
|
|
|
|
Q_FOREACH(WorldItemSubPoint *node, m_listItems)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
polygon << node->pos();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update middle points
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.size(); ++i)
|
|
|
|
|
|
|
|
m_listLines.at(i).itemPoint->setPos((m_listLines.at(i).lineItem.first->pos() + m_listLines.at(i).lineItem.second->pos()) / 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_polygon = polygon;
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemPath::addSubPoint(WorldItemSubPoint *subPoint)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.size(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (subPoint == m_listLines.at(i).itemPoint)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LineStruct oldLineItem = m_listLines[i];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the first middle sub-point
|
|
|
|
|
|
|
|
WorldItemSubPoint *firstItem = new WorldItemSubPoint(WorldItemSubPoint::MiddleType, this);
|
|
|
|
|
|
|
|
firstItem->setPos((oldLineItem.lineItem.first->pos() + subPoint->pos()) / 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the second middle sub-point
|
|
|
|
|
|
|
|
WorldItemSubPoint *secondItem = new WorldItemSubPoint(WorldItemSubPoint::MiddleType, this);
|
|
|
|
|
|
|
|
secondItem->setPos((oldLineItem.lineItem.second->pos() + subPoint->pos()) / 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add first line in the list
|
|
|
|
|
|
|
|
LineStruct firstNewLineItem;
|
|
|
|
|
|
|
|
firstNewLineItem.itemPoint = firstItem;
|
|
|
|
|
|
|
|
firstNewLineItem.lineItem = LineItem(oldLineItem.lineItem.first, subPoint);
|
|
|
|
|
|
|
|
m_listLines.push_back(firstNewLineItem);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add second line in the list
|
|
|
|
|
|
|
|
LineStruct secondNewLineItem;
|
|
|
|
|
|
|
|
secondNewLineItem.itemPoint = secondItem;
|
|
|
|
|
|
|
|
secondNewLineItem.lineItem = LineItem(subPoint, oldLineItem.lineItem.second);
|
|
|
|
|
|
|
|
m_listLines.push_back(secondNewLineItem);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_listLines.removeAt(i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int pos = m_listItems.indexOf(oldLineItem.lineItem.second);
|
|
|
|
|
|
|
|
m_listItems.insert(pos, subPoint);
|
|
|
|
|
|
|
|
subPoint->setFlag(ItemSendsScenePositionChanges);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool WorldItemPath::removeSubPoint(WorldItemSubPoint *subPoint)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int pos = m_listItems.indexOf(subPoint);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// First and second points can not be removed
|
|
|
|
|
|
|
|
if ((pos == 0) || (pos == m_listItems.size() - 1))
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_listItems.takeAt(pos);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LineStruct newLineItem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newLineItem.itemPoint = subPoint;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Delete first line
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.size(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (subPoint == m_listLines.at(i).lineItem.first)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Saving second point for new line
|
|
|
|
|
|
|
|
newLineItem.lineItem.second = m_listLines.at(i).lineItem.second;
|
|
|
|
|
|
|
|
delete m_listLines.at(i).itemPoint;
|
|
|
|
|
|
|
|
m_listLines.removeAt(i);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Delete second line
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.size(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (subPoint == m_listLines.at(i).lineItem.second)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Saving first point for new line
|
|
|
|
|
|
|
|
newLineItem.lineItem.first = m_listLines.at(i).lineItem.first;
|
|
|
|
|
|
|
|
delete m_listLines.at(i).itemPoint;
|
|
|
|
|
|
|
|
m_listLines.removeAt(i);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
subPoint->setPos((newLineItem.lineItem.first->pos() + newLineItem.lineItem.second->pos()) / 2);
|
|
|
|
|
|
|
|
m_listLines.push_back(newLineItem);
|
|
|
|
|
|
|
|
subPoint->setFlag(ItemSendsScenePositionChanges, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemPath::setPolygon(const QPolygonF &polygon)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_polygon = polygon;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPolygonF WorldItemPath::polygon() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return m_polygon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QPainterPath WorldItemPath::shape() const
|
|
|
|
QPainterPath WorldItemPath::shape() const
|
|
|
@ -582,7 +462,8 @@ void WorldItemPath::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
|
|
|
|
// Here comes the magic:
|
|
|
|
// Here comes the magic:
|
|
|
|
//painter->setClipRect(option->exposedRect);
|
|
|
|
//painter->setClipRect(option->exposedRect);
|
|
|
|
|
|
|
|
|
|
|
|
if (option->state & QStyle::State_Selected)
|
|
|
|
//if (option->state & QStyle::State_Selected)
|
|
|
|
|
|
|
|
if (isActived())
|
|
|
|
painter->setPen(m_selectedPen);
|
|
|
|
painter->setPen(m_selectedPen);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
painter->setPen(m_pen);
|
|
|
|
painter->setPen(m_pen);
|
|
|
@ -590,17 +471,49 @@ void WorldItemPath::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
|
|
|
|
painter->drawPolyline(m_polygon);
|
|
|
|
painter->drawPolyline(m_polygon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant WorldItemPath::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
|
|
void WorldItemPath::createSubPoints()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (change == ItemPositionHasChanged)
|
|
|
|
WorldItemSubPoint *firstPoint;
|
|
|
|
|
|
|
|
firstPoint = new WorldItemSubPoint(WorldItemSubPoint::EdgeType, this);
|
|
|
|
|
|
|
|
firstPoint->setPos(m_polygon.front());
|
|
|
|
|
|
|
|
firstPoint->setFlag(ItemSendsScenePositionChanges);
|
|
|
|
|
|
|
|
m_listItems.push_back(firstPoint);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < m_polygon.count(); ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
WorldItemSubPoint *secondPoint = new WorldItemSubPoint(WorldItemSubPoint::EdgeType, this);
|
|
|
|
|
|
|
|
secondPoint->setPos(m_polygon.at(i));
|
|
|
|
|
|
|
|
secondPoint->setFlag(ItemSendsScenePositionChanges);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WorldItemSubPoint *middlePoint = new WorldItemSubPoint(WorldItemSubPoint::MiddleType, this);
|
|
|
|
|
|
|
|
middlePoint->setPos((firstPoint->pos() + secondPoint->pos()) / 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LineStruct newLineItem;
|
|
|
|
|
|
|
|
newLineItem.itemPoint = middlePoint;
|
|
|
|
|
|
|
|
newLineItem.lineItem = LineItem(firstPoint, secondPoint);
|
|
|
|
|
|
|
|
m_listLines.push_back(newLineItem);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
firstPoint = secondPoint;
|
|
|
|
|
|
|
|
m_listItems.push_back(firstPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemPath::removeSubPoints()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.count(); ++i)
|
|
|
|
|
|
|
|
delete m_listLines.at(i).itemPoint;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listItems.count(); ++i)
|
|
|
|
|
|
|
|
delete m_listItems.at(i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_listItems.clear();
|
|
|
|
|
|
|
|
m_listLines.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WorldItemZone::WorldItemZone(const QPolygonF &polygon, QGraphicsItem *parent)
|
|
|
|
WorldItemZone::WorldItemZone(const QPolygonF &polygon, QGraphicsItem *parent)
|
|
|
|
: AbstractWorldItem(parent),
|
|
|
|
: AbstractWorldItem(parent),
|
|
|
|
m_polygon(polygon)
|
|
|
|
m_polygon(polygon),
|
|
|
|
|
|
|
|
m_pointEdit(false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//setFlag(ItemIsSelectable);
|
|
|
|
//setFlag(ItemIsSelectable);
|
|
|
|
|
|
|
|
|
|
|
@ -646,7 +559,6 @@ void WorldItemZone::scaleOn(const QPointF &pivot, const QPointF &factor)
|
|
|
|
prepareGeometryChange();
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
|
|
|
|
QPolygonF scaledPolygon(m_polygon);
|
|
|
|
QPolygonF scaledPolygon(m_polygon);
|
|
|
|
|
|
|
|
|
|
|
|
scaledPolygon.translate(pos() - pivot);
|
|
|
|
scaledPolygon.translate(pos() - pivot);
|
|
|
|
|
|
|
|
|
|
|
|
QTransform trans;
|
|
|
|
QTransform trans;
|
|
|
@ -656,22 +568,151 @@ void WorldItemZone::scaleOn(const QPointF &pivot, const QPointF &factor)
|
|
|
|
m_polygon.translate(pivot - pos());
|
|
|
|
m_polygon.translate(pivot - pos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemZone::turnOn(const qreal angle)
|
|
|
|
void WorldItemZone::setColor(const QColor &color)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
m_pen.setColor(color);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QColor brushColor(color);
|
|
|
|
|
|
|
|
brushColor.setAlpha(TRANSPARENCY);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_brush.setColor(brushColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemZone::radiusOn(const qreal radius)
|
|
|
|
void WorldItemZone::setEnabledSubPoints(bool enabled)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
m_pointEdit = enabled;
|
|
|
|
|
|
|
|
if (m_pointEdit)
|
|
|
|
|
|
|
|
createSubPoints();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
removeSubPoints();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setShapeChanged(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemZone::setColor(const QColor &color)
|
|
|
|
void WorldItemZone::moveSubPoint(WorldItemSubPoint *subPoint)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_pen.setColor(color);
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
|
|
|
|
QColor brushColor(color);
|
|
|
|
QPolygonF polygon;
|
|
|
|
brushColor.setAlpha(TRANSPARENCY);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_brush.setColor(brushColor);
|
|
|
|
// Update polygon
|
|
|
|
|
|
|
|
Q_FOREACH(WorldItemSubPoint *node, m_listItems)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
polygon << node->pos();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update middle points
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.size(); ++i)
|
|
|
|
|
|
|
|
m_listLines.at(i).itemPoint->setPos((m_listLines.at(i).lineItem.first->pos() + m_listLines.at(i).lineItem.second->pos()) / 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_polygon = polygon;
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setShapeChanged(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemZone::addSubPoint(WorldItemSubPoint *subPoint)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.size(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (subPoint == m_listLines.at(i).itemPoint)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LineStruct oldLineItem = m_listLines[i];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the first middle sub-point
|
|
|
|
|
|
|
|
WorldItemSubPoint *firstItem = new WorldItemSubPoint(WorldItemSubPoint::MiddleType, this);
|
|
|
|
|
|
|
|
firstItem->setPos((oldLineItem.lineItem.first->pos() + subPoint->pos()) / 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the second middle sub-point
|
|
|
|
|
|
|
|
WorldItemSubPoint *secondItem = new WorldItemSubPoint(WorldItemSubPoint::MiddleType, this);
|
|
|
|
|
|
|
|
secondItem->setPos((oldLineItem.lineItem.second->pos() + subPoint->pos()) / 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add first line in the list
|
|
|
|
|
|
|
|
LineStruct firstNewLineItem;
|
|
|
|
|
|
|
|
firstNewLineItem.itemPoint = firstItem;
|
|
|
|
|
|
|
|
firstNewLineItem.lineItem = LineItem(oldLineItem.lineItem.first, subPoint);
|
|
|
|
|
|
|
|
m_listLines.push_back(firstNewLineItem);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add second line in the list
|
|
|
|
|
|
|
|
LineStruct secondNewLineItem;
|
|
|
|
|
|
|
|
secondNewLineItem.itemPoint = secondItem;
|
|
|
|
|
|
|
|
secondNewLineItem.lineItem = LineItem(subPoint, oldLineItem.lineItem.second);
|
|
|
|
|
|
|
|
m_listLines.push_back(secondNewLineItem);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_listLines.removeAt(i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int pos = m_listItems.indexOf(oldLineItem.lineItem.second);
|
|
|
|
|
|
|
|
m_listItems.insert(pos, subPoint);
|
|
|
|
|
|
|
|
subPoint->setFlag(ItemSendsScenePositionChanges);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setShapeChanged(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool WorldItemZone::removeSubPoint(WorldItemSubPoint *subPoint)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_listItems.size() < 4)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int pos = m_listItems.indexOf(subPoint);
|
|
|
|
|
|
|
|
m_listItems.takeAt(pos);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LineStruct newLineItem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newLineItem.itemPoint = subPoint;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Delete first line
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.size(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (subPoint == m_listLines.at(i).lineItem.first)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Saving second point for new line
|
|
|
|
|
|
|
|
newLineItem.lineItem.second = m_listLines.at(i).lineItem.second;
|
|
|
|
|
|
|
|
delete m_listLines.at(i).itemPoint;
|
|
|
|
|
|
|
|
m_listLines.removeAt(i);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Delete second line
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.size(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (subPoint == m_listLines.at(i).lineItem.second)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Saving first point for new line
|
|
|
|
|
|
|
|
newLineItem.lineItem.first = m_listLines.at(i).lineItem.first;
|
|
|
|
|
|
|
|
delete m_listLines.at(i).itemPoint;
|
|
|
|
|
|
|
|
m_listLines.removeAt(i);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
m_listLines.push_back(newLineItem);
|
|
|
|
|
|
|
|
subPoint->setPos((newLineItem.lineItem.first->pos() + newLineItem.lineItem.second->pos()) / 2);
|
|
|
|
|
|
|
|
subPoint->setFlag(ItemSendsScenePositionChanges, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setShapeChanged(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemZone::setPolygon(const QPolygonF &polygon)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_polygon = polygon;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPolygonF WorldItemZone::polygon() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return m_polygon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QRectF WorldItemZone::boundingRect() const
|
|
|
|
QRectF WorldItemZone::boundingRect() const
|
|
|
@ -688,7 +729,8 @@ QPainterPath WorldItemZone::shape() const
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
|
|
|
|
void WorldItemZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (option->state & QStyle::State_Selected)
|
|
|
|
// if (option->state & QStyle::State_Selected)
|
|
|
|
|
|
|
|
if (isActived())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
painter->setPen(m_selectedPen);
|
|
|
|
painter->setPen(m_selectedPen);
|
|
|
|
painter->setBrush(m_selectedBrush);
|
|
|
|
painter->setBrush(m_selectedBrush);
|
|
|
@ -702,12 +744,192 @@ void WorldItemZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
|
|
|
|
painter->drawPolygon(m_polygon);
|
|
|
|
painter->drawPolygon(m_polygon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant WorldItemZone::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
|
|
void WorldItemZone::createSubPoints()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (change == ItemPositionHasChanged)
|
|
|
|
WorldItemSubPoint *firstPoint;
|
|
|
|
|
|
|
|
firstPoint = new WorldItemSubPoint(WorldItemSubPoint::EdgeType, this);
|
|
|
|
|
|
|
|
firstPoint->setPos(m_polygon.front());
|
|
|
|
|
|
|
|
firstPoint->setFlag(ItemSendsScenePositionChanges);
|
|
|
|
|
|
|
|
m_listItems.push_back(firstPoint);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < m_polygon.count(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
WorldItemSubPoint *secondPoint = new WorldItemSubPoint(WorldItemSubPoint::EdgeType, this);
|
|
|
|
|
|
|
|
secondPoint->setPos(m_polygon.at(i));
|
|
|
|
|
|
|
|
secondPoint->setFlag(ItemSendsScenePositionChanges);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WorldItemSubPoint *middlePoint = new WorldItemSubPoint(WorldItemSubPoint::MiddleType, this);
|
|
|
|
|
|
|
|
middlePoint->setPos((firstPoint->pos() + secondPoint->pos()) / 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LineStruct newLineItem;
|
|
|
|
|
|
|
|
newLineItem.itemPoint = middlePoint;
|
|
|
|
|
|
|
|
newLineItem.lineItem = LineItem(firstPoint, secondPoint);
|
|
|
|
|
|
|
|
m_listLines.push_back(newLineItem);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
firstPoint = secondPoint;
|
|
|
|
|
|
|
|
m_listItems.push_back(firstPoint);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LineStruct endLineItem;
|
|
|
|
|
|
|
|
endLineItem.itemPoint = new WorldItemSubPoint(WorldItemSubPoint::MiddleType, this);
|
|
|
|
|
|
|
|
endLineItem.itemPoint->setPos((m_listItems.first()->pos() + m_listItems.last()->pos()) / 2);
|
|
|
|
|
|
|
|
endLineItem.lineItem = LineItem(m_listItems.last(), m_listItems.first());
|
|
|
|
|
|
|
|
m_listLines.push_back(endLineItem);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemZone::removeSubPoints()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listLines.count(); ++i)
|
|
|
|
|
|
|
|
delete m_listLines.at(i).itemPoint;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listItems.count(); ++i)
|
|
|
|
|
|
|
|
delete m_listItems.at(i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_listItems.clear();
|
|
|
|
|
|
|
|
m_listLines.clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//*******************************************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WorldItemSubPoint::WorldItemSubPoint(SubPointType pointType, AbstractWorldItem *parent)
|
|
|
|
|
|
|
|
: QGraphicsObject(parent),
|
|
|
|
|
|
|
|
m_type(pointType),
|
|
|
|
|
|
|
|
m_active(false),
|
|
|
|
|
|
|
|
m_parent(parent)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
setZValue(WORLD_POINT_LAYER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_brush.setColor(QColor(20, 100, 255));
|
|
|
|
|
|
|
|
m_brush.setStyle(Qt::SolidPattern);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_brushMiddle.setColor(QColor(255, 25, 100));
|
|
|
|
|
|
|
|
m_brushMiddle.setStyle(Qt::SolidPattern);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_selectedBrush.setColor(QColor(255, 255, 255, 100));
|
|
|
|
|
|
|
|
m_selectedBrush.setStyle(Qt::SolidPattern);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_rect.setCoords(-SIZE_POINT, -SIZE_POINT, SIZE_POINT, SIZE_POINT);
|
|
|
|
|
|
|
|
updateBoundingRect();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//setFlag(ItemIgnoresTransformations);
|
|
|
|
|
|
|
|
//setFlag(ItemSendsScenePositionChanges);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WorldItemSubPoint::~WorldItemSubPoint()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemSubPoint::setSubPointType(SubPointType nodeType)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_type = nodeType;
|
|
|
|
|
|
|
|
setFlag(ItemSendsScenePositionChanges);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WorldItemSubPoint::SubPointType WorldItemSubPoint::subPointType() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return m_type;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemSubPoint::rotateOn(const QPointF &pivot, const qreal deltaAngle)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPolygonF rotatedPolygon(m_rect);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
rotatedPolygon.translate(scenePos() - pivot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QTransform trans;
|
|
|
|
|
|
|
|
trans = trans.rotate(deltaAngle);
|
|
|
|
|
|
|
|
rotatedPolygon = trans.map(rotatedPolygon);
|
|
|
|
|
|
|
|
rotatedPolygon.translate(pivot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setPos(m_parent->mapFromParent(rotatedPolygon.boundingRect().center()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemSubPoint::scaleOn(const QPointF &pivot, const QPointF &factor)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPolygonF scaledPolygon(m_rect);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
scaledPolygon.translate(scenePos() - pivot);
|
|
|
|
|
|
|
|
//scaledPolygon.translate(-pivot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QTransform trans;
|
|
|
|
|
|
|
|
trans = trans.scale(factor.x(), factor.y());
|
|
|
|
|
|
|
|
scaledPolygon = trans.map(scaledPolygon);
|
|
|
|
|
|
|
|
scaledPolygon.translate(pivot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setPos(m_parent->mapFromParent(scaledPolygon.boundingRect().center()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QRectF WorldItemSubPoint::boundingRect() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return m_boundingRect;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemSubPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
painter->setPen(Qt::NoPen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_type == WorldItemSubPoint::EdgeType)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (isActived())
|
|
|
|
|
|
|
|
painter->setBrush(m_selectedBrush);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
painter->setBrush(m_brush);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
painter->setBrush(m_brushMiddle);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Draw point
|
|
|
|
|
|
|
|
painter->drawRect(m_rect);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int WorldItemSubPoint::type() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Type;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemSubPoint::setActived(bool actived)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_active = actived;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool WorldItemSubPoint::isActived() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return m_active;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QVariant WorldItemSubPoint::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (change == ItemPositionHasChanged)
|
|
|
|
|
|
|
|
m_parent->moveSubPoint(this);
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemSubPoint::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((m_type == MiddleType) && (event->button() == Qt::LeftButton))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_parent->addSubPoint(this);
|
|
|
|
|
|
|
|
setSubPointType(EdgeType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ((m_type == EdgeType) && (event->button() == Qt::RightButton))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (m_parent->removeSubPoint(this))
|
|
|
|
|
|
|
|
setSubPointType(MiddleType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldItemSubPoint::updateBoundingRect()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_boundingRect.setCoords(-SIZE_POINT, -SIZE_POINT, SIZE_POINT, SIZE_POINT);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} /* namespace WorldEditor */
|
|
|
|
} /* namespace WorldEditor */
|
|
|
|