基于Qt的车载GPS监控系统(5)温度设置


设置界面

Created with Raphaël 2.1.0主界面主界面温度设置温度设置用户进行系统温度报警设置把新的用户设置保存到配置文件数据已保存,返回

界面的类构成

基类:SetDialog 实现子功能界面通用的共性元素,背景设置,系统标题,子功能名称,返回按钮。
派生类:AlarmDialog 实现温度上限,下限,当前值的显示与设置功能。

设置对话框头文件

#ifndef SETDIALOG_H
#define SETDIALOG_H
#include <QtGui>
#include <QDebug>
#include"dht9000.h"

class SetDialog : public QDialog
{
    Q_OBJECT
public:
    SetDialog(QWidget *parent=0);
protected:
    QLineEdit * lineTitle;
    struct st_sys_dev g_dev[1];
    QToolButton *buttonSet;
private:
    QLabel *labelBg;
};
#endif // SETDIALOG_H

设置对话框实现文件

#include "setdialog.h"
#include "dht9000.h"
#include<QtGui>
#include<QDebug>


SetDialog::SetDialog( QWidget *parent)
    : QDialog( parent)
{
    load_dev(g_dev);

    this->setWindowIcon(QPixmap( ":/images/1.png") );
    this->setWindowTitle(tr("GP9001车载GPS监控系统"));
    this->setMinimumSize(800,480);
    this->setMaximumSize(800,480);
    labelBg = new QLabel(this);
    labelBg->setGeometry(QRect(0, 0, 800, 480));
    labelBg->setPixmap(QPixmap(":/images/9001bg.jpg"));
    labelBg->setScaledContents(true);

    lineTitle = new QLineEdit(this);
    //设置显示数字字体大小
    QFont font = lineTitle->font();
    font.setPointSize(font.pointSize() + 5);

    lineTitle->setFont(font);
    lineTitle->setText(tr("系统设置"));
    lineTitle->setReadOnly(true);
    lineTitle->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
    lineTitle->setGeometry(QRect(300, 90, 200, 35));

    buttonSet = new QToolButton(this);
    buttonSet->setGeometry(QRect(350, 360, 100, 100));
    buttonSet->setText( tr( "保存/退出" ) );
    buttonSet->setIcon( QPixmap( ":/images/5.png") );
    buttonSet->setIconSize( QPixmap( ":/images/5.png").size() );
    buttonSet->setAutoRaise( TRUE );
    buttonSet->setToolButtonStyle( Qt::ToolButtonTextUnderIcon);
    connect(buttonSet,SIGNAL(clicked()),this,SLOT(accept()));
}

温度设置头文件

ifndef ALARMDIALOG_H
#define ALARMDIALOG_H
#include "setdialog.h"

class AlarmDialog:public SetDialog
{
    Q_OBJECT
public:
    AlarmDialog(QWidget *parent = 0);
public slots:
    void saveDev();
private:
    QLabel *labTempUp;
    QSpinBox *spinTempUp;
    QSlider *slidTempUp;

    QLabel *labTempLow;
    QSpinBox *spinTempLow;
    QSlider *slidTempLow;

    QLabel *labHumiUp;
    QSpinBox *spinHumiUp;
    QSlider *slidHumiUp;
};
#endif // ALARMDIALOG_H

温度设置实现程序

#include"alarmdialog.h"

AlarmDialog::AlarmDialog(QWidget *parent)
    :SetDialog(parent)
{
    this->lineTitle->setText(tr("温度设置"));
    load_dev(g_dev);

    //设置温度上限值
    labTempUp = new QLabel(this);
    labTempUp->setText(tr("设置温度上限值:"));
    labTempUp->setGeometry(QRect(200, 170, 100, 25));

    spinTempUp = new QSpinBox(this);
    spinTempUp->setRange(20,50);
    spinTempUp->setGeometry(QRect(310, 170, 60, 25));
    spinTempUp->setValue(g_dev->alarm_set.temp_upper);

    slidTempUp = new QSlider(this);
    slidTempUp->setRange(20,50);
    slidTempUp->setOrientation(Qt::Horizontal);
    slidTempUp->setGeometry(QRect(380, 170, 260, 25));
    slidTempUp->setValue(g_dev->alarm_set.temp_upper);

    connect(spinTempUp,SIGNAL(valueChanged(int)),slidTempUp,SLOT(setValue(int)));
    connect(slidTempUp,SIGNAL(valueChanged(int)),spinTempUp,SLOT(setValue(int)));
    //设置温度下限值
    labTempLow = new QLabel(this);
    labTempLow->setText(tr("设置温度下限值:"));
    labTempLow->setGeometry(QRect(200, 220, 100, 25));

    spinTempLow = new QSpinBox(this);
    spinTempLow->setRange(-30,15);
    spinTempLow->setGeometry(QRect(310, 220, 60, 25));
    spinTempLow->setValue(g_dev->alarm_set.temp_lower);

    slidTempLow = new QSlider(this);
    slidTempLow->setRange(-30,15);
    slidTempLow->setOrientation(Qt::Horizontal);
    slidTempLow->setGeometry(QRect(380, 220, 260, 25));
    slidTempLow->setValue(g_dev->alarm_set.temp_lower);

    connect(spinTempLow,SIGNAL(valueChanged(int)),slidTempLow,SLOT(setValue(int)));
    connect(slidTempLow,SIGNAL(valueChanged(int)),spinTempLow,SLOT(setValue(int)));

    //设置车厢温度
    labHumiUp = new QLabel(this);
    labHumiUp->setText(tr("设置车厢温度值:"));
    labHumiUp->setGeometry(QRect(200, 270, 100, 25));

    spinHumiUp = new QSpinBox(this);
    spinHumiUp->setRange(-30,20);
    spinHumiUp->setGeometry(QRect(310, 270, 60, 25));
    spinHumiUp->setValue(g_dev->alarm_set.temp);

    slidHumiUp = new QSlider(this);
    slidHumiUp->setRange(-30,20);
    slidHumiUp->setOrientation(Qt::Horizontal);
    slidHumiUp->setGeometry(QRect(380, 270, 260, 25));
    slidHumiUp->setValue(g_dev->alarm_set.temp);

    connect(spinHumiUp,SIGNAL(valueChanged(int)),slidHumiUp,SLOT(setValue(int)));
    connect(slidHumiUp,SIGNAL(valueChanged(int)),spinHumiUp,SLOT(setValue(int)));


    connect(this->buttonSet,SIGNAL(clicked()),this,SLOT(saveDev()));
}

void AlarmDialog::saveDev()
{
    g_dev->alarm_set.temp_upper = spinTempUp->value();
    g_dev->alarm_set.temp_lower = spinTempLow->value();
    g_dev->alarm_set.temp = spinHumiUp->value();

    save_dev(g_dev);
}

Copyright © 2016 www.91arm.com 【91创客学堂】