|
- #ifndef HMIWIDGET_H
- #define HMIWIDGET_H
-
- #include <QGraphicsRectItem>
- #include <QGraphicsEllipseItem>
- #include <QGraphicsSceneMouseEvent>
- #include <QCursor>
- #include <QPainter>
-
- // 可调整大小的形状模板基类
- template <typename BaseShape>
- class ResizableShape : public BaseShape {
- protected:
- bool resizing;
-
- public:
- ResizableShape(qreal x, qreal y, qreal w, qreal h);
-
- // 事件处理
- void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
- void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
- void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
- protected:
- bool isInResizeArea(const QPointF &pos) const;
- };
-
- // 可调整大小的矩形
- class ResizableRectangle : public ResizableShape<QGraphicsRectItem> {
- public:
- ResizableRectangle(qreal x, qreal y, qreal w, qreal h);
- };
-
- // 可调整大小的椭圆
- class ResizableEllipse : public ResizableShape<QGraphicsEllipseItem> {
- public:
- ResizableEllipse(qreal x, qreal y, qreal w, qreal h);
- };
-
- #endif // HMIWIDGET_H
|