|
|
|
@ -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,134 +61,121 @@ 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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加分隔线
|
|
|
|
|
QLabel *separatorLine = new QLabel();
|
|
|
|
|
separatorLine->setFixedHeight(3);
|
|
|
|
|
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,42 +231,19 @@ 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 =
|
|
|
|
|
QString buttonStyle =
|
|
|
|
|
"QPushButton {"
|
|
|
|
|
" background: qlineargradient(x1:0, y1:0, x2:0, y2:1,"
|
|
|
|
|
" stop:0 rgba(82, 194, 242, 0.3),"
|
|
|
|
|
" 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)
|
|
|
|
|
{
|
|
|
|
|