本系统利用的是Qt Creator 5.12.12制作的。可实现的功能如下:①根据用户设定的设备的运行参数生成室内温度、湿度、空气质量随时间的变化情况;②若系统是智能的,可根据用户输入的户外温度、湿度的变化生成设备的运行指令。系统的代码量达到了2000行,需要完整源码的可私聊50r解决。下面逐一介绍系统的功能:
一、系统的文件分类:
1.mainwindow类
本类主要是用于生成主界面便于用户进行不同的操作的GUI界面。
2.airconditionface类
本类是生成手工修改空调运行参数:热容量、冷容量、温度、功率的GUI界面。
3.ventilation类
本类是生成手工修改新风系统运行参数:气容量、功率的GUI界面。
4.underface类
本类是生成手工修改地暖系统运行参数:温度、功率的GUI界面。
5. humidificationface类
本类是生成手工修改加湿系统运行参数:湿度、功率的GUI界面
6. dehumidification类
本类是生成手工修改除湿系统运行参数:湿度、功率的GUI界面
7.sys类
本类是包含空调类、新风系统类、地暖系统类、除湿系统类、加湿系统类的一个大类,在其中还初始化了5个static类对象air(空调)、und(地暖)、ven(新风)、hum(加湿)、deh(除湿),便于后面对系统进行控制。
8.readface类
本类是读取文件的GUI界面,可从用户的电脑是读取txt文件和XML文件并显示出来,方便用户读取数据。
9.runface类
本类是生成室内温度、湿度、空气质量随时间的变化情况的GUI界面。
10.automodeface类
本类是让用户在智能模式下输入外界的温、湿度的GUI界面。
11.autorunface类
本类是根据用户输入的户外温度、湿度的变化生成设备的运行指令的GUI界面。
12.introface类
本类是介绍产品信息的界面。
二、系统页面展示:
1.主页面:
//mainwindow.cpp文件
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "sys.h"
#include "airconditionface.h"
#include "ventilation.h"
#include "underface.h"
#include "humidificationface.h"
#include "dehumidification.h"
#include "introface.h"
#include "runface.h"
#include "readface.h"
#include "automodeface.h"
#include <QLineEdit>
#include <QRegExpValidator>
#include <QPushButton>
#include <QPainter>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setFixedSize(1000,600);
this->setWindowTitle("智能家居模拟系统");
this->setWindowIcon(QPixmap(":/image/icon.png"));
//创建产品介绍按钮,从而能够让用户查看使用说明
QPushButton*helpbutton=new QPushButton(this);
helpbutton->setText("查看介绍信息");
helpbutton->setStyleSheet("background-color:rgb(0, 199, 140)");
helpbutton->setFocusPolicy(Qt::NoFocus);
helpbutton->setFixedSize(helpbutton->width()*1.5,helpbutton->height()*1.15);
helpbutton->move((this->width()-helpbutton->width())*0.5,this->height()*0.1);
introface*introface1=new introface;
connect(helpbutton,&QPushButton::clicked,this,[=](){
introface1->show();
});
//创建空调按钮,从而能够修改空调的参数
QPushButton*airbutton=new QPushButton(this);
airbutton->setText("修改空调信息");
airbutton->setStyleSheet("background-color:rgb(0, 199, 140)");
airbutton->setFocusPolicy(Qt::NoFocus);
airbutton->setFixedSize(airbutton->width()*1.5,airbutton->height()*1.15);
airbutton->move((this->width()-airbutton->width())*0.5,this->height()*0.2);
airconditionface*airconditionface1=new airconditionface;
connect(airbutton,&QPushButton::clicked,this,[=](){
airconditionface1->show();
});
//airbutton->setStyleSheet("QPushButton{border:0px;}");
//airbutton->setStyleSheet("QPushButton{border-top-left-radius:15px;""border-top-right-radius:5px;}");
//创建新风按钮,从而能够修改新风的参数
QPushButton*venbutton=new QPushButton(this);
venbutton->setText("修改新风系统信息");
venbutton->setStyleSheet("background-color:rgb(0, 199, 140)");
venbutton->setFocusPolicy(Qt::NoFocus);
venbutton->setFixedSize(venbutton->width()*1.5,venbutton->height()*1.15);
venbutton->move((this->width()-venbutton->width())*0.5,this->height()*0.3);
ventilation*ventilation1=new ventilation;
connect(venbutton,&QPushButton::clicked,this,[=](){
ventilation1->show();
});
//创建地暖按钮,从而能够修改地暖的参数
QPushButton*undbutton=new QPushButton(this);
undbutton->setText("修改地暖系统信息");
undbutton->setStyleSheet("background-color:rgb(0, 199, 140)");
undbutton->setFocusPolicy(Qt::NoFocus);
undbutton->setFixedSize(undbutton->width()*1.5,undbutton->height()*1.15);
undbutton->move((this->width()-undbutton->width())*0.5,this->height()*0.4);
underface*underface1=new underface;
connect(undbutton,&QPushButton::clicked,this,[=](){
underface1->show();
});
//创建加湿按钮,从而能够修改加湿的参数
QPushButton*humbutton=new QPushButton(this);
humbutton->setText("修改加湿系统信息");
humbutton->setStyleSheet("background-color:rgb(0, 199, 140)");
humbutton->setFocusPolicy(Qt::NoFocus);
humbutton->setFixedSize(humbutton->width()*1.5,humbutton->height()*1.15);
humbutton->move((this->width()-humbutton->width())*0.5,this->height()*0.5);
humidificationface*humidificationface1=new humidificationface;
connect(humbutton,&QPushButton::clicked,this,[=](){
humidificationface1->show();
});
//创建除湿按钮,从而能够修改加湿的参数
QPushButton*dehbutton=new QPushButton(this);
dehbutton->setText("修改除湿系统信息");
dehbutton->setStyleSheet("background-color:rgb(0, 199, 140)");
dehbutton->setFocusPolicy(Qt::NoFocus);
dehbutton->setFixedSize(dehbutton->width()*1.5,dehbutton->height()*1.15);
dehbutton->move((this->width()-dehbutton->width())*0.5,this->height()*0.6);
dehumidification*dehumidification1=new dehumidification;
connect(dehbutton,&QPushButton::clicked,this,[=](){
dehumidification1->show();
});
//创建进入智能控制的界面的按钮
QPushButton*autobutton=new QPushButton(this);
autobutton->setText("进入智能模式");
autobutton->setStyleSheet("background-color:rgb(0, 199, 140)");
autobutton->setFocusPolicy(Qt::NoFocus);
autobutton->setFixedSize(autobutton->width()*1.5,autobutton->height()*1.15);
autobutton->move((this->width()-autobutton->width())*0.5,this->height()*0.7);
automodeface*automodeface1=new automodeface;
connect(autobutton,&QPushButton::clicked,this,[=](){
automodeface1->show();
});
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::paintEvent(QPaintEvent*)
{
QPainter painter(this);
QPixmap pix;
pix.load(":/image/3.png");
painter.drawPixmap(0,0,this->width(),this->height(),pix);
}
2.查看介绍信息界面:
//introface.cpp
#include "introface.h"
#include <QPainter>
introface::introface(QWidget *parent) : QMainWindow(parent)
{
this->setFixedSize(1000,600);
this->setWindowIcon(QPixmap(":/image/icon.png"));
this->setWindowTitle("产品介绍");
}
void introface::paintEvent(QPaintEvent*)
{
QPainter painter(this);
QPixmap pix;
pix.load(":/image/13.png");
painter.drawPixmap(0,0,this->width(),this->height(),pix);
}
3.修改空调信息界面:
//airconditionface.cpp
#include "airconditionface.h"
#include "mainwindow.h"
#include "runface.h"
#include "readface.h"
#include <QLineEdit>
#include <QRegExpValidator>
#include <QPainter>
#include <QDebug>
#include <QPushButton>
#include <QFont>
#include <QMessageBox>
airconditionface::airconditionface(QWidget *parent): QMainWindow(parent)
{
this->setFixedSize(1000,600);
this->setWindowTitle("编辑空调信息页面");
this->setWindowIcon(QPixmap(":/image/4.png"));
//创建查看设备运行情况按钮
QPushButton*runbutton=new QPushButton(this);
runbutton->setText("查看运行情况");
runbutton->setStyleSheet("background-color:rgb(0, 199, 140)");
runbutton->setFocusPolicy(Qt::NoFocus);
runbutton->setFixedSize(runbutton->width()*1.5,runbutton->height()*1.15);
runbutton->move((this->width()-runbutton->width())*0.6,this->height()*0.85);
runface*runface1=new runface;
connect(runbutton,&QPushButton::clicked,this,[=](){
runface1->show();
});
//连接信号量
connect(this,SIGNAL(sentHeatCapacity(int)),runface1,SLOT(recHeatCapacity(int)));
connect(this,SIGNAL(sentCoolCapacity(int)),runface1,SLOT(recCoolCapacity(int)));
connect(this,SIGNAL(sentPower(int)),runface1,SLOT(recPower1(int)));
connect(this,SIGNAL(sentTemprature(int)),runface1,SLOT(recTemprature(int)));
//创建读取文件按钮,从而能够修改参数
QPushButton*readbutton=new QPushButton(this);
readbutton->setText("读取文件");
readbutton->setStyleSheet("background-color:rgb(0, 199, 140)");
readbutton->setFocusPolicy(Qt::NoFocus);
readbutton->setFixedSize(readbutton->width()*1.5,readbutton->height()*1.15);
readbutton->move((this->width()-readbutton->width())*0.4,this->height()*0.85);
readface*readface1=new readface;
connect(readbutton,&QPushButton::clicked,this,[=](){
readface1->show();
});
//设置字体
QFont qfont;
qfont.setFamily("华文彩云");
QLabel*label=new QLabel(this);
label->resize(900,60);
label->setFont(QFont("Timers",12,QFont::Bold));
label->setText(QString("当前热容量:%1J/K 当前冷容量:%2J/K 当前温度:%3℃ 当前功率:%4W").arg(air.getHeatCapacity()).arg(air.getCoolCapacity()).arg(air.getTemprature()).arg(air.getPower()));
label->move((this->width()-label->width())*0.8,this->height()*0.005);
label->show();
QPushButton*confirmbtn1=new QPushButton(this);
confirmbtn1->move((this->width()-confirmbtn1->width())*0.8,this->height()*0.12);
confirmbtn1->setFixedSize(confirmbtn1->width()*0.5,confirmbtn1->height());
confirmbtn1->setText("确认");
confirmbtn1->setFont(qfont);
confirmbtn1->setStyleSheet("background-color:rgb(0, 199, 140)");
QLineEdit*line1=new QLineEdit(this);
line1->setFont(QFont("Timers",16,QFont::Bold));
line1->setFixedSize(380,60);
line1->setPlaceholderText(tr("请输入想要设定的热容量"));
line1->move((this->width()-line1->width())*0.5,this->height()*0.1);
connect(confirmbtn1,&QPushButton::clicked,this,[=](){
air.setHeatCapacity(line1->text().toInt());
qDebug()<<air.getHeatCapacity();
QMessageBox message(QMessageBox::Information, "information","成功设置热容量!");
message.setIconPixmap(QPixmap(":/image/2.png"));
message.setStyleSheet("QLabel{""min-width: 125px;""min-height: 100px; ""}");
message.show();
message.exec();
label->setText(QString("当前热容量:%1J/K 当前冷容量:%2J/K 当前温度:%3℃ 当前功率:%4W").arg(air.getHeatCapacity()).arg(air.getCoolCapacity()).arg(air.getTemprature()).arg(air.getPower()));
emit sentHeatCapacity(air.getHeatCapacity());
});
QPushButton*confirmbtn2=new QPushButton(this);
confirmbtn2->move((this->width()-confirmbtn2->width())*0.8,this->height()*0.32);
confirmbtn2->setFixedSize(confirmbtn2->width()*0.5,confirmbtn2->height());
confirmbtn2->setText("确认");
confirmbtn2->setFont(qfont);
confirmbtn2->setStyleSheet("background-color:rgb(0, 199, 140)");
QLineEdit*line2=new QLineEdit(this);
line2->setFont(QFont("Timers",16,QFont::Bold));
line2->setFixedSize(380,60);
line2->setPlaceholderText(tr("请输入想要设定的冷容量"));
line2->move((this->width()-line2->width())*0.5,this->height()*0.3);
connect(confirmbtn2,&QPushButton::clicked,this,[=](){
air.setCoolCapacity(line2->text().toInt());
qDebug()<<air.getCoolCapacity();
QMessageBox message(QMessageBox::Information, "information","成功设置冷容量!");
message.setIconPixmap(QPixmap(":/image/2.png"));
message.setStyleSheet("QLabel{""min-width: 125px;""min-height: 100px; ""}");
message.show();
message.exec();
label->setText(QString("当前热容量:%1J/K 当前冷容量:%2J/K 当前温度:%3℃ 当前功率:%4W").arg(air.getHeatCapacity()).arg(air.getCoolCapacity()).arg(air.getTemprature()).arg(air.getPower()));
emit sentCoolCapacity(air.getCoolCapacity());
});
QPushButton*confirmbtn3=new QPushButton(this);
confirmbtn3->move((this->width()-confirmbtn3->width())*0.8,this->height()*0.52);
confirmbtn3->setFixedSize(confirmbtn3->width()*0.5,confirmbtn3->height());
confirmbtn3->setText("确认");
confirmbtn3->setFont(qfont);
confirmbtn3->setStyleSheet("background-color:rgb(0, 199, 140)");
QLineEdit*line3=new QLineEdit(this);
line3->setFont(QFont("Timers",16,QFont::Bold));
line3->setFixedSize(380,60);
line3->setPlaceholderText(tr("请输入想要设定的功率"));
line3->move((this->width()-line3->width())*0.5,this->height()*0.5);
connect(confirmbtn3,&QPushButton::clicked,this,[=](){
air.setPower(line3->text().toInt());
qDebug()<<air.getPower();
QMessageBox message(QMessageBox::Information, "information","成功设置功率!");
message.setIconPixmap(QPixmap(":/image/2.png"));
message.setStyleSheet("QLabel{""min-width: 125px;""min-height: 100px; ""}");
message.show();
message.exec();
label->setText(QString("当前热容量:%1J/K 当前冷容量:%2J/K 当前温度:%3℃ 当前功率:%4W").arg(air.getHeatCapacity()).arg(air.getCoolCapacity()).arg(air.getTemprature()).arg(air.getPower()));
emit sentPower(air.getPower());
});
QPushButton*confirmbtn4=new QPushButton(this);
confirmbtn4->move((this->width()-confirmbtn4->width())*0.8,this->height()*0.72);
confirmbtn4->setFixedSize(confirmbtn4->width()*0.5,confirmbtn4->height());
confirmbtn4->setText("确认");
confirmbtn4->setFont(qfont);
confirmbtn4->setStyleSheet("background-color:rgb(0, 199, 140)");
QLineEdit*line4=new QLineEdit(this);
line4->setFont(QFont("Timers",16,QFont::Bold));
line4->setFixedSize(380,60);
line4->setPlaceholderText(tr("请输入想要设定的温度"));
line4->move((this->width()-line4->width())*0.5,this->height()*0.7);
connect(confirmbtn4,&QPushButton::clicked,this,[=](){
air.setTemprature(line4->text().toInt());
qDebug()<<air.getTemprature();
QMessageBox message(QMessageBox::Information, "information","成功设置温度!");
message.setIconPixmap(QPixmap(":/image/2.png"));
message.setStyleSheet("QLabel{""min-width: 125px;""min-height: 100px; ""}");
message.show();
message.exec();
label->setText(QString("当前热容量:%1J/K 当前冷容量:%2J/K 当前温度:%3℃ 当前功率:%4W").arg(air.getHeatCapacity()).arg(air.getCoolCapacity()).arg(air.getTemprature()).arg(air.getPower()));
emit sentTemprature(air.getTemprature());
});
}
void airconditionface::paintEvent(QPaintEvent*)
{
QPainter painter(this);
QPixmap pix;
pix.load(":/image/4.png");
painter.drawPixmap(0,0,this->width(),this->height(),pix);
}
4.修改新风系统信息界面:
//ventilation.cpp
#include "ventilation.h"
#include "runface.h"
#include "readface.h"
#include <QLineEdit>
#include <QRegExpValidator>
#include <QPainter>
#include <QPushButton>
#include <QDebug>
#include <QMessageBox>
#include <QLabel>
ventilation::ventilation(QWidget *parent) : QMainWindow(parent)
{
this->setFixedSize(1000,600);
this->setWindowTitle("编辑新风系统信息页面");
this->setWindowIcon(QPixmap(":/image/5.png"));
//设置字体
QFont qfont;
qfont.setFamily("华文彩云");
//创建查看设备运行情况按钮
QPushButton*runbutton=new QPushButton(this);
runbutton->setText("查看运行情况");
runbutton->setStyleSheet("background-color:rgb(0, 199, 140)");
runbutton->setFocusPolicy(Qt::NoFocus);
runbutton->setFixedSize(runbutton->width()*1.5,runbutton->height()*1.15);
runbutton->move((this->width()-runbutton->width())*0.6,this->height()*0.85);
runface*runface1=new runface;
connect(runbutton,&QPushButton::clicked,this,[=](){
runface1->show();
});
//连接信号量
connect(this,SIGNAL(sentAirVolumn(int)),runface1,SLOT(recAirVolumn(int)));
connect(this,SIGNAL(sentPower(int)),runface1,SLOT(recPower2(int)));
//创建读取文件按钮,从而能够修改参数
QPushButton*readbutton=new QPushButton(this);
readbutton->setText("读取文件");
readbutton->setStyleSheet("background-color:rgb(0, 199, 140)");
readbutton->setFocusPolicy(Qt::NoFocus);
readbutton->setFixedSize(readbutton->width()*1.5,readbutton->height()*1.15);
readbutton->move((this->width()-readbutton->width())*0.4,this->height()*0.85);
readface*readface1=new readface;
connect(readbutton,&QPushButton::clicked,this,[=](){
readface1->show();
});
QLabel*label=new QLabel(this);
label->resize(900,60);
label->setFont(QFont("Timers",12,QFont::Bold));
label->setText(QString("当前气容量:%1L 当前功率:%2W").arg(ven.getAirVolumn()).arg(ven.getPower()));
label->move((this->width()-label->width())*3,this->height()*0.12);
label->show();
QPushButton*confirmbtn1=new QPushButton(this);
confirmbtn1->move((this->width()-confirmbtn1->width())*0.8,this->height()*0.32);
confirmbtn1->setFixedSize(confirmbtn1->width()*0.5,confirmbtn1->height());
confirmbtn1->setText("确认");
confirmbtn1->setFont(qfont);
confirmbtn1->setStyleSheet("background-color:rgb(0, 199, 140)");
QLineEdit*line1=new QLineEdit(this);
line1->setFont(QFont("Timers",16,QFont::Bold));
line1->setFixedSize(380,60);
line1->setPlaceholderText(tr("请输入想要设定的功率"));
//editgamer->setValidator(new QRegExpValidator(QRegExp("[2-6]")));
line1->move((this->width()-line1->width())*0.5,this->height()*0.3);
connect(confirmbtn1,&QPushButton::clicked,this,[=](){
ven.setPower(line1->text().toInt());
qDebug()<<ven.getPower();
QMessageBox message(QMessageBox::Information, "information","成功设置功率!");
message.setIconPixmap(QPixmap(":/image/2.png"));
message.setStyleSheet("QLabel{""min-width: 125px;""min-height: 100px; ""}");
message.show();
message.exec();
label->setText(QString("当前气容量:%1L 当前功率:%2W").arg(ven.getAirVolumn()).arg(ven.getPower()));
emit sentPower(ven.getPower());
});
QPushButton*confirmbtn2=new QPushButton(this);
confirmbtn2->move((this->width()-confirmbtn2->width())*0.8,this->height()*0.52);
confirmbtn2->setFixedSize(confirmbtn2->width()*0.5,confirmbtn2->height());
confirmbtn2->setText("确认");
confirmbtn2->setFont(qfont);
confirmbtn2->setStyleSheet("background-color:rgb(0, 199, 140)");
QLineEdit*line2=new QLineEdit(this);
line2->setFont(QFont("Timers",16,QFont::Bold));
line2->setFixedSize(380,60);
line2->setPlaceholderText(tr("请输入想要设定的气容量"));
//editgamer->setValidator(new QRegExpValidator(QRegExp("[2-6]")));
line2->move((this->width()-line2->width())*0.5,this->height()*0.5);
connect(confirmbtn2,&QPushButton::clicked,this,[=](){
ven.setAirVolumn(line2->text().toInt());
qDebug()<<ven.getAirVolumn();
QMessageBox message(QMessageBox::Information, "information","成功设置气容量!");
message.setIconPixmap(QPixmap(":/image/2.png"));
message.setStyleSheet("QLabel{""min-width: 125px;""min-height: 100px; ""}");
message.show();
message.exec();
label->setText(QString("当前气容量:%1L 当前功率:%2W").arg(ven.getAirVolumn()).arg(ven.getPower()));
emit sentAirVolumn(ven.getAirVolumn());
});
}
void ventilation::paintEvent(QPaintEvent*)
{
QPainter painter(this);
QPixmap pix;
pix.load(":/image/6.png");
painter.drawPixmap(0,0,this->width(),this->height(),pix);
}
5. 修改地暖系统信息界面:
//underface.cpp
#include "underface.h"
#include "runface.h"
#include "readface.h"
#include <QLineEdit>
#include <QRegExpValidator>
#include <QPainter>
#include <QPushButton>
#include <QDebug>
#include <QMessageBox>
#include <QLabel>
underface::underface(QWidget *parent) : QMainWindow(parent)
{
this->setFixedSize(1000,600);
this->setWindowTitle("编辑地暖系统信息页面");
this->setWindowIcon(QPixmap(":/image/7.png"));
//设置字体
QFont qfont;
qfont.setFamily("华文彩云");
//创建查看设备运行情况按钮
QPushButton*runbutton=new QPushButton(this);
runbutton->setText("查看运行情况");
runbutton->setStyleSheet("background-color:rgb(0, 199, 140)");
runbutton->setFocusPolicy(Qt::NoFocus);
runbutton->setFixedSize(runbutton->width()*1.5,runbutton->height()*1.15);
runbutton->move((this->width()-runbutton->width())*0.6,this->height()*0.85);
runface*runface1=new runface;
connect(runbutton,&QPushButton::clicked,this,[=](){
runface1->show();
});
//连接信号量
connect(this,SIGNAL(sentaveTemprature(int)),runface1,SLOT(recaveTemprature(int)));
connect(this,SIGNAL(sentPower(int)),runface1,SLOT(recPower3(int)));
//创建读取文件按钮,从而能够修改参数
QPushButton*readbutton=new QPushButton(this);
readbutton->setText("读取文件");
readbutton->setStyleSheet("background-color:rgb(0, 199, 140)");
readbutton->setFocusPolicy(Qt::NoFocus);
readbutton->setFixedSize(readbutton->width()*1.5,readbutton->height()*1.15);
readbutton->move((this->width()-readbutton->width())*0.4,this->height()*0.85);
readface*readface1=new readface;
connect(readbutton,&QPushButton::clicked,this,[=](){
readface1->show();
});
QLabel*label=new QLabel(this);
label->resize(900,60);
label->setFont(QFont("Timers",12,QFont::Bold));
label->setText(QString("当前温度:%1℃ 当前功率:%2W").arg(und.getaveTemprature()).arg(und.getPower()));
label->move((this->width()-label->width())*3,this->height()*0.12);
label->show();
QPushButton*confirmbtn1=new QPushButton(this);
confirmbtn1->move((this->width()-confirmbtn1->width())*0.8,this->height()*0.32);
confirmbtn1->setFixedSize(confirmbtn1->width()*0.5,confirmbtn1->height());
confirmbtn1->setText("确认");
confirmbtn1->setFont(qfont);
confirmbtn1->setStyleSheet("background-color:rgb(0, 199, 140)");
QLineEdit*line1=new QLineEdit(this);
line1->setFont(QFont("Timers",16,QFont::Bold));
line1->setFixedSize(380,60);
line1->setPlaceholderText(tr("请输入想要设定的温度"));
//editgamer->setValidator(new QRegExpValidator(QRegExp("[2-6]")));
line1->move((this->width()-line1->width())*0.5,this->height()*0.3);
connect(confirmbtn1,&QPushButton::clicked,this,[=](){
und.setaveTemprature(line1->text().toInt());
qDebug()<<und.getaveTemprature();
QMessageBox message(QMessageBox::Information, "information","成功设置温度!");
message.setIconPixmap(QPixmap(":/image/2.png"));
message.setStyleSheet("QLabel{""min-width: 125px;""min-height: 100px; ""}");
message.show();
message.exec();
label->setText(QString("当前温度:%1℃ 当前功率:%2W").arg(und.getaveTemprature()).arg(und.getPower()));
emit sentaveTemprature(und.getaveTemprature());
});
QPushButton*confirmbtn2=new QPushButton(this);
confirmbtn2->move((this->width()-confirmbtn2->width())*0.8,this->height()*0.52);
confirmbtn2->setFixedSize(confirmbtn2->width()*0.5,confirmbtn2->height());
confirmbtn2->setText("确认");
confirmbtn2->setFont(qfont);
confirmbtn2->setStyleSheet("background-color:rgb(0, 199, 140)");
QLineEdit*line2=new QLineEdit(this);
line2->setFont(QFont("Timers",16,QFont::Bold));
line2->setFixedSize(380,60);
line2->setPlaceholderText(tr("请输入想要设定的功率"));
//editgamer->setValidator(new QRegExpValidator(QRegExp("[2-6]")));
line2->move((this->width()-line2->width())*0.5,this->height()*0.5);
connect(confirmbtn2,&QPushButton::clicked,this,[=](){
und.setPower(line2->text().toInt());
qDebug()<<und.getPower();
QMessageBox message(QMessageBox::Information, "information","成功设置功率!");
message.setIconPixmap(QPixmap(":/image/2.png"));
message.setStyleSheet("QLabel{""min-width: 125px;""min-height: 100px; ""}");
message.show();
message.exec();
label->setText(QString("当前温度:%1℃ 当前功率:%2W").arg(und.getaveTemprature()).arg(und.getPower()));
emit sentPower(und.getPower());
});
}
void underface::paintEvent(QPaintEvent*)
{
QPainter painter(this);
QPixmap pix;
pix.load(":/image/7.png");
painter.drawPixmap(0,0,this->width(),this->height(),pix);
}
6. 修改加湿系统信息界面:
7. 修改除湿系统信息界面:
8.运行情况:(以空调为例,首先应置空调功率为至少100W从而打开空调,这里默认空调是以制冷模式打开的,我设定的温度是18℃,温度会在5min内不断下降 )
9. 智能控制界面:
用户输入户外温度、湿度的GUI界面如下图所示:
系统收到外界温度时,会进行判断,根据科学研究,当外界气温大于28℃时,人体会感到炎热,因此空调将开启制冷功能,这里默认的是空调将温度设为22℃,用户觉得不合适可以另外调节;当外界温度小于15℃时,人体会感到寒冷,此处会有两种抉择:开启空调制热功能还是地暖(显然将两者同时开启并不是一个好的选择),从使用费用上来分析,空调确实没有地暖节能,普通空调一个月的耗电量起码也要250度,地暖则不到,地暖怎么用都要比空调省钱,另外地暖运行起来没有噪音和空调对流风吹的带来的不适,地暖采用整个地板辐射均匀热辐射作为散热系统,而且热量是从下到上让人备感舒适,给人脚暖头凉的舒适舒适,因此这里系统默认是开启地暖系统,默认是认为地暖系统会将温度调至25℃。代码如下图所示:
下面来看看当系统收到外界湿度时会做出怎样的反应:据研究表明,适宜人体的湿度大概为30%~50%,为了方便,本系统取35%,当外界湿度大于50%时,需要除湿,当外界湿度小于20%时,需要加湿,用代码表示就是下面这样:
图表 21
例如,输入外界温度30℃,湿度60%,此时将开启空调制冷功能和除湿器,如图所示:
//autorunface.cpp
#include "autorunface.h"
#include "sys.h"
#include <QLineEdit>
#include <QRegExpValidator>
#include <QPainter>
#include <QDebug>
#include <QPushButton>
#include <QFont>
#include <QMessageBox>
#include <QLabel>
autorunface::autorunface(QWidget *parent) : QMainWindow(parent)
{
this->setFixedSize(1000,600);
this->setWindowTitle("智能模式");
this->setWindowIcon(QPixmap(":/image/1.png"));
//设置字体
QFont qfont;
qfont.setFamily("华文彩云");
QLabel*label=new QLabel(this);
label->resize(900,60);
label->setFont(QFont("Timers",12,QFont::Bold));
label->setText(QString("请点击刷新按钮生成设备运行信息"));
label->move((this->width()-label->width())*3,this->height()*0.01);
label->show();
QPushButton*refreshbtn=new QPushButton(this);
refreshbtn->move((this->width()-refreshbtn->width())*0.5,this->height()*0.1);
refreshbtn->setFixedSize(refreshbtn->width()*0.6,refreshbtn->height());
refreshbtn->setText("刷新");
// refreshbtn->setFont(qfont);
refreshbtn->setStyleSheet("background-color:rgb(0, 199, 140)");
QLabel*label1=new QLabel(this);
QLabel*label2=new QLabel(this);
QLabel*label3=new QLabel(this);
QLabel*label4=new QLabel(this);
QLabel*label5=new QLabel(this);
QLabel*label6=new QLabel(this);
QLabel*label7=new QLabel(this);
QLabel*label8=new QLabel(this);
connect(refreshbtn,&QPushButton::clicked,this,[=](){
if(air.getPower())
{
if(air.getCoolCapacity())
{
label6->resize(580,60);
label6->setFont(QFont("Timers",14,QFont::Bold));
label6->setStyleSheet("color:red");
label6->setText(QString("空调制冷功能已为您开启!"));
label6->move((this->width()-label6->width())*0.8,this->height()*0.3);
label6->show();
}
label1->resize(1000,60);
label1->setFont(QFont("Timers",14,QFont::Bold));
label1->setStyleSheet("color:red");
label1->setText(QString("空调热容量:%1J/K 空调冷容量:%2J/K 空调温度:%3℃ 空调功率:%4W").arg(air.getHeatCapacity()).arg(air.getCoolCapacity()).arg(air.getTemprature()).arg(air.getPower()));
label1->move((this->width()-label1->width())*0.4,this->height()*0.4);
label1->show();
}
if(und.getPower())
{
label2->resize(580,60);
label2->setFont(QFont("Timers",14,QFont::Bold));
label2->setStyleSheet("color:red");
label2->setText(QString("地暖制热功能已为您开启!"));
label2->move((this->width()-label2->width())*0.8,this->height()*0.3);
label2->show();
label3->resize(550,60);
label3->setFont(QFont("Timers",14,QFont::Bold));
label3->setStyleSheet("color:red");
label3->setText(QString(QString("地暖系统温度:%1℃ 地暖系统功率:%2W").arg(und.getaveTemprature()).arg(und.getPower())));
label3->move((this->width()-label3->width())*0.6,this->height()*0.4);
label3->show();
}
if(hum.getPower())
{
label7->resize(580,60);
label7->setFont(QFont("Timers",14,QFont::Bold));
label7->setStyleSheet("color:red");
label7->setText(QString("加湿器已为您开启!"));
label7->move((this->width()-label7->width())*0.9,this->height()*0.5);
label7->show();
label4->resize(550,60);
label4->setFont(QFont("Timers",14,QFont::Bold));
label4->setStyleSheet("color:red");
label4->setText(QString(QString("加湿系统湿度:%1RH 加湿系统功率:%2W").arg(hum.gethumidity()).arg(hum.getPower())));
label4->move((this->width()-label4->width())*0.5,this->height()*0.6);
label4->show();
}
if(deh.getPower())
{
label8->resize(580,60);
label8->setFont(QFont("Timers",14,QFont::Bold));
label8->setStyleSheet("color:red");
label8->setText(QString("除湿器已为您开启!"));
label8->move((this->width()-label8->width())*0.9,this->height()*0.5);
label8->show();
label5->resize(550,60);
label5->setFont(QFont("Timers",14,QFont::Bold));
label5->setStyleSheet("color:red");
label5->setText(QString(QString("除湿系统湿度:%1RH 除湿系统功率:%2W").arg(deh.gethumidity()).arg(deh.getPower())));
label5->move((this->width()-label5->width())*0.5,this->height()*0.6);
label5->show();
}
});
}
void autorunface::rectemp(int a)
{
//当外界气温到达28摄氏度时,人体会感觉到炎热,开启空调制冷功能
if(a>28)
{
air.setCoolCapacity(100);
air.setHeatCapacity(0);
air.setTemprature(22);
air.setPower(100);
}
//外界气温低于15摄氏度时,人体会感到寒冷,开启地暖制热功能
if(a<15)
{
und.setaveTemprature(25);
und.setPower(100);
}
}
void autorunface::rechumidity(int a)
{
//当外界湿度大于50时,需要除湿
if(a>50)
{
deh.setPower(100);
deh.sethumidity(35);
}
//当外界湿度小于20时,需要加湿
if(a<20)
{
hum.setPower(100);
hum.sethumidity(35);
}
}
void autorunface::paintEvent(QPaintEvent*)
{
QPainter painter(this);
QPixmap pix;
pix.load(":/image/14.png");
painter.drawPixmap(0,0,this->width(),this->height(),pix);
}