67 lines
1.8 KiB
C++
67 lines
1.8 KiB
C++
#include "util/connectingSelector.h"
|
|
#include <QGraphicsSceneMouseEvent>
|
|
#include <QGraphicsView>
|
|
#include <graphicsItem/graphicsBaseItem.h>
|
|
|
|
ConnectingSelector::ConnectingSelector(QObject *parent)
|
|
: BaseSelector(parent),m_pConnectingItem(nullptr)
|
|
{
|
|
m_type = ST_connecting;
|
|
}
|
|
ConnectingSelector::~ConnectingSelector()
|
|
{
|
|
|
|
}
|
|
|
|
void ConnectingSelector::mousePressEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
|
|
{
|
|
ms_ptMouseLast = event->scenePos();
|
|
|
|
}
|
|
|
|
void ConnectingSelector::mouseMoveEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
|
|
{
|
|
ms_ptMouseLast = event->scenePos();
|
|
if(m_pConnectingItem == nullptr)
|
|
{
|
|
QList<QGraphicsItem *> items = scene->selectedItems();
|
|
if (items.count() == 1)
|
|
{
|
|
GraphicsBaseItem* item = qgraphicsitem_cast<GraphicsBaseItem*>(items.first());
|
|
if(item)
|
|
{
|
|
if(ms_nDragHandle != H_none)
|
|
{
|
|
item->setState(S_lineOut);
|
|
QPointF start = item->mapFromScene(ms_ptMouseDown);
|
|
QPointF end = item->mapFromScene(ms_ptMouseLast);
|
|
item->setBeginConnectPos(start);
|
|
item->setEndConnectPos(end);
|
|
m_pConnectingItem = item;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(m_pConnectingItem)
|
|
{
|
|
QPointF end = m_pConnectingItem->mapFromScene(ms_ptMouseLast);
|
|
m_pConnectingItem->setEndConnectPos(end);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void ConnectingSelector::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
|
|
{
|
|
if(m_pConnectingItem)
|
|
m_pConnectingItem->setState(S_normal);
|
|
m_pConnectingItem = nullptr;
|
|
ms_nDragHandle = H_none;
|
|
setCursor(scene, Qt::ArrowCursor);
|
|
scene->callParentEvent(event);
|
|
emit setWorkingSelector(ST_base);
|
|
}
|
|
|