539 lines
21 KiB
C++
539 lines
21 KiB
C++
#include "QtSaveImgSet.h"
|
|
#include "QScreen"
|
|
|
|
QtSaveImgSet::QtSaveImgSet(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
{
|
|
ui.setupUi(this);
|
|
//追踪鼠标,写在构造函数中
|
|
this->setMouseTracking(true);
|
|
ui.centralWidget->setMouseTracking(true);
|
|
ui.title->setMouseTracking(true);
|
|
|
|
ui.label_icon->setStyleSheet("image: url(./Icon/logo_Dongsheng.png);");
|
|
setWindowFlags(Qt::FramelessWindowHint); //隐藏标题栏
|
|
ui.pushButton_min->setText("");
|
|
ui.pushButton_close->setText("");
|
|
ui.pushButton_max->setText("");
|
|
ui.pushButton_min->setStyleSheet("background-color:transparent;image: url(./Icon/min_n.png);");
|
|
ui.pushButton_close->setStyleSheet("background-color:transparent;image: url(./Icon/close_n.png);");
|
|
ui.pushButton_max->setStyleSheet("background-color:transparent;image: url(./Icon/Max_n.png);");
|
|
ui.pushButton_max->hide();
|
|
connect(ui.pushButton_min, &QPushButton::pressed, [=]() {
|
|
this->showMinimized();
|
|
qApp->processEvents();
|
|
});
|
|
connect(ui.pushButton_close, &QPushButton::clicked, [=]() {
|
|
this->close();
|
|
qApp->processEvents();
|
|
});
|
|
|
|
QScreen* screen = QGuiApplication::primaryScreen();
|
|
QSize screenSize = screen->size();
|
|
static int screenWidth = screenSize.width();
|
|
static int screenHeight = screenSize.height();
|
|
qDebug() << "Screen resolution: " << screenWidth << "x" << screenHeight;
|
|
|
|
static int maxClickedNum = 1;
|
|
setWindowFlags(Qt::FramelessWindowHint); //隐藏标题栏
|
|
//this->showNormal();
|
|
this->resize(screenWidth / 3, screenHeight / 3 + 100);
|
|
this->move(screenWidth / 4, screenHeight / 4);
|
|
|
|
|
|
|
|
//搜索到的相机列表
|
|
ui.tableWidget->setColumnCount(7);
|
|
headerLabels << "序号" << "相机key"<<"界面窗口名称" << "原图" << "Seg图" << "Class图" << "结果图";
|
|
ui.tableWidget->setHorizontalHeaderLabels(headerLabels);
|
|
ui.tableWidget->setColumnWidth(0, 50);
|
|
ui.tableWidget->setColumnWidth(1, 150);
|
|
ui.tableWidget->setColumnWidth(2, 150);
|
|
ui.tableWidget->setColumnWidth(3, 100);
|
|
ui.tableWidget->setColumnWidth(4, 100);
|
|
ui.tableWidget->setColumnWidth(5, 100);
|
|
ui.tableWidget->setColumnWidth(6, 100);
|
|
ui.tableWidget->setMouseTracking(true);
|
|
ui.tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); // 整行选中
|
|
ui.tableWidget->horizontalHeader()->setSectionsClickable(false);
|
|
ui.tableWidget->verticalHeader()->hide();
|
|
//ui.tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
|
ui.tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section {background-color:rgb(65,65,65);}");
|
|
ui.tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); // 不可编辑
|
|
//ui.tableWidget_defectList->setFrameShape(QFrame::NoFrame); // 设置无边框
|
|
//ui.tableWidget_defectList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
|
ui.tableWidget->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
|
|
ui.tableWidget->setRowCount(0);
|
|
|
|
//保存按钮
|
|
connect(ui.pushButton_save, &QPushButton::clicked, [=]() {
|
|
|
|
QJsonArray SaveImgArray;
|
|
for (int i = 0; i < ui.tableWidget->rowCount(); i++)
|
|
{
|
|
QJsonObject SaveImgObj;
|
|
SaveImgObj.insert("相机key", ui.tableWidget->item(i, 1)->text());
|
|
SaveImgObj.insert("界面窗口名称",ui.tableWidget->item(i, 2)->text());
|
|
for (int j = 0; j < 4; j++)
|
|
{
|
|
if (myQCheckBoxQueue[i * 4 + j]->isChecked())
|
|
SaveImgObj.insert(headerLabels[j + 3], "保存");
|
|
else
|
|
SaveImgObj.insert(headerLabels[j + 3], "不保存");
|
|
}
|
|
SaveImgArray.append(SaveImgObj);
|
|
}
|
|
QJsonObject newprogramObj = programObj;
|
|
newprogramObj.insert("存图设置", SaveImgArray);
|
|
if (newprogramObj != programObj)
|
|
{
|
|
QString tmpDate = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz");
|
|
BackUp_json_cfg_file_path = currPath + "/config/backup/" + tmpDate + "_" + cfg_name;
|
|
//内存中的数据写到文件
|
|
QJsonDocument olddoc(programObj);
|
|
//将json对象转换成字符串
|
|
QByteArray olddata = olddoc.toJson();
|
|
QFile oldfile(BackUp_json_cfg_file_path);
|
|
oldfile.open(QIODevice::WriteOnly);
|
|
oldfile.write(olddata);
|
|
oldfile.close();
|
|
|
|
//内存中的数据写到文件
|
|
QJsonDocument doc(newprogramObj);
|
|
//将json对象转换成字符串
|
|
QByteArray data = doc.toJson();
|
|
QFile file(json_cfg_file_path);
|
|
file.open(QIODevice::WriteOnly);
|
|
file.write(data);
|
|
file.close();
|
|
|
|
programObj = newprogramObj;
|
|
QStringList moduleKeyList;
|
|
for (int SA = 0; SA < stationArray.size(); SA++)
|
|
{
|
|
QJsonObject stationObj = stationArray[SA].toObject();
|
|
QString stationKey = stationObj.value("工站名").toString();
|
|
|
|
QJsonArray AlgorithmListArray = stationObj.value("算法列表").toArray();
|
|
for (int AL = 0; AL < AlgorithmListArray.size(); AL++)
|
|
moduleKeyList.append(AlgorithmListArray[AL].toObject().value("算法名称").toString());
|
|
}
|
|
emit reLoadJsonSetParameter(moduleKeyList);
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
//
|
|
void QtSaveImgSet::setJsonName(QString jsonName)
|
|
{
|
|
ui.tableWidget->setRowCount(0);
|
|
myQCheckBoxQueue.clear();
|
|
QJsonObject current_programObj=load_camera_cfg(jsonName);
|
|
//解析
|
|
QStringList myCfgWindow_NameList;//查找所有相机,按照"界面窗口名称"
|
|
QStringList myCfgWindow_KeyList;
|
|
{
|
|
stationArray = current_programObj.value("工站列表").toArray();
|
|
int allCameraNum = 0;
|
|
int allAlgorithmNum = 0;
|
|
int rowIndex = 0;
|
|
QGridLayout* QL_camera = nullptr;
|
|
QGridLayout* QL_Algorithm = nullptr;
|
|
//分开设置,关闭窗口释放ui.tabWidget_camera不崩溃;
|
|
for (int SA = 0; SA < stationArray.size(); SA++)
|
|
{
|
|
QJsonObject stationObj = stationArray[SA].toObject();
|
|
QString stationKey = stationObj.value("工站名").toString();
|
|
|
|
QJsonArray cameraListArray = stationObj.value("相机模块列表").toArray();
|
|
for (int CA = 0; CA < cameraListArray.size(); CA++)
|
|
{
|
|
QJsonObject cameraObj = cameraListArray[CA].toObject();
|
|
QString myCfgWindow_Key = cameraObj.value("相机key").toString();
|
|
QString myCfgWindow_Name = cameraObj.value("界面窗口名称").toString();
|
|
myCfgWindow_NameList.append(myCfgWindow_Name);
|
|
myCfgWindow_KeyList.append(myCfgWindow_Key);
|
|
}
|
|
}
|
|
}
|
|
//配置文件内容
|
|
QStringList myCfgSaveImg_NameList;
|
|
QStringList myCfgSaveImg_KeyList;
|
|
{
|
|
QJsonArray SaveImgArray = current_programObj.value("存图设置").toArray();
|
|
int allCameraNum = 0;
|
|
int allAlgorithmNum = 0;
|
|
int rowIndex = 0;
|
|
QGridLayout* QL_camera = nullptr;
|
|
QGridLayout* QL_Algorithm = nullptr;
|
|
//分开设置,关闭窗口释放ui.tabWidget_camera不崩溃;
|
|
for (int SA = 0; SA < SaveImgArray.size(); SA++)
|
|
{
|
|
QJsonObject SaveImgObj = SaveImgArray[SA].toObject();
|
|
QString SaveImg_Key = SaveImgObj.value("相机key").toString();
|
|
QString SaveImgName = SaveImgObj.value("界面窗口名称").toString();
|
|
myCfgSaveImg_NameList.append(SaveImgName);
|
|
myCfgSaveImg_KeyList.append(SaveImg_Key);
|
|
}
|
|
|
|
//判断
|
|
if (myCfgWindow_NameList != myCfgSaveImg_NameList || myCfgWindow_KeyList!= myCfgSaveImg_KeyList) //不匹配,按照myCfgWindow_NameList重新布局设置
|
|
{
|
|
for (int i = 0; i < myCfgWindow_NameList.size(); i++)
|
|
{
|
|
ui.tableWidget->setRowCount(ui.tableWidget->rowCount() + 1);
|
|
int rowNum2 = ui.tableWidget->rowCount();
|
|
ui.tableWidget->setItem(rowNum2 - 1, 0, new QTableWidgetItem(QString::number(i)));//序号
|
|
ui.tableWidget->setItem(rowNum2 - 1, 1, new QTableWidgetItem(myCfgWindow_KeyList[i]));//相机key
|
|
ui.tableWidget->setItem(rowNum2 - 1, 2, new QTableWidgetItem(myCfgWindow_NameList[i]));//界面窗口名称
|
|
//居中
|
|
ui.tableWidget->item(rowNum2 - 1, 0)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
ui.tableWidget->item(rowNum2 - 1, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
ui.tableWidget->item(rowNum2 - 1, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
//string mytext = "userName:" + userName + ",SN:" + SN;
|
|
//ui.comboBox_SN->addItem(QString::fromStdString(SN));
|
|
for (int j = 0; j < 4; j++)
|
|
{
|
|
QCheckBox* ifAddBox = new QCheckBox;
|
|
myQCheckBoxQueue.enqueue(ifAddBox);
|
|
QWidget* w = new QWidget(this); //创建一个widget
|
|
QHBoxLayout* hLayout = new QHBoxLayout(); //创建布局
|
|
hLayout->addWidget(ifAddBox); //添加checkbox
|
|
hLayout->setMargin(0); //设置边缘距离 否则会很难看
|
|
hLayout->setAlignment(ifAddBox, Qt::AlignCenter); //居中
|
|
w->setLayout(hLayout); //设置widget的布局
|
|
ui.tableWidget->setCellWidget(rowNum2 - 1, j + 3, w);
|
|
}
|
|
}
|
|
}
|
|
else //匹配,按照myCfgSaveImg_NameList显示
|
|
{
|
|
for (int SA = 0; SA < SaveImgArray.size(); SA++)
|
|
{
|
|
QJsonObject SaveImgObj = SaveImgArray[SA].toObject();
|
|
QString SaveImg_Key = SaveImgObj.value("相机key").toString();
|
|
QString SaveImgName = SaveImgObj.value("界面窗口名称").toString();
|
|
|
|
ui.tableWidget->setRowCount(ui.tableWidget->rowCount() + 1);
|
|
int rowNum2 = ui.tableWidget->rowCount();
|
|
ui.tableWidget->setItem(rowNum2 - 1, 0, new QTableWidgetItem(QString::number(SA)));//序号
|
|
ui.tableWidget->setItem(rowNum2 - 1, 1, new QTableWidgetItem(SaveImg_Key));//相机名称
|
|
ui.tableWidget->setItem(rowNum2 - 1, 2, new QTableWidgetItem(SaveImgName));//界面窗口名称
|
|
//居中
|
|
ui.tableWidget->item(rowNum2 - 1, 0)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
ui.tableWidget->item(rowNum2 - 1, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
ui.tableWidget->item(rowNum2 - 1, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
//string mytext = "userName:" + userName + ",SN:" + SN;
|
|
//ui.comboBox_SN->addItem(QString::fromStdString(SN));
|
|
for (int j = 0; j < 4; j++)
|
|
{
|
|
QCheckBox* ifAddBox = new QCheckBox;
|
|
if (SaveImgObj.value(headerLabels[j + 3]).toString() == "保存")
|
|
ifAddBox->setChecked(true);
|
|
myQCheckBoxQueue.enqueue(ifAddBox);
|
|
QWidget* w = new QWidget(this); //创建一个widget
|
|
QHBoxLayout* hLayout = new QHBoxLayout(); //创建布局
|
|
hLayout->addWidget(ifAddBox); //添加checkbox
|
|
hLayout->setMargin(0); //设置边缘距离 否则会很难看
|
|
hLayout->setAlignment(ifAddBox, Qt::AlignCenter); //居中
|
|
w->setLayout(hLayout); //设置widget的布局
|
|
ui.tableWidget->setCellWidget(rowNum2 - 1, j + 3, w);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
QJsonObject QtSaveImgSet::load_camera_cfg(QString cfg)
|
|
{
|
|
cfg_name = cfg;
|
|
QDir dir = QApplication::applicationDirPath();
|
|
currPath = dir.path();
|
|
json_cfg_file_path = currPath + "/config/" + cfg;//camera_cfg.json";
|
|
QString tmpDate = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz");
|
|
BackUp_json_cfg_file_path = currPath + "/config/backup/" + tmpDate + "_" + cfg;
|
|
|
|
QJsonObject json_object;
|
|
try
|
|
{
|
|
QJsonParseError jsonError;
|
|
if (json_cfg_file_path.isEmpty())
|
|
{
|
|
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " JsonPath is null!";
|
|
return json_object;
|
|
}
|
|
|
|
QFile JsonFile;
|
|
JsonFile.setFileName(json_cfg_file_path);
|
|
if (!JsonFile.isReadable())
|
|
{
|
|
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " camera_cfg.json not isReadable!";
|
|
//return json_object;
|
|
}
|
|
JsonFile.open(QIODevice::ReadOnly);
|
|
|
|
QByteArray m_Byte = JsonFile.readAll();
|
|
if (m_Byte.isEmpty())
|
|
{
|
|
qDebug() << __FUNCTION__ << " line:" << __LINE__ << json_cfg_file_path + " Content is empty";
|
|
JsonFile.close();
|
|
return json_object;
|
|
}
|
|
|
|
QJsonDocument jsonDocument(QJsonDocument::fromJson(m_Byte, &jsonError));
|
|
|
|
if (!jsonDocument.isNull() && jsonError.error == QJsonParseError::NoError)
|
|
{
|
|
if (jsonDocument.isObject())
|
|
{
|
|
json_object = jsonDocument.object();
|
|
JsonFile.close();
|
|
programObj = json_object;
|
|
return json_object;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
qCritical() << __FUNCTION__ << " line:" << __LINE__ << json_cfg_file_path + " is error!";
|
|
}
|
|
JsonFile.close();
|
|
|
|
}
|
|
catch (QString ev)
|
|
{
|
|
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " ev:" << ev;
|
|
}
|
|
programObj = json_object;
|
|
return json_object;
|
|
}
|
|
|
|
QtSaveImgSet::~QtSaveImgSet()
|
|
{}
|
|
|
|
#define MOUSE_MARGIN 2
|
|
//计算鼠标位置
|
|
QtSaveImgSet::MousePoss QtSaveImgSet::calcmouseposs(QPoint p)
|
|
{
|
|
QtSaveImgSet::MousePoss mp;
|
|
if (p.x() < MOUSE_MARGIN && p.y() < MOUSE_MARGIN)
|
|
mp = QtSaveImgSet::MousePoss::LeftUp; //左上
|
|
else if (p.x() > MOUSE_MARGIN && p.y() < MOUSE_MARGIN && p.x() < this->width() - MOUSE_MARGIN)
|
|
mp = QtSaveImgSet::MousePoss::Up; //上
|
|
else if (p.x() > this->width() - MOUSE_MARGIN && p.y() < MOUSE_MARGIN)
|
|
mp = QtSaveImgSet::MousePoss::RightUp; //右上
|
|
else if (p.x() > this->width() - MOUSE_MARGIN && p.y() > MOUSE_MARGIN && p.y() < this->height() - MOUSE_MARGIN)
|
|
mp = QtSaveImgSet::MousePoss::Right; //右
|
|
else if (p.x() > this->width() - MOUSE_MARGIN && p.y() > this->height() - MOUSE_MARGIN)
|
|
mp = QtSaveImgSet::MousePoss::RightDown; //右下
|
|
else if (p.x() > MOUSE_MARGIN && p.x() < this->width() - MOUSE_MARGIN && p.y() > this->height() - MOUSE_MARGIN)
|
|
mp = QtSaveImgSet::MousePoss::Down; //下
|
|
else if (p.x() < MOUSE_MARGIN && p.y() > this->height() - MOUSE_MARGIN)
|
|
mp = QtSaveImgSet::MousePoss::LeftDown; //左下
|
|
else if (p.x() < MOUSE_MARGIN && p.y() < this->height() - MOUSE_MARGIN && p.y() > MOUSE_MARGIN)
|
|
mp = QtSaveImgSet::MousePoss::Left; //左
|
|
else
|
|
mp = QtSaveImgSet::MousePoss::Middle; //中间
|
|
return mp;
|
|
}
|
|
//修改鼠标样式
|
|
void QtSaveImgSet::setCursorType(QtSaveImgSet::MousePoss type)
|
|
{
|
|
Qt::CursorShape cursor;
|
|
switch (type)
|
|
{
|
|
case QtSaveImgSet::MousePoss::LeftUp:
|
|
case QtSaveImgSet::MousePoss::RightDown:
|
|
cursor = Qt::SizeFDiagCursor;
|
|
break;
|
|
case QtSaveImgSet::MousePoss::Up:
|
|
case QtSaveImgSet::MousePoss::Down:
|
|
cursor = Qt::SizeVerCursor;
|
|
break;
|
|
case QtSaveImgSet::MousePoss::RightUp:
|
|
case QtSaveImgSet::MousePoss::LeftDown:
|
|
cursor = Qt::SizeBDiagCursor;
|
|
break;
|
|
case QtSaveImgSet::MousePoss::Right:
|
|
case QtSaveImgSet::MousePoss::Left:
|
|
cursor = Qt::SizeHorCursor;
|
|
break;
|
|
default:
|
|
cursor = Qt::ArrowCursor;
|
|
break;
|
|
}
|
|
setCursor(cursor);
|
|
}
|
|
//改变窗口的大小
|
|
void QtSaveImgSet::changeWindowSize(QtSaveImgSet::MousePoss type, QRect& wid, QPoint ptemp, int minWidth, int minHeight)
|
|
{
|
|
switch (type)//改变窗口的大小
|
|
{
|
|
case QtSaveImgSet::MousePoss::LeftUp:
|
|
{
|
|
QPoint pos = wid.topLeft();
|
|
|
|
if (wid.width() > minWidth || ptemp.x() < 0)
|
|
pos.rx() = pos.rx() + ptemp.x();
|
|
if (wid.height() > minHeight || ptemp.y() < 0)
|
|
pos.ry() = pos.ry() + ptemp.y();
|
|
|
|
wid.setTopLeft(pos);
|
|
break;//左上角
|
|
}
|
|
case QtSaveImgSet::MousePoss::RightUp:
|
|
{
|
|
QPoint pos = wid.topRight();
|
|
|
|
if (wid.width() > minWidth || ptemp.x() > 0)
|
|
pos.rx() = pos.rx() + ptemp.x();
|
|
if (wid.height() > minHeight || ptemp.y() < 0)
|
|
pos.ry() = pos.ry() + ptemp.y();
|
|
|
|
wid.setTopRight(pos);
|
|
break;//右上角
|
|
}
|
|
case QtSaveImgSet::MousePoss::LeftDown:
|
|
{
|
|
QPoint pos = wid.bottomLeft();
|
|
|
|
if (wid.width() > minWidth || ptemp.x() < 0)
|
|
pos.rx() = pos.rx() + ptemp.x();
|
|
if (wid.height() > minHeight || ptemp.y() > 0)
|
|
pos.ry() = pos.ry() + ptemp.y();
|
|
|
|
wid.setBottomLeft(pos);
|
|
break;//左下角
|
|
}
|
|
case QtSaveImgSet::MousePoss::RightDown:
|
|
{
|
|
QPoint pos = wid.bottomRight();
|
|
|
|
if (wid.width() > minWidth || ptemp.x() > 0)
|
|
pos.rx() = pos.rx() + ptemp.x();
|
|
if (wid.height() > minHeight || ptemp.y() > 0)
|
|
pos.ry() = pos.ry() + ptemp.y();
|
|
|
|
wid.setBottomRight(pos);
|
|
break;//右下角
|
|
}
|
|
case QtSaveImgSet::MousePoss::Up:
|
|
{
|
|
int topY = wid.top();
|
|
if (wid.height() > minHeight || ptemp.y() < 0)
|
|
topY = topY + ptemp.y();
|
|
|
|
wid.setTop(topY);
|
|
break;//上
|
|
}
|
|
case QtSaveImgSet::MousePoss::Left:
|
|
{
|
|
int leftX = wid.left();
|
|
|
|
if (wid.width() > minWidth || ptemp.x() < 0)
|
|
leftX = leftX + ptemp.x();
|
|
|
|
wid.setLeft(leftX);
|
|
break;//左
|
|
}
|
|
case QtSaveImgSet::MousePoss::Right:
|
|
{
|
|
int rightX = wid.right();
|
|
|
|
if (wid.width() > minWidth || ptemp.x() > 0)
|
|
rightX = rightX + ptemp.x();
|
|
|
|
wid.setRight(rightX);
|
|
break;//右
|
|
}
|
|
case QtSaveImgSet::MousePoss::Down:
|
|
{
|
|
int botY = wid.bottom();
|
|
if (wid.height() > minHeight || ptemp.y() > 0)
|
|
botY = botY + ptemp.y();
|
|
|
|
wid.setBottom(botY);
|
|
break;//下
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
//三个鼠标事件的重写
|
|
void QtSaveImgSet::mousePressEvent(QMouseEvent* e)
|
|
{
|
|
|
|
if (e->button() == Qt::LeftButton) //鼠标左键按下
|
|
{
|
|
m_lastPos = e->globalPos();
|
|
e->ignore();
|
|
}
|
|
|
|
|
|
}
|
|
//鼠标移动
|
|
void QtSaveImgSet::mouseMoveEvent(QMouseEvent* e)
|
|
{
|
|
//最大化状态,鼠标是否在标题栏,拖拽还原
|
|
if (this->isMaximized())
|
|
{
|
|
if (ui.title->geometry().contains(this->mapFromGlobal(QCursor::pos())) && e->buttons() == Qt::LeftButton)
|
|
{
|
|
QPoint ptemp = e->globalPos();
|
|
if (ptemp != m_lastPos)
|
|
{
|
|
this->showNormal();
|
|
}
|
|
}
|
|
}
|
|
QtSaveImgSet::MousePoss curPos = calcmouseposs(e->pos());
|
|
if (!e->buttons())
|
|
{
|
|
setCursorType(curPos);
|
|
mp_curPos = curPos;
|
|
}
|
|
|
|
if (e->buttons() == Qt::LeftButton) //坐标左键按下并移动
|
|
{
|
|
QPoint ptemp = e->globalPos();
|
|
ptemp = ptemp - m_lastPos; //鼠标移动的偏移量
|
|
if (mp_curPos == QtSaveImgSet::MousePoss::Middle && ui.title->geometry().contains(this->mapFromGlobal(QCursor::pos()))
|
|
&& !ui.pushButton_max->geometry().contains(this->mapFromGlobal(QCursor::pos()))
|
|
&& !ui.pushButton_min->geometry().contains(this->mapFromGlobal(QCursor::pos()))
|
|
&& !ui.pushButton_close->geometry().contains(this->mapFromGlobal(QCursor::pos())))
|
|
{
|
|
move(ptemp + pos());
|
|
}
|
|
else
|
|
{
|
|
QRect wid = geometry();
|
|
int minWidth = this->minimumWidth();
|
|
int minHeight = this->minimumHeight();
|
|
if (ptemp.x() < 50 && ptemp.x() > -50)
|
|
{
|
|
changeWindowSize(mp_curPos, wid, ptemp, minWidth, minHeight);
|
|
//更新大小
|
|
setGeometry(wid);
|
|
}
|
|
}
|
|
m_lastPos = e->globalPos();
|
|
}
|
|
e->ignore();
|
|
}
|
|
//鼠标释放
|
|
void QtSaveImgSet::mouseReleaseEvent(QMouseEvent* e)
|
|
{
|
|
if (e->button() == Qt::LeftButton && ui.title->geometry().contains(this->mapFromGlobal(QCursor::pos()))
|
|
&& !ui.pushButton_max->geometry().contains(this->mapFromGlobal(QCursor::pos()))
|
|
&& !ui.pushButton_min->geometry().contains(this->mapFromGlobal(QCursor::pos()))
|
|
&& !ui.pushButton_close->geometry().contains(this->mapFromGlobal(QCursor::pos()))) //鼠标左键释放
|
|
{
|
|
int dx = e->globalX() - m_lastPos.x();
|
|
int dy = e->globalY() - m_lastPos.y();
|
|
move(x() + dx, y() + dy);
|
|
}
|
|
QApplication::restoreOverrideCursor();//恢复鼠标指针性状
|
|
e->ignore();
|
|
} |