|
- #ifndef BUTTON_H
- #define BUTTON_H
- #include "item.h"
-
- class Button : public Item
- {
- public:
- Button(const QString &type);
- QRectF boundingRect() const override;
- void paint(QPainter *painter,
- const QStyleOptionGraphicsItem *option,
- QWidget *) override;
- void addMenuActions(QMenu *menu) override;
- void handleMenuAction(QAction *action) override;
- void setCustomImage(const QString& imagePath);
- void loadImage();
-
- // 鼠标事件处理
- void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
- void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
-
- private:
- QString imagePath_;
- QPixmap customPixmap_;
- bool resizing_ = false; // 是否正在调整大小
- QPointF resizeStartPos_; // 调整大小开始位置
- QSizeF originalSize_; // 调整前的原始大小
- QSizeF currentSize_ = QSizeF(50, 50); // 当前实际尺寸
- int resizeHandleSize_ = 8; // 调整手柄大小
- int resizeMargin_ = 5; // 调整边距
- };
-
- #endif // BUTTON_H
|