選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

42 行
1.2 KiB

  1. #ifndef HMIWIDGET_H
  2. #define HMIWIDGET_H
  3. #include <QGraphicsRectItem>
  4. #include <QGraphicsEllipseItem>
  5. #include <QGraphicsSceneMouseEvent>
  6. #include <QCursor>
  7. #include <QPainter>
  8. // 可调整大小的形状模板基类
  9. template <typename BaseShape>
  10. class ResizableShape : public BaseShape {
  11. protected:
  12. bool resizing;
  13. public:
  14. ResizableShape(qreal x, qreal y, qreal w, qreal h);
  15. // 事件处理
  16. void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
  17. void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
  18. void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
  19. void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
  20. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
  21. protected:
  22. bool isInResizeArea(const QPointF &pos) const;
  23. };
  24. // 可调整大小的矩形
  25. class ResizableRectangle : public ResizableShape<QGraphicsRectItem> {
  26. public:
  27. ResizableRectangle(qreal x, qreal y, qreal w, qreal h);
  28. };
  29. // 可调整大小的椭圆
  30. class ResizableEllipse : public ResizableShape<QGraphicsEllipseItem> {
  31. public:
  32. ResizableEllipse(qreal x, qreal y, qreal w, qreal h);
  33. };
  34. #endif // HMIWIDGET_H