DiagramDesigner/diagramCavas/include/util/baseSelector.h

92 lines
2.9 KiB
C
Raw Normal View History

2024-12-03 20:07:25 +08:00
/**
*\file baseSelector.h
*
*\brief selector是用来实现对图元进行具体操作的类
*
*\author dsc
*/
#ifndef BASESELECTOR_H
#define BASESELECTOR_H
#include <QObject>
#include "designerScene.h"
enum SelectorType
{
ST_base = 0, //基本
ST_cerating, //创建
ST_moving, //移动
ST_editing, //顶点编辑
ST_scaling, //缩放
ST_rotation, //旋转
ST_connecting, //连接
ST_subMoving, //子对象移动
ST_linkMoving, //连接线移动
2024-12-03 20:07:25 +08:00
};
enum OperationMode
{
OM_none = 0,
OM_move, //移动
OM_create, //创建
OM_edit, //顶点编辑
OM_scale, //缩放
OM_rotate, //旋转
OM_connect, //连接
OM_subMove,//子对象移动
OM_linkMove, //连接线移动
2024-12-03 20:07:25 +08:00
};
class GraphicsProjectModelItem;
2024-12-07 17:24:36 +08:00
using ItemMap = QMap<QString,QMap<QString,GraphicsProjectModelItem*>>;
2024-12-07 17:24:36 +08:00
2024-12-03 20:07:25 +08:00
class BaseSelector : public QObject
{
Q_OBJECT
public:
2025-02-06 16:36:50 +08:00
explicit BaseSelector(FixedPortsModel* model,QObject *parent = 0);
2024-12-03 20:07:25 +08:00
virtual ~BaseSelector();
public:
virtual void mousePressEvent(QGraphicsSceneMouseEvent*, DesignerScene*);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*, DesignerScene*);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*, DesignerScene*);
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*, DesignerScene*);
2025-05-09 19:36:32 +08:00
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event, DesignerScene*);
virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event, DesignerScene*);
virtual void dropEvent(QGraphicsSceneDragDropEvent *event, DesignerScene*);
2025-06-06 18:57:37 +08:00
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event,DesignerScene*);
2024-12-03 20:07:25 +08:00
SelectorType getSelectorType() { return m_type; }
//void setOperationMode(OperationMode m) { m_opMode = m; }
OperationMode getOperationMode() { return ms_opMode; }
void setCursor(DesignerScene*, const QCursor&);
2024-12-07 17:24:36 +08:00
void setSceneName(const QString& str) {m_sceneName = str;}
QString sceneName() const {return m_sceneName;}
2024-12-03 20:07:25 +08:00
2025-04-30 16:29:17 +08:00
FixedPortsModel* getModel() {return _model;}
void updateConnectLineByTopology(QList<QGraphicsItem *>); //通过拓扑关系更新位置
2024-12-03 20:07:25 +08:00
signals:
void setWorkingSelector(SelectorType);
protected:
//静态变量用于不同类型selector间的成员共享
static OperationMode ms_opMode;
static QPointF ms_ptMouseDown;
static QPointF ms_ptMouseLast;
static double ms_dAngleMouseDownToItem; //鼠标按下时其位置和item中心点形成的夹角
static int ms_nDragHandle; //当前抓取的控制点
SelectorType m_type;
2024-12-07 17:24:36 +08:00
QString m_sceneName;
2025-02-06 16:36:50 +08:00
FixedPortsModel* _model;
2024-12-03 20:07:25 +08:00
private:
bool m_bHoverOnHandel; //鼠标是否悬停在handel
OperationMode m_opMode;
};
#endif