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

82 lines
2.1 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
#include <QObject>
#include <QGraphicsRectItem>
#include <QGraphicsSceneMouseEvent>
#include <QBrush>
#include <QDebug>
#include <QPen>
#include <QPainter>
#include <cmath>
#include "global.h"
#include "GlobalDefine.h"
class MyDrawRectItem : public QObject, public QGraphicsRectItem
{
Q_OBJECT
public:
enum TransformType {
NONE,
MOVE,
ROTATE,
SCALE
};
public:
MyDrawRectItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent = nullptr)
: QGraphicsRectItem(x, y, width, height, parent) {
}
~MyDrawRectItem();
int Id() const { return m_id; }
void Id(int val) { m_id = val; }
double RectX() const { return m_rectX; }
void RectX(double val) { m_rectX = val; }
double RectY() const { return m_rectY; }
void RectY(double val) { m_rectY = val; }
double Width() const { return m_width; }
void Width(double val) { m_width = val; }
double Height() const { return m_height; }
void Height(double val) { m_height = val; }
private:
void CountPerVertexCoord(double xCoord, double yCoord, int pointPos); //pointPos:0:左下1右上2右下
void CountRectVertexCoord();
public:
void SetDrawRectAttr(double x1, double y1, double width, double height);
void SetActualDieCoordAndUpdate(double x1, double y1, double width, double height, double angle);
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
signals:
void signal_select(int id);
private:
//矩形属性:
double m_rectX;
double m_rectY;
double m_width;
double m_height;
double m_rotateAngle = 0;
double m_leftDownX;
double m_leftDownY;
double m_rightTopX;
double m_rightTopY;
double m_rightDownX;
double m_rightDownY;
QLineF m_levelLine;
int m_id;
bool m_isMoustLeftPress = false;
TransformType m_translteType;
QPointF m_mousePressDownPos; //鼠标按下时在场景中的位置
double m_backupWidth = 0.0;
double m_backupHeight = 0.0;
double m_initScale = 1.0;
double m_nowScale = 0;
};