qt/ledset/expertboxlayoutwin.h
2023-09-01 16:17:33 +08:00

77 lines
2.1 KiB
C++

#ifndef EXPERTBOXLAYOUTWIN_H
#define EXPERTBOXLAYOUTWIN_H
#include "basewin.h"
#include "gutil/qjson.h"
#include <QLabel>
#include <QButtonGroup>
#include <QCheckBox>
class ExpertWin;
class BoxPanel;
class ExpertBoxLayoutWin : public BaseWin {
Q_OBJECT
public:
explicit ExpertBoxLayoutWin(ExpertWin *parent = 0);
QCheckBox *fdHasPos, *fdHasSize, *fdHasConn, *fdHasName, *fdHasOutline, *fdSnap;
QButtonGroup *grpGrp;
BoxPanel *box{0};
QLabel *fdModNum, *fdBoxSize;
};
class ModuleUnit;
class BoxPanel : public QWidget {
Q_OBJECT
public:
explicit BoxPanel(ExpertBoxLayoutWin *boxWin) : boxWin(boxWin) {
setFocusPolicy(Qt::ClickFocus);
}
void fitSize() {
boxRect = childrenRect();
auto www = qMax(1000, boxRect.x()+boxRect.width()+1);
auto hhh = qMax(1000, boxRect.y()+boxRect.height()+1);
if(www!=width() || hhh!=height()) resize(www, hhh);
else update();
boxWin->fdBoxSize->setText(QString("%1 x %2").arg(boxRect.width()).arg(boxRect.height()));
}
void del();
QRect boxRect, grpRect;
double rate{1};
QRectF rect;
std::vector<ModuleUnit *> sels;
std::vector<ModuleUnit *> copieds;
ExpertBoxLayoutWin *boxWin;
bool isDrawing{false};
protected:
void keyPressEvent(QKeyEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *event) override;
void paintEvent(QPaintEvent *event) override;
};
class ModuleUnit : public QWidget {
Q_OBJECT
public:
explicit ModuleUnit(int, int, int, int, const JObj &module, const QString &name, QWidget *parent = 0);
void drawed();
BoxPanel *box;
QPoint mPressRel{INT_MIN, INT_MIN};
int mX, mY, mW, mH;
JObj mModule;
QString name;
bool isSel = false;
bool isVerticalMirror = false;
bool isHorizonMirror = false;
protected:
void mousePressEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
};
#endif // EXPERTBOXLAYOUTWIN_H