69 lines
1.7 KiB
C++
69 lines
1.7 KiB
C++
#include "util/creatingSelector.h"
|
|
#include "graphicsItem/graphicsRectItem.h"
|
|
#include <QGraphicsSceneMouseEvent>
|
|
#include <QGraphicsView>
|
|
|
|
CreatingSelector::CreatingSelector(QObject *parent)
|
|
: BaseSelector(parent)
|
|
{
|
|
m_type = ST_cerating;
|
|
m_pCreatingItem = nullptr;
|
|
}
|
|
CreatingSelector::~CreatingSelector()
|
|
{
|
|
|
|
}
|
|
|
|
void CreatingSelector::mousePressEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
|
|
{
|
|
if (event->button() != Qt::LeftButton)
|
|
return;
|
|
|
|
scene->clearSelection();
|
|
ms_ptMouseDown = event->scenePos();
|
|
ms_ptMouseLast = event->scenePos();
|
|
|
|
switch (m_creatingType) {
|
|
case GIT_rect:
|
|
m_pCreatingItem = new GraphicsRectItem(QRect(1, 1, 1, 1));
|
|
break;
|
|
case GIT_roundRect:
|
|
m_pCreatingItem = new GraphicsRectItem(QRect(1, 1, 1, 1), true);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
ms_ptMouseDown += QPoint(2, 2);
|
|
m_pCreatingItem->setPos(event->scenePos());
|
|
scene->addItem(m_pCreatingItem);
|
|
m_pCreatingItem->setSelected(true);
|
|
|
|
ms_opMode = OM_scale;
|
|
ms_nDragHandle = H_rightBottom;
|
|
}
|
|
|
|
void CreatingSelector::mouseMoveEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
|
|
{
|
|
setCursor(scene, Qt::CrossCursor);
|
|
BaseSelector::mouseMoveEvent(event, scene);
|
|
}
|
|
|
|
void CreatingSelector::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
|
|
{
|
|
BaseSelector::mouseReleaseEvent(event, scene);
|
|
|
|
if (event->scenePos() == (ms_ptMouseDown - QPoint(2, 2))) //最小拖动范围
|
|
{
|
|
if(m_pCreatingItem)
|
|
{
|
|
m_pCreatingItem->setSelected(false);
|
|
scene->removeItem(m_pCreatingItem);
|
|
delete m_pCreatingItem;
|
|
m_pCreatingItem = nullptr;
|
|
}
|
|
}
|
|
|
|
emit setWorkingSelector(ST_base);
|
|
}
|