151 lines
3.9 KiB
C++
151 lines
3.9 KiB
C++
#ifndef EOBJECT_H
|
|
#define EOBJECT_H
|
|
#include "loappconfig.h"
|
|
#include "loapptools.h"
|
|
#include "globaldefine.h"
|
|
#include <math.h>
|
|
#include <QGraphicsObject>
|
|
#include <QGraphicsScene>
|
|
|
|
#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
|
|
#define INVALID_RECT QRect(-1, -5, -6, -8)
|
|
|
|
struct BorderImg {
|
|
QString name;
|
|
QPixmap img;
|
|
};
|
|
|
|
class eObjectAttr;
|
|
class eObject : public QGraphicsObject {
|
|
Q_OBJECT
|
|
public:
|
|
static QVector<BorderImg> bdImgs;
|
|
static int maxImgWidth;
|
|
typedef enum {
|
|
NONE = 0,
|
|
LT,
|
|
T,
|
|
RT,
|
|
L,
|
|
R,
|
|
LB,
|
|
B,
|
|
RB
|
|
} HANDLE_DIR;
|
|
|
|
enum InteractiveType {
|
|
Dynamic = 0,
|
|
Static,
|
|
Custom
|
|
};
|
|
|
|
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;
|
|
|
|
virtual QRectF boundingRect() const override;
|
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
|
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *) override;
|
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *) override;
|
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
|
|
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override{};
|
|
virtual QWidget* wAttrElement() = 0;
|
|
|
|
virtual QWidget* wAttr();
|
|
virtual QStringList filesList() const { return QStringList(); }
|
|
virtual bool save(const QString &pRoot) = 0;
|
|
virtual QJsonObject elementJson() const;
|
|
|
|
void setRLimit(const QRectF &r);
|
|
QRectF rLimit() const { return m_rLimit; }
|
|
InteractiveType interactiveType() const { return m_interactiveType; }
|
|
QRectF rect() const { return QRectF(0, 0, width, height); }
|
|
QRectF geometry() const { return QRectF(x(), y(), width, height); }
|
|
|
|
QString getFileMd5(QString filePath);
|
|
|
|
signals:
|
|
void requestUpdate(const QRectF &);
|
|
void geometryChanged(const QRectF &);
|
|
void rectChanged(const QRectF &);
|
|
void sigCiTie(bool,int);
|
|
|
|
void sPlayBQ();
|
|
void sStopBQ();
|
|
|
|
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);
|
|
|
|
virtual void playElectment() {}
|
|
virtual void stopElectment() {}
|
|
|
|
protected:
|
|
int handleLen() const { return m_handleLen; }
|
|
QPointF pointToParent(const QPointF &p);
|
|
HANDLE_DIR handleDir(const QPointF &p);
|
|
void adjustHandle();
|
|
|
|
InteractiveType m_interactiveType;
|
|
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;
|
|
HANDLE_DIR m_hDir;
|
|
QRectF m_rLimit;
|
|
bool bMousePress=false;
|
|
bool bLeftCitie=false, bRightCitie=false, bTopCitie=false, bBottomCitie=false;
|
|
int m_keyPressId=0;
|
|
|
|
eObjectAttr *m_wAttr;
|
|
|
|
int bdImgIdx = -1;
|
|
void init();
|
|
};
|
|
|
|
#endif // EOBJECT_H
|