You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.5 KiB

  1. #ifndef LIGHT_H
  2. #define LIGHT_H
  3. #include "item.h"
  4. class Light : public Item
  5. {
  6. public:
  7. Light(const QString &type);
  8. QRectF boundingRect() const override;
  9. void paint(QPainter *painter,
  10. const QStyleOptionGraphicsItem *option,
  11. QWidget *) override;
  12. bool state() const override;
  13. void addMenuActions(QMenu *menu) override;
  14. void handleMenuAction(QAction *action) override;
  15. void setCustomImage(const QString& imagePath);
  16. void setOnImage(const QString& imagePath);
  17. void setOffImage(const QString& imagePath);
  18. void setCurrentSize(QSizeF size);
  19. QSizeF currentSize();
  20. QString onImagePath();
  21. QString offImagePath();
  22. void loadImage();
  23. void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
  24. void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
  25. void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
  26. private:
  27. QString onImagePath_; // ON状态图片路径
  28. QString offImagePath_; // OFF状态图片路径
  29. QPixmap onPixmap_; // ON状态图片
  30. QPixmap offPixmap_; // OFF状态图片
  31. bool resizing_ = false; // 是否正在调整大小
  32. QPointF resizeStartPos_; // 调整大小开始位置
  33. QSizeF originalSize_; // 调整前的原始大小
  34. QSizeF currentSize_ = QSizeF(50, 50); // 当前实际尺寸
  35. int resizeHandleSize_ = 8; // 调整手柄大小
  36. int resizeMargin_ = 5; // 调整边距
  37. };
  38. #endif // LIGHT_H