设备修改

main
123 4 days ago
parent 625dc523a0
commit 96f7f667fa

@ -168,17 +168,6 @@ public:
*/
void updateDeviceStatus(DeviceStatus status);
/**
* @brief
* @param strength (0-100)
*/
void updateSignalStrength(int strength);
/**
* @brief
* @param level (0-100)
*/
void updateBatteryLevel(int level);
/**
* @brief
@ -337,10 +326,6 @@ private:
// UI组件 - 信息区域
QLabel *m_locationLabel; ///< 位置信息标签
QLabel *m_networkLabel; ///< 网络地址标签
QLabel *m_signalLabel; ///< 信号强度标签
QLabel *m_batteryLabel; ///< 电量标签
QProgressBar *m_signalProgressBar; ///< 信号强度进度条
QProgressBar *m_batteryProgressBar; ///< 电量进度条
// UI组件 - 操作按钮
QPushButton *m_detailsButton; ///< 详情按钮
@ -351,11 +336,11 @@ private:
QVBoxLayout *m_mainLayout; ///< 主布局
QHBoxLayout *m_headerLayout; ///< 头部布局
QGridLayout *m_infoLayout; ///< 信息区域布局
QHBoxLayout *m_buttonLayout; ///< 按钮区域布局
QVBoxLayout *m_buttonLayout; ///< 按钮区域布局(垂直排列)
// 样式和配置 - 优化的卡片尺寸
static const int CARD_WIDTH = 320; ///< 卡片宽度 (再次增加)
static const int CARD_HEIGHT = 280; ///< 卡片高度 (显著增加)
static const int CARD_HEIGHT = 240; ///< 卡片高度 (增加以显示完整信息)
static const int BORDER_RADIUS = 8; ///< 圆角半径
static const int PADDING = 15; ///< 内边距 (增加)
static const int MARGIN = 8; ///< 外边距 (增加)

@ -109,8 +109,8 @@
function initMap() {
map = new AMap.Map('container', {
resizeEnable: true,
zoom: 18,
center: [113.04336, 28.2561619], // 恢复为原来的实验地点坐标
zoom: 19,
center: [113.04436, 28.2551619], // 恢复为原来的实验地点坐标
pitch: 0,
showLabel: true,
mapStyle: 'amap://styles/normal',

@ -31,10 +31,6 @@ DeviceCard::DeviceCard(const DeviceInfo &device, QWidget *parent)
, m_statusIndicator(nullptr)
, m_locationLabel(nullptr)
, m_networkLabel(nullptr)
, m_signalLabel(nullptr)
, m_batteryLabel(nullptr)
, m_signalProgressBar(nullptr)
, m_batteryProgressBar(nullptr)
, m_detailsButton(nullptr)
, m_controlButton(nullptr)
, m_locationButton(nullptr)
@ -65,122 +61,109 @@ void DeviceCard::setupUI()
// 创建主布局 - 增加垂直间距
m_mainLayout = new QVBoxLayout(this);
m_mainLayout->setContentsMargins(PADDING, PADDING, PADDING, PADDING);
m_mainLayout->setSpacing(15); // 增加间距
m_mainLayout->setSpacing(18); // 增加间距以适应更大的卡片
// === 头部区域 ===
m_headerLayout = new QHBoxLayout();
m_headerLayout->setSpacing(12);
m_headerLayout->setSpacing(8); // 减少间距,让名称更靠左
m_headerLayout->setContentsMargins(0, 0, 0, 0); // 移除边距
// 设备图标 - 增大尺寸
// 设备图标 - 适当调整尺寸
m_deviceIconLabel = new QLabel();
m_deviceIconLabel->setFixedSize(40, 40);
m_deviceIconLabel->setFixedSize(32, 32); // 稍微减小图标
m_deviceIconLabel->setScaledContents(true);
updateDeviceIcon();
// 设备名称 - 增大字体
// 设备名称 - 调整字体和位置
m_deviceNameLabel = new QLabel(m_deviceInfo.name);
m_deviceNameLabel->setFont(QFont("Arial", 16, QFont::Bold));
m_deviceNameLabel->setFont(QFont("Arial", 15, QFont::Bold)); // 稍微减小字体
m_deviceNameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_deviceNameLabel->setWordWrap(true);
m_deviceNameLabel->setMinimumWidth(150);
m_deviceNameLabel->setWordWrap(false); // 禁用换行
m_deviceNameLabel->setMinimumWidth(140); // 增加最小宽度,确保名称完整显示
m_deviceNameLabel->setMaximumHeight(20); // 限制高度,防止换行
m_deviceNameLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); // 左对齐,垂直居中
m_deviceNameLabel->setContentsMargins(0, 0, 0, 0); // 恢复正常边距
// 状态指示器(圆点)- 增大尺寸
// 状态指示器(圆点)- 适当调整尺寸
m_statusIndicator = new QLabel("");
m_statusIndicator->setFixedSize(24, 24);
m_statusIndicator->setFixedSize(20, 20);
m_statusIndicator->setAlignment(Qt::AlignCenter);
m_statusIndicator->setFont(QFont("Arial", 18));
m_statusIndicator->setFont(QFont("Arial", 16));
// 状态文本 - 增大字体
// 状态文本 - 适当调整字体
m_statusLabel = new QLabel(getStatusText(m_currentStatus));
m_statusLabel->setFont(QFont("Arial", 13, QFont::Bold));
m_statusLabel->setMinimumWidth(40); // 确保状态文本有足够空间
m_headerLayout->addWidget(m_deviceIconLabel);
m_headerLayout->addWidget(m_deviceNameLabel);
m_headerLayout->addStretch();
m_headerLayout->addWidget(m_deviceNameLabel, 1); // 给名称更多空间
m_headerLayout->addWidget(m_statusIndicator);
m_headerLayout->addWidget(m_statusLabel);
// === 信息区域 ===
// === 信息和按钮区域 - 水平布局 ===
QHBoxLayout *contentLayout = new QHBoxLayout();
contentLayout->setSpacing(20);
// 左侧:信息区域
m_infoLayout = new QGridLayout();
m_infoLayout->setSpacing(12); // 增加间距
m_infoLayout->setSpacing(12);
// 位置信息 - 增大显示
QLabel *locationIcon = new QLabel("📍");
locationIcon->setFixedSize(22, 22);
locationIcon->setFixedSize(24, 24);
locationIcon->setAlignment(Qt::AlignCenter);
locationIcon->setFont(QFont("Arial", 14));
locationIcon->setFont(QFont("Arial", 16));
m_locationLabel = new QLabel(QString("%1,%2").arg(m_deviceInfo.longitude, 0, 'f', 2).arg(m_deviceInfo.latitude, 0, 'f', 2));
m_locationLabel->setFont(QFont("Arial", 11));
m_locationLabel->setFont(QFont("Arial", 13));
// 网络信息 - 增大显示
QLabel *networkIcon = new QLabel("🌐");
networkIcon->setFixedSize(22, 22);
networkIcon->setFixedSize(24, 24);
networkIcon->setAlignment(Qt::AlignCenter);
networkIcon->setFont(QFont("Arial", 14));
networkIcon->setFont(QFont("Arial", 16));
m_networkLabel = new QLabel(m_deviceInfo.ipAddress);
m_networkLabel->setFont(QFont("Arial", 11));
// 信号强度 - 增大显示
QLabel *signalIcon = new QLabel("📶");
signalIcon->setFixedSize(22, 22);
signalIcon->setAlignment(Qt::AlignCenter);
signalIcon->setFont(QFont("Arial", 14));
m_signalLabel = new QLabel(QString("%1%").arg(m_deviceInfo.signalStrength));
m_signalLabel->setFont(QFont("Arial", 11, QFont::Bold));
m_signalProgressBar = new QProgressBar();
m_signalProgressBar->setRange(0, 100);
m_signalProgressBar->setValue(m_deviceInfo.signalStrength);
m_signalProgressBar->setFixedHeight(16); // 增加进度条高度
m_signalProgressBar->setTextVisible(false);
// 电量水平 - 增大显示
QLabel *batteryIcon = new QLabel("🔋");
batteryIcon->setFixedSize(22, 22);
batteryIcon->setAlignment(Qt::AlignCenter);
batteryIcon->setFont(QFont("Arial", 14));
m_batteryLabel = new QLabel(QString("%1%").arg(m_deviceInfo.batteryLevel));
m_batteryLabel->setFont(QFont("Arial", 11, QFont::Bold));
m_batteryProgressBar = new QProgressBar();
m_batteryProgressBar->setRange(0, 100);
m_batteryProgressBar->setValue(m_deviceInfo.batteryLevel);
m_batteryProgressBar->setFixedHeight(16); // 增加进度条高度
m_batteryProgressBar->setTextVisible(false);
m_networkLabel->setFont(QFont("Arial", 13));
// 添加到网格布局
m_infoLayout->addWidget(locationIcon, 0, 0);
m_infoLayout->addWidget(m_locationLabel, 0, 1, 1, 2);
m_infoLayout->addWidget(m_locationLabel, 0, 1);
m_infoLayout->addWidget(networkIcon, 1, 0);
m_infoLayout->addWidget(m_networkLabel, 1, 1, 1, 2);
m_infoLayout->addWidget(signalIcon, 2, 0);
m_infoLayout->addWidget(m_signalLabel, 2, 1);
m_infoLayout->addWidget(m_signalProgressBar, 2, 2);
m_infoLayout->addWidget(batteryIcon, 3, 0);
m_infoLayout->addWidget(m_batteryLabel, 3, 1);
m_infoLayout->addWidget(m_batteryProgressBar, 3, 2);
// === 操作按钮区域 ===
m_buttonLayout = new QHBoxLayout();
m_buttonLayout->setSpacing(8);
m_infoLayout->addWidget(m_networkLabel, 1, 1);
// 创建信息区域容器
QWidget *infoWidget = new QWidget();
infoWidget->setLayout(m_infoLayout);
// 右侧:操作按钮区域
m_buttonLayout = new QVBoxLayout();
m_buttonLayout->setSpacing(6);
m_detailsButton = new QPushButton("详情");
m_detailsButton->setFixedSize(62, 35);
m_detailsButton->setFixedSize(60, 32);
m_detailsButton->setToolTip("设备详情");
m_detailsButton->setFont(QFont("Arial", 11, QFont::Bold));
m_detailsButton->setFont(QFont("Arial", 12, QFont::Bold));
m_controlButton = new QPushButton("控制");
m_controlButton->setFixedSize(62, 35);
m_controlButton->setFixedSize(60, 32);
m_controlButton->setToolTip("设备控制");
m_controlButton->setFont(QFont("Arial", 11, QFont::Bold));
m_controlButton->setFont(QFont("Arial", 12, QFont::Bold));
m_locationButton = new QPushButton("定位");
m_locationButton->setFixedSize(62, 35);
m_locationButton->setFixedSize(60, 32);
m_locationButton->setToolTip("设备定位");
m_locationButton->setFont(QFont("Arial", 11, QFont::Bold));
m_locationButton->setFont(QFont("Arial", 12, QFont::Bold));
m_buttonLayout->addWidget(m_detailsButton);
m_buttonLayout->addWidget(m_controlButton);
m_buttonLayout->addWidget(m_locationButton);
m_buttonLayout->addStretch();
// 创建按钮区域容器
QWidget *buttonWidget = new QWidget();
buttonWidget->setLayout(m_buttonLayout);
// 添加到水平布局
contentLayout->addWidget(infoWidget, 1); // 信息区域占更多空间
contentLayout->addWidget(buttonWidget, 0); // 按钮区域固定大小
// === 组装主布局 ===
m_mainLayout->addLayout(m_headerLayout);
@ -191,8 +174,8 @@ void DeviceCard::setupUI()
separatorLine->setStyleSheet("background-color: rgba(82, 194, 242, 0.6); margin: 4px 0px; border-radius: 1px;");
m_mainLayout->addWidget(separatorLine);
m_mainLayout->addLayout(m_infoLayout);
m_mainLayout->addLayout(m_buttonLayout);
// 添加新的内容布局(信息和按钮水平排列)
m_mainLayout->addLayout(contentLayout);
m_mainLayout->addStretch();
}
@ -248,29 +231,6 @@ void DeviceCard::setupStyle()
m_locationLabel->setStyleSheet(infoLabelStyle);
m_networkLabel->setStyleSheet(infoLabelStyle);
m_signalLabel->setStyleSheet(infoLabelStyle);
m_batteryLabel->setStyleSheet(infoLabelStyle);
// 进度条样式 - 优化为更清晰的显示
QString progressBarStyle =
"QProgressBar {"
" border: 2px solid rgba(82, 194, 242, 0.7);"
" border-radius: 8px;"
" background-color: rgba(25, 35, 45, 0.9);"
" text-align: center;"
" font-weight: bold;"
" color: white;"
" font-size: 10px;"
"}"
"QProgressBar::chunk {"
" background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
" stop:0 #00FF7F, stop:0.7 #FFD700, stop:1 #FF4444);"
" border-radius: 6px;"
" margin: 2px;"
"}";
m_signalProgressBar->setStyleSheet(progressBarStyle);
m_batteryProgressBar->setStyleSheet(progressBarStyle);
// 按钮样式 - 优化为更清晰的显示
QString buttonStyle =
@ -280,10 +240,10 @@ void DeviceCard::setupStyle()
" stop:1 rgba(45, 120, 180, 0.3));"
" color: rgb(230, 240, 250);"
" border: 2px solid rgba(82, 194, 242, 0.5);"
" border-radius: 8px;"
" font-size: 11px;"
" border-radius: 6px;"
" font-size: 12px;"
" font-weight: bold;"
" padding: 4px;"
" padding: 2px;"
"}"
"QPushButton:hover {"
" background: qlineargradient(x1:0, y1:0, x2:0, y2:1,"
@ -321,8 +281,6 @@ void DeviceCard::updateDeviceInfo(const DeviceInfo &device)
m_deviceNameLabel->setText(device.name);
m_locationLabel->setText(formatCoordinates(device.longitude, device.latitude));
m_networkLabel->setText(QString("%1:%2").arg(device.ipAddress).arg(device.port));
m_signalProgressBar->setValue(device.signalStrength);
m_batteryProgressBar->setValue(device.batteryLevel);
updateDeviceIcon();
updateDeviceStatus(device.status);
@ -339,39 +297,7 @@ void DeviceCard::updateDeviceStatus(DeviceStatus status)
qDebug() << "Device status updated:" << m_deviceInfo.name << "status:" << static_cast<int>(status);
}
void DeviceCard::updateSignalStrength(int strength)
{
m_deviceInfo.signalStrength = qBound(0, strength, 100);
m_signalProgressBar->setValue(m_deviceInfo.signalStrength);
// 根据信号强度更新颜色
QString color;
if (strength >= 70) color = "#00FF7F"; // 绿色
else if (strength >= 30) color = "#FFD700"; // 黄色
else color = "#FF4444"; // 红色
m_signalProgressBar->setStyleSheet(
m_signalProgressBar->styleSheet() +
QString("QProgressBar::chunk { background-color: %1; }").arg(color)
);
}
void DeviceCard::updateBatteryLevel(int level)
{
m_deviceInfo.batteryLevel = qBound(0, level, 100);
m_batteryProgressBar->setValue(m_deviceInfo.batteryLevel);
// 根据电量水平更新颜色
QString color;
if (level >= 50) color = "#00FF7F"; // 绿色
else if (level >= 20) color = "#FFD700"; // 黄色
else color = "#FF4444"; // 红色
m_batteryProgressBar->setStyleSheet(
m_batteryProgressBar->styleSheet() +
QString("QProgressBar::chunk { background-color: %1; }").arg(color)
);
}
void DeviceCard::updateLocation(double longitude, double latitude)
{

@ -73,11 +73,11 @@ void DeviceListPanel::setupUI()
// 面板标题
m_titleLabel = new QLabel("🤖 设备管理");
m_titleLabel->setFont(QFont("Arial", 16, QFont::Bold));
m_titleLabel->setFont(QFont("Arial", 18, QFont::Bold));
// 设备数量标签
m_deviceCountLabel = new QLabel("设备: 0");
m_deviceCountLabel->setFont(QFont("Arial", 10));
m_deviceCountLabel->setFont(QFont("Arial", 12));
m_headerLayout->addWidget(m_titleLabel);
m_headerLayout->addStretch();

Loading…
Cancel
Save