在前面GC9项目之前其实单独写过一个HUD,这里就直接把原来的资源弄过,按照现在的想的思路重新搞一次。
HUD北京为透明,这样可以感觉是真的投在玻璃上。HUD上面目前引出的接口如下
/** * @brief fastStart * 快速启动 */ void fastStart(); /** * @brief selfInspection * 自检程序 */ void selfInspection(); /** * @brief powerUp * HUD上电操作 */ void powerUp(); /** * @brief powerOff * HUD断电操作 */ void powerOff(); /** * @brief setLaneKeeping * 设置车道保持 */ void setLaneKeeping(LaneKeep temp = m_LaneKeep_No); /** * @brief setCruiseControl * @param temp * 设置定速巡航 */ void setCruiseControl(bool temp); /** * @brief setSelfAdaptiveCruiseControl * @param temp * 设置自适应巡航 */ void setSelfAdaptiveCruiseControl(bool temp); /** * @brief setSelfAdaptiveCruiseControlDistance * @param temp * 设置距离 */ void setSelfAdaptiveCruiseControlDistance(int temp); /** * @brief setSelfAdaptiveCruiseControlModel * @param temp * 设置自适应巡航模式 */ void setSelfAdaptiveCruiseControlModel(SelfAdaptiveCruiseControlModel temp); /** * @brief setCarSpeed * @param temp * 设置车速 */ void setCarSpeed(int temp); /** * @brief setTurnLight * @param temp * 设置转向灯 */ void setTurnLight(int temp); /** * @brief setDirection * @param temp * 设置导航方向 */ void setDirection(Direction temp); /** * @brief setDirectionDistance * @param temp * 设置距离 */ void setDirectionDistance(int temp = 150);
显示速度的数字仪表部分实现代码如下
#ifndef HUD_NUMBER_H #define HUD_NUMBER_H #include <QWidget> #include <QThread> class HUDNumberThread : public QThread { Q_OBJECT public: /** * @brief run * 重载线程函数 */ virtual void run(); signals: void signalTimeOut(); }; namespace Ui { class HUD_Number; } class HUD_Number : public QWidget { Q_OBJECT public: explicit HUD_Number(QWidget *parent = nullptr); ~HUD_Number(); /** * @brief set_Number * @param number * 设置车速 */ void setNumber(int number = 888); void selfInspection(); private: Ui::HUD_Number *ui; HUDNumberThread *m_hudNumber = nullptr; }; #endif // HUD_NUMBER_H #include "hud_number.h" #include "ui_hud_number.h" HUD_Number::HUD_Number(QWidget *parent) : QWidget(parent), ui(new Ui::HUD_Number) { ui->setupUi(this); } HUD_Number::~HUD_Number() { delete ui; } void HUD_Number::setNumber(int number) { if(number<10) { ui->label_N_B->hide(); ui->label_N_S->hide(); ui->label_N_G->show(); ui->label_N_G->setGeometry(104,0,104,147); ui->label_N_KM->move(ui->label_N_G->x()+6,154); switch (number) { case 0: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/0.png)"); break; case 1: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/1.png)"); break; case 2: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/2.png)"); break; case 3: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/3.png)"); break; case 4: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/4.png)"); break; case 5: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/5.png)"); break; case 6: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/6.png)"); break; case 7: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/7.png)"); break; case 8: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/8.png)"); break; case 9: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/9.png)"); break; default: break; } } else if(number>=10 && number <100) { ui->label_N_B->hide(); ui->label_N_S->show(); ui->label_N_G->show(); ui->label_N_S->setGeometry(52,0,104,147); ui->label_N_G->setGeometry(156,0,104,147); ui->label_N_KM->move(ui->label_N_G->x()+6,154); switch (number%10) { case 0: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/0.png)"); break; case 1: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/1.png)"); break; case 2: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/2.png)"); break; case 3: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/3.png)"); break; case 4: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/4.png)"); break; case 5: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/5.png)"); break; case 6: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/6.png)"); break; case 7: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/7.png)"); break; case 8: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/8.png)"); break; case 9: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/9.png)"); break; default: break; } switch (number/10) { case 0: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/0.png)"); break; case 1: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/1.png)"); break; case 2: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/2.png)"); break; case 3: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/3.png)"); break; case 4: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/4.png)"); break; case 5: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/5.png)"); break; case 6: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/6.png)"); break; case 7: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/7.png)"); break; case 8: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/8.png)"); break; case 9: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/9.png)"); break; default: break; } } else if(number>=100 && number < 1000) { ui->label_N_B->show(); ui->label_N_S->show(); ui->label_N_G->show(); ui->label_N_B->setGeometry(0,0,104,147); ui->label_N_S->setGeometry(104,0,104,147); ui->label_N_G->setGeometry(208,0,104,147); ui->label_N_KM->move(ui->label_N_G->x()+6,154); switch (number%10) { case 0: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/0.png)"); break; case 1: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/1.png)"); break; case 2: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/2.png)"); break; case 3: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/3.png)"); break; case 4: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/4.png)"); break; case 5: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/5.png)"); break; case 6: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/6.png)"); break; case 7: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/7.png)"); break; case 8: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/8.png)"); break; case 9: ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/9.png)"); break; default: break; } switch (number/10%10) { case 0: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/0.png)"); break; case 1: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/1.png)"); break; case 2: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/2.png)"); break; case 3: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/3.png)"); break; case 4: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/4.png)"); break; case 5: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/5.png)"); break; case 6: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/6.png)"); break; case 7: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/7.png)"); break; case 8: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/8.png)"); break; case 9: ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/9.png)"); break; default: break; } switch (number/100) { case 0: ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/0.png)"); break; case 1: ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/1.png)"); break; case 2: ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/2.png)"); break; case 3: ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/3.png)"); break; case 4: ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/4.png)"); break; case 5: ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/5.png)"); break; case 6: ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/6.png)"); break; case 7: ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/7.png)"); break; case 8: ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/8.png)"); break; case 9: ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/9.png)"); break; default: break; } } else { } } void HUD_Number::selfInspection() { setNumber(); if(!m_hudNumber) { m_hudNumber = new HUDNumberThread(); connect(m_hudNumber,&HUDNumberThread::signalTimeOut,this,[=](){setNumber(0);}); m_hudNumber->start(); } } void HUDNumberThread::run() { msleep(3000); emit signalTimeOut(); }
转向灯实现代码如下
#ifndef HUD_TURNLIGHT_H #define HUD_TURNLIGHT_H #include <QWidget> #include <QThread> class HUDTurnLIghtThread : public QThread { Q_OBJECT public: /** * @brief run * 重载线程函数 */ virtual void run(); signals: void signalTimeOut(); }; namespace Ui { class HUD_TurnLight; } class HUD_TurnLight : public QWidget { Q_OBJECT public: explicit HUD_TurnLight(QWidget *parent = nullptr); ~HUD_TurnLight(); /** * @brief selfInspection * 初始化 */ void selfInspection(); /** * @brief setTurnLight * @param temp * 设置转向灯 */ void setTurnLight(int temp); private: Ui::HUD_TurnLight *ui; HUDTurnLIghtThread *m_hudTurnLightThread = nullptr; QTimer *m_timerTurnLeft = nullptr; //左转向灯定时器 QTimer *m_timerTurnRight = nullptr; //右转向灯定时器 }; #endif // HUD_TURNLIGHT_H #include "hud_turnlight.h" #include "ui_hud_turnlight.h" #include <QTimer> HUD_TurnLight::HUD_TurnLight(QWidget *parent) : QWidget(parent), ui(new Ui::HUD_TurnLight) { ui->setupUi(this); ui->label_turnLIght_L->hide(); ui->label_turnLIght_L->hide(); m_timerTurnLeft = new QTimer(this); m_timerTurnRight = new QTimer(this); connect(m_timerTurnLeft,&QTimer::timeout,this,[=](){ if(ui->label_turnLIght_L->isHidden()) { ui->label_turnLIght_L->show(); } else { ui->label_turnLIght_L->hide(); } }); connect(m_timerTurnRight,&QTimer::timeout,this,[=](){ if(ui->label_turnLIght_L->isHidden()) { ui->label_turnLIght_L->show(); } else { ui->label_turnLIght_L->hide(); } }); } HUD_TurnLight::~HUD_TurnLight() { delete ui; } void HUD_TurnLight::selfInspection() { ui->label_turnLIght_L->show(); ui->label_turnLIght_R->show(); if(!m_hudTurnLightThread) { m_hudTurnLightThread = new HUDTurnLIghtThread(); connect(m_hudTurnLightThread,&HUDTurnLIghtThread::signalTimeOut,this,[=](){ ui->label_turnLIght_L->hide(); ui->label_turnLIght_R->hide(); }); m_hudTurnLightThread->start(); } } void HUD_TurnLight::setTurnLight(int temp) { switch (temp) { case 0: { if(m_timerTurnRight->isActive()) { m_timerTurnRight->stop(); ui->label_turnLIght_L->hide(); } m_timerTurnLeft->start(1000); break; } case 1: { if(m_timerTurnLeft->isActive()) { m_timerTurnLeft->stop(); ui->label_turnLIght_L->hide(); } m_timerTurnRight->start(1000); break; } case 2: { m_timerTurnLeft->start(1000); m_timerTurnRight->start(1000); break; } case 3: { if(m_timerTurnLeft->isActive()) { m_timerTurnLeft->stop(); ui->label_turnLIght_L->hide(); } if(m_timerTurnRight->isActive()) { m_timerTurnRight->stop(); ui->label_turnLIght_R->hide(); } break; } } } void HUDTurnLIghtThread::run() { msleep(3000); emit signalTimeOut(); }
导航实现代码如下
#ifndef HUD_DIRECTION_H #define HUD_DIRECTION_H #include <QWidget> #include <QThread> enum Direction{ m_straight, m_rightUp, m_right, m_rightDown, m_turnaround, m_leftDown, m_left, m_leftUp }; class HUDDirectionThread : public QThread { Q_OBJECT public: /** * @brief run * 重载线程函数 */ virtual void run(); signals: void signalTimeOut(); }; namespace Ui { class HUD_Direction; } class HUD_Direction : public QWidget { Q_OBJECT public: explicit HUD_Direction(QWidget *parent = nullptr); ~HUD_Direction(); /** * @brief setDirection * @param temp * 设置导航方向 */ void setDirection(Direction temp); /** * @brief setDirectionDistance * @param temp * 设置距离 */ void setDirectionDistance(int temp = 150); void selfInspection(); private: Ui::HUD_Direction *ui; HUDDirectionThread *m_hudDirectionThrerad = nullptr; }; #endif // HUD_DIRECTION_H #include "hud_direction.h" #include "ui_hud_direction.h" HUD_Direction::HUD_Direction(QWidget *parent) : QWidget(parent), ui(new Ui::HUD_Direction) { ui->setupUi(this); ui->label_up->hide(); ui->label_left->hide(); ui->label_leftUp->hide(); ui->label_right->hide(); ui->label_line_1->hide(); ui->label_line_2->hide(); ui->label_line_3->hide(); ui->label_rightUp->hide(); ui->label_leftDown->hide(); ui->label_lineBase->hide(); ui->label_rightDown->hide(); ui->label_turnraound->hide(); ui->label_pointer->hide(); ui->label_base->hide(); // setDirection(m_rightUp); // setDirectionDistance(110); } HUD_Direction::~HUD_Direction() { delete ui; } void HUD_Direction::setDirection(Direction temp) { switch (temp) { case m_straight: { ui->label_up->show(); ui->label_left->hide(); ui->label_leftUp->hide(); ui->label_right->hide(); ui->label_line_1->hide(); ui->label_line_2->hide(); ui->label_line_3->hide(); ui->label_rightUp->hide(); ui->label_leftDown->hide(); ui->label_lineBase->hide(); ui->label_rightDown->hide(); ui->label_turnraound->hide(); ui->label_pointer->show(); ui->label_base->show(); break; } case m_rightUp: { ui->label_up->hide(); ui->label_left->hide(); ui->label_leftUp->hide(); ui->label_right->hide(); ui->label_line_1->hide(); ui->label_line_2->hide(); ui->label_line_3->hide(); ui->label_rightUp->show(); ui->label_leftDown->hide(); ui->label_lineBase->hide(); ui->label_rightDown->hide(); ui->label_turnraound->hide(); ui->label_pointer->show(); ui->label_base->show(); break; } case m_right: { ui->label_up->hide(); ui->label_left->hide(); ui->label_leftUp->hide(); ui->label_right->show(); ui->label_line_1->hide(); ui->label_line_2->hide(); ui->label_line_3->hide(); ui->label_rightUp->hide(); ui->label_leftDown->hide(); ui->label_lineBase->hide(); ui->label_rightDown->hide(); ui->label_turnraound->hide(); ui->label_pointer->show(); ui->label_base->show(); break; } case m_rightDown: { ui->label_up->hide(); ui->label_left->hide(); ui->label_leftUp->hide(); ui->label_right->hide(); ui->label_line_1->hide(); ui->label_line_2->hide(); ui->label_line_3->hide(); ui->label_rightUp->hide(); ui->label_leftDown->hide(); ui->label_lineBase->hide(); ui->label_rightDown->show(); ui->label_turnraound->hide(); ui->label_pointer->show(); ui->label_base->show(); break; } case m_turnaround: { ui->label_up->hide(); ui->label_left->hide(); ui->label_leftUp->hide(); ui->label_right->hide(); ui->label_line_1->hide(); ui->label_line_2->hide(); ui->label_line_3->hide(); ui->label_rightUp->hide(); ui->label_leftDown->hide(); ui->label_lineBase->hide(); ui->label_rightDown->hide(); ui->label_turnraound->show(); ui->label_base->hide(); ui->label_pointer->hide(); break; } case m_leftDown: { ui->label_up->hide(); ui->label_left->hide(); ui->label_leftUp->hide(); ui->label_right->hide(); ui->label_line_1->hide(); ui->label_line_2->hide(); ui->label_line_3->hide(); ui->label_rightUp->hide(); ui->label_leftDown->show(); ui->label_lineBase->hide(); ui->label_rightDown->hide(); ui->label_turnraound->hide(); ui->label_pointer->show(); ui->label_base->show(); break; } case m_left: { ui->label_up->hide(); ui->label_left->show(); ui->label_leftUp->hide(); ui->label_right->hide(); ui->label_line_1->hide(); ui->label_line_2->hide(); ui->label_line_3->hide(); ui->label_rightUp->hide(); ui->label_leftDown->hide(); ui->label_lineBase->hide(); ui->label_rightDown->hide(); ui->label_turnraound->hide(); ui->label_pointer->show(); ui->label_base->show(); break; } case m_leftUp: { ui->label_up->hide(); ui->label_left->hide(); ui->label_leftUp->show(); ui->label_right->hide(); ui->label_line_1->hide(); ui->label_line_2->hide(); ui->label_line_3->hide(); ui->label_rightUp->hide(); ui->label_leftDown->hide(); ui->label_lineBase->hide(); ui->label_rightDown->hide(); ui->label_turnraound->hide(); ui->label_pointer->show(); ui->label_base->show(); break; } } } void HUD_Direction::setDirectionDistance(int temp) { if(temp>100 && temp <= 150) { ui->label_line_1->show(); ui->label_line_2->show(); ui->label_line_3->show(); ui->label_lineBase->show(); } else if(temp <= 100 && temp >50) { ui->label_line_1->show(); ui->label_line_2->show(); ui->label_line_3->hide(); ui->label_lineBase->show(); } else if(temp <= 50 && temp >0) { ui->label_line_1->show(); ui->label_line_2->hide(); ui->label_line_3->hide(); ui->label_lineBase->show(); } else if(temp<= 0) { ui->label_line_1->hide(); ui->label_line_2->hide(); ui->label_line_3->hide(); ui->label_lineBase->hide(); } } void HUD_Direction::selfInspection() { ui->label_up->show(); ui->label_left->show(); ui->label_leftUp->show(); ui->label_right->show(); ui->label_line_1->show(); ui->label_line_2->show(); ui->label_line_3->show(); ui->label_rightUp->show(); ui->label_leftDown->show(); ui->label_lineBase->show(); ui->label_rightDown->show(); ui->label_turnraound->show(); ui->label_pointer->show(); ui->label_base->hide(); if(!m_hudDirectionThrerad) { m_hudDirectionThrerad = new HUDDirectionThread(); connect(m_hudDirectionThrerad,&HUDDirectionThread::signalTimeOut,this,[=](){ ui->label_up->hide(); ui->label_left->hide(); ui->label_leftUp->hide(); ui->label_right->hide(); ui->label_line_1->hide(); ui->label_line_2->hide(); ui->label_line_3->hide(); ui->label_rightUp->hide(); ui->label_leftDown->hide(); ui->label_lineBase->hide(); ui->label_rightDown->hide(); ui->label_turnraound->hide(); ui->label_pointer->hide(); ui->label_base->hide(); }); m_hudDirectionThrerad->start(); } } void HUDDirectionThread::run() { msleep(3000); emit signalTimeOut(); }
巡航代码如下
#ifndef HUD_CRUISE_H #define HUD_CRUISE_H #include <QWidget> #include <QThread> enum LaneKeep { m_LaneKeep_No, m_LaneKeep_Left, m_LaneKeep_Right, m_LaneKeep_Double }; enum SelfAdaptiveCruiseControlModel { m_SelfAdaptiveCruiseControlModel_Near, m_SelfAdaptiveCruiseControlModel_Normal, m_SelfAdaptiveCruiseControlModel_Far }; class HUDCruiseThread : public QThread { Q_OBJECT public: /** * @brief run * 重载线程函数 */ virtual void run(); signals: void signalTimeOut(); }; namespace Ui { class HUD_Cruise; } class HUD_Cruise : public QWidget { Q_OBJECT public: explicit HUD_Cruise(QWidget *parent = nullptr); ~HUD_Cruise(); /** * @brief selfInspection * 自检函数 */ void selfInspection(); /** * @brief setLaneKeeping * 设置车道保持 */ void setLaneKeeping(LaneKeep temp = m_LaneKeep_No); /** * @brief setCruiseControl * @param temp * 设置定速巡航 */ void setCruiseControl(bool temp); /** * @brief setSelfAdaptiveCruiseControl * @param temp * 设置自适应巡航 */ void setSelfAdaptiveCruiseControl(bool temp); /** * @brief setSelfAdaptiveCruiseControlDistance * @param temp * 设置距离 */ void setSelfAdaptiveCruiseControlDistance(int temp); /** * @brief setSelfAdaptiveCruiseControlModel * @param temp * 设置自适应巡航模式 */ void setSelfAdaptiveCruiseControlModel(SelfAdaptiveCruiseControlModel temp); private: Ui::HUD_Cruise *ui; HUDCruiseThread *m_hudCruise = nullptr; int m_selfAdaptiveCruiseControl = 0; }; #endif // HUD_CRUISE_H #include "hud_cruise.h" #include "ui_hud_cruise.h" HUD_Cruise::HUD_Cruise(QWidget *parent) : QWidget(parent), ui(new Ui::HUD_Cruise) { ui->setupUi(this); ui->label_car->hide(); ui->label_sel_1->hide(); ui->label_sel_2->hide(); ui->label_sel_3->hide(); ui->label_speed->hide(); ui->label_line_L->hide(); ui->label_line_R->hide(); } HUD_Cruise::~HUD_Cruise() { delete ui; } void HUD_Cruise::selfInspection() { ui->label_car->show(); ui->label_sel_1->show(); ui->label_sel_2->show(); ui->label_sel_3->show(); ui->label_speed->show(); ui->label_line_L->show(); ui->label_line_R->show(); if(!m_hudCruise) { m_hudCruise = new HUDCruiseThread(); connect(m_hudCruise,&HUDCruiseThread::signalTimeOut,this,[=](){ ui->label_car->hide(); ui->label_sel_1->hide(); ui->label_sel_2->hide(); ui->label_sel_3->hide(); ui->label_speed->hide(); ui->label_line_L->hide(); ui->label_line_R->hide(); }); m_hudCruise->start(); } } void HUD_Cruise::setLaneKeeping(LaneKeep temp) { switch (temp){ case m_LaneKeep_No: { ui->label_line_L->hide(); ui->label_line_R->hide(); break; } case m_LaneKeep_Left: { ui->label_line_L->show(); ui->label_line_R->hide(); break; } case m_LaneKeep_Right: { ui->label_line_L->hide(); ui->label_line_R->show(); break; } case m_LaneKeep_Double: { ui->label_line_L->show(); ui->label_line_R->show(); break; } } } void HUD_Cruise::setCruiseControl(bool temp) { if(temp) { ui->label_speed->show(); } else { ui->label_speed->hide(); } } void HUD_Cruise::setSelfAdaptiveCruiseControl(bool temp) { if(temp) { ui->label_car->show(); } else { ui->label_car->hide(); } } void HUD_Cruise::setSelfAdaptiveCruiseControlDistance(int temp) { switch (m_selfAdaptiveCruiseControl) { case m_SelfAdaptiveCruiseControlModel_Near: { if(temp>0 && temp <= 10) { ui->label_sel_3->hide(); ui->label_sel_2->hide(); ui->label_sel_1->show(); } else if(temp>10 && temp <= 30) { ui->label_sel_3->hide(); ui->label_sel_2->show(); ui->label_sel_1->show(); } else if(temp>30 && temp <= 200) { ui->label_sel_3->show(); ui->label_sel_2->show(); ui->label_sel_1->show(); } else { ui->label_sel_3->hide(); ui->label_sel_2->hide(); ui->label_sel_1->hide(); } break; } case m_SelfAdaptiveCruiseControlModel_Normal: { if(temp>0 && temp <= 10) { ui->label_sel_3->hide(); ui->label_sel_2->hide(); ui->label_sel_1->show(); } else if(temp>10 && temp <= 30) { ui->label_sel_3->hide(); ui->label_sel_2->show(); ui->label_sel_1->show(); } else if(temp>30 && temp <= 200) { ui->label_sel_3->show(); ui->label_sel_2->show(); ui->label_sel_1->show(); } else { ui->label_sel_3->hide(); ui->label_sel_2->hide(); ui->label_sel_1->hide(); } break; } case m_SelfAdaptiveCruiseControlModel_Far: { if(temp>0 && temp <= 10) { ui->label_sel_3->hide(); ui->label_sel_2->hide(); ui->label_sel_1->show(); } else if(temp>10 && temp <= 30) { ui->label_sel_3->hide(); ui->label_sel_2->show(); ui->label_sel_1->show(); } else if(temp>30 && temp <= 200) { ui->label_sel_3->show(); ui->label_sel_2->show(); ui->label_sel_1->show(); } else { ui->label_sel_3->hide(); ui->label_sel_2->hide(); ui->label_sel_1->hide(); } break; } } } void HUD_Cruise::setSelfAdaptiveCruiseControlModel(SelfAdaptiveCruiseControlModel temp) { m_selfAdaptiveCruiseControl = temp; } void HUDCruiseThread::run() { msleep(3000); emit signalTimeOut(); }
以上就是目前HUD的实现代码