qt/LedOK/wProgramManager/wEditProgram/wElement/eobject.h

151 lines
3.9 KiB
C
Raw Normal View History

2022-01-04 18:11:48 +08:00
#ifndef EOBJECT_H
#define EOBJECT_H
2022-01-07 18:22:58 +08:00
#include "loappconfig.h"
#include "loapptools.h"
#include "globaldefine.h"
2022-01-04 18:11:48 +08:00
#include <math.h>
2022-01-07 18:22:58 +08:00
#include <QGraphicsObject>
#include <QGraphicsScene>
2022-01-04 18:11:48 +08:00
#include <QDebug>
#include <QPainter>
#include <QJsonValue>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QWidget>
#include <QSpinBox>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QHBoxLayout>
#include <QVBoxLayout>
#define MACRO_DEFAULT_PLAYDURATION 10
2022-01-07 18:22:58 +08:00
#define INVALID_RECT QRect(-1, -5, -6, -8)
2022-01-04 18:11:48 +08:00
2022-01-20 10:08:17 +08:00
struct BorderImg {
QString name;
QPixmap img;
};
2022-01-04 18:11:48 +08:00
class eObjectAttr;
2022-01-07 18:22:58 +08:00
class eObject : public QGraphicsObject {
2022-01-04 18:11:48 +08:00
Q_OBJECT
public:
2022-01-20 10:08:17 +08:00
static QVector<BorderImg> bdImgs;
static int maxImgWidth;
2022-01-07 18:22:58 +08:00
typedef enum {
NONE = 0,
LT,
T,
RT,
L,
R,
LB,
B,
RB
} HANDLE_DIR;
enum InteractiveType {
Dynamic = 0,
Static,
Custom
};
2022-01-04 18:11:48 +08:00
enum ElementType {
Text = QGraphicsItem::UserType + 1,
Photo,
Movie,
Gif,
DClock,
AClock,
Audio,
Office,
Temp,
Weather,
Rss,
Timer,
ColorText,
Window
};
explicit eObject(InteractiveType type = Dynamic, QGraphicsItem *parent = nullptr);
explicit eObject(QRectF rect, InteractiveType type = Dynamic, QGraphicsItem *parent = nullptr);
explicit eObject(const QJsonObject &json, InteractiveType type = Dynamic, QGraphicsItem *parent = nullptr);
int m_iType=-1;
2022-01-07 18:22:58 +08:00
virtual QRectF boundingRect() const override;
2022-01-20 10:08:17 +08:00
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *) override;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *) override;
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
2022-01-07 18:22:58 +08:00
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override{};
2022-01-04 18:11:48 +08:00
virtual QWidget* wAttrElement() = 0;
virtual QWidget* wAttr();
virtual QStringList filesList() const { return QStringList(); }
2022-01-20 10:08:17 +08:00
virtual bool save(const QString &pRoot) = 0;
2022-01-04 18:11:48 +08:00
virtual QJsonObject elementJson() const;
2022-01-07 18:22:58 +08:00
void setRLimit(const QRectF &r);
QRectF rLimit() const { return m_rLimit; }
InteractiveType interactiveType() const { return m_interactiveType; }
2022-01-20 10:08:17 +08:00
QRectF rect() const { return QRectF(0, 0, width, height); }
QRectF geometry() const { return QRectF(x(), y(), width, height); }
2022-01-07 18:22:58 +08:00
2022-01-04 18:11:48 +08:00
QString getFileMd5(QString filePath);
2022-01-20 10:08:17 +08:00
signals:
2022-01-07 18:22:58 +08:00
void requestUpdate(const QRectF &);
void geometryChanged(const QRectF &);
void rectChanged(const QRectF &);
void sigCiTie(bool,int);
2022-01-04 18:11:48 +08:00
void sPlayBQ();
void sStopBQ();
public slots:
2022-01-07 18:22:58 +08:00
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);
2022-01-04 18:11:48 +08:00
virtual void playElectment() {}
virtual void stopElectment() {}
2022-01-07 18:22:58 +08:00
protected:
int handleLen() const { return m_handleLen; }
QPointF pointToParent(const QPointF &p);
HANDLE_DIR handleDir(const QPointF &p);
void adjustHandle();
InteractiveType m_interactiveType;
2022-01-20 10:08:17 +08:00
bool m_movable;
int m_handleLen;
QPen m_handlePen;
QPen m_borderPen;
qreal width, height;
QRectF m_rL, m_rR, m_rT, m_rB, m_rLT, m_rRT, m_rRB, m_rLB;
QRectF m_rOrg;
QPointF m_pOrg;
2022-01-07 18:22:58 +08:00
HANDLE_DIR m_hDir;
2022-01-20 10:08:17 +08:00
QRectF m_rLimit;
bool bMousePress=false;
bool bLeftCitie=false, bRightCitie=false, bTopCitie=false, bBottomCitie=false;
2022-01-07 18:22:58 +08:00
int m_keyPressId=0;
2022-01-04 18:11:48 +08:00
eObjectAttr *m_wAttr;
2022-01-20 10:08:17 +08:00
int bdImgIdx = -1;
2022-01-07 18:22:58 +08:00
void init();
2022-01-04 18:11:48 +08:00
};
#endif // EOBJECT_H