qt/LedOK/program/ebase.h
2024-08-07 18:18:37 +08:00

89 lines
2.5 KiB
C++

#ifndef EBASE_H
#define EBASE_H
#include <QGraphicsObject>
#include "gutil/qjson.h"
#include <QVBoxLayout>
#include <QSpinBox>
#include <QPen>
#include <float.h>
#define m_handleLen 10
class EBase : public QGraphicsObject {
Q_OBJECT
public:
enum ElementType {
Text = QGraphicsItem::UserType + 1,
Image, Video, Gif, Audio,
DClock, AClock, Timer, Timer2, Environ, Window, Web
};
Q_ENUM(ElementType)
explicit EBase(EBase *multiWin = nullptr);
void setBaseAttr(const JObj &);
void addBaseAttr(JObj &) const;
QRectF boundingRect() const override;
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
virtual JObj attrJson() const = 0;
virtual void loadFiles() {}
virtual void freeFiles() {}
virtual bool save(const QString &) {return true;}
virtual QWidget* attrWgt() = 0;
void addBaseAttrWgt(QBoxLayout *vBox);
inline void setSize(qreal width, qreal height) {
prepareGeometryChange();
mWidth = width;
mHeight = height;
emit sizeChanged();
}
void fitProgSize();
QRectF innerRect() const;
QRectF rect() const { return innerRect(); }
int mType = -1;
EBase *mMultiWin = 0;
qreal mWidth = 0, mHeight = 0;
int _rotate = 0;
QSpinBox *fdDuration = 0;
int mStartTime = 0, mDuration = 10;
QString mEntryEffect, mExitEffect;
int mEntryDur = 1, mExitDur = 1;
double _opacity = 1, _blink = 1;
bool _hasBlink = false, _hasBreathe = false;
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};
std::vector<EBase *> mOtherEles;
int bdImgIdx{-1};
QString bdEff{"rotate"};
int bdSpeed{2};
int bdOff{0};
int bdTimerId{0};
};
#endif // EBASE_H