|
- #include "tempshow_1.h"
- #include "ui_tempshow_1.h"
- #include <QDebug>
- #include <QMessageBox>
- TempShow_1::TempShow_1(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::TempShow_1)
- {
- ui->setupUi(this);
- setWindowTitle(tr("温度显示_1"));
- //绘图部分
- t = 0;
- p = 200;
- Point.setX(200); /* 初始化起始点的纵坐标为0 */
- Point.setY(220); /* 初始化起始点的横坐标为0 */
- path = new QPainterPath;
- timer = new QTimer(this);
- connect(timer,SIGNAL(timeout()),this,SLOT(timerUpDate()));
- startPainting();
- }
- TempShow_1::~TempShow_1()
- {
- delete ui;
- }
- void TempShow_1::setValues(QString Test)
- {
- Temp_int = Test;
- ui->tempLabel->setText(Temp_int);
- }
- void TempShow_1::timerUpDate()
- {
- Saber = ui->tempLabel->text().toInt();
- qDebug()<<Saber;
- t += 10;
- Point.setX(t); /* 时间加二秒 */
- if(Saber < 40 && Saber != 0){
- if(Saber == 20)
- Point.setY(0); // 设置温度下限20℃
- else if(Saber == 21)
- Point.setY(-30); // 绘制温度21℃
- else if(Saber == 22)
- Point.setY(-60); // 绘制温度22℃
- else if(Saber == 23)
- Point.setY(-90); // 绘制温度23℃
- else if(Saber == 24)
- Point.setY(-120); // 绘制温度24℃
- else if(Saber == 25)
- Point.setY(-150); // 绘制温度25℃
- else if(Saber == 26)
- Point.setY(-180); // 绘制温度26℃
- else if(Saber == 27)
- Point.setY(-210); // 绘制温度27℃
- else if(Saber == 28)
- Point.setY(-240); // 绘制温度28℃
- else if(Saber == 29)
- Point.setY(-270); // 绘制温度29℃
- else if(Saber == 30)
- Point.setY(-300); // 绘制温度30℃
- else if(Saber == 31)
- Point.setY(-330); // 绘制温度31℃
- else if(Saber == 32)
- Point.setY(-360); // 绘制温度31℃
- else if(Saber == 33)
- Point.setY(-390); // 绘制温度31℃
- else{
- Point.setY(-420); // 过滤超标温度值!
- QMessageBox msgBox;
- msgBox.setText("The Temp has been outnumber the definition !");
- msgBox.exec();
- }
- qDebug()<<Saber;
- path->lineTo(Point); /*绘点连线*/
- }
- /*int groupBoxWidth = ui->groupBox_3->width();
- if(t > groupBoxWidth){
- // when the Time t more than groupBoxWidth,readjust the DrawArea
- p = p - 10; //调整坐标原点
- if(p == 190)
- p = 200;
- }*/
- update();
- }
- void TempShow_1::startPainting(void)
- {
- timer->start(1000);
- }
- void TempShow_1::closePainting(void)
- {
- timer->stop();
- }
- void TempShow_1::paintEvent(QPaintEvent *)
- {
- QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing, true);
- QPen thickPen(palette().foreground(), 2.0); // 设置大刻度线画笔为粗黑!
- QPen thinPen(palette().foreground(), 1.0); // 设置小刻度线画笔为细黑!
- painter.translate(40,430); // 调整坐标原点
- int width_X = 560.0;
- int higth_Y = 420;
- QLineF line_X(0.0, 0.0, width_X, 0.0);
- painter.drawLine(line_X); // 绘制X轴
- QLineF line_Y(0.0, 0.0, 0.0, -higth_Y);
- painter.drawLine(line_Y); // 绘制X轴
- painter.setPen(QPen(Qt::red, 2)); // 设置画笔颜色和大小
- painter.drawPath(*path); // 绘制路径
- /*画刻度还有数字*/
- for(int i = 1; i < higth_Y; i++){
- if(i % 30 == 0){
- painter.setPen(thickPen);
- QLineF lineThick(0.0, -(0.0 + i), 5.0, -(0.0 + i));
- painter.drawLine(lineThick);
- }
- if(i % 6 == 0) {
- painter.setPen(thinPen);
- QLineF lineThin(0.0, -(0.0 + i), 2.0, -(0.0 + i));
- painter.drawLine(lineThin);
- }
- }
- }
复制代码 |
|