#ifndef LIGHT_H #define LIGHT_H #include "item.h" class Light : public Item { public: Light(const QString &type); QRectF boundingRect() const override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) override; bool state() const override; void addMenuActions(QMenu *menu) override; void handleMenuAction(QAction *action) override; void setCustomImage(const QString& imagePath); void setOnImage(const QString& imagePath); void setOffImage(const QString& imagePath); void setCurrentSize(QSizeF size); QSizeF currentSize(); QString onImagePath(); QString offImagePath(); void loadImage(); void mousePressEvent(QGraphicsSceneMouseEvent *event) override; void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; private: QString onImagePath_; // ON状态图片路径 QString offImagePath_; // OFF状态图片路径 QPixmap onPixmap_; // ON状态图片 QPixmap offPixmap_; // OFF状态图片 bool resizing_ = false; // 是否正在调整大小 QPointF resizeStartPos_; // 调整大小开始位置 QSizeF originalSize_; // 调整前的原始大小 QSizeF currentSize_ = QSizeF(50, 50); // 当前实际尺寸 int resizeHandleSize_ = 8; // 调整手柄大小 int resizeMargin_ = 5; // 调整边距 }; #endif // LIGHT_H