qt/LedOK/program/ebase.h

86 lines
2.4 KiB
C
Raw Normal View History

2022-08-25 18:37:24 +08:00
#ifndef EBASE_H
#define EBASE_H
#include <QGraphicsObject>
2023-10-23 14:58:29 +08:00
#include "gutil/qjson.h"
2022-08-25 18:37:24 +08:00
#include <QVBoxLayout>
2024-02-21 18:08:50 +08:00
#include <QSpinBox>
2022-08-25 18:37:24 +08:00
#include <QPen>
2023-04-21 11:06:47 +08:00
#include <float.h>
2022-08-25 18:37:24 +08:00
#define m_handleLen 10
class EBase : public QGraphicsObject {
Q_OBJECT
public:
enum ElementType {
Text = QGraphicsItem::UserType + 1,
2024-02-21 18:08:50 +08:00
Image, Video, Gif, Audio,
2022-08-25 18:37:24 +08:00
DClock, AClock, Timer, Environ, Window, Web
};
Q_ENUM(ElementType)
explicit EBase(EBase *multiWin = nullptr);
2023-10-23 14:58:29 +08:00
void setBaseAttr(const JObj &);
void addBaseAttr(JObj &) const;
2022-08-25 18:37:24 +08:00
QRectF boundingRect() const override;
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
2023-10-23 14:58:29 +08:00
virtual JObj attrJson() const = 0;
2022-08-25 18:37:24 +08:00
virtual void loadFiles() {}
virtual void freeFiles() {}
virtual bool save(const QString &) {return true;}
virtual QWidget* attrWgt() = 0;
2023-04-18 14:14:46 +08:00
void addBaseAttrWgt(QBoxLayout *vBox);
2022-08-25 18:37:24 +08:00
inline void setSize(qreal width, qreal height) {
prepareGeometryChange();
mWidth = width;
mHeight = height;
emit sizeChanged();
}
void fitProgSize();
QRectF innerRect() const;
QRectF rect() const { return innerRect(); }
2024-02-21 18:08:50 +08:00
int mType = -1;
EBase *mMultiWin = 0;
qreal mWidth = 0, mHeight = 0;
QSpinBox *fdDuration = 0;
int mStartTime = 0, mDuration = 10;
QString mEntryEffect, mExitEffect;
int mEntryDur = 1, mExitDur = 1;
2022-08-25 18:37:24 +08:00
signals:
void sizeChanged();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *) override;
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
void timerEvent(QTimerEvent *) override;
void setFrmSec(const QPointF &);
void setFrmSecIfNeed(Qt::WindowFrameSection frmSec, Qt::CursorShape cursor);
void clearSnap();
QPen mSidePen;
QRectF m_rL, m_rR, m_rT, m_rB, m_rLT, m_rRT, m_rRB, m_rLB;
QPointF mPressRel{FLT_MAX, FLT_MAX};
Qt::WindowFrameSection mFrmSec{Qt::NoSection};
char mLRSnap{0}, mTBSnap{0};
QList<EBase *> mOtherEles;
int bdImgIdx{-1};
QString bdEff{"rotate"};
int bdSpeed{2};
int bdOff{0};
int bdTimerId{0};
};
#endif // EBASE_H