227 lines
6.8 KiB
C++
227 lines
6.8 KiB
C++
#include <QDialog>
|
|
#include <qpushbutton.h>
|
|
#include <qlayout.h>
|
|
#include <globalStruct.h>
|
|
#include <qtimer.h>
|
|
#include <qlabel.h>
|
|
#include <uiModule/components/fancyButton.h>
|
|
#include <qdatetime.h>
|
|
#include <uiModule/uiModule_imageView.h>
|
|
|
|
class imageDoubleCheckQdialog :public QDialog
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
ImageWidgetManager* _ImageWidgetManager = new ImageWidgetManager();
|
|
QWidget* menuBarWidget = new QWidget();
|
|
QPushButton* closeBtn = new QPushButton(this);
|
|
fancyButtonText* okBtn = new fancyButtonText(120, 40, "OK", "继续");
|
|
fancyButtonText* ngBtn = new fancyButtonText(120, 40, "NG", "继续");
|
|
QMutex mutex;
|
|
QQueue< QPixmap>imgqueue;
|
|
imageDoubleCheckQdialog()
|
|
{
|
|
QPalette paletteWhite, paletteRed, paletteGreen;
|
|
paletteWhite.setColor(QPalette::WindowText, Qt::white);
|
|
paletteRed.setColor(QPalette::WindowText, Qt::red);
|
|
paletteGreen.setColor(QPalette::WindowText, Qt::green);
|
|
QFont font("微软雅黑", 16, QFont::Bold);
|
|
QFont font2("微软雅黑", 18, QFont::Bold);
|
|
QFont font3("微软雅黑", 12, QFont::Bold);
|
|
|
|
this->setObjectName("warnDialog");
|
|
this->setStyleSheet(QString("QDialog#warnDialog {"
|
|
"background-color: rgb(%1);"
|
|
"border: 1px solid black;"
|
|
"border-radius: 1px;}").arg(sColor_blue));
|
|
this->setWindowFlags(Qt::FramelessWindowHint); // 设置无边框的样式
|
|
this->setFixedSize(QSize(minWidth, minHeight));
|
|
|
|
QGridLayout* layout = new QGridLayout(this);
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
menuBarWidget->setStyleSheet(QString("QWidget { background-color: black;"
|
|
"border: 0px solid red;" // 显式设置边框
|
|
"border-radius: 0px;" // 设置边框半径为0,确保没有圆角
|
|
"}"));
|
|
menuBarWidget->setFixedHeight(35);
|
|
menuBarWidget->setFixedWidth(minWidth);
|
|
|
|
QHBoxLayout* menuBarLayout = new QHBoxLayout(menuBarWidget);
|
|
menuBarLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
QHBoxLayout* menuBarLayoutLeft = new QHBoxLayout();
|
|
menuBarLayoutLeft->setContentsMargins(0, 0, 0, 0);
|
|
menuBarLayoutLeft->setAlignment(Qt::AlignLeft);
|
|
|
|
QHBoxLayout* menuBarLayoutRight = new QHBoxLayout();
|
|
menuBarLayoutRight->setContentsMargins(0, 0, 0, 0);
|
|
menuBarLayoutRight->setAlignment(Qt::AlignRight);
|
|
|
|
menuBarLayout->addLayout(menuBarLayoutLeft);
|
|
menuBarLayout->addLayout(menuBarLayoutRight);
|
|
|
|
QLabel* warnLabel = new QLabel();
|
|
warnLabel->setAlignment(Qt::AlignLeft);
|
|
warnLabel->setFont(font);
|
|
warnLabel->setText("请确认是否NG");
|
|
warnLabel->setPalette(paletteWhite);
|
|
menuBarLayoutLeft->addWidget(warnLabel);
|
|
|
|
closeBtn->setIcon(QPixmap(":/topBar/icon/close.png")); // 设置图标
|
|
closeBtn->setFixedHeight(35);
|
|
closeBtn->setStyleSheet(QString("QPushButton { background-color: transparent;"
|
|
"border: 0px solid red;" // 显式设置边框
|
|
"border-radius: 0px;" // 设置边框半径为0,确保没有圆角
|
|
"}"
|
|
"QPushButton:focus {"
|
|
" outline: none;"
|
|
"}"
|
|
"QPushButton:hover { background-color: rgb(%1); }").arg(sColor_Red)); // 设置透明背景和悬停时的背景色
|
|
closeBtn->setFixedHeight(35);
|
|
closeBtn->setFixedWidth(50);
|
|
menuBarLayoutRight->addWidget(closeBtn);
|
|
|
|
QObject::connect(closeBtn, &QPushButton::clicked, this, &QDialog::close);
|
|
|
|
QHBoxLayout* imageViewLayout = new QHBoxLayout();
|
|
imageViewLayout->addWidget(_ImageWidgetManager);
|
|
|
|
_ImageWidgetManager->createViewer("");
|
|
_ImageWidgetManager->disableAllSwitchBtn();
|
|
|
|
QHBoxLayout* okngBtnLayout = new QHBoxLayout();
|
|
okngBtnLayout->addWidget(okBtn);
|
|
okngBtnLayout->addWidget(ngBtn);
|
|
|
|
//QObject::connect(okBtn, &QPushButton::clicked, this, &QDialog::close);
|
|
//QObject::connect(ngBtn, &QPushButton::clicked, this, &QDialog::close);
|
|
QObject::connect(okBtn, &QPushButton::clicked, this, [=]() {pressOK(); });
|
|
QObject::connect(ngBtn, &QPushButton::clicked, this, [=]() {pressNG(); });
|
|
|
|
layout->addWidget(menuBarWidget, 0, 0);
|
|
layout->addLayout(imageViewLayout, 1, 0);
|
|
layout->addLayout(okngBtnLayout, 2, 0);
|
|
this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);
|
|
//this->show();
|
|
}
|
|
void showAndSetImg(QPixmap img)
|
|
{
|
|
mutex.lock();
|
|
std::cout << isShowing<<"-" << imgqueue.size()<< std::endl;
|
|
if (isShowing == false && imgqueue.size() == 0)
|
|
{
|
|
_ImageWidgetManager->showImg(img, imgWidgetShowType::imgWidgetOri, 0);
|
|
this->show();
|
|
isShowing = true;
|
|
}
|
|
else
|
|
{
|
|
imgqueue.enqueue(img);
|
|
}
|
|
mutex.unlock();
|
|
}
|
|
signals:
|
|
void okSignal();
|
|
void ngSignal();
|
|
private:
|
|
void pressOK()
|
|
{
|
|
mutex.lock();
|
|
emit okSignal();
|
|
if (imgqueue.size() > 0)
|
|
{
|
|
QPixmap img = imgqueue.dequeue();
|
|
_ImageWidgetManager->showImg(img, imgWidgetShowType::imgWidgetOri, 0);
|
|
}
|
|
else
|
|
{
|
|
isShowing = false;
|
|
close();
|
|
}
|
|
mutex.unlock();
|
|
}
|
|
void pressNG()
|
|
{
|
|
mutex.lock();
|
|
emit ngSignal();
|
|
if (imgqueue.size() > 0)
|
|
{
|
|
QPixmap img = imgqueue.dequeue();
|
|
_ImageWidgetManager->showImg(img, imgWidgetShowType::imgWidgetOri, 0);
|
|
}
|
|
else
|
|
{
|
|
isShowing = false;
|
|
close();
|
|
}
|
|
mutex.unlock();
|
|
}
|
|
bool isShowing = false;
|
|
bool isMoving = false;
|
|
bool isResizing = false;
|
|
int minWidth = 720, minHeight = 480;
|
|
QSize originalSize;
|
|
//窗口移动
|
|
#pragma region 窗口移动变量
|
|
QPoint startPos;
|
|
QRect startFrameGeometry;
|
|
QTime lastWindowMoveTime;
|
|
int freshDelay = 1000 / windowMoveFreshRate;
|
|
bool setNormalAndMove = false;//判断是否从最大化开始移动
|
|
#pragma endregion
|
|
protected:
|
|
void mousePressEvent(QMouseEvent* event) override {
|
|
QPoint pos = event->pos();
|
|
std::cout << "y" << pos.y() << " x" << pos.x() << std::endl;
|
|
if (pos.y() < 35)//标题栏
|
|
{
|
|
if (event->button() == Qt::LeftButton) {
|
|
startPos = event->globalPos();
|
|
startFrameGeometry = frameGeometry();
|
|
isMoving = true;
|
|
lastWindowMoveTime.start(); // 按下时开始计时
|
|
}
|
|
}
|
|
else if (pos.x() < 10 || //左边框
|
|
pos.x() > this->size().width()-10 || //下边框
|
|
pos.y() > this->size().height() - 10)//右边框
|
|
{
|
|
if (event->button() == Qt::LeftButton) {
|
|
isResizing = true;
|
|
startPos = event->globalPos();
|
|
originalSize = size();
|
|
}
|
|
}
|
|
QDialog::mousePressEvent(event);
|
|
}
|
|
void mouseMoveEvent(QMouseEvent* event) override {
|
|
if (event->buttons() == Qt::LeftButton)
|
|
{
|
|
if (isMoving) {
|
|
QPoint pos = event->globalPos();
|
|
if (getMax(getAbs(pos.x() - startPos.x()), getAbs(pos.y() - startPos.y())) > 10)
|
|
if (lastWindowMoveTime.elapsed() > freshDelay)//每秒刷新100次
|
|
{
|
|
lastWindowMoveTime.restart();
|
|
move(startFrameGeometry.topLeft() + (event->globalPos() - startPos));
|
|
}
|
|
}
|
|
if (isResizing) {
|
|
QPoint delta = event->globalPos() - startPos;
|
|
QSize newSize = originalSize + QSize(delta.x(), delta.y());
|
|
setFixedSize(getMax(minWidth ,newSize.width()), getMax(minHeight, newSize.height()));
|
|
menuBarWidget->setFixedWidth(getMax(minWidth, newSize.width()));
|
|
}
|
|
}
|
|
QDialog::mouseMoveEvent(event);
|
|
}
|
|
void mouseReleaseEvent(QMouseEvent* event) override {
|
|
if (event->button() == Qt::LeftButton) {
|
|
isMoving = false;
|
|
isResizing = false;
|
|
}
|
|
QDialog::mouseReleaseEvent(event);
|
|
}
|
|
};
|
|
#pragma once |