Files
eUi/src/launcher/GUI/front/pages/displayPageWidget.h
T
2025-10-15 11:02:29 +08:00

487 lines
14 KiB
C++

#include <qwidget.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qtoolbutton.h>
#include <qpainter.h>
#include <qpainterpath.h>
#include <qbrush.h>
#include <qpen.h>
#include <unordered_map>
#include <functional>
#include <uiModule/uiModule_imageView.h>
#include <uiModule/components/fancyWidget.h>
#include <uiModule/uiModule_summaryDataManager.h>
#include <qlistwidget.h>
#include <uiModule/uiModule_historyListWidget.h>
#include <uiModule/uiModule_952BiaoDingSwitch.h>
#include <jsonEditorDialog.h>
#include <uiModule/uiModule_dsStatsWidget.h>
#include <uiModule/uiModule_histogramWidget.h>
#include <uiModule/uiModule_userSwitch.h>
#include <uiModule/uiModule_softwareDataDisplay.h>
#include <uiModule/uiModule_runCommand.h>
class toolBarWidget : public QWidget {
Q_OBJECT
public:
ConnectionWidget* _ConnectionWidget = new ConnectionWidget(this);
toolBarWidget(appConfig* config) :m_config(config) {
this->setObjectName("toolBarWidget");
Title = new QLabel(QString::fromStdString(Translation::getInstance().translate("TOOLS")));
Title->setObjectName("titleLabel");
Title->setAlignment(Qt::AlignCenter);
Layout->addWidget(Title);
QWidget* lineWidgetJustForShow = new QWidget(this);
lineWidgetJustForShow->setObjectName("lineWidgetJustForShow");
lineWidgetJustForShow->setStyleSheet(R"(
QWidget#lineWidgetJustForShow {
background: rgb(32, 36, 40);
border-radius: 1px; /* 圆角半径 */
}
)");
lineWidgetJustForShow->setFixedWidth(5);
Layout->addWidget(lineWidgetJustForShow);
// 创建按钮容器布局,用于后续添加按钮
buttonsLayout = new QHBoxLayout();
buttonsLayout->setSpacing(5);
buttonsLayout->setContentsMargins(0, 0, 0, 0);
Layout->addLayout(buttonsLayout);
QWidget* spacerWidget = new QWidget;
spacerWidget->setMaximumWidth(2560);
Layout->addWidget(spacerWidget, 1);
Layout->addWidget(_ConnectionWidget);
this->setStyleSheet(R"(
toolBarWidget#toolBarWidget {
background-color: rgb(50, 55, 60);
border-radius: 10px;
border: 1px solid rgb(70, 75, 80);
}
QLabel#titleLabel {
color: white;
font-family: "微软雅黑";
font-size: 20px;
font-weight: normal;
}
)");
this->setFixedHeight(80);
}
// 通用的创建工具按钮函数实现
bool createToolButton(const QString& iconPath, const QString& text,
std::function<void()> clickHandler,
const QSize& buttonSize = QSize(100, 60), const QSize& iconSize = QSize(30, 30)){
// 参数验证
if (iconPath.isEmpty() || text.isEmpty() || !clickHandler) {
return false;
}
// 创建布局
QVBoxLayout* btnLayout = new QVBoxLayout();
if (!btnLayout) {
return false;
}
btnLayout->setSpacing(0);
btnLayout->setContentsMargins(0, 0, 0, 0);
// 使用 QToolButton 来实现图标在上文字在下的效果
QToolButton* btn = new QToolButton(this);
if (!btn) {
delete btnLayout;
return false;
}
// 设置图标,检查图标是否加载成功
QIcon icon(iconPath);
if (icon.isNull()) {
delete btn;
delete btnLayout;
return false;
}
btn->setIcon(icon);
btn->setText(text);
btn->setIconSize(iconSize);
btn->setFixedSize(buttonSize.width(), buttonSize.height()); // 增加高度以容纳文字
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); // 文字在图标下方
// 设置按钮样式
btn->setStyleSheet(R"(
QToolButton {
background-color: transparent;
border: none;
color: white;
font-family: "微软雅黑";
font-size: 14px;
font-weight: bold;
}
QToolButton:hover {
background-color: black;
border-radius: 5px;
}
)");
btnLayout->addWidget(btn);
btnLayout->setAlignment(Qt::AlignCenter);
// 连接点击事件
if (!connect(btn, &QToolButton::clicked, clickHandler)) {
delete btn;
delete btnLayout;
return false;
}
// 添加到按钮布局容器中
buttonsLayout->addLayout(btnLayout);
return true;
}
bool createToolButton(QIcon icon, const QString& text,
std::function<void()> clickHandler,
const QSize& buttonSize = QSize(100, 60), const QSize& iconSize = QSize(30, 30)) {
// 参数验证
if (text.isEmpty() || !clickHandler) {
return false;
}
// 创建布局
QVBoxLayout* btnLayout = new QVBoxLayout();
if (!btnLayout) {
return false;
}
btnLayout->setSpacing(0);
btnLayout->setContentsMargins(0, 0, 0, 0);
// 使用 QToolButton 来实现图标在上文字在下的效果
QToolButton* btn = new QToolButton(this);
if (!btn) {
delete btnLayout;
return false;
}
// 设置图标,检查图标是否加载成功
btn->setIcon(icon);
btn->setText(text);
btn->setIconSize(iconSize);
btn->setFixedSize(buttonSize.width(), buttonSize.height()); // 增加高度以容纳文字
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); // 文字在图标下方
// 设置按钮样式
btn->setStyleSheet(R"(
QToolButton {
background-color: transparent;
border: none;
color: white;
font-family: "微软雅黑";
font-size: 14px;
font-weight: bold;
}
QToolButton:hover {
background-color: black;
border-radius: 5px;
}
)");
btnLayout->addWidget(btn);
btnLayout->setAlignment(Qt::AlignCenter);
// 连接点击事件
if (!connect(btn, &QToolButton::clicked, clickHandler)) {
delete btn;
delete btnLayout;
return false;
}
// 添加到按钮布局容器中
buttonsLayout->addLayout(btnLayout);
return true;
}
protected:
// 重写paintEvent确保背景绘制
void paintEvent(QPaintEvent* event) override {
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
// 绘制圆角矩形背景
QPainterPath path;
path.addRoundedRect(this->rect(), 10, 10);
// 设置背景色
painter.fillPath(path, QBrush(QColor(50, 55, 60)));
// 绘制边框
QPen pen(QColor(70, 75, 80), 1);
painter.setPen(pen);
painter.drawPath(path);
QWidget::paintEvent(event);
}
private:
QLabel* Title;
QHBoxLayout* Layout = new QHBoxLayout(this);
QHBoxLayout* buttonsLayout; // 按钮容器布局
appConfig* m_config;
};
class displayWidget :public QWidget{
Q_OBJECT
public:
toolBarWidget* _toolBarWidget;
QGridLayout* Layout;
QLabel* icon, * Title;
QWidget* leftWidget, * rightWidget1, * rightWidget2;
//switchProductWidget* _switchProductWidget;
ImageWidgetManager _ImageWidgetManager;
summaryDataManager* _summaryDataManager;
dsStatsWidget* _dsStatsWidget;
historyShowListWidget* historyImgs = new historyShowListWidget();
dayNightShiftHistogramWidget* _dayNightShiftHistogramWidget;
userSwitch* _userSwitch;
softwareDataDisplay* _softwareDataDisplay;
runCommandWidget* _runCommandWidget;
LogWindow* log = new LogWindow();
displayWidget(appConfig* config) :m_config(config){
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->setMaximumSize(9999, 9999);
Layout = new QGridLayout(this);
Layout->setContentsMargins(0, 0, 0, 0);
this->setObjectName("DisplayWidget");
Layout->setAlignment(Qt::AlignLeft);
leftWidget = new QWidget();
rightWidget1 = new QWidget();
rightWidget2 = new QWidget();
Layout->addWidget(leftWidget, 0, 0);
QWidget* lineWidgetJustForShow = new QWidget(this);
lineWidgetJustForShow->setObjectName("lineWidgetJustForShow");
lineWidgetJustForShow->setStyleSheet(R"(
QWidget#lineWidgetJustForShow {
background: rgb(50, 55, 60);
border-radius: 1px; /* 圆角半径 */
}
)");
lineWidgetJustForShow->setFixedWidth(3);
Layout->addWidget(lineWidgetJustForShow, 0, 1);
Layout->addWidget(rightWidget2, 0, 2);
Layout->setColumnStretch(0, 9);
Layout->setColumnStretch(1, 1);
Layout->setColumnStretch(2, 3);
_toolBarWidget = new toolBarWidget(config);
//Layout->setColumnStretch(2, 1);
leftItemInit(config);
rightItemInit1();
rightItemInit2();
connectFunc();
//historyImgs->addData(true, "D:/CCD/yuantu/2024-06-04/23H/TEST/1 (1).bmp", QPixmap("D:/CCD/yuantu/2024-06-04/23H/TEST/1 (1).bmp"));
}
void rightItemInit1(){
QVBoxLayout* hLayout = new QVBoxLayout(rightWidget1);
hLayout->addWidget(historyImgs);
}
void rightItemInit2(){
QVBoxLayout* hLayout = new QVBoxLayout(rightWidget2);
{
_dsStatsWidget = new dsStatsWidget();
_dsStatsWidget->setMaximumHeight(300);
QHBoxLayout* layoutH = new QHBoxLayout();
layoutH->setContentsMargins(0, 0, 0, 0);
layoutH->addWidget(_dsStatsWidget);
QVBoxLayout* layoutV = new QVBoxLayout();
layoutV->setContentsMargins(0, 0, 0, 0);
_userSwitch = new userSwitch(m_config,this);
_softwareDataDisplay = new softwareDataDisplay();
layoutV->addWidget(_userSwitch);
layoutV->addWidget(_softwareDataDisplay);
layoutH->addLayout(layoutV);
hLayout->addLayout(layoutH);
}
_dayNightShiftHistogramWidget = new dayNightShiftHistogramWidget();
hLayout->addWidget(_dayNightShiftHistogramWidget);
_summaryDataManager = new summaryDataManager();
_summaryDataManager->widget->setObjectName("_summaryDataManager");
_summaryDataManager->widget->setStyleSheet(R"(
QWidget#_summaryDataManager {
background: rgb(50, 55, 60);
border-radius: 10px; /* 圆角半径 */
}
)");
//hLayout->addWidget(_summaryDataManager->widget);
log->setObjectName("logWidget");
log->setStyleSheet(R"(
QMainWindow#logWidget {
background: rgb(50, 55, 60);
border-radius: 10px; /* 圆角半径 */
}
)");
log->setMinimumHeight(200);
hLayout->addWidget(log);
log->setStyleSheet("background-color: rgb(50,50,50);");
hLayout->setContentsMargins(0, 0, 0, 0);
}
void leftItemInit(appConfig* config){
auto& trans = Translation::getInstance();
QPalette palette;
palette.setColor(QPalette::WindowText, Qt::white);
QFont font("微软雅黑", 24, QFont::Bold);
QFont font2("微软雅黑", 16);
QVBoxLayout* vLayout = new QVBoxLayout(leftWidget);
vLayout->setContentsMargins(0, 0, 0, 0);
QWidget* titleWidget = new QWidget(this);
QFont font3("微软雅黑", 10, QFont::Bold);
#pragma region 日志分析按钮
{
_toolBarWidget->createToolButton(":/TongYongUiIcon/TongYongUiIcon/4.LogAnalyze.png",
QString::fromStdString(trans.translate("Log")),
[=]() {
emit changeStackWidget(2);
});
}
#pragma endregion
#pragma region 打开配置文件按钮
{
/*QVBoxLayout* btnLayout = new QVBoxLayout();
QPushButton* btn = new QPushButton(this);
btn->setIcon(QIcon(":/TongYongUiIcon/TongYongUiIcon/9.paramSetting.png"));
btn->setFixedSize(QSize(50, 50));
btn->setIconSize(QSize(25, 25));
btn->setStyleSheet(R"(
QPushButton {
background-color: transparent;
border: none;
}
QPushButton:hover {
background-color: black;
border-radius: 5px;
}
)");
QLabel* text = new QLabel(config->_translation->translate("SettingJson"));
text->setFont(font3);
text->setPalette(palette);
btnLayout->addWidget(btn);
btnLayout->addWidget(text);
titleLayout->addLayout(btnLayout);
connect(btn, &QPushButton::clicked, [=]() {
QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(config->settingJsonPath)));
});*/
}
#pragma endregion
#pragma region 结果图查看按钮
{
_toolBarWidget->createToolButton(":/TongYongUiIcon/TongYongUiIcon/23.1.imageView.png",
QString::fromStdString(trans.translate("ViewImage")),
[=]() {
QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(config->imgSavePath)));
});
}
#pragma endregion
#pragma region 修改检测参数按钮
{
_toolBarWidget->createToolButton(":/TongYongUiIcon/TongYongUiIcon/search_1.png",
QString::fromStdString(trans.translate("Param")),
[=]() {
config->Authorization.executeWithPermission(Auth::UserLevel::ADMIN,[this]() {
JsonParamTableEditor* dlg = new JsonParamTableEditor(this);
dlg->setJsonObject(m_config->settingJson["backend"]["algorithmSettings"]);
dlg->setAttribute(Qt::WA_DeleteOnClose);
connect(dlg, &JsonParamTableEditor::jsonAccepted, [this](const nlohmann::json& result) {
m_config->settingJson["backend"]["algorithmSettings"] = result;
});
dlg->show();
});
});
}
#pragma endregion
#pragma region 故障排查按钮
{
_runCommandWidget = new runCommandWidget();
_toolBarWidget->createToolButton(":/TongYongUiIcon/TongYongUiIcon/18.help.png",
QString::fromStdString(trans.translate("Debug")),
[=]() {
_runCommandWidget->show();
_runCommandWidget->raise();
});
}
#pragma endregion
#pragma region 读取bin目录下的tools文件夹并展示
{
std::vector<std::string> files;
fileManager::getAllFiles("./tools", files, "lnk");
for (auto& lnkPath : files) {
std::string fileName = fileManager::getFileName(lnkPath);
auto exePath = getShortcutTarget(QString::fromStdString(lnkPath));
auto icon = getFileIcon(exePath, QSize(30, 30));
_toolBarWidget->createToolButton(icon, QString::fromLocal8Bit(fileName.c_str()), [=]() {
QProcess::startDetached(exePath);
});
}
}
#pragma endregion
vLayout->addWidget(_toolBarWidget);
vLayout->addWidget(&_ImageWidgetManager);
_ImageWidgetManager.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
for (auto& vData : config->viewDatas)
{
auto ptr = _ImageWidgetManager.createViewer(QString::fromStdString(vData.name), vData.viewers,vData.xPos , vData.yPos);
}
_ImageWidgetManager.adjustImageWidget();
}
void windowChanged(){
//int width = this->width();
//leftWidget->setMaximumWidth(width / 1.2);
//rightWidget->setMaximumWidth(width / 2);
}
void connectFunc(){
QObject::connect(historyImgs, &historyShowListWidget::itemClickSignal,
this, &displayWidget::historyClick);
}
public slots:
void recvMainWindowStdLogMsg(QString msg)
{
log->addLog(msg);
}
private slots:
void historyClick(QString path)
{
if (path == "")
return;
emit historyClickSignal(path);
emit changeStackWidget(3);
}
private:
appConfig* m_config;
signals:
void historyClickSignal(QString);
void changeStackWidget(int);
};
#pragma once