118 lines
3.1 KiB
C++
118 lines
3.1 KiB
C++
#ifndef LOQGRAPHICSOBJECT_H
|
|
#define LOQGRAPHICSOBJECT_H
|
|
|
|
#include <cmath>
|
|
#include <QDebug>
|
|
#include <QPainter>
|
|
#include <QPainterPath>
|
|
#include <QGraphicsScene>
|
|
#include <QGraphicsObject>
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#define INVALID_RECT QRect(-1, -5, -6, -8)
|
|
|
|
class LoQGraphicsObject : public QGraphicsObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
typedef enum {
|
|
NONE = 0,
|
|
LT,
|
|
T,
|
|
RT,
|
|
L,
|
|
R,
|
|
LB,
|
|
B,
|
|
RB
|
|
} HANDLE_DIR;
|
|
|
|
public:
|
|
enum InteractiveType {
|
|
Dynamic = 0,
|
|
Static,
|
|
Custom
|
|
};
|
|
|
|
public:
|
|
explicit LoQGraphicsObject(InteractiveType type = Dynamic, QGraphicsItem *parent = nullptr);
|
|
LoQGraphicsObject(QRectF rect, InteractiveType type = Dynamic, QGraphicsItem *parent = nullptr);
|
|
LoQGraphicsObject(qreal x, qreal y, qreal w, qreal h, InteractiveType type = Dynamic, QGraphicsItem *parent = nullptr);
|
|
|
|
private:
|
|
void init();
|
|
|
|
public:
|
|
virtual QRectF boundingRect() const override;
|
|
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
|
virtual void setInteractiveType(InteractiveType type = Dynamic);
|
|
|
|
public:
|
|
InteractiveType interactiveType() const { return m_interactiveType; }
|
|
QRectF rect() const { return QRectF(0, 0, m_w, m_h); }
|
|
QRectF geometry() const { return QRectF(x(), y(), m_w, m_h); }
|
|
|
|
public:
|
|
void setRLimit(const QRectF &r);
|
|
QRectF rLimit() const { return m_rLimit; }
|
|
|
|
signals:
|
|
void requestUpdate(const QRectF &);
|
|
void geometryChanged(const QRectF &);
|
|
void rectChanged(const QRectF &);
|
|
|
|
void sigCiTie(bool,int);
|
|
public slots:
|
|
void setGeometry (qreal x, qreal y, qreal w, qreal h) { setGeometry(QRectF(x, y, w, h)); }
|
|
void setGeometry (const QRectF &r);
|
|
void updateGeometry();
|
|
void updateGeometry(const QRectF &gLast) { updateGeometry(geometry(), gLast); }
|
|
void updateGeometry(const QRectF &gCur, const QRectF &gLast);
|
|
void setBrightBianLeft(bool);
|
|
void setBrightBianTop(bool);
|
|
void setBrightBianRight(bool);
|
|
void setBrightBianbottom(bool);
|
|
|
|
protected:
|
|
int handleLen() const { return m_handleLen; }
|
|
QPointF pointToParent(const QPointF &p);
|
|
HANDLE_DIR handleDir(const QPointF &p);
|
|
void adjustHandle();
|
|
|
|
private:
|
|
InteractiveType m_interactiveType;
|
|
bool m_movable;
|
|
int m_handleLen;
|
|
QPen m_handlePen;
|
|
QPen m_borderPen;
|
|
|
|
private:
|
|
qreal m_w;
|
|
qreal m_h;
|
|
QRectF m_rLT;
|
|
QRectF m_rT;
|
|
|
|
QRectF m_rRT;
|
|
QRectF m_rL;
|
|
QRectF m_rR;
|
|
QRectF m_rLB;
|
|
QRectF m_rB;
|
|
QRectF m_rRB;
|
|
QRectF m_rOrg;
|
|
QPointF m_pOrg;
|
|
HANDLE_DIR m_hDir;
|
|
QRectF m_rLimit;
|
|
bool bMousePress=false;
|
|
bool bLeftCitie=false;
|
|
bool bRightCitie=false;
|
|
bool bTopCitie=false;
|
|
bool bBottomCitie=false;
|
|
int m_keyPressId=0;
|
|
|
|
};
|
|
|
|
#endif // LOQGRAPHICSOBJECT_H
|