程序体验地址:https://pan.baidu.com/s/1rQFZx5JIud8lWdjMHl0tpg
目前版本还没有成功把字体打包的程序中,为了更好的效果体验,请先安装文件中的两个字体
程序体验地址:https://pan.baidu.com/s/1rQFZx5JIud8lWdjMHl0tpg
目前版本还没有成功把字体打包的程序中,为了更好的效果体验,请先安装文件中的两个字体
效果图
今天的里面,中间的平均油耗是不包括的,平均油耗的实现被我划分到到了左迷你显现器中了。
转速表的对外接口
/** * @brief selfInspection * 转速表自检程序 */ void selfInspection(); /** * @brief setTacho * @param tacho * 设置发动机转速0-8000 转速 */ void setTacho(int tacho = 0); /** * @brief setTemperature * @param temperatur * 设置温度 */ void setTemperature(int temperatur = 0);
最基本的初始化部分
Tachometer::Tachometer(QWidget *parent) :QWidget(parent),ui(new Ui::Tachometer) { ui->setupUi(this); ui->label_mainback->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Tachometer/mainback.png);}"); ui->label_flag_temperature->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Tachometer/temperature_r.png);}"); ui->label_pointer->installEventFilter(this); ui->label_pointer_shade->installEventFilter(this); ui->label_pointer_temperature->installEventFilter(this); m_timerTachoSelfInspection = new QTimer(this); m_timerTemperatureSelfInspection = new QTimer(this); connect(m_timerTachoSelfInspection,&QTimer::timeout,this,&Tachometer::slot_timerTachoSelfInspection); connect(m_timerTemperatureSelfInspection,&QTimer::timeout,this,&Tachometer::slot_timerTempearutreSelfInspection); setTacho(); }
剩下的实现内容
void Tachometer::selfInspection() { this->tachoSelfInspection(); this->temperatureSelfInspection(); } void Tachometer::setTacho(int tacho) { currentTacho = tacho; m_Angle = currentTacho*0.03375-135; update(); } void Tachometer::setTemperature(int temperatur) { currentTemperature = temperatur; m_Temperature = temperatur; if(m_Temperature >75) { ui->label_flag_temperature->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Tachometer/temperature_r.png);}"); } else { ui->label_flag_temperature->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Tachometer/temperature_w.png);}"); } update(); } void Tachometer::tachoSelfInspection() { if(m_timerTachoSelfInspection) { m_timerTachoSelfInspection->start(10); } } void Tachometer::temperatureSelfInspection() { if(m_timerTemperatureSelfInspection) { m_timerTemperatureSelfInspection->start(10); ui->label_flag_temperature->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Tachometer/temperature_r.png);}"); } } bool Tachometer::eventFilter(QObject *watched, QEvent *event) { if(watched == ui->label_pointer && event->type() == QEvent::Paint) { drawPonter(m_Angle); } if(watched == ui->label_pointer_shade && event->type() == QEvent::Paint) { drawPonterShade(m_Angle); } if(watched == ui->label_pointer_temperature && event->type() == QEvent::Paint) { drawTemperature(m_Temperature); } return QWidget::eventFilter(watched,event); } void Tachometer::drawPonter(int angle) { m_shadeOpacity = currentTacho / 10000.0; QPainter painter(ui->label_pointer); painter.setRenderHint((QPainter::SmoothPixmapTransform)); painter.setRenderHint(QPainter::HighQualityAntialiasing); painter.translate(304,303.5); painter.save(); painter.rotate(angle); painter.drawPixmap(-304,-302,416,500,QPixmap(":/Comfort/Resources/MeterDisplay/Comfort/Tachometer/pointer.png")); painter.restore(); } void Tachometer::drawPonterShade(int angle) { QPainter painter(ui->label_pointer_shade); painter.setOpacity(m_shadeOpacity); painter.setRenderHint((QPainter::SmoothPixmapTransform)); painter.setRenderHint(QPainter::HighQualityAntialiasing); painter.translate(304,303.5); painter.save(); painter.rotate(angle); painter.drawPixmap(-304,-302,416,500,QPixmap(":/Comfort/Resources/MeterDisplay/Comfort/Tachometer/pointer_shade.png")); painter.restore(); } void Tachometer::slot_timerTachoSelfInspection() { if(m_flagTachoSelfInspection) { if(currentTacho>0) { currentTacho = currentTacho-80; } else { m_flagTachoSelfInspection = !m_flagTachoSelfInspection; m_timerTachoSelfInspection->stop(); emit signalSelfInspectionfinished(); } } else { if(currentTacho<8100) { currentTacho = currentTacho+80; } else { m_flagTachoSelfInspection = !m_flagTachoSelfInspection; } } setTacho(currentTacho); } void Tachometer::slot_timerTempearutreSelfInspection() { if(m_flagTemperatireSelfInspection) { if(currentTemperature >0) { currentTemperature--; } else { m_flagTemperatireSelfInspection = !m_flagTemperatireSelfInspection; m_timerTemperatureSelfInspection->stop(); emit signalSelfInspectionfinished(); ui->label_flag_temperature->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Tachometer/temperature_w.png);}"); } } else { if(currentTemperature <100) { currentTemperature++; } else { m_flagTemperatireSelfInspection = !m_flagTemperatireSelfInspection; } } setTemperature(currentTemperature); } void Tachometer::drawTemperature(int temperature) { QPainter painter(ui->label_pointer_temperature); painter.setRenderHint((QPainter::SmoothPixmapTransform)); painter.setRenderHint(QPainter::HighQualityAntialiasing); painter.translate(304,303.5); painter.setPen(QPen(Qt::white,6,Qt::SolidLine)); painter.save(); if(temperature<=25) { painter.drawArc(-304,-308,608,608,247*16,temperature*7); } else if(temperature>25 && temperature <= 50) { painter.drawArc(-304,-308,608,608,247*16,24*7); painter.drawArc(-304,-308,608,608,259*16,(temperature-25)*7); } else if(temperature>50 && temperature <= 75) { painter.drawArc(-304,-308,608,608,247*16,24*7); painter.drawArc(-304,-308,608,608,259*16,24*7); painter.drawArc(-304,-308,608,608,271*16,(temperature-50)*7); } else if(temperature>75 && temperature <= 90) { painter.drawArc(-304,-308,608,608,247*16,24*7); painter.drawArc(-304,-308,608,608,259*16,24*7); painter.drawArc(-304,-308,608,608,271*16,24*7); painter.drawArc(-304,-308,608,608,283*16,(temperature-75)*7); } else if(temperature>90 && temperature <= 100) { painter.drawArc(-304,-308,608,608,247*16,24*7); painter.drawArc(-304,-308,608,608,259*16,24*7); painter.drawArc(-304,-308,608,608,271*16,24*7); painter.drawArc(-304,-308,608,608,283*16,15*7); painter.setPen(QPen(Qt::red,6,Qt::SolidLine)); painter.drawArc(-304,-308,608,608,290*16,(temperature-90)*7); } painter.restore(); }