389 lines
11 KiB
C++
Raw Normal View History

2024-11-25 17:15:44 +08:00
#include "titlewidget.h"
#include "ui_titlewidget.h"
#include <QPixmap>
#include <windows.h>
#include <wlanapi.h>
#include "mainwindowpagecontrol.h"
#include <QDebug>
#include <QDir>
#include "icemodule.h"
#include "ccommunicateapi.h"
#include "currentuserdata.h"
#include "loginwidget.h"
2024-12-03 13:41:51 +08:00
#include "BCIManager.h"
2024-11-25 17:15:44 +08:00
TitleWidget::TitleWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::TitleWidget),
checkTimer(nullptr)
{
ui->setupUi(this);
2024-12-03 13:41:51 +08:00
connect(ui->back1_Btn, SIGNAL(clicked()), this, SLOT(slotBackClicked()));
connect(ui->back2_Btn, SIGNAL(clicked()), this, SLOT(slotBackClicked()));
2024-11-25 17:15:44 +08:00
ui->user_Btn->setIcon(QIcon(":/DependFile/Source/User/user1.png"));
2024-12-03 13:41:51 +08:00
ui->user_Btn->setIconSize(QSize(40, 40));
2024-11-25 17:15:44 +08:00
setBackBtnVisible(false);
checkTimer = new QTimer();
checkTimer->setInterval(3000);
2024-12-03 13:41:51 +08:00
connect(checkTimer, SIGNAL(timeout()), this, SLOT(slotCheckTimer()));
2024-11-25 17:15:44 +08:00
checkTimer->start();
2024-12-03 13:41:51 +08:00
connect(CCommunicateAPI::getInstance(), SIGNAL(signalCommunicateChanged(QString)), this, SLOT(slotStateChanged(QString)));
2024-11-25 17:15:44 +08:00
ui->signal_Label->setVisible(false);
ui->wifiSignal2_Label->setVisible(true);
2024-12-03 13:41:51 +08:00
ui->brainSignal_Labe->move(1550, 30);
ui->sound_Button->move(1480, 30);
2024-11-25 17:15:44 +08:00
2024-12-03 13:41:51 +08:00
ui->wifiSignal_Label->move(1620, 30);
2024-11-25 17:15:44 +08:00
2024-11-26 09:14:39 +08:00
2024-11-25 17:15:44 +08:00
ui->title_Label->setText(tr("功能选择")); //默认汉字
ui->quit_Btn->setVisible(false);
ui->back1_Btn->setVisible(true);
ui->back2_Btn->setVisible(true);
m_soundDialog = new SoundDialog();
2024-12-03 13:41:51 +08:00
connect(&BCIManager::getInstance(), &BCIManager::signalDeviceStatus, this, &TitleWidget::slotBciDeviceStatus);
2024-11-25 17:15:44 +08:00
}
TitleWidget::~TitleWidget()
{
if(m_soundDialog)
{
delete m_soundDialog;
}
delete ui;
}
void TitleWidget::slotBackClicked()
{
int currentPage = MainWindowPageControl::getInstance()->getCurrentPageIndex();
2024-12-03 13:41:51 +08:00
if(!(currentPage >= MainPage_E && currentPage <= visionTrain))
2024-11-25 17:15:44 +08:00
{
2024-12-03 13:41:51 +08:00
currentPage = MainPage_E; //初始化异常值276795792,设置当前页索引为0
}
qDebug() << "当前页" << currentPage;
switch(currentPage)
2024-11-25 17:15:44 +08:00
{
2024-12-03 13:41:51 +08:00
case MainPage_E:
{
LoginWidget login;//
login.setWindowModality(Qt::WindowModal);//
login.exec(); //
// MainWindowPageControl::getInstance()->setCurrentPage(LoginPage_E);
// qDebug()<<"开始跳转";
}
break;
case BrainTraining:
case UserPage_E:
case SettingPage_E:
case BicycleParamSet_E:
case FesBicycleParamSet_E:
2024-11-25 17:15:44 +08:00
MainWindowPageControl::getInstance()->setCurrentPage(MainPage_E);
break;
2024-12-03 13:41:51 +08:00
case FesParamSet_E:
{
//分两种情况
switch(m_trainType)
{
case 0://1、直接选择的FES训练跳到主界面
MainWindowPageControl::getInstance()->setCurrentPage(MainPage_E);
break;
case 1://2、从踏车界面跳转到FES界面,跳到踏车界面
MainWindowPageControl::getInstance()->setCurrentPage(BicycleParamSet_E);
break;
}
}
2024-11-25 17:15:44 +08:00
break;
2024-12-03 13:41:51 +08:00
case BicycleToFes_E:
2024-11-25 17:15:44 +08:00
MainWindowPageControl::getInstance()->setCurrentPage(FesBicycleParamSet_E);
2024-12-03 13:41:51 +08:00
break;
case TrainingParamSetting_E:
{
if(m_trainType == 0)
{
MainWindowPageControl::getInstance()->setCurrentPage(BicycleParamSet_E);
}
else if(m_trainType == 1)
{
MainWindowPageControl::getInstance()->setCurrentPage(FesBicycleParamSet_E);
}
2024-11-25 17:15:44 +08:00
2024-12-03 13:41:51 +08:00
//qDebug() <<"Hello";
}
break;
case visionTrain:
MainWindowPageControl::getInstance()->setCurrentPage(BrainTraining);
break;
2024-11-25 17:15:44 +08:00
}
}
//设置当前用户
2024-12-03 13:41:51 +08:00
void TitleWidget::setUser(const ST_PatientMsg &st_patientMsg)
2024-11-25 17:15:44 +08:00
{
ui->user_Btn->setText(st_patientMsg.name);
}
//设置wifi信号强度
void TitleWidget::setSignalStrength(int value)
{
Q_UNUSED(value)
}
//设置标题
void TitleWidget::setTitleByPage(E_PAGENAME pageType)
{
QString title;
switch(pageType)
{
2024-12-03 13:41:51 +08:00
case MainPage_E:
title = tr("功能选择");
setBackBtnVisible(true);
ui->quit_Btn->setVisible(false);
//只修改pageIndex不发送槽函数
MainWindowPageControl::getInstance()->setPageIndex(MainPage_E);
break;
case TrainingPage_E:
title = tr("");//上肢、下肢、四肢训练
setBackBtnVisible(false);
ui->quit_Btn->setVisible(false);
break;
case UserPage_E:
title = tr("用户管理");
setBackBtnVisible(true);
break;
case SettingPage_E:
title = tr("软件设置");
setBackBtnVisible(true);
break;
case BicycleParamSet_E:
title = tr("参数设置");
setBackBtnVisible(true);
break;
case FesParamSet_E:
setBackBtnVisible(true);
title = tr("FES参数");
break;
case FesBicycleParamSet_E:
setBackBtnVisible(true);
title = tr("踏车参数");
break;
case TrainingParamSetting_E:
setBackBtnVisible(true);
title = tr("参数设置");
break;
case BrainTraining:
setBackBtnVisible(true);
title = tr("脑控康复");
break;
case visionTrain:
setBackBtnVisible(true);
title = tr("视觉脑机康复训练");
break;
default:
break;
2024-11-25 17:15:44 +08:00
}
ui->title_Label->setText(title);
}
void TitleWidget::setTrainType(int8_t type)
{
m_trainType = type;
}
void TitleWidget::on_user_Btn_clicked()
{
MainWindowPageControl::getInstance()->setCurrentPage(UserPage_E);
}
void TitleWidget::slotCheckTimer()
{
showWIFI();
}
void TitleWidget::showWIFI()
{
#if 0
DWORD dwError = ERROR_SUCCESS;
DWORD dwNegotiatedVersion;
HANDLE hClientHandle = NULL;
dwError = WlanOpenHandle(1, NULL, &dwNegotiatedVersion, &hClientHandle);
if (dwError != ERROR_SUCCESS)
{
2024-12-03 13:41:51 +08:00
WlanCloseHandle(hClientHandle, NULL);
2024-11-25 17:15:44 +08:00
return;
}
PWLAN_INTERFACE_INFO_LIST pInterfaceList = NULL;
2024-12-03 13:41:51 +08:00
dwError = WlanEnumInterfaces(hClientHandle, NULL, &pInterfaceList);
2024-11-25 17:15:44 +08:00
if ( dwError != ERROR_SUCCESS )
{
WlanFreeMemory(pInterfaceList);
2024-12-03 13:41:51 +08:00
WlanCloseHandle(hClientHandle, NULL);
2024-11-25 17:15:44 +08:00
return;
}
GUID &guid = pInterfaceList->InterfaceInfo[0].InterfaceGuid;
PWLAN_AVAILABLE_NETWORK_LIST pWLAN_AVAILABLE_NETWORK_LIST = NULL;
dwError = WlanGetAvailableNetworkList(hClientHandle, &guid,
2024-12-03 13:41:51 +08:00
2, NULL, &pWLAN_AVAILABLE_NETWORK_LIST);
2024-11-25 17:15:44 +08:00
if (dwError != ERROR_SUCCESS)
{
WlanFreeMemory(pInterfaceList);
WlanFreeMemory(pWLAN_AVAILABLE_NETWORK_LIST);
2024-12-03 13:41:51 +08:00
WlanCloseHandle(hClientHandle, NULL);
2024-11-25 17:15:44 +08:00
return;
}
WLAN_AVAILABLE_NETWORK wlanAN;
2024-12-03 13:41:51 +08:00
bool isConnected = false;
2024-11-25 17:15:44 +08:00
int numberOfItems = pWLAN_AVAILABLE_NETWORK_LIST->dwNumberOfItems;
if (numberOfItems > 0)
{
2024-12-03 13:41:51 +08:00
for(int i = 0; i < numberOfItems; i++)
2024-11-25 17:15:44 +08:00
{
wlanAN = pWLAN_AVAILABLE_NETWORK_LIST->Network[i];
if(wlanAN.dwFlags & 1)
{
2024-12-03 13:41:51 +08:00
isConnected = true;
2024-11-25 17:15:44 +08:00
2024-12-03 13:41:51 +08:00
int wifiQuality = (int)wlanAN.wlanSignalQuality;
2024-11-25 17:15:44 +08:00
2024-12-03 13:41:51 +08:00
if(wifiQuality > 75)
2024-11-25 17:15:44 +08:00
{
QPixmap pixmapWireless(":/DependFile/Source/signal/wifi3.png");
ui->wifiSignal_Label->setPixmap(pixmapWireless);
}
2024-12-03 13:41:51 +08:00
else if(wifiQuality > 50 && wifiQuality <= 75)
2024-11-25 17:15:44 +08:00
{
QPixmap pixmapWireless(":/DependFile/Source/signal/wifi2.png");
ui->wifiSignal_Label->setPixmap(pixmapWireless);
}
2024-12-03 13:41:51 +08:00
else if(wifiQuality > 25 && wifiQuality <= 50)
2024-11-25 17:15:44 +08:00
{
QPixmap pixmapWireless(":/DependFile/Source/signal/wifi1.png");
ui->wifiSignal_Label->setPixmap(pixmapWireless);
}
2024-12-03 13:41:51 +08:00
else if(wifiQuality > 0 && wifiQuality <= 25)
2024-11-25 17:15:44 +08:00
{
QPixmap pixmapWireless(":/icons/WirelessIcon3.png");
ui->wifiSignal_Label->setPixmap(pixmapWireless);
}
}
}
}
if (!isConnected)
{
QPixmap pixmapWireless(":/icons/WirelessIcon4.png");
ui->wifiSignal_Label->setPixmap(pixmapWireless);
}
WlanFreeMemory(pInterfaceList);
WlanFreeMemory(pWLAN_AVAILABLE_NETWORK_LIST);
2024-12-03 13:41:51 +08:00
WlanCloseHandle(hClientHandle, NULL);
2024-11-25 17:15:44 +08:00
#else
QPixmap pixmap;
if(IceModule::getInstance()->getBicycleDeviceState())
{
pixmap.load(":/DependFile/Source/signal/deviceConnected.png");
}
else
2024-12-03 13:41:51 +08:00
{
2024-11-25 17:15:44 +08:00
pixmap.load(":/DependFile/Source/signal/deviceDisconnected.png");
2024-12-03 13:41:51 +08:00
}
2024-11-25 17:15:44 +08:00
ui->wifiSignal_Label->setPixmap(pixmap);
#endif
}
void TitleWidget::setBackBtnVisible(bool visible)
{
ui->back1_Btn->setVisible(visible);
ui->back2_Btn->setVisible(visible);
ui->quit_Btn->setVisible(!visible);
}
void TitleWidget::on_quit_Btn_clicked()
{
emit signalCloseWindow();
//MainWindowPageControl::getInstance()->setCurrentPage(LoginPage_E);
/*
*
*/
}
void TitleWidget::slotStateChanged(QString str)
{
ui->state_label->setText(str);
}
void TitleWidget::slotSaveUpPicture()
{
QPixmap upPicture = this->grab();
QString dirPath = QApplication::applicationDirPath() + "/DependFile/Source/trainDisplayPage";
QDir resultDir(dirPath);
if(!resultDir.exists())
2024-12-03 13:41:51 +08:00
{
qDebug() << "保存图片失败";
}
2024-11-25 17:15:44 +08:00
if(upPicture.save(dirPath + "/upPicture.png"))
2024-12-03 13:41:51 +08:00
{
qDebug() << dirPath + "/upPicture.png";
}
2024-11-25 17:15:44 +08:00
}
2024-12-03 13:41:51 +08:00
void TitleWidget::changeEvent(QEvent *event)
2024-11-25 17:15:44 +08:00
{
switch (event->type())
{
2024-12-03 13:41:51 +08:00
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
QWidget::changeEvent(event);
break;
2024-11-25 17:15:44 +08:00
}
setUser(CurrentUserData::getInstace()->getCurrentPatientMsg());
}
void TitleWidget::on_sound_Button_clicked()
{
m_soundDialog->show();
}
2024-12-03 13:41:51 +08:00
void TitleWidget::slotBciDeviceStatus(bool bConnected)
{
if(bConnected)
{
ui->brainSignal_Labe->setStyleSheet("QLabel#brainSignal_Labe{border-image:url(:/DependFile/Source/signal/icon_brain_on.png);}");
}
else
{
ui->brainSignal_Labe->setStyleSheet("QLabel#brainSignal_Labe{border-image:url(:/DependFile/Source/signal/icon_brain_off.png);}");
}
}
2024-11-25 17:15:44 +08:00