ledset
This commit is contained in:
parent
f2f5742ba5
commit
71f945caba
|
@ -0,0 +1,98 @@
|
||||||
|
#include "expertboxlayoutwin.h"
|
||||||
|
#include "moduleunit.h"
|
||||||
|
#include "gutil/qgui.h"
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QScrollArea>
|
||||||
|
|
||||||
|
ExpertBoxLayoutWin::ExpertBoxLayoutWin(QWidget *parent) : BaseWin{parent} {
|
||||||
|
//setWindowModality(Qt::WindowModal);
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
setWindowTitle("箱体高级布局");
|
||||||
|
resize(1024, 720);
|
||||||
|
|
||||||
|
auto vBox = new VBox(center);
|
||||||
|
vBox->setContentsMargins(0,0,0,0);
|
||||||
|
vBox->setSpacing(3);
|
||||||
|
vBox->addLayout(addBtns(new QHBoxLayout()));
|
||||||
|
|
||||||
|
auto hBox = new HBox(vBox);
|
||||||
|
vBox = new VBox(hBox);
|
||||||
|
|
||||||
|
vBox->addWidget(new QLabel("模组编辑"));
|
||||||
|
|
||||||
|
auto grid = new Grid(vBox);
|
||||||
|
auto btnAdd = new QPushButton("添加");
|
||||||
|
grid->addWidget(btnAdd, 0, 0);
|
||||||
|
auto btnDel = new QPushButton("删除");
|
||||||
|
grid->addWidget(btnDel, 0, 1);
|
||||||
|
auto btnMove = new QPushButton("移动");
|
||||||
|
grid->addWidget(btnMove, 1, 0);
|
||||||
|
auto btnRotate = new QPushButton("旋转");
|
||||||
|
grid->addWidget(btnRotate, 1, 1);
|
||||||
|
|
||||||
|
vBox->addWidget(new QLabel("HUB口编辑"));
|
||||||
|
|
||||||
|
grid = new Grid(vBox);
|
||||||
|
auto btnPort = new QPushButton("端口");
|
||||||
|
grid->addWidget(btnPort, 0, 0);
|
||||||
|
auto btnManual = new QPushButton("手动");
|
||||||
|
grid->addWidget(btnManual, 0, 1);
|
||||||
|
auto btnUp = new QPushButton("上移");
|
||||||
|
grid->addWidget(btnUp, 1, 0);
|
||||||
|
auto btnDown = new QPushButton("下移");
|
||||||
|
grid->addWidget(btnDown, 1, 1);
|
||||||
|
|
||||||
|
vBox->addWidget(new QLabel("HUB口编辑"));
|
||||||
|
|
||||||
|
grid = new Grid(vBox);
|
||||||
|
auto fdHasPos = new QCheckBox("位置");
|
||||||
|
grid->addWidget(fdHasPos, 0, 0);
|
||||||
|
auto fdHasSize = new QCheckBox("大小");
|
||||||
|
grid->addWidget(fdHasSize, 0, 1);
|
||||||
|
auto fdHasConn = new QCheckBox("连接");
|
||||||
|
grid->addWidget(fdHasConn, 1, 0);
|
||||||
|
auto fdHasName = new QCheckBox("名称");
|
||||||
|
grid->addWidget(fdHasName, 1, 1);
|
||||||
|
auto fdHasOutline = new QCheckBox("轮廓");
|
||||||
|
grid->addWidget(fdHasOutline, 2, 0);
|
||||||
|
auto fdHasRotate = new QCheckBox("旋转");
|
||||||
|
grid->addWidget(fdHasRotate, 2, 1);
|
||||||
|
|
||||||
|
vBox->addStretch();
|
||||||
|
|
||||||
|
vBox = new VBox(hBox);
|
||||||
|
hBox = new HBox(vBox);
|
||||||
|
hBox->addStretch();
|
||||||
|
|
||||||
|
auto scroll = new QScrollArea;
|
||||||
|
vBox->addWidget(scroll);
|
||||||
|
|
||||||
|
auto screen = new QWidget(scroll);
|
||||||
|
screen->setGeometry(0, 0, 1024, 1024);
|
||||||
|
screen->setAutoFillBackground(true);
|
||||||
|
auto pal = palette();
|
||||||
|
pal.setColor(QPalette::Window, QColor(0x222222));
|
||||||
|
screen->setPalette(pal);
|
||||||
|
|
||||||
|
int idx = 0;
|
||||||
|
for(int rr=0; rr<4; rr++) {
|
||||||
|
QString name = "P"+QString::number(rr+1);
|
||||||
|
|
||||||
|
auto unit = new ModuleUnit(this, name, idx, 0, 128, 128, screen);
|
||||||
|
unit->setAutoFillBackground(true);
|
||||||
|
pal.setColor(QPalette::Window, colors[rr]);
|
||||||
|
unit->setPalette(pal);
|
||||||
|
idx += 128;
|
||||||
|
}
|
||||||
|
|
||||||
|
// connect(canvas, &ResizeEmitedWgt::resized, this, [this, canvas, screen] {
|
||||||
|
// screen->resize(qRound(screenWidth*rate), qRound(screenHeight*rate));
|
||||||
|
// auto children = screen->children();
|
||||||
|
// foreach(auto childObj, children) {
|
||||||
|
// auto unit = static_cast<ScreenUnit*>(childObj);
|
||||||
|
// unit->setGeometry(qRound(unit->mX*rate), qRound(unit->mY*rate), qRound(unit->mW*rate), qRound(unit->mH*rate));
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef EXPERTBOXLAYOUTWIN_H
|
||||||
|
#define EXPERTBOXLAYOUTWIN_H
|
||||||
|
|
||||||
|
#include "basewin.h"
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QSpinBox>
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
|
class ExpertBoxLayoutWin : public BaseWin {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ExpertBoxLayoutWin(QWidget *parent = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EXPERTBOXLAYOUTWIN_H
|
|
@ -2,6 +2,7 @@
|
||||||
#include "gutil/qgui.h"
|
#include "gutil/qgui.h"
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
#include "screenunit.h"
|
#include "screenunit.h"
|
||||||
|
#include "expertboxlayoutwin.h"
|
||||||
#include "expertsmartpointsetwin.h"
|
#include "expertsmartpointsetwin.h"
|
||||||
#include "expertscreenconnwin.h"
|
#include "expertscreenconnwin.h"
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
|
@ -9,7 +10,6 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
#include <QStackedLayout>
|
|
||||||
#include <QRadioButton>
|
#include <QRadioButton>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
@ -351,6 +351,10 @@ QTabBar::tab:selected {margin-top: 0; border-bottom: none; color: #acf; backgrou
|
||||||
auto btn = new QPushButton(tr("平面造型"));
|
auto btn = new QPushButton(tr("平面造型"));
|
||||||
btn->setProperty("ss","blue");
|
btn->setProperty("ss","blue");
|
||||||
btn->setMaximumWidth(100);
|
btn->setMaximumWidth(100);
|
||||||
|
connect(btn, &QPushButton::clicked, this, [=] {
|
||||||
|
auto win = new ExpertBoxLayoutWin(this);
|
||||||
|
win->show();
|
||||||
|
});
|
||||||
vvv->addWidget(btn);
|
vvv->addWidget(btn);
|
||||||
}
|
}
|
||||||
connect(fdNormal, &QRadioButton::toggled, this, [=](bool checked) {
|
connect(fdNormal, &QRadioButton::toggled, this, [=](bool checked) {
|
||||||
|
|
|
@ -40,6 +40,18 @@ public:
|
||||||
parent->addWidget(wgt);
|
parent->addWidget(wgt);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
class Grid : public QGridLayout {
|
||||||
|
public:
|
||||||
|
inline Grid(QWidget *parent=0) : QGridLayout(parent) {}
|
||||||
|
inline Grid(QBoxLayout *parent) {
|
||||||
|
parent->addLayout(this);
|
||||||
|
};
|
||||||
|
inline Grid(QStackedLayout *parent) {
|
||||||
|
auto wgt = new QWidget;
|
||||||
|
wgt->setLayout(this);
|
||||||
|
parent->addWidget(wgt);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
class NumTable : public QTableWidget {
|
class NumTable : public QTableWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -35,6 +35,7 @@ SOURCES += \
|
||||||
basewin.cpp \
|
basewin.cpp \
|
||||||
brightwin.cpp \
|
brightwin.cpp \
|
||||||
crc.c \
|
crc.c \
|
||||||
|
expertboxlayoutwin.cpp \
|
||||||
expertscreenconnwin.cpp \
|
expertscreenconnwin.cpp \
|
||||||
expertsmartpointsetwin.cpp \
|
expertsmartpointsetwin.cpp \
|
||||||
expertwin.cpp \
|
expertwin.cpp \
|
||||||
|
@ -43,6 +44,7 @@ SOURCES += \
|
||||||
gutil/qgui.cpp \
|
gutil/qgui.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
mainwin.cpp \
|
mainwin.cpp \
|
||||||
|
moduleunit.cpp \
|
||||||
pcaprethread.cpp \
|
pcaprethread.cpp \
|
||||||
pcapwin.cpp \
|
pcapwin.cpp \
|
||||||
screenunit.cpp \
|
screenunit.cpp \
|
||||||
|
@ -52,6 +54,7 @@ HEADERS += \
|
||||||
basewin.h \
|
basewin.h \
|
||||||
brightwin.h \
|
brightwin.h \
|
||||||
crc.h \
|
crc.h \
|
||||||
|
expertboxlayoutwin.h \
|
||||||
expertscreenconnwin.h \
|
expertscreenconnwin.h \
|
||||||
expertsmartpointsetwin.h \
|
expertsmartpointsetwin.h \
|
||||||
expertwin.h \
|
expertwin.h \
|
||||||
|
@ -59,6 +62,7 @@ HEADERS += \
|
||||||
globalfunc.h \
|
globalfunc.h \
|
||||||
gutil/qgui.h \
|
gutil/qgui.h \
|
||||||
mainwin.h \
|
mainwin.h \
|
||||||
|
moduleunit.h \
|
||||||
pcaprethread.h \
|
pcaprethread.h \
|
||||||
pcapwin.h \
|
pcapwin.h \
|
||||||
screenunit.h \
|
screenunit.h \
|
||||||
|
|
|
@ -0,0 +1,324 @@
|
||||||
|
#include "moduleunit.h"
|
||||||
|
#include "expertwin.h"
|
||||||
|
#include <QDirIterator>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QSpinBox>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
ModuleUnit::ModuleUnit(ExpertWin *expertWin, const QString &name, int x, int y, int w, int h, QWidget *parent) : QWidget{parent}, expertWin{expertWin}, name{name}, mX{x}, mY{y}, mW{w}, mH{h} {
|
||||||
|
setGeometry(x, y, w, h);
|
||||||
|
setMouseTracking(true);
|
||||||
|
auto font = this->font();
|
||||||
|
font.setPixelSize(12);
|
||||||
|
setFont(font);
|
||||||
|
|
||||||
|
mSidePen.setCapStyle(Qt::FlatCap);
|
||||||
|
mSidePen.setDashPattern(QVector<qreal>{2,2});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModuleUnit::paintEvent(QPaintEvent *) {
|
||||||
|
QPainter painter(this);
|
||||||
|
painter.setPen(mSidePen);
|
||||||
|
painter.drawRect(QRectF(0.5, 0.5, width()-1, height()-1));
|
||||||
|
painter.drawText(2, 16, name);
|
||||||
|
painter.drawText(2, 32, "位置: "+QString::number(mX)+", "+QString::number(mY));
|
||||||
|
painter.drawText(2, 48, "大小: "+QString::number(mW)+" x "+QString::number(mH));
|
||||||
|
//磁条吸附时两化吸附的边
|
||||||
|
static QPen snapPen(QColor(0x00ff00), 2);
|
||||||
|
painter.setPen(snapPen);
|
||||||
|
if(mLRSnap==1) painter.drawLine(QPointF(1, 0), QPointF(1, height()));
|
||||||
|
else if(mLRSnap==2) painter.drawLine(QPointF(width()-1, 0), QPointF(width()-1, height()));
|
||||||
|
if(mTBSnap==1) painter.drawLine(QPointF(0, 1), QPointF(width(), 1));
|
||||||
|
else if(mTBSnap==2) painter.drawLine(QPointF(0, height()-1), QPointF(width(), height()-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModuleUnit::setFrmSec(const QPoint &pos) {
|
||||||
|
if(isMaximized()) return;
|
||||||
|
if(pos.y()<8) {
|
||||||
|
if(pos.x()<16) setFrmSecIfNeed(Qt::TopLeftSection, Qt::SizeFDiagCursor);
|
||||||
|
else if(pos.x()<width()-16) setFrmSecIfNeed(Qt::TopSection, Qt::SizeVerCursor);
|
||||||
|
else setFrmSecIfNeed(Qt::TopRightSection, Qt::SizeBDiagCursor);
|
||||||
|
} else if(pos.y()>=height()-8) {
|
||||||
|
if(pos.x()<16) setFrmSecIfNeed(Qt::BottomLeftSection, Qt::SizeBDiagCursor);
|
||||||
|
else if(pos.x()<width()-16) setFrmSecIfNeed(Qt::BottomSection, Qt::SizeVerCursor);
|
||||||
|
else setFrmSecIfNeed(Qt::BottomRightSection, Qt::SizeFDiagCursor);
|
||||||
|
} else if(pos.x()<8) {
|
||||||
|
if(pos.y()<16) setFrmSecIfNeed(Qt::TopLeftSection, Qt::SizeFDiagCursor);
|
||||||
|
else if(pos.y()<height()-16) setFrmSecIfNeed(Qt::LeftSection, Qt::SizeHorCursor);
|
||||||
|
else setFrmSecIfNeed(Qt::BottomLeftSection, Qt::SizeBDiagCursor);
|
||||||
|
} else if(pos.x()>=width()-8) {
|
||||||
|
if(pos.y()<16) setFrmSecIfNeed(Qt::TopRightSection, Qt::SizeBDiagCursor);
|
||||||
|
else if(pos.y()<height()-16) setFrmSecIfNeed(Qt::RightSection, Qt::SizeHorCursor);
|
||||||
|
else setFrmSecIfNeed(Qt::BottomRightSection, Qt::SizeFDiagCursor);
|
||||||
|
} else setFrmSecIfNeed(Qt::TitleBarArea, Qt::SizeAllCursor);
|
||||||
|
}
|
||||||
|
void ModuleUnit::mousePressEvent(QMouseEvent *e) {
|
||||||
|
QWidget::mousePressEvent(e);
|
||||||
|
if(e->button() != Qt::LeftButton) return;
|
||||||
|
setFrmSec(e->pos());
|
||||||
|
if(mFrmSec==Qt::TitleBarArea || mFrmSec==Qt::TopSection || mFrmSec==Qt::LeftSection || mFrmSec==Qt::TopLeftSection) mPressRel = mPressRel = pos() - e->globalPos();
|
||||||
|
else if(mFrmSec==Qt::BottomRightSection) mPressRel = QPoint(width() - e->globalX(), height() - e->globalY());
|
||||||
|
else if(mFrmSec==Qt::RightSection ) mPressRel = QPoint(width() - e->globalX(), height() );
|
||||||
|
else if(mFrmSec==Qt::BottomSection ) mPressRel = QPoint(width() , height() - e->globalY());
|
||||||
|
else if(mFrmSec==Qt::TopRightSection ) mPressRel = geometry().topRight() - e->globalPos();
|
||||||
|
else if(mFrmSec==Qt::BottomLeftSection ) mPressRel = geometry().bottomLeft() - e->globalPos();
|
||||||
|
else if(mFrmSec==Qt::NoSection) mPressRel.setX(INT_MIN);
|
||||||
|
if(mPressRel.x()!=INT_MIN) {
|
||||||
|
mOtherEles.clear();
|
||||||
|
auto parent = this->parentWidget();
|
||||||
|
if(0 == parent) return;
|
||||||
|
auto items = parent->children();
|
||||||
|
foreach(auto item, items) {
|
||||||
|
if(item==this) continue;
|
||||||
|
auto ele = static_cast<ModuleUnit*>(item);
|
||||||
|
mOtherEles.append(ele);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModuleUnit::mouseReleaseEvent(QMouseEvent *event) {
|
||||||
|
QWidget::mouseReleaseEvent(event);
|
||||||
|
if(Qt::LeftButton == event->button()) {
|
||||||
|
mPressRel.setX(INT_MIN);
|
||||||
|
clearSnap();
|
||||||
|
foreach(auto ele, mOtherEles) ele->clearSnap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#define SnapSpace 6
|
||||||
|
void ModuleUnit::mouseMoveEvent(QMouseEvent *e){
|
||||||
|
if(! (e->buttons() & Qt::LeftButton)) {
|
||||||
|
setFrmSec(e->pos());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(mFrmSec==Qt::NoSection || mPressRel.x()==INT_MIN) return;
|
||||||
|
auto mousePos = e->globalPos();
|
||||||
|
auto dstHor = mPressRel.x() + mousePos.x();
|
||||||
|
auto dstVer = mPressRel.y() + mousePos.y();
|
||||||
|
mLRSnap = mTBSnap = 0;
|
||||||
|
foreach(auto ele, mOtherEles) ele->clearSnap();
|
||||||
|
if(mFrmSec==Qt::TitleBarArea) {
|
||||||
|
dstHor = qBound(0, dstHor, expertWin->screenWidth - width());
|
||||||
|
dstVer = qBound(0, dstVer, expertWin->screenHeight - height());
|
||||||
|
if(dstHor==0) mLRSnap = 1;
|
||||||
|
else if(dstHor==expertWin->screenWidth - width()) mLRSnap = 2;
|
||||||
|
if(dstVer==0) mTBSnap = 1;
|
||||||
|
else if(dstVer==expertWin->screenHeight - height()) mTBSnap = 2;
|
||||||
|
if(mLRSnap==0) foreach(ModuleUnit *ele, mOtherEles) {//左右
|
||||||
|
if(abs(dstHor - ele->x()) < SnapSpace && ele->x() <= expertWin->screenWidth - width()) {
|
||||||
|
dstHor = ele->x();
|
||||||
|
mLRSnap = 1;
|
||||||
|
ele->mLRSnap = 1;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto eleRight = ele->x() + ele->width();
|
||||||
|
if(abs(dstHor - eleRight) < SnapSpace && eleRight <= expertWin->screenWidth - width()) {
|
||||||
|
dstHor = eleRight;
|
||||||
|
mLRSnap = 1;
|
||||||
|
ele->mLRSnap = 2;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto right = dstHor + width();
|
||||||
|
if(abs(right - ele->x()) < SnapSpace && ele->x() - width() >= 0) {
|
||||||
|
dstHor = ele->x() - width();
|
||||||
|
mLRSnap = 2;
|
||||||
|
ele->mLRSnap = 1;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(abs(right - eleRight) < SnapSpace && eleRight - width() >= 0) {
|
||||||
|
dstHor = eleRight - width();
|
||||||
|
mLRSnap = 2;
|
||||||
|
ele->mLRSnap = 2;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(mTBSnap==0) foreach(ModuleUnit *ele, mOtherEles) {//上下
|
||||||
|
if(abs(dstVer-ele->y()) < SnapSpace && ele->y() <= expertWin->screenHeight - height()) {
|
||||||
|
dstVer = ele->y();
|
||||||
|
mTBSnap = 1;
|
||||||
|
ele->mTBSnap = 1;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto eleBtm = ele->y() + ele->height();
|
||||||
|
if(abs(dstVer - eleBtm) < SnapSpace && eleBtm <= expertWin->screenHeight - height()) {
|
||||||
|
dstVer = eleBtm;
|
||||||
|
mTBSnap = 1;
|
||||||
|
ele->mTBSnap = 2;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto btm = dstVer + height();
|
||||||
|
if(abs(btm - ele->y()) < SnapSpace && ele->y() - height() >= 0) {
|
||||||
|
dstVer = ele->y() - height();
|
||||||
|
mTBSnap = 2;
|
||||||
|
ele->mTBSnap = 1;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(abs(btm - eleBtm) < SnapSpace && eleBtm - height() >= 0) {
|
||||||
|
dstVer = eleBtm - height();
|
||||||
|
mTBSnap = 2;
|
||||||
|
ele->mTBSnap = 2;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
move(dstHor, dstVer);
|
||||||
|
mX = qRound(dstHor / expertWin->rate);
|
||||||
|
mY = qRound(dstVer / expertWin->rate);
|
||||||
|
update();
|
||||||
|
} else if(mFrmSec==Qt::BottomRightSection) {
|
||||||
|
if(dstHor < m_handleLen) dstHor = m_handleLen;
|
||||||
|
if(dstVer < m_handleLen) dstVer = m_handleLen;
|
||||||
|
if(expertWin->screenWidth>0 && expertWin->screenHeight>0) {
|
||||||
|
dstHor = qMin(dstHor, expertWin->screenWidth - x());
|
||||||
|
dstVer = qMin(dstVer, expertWin->screenHeight - y());
|
||||||
|
}
|
||||||
|
resize(dstHor, dstVer);
|
||||||
|
mW = qRound(dstHor / expertWin->rate);
|
||||||
|
mH = qRound(dstVer / expertWin->rate);
|
||||||
|
} else if(mFrmSec==Qt::RightSection) {
|
||||||
|
if(dstHor < m_handleLen) dstHor = m_handleLen;
|
||||||
|
if(expertWin->screenWidth>0 && expertWin->screenHeight>0) dstHor = qMin(dstHor, expertWin->screenWidth - x());
|
||||||
|
auto right = x() + dstHor;
|
||||||
|
if(right < expertWin->screenWidth-8) foreach(ModuleUnit *ele, mOtherEles) {//左右
|
||||||
|
if(abs(right - ele->x()) < SnapSpace) {
|
||||||
|
dstHor = ele->x() - x();
|
||||||
|
mLRSnap = 2;
|
||||||
|
ele->mLRSnap = 1;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto eleRight = ele->x() + ele->width();
|
||||||
|
if(abs(right - eleRight) < SnapSpace) {
|
||||||
|
dstHor = eleRight - x();
|
||||||
|
mLRSnap = 2;
|
||||||
|
ele->mLRSnap = 2;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resize(dstHor, mPressRel.y());
|
||||||
|
mW = qRound(dstHor / expertWin->rate);
|
||||||
|
} else if(mFrmSec==Qt::BottomSection) {
|
||||||
|
if(dstVer < m_handleLen) dstVer = m_handleLen;
|
||||||
|
if(expertWin->screenWidth>0 && expertWin->screenHeight>0) dstVer = qMin(dstVer, expertWin->screenHeight - y());
|
||||||
|
auto btm = y() + dstVer;
|
||||||
|
if(btm < expertWin->screenHeight-8) foreach(ModuleUnit *ele, mOtherEles) {//上下
|
||||||
|
auto eleBtm = ele->y() + ele->height();
|
||||||
|
if(abs(btm - ele->y()) < SnapSpace) {
|
||||||
|
dstVer = ele->y() - y();
|
||||||
|
mTBSnap = 2;
|
||||||
|
ele->mTBSnap = 1;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(abs(btm - eleBtm) < SnapSpace) {
|
||||||
|
dstVer = eleBtm - y();
|
||||||
|
mTBSnap = 2;
|
||||||
|
ele->mTBSnap = 2;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resize(mPressRel.rx(), dstVer);
|
||||||
|
mH = qRound(dstVer / expertWin->rate);
|
||||||
|
} else {
|
||||||
|
auto geo = geometry();
|
||||||
|
if(mFrmSec==Qt::LeftSection) {
|
||||||
|
dstHor = qMin(dstHor, geo.right() - m_handleLen);
|
||||||
|
if(dstHor < 0) dstHor = 0;
|
||||||
|
if(dstHor > 8) foreach(ModuleUnit *ele, mOtherEles) {//左右
|
||||||
|
if(abs(dstHor - ele->x()) < SnapSpace) {
|
||||||
|
dstHor = ele->x();
|
||||||
|
mLRSnap = 1;
|
||||||
|
ele->mLRSnap = 1;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto eleRight = ele->x() + ele->width();
|
||||||
|
if(abs(dstHor - eleRight) < SnapSpace) {
|
||||||
|
dstHor = eleRight;
|
||||||
|
mLRSnap = 1;
|
||||||
|
ele->mLRSnap = 2;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
geo.setLeft(dstHor);
|
||||||
|
} else if(mFrmSec==Qt::TopSection) {
|
||||||
|
dstVer = qMin(dstVer, geo.bottom() - m_handleLen);
|
||||||
|
if(dstVer < 0) dstVer = 0;
|
||||||
|
if(dstVer > 8) foreach(ModuleUnit *ele, mOtherEles) {//上下
|
||||||
|
if(abs(dstVer - ele->y()) < SnapSpace) {
|
||||||
|
dstVer = ele->y();
|
||||||
|
mTBSnap = 1;
|
||||||
|
ele->mTBSnap = 1;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto eleBtm = ele->y() + ele->height();
|
||||||
|
if(abs(dstVer - eleBtm) < SnapSpace) {
|
||||||
|
dstVer = eleBtm;
|
||||||
|
mTBSnap = 1;
|
||||||
|
ele->mTBSnap = 2;
|
||||||
|
ele->update();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
geo.setTop(dstVer);
|
||||||
|
} else if(mFrmSec==Qt::TopLeftSection) {
|
||||||
|
dstHor = qMin(dstHor, geo.right() - m_handleLen);
|
||||||
|
dstVer = qMin(dstVer, geo.bottom() - m_handleLen);
|
||||||
|
if(dstHor < 0) dstHor = 0;
|
||||||
|
if(dstVer < 0) dstVer = 0;
|
||||||
|
geo.setLeft(dstHor);
|
||||||
|
geo.setTop(dstVer);
|
||||||
|
} else if(mFrmSec==Qt::TopRightSection) {
|
||||||
|
dstHor = qMax(dstHor, geo.x() + m_handleLen);
|
||||||
|
dstVer = qMin(dstVer, geo.bottom() - m_handleLen);
|
||||||
|
if(dstHor > expertWin->screenWidth) dstHor = expertWin->screenWidth;
|
||||||
|
if(dstVer < 0) dstVer = 0;
|
||||||
|
geo.setRight(dstHor);
|
||||||
|
geo.setTop(dstVer);
|
||||||
|
} else if(mFrmSec==Qt::BottomLeftSection) {
|
||||||
|
dstHor = qMin(dstHor, geo.right() - m_handleLen);
|
||||||
|
dstVer = qMax(dstVer, geo.y() + m_handleLen);
|
||||||
|
if(dstHor < 0) dstHor = 0;
|
||||||
|
if(dstVer > expertWin->screenHeight) dstVer = expertWin->screenHeight;
|
||||||
|
geo.setLeft(dstHor);
|
||||||
|
geo.setBottom(dstVer);
|
||||||
|
}
|
||||||
|
setGeometry(geo);
|
||||||
|
mX = qRound(geo.x() / expertWin->rate);
|
||||||
|
mY = qRound(geo.y() / expertWin->rate);
|
||||||
|
mW = qRound(geo.width() / expertWin->rate);
|
||||||
|
mH = qRound(geo.height() / expertWin->rate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ModuleUnit::leaveEvent(QEvent *) {
|
||||||
|
setFrmSecIfNeed(Qt::NoSection, Qt::ArrowCursor);
|
||||||
|
mPressRel.setX(INT_MIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModuleUnit::setFrmSecIfNeed(Qt::WindowFrameSection frmSec, Qt::CursorShape cursor) {
|
||||||
|
if(mFrmSec==frmSec) return;
|
||||||
|
mFrmSec = frmSec;
|
||||||
|
if(cursor==Qt::ArrowCursor) unsetCursor();
|
||||||
|
else setCursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModuleUnit::clearSnap() {
|
||||||
|
if(mLRSnap==0 && mTBSnap==0) return;
|
||||||
|
mLRSnap = mTBSnap = 0;
|
||||||
|
update();
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
#ifndef MODULEUNIT_H
|
||||||
|
#define MODULEUNIT_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QPen>
|
||||||
|
|
||||||
|
#define m_handleLen 10
|
||||||
|
class ExpertWin;
|
||||||
|
class ModuleUnit : public QWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ModuleUnit(ExpertWin *, const QString &name, int x, int y, int w, int h, QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
ExpertWin *expertWin{0};
|
||||||
|
QString name;
|
||||||
|
int mX, mY, mW, mH;
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *) override;
|
||||||
|
void mousePressEvent(QMouseEvent *) override;
|
||||||
|
void mouseReleaseEvent(QMouseEvent *) override;
|
||||||
|
void mouseMoveEvent(QMouseEvent *) override;
|
||||||
|
void leaveEvent(QEvent *) override;
|
||||||
|
|
||||||
|
void setFrmSec(const QPoint &);
|
||||||
|
void setFrmSecIfNeed(Qt::WindowFrameSection frmSec, Qt::CursorShape cursor);
|
||||||
|
void clearSnap();
|
||||||
|
QPen mSidePen{Qt::white};
|
||||||
|
|
||||||
|
QPoint mPressRel{INT_MIN, INT_MIN};
|
||||||
|
Qt::WindowFrameSection mFrmSec{Qt::NoSection};
|
||||||
|
char mLRSnap{0}, mTBSnap{0};
|
||||||
|
QList<ModuleUnit *> mOtherEles;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MODULEUNIT_H
|
Loading…
Reference in New Issue
Block a user