111 lines
3.5 KiB
C++
111 lines
3.5 KiB
C++
#include "devstatus.h"
|
||
#include "ui_devstatus.h"
|
||
#include <QPainter>
|
||
#include <QBrush>
|
||
#include "VrLog.h"
|
||
|
||
devstatus::devstatus(QWidget *parent)
|
||
: QWidget(parent)
|
||
, ui(new Ui::devstatus)
|
||
{
|
||
ui->setupUi(this);
|
||
|
||
// 强制应用样式表 - 这是关键!
|
||
this->setAttribute(Qt::WA_StyledBackground, true);
|
||
|
||
// 初始化时设置样式
|
||
setItemStyle();
|
||
|
||
// 初始化设备状态(离线状态)
|
||
updateCamera1Status(false);
|
||
updateCamera2Status(false);
|
||
updateRobotStatus(false);
|
||
}
|
||
|
||
devstatus::~devstatus()
|
||
{
|
||
delete ui;
|
||
}
|
||
|
||
// 设置devstatus的样式
|
||
void devstatus::setItemStyle()
|
||
{
|
||
// 参考ResultItem的样式设置,添加边框作为格子间分隔线
|
||
this->setStyleSheet(
|
||
"devstatus { "
|
||
" border: 2px solid #191A1C; " // 添加边框作为格子间分隔线
|
||
" border-radius: 0px; " // 去掉圆角,让分隔线更清晰
|
||
"} "
|
||
);
|
||
}
|
||
|
||
// 设置相机状态图片的私有成员函数
|
||
void devstatus::setCameraStatusImage(QWidget* widget, bool isOnline) {
|
||
if (!widget) return;
|
||
|
||
QString imagePath = isOnline ? ":/resource/camera_online.png" : ":/resource/camera_offline.png";
|
||
|
||
widget->setStyleSheet(QString("background-image: url(%1); background-repeat: no-repeat; background-position: center;")
|
||
.arg(imagePath));
|
||
widget->setFixedSize(32, 32); // 调整大小以适应图片
|
||
}
|
||
|
||
// 设置机械臂状态图片的私有成员函数
|
||
void devstatus::setRobotStatusImage(QWidget* widget, bool isOnline) {
|
||
if (!widget) return;
|
||
|
||
QString imagePath = isOnline ? ":/resource/robot_online.png" : ":/resource/robot_offline.png";
|
||
|
||
widget->setStyleSheet(QString("background-image: url(%1); background-repeat: no-repeat; background-position: center;")
|
||
.arg(imagePath));
|
||
widget->setFixedSize(32, 32); // 调整大小以适应图片
|
||
}
|
||
|
||
// 更新相机1状态
|
||
void devstatus::updateCamera1Status(bool isConnected)
|
||
{
|
||
setCameraStatusImage(ui->dev_camer_1_img, isConnected);
|
||
|
||
QString statusText = isConnected ? "相机1在线" : "相机1离线";
|
||
QString colorStyle = isConnected ? "color: rgb(140, 180, 60);" : "color: rgb(220, 60, 60);";
|
||
|
||
ui->dev_camera_1_txt->setText(statusText);
|
||
ui->dev_camera_1_txt->setStyleSheet(colorStyle);
|
||
}
|
||
|
||
// 更新相机2状态
|
||
void devstatus::updateCamera2Status(bool isConnected)
|
||
{
|
||
setCameraStatusImage(ui->dev_camer_2_img, isConnected);
|
||
|
||
QString statusText = isConnected ? "相机2在线" : "相机2离线";
|
||
QString colorStyle = isConnected ? "color: rgb(140, 180, 60);" : "color: rgb(220, 60, 60);";
|
||
|
||
ui->dev_camera_2_txt->setText(statusText);
|
||
ui->dev_camera_2_txt->setStyleSheet(colorStyle);
|
||
}
|
||
|
||
// 更新机械臂状态
|
||
void devstatus::updateRobotStatus(bool isConnected)
|
||
{
|
||
setRobotStatusImage(ui->dev_robot_img, isConnected);
|
||
|
||
QString statusText = isConnected ? "机械臂在线" : "机械臂离线";
|
||
QString colorStyle = isConnected ? "color: rgb(140, 180, 60);" : "color: rgb(220, 60, 60);";
|
||
|
||
ui->dev_robot_txt->setText(statusText);
|
||
ui->dev_robot_txt->setStyleSheet(colorStyle);
|
||
}
|
||
|
||
// 设置相机数量(用于控制相机二的显示)
|
||
void devstatus::setCameraCount(int cameraCount)
|
||
{
|
||
// 如果相机数量小于2,隐藏相机二相关的UI元素
|
||
bool showCamera2 = (cameraCount >= 2);
|
||
|
||
LOG_DEBUG("setCameraCount: %d", cameraCount);
|
||
|
||
ui->dev_camer_2_img->setVisible(showCamera2);
|
||
ui->dev_camera_2_txt->setVisible(showCamera2);
|
||
}
|