HMI-33-【运动模式】补上油量表和水温表
上一篇,以为是做了一个收尾,写了灯光控制面板和底部的信息栏,但是,有位眼见的小伙伴江山壹角
,直接不给我面子,说我的水温表和油量表不会动。截图位置,我记仇哈。
所以今天我们的这篇文章就是实现下水温表和油量表,别看就加起来就16个方块,我写了两个晚上,今天这个也顺带吧转向带的控制代码横展过来,目前呢,转向灯用的还是定时器控制的 ,可以在不同的电脑上有不同的表现了,后期小伙伴如果发现频率不同步的话,可以使用线程产生定时器,来替换我的定时器即可。
[TOC]
关键字:
HMI
、油量表
、水温表
、ui
、Qt
增加转向灯控制代码
转向灯控制代码不用动脑子,我UI也是从舒适
模式粘贴过来的,所带代码也是可以横展过来的。核心部分如下:
void MDS_LightControl::selfInspection()
{
ui->label_turnlight_l->show();
ui->label_turnlight_r->show();
QTimer::singleShot(2000,this,[=](){
ui->label_turnlight_l->hide();
ui->label_turnlight_r->hide();});
}
void MDS_LightControl::setTurnLight(turnLight light)
{
switch (light) {
case m_turnLightLeft:
{
if(m_timerTurnRight->isActive())
{
m_timerTurnRight->stop();
ui->label_turnlight_r->hide();
}
m_timerTurnLeft->start(1000);
break;
}
case m_turnLightRight:
{
if(m_timerTurnLeft->isActive())
{
m_timerTurnLeft->stop();
ui->label_turnlight_l->hide();
}
m_timerTurnRight->start(1000);
break;
}
case m_turnLightWarning:
{
m_timerTurnLeft->stop();
m_timerTurnRight->stop();
m_timerTurnLeft->start(1000);
m_timerTurnRight->start(1000);
break;
}
case m_turnLightOff:
{
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;
}
}
}
水温表和油量表代码实现
这个在计算是时候,我用了程序计算机,哎,这个计算机,谁用谁知道,除法不带小数呀,开始算的大半段都白写了,后面才反应过来。小伙伴们要注意哦。运动模式下的水温表和油量表和舒适模式不一样,不是连续的,类似于一格一格的吧。具体可以看下面的动画。这里直接贴上核心代码:
/**
* @brief MDS_Center::drawOil
* @param angle
* 绘制油量表
*/
void MDS_Center::drawOil(int percentage)
{
//半径350
QPainter painter(ui->label_drawOil);
painter.setRenderHint((QPainter::SmoothPixmapTransform));
painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.translate(-43,-195);
painter.save();
painter.setPen(QPen(Qt::white,5,Qt::SolidLine));
if(percentage>0 && percentage <= 13)
{
painter.drawArc(-315,-315,630,630,279*16,4*16);
}
else if(percentage>13 && percentage<=25){
painter.drawArc(-315,-315,630,630,279*16,4*16);
painter.drawArc(-315,-315,630,630,285*16,3*16);
}
else if(percentage>25 && percentage<=38){
painter.drawArc(-315,-315,630,630,279*16,4*16);
painter.drawArc(-315,-315,630,630,285*16,3*16);
painter.drawArc(-315,-315,630,630,290*16,3*16);
}
else if(percentage>38 && percentage<=50){
painter.drawArc(-315,-315,630,630,279*16,4*16);
painter.drawArc(-315,-315,630,630,285*16,3*16);
painter.drawArc(-315,-315,630,630,290*16,3*16);
painter.drawArc(-315,-315,630,630,295*16,3*16+8);
}
else if(percentage>50 && percentage<=63){
painter.drawArc(-315,-315,630,630,279*16,4*16);
painter.drawArc(-315,-315,630,630,285*16,3*16);
painter.drawArc(-315,-315,630,630,290*16,3*16);
painter.drawArc(-315,-315,630,630,295*16,3*16+8);
painter.drawArc(-315,-315,630,630,301*16+8,3*16+6);
}
else if(percentage>63 && percentage<=75){
painter.drawArc(-315,-315,630,630,279*16,4*16);
painter.drawArc(-315,-315,630,630,285*16,3*16);
painter.drawArc(-315,-315,630,630,290*16,3*16);
painter.drawArc(-315,-315,630,630,295*16,3*16+8);
painter.drawArc(-315,-315,630,630,301*16+8,3*16+6);
painter.drawArc(-315,-315,630,630,307*16,3*16);
}
else if(percentage>76 && percentage<=88){
painter.drawArc(-315,-315,630,630,279*16,4*16);
painter.drawArc(-315,-315,630,630,285*16,3*16);
painter.drawArc(-315,-315,630,630,290*16,3*16);
painter.drawArc(-315,-315,630,630,295*16,3*16+8);
painter.drawArc(-315,-315,630,630,301*16+8,3*16+6);
painter.drawArc(-315,-315,630,630,307*16,3*16);
painter.drawArc(-315,-315,630,630,312*16,3*16);
}
else if(percentage>88 && percentage<=100){
painter.drawArc(-315,-315,630,630,279*16,4*16);
painter.drawArc(-315,-315,630,630,285*16,3*16);
painter.drawArc(-315,-315,630,630,290*16,3*16);
painter.drawArc(-315,-315,630,630,295*16,3*16+8);
painter.drawArc(-315,-315,630,630,301*16+8,3*16+6);
painter.drawArc(-315,-315,630,630,307*16,3*16);
painter.drawArc(-315,-315,630,630,312*16,3*16);
painter.drawArc(-315,-315,630,630,317*16,4*16);
}
painter.restore();
}
/**
* @brief MDS_Center::drawWater
* @param angle
* 绘制水温表
*/
void MDS_Center::drawWater(int percentage)
{
QPainter painter(ui->label_drawWater);
painter.setRenderHint((QPainter::SmoothPixmapTransform));
painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.translate(257,-195);
painter.save();
painter.setPen(QPen(Qt::white,5,Qt::SolidLine));
if(percentage>0 && percentage <= 13)
{
painter.drawArc(-315,-315,630,630,257*16,4*16);
}
else if(percentage>13 && percentage<=25){
painter.drawArc(-315,-315,630,630,252*16,3*16);
painter.drawArc(-315,-315,630,630,257*16,4*16);
}
else if(percentage>25 && percentage<=38){
painter.drawArc(-315,-315,630,630,247*16,3*16);
painter.drawArc(-315,-315,630,630,252*16,3*16);
painter.drawArc(-315,-315,630,630,257*16,4*16);
}
else if(percentage>38 && percentage<=50){
painter.drawArc(-315,-315,630,630,241*16,4*16);
painter.drawArc(-315,-315,630,630,247*16,3*16);
painter.drawArc(-315,-315,630,630,252*16,3*16);
painter.drawArc(-315,-315,630,630,257*16,4*16);
}
else if(percentage>50 && percentage<=63){
painter.drawArc(-315,-315,630,630,235*16,4*16);
painter.drawArc(-315,-315,630,630,241*16,4*16);
painter.drawArc(-315,-315,630,630,247*16,3*16);
painter.drawArc(-315,-315,630,630,252*16,3*16);
painter.drawArc(-315,-315,630,630,257*16,4*16);
}
else if(percentage>63 && percentage<=75){
painter.drawArc(-315,-315,630,630,230*16,3*16);
painter.drawArc(-315,-315,630,630,235*16,4*16);
painter.drawArc(-315,-315,630,630,241*16,4*16);
painter.drawArc(-315,-315,630,630,247*16,3*16);
painter.drawArc(-315,-315,630,630,252*16,3*16);
painter.drawArc(-315,-315,630,630,257*16,4*16);
}
else if(percentage>76 && percentage<=88){
painter.drawArc(-315,-315,630,630,225*16,3*16);
painter.drawArc(-315,-315,630,630,230*16,3*16);
painter.drawArc(-315,-315,630,630,235*16,4*16);
painter.drawArc(-315,-315,630,630,241*16,4*16);
painter.drawArc(-315,-315,630,630,247*16,3*16);
painter.drawArc(-315,-315,630,630,252*16,3*16);
painter.drawArc(-315,-315,630,630,257*16,4*16);
}
else if(percentage>88 && percentage<=100){
painter.drawArc(-315,-315,630,630,219*16,4*16);
painter.drawArc(-315,-315,630,630,225*16,3*16);
painter.drawArc(-315,-315,630,630,230*16,3*16);
painter.drawArc(-315,-315,630,630,235*16,4*16);
painter.drawArc(-315,-315,630,630,241*16,4*16);
painter.drawArc(-315,-315,630,630,247*16,3*16);
painter.drawArc(-315,-315,630,630,252*16,3*16);
painter.drawArc(-315,-315,630,630,257*16,4*16);
}
painter.restore();
}
目前进度
说明:
本项目中所使借鉴原型来自:[吉利] 博瑞GE | 仪表HMI设计、吉利汽车HMI项目。
设计图的所有权和解释权都归吉利汽车所有。
本项目所有资源文件均有打不死的小海复刻制作。
本项目代码暂时不会开源,有需要的源码的可与我联系,左上角二维码加微信。
本项目仅限学习交流、禁止商业使用。