#include "wirelesswidget.h" #include "overlaydialogswidget.h" #include #include // 样式常量定义 const QString WirelessWidget::BUTTON_STYLE = R"( QPushButton { background-color: #f5f5f5; color: #333333; border: 1px solid #ddd; border-radius: 6px; padding: 8px 16px; font-size: 14px; font-weight: 500; min-height: 36px; } QPushButton:hover { background-color: #e8e8e8; border-color: #ccc; } QPushButton:pressed { background-color: #d0d0d0; } )"; const QString WirelessWidget::PRIMARY_BUTTON_STYLE = R"( QPushButton { background-color: #2196F3; color: white; border: none; border-radius: 6px; padding: 8px 16px; font-size: 14px; font-weight: 500; min-height: 36px; } QPushButton:hover { background-color: #1976D2; } QPushButton:pressed { background-color: #1565C0; } )"; const QString WirelessWidget::DANGER_BUTTON_STYLE = R"( QPushButton { background-color: #f44336; color: white; border: none; border-radius: 6px; padding: 8px 16px; font-size: 14px; font-weight: 500; min-height: 36px; } QPushButton:hover { background-color: #d32f2f; } QPushButton:pressed { background-color: #c62828; } )"; const QString WirelessWidget::INPUT_STYLE = R"( QLineEdit, QComboBox { background-color: white; border: 1px solid #ddd; border-radius: 6px; padding: 8px 12px; font-size: 14px; min-height: 36px; } QLineEdit:focus, QComboBox:focus { border-color: #2196F3; } QComboBox::drop-down { subcontrol-origin: padding; subcontrol-position: center right; width: 30px; border: none; } QComboBox::down-arrow { image: url(:/icons/arrow_down.svg); width: 14px; height: 14px; } )"; const QString WirelessWidget::GROUP_STYLE = R"( QGroupBox { background-color: white; border: 1px solid #e0e0e0; border-radius: 8px; margin-top: 16px; padding-top: 16px; font-size: 14px; font-weight: 600; } QGroupBox::title { subcontrol-origin: margin; left: 16px; padding: 0 8px; color: #333; } )"; const QString WirelessWidget::TAB_STYLE = R"( QPushButton { background-color: transparent; color: #666; border: none; border-bottom: 2px solid transparent; padding: 12px 24px; font-size: 14px; font-weight: 500; min-width: 100px; } QPushButton:hover { color: #2196F3; background-color: rgba(33, 150, 243, 0.05); } )"; const QString WirelessWidget::TAB_ACTIVE_STYLE = R"( QPushButton { background-color: transparent; color: #2196F3; border: none; border-bottom: 2px solid #2196F3; padding: 12px 24px; font-size: 14px; font-weight: 600; min-width: 100px; } )"; WirelessWidget::WirelessWidget(QWidget *parent) : QWidget(parent), m_currentTab(0) { setupUI(); // 初始化状态刷新定时器 m_statusTimer = new QTimer(this); connect(m_statusTimer, &QTimer::timeout, this, &WirelessWidget::onRefreshStatus); m_statusTimer->start(5000); // 每5秒刷新一次 // 初始刷新 onRefreshStatus(); } void WirelessWidget::setupUI() { QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setSpacing(0); // 标题栏 mainLayout->addWidget(createTitleBar()); // Tab栏 mainLayout->addWidget(createTabBar()); // 内容区域(滚动区域) QScrollArea *scrollArea = new QScrollArea; scrollArea->setWidgetResizable(true); scrollArea->setFrameShape(QFrame::NoFrame); scrollArea->setStyleSheet("QScrollArea { background-color: #f5f5f5; }"); m_contentStack = new QStackedWidget; m_contentStack->addWidget(createWifiPanel()); m_contentStack->addWidget(create4GPanel()); m_contentStack->addWidget(createStatusPanel()); scrollArea->setWidget(m_contentStack); mainLayout->addWidget(scrollArea, 1); // 默认显示WiFi面板 onTabChanged(0); } QWidget *WirelessWidget::createTitleBar() { QWidget *titleBar = new QWidget; titleBar->setFixedHeight(60); titleBar->setStyleSheet("background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #1976D2, stop:1 #1565C0);"); QHBoxLayout *layout = new QHBoxLayout(titleBar); layout->setContentsMargins(16, 0, 16, 0); // 返回按钮 m_backBtn = new QPushButton("← 返回"); m_backBtn->setCursor(Qt::PointingHandCursor); m_backBtn->setStyleSheet(R"( QPushButton { background: rgba(255,255,255,0.2); color: white; border: none; border-radius: 6px; padding: 8px 16px; font-size: 14px; } QPushButton:hover { background: rgba(255,255,255,0.3); } )"); connect(m_backBtn, &QPushButton::clicked, this, &WirelessWidget::backRequested); layout->addWidget(m_backBtn); // 标题(居中) m_titleLabel = new QLabel("无线通讯"); m_titleLabel->setStyleSheet("color: white; font-size: 18px; font-weight: bold;"); m_titleLabel->setAlignment(Qt::AlignCenter); layout->addWidget(m_titleLabel, 1); // 右侧占位,保持标题居中 QWidget *spacer = new QWidget; spacer->setFixedWidth(m_backBtn->sizeHint().width()); layout->addWidget(spacer); return titleBar; } QWidget *WirelessWidget::createTabBar() { QWidget *tabBar = new QWidget; tabBar->setFixedHeight(48); tabBar->setStyleSheet("background-color: white; border-bottom: 1px solid #e0e0e0;"); QHBoxLayout *layout = new QHBoxLayout(tabBar); layout->setContentsMargins(16, 0, 16, 0); layout->setSpacing(0); QStringList tabNames = {"WiFi", "4G网络", "连接状态"}; for (int i = 0; i < tabNames.size(); ++i) { QPushButton *tabBtn = new QPushButton(tabNames[i]); tabBtn->setStyleSheet(i == 0 ? TAB_ACTIVE_STYLE : TAB_STYLE); tabBtn->setCursor(Qt::PointingHandCursor); connect(tabBtn, &QPushButton::clicked, this, [this, i]() { onTabChanged(i); }); layout->addWidget(tabBtn); m_tabButtons.append(tabBtn); } layout->addStretch(); return tabBar; } QWidget *WirelessWidget::createWifiPanel() { QWidget *panel = new QWidget; panel->setStyleSheet("background-color: #f5f5f5;"); QVBoxLayout *layout = new QVBoxLayout(panel); layout->setContentsMargins(20, 20, 20, 20); layout->setSpacing(16); // WiFi列表区域 QGroupBox *listGroup = new QGroupBox("可用网络"); listGroup->setStyleSheet(GROUP_STYLE); QVBoxLayout *listLayout = new QVBoxLayout(listGroup); listLayout->setContentsMargins(16, 24, 16, 16); listLayout->setSpacing(12); // 扫描按钮 QHBoxLayout *scanLayout = new QHBoxLayout; m_wifiScanBtn = new QPushButton("扫描网络"); m_wifiScanBtn->setStyleSheet(PRIMARY_BUTTON_STYLE); m_wifiScanBtn->setFixedWidth(120); m_wifiScanBtn->setCursor(Qt::PointingHandCursor); connect(m_wifiScanBtn, &QPushButton::clicked, this, &WirelessWidget::onWifiScan); scanLayout->addWidget(m_wifiScanBtn); scanLayout->addStretch(); listLayout->addLayout(scanLayout); // WiFi列表 m_wifiList = new QListWidget; m_wifiList->setFixedHeight(200); m_wifiList->setStyleSheet(R"( QListWidget { background-color: white; border: 1px solid #ddd; border-radius: 6px; font-size: 14px; } QListWidget::item { padding: 12px; border-bottom: 1px solid #eee; } QListWidget::item:selected { background-color: #e3f2fd; color: #1976D2; } QListWidget::item:hover { background-color: #f5f5f5; } )"); connect(m_wifiList, &QListWidget::itemClicked, this, &WirelessWidget::onWifiItemClicked); listLayout->addWidget(m_wifiList); layout->addWidget(listGroup); // 连接设置区域 QGroupBox *connectGroup = new QGroupBox("连接设置"); connectGroup->setStyleSheet(GROUP_STYLE); QVBoxLayout *connectLayout = new QVBoxLayout(connectGroup); connectLayout->setContentsMargins(16, 24, 16, 16); connectLayout->setSpacing(12); // 密码输入 QHBoxLayout *passwordLayout = new QHBoxLayout; QLabel *passwordLabel = new QLabel("密码:"); passwordLabel->setFixedWidth(60); passwordLabel->setStyleSheet("font-size: 14px; color: #333;"); passwordLayout->addWidget(passwordLabel); m_wifiPasswordEdit = new QLineEdit; m_wifiPasswordEdit->setStyleSheet(INPUT_STYLE); m_wifiPasswordEdit->setEchoMode(QLineEdit::Password); m_wifiPasswordEdit->setPlaceholderText("输入WiFi密码"); passwordLayout->addWidget(m_wifiPasswordEdit, 1); connectLayout->addLayout(passwordLayout); // 连接状态 QHBoxLayout *statusLayout = new QHBoxLayout; QLabel *statusTitle = new QLabel("状态:"); statusTitle->setFixedWidth(60); statusTitle->setStyleSheet("font-size: 14px; color: #333;"); statusLayout->addWidget(statusTitle); m_wifiStatusLabel = new QLabel("未连接"); m_wifiStatusLabel->setStyleSheet("font-size: 14px; color: #f44336;"); statusLayout->addWidget(m_wifiStatusLabel); statusLayout->addStretch(); connectLayout->addLayout(statusLayout); // 信号强度 QHBoxLayout *signalLayout = new QHBoxLayout; QLabel *signalTitle = new QLabel("信号:"); signalTitle->setFixedWidth(60); signalTitle->setStyleSheet("font-size: 14px; color: #333;"); signalLayout->addWidget(signalTitle); m_wifiSignalBar = new QProgressBar; m_wifiSignalBar->setFixedHeight(10); m_wifiSignalBar->setRange(0, 100); m_wifiSignalBar->setValue(0); m_wifiSignalBar->setTextVisible(false); m_wifiSignalBar->setStyleSheet(R"( QProgressBar { background-color: #e0e0e0; border-radius: 5px; } QProgressBar::chunk { background-color: #4CAF50; border-radius: 5px; } )"); signalLayout->addWidget(m_wifiSignalBar, 1); connectLayout->addLayout(signalLayout); // 操作按钮 QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addStretch(); m_wifiDisconnectBtn = new QPushButton("断开连接"); m_wifiDisconnectBtn->setStyleSheet(DANGER_BUTTON_STYLE); m_wifiDisconnectBtn->setFixedWidth(100); m_wifiDisconnectBtn->setCursor(Qt::PointingHandCursor); m_wifiDisconnectBtn->setEnabled(false); connect(m_wifiDisconnectBtn, &QPushButton::clicked, this, &WirelessWidget::onWifiDisconnect); buttonLayout->addWidget(m_wifiDisconnectBtn); m_wifiConnectBtn = new QPushButton("连接"); m_wifiConnectBtn->setStyleSheet(PRIMARY_BUTTON_STYLE); m_wifiConnectBtn->setFixedWidth(100); m_wifiConnectBtn->setCursor(Qt::PointingHandCursor); connect(m_wifiConnectBtn, &QPushButton::clicked, this, &WirelessWidget::onWifiConnect); buttonLayout->addWidget(m_wifiConnectBtn); connectLayout->addLayout(buttonLayout); layout->addWidget(connectGroup); layout->addStretch(); // 添加模拟WiFi数据 updateWifiList(); return panel; } QWidget *WirelessWidget::create4GPanel() { QWidget *panel = new QWidget; panel->setStyleSheet("background-color: #f5f5f5;"); QVBoxLayout *layout = new QVBoxLayout(panel); layout->setContentsMargins(20, 20, 20, 20); layout->setSpacing(16); // SIM卡状态 QGroupBox *simGroup = new QGroupBox("SIM卡状态"); simGroup->setStyleSheet(GROUP_STYLE); QVBoxLayout *simLayout = new QVBoxLayout(simGroup); simLayout->setContentsMargins(16, 24, 16, 16); simLayout->setSpacing(12); QHBoxLayout *simStatusLayout = new QHBoxLayout; QLabel *simTitle = new QLabel("SIM卡:"); simTitle->setFixedWidth(80); simTitle->setStyleSheet("font-size: 14px; color: #333;"); simStatusLayout->addWidget(simTitle); m_simStatusLabel = new QLabel("已插入 (中国移动)"); m_simStatusLabel->setStyleSheet("font-size: 14px; color: #4CAF50;"); simStatusLayout->addWidget(m_simStatusLabel); simStatusLayout->addStretch(); simLayout->addLayout(simStatusLayout); // 信号强度 QHBoxLayout *signal4GLayout = new QHBoxLayout; QLabel *signal4GTitle = new QLabel("信号强度:"); signal4GTitle->setFixedWidth(80); signal4GTitle->setStyleSheet("font-size: 14px; color: #333;"); signal4GLayout->addWidget(signal4GTitle); m_4gSignalBar = new QProgressBar; m_4gSignalBar->setFixedHeight(10); m_4gSignalBar->setRange(0, 100); m_4gSignalBar->setValue(75); m_4gSignalBar->setTextVisible(false); m_4gSignalBar->setStyleSheet(R"( QProgressBar { background-color: #e0e0e0; border-radius: 5px; } QProgressBar::chunk { background-color: #4CAF50; border-radius: 5px; } )"); signal4GLayout->addWidget(m_4gSignalBar, 1); simLayout->addLayout(signal4GLayout); layout->addWidget(simGroup); // APN设置 QGroupBox *apnGroup = new QGroupBox("APN设置"); apnGroup->setStyleSheet(GROUP_STYLE); QVBoxLayout *apnLayout = new QVBoxLayout(apnGroup); apnLayout->setContentsMargins(16, 24, 16, 16); apnLayout->setSpacing(12); // APN选择 QHBoxLayout *apnSelectLayout = new QHBoxLayout; QLabel *apnSelectLabel = new QLabel("预设APN:"); apnSelectLabel->setFixedWidth(80); apnSelectLabel->setStyleSheet("font-size: 14px; color: #333;"); apnSelectLayout->addWidget(apnSelectLabel); m_apnCombo = new QComboBox; m_apnCombo->setStyleSheet(INPUT_STYLE); m_apnCombo->addItems({"中国移动 (cmnet)", "中国联通 (3gnet)", "中国电信 (ctnet)", "自定义"}); m_apnCombo->setCursor(Qt::PointingHandCursor); apnSelectLayout->addWidget(m_apnCombo, 1); apnLayout->addLayout(apnSelectLayout); // 自定义APN QHBoxLayout *apnCustomLayout = new QHBoxLayout; QLabel *apnCustomLabel = new QLabel("APN:"); apnCustomLabel->setFixedWidth(80); apnCustomLabel->setStyleSheet("font-size: 14px; color: #333;"); apnCustomLayout->addWidget(apnCustomLabel); m_apnEdit = new QLineEdit; m_apnEdit->setStyleSheet(INPUT_STYLE); m_apnEdit->setPlaceholderText("输入自定义APN"); m_apnEdit->setText("cmnet"); apnCustomLayout->addWidget(m_apnEdit, 1); apnLayout->addLayout(apnCustomLayout); // 用户名 QHBoxLayout *usernameLayout = new QHBoxLayout; QLabel *usernameLabel = new QLabel("用户名:"); usernameLabel->setFixedWidth(80); usernameLabel->setStyleSheet("font-size: 14px; color: #333;"); usernameLayout->addWidget(usernameLabel); m_4gUsernameEdit = new QLineEdit; m_4gUsernameEdit->setStyleSheet(INPUT_STYLE); m_4gUsernameEdit->setPlaceholderText("可选"); usernameLayout->addWidget(m_4gUsernameEdit, 1); apnLayout->addLayout(usernameLayout); // 密码 QHBoxLayout *password4GLayout = new QHBoxLayout; QLabel *password4GLabel = new QLabel("密码:"); password4GLabel->setFixedWidth(80); password4GLabel->setStyleSheet("font-size: 14px; color: #333;"); password4GLayout->addWidget(password4GLabel); m_4gPasswordEdit = new QLineEdit; m_4gPasswordEdit->setStyleSheet(INPUT_STYLE); m_4gPasswordEdit->setEchoMode(QLineEdit::Password); m_4gPasswordEdit->setPlaceholderText("可选"); password4GLayout->addWidget(m_4gPasswordEdit, 1); apnLayout->addLayout(password4GLayout); layout->addWidget(apnGroup); // 连接状态 QGroupBox *statusGroup = new QGroupBox("连接状态"); statusGroup->setStyleSheet(GROUP_STYLE); QVBoxLayout *statusLayout = new QVBoxLayout(statusGroup); statusLayout->setContentsMargins(16, 24, 16, 16); statusLayout->setSpacing(12); QHBoxLayout *status4GLayout = new QHBoxLayout; QLabel *status4GTitle = new QLabel("状态:"); status4GTitle->setFixedWidth(80); status4GTitle->setStyleSheet("font-size: 14px; color: #333;"); status4GLayout->addWidget(status4GTitle); m_4gStatusLabel = new QLabel("未连接"); m_4gStatusLabel->setStyleSheet("font-size: 14px; color: #f44336;"); status4GLayout->addWidget(m_4gStatusLabel); status4GLayout->addStretch(); statusLayout->addLayout(status4GLayout); // 操作按钮 QHBoxLayout *button4GLayout = new QHBoxLayout; button4GLayout->addStretch(); m_4gDisconnectBtn = new QPushButton("断开连接"); m_4gDisconnectBtn->setStyleSheet(DANGER_BUTTON_STYLE); m_4gDisconnectBtn->setFixedWidth(100); m_4gDisconnectBtn->setCursor(Qt::PointingHandCursor); m_4gDisconnectBtn->setEnabled(false); connect(m_4gDisconnectBtn, &QPushButton::clicked, this, &WirelessWidget::on4GDisconnect); button4GLayout->addWidget(m_4gDisconnectBtn); m_4gConnectBtn = new QPushButton("连接"); m_4gConnectBtn->setStyleSheet(PRIMARY_BUTTON_STYLE); m_4gConnectBtn->setFixedWidth(100); m_4gConnectBtn->setCursor(Qt::PointingHandCursor); connect(m_4gConnectBtn, &QPushButton::clicked, this, &WirelessWidget::on4GConnect); button4GLayout->addWidget(m_4gConnectBtn); statusLayout->addLayout(button4GLayout); layout->addWidget(statusGroup); layout->addStretch(); return panel; } QWidget *WirelessWidget::createStatusPanel() { QWidget *panel = new QWidget; panel->setStyleSheet("background-color: #f5f5f5;"); QVBoxLayout *layout = new QVBoxLayout(panel); layout->setContentsMargins(20, 20, 20, 20); layout->setSpacing(16); // 网络信息 QGroupBox *infoGroup = new QGroupBox("网络信息"); infoGroup->setStyleSheet(GROUP_STYLE); QVBoxLayout *infoLayout = new QVBoxLayout(infoGroup); infoLayout->setContentsMargins(16, 24, 16, 16); infoLayout->setSpacing(12); auto createInfoRow = [](const QString &title, QLabel *&valueLabel, const QString &defaultValue) -> QHBoxLayout * { QHBoxLayout *row = new QHBoxLayout; QLabel *titleLabel = new QLabel(title); titleLabel->setFixedWidth(100); titleLabel->setStyleSheet("font-size: 14px; color: #666;"); row->addWidget(titleLabel); valueLabel = new QLabel(defaultValue); valueLabel->setStyleSheet("font-size: 14px; color: #333; font-weight: 500;"); row->addWidget(valueLabel); row->addStretch(); return row; }; infoLayout->addLayout(createInfoRow("连接类型:", m_connectionTypeLabel, "未连接")); infoLayout->addLayout(createInfoRow("IP地址:", m_ipAddressLabel, "--")); infoLayout->addLayout(createInfoRow("MAC地址:", m_macAddressLabel, "--")); infoLayout->addLayout(createInfoRow("信号强度:", m_signalStrengthLabel, "--")); layout->addWidget(infoGroup); // 流量统计 QGroupBox *trafficGroup = new QGroupBox("流量统计"); trafficGroup->setStyleSheet(GROUP_STYLE); QVBoxLayout *trafficLayout = new QVBoxLayout(trafficGroup); trafficLayout->setContentsMargins(16, 24, 16, 16); trafficLayout->setSpacing(12); trafficLayout->addLayout(createInfoRow("上传速度:", m_uploadSpeedLabel, "0 KB/s")); trafficLayout->addLayout(createInfoRow("下载速度:", m_downloadSpeedLabel, "0 KB/s")); layout->addWidget(trafficGroup); // 刷新按钮 QHBoxLayout *refreshLayout = new QHBoxLayout; refreshLayout->addStretch(); QPushButton *refreshBtn = new QPushButton("刷新状态"); refreshBtn->setStyleSheet(PRIMARY_BUTTON_STYLE); refreshBtn->setFixedWidth(120); refreshBtn->setCursor(Qt::PointingHandCursor); connect(refreshBtn, &QPushButton::clicked, this, &WirelessWidget::onRefreshStatus); refreshLayout->addWidget(refreshBtn); layout->addLayout(refreshLayout); layout->addStretch(); return panel; } void WirelessWidget::onTabChanged(int index) { m_currentTab = index; m_contentStack->setCurrentIndex(index); // 更新Tab样式 for (int i = 0; i < m_tabButtons.size(); ++i) { m_tabButtons[i]->setStyleSheet(i == index ? TAB_ACTIVE_STYLE : TAB_STYLE); } } void WirelessWidget::updateWifiList() { m_wifiList->clear(); // 添加模拟WiFi数据 QStringList wifiNetworks = { "🔒 Office_5G (信号: 优)", "🔒 Office_2.4G (信号: 良)", "🔒 Guest_Network (信号: 中)", "🔓 Public_WiFi (信号: 弱)", "🔒 HomeNetwork (信号: 弱)"}; for (const QString &network : wifiNetworks) { QListWidgetItem *item = new QListWidgetItem(network); m_wifiList->addItem(item); } } void WirelessWidget::onWifiScan() { m_wifiScanBtn->setEnabled(false); m_wifiScanBtn->setText("扫描中..."); // 模拟扫描延迟 QTimer::singleShot(1500, this, [this]() { updateWifiList(); m_wifiScanBtn->setEnabled(true); m_wifiScanBtn->setText("扫描网络"); OverlayDialog::information(window(), "扫描完成", "发现 5 个可用网络"); }); } void WirelessWidget::onWifiItemClicked(QListWidgetItem *item) { Q_UNUSED(item) m_wifiPasswordEdit->setFocus(); } void WirelessWidget::onWifiConnect() { if (m_wifiList->currentItem() == nullptr) { OverlayDialog::warning(window(), "提示", "请先选择要连接的WiFi网络"); return; } QString network = m_wifiList->currentItem()->text(); bool needPassword = network.contains("🔒"); if (needPassword && m_wifiPasswordEdit->text().isEmpty()) { OverlayDialog::warning(window(), "提示", "请输入WiFi密码"); return; } m_wifiConnectBtn->setEnabled(false); m_wifiConnectBtn->setText("连接中..."); // 模拟连接 QTimer::singleShot(2000, this, [this, network]() { m_wifiConnectBtn->setEnabled(true); m_wifiConnectBtn->setText("连接"); // 模拟连接成功 m_wifiStatusLabel->setText("已连接"); m_wifiStatusLabel->setStyleSheet("font-size: 14px; color: #4CAF50;"); m_wifiSignalBar->setValue(85); m_wifiDisconnectBtn->setEnabled(true); updateConnectionStatus(); OverlayDialog::information(window(), "连接成功", "已成功连接到WiFi网络"); }); } void WirelessWidget::onWifiDisconnect() { m_wifiStatusLabel->setText("未连接"); m_wifiStatusLabel->setStyleSheet("font-size: 14px; color: #f44336;"); m_wifiSignalBar->setValue(0); m_wifiDisconnectBtn->setEnabled(false); m_wifiPasswordEdit->clear(); updateConnectionStatus(); OverlayDialog::information(window(), "已断开", "WiFi连接已断开"); } void WirelessWidget::on4GConnect() { m_4gConnectBtn->setEnabled(false); m_4gConnectBtn->setText("连接中..."); QTimer::singleShot(2000, this, [this]() { m_4gConnectBtn->setEnabled(true); m_4gConnectBtn->setText("连接"); m_4gStatusLabel->setText("已连接 (4G LTE)"); m_4gStatusLabel->setStyleSheet("font-size: 14px; color: #4CAF50;"); m_4gDisconnectBtn->setEnabled(true); updateConnectionStatus(); OverlayDialog::information(window(), "连接成功", "4G网络连接成功"); }); } void WirelessWidget::on4GDisconnect() { m_4gStatusLabel->setText("未连接"); m_4gStatusLabel->setStyleSheet("font-size: 14px; color: #f44336;"); m_4gDisconnectBtn->setEnabled(false); updateConnectionStatus(); OverlayDialog::information(window(), "已断开", "4G网络连接已断开"); } void WirelessWidget::onRefreshStatus() { updateConnectionStatus(); } void WirelessWidget::updateConnectionStatus() { // 检查连接状态并更新状态面板 bool wifiConnected = m_wifiStatusLabel->text().contains("已连接"); bool g4Connected = m_4gStatusLabel->text().contains("已连接"); if (wifiConnected) { m_connectionTypeLabel->setText("WiFi"); m_ipAddressLabel->setText("192.168.1.105"); m_macAddressLabel->setText("AA:BB:CC:DD:EE:FF"); m_signalStrengthLabel->setText(QString("%1%").arg(m_wifiSignalBar->value())); m_uploadSpeedLabel->setText("125 KB/s"); m_downloadSpeedLabel->setText("2.3 MB/s"); } else if (g4Connected) { m_connectionTypeLabel->setText("4G LTE"); m_ipAddressLabel->setText("10.0.0.55"); m_macAddressLabel->setText("--"); m_signalStrengthLabel->setText(QString("%1%").arg(m_4gSignalBar->value())); m_uploadSpeedLabel->setText("85 KB/s"); m_downloadSpeedLabel->setText("1.2 MB/s"); } else { m_connectionTypeLabel->setText("未连接"); m_ipAddressLabel->setText("--"); m_macAddressLabel->setText("--"); m_signalStrengthLabel->setText("--"); m_uploadSpeedLabel->setText("0 KB/s"); m_downloadSpeedLabel->setText("0 KB/s"); } }