2025-06-19 01:38:50 +08:00
|
|
|
|
#include "devstatus.h"
|
|
|
|
|
|
#include "ui_devstatus.h"
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
#include <QBrush>
|
|
|
|
|
|
#include "VrLog.h"
|
|
|
|
|
|
|
|
|
|
|
|
devstatus::devstatus(QWidget *parent)
|
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
|
, ui(new Ui::devstatus)
|
2025-07-26 01:10:21 +08:00
|
|
|
|
, m_selectedCameraIndex(0)
|
|
|
|
|
|
, m_camera1Name("")
|
|
|
|
|
|
, m_camera2Name("")
|
2025-06-19 01:38:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
|
|
|
|
// 强制应用样式表 - 这是关键!
|
|
|
|
|
|
this->setAttribute(Qt::WA_StyledBackground, true);
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化时设置样式
|
|
|
|
|
|
setItemStyle();
|
|
|
|
|
|
|
2025-07-26 01:10:21 +08:00
|
|
|
|
// 初始化点击事件
|
|
|
|
|
|
initClickEvents();
|
|
|
|
|
|
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 初始化设备状态(离线状态)
|
|
|
|
|
|
updateCamera1Status(false);
|
|
|
|
|
|
updateCamera2Status(false);
|
|
|
|
|
|
updateRobotStatus(false);
|
2025-08-05 22:52:10 +08:00
|
|
|
|
|
|
|
|
|
|
setCameraSelectedStyle(1);
|
2025-06-19 01:38:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
devstatus::~devstatus()
|
|
|
|
|
|
{
|
|
|
|
|
|
delete ui;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置devstatus的样式
|
|
|
|
|
|
void devstatus::setItemStyle()
|
|
|
|
|
|
{
|
|
|
|
|
|
this->setStyleSheet(
|
|
|
|
|
|
"devstatus { "
|
|
|
|
|
|
" border: 2px solid #191A1C; " // 添加边框作为格子间分隔线
|
|
|
|
|
|
" border-radius: 0px; " // 去掉圆角,让分隔线更清晰
|
|
|
|
|
|
"} "
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置相机状态图片的私有成员函数
|
|
|
|
|
|
void devstatus::setCameraStatusImage(QWidget* widget, bool isOnline) {
|
|
|
|
|
|
if (!widget) return;
|
|
|
|
|
|
|
2025-11-19 00:23:09 +08:00
|
|
|
|
QString imagePath = isOnline ? ":/common/resource/camera_online.png" : ":/common/resource/camera_offline.png";
|
2025-06-19 01:38:50 +08:00
|
|
|
|
|
2025-06-26 00:40:36 +08:00
|
|
|
|
widget->setStyleSheet(QString("image: url(%1);").arg(imagePath));
|
|
|
|
|
|
// widget->setFixedSize(32, 32); // 调整大小以适应图片
|
2025-06-19 01:38:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置机械臂状态图片的私有成员函数
|
|
|
|
|
|
void devstatus::setRobotStatusImage(QWidget* widget, bool isOnline) {
|
|
|
|
|
|
if (!widget) return;
|
|
|
|
|
|
|
2025-11-19 00:23:09 +08:00
|
|
|
|
QString imagePath = isOnline ? ":/common/resource/robot_online.png" : ":/common/resource/robot_offline.png";
|
2025-06-19 01:38:50 +08:00
|
|
|
|
|
2025-06-26 00:40:36 +08:00
|
|
|
|
widget->setStyleSheet(QString("image: url(%1); ").arg(imagePath));
|
|
|
|
|
|
// widget->setFixedSize(32, 32); // 调整大小以适应图片
|
2025-06-19 01:38:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-26 01:10:21 +08:00
|
|
|
|
// 设置相机1名称
|
|
|
|
|
|
void devstatus::setCamera1Name(const QString& name)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_camera1Name = name;
|
|
|
|
|
|
// 如果相机1已经初始化过状态,则更新显示文本
|
|
|
|
|
|
if (ui->dev_camera_1_txt) {
|
|
|
|
|
|
updateCamera1DisplayText(ui->dev_camera_1_txt->text().contains("在线"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置相机2名称
|
|
|
|
|
|
void devstatus::setCamera2Name(const QString& name)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_camera2Name = name;
|
|
|
|
|
|
// 如果相机2已经初始化过状态,则更新显示文本
|
|
|
|
|
|
if (ui->dev_camera_2_txt) {
|
|
|
|
|
|
updateCamera2DisplayText(ui->dev_camera_2_txt->text().contains("在线"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 更新相机1状态
|
|
|
|
|
|
void devstatus::updateCamera1Status(bool isConnected)
|
|
|
|
|
|
{
|
|
|
|
|
|
setCameraStatusImage(ui->dev_camer_1_img, isConnected);
|
2025-07-26 01:10:21 +08:00
|
|
|
|
updateCamera1DisplayText(isConnected);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新相机2状态
|
|
|
|
|
|
void devstatus::updateCamera2Status(bool isConnected)
|
|
|
|
|
|
{
|
|
|
|
|
|
setCameraStatusImage(ui->dev_camer_2_img, isConnected);
|
|
|
|
|
|
updateCamera2DisplayText(isConnected);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新相机1显示文本的私有方法
|
|
|
|
|
|
void devstatus::updateCamera1DisplayText(bool isConnected)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString statusText;
|
|
|
|
|
|
if (m_camera1Name.isEmpty()) {
|
|
|
|
|
|
statusText = isConnected ? "相机1在线" : "相机1离线";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
statusText = isConnected ? QString("%1在线").arg(m_camera1Name) : QString("%1离线").arg(m_camera1Name);
|
|
|
|
|
|
}
|
2025-06-19 01:38:50 +08:00
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-26 01:10:21 +08:00
|
|
|
|
// 更新相机2显示文本的私有方法
|
|
|
|
|
|
void devstatus::updateCamera2DisplayText(bool isConnected)
|
2025-06-19 01:38:50 +08:00
|
|
|
|
{
|
2025-07-26 01:10:21 +08:00
|
|
|
|
QString statusText;
|
|
|
|
|
|
if (m_camera2Name.isEmpty()) {
|
|
|
|
|
|
statusText = isConnected ? "相机2在线" : "相机2离线";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
statusText = isConnected ? QString("%1在线").arg(m_camera2Name) : QString("%1离线").arg(m_camera2Name);
|
|
|
|
|
|
}
|
2025-06-19 01:38:50 +08:00
|
|
|
|
|
|
|
|
|
|
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);
|
2025-07-23 01:35:14 +08:00
|
|
|
|
ui->dev_robot_txt->setStyleSheet(colorStyle);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新串口状态
|
|
|
|
|
|
void devstatus::updateSerialStatus(bool isConnected)
|
|
|
|
|
|
{
|
|
|
|
|
|
setRobotStatusImage(ui->dev_robot_img, isConnected);
|
|
|
|
|
|
QString statusText = isConnected ? "RS485在线" : "RS485离线";
|
|
|
|
|
|
QString colorStyle = isConnected ? "color: rgb(140, 180, 60);" : "color: rgb(220, 60, 60);";
|
|
|
|
|
|
|
|
|
|
|
|
ui->dev_robot_txt->setText(statusText);
|
2025-06-19 01:38:50 +08:00
|
|
|
|
ui->dev_robot_txt->setStyleSheet(colorStyle);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-28 23:06:09 +08:00
|
|
|
|
// 设置相机数量(用于控制相机二的显示和布局方向)
|
2025-06-19 01:38:50 +08:00
|
|
|
|
void devstatus::setCameraCount(int cameraCount)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 如果相机数量小于2,隐藏相机二相关的UI元素
|
|
|
|
|
|
bool showCamera2 = (cameraCount >= 2);
|
|
|
|
|
|
|
2025-06-25 01:37:57 +08:00
|
|
|
|
LOG_DEBUG("setCameraCount: %d \n", cameraCount);
|
2025-06-19 01:38:50 +08:00
|
|
|
|
|
2025-06-26 00:40:36 +08:00
|
|
|
|
// 隐藏整个相机2的frame,而不是单独隐藏图片和文字
|
|
|
|
|
|
if (ui->frame_camera_2) {
|
|
|
|
|
|
ui->frame_camera_2->setVisible(showCamera2);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 如果frame_camera_2不存在,则单独隐藏图片和文字控件
|
|
|
|
|
|
ui->dev_camer_2_img->setVisible(showCamera2);
|
|
|
|
|
|
ui->dev_camera_2_txt->setVisible(showCamera2);
|
|
|
|
|
|
}
|
2025-06-28 23:06:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 根据相机数量选择布局方式
|
|
|
|
|
|
if (cameraCount >= 2) {
|
|
|
|
|
|
// 多相机:纵向排列
|
|
|
|
|
|
setVerticalLayout();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 单相机:横向排列,相机和机械臂各占一半
|
|
|
|
|
|
setHorizontalLayoutForSingleCamera();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置为纵向布局
|
|
|
|
|
|
void devstatus::setVerticalLayout()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 调整主widget的尺寸以适应纵向布局
|
|
|
|
|
|
this->setMinimumSize(180, 198);
|
|
|
|
|
|
this->resize(180, 198);
|
|
|
|
|
|
|
|
|
|
|
|
// 通过调整每个frame的尺寸和位置来模拟垂直布局
|
|
|
|
|
|
adjustFramesForVerticalLayout();
|
|
|
|
|
|
|
|
|
|
|
|
LOG_DEBUG("Layout adjusted for vertical display\n");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置为单相机横向布局(相机和机械臂各占一半)
|
|
|
|
|
|
void devstatus::setHorizontalLayoutForSingleCamera()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 设置单相机模式的widget尺寸
|
|
|
|
|
|
this->setMinimumSize(180, 80);
|
|
|
|
|
|
this->resize(180, 80);
|
|
|
|
|
|
|
|
|
|
|
|
// 调整为单相机横向布局的frame尺寸和位置
|
|
|
|
|
|
adjustFramesForSingleCameraHorizontalLayout();
|
|
|
|
|
|
|
|
|
|
|
|
LOG_DEBUG("Layout adjusted for single camera horizontal display\n");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 调整frames为纵向排列
|
|
|
|
|
|
void devstatus::adjustFramesForVerticalLayout()
|
|
|
|
|
|
{
|
|
|
|
|
|
int frameWidth = 180;
|
|
|
|
|
|
int frameHeight = 64;
|
|
|
|
|
|
int spacing = 2;
|
|
|
|
|
|
int startY = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// 重新定位frame的位置以实现纵向排列效果
|
|
|
|
|
|
if (ui->frame_camera_1) {
|
|
|
|
|
|
ui->frame_camera_1->setGeometry(0, startY, frameWidth, frameHeight);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ui->frame_camera_2) {
|
|
|
|
|
|
ui->frame_camera_2->setGeometry(0, startY + frameHeight + spacing, frameWidth, frameHeight);
|
|
|
|
|
|
startY += frameHeight + spacing;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ui->frame_robot) {
|
|
|
|
|
|
ui->frame_robot->setGeometry(0, startY + frameHeight + spacing, frameWidth, frameHeight);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 调整frames为单相机横向排列(相机和机械臂各占一半)
|
|
|
|
|
|
void devstatus::adjustFramesForSingleCameraHorizontalLayout()
|
|
|
|
|
|
{
|
|
|
|
|
|
int frameWidth = 275; // 每个frame占一半宽度 (180/2 - 5间距)
|
|
|
|
|
|
int frameHeight = 70;
|
|
|
|
|
|
int spacing = 6;
|
|
|
|
|
|
|
|
|
|
|
|
// 相机1占左半边
|
|
|
|
|
|
if (ui->frame_camera_1) {
|
|
|
|
|
|
ui->frame_camera_1->setGeometry(0, 0, frameWidth, frameHeight);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 相机2隐藏(在setCameraCount中已处理)
|
|
|
|
|
|
|
|
|
|
|
|
// 机械臂占右半边
|
|
|
|
|
|
if (ui->frame_robot) {
|
|
|
|
|
|
ui->frame_robot->setGeometry(frameWidth + spacing, 0, frameWidth, frameHeight);
|
|
|
|
|
|
}
|
2025-06-19 01:38:50 +08:00
|
|
|
|
}
|
2025-07-26 01:10:21 +08:00
|
|
|
|
|
|
|
|
|
|
// 初始化点击事件
|
|
|
|
|
|
void devstatus::initClickEvents()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 为相机1的frame添加点击事件
|
|
|
|
|
|
if (ui->frame_camera_1) {
|
|
|
|
|
|
ui->frame_camera_1->installEventFilter(this);
|
|
|
|
|
|
ui->frame_camera_1->setMouseTracking(true);
|
|
|
|
|
|
ui->frame_camera_1->setCursor(Qt::PointingHandCursor); // 设置鼠标样式为手型
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 为相机2的frame添加点击事件
|
|
|
|
|
|
if (ui->frame_camera_2) {
|
|
|
|
|
|
ui->frame_camera_2->installEventFilter(this);
|
|
|
|
|
|
ui->frame_camera_2->setMouseTracking(true);
|
|
|
|
|
|
ui->frame_camera_2->setCursor(Qt::PointingHandCursor); // 设置鼠标样式为手型
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 事件过滤器,处理鼠标点击事件
|
|
|
|
|
|
bool devstatus::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (event->type() == QEvent::MouseButtonPress) {
|
|
|
|
|
|
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
|
|
|
|
|
|
if (mouseEvent->button() == Qt::LeftButton) {
|
|
|
|
|
|
if (obj == ui->frame_camera_1) {
|
|
|
|
|
|
onCamera1Clicked();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} else if (obj == ui->frame_camera_2) {
|
|
|
|
|
|
onCamera2Clicked();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return QWidget::eventFilter(obj, event);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 相机1点击槽函数
|
|
|
|
|
|
void devstatus::onCamera1Clicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_selectedCameraIndex != 1) {
|
|
|
|
|
|
m_selectedCameraIndex = 1;
|
|
|
|
|
|
setCameraSelectedStyle(1);
|
|
|
|
|
|
emit cameraClicked(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 相机2点击槽函数
|
|
|
|
|
|
void devstatus::onCamera2Clicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_selectedCameraIndex != 2) {
|
|
|
|
|
|
m_selectedCameraIndex = 2;
|
|
|
|
|
|
setCameraSelectedStyle(2);
|
|
|
|
|
|
emit cameraClicked(2);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置相机选中状态的样式
|
|
|
|
|
|
void devstatus::setCameraSelectedStyle(int cameraIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 重置所有相机的样式
|
|
|
|
|
|
if (ui->frame_camera_1) {
|
|
|
|
|
|
ui->frame_camera_1->setStyleSheet("background-color: rgb(37, 38, 42);");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ui->frame_camera_2) {
|
|
|
|
|
|
ui->frame_camera_2->setStyleSheet("background-color: rgb(37, 38, 42);");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置选中相机的样式
|
|
|
|
|
|
QString selectedStyle = "QFrame { background-color: rgb(67, 68, 72);}";
|
|
|
|
|
|
|
|
|
|
|
|
if (cameraIndex == 1 && ui->frame_camera_1) {
|
|
|
|
|
|
ui->frame_camera_1->setStyleSheet(selectedStyle);
|
|
|
|
|
|
} else if (cameraIndex == 2 && ui->frame_camera_2) {
|
|
|
|
|
|
ui->frame_camera_2->setStyleSheet(selectedStyle);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|