diff --git a/SmartGreenhouse.pro b/SmartGreenhouse.pro new file mode 100644 index 0000000..6b4d615 --- /dev/null +++ b/SmartGreenhouse.pro @@ -0,0 +1,41 @@ +QT += core gui network sql +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + mainmenu.cpp \ + sql.cpp \ + submenu.cpp + +HEADERS += \ + mainmenu.h \ + sql.h \ + submenu.h + +FORMS += \ + mainmenu.ui \ + submenu.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +DISTFILES += + +RESOURCES += \ + img/img.qrc \ + img/img.qrc diff --git a/airconditurepage.ui b/airconditurepage.ui deleted file mode 100644 index fdd860b..0000000 --- a/airconditurepage.ui +++ /dev/null @@ -1,19 +0,0 @@ - - - airconditurePage - - - - 0 - 0 - 400 - 300 - - - - Form - - - - - diff --git a/camerapage.cpp b/camerapage.cpp deleted file mode 100644 index 9a6ec99..0000000 --- a/camerapage.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "camerapage.h" -#include "ui_camerapage.h" - -cameraPage::cameraPage(QWidget *parent) : - QWidget(parent), - ui(new Ui::cameraPage) -{ - ui->setupUi(this); -} - -cameraPage::~cameraPage() -{ - delete ui; -} diff --git a/camerapage.ui b/camerapage.ui deleted file mode 100644 index 657e9bf..0000000 --- a/camerapage.ui +++ /dev/null @@ -1,19 +0,0 @@ - - - cameraPage - - - - 0 - 0 - 400 - 300 - - - - Form - - - - - diff --git a/client.cpp b/client.cpp deleted file mode 100644 index 3ec90dd..0000000 --- a/client.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "client.h" - -#include - -client::client() -{ - socket = new QTcpSocket(this); -} - -//连接服务器 -void client::connect() -{ - socket->connectToHost("192.168.0.169", 8888); -} - -//发送消息 -void client::sendMessage() -{ - QString strLine = "hello world!"; - socket->write(strLine); -} - -//接收消息 -void client::recvMessage() -{ - QByteArray arr = socket->readAll(); - qDebug() << arr; -} diff --git a/client.h b/client.h deleted file mode 100644 index e4e3a4d..0000000 --- a/client.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef CLIENT_H -#define CLIENT_H - -#include - -class client -{ -public: - client(); - - //连接服务器 - void connect(); - - //发送消息 - void sendMessage(); - - //接收消息 - void recvMessage(); -private: - QTcpSocket * socket; -}; - -#endif // CLIENT_H diff --git a/historydata.cpp b/historydata.cpp deleted file mode 100644 index c1df6e2..0000000 --- a/historydata.cpp +++ /dev/null @@ -1,188 +0,0 @@ -#include "historydata.h" -#include "ui_historydata.h" - -#include -#include - -historyData::historyData(QWidget *parent) : - QWidget(parent), - ui(new Ui::historyData) -{ - ui->setupUi(this); - - //设置窗口标题 - this->setWindowTitle("历史数据"); - this->setFixedSize(this->width(), this->height()); - - //实例化 - chart = new QChart; - chart->setAnimationOptions(QChart::SeriesAnimations); //在缩放窗口大小时可以用动画进行美化 - TemSeries = new QLineSeries(); - HumSeries = new QLineSeries(); - LightSeries = new QLineSeries(); - SmokeSeries = new QLineSeries(); - paintXY(); - - //创建套接字,和A9服务器取得连接 - historyDataSocket = new QTcpSocket(this); - historyDataSocket->connectToHost("192.168.200.105", 7777); - - connect(historyDataSocket, SIGNAL(readyRead()), this, SLOT(recvA9ServerSlot())); -} - -historyData::~historyData() -{ - delete ui; - historyDataSocket->close(); - historyDataSocket = NULL; -} - -void historyData::on_historyDataReturnBrn_clicked() -{ - TemSeries->clear(); - HumSeries->clear(); - LightSeries->clear(); - SmokeSeries->clear(); - emit historyDataToWidgetSignal(); -} - -void historyData::on_searchHistoryDataBtn_clicked() -{ - QString command = {"searchHistoryData"}; - QByteArray arr; - arr.clear(); - arr.append(command); - if(this->historyDataSocket->write(arr) == -1) - { - int ret = QMessageBox::question(this, "提交命令失败", "你提交的命令并没有上传到服务器!!!", QMessageBox::Yes); - } - else - { - int ret = QMessageBox::question(this, "提交成功", "恭喜你成功提交数据到服务器!!!", QMessageBox::Yes); - } - - //清空坐标里的内容 - TemSeries->clear(); - HumSeries->clear(); - LightSeries->clear(); - SmokeSeries->clear(); - - paintTemSeries(); - paintHumSeries(); - paintLightSeries(); - paintSmokeSeries(); - -} - -void historyData::recvA9ServerSlot() -{ - QByteArray recvServer = historyDataSocket->readAll(); - qDebug() << "history recv " << recvServer; -} - -//画坐标轴 -void historyData::paintXY() -{ - axisX = new QValueAxis; - //设置坐标轴的格式 - - axisX->setRange(0,12); //设置范围 - axisX->setLabelFormat("%d"); //设置刻度的格式 - axisX->setGridLineVisible(true); //网格线可见 - axisX->setTickCount(12); //设置多少格 - axisX->setMinorTickCount(5); //设置每格小刻度线的数目 - chart->addAxis(axisX, Qt::AlignBottom); //为chart设置x轴,并把轴附加到线上 - - axisY = new QValueAxis; - axisY->setRange(0,100); //设置范围 - axisY->setLabelFormat("%d"); //设置刻度的格式 - axisY->setGridLineVisible(true); //网格线可见 - axisY->setTickCount(11); //设置多少格 - axisY->setMinorTickCount(5); //设置每格小刻度线的数目 - chart->addAxis(axisY, Qt::AlignLeft); //为chart设置y轴,并把轴附加到线上 - - //用Qchart在QChartView上面 - ui->canvas->setChart(chart); - ui->canvas->setRenderHint(QPainter::Antialiasing); //抗锯齿 -} - -//画温度的折线统计图 -void historyData::paintTemSeries() -{ - //设置一个pen给线 - QPen TemPen; - TemPen.setWidth(2); - TemPen.setColor(Qt::red); - - //把笔交给线 - TemSeries->setPen(TemPen); - TemSeries->setName("温度"); - - *TemSeries << QPointF(0,24) << QPointF(1,23) << QPointF(2,25) << QPointF(3,27) << QPointF(4,29)<< QPointF(5,29) << QPointF(6,30) << QPointF(7,32) << QPointF(8,35)<< QPointF(9,37) << QPointF(10,35) << QPointF(11,33) << QPointF(12,30); - chart->addSeries(TemSeries); - - //把线绑定到坐标轴上 - TemSeries->attachAxis(axisX); - TemSeries->attachAxis(axisY); -} - -//画湿度的折线统计图 -void historyData::paintHumSeries() -{ - //设置一个pen给线 - QPen HumPen; - HumPen.setWidth(2); - HumPen.setColor(Qt::yellow); - - //把笔交给线 - HumSeries->setPen(HumPen); - HumSeries->setName("湿度"); - - *HumSeries << QPointF(0,65) << QPointF(1,67) << QPointF(2,64) << QPointF(3,64) << QPointF(4,62)<< QPointF(5,60) << QPointF(6,58) << QPointF(7,57) << QPointF(8,57)<< QPointF(9,55) << QPointF(10,56) << QPointF(11,58) << QPointF(12,62); - chart->addSeries(HumSeries); - - //把线绑定到坐标轴上 - HumSeries->attachAxis(axisX); - HumSeries->attachAxis(axisY); -} - -//画光照强度的折线统计图 -void historyData::paintLightSeries() -{ - //设置一个pen给线 - QPen LightPen; - LightPen.setWidth(2); - LightPen.setColor(Qt::green); - - //把笔交给线 - LightSeries->setPen(LightPen); - LightSeries->setName("光照强度"); - - *LightSeries << QPointF(0,48) << QPointF(1,53) << QPointF(2,52) << QPointF(3,51) << QPointF(4,53)<< QPointF(5,50) << QPointF(6,55) << QPointF(7,60) << QPointF(8,68)<< QPointF(9,69) << QPointF(10,75) << QPointF(11,62) << QPointF(12,55); - chart->addSeries(LightSeries); - - //把线绑定到坐标轴上 - LightSeries->attachAxis(axisX); - LightSeries->attachAxis(axisY); -} - -//画烟雾浓度的折线统计图 -void historyData::paintSmokeSeries() -{ - //设置一个pen给线 - QPen SmokePen; - SmokePen.setWidth(2); - SmokePen.setColor(Qt::blue); - - //把笔交给线 - SmokeSeries->setPen(SmokePen); - SmokeSeries->setName("烟雾浓度"); - - *SmokeSeries << QPointF(0,10) << QPointF(3,10) << QPointF(7,10) << QPointF(9,10) << QPointF(12,10); - chart->addSeries(SmokeSeries); - - //把线绑定到坐标轴上 - SmokeSeries->attachAxis(axisX); - SmokeSeries->attachAxis(axisY); - -} diff --git a/historydata.cpp.autosave b/historydata.cpp.autosave deleted file mode 100644 index 200d587..0000000 --- a/historydata.cpp.autosave +++ /dev/null @@ -1,189 +0,0 @@ -#include "historydata.h" -#include "ui_historydata.h" - -#include -#include - -historyData::historyData(QWidget *parent) : - QWidget(parent), - ui(new Ui::historyData) -{ - ui->setupUi(this); - - //设置窗口标题 - this->setWindowTitle("历史数据"); - this->setFixedSize(this->width(), this->height()); - - //实例化 - chart = new QChart; - chart->setAnimationOptions(QChart::SeriesAnimations); //在缩放窗口大小时可以用动画进行美化 - TemSeries = new QLineSeries(); - HumSeries = new QLineSeries(); - LightSeries = new QLineSeries(); - SmokeSeries = new QLineSeries(); - paintXY(); - - //创建套接字,和A9服务器取得连接 - historyDataSocket = new QTcpSocket(this); - historyDataSocket->connectToHost("192.168.200.105", 7777); - - connect(historyDataSocket, SIGNAL(readyRead()), this, SLOT(recvA9ServerSlot())); -} - -historyData::~historyData() -{ - delete ui; - historyDataSocket->close(); - historyDataSocket = NULL; -} - -void historyData::on_historyDataReturnBrn_clicked() -{ - TemSeries->clear(); - HumSeries->clear(); - LightSeries->clear(); - SmokeSeries->clear(); - emit historyDataToWidgetSignal(); -} - -void historyData::on_searchHistoryDataBtn_clicked() -{ - QString command = {"searchHistoryData"}; - QByteArray arr; - arr.clear(); - arr.append(command); - if(this->historyDataSocket->write(arr) == -1) - { - int ret = QMessageBox::question(this, "提交命令失败", "你提交的命令并没有上传到服务器!!!", QMessageBox::Yes); - } - else - { - int ret = QMessageBox::question(this, "提交成功", "恭喜你成功提交数据到服务器!!!", QMessageBox::Yes); - } - - //清空坐标里的内容 - TemSeries->clear(); - HumSeries->clear(); - LightSeries->clear(); - SmokeSeries->clear(); - - paintTemSeries(); - paintHumSeries(); - paintLightSeries(); - paintSmokeSeries(); - -} - -void historyData::recvA9ServerSlot() -{ - QString recvServer = historyDataSocket->readAll(); - qDebug() << "history recv " << recvServer; - -} - -//画坐标轴 -void historyData::paintXY() -{ - axisX = new QValueAxis; - //设置坐标轴的格式 - - axisX->setRange(0,12); //设置范围 - axisX->setLabelFormat("%d"); //设置刻度的格式 - axisX->setGridLineVisible(true); //网格线可见 - axisX->setTickCount(12); //设置多少格 - axisX->setMinorTickCount(5); //设置每格小刻度线的数目 - chart->addAxis(axisX, Qt::AlignBottom); //为chart设置x轴,并把轴附加到线上 - - axisY = new QValueAxis; - axisY->setRange(0,100); //设置范围 - axisY->setLabelFormat("%d"); //设置刻度的格式 - axisY->setGridLineVisible(true); //网格线可见 - axisY->setTickCount(11); //设置多少格 - axisY->setMinorTickCount(5); //设置每格小刻度线的数目 - chart->addAxis(axisY, Qt::AlignLeft); //为chart设置y轴,并把轴附加到线上 - - //用Qchart在QChartView上面 - ui->canvas->setChart(chart); - ui->canvas->setRenderHint(QPainter::Antialiasing); //抗锯齿 -} - -//画温度的折线统计图 -void historyData::paintTemSeries() -{ - //设置一个pen给线 - QPen TemPen; - TemPen.setWidth(2); - TemPen.setColor(Qt::red); - - //把笔交给线 - TemSeries->setPen(TemPen); - TemSeries->setName("温度"); - - *TemSeries << QPointF(0,24) << QPointF(1,23) << QPointF(2,25) << QPointF(3,27) << QPointF(4,29)<< QPointF(5,29) << QPointF(6,30) << QPointF(7,32) << QPointF(8,35)<< QPointF(9,37) << QPointF(10,35) << QPointF(11,33) << QPointF(12,30); - chart->addSeries(TemSeries); - - //把线绑定到坐标轴上 - TemSeries->attachAxis(axisX); - TemSeries->attachAxis(axisY); -} - -//画湿度的折线统计图 -void historyData::paintHumSeries() -{ - //设置一个pen给线 - QPen HumPen; - HumPen.setWidth(2); - HumPen.setColor(Qt::yellow); - - //把笔交给线 - HumSeries->setPen(HumPen); - HumSeries->setName("湿度"); - - *HumSeries << QPointF(0,65) << QPointF(1,67) << QPointF(2,64) << QPointF(3,64) << QPointF(4,62)<< QPointF(5,60) << QPointF(6,58) << QPointF(7,57) << QPointF(8,57)<< QPointF(9,55) << QPointF(10,56) << QPointF(11,58) << QPointF(12,62); - chart->addSeries(HumSeries); - - //把线绑定到坐标轴上 - HumSeries->attachAxis(axisX); - HumSeries->attachAxis(axisY); -} - -//画光照强度的折线统计图 -void historyData::paintLightSeries() -{ - //设置一个pen给线 - QPen LightPen; - LightPen.setWidth(2); - LightPen.setColor(Qt::green); - - //把笔交给线 - LightSeries->setPen(LightPen); - LightSeries->setName("光照强度"); - - *LightSeries << QPointF(0,48) << QPointF(1,53) << QPointF(2,52) << QPointF(3,51) << QPointF(4,53)<< QPointF(5,50) << QPointF(6,55) << QPointF(7,60) << QPointF(8,68)<< QPointF(9,69) << QPointF(10,75) << QPointF(11,62) << QPointF(12,55); - chart->addSeries(LightSeries); - - //把线绑定到坐标轴上 - LightSeries->attachAxis(axisX); - LightSeries->attachAxis(axisY); -} - -//画烟雾浓度的折线统计图 -void historyData::paintSmokeSeries() -{ - //设置一个pen给线 - QPen SmokePen; - SmokePen.setWidth(2); - SmokePen.setColor(Qt::blue); - - //把笔交给线 - SmokeSeries->setPen(SmokePen); - SmokeSeries->setName("烟雾浓度"); - - *SmokeSeries << QPointF(0,10) << QPointF(3,10) << QPointF(7,10) << QPointF(9,10) << QPointF(12,10); - chart->addSeries(SmokeSeries); - - //把线绑定到坐标轴上 - SmokeSeries->attachAxis(axisX); - SmokeSeries->attachAxis(axisY); - -} diff --git a/historydata.h b/historydata.h deleted file mode 100644 index fccc55b..0000000 --- a/historydata.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef HISTORYDATA_H -#define HISTORYDATA_H - -#include -#include -#include -#include -#include -#include - -QT_CHARTS_USE_NAMESPACE - -namespace Ui { -class historyData; -} - -class historyData : public QWidget -{ - Q_OBJECT - -public: - explicit historyData(QWidget *parent = 0); - ~historyData(); - - //画坐标轴 - void paintXY(); - - //画温度的折线统计图 - void paintTemSeries(); - - //画湿度的折线统计图 - void paintHumSeries(); - - //画光照强度的折线统计图 - void paintLightSeries(); - - //画烟雾浓度的折线统计图 - void paintSmokeSeries(); -signals: - void historyDataToWidgetSignal(); - -private slots: - void on_historyDataReturnBrn_clicked(); - - void on_searchHistoryDataBtn_clicked(); - - void recvA9ServerSlot(); -private: - Ui::historyData *ui; - QTcpSocket * historyDataSocket; - QLineSeries * TemSeries; //创建画温度的线 - QLineSeries * HumSeries; //创建画湿度的线 - QLineSeries * LightSeries; //创建画光照强度的线 - QLineSeries * SmokeSeries; //创建画烟感的线 - QValueAxis * axisX; //X轴 - QValueAxis * axisY; //Y轴 - QChart * chart; -}; - -#endif // HISTORYDATA_H diff --git a/historydata.ui b/historydata.ui deleted file mode 100644 index 24debef..0000000 --- a/historydata.ui +++ /dev/null @@ -1,85 +0,0 @@ - - - historyData - - - - 0 - 0 - 992 - 612 - - - - Form - - - - - 410 - 30 - 171 - 41 - - - - - 华文行楷 - 20 - - - - 历史数据 - - - Qt::AlignCenter - - - - - - 330 - 550 - 111 - 41 - - - - 查询历史数据 - - - - - - 580 - 550 - 111 - 41 - - - - 返回 - - - - - - 19 - 79 - 951 - 451 - - - - - - - QChartView - QWidget -
qchartview.h
- 1 -
-
- - -
diff --git a/img/OIP-C.jpg b/img/OIP-C.jpg new file mode 100644 index 0000000..dd06c1b Binary files /dev/null and b/img/OIP-C.jpg differ diff --git a/img/OIP-C1.jpg b/img/OIP-C1.jpg new file mode 100644 index 0000000..a30f47c Binary files /dev/null and b/img/OIP-C1.jpg differ diff --git a/img/OIP-C2.jpg b/img/OIP-C2.jpg new file mode 100644 index 0000000..a7eb4f0 Binary files /dev/null and b/img/OIP-C2.jpg differ diff --git a/img/OIP-C3.jpg b/img/OIP-C3.jpg new file mode 100644 index 0000000..410ba7a Binary files /dev/null and b/img/OIP-C3.jpg differ diff --git a/img/R-C.jpg b/img/R-C.jpg new file mode 100644 index 0000000..7f04cf6 Binary files /dev/null and b/img/R-C.jpg differ diff --git a/img/hide.png b/img/hide.png new file mode 100644 index 0000000..6a0eac0 Binary files /dev/null and b/img/hide.png differ diff --git a/img/ico.png b/img/ico.png new file mode 100644 index 0000000..065c1ff Binary files /dev/null and b/img/ico.png differ diff --git a/img/img.qrc b/img/img.qrc new file mode 100644 index 0000000..2a09599 --- /dev/null +++ b/img/img.qrc @@ -0,0 +1,13 @@ + + + hide.png + ico.png + img.qrc + OIP-C.jpg + OIP-C1.jpg + OIP-C2.jpg + OIP-C3.jpg + R-C.jpg + show.png + + diff --git a/img/show.png b/img/show.png new file mode 100644 index 0000000..3bce2cf Binary files /dev/null and b/img/show.png differ diff --git a/lightpage.cpp b/lightpage.cpp deleted file mode 100644 index b5ce3c8..0000000 --- a/lightpage.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "lightpage.h" -#include "ui_lightpage.h" - -lightPage::lightPage(QWidget *parent) : - QWidget(parent), - ui(new Ui::lightPage) -{ - ui->setupUi(this); - - -} - -lightPage::~lightPage() -{ - delete ui; -} - -void lightPage::on_livingLightONOFFBtn_clicked() -{ - -} - -void lightPage::on_bedroomLightONOFFBtn_clicked() -{ - -} diff --git a/lightpage.h b/lightpage.h deleted file mode 100644 index 6811264..0000000 --- a/lightpage.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef LIGHTPAGE_H -#define LIGHTPAGE_H - -#include -#include - -namespace Ui { -class lightPage; -} - -class lightPage : public QWidget -{ - Q_OBJECT - -public: - explicit lightPage(QWidget *parent = 0); - ~lightPage(); - -private slots: - void on_livingLightONOFFBtn_clicked(); - - void on_bedroomLightONOFFBtn_clicked(); - -private: - Ui::lightPage *ui; - QPixmap lightONPix; - QPixmap lightOFFPix; -}; - -#endif // LIGHTPAGE_H diff --git a/lightpage.ui b/lightpage.ui deleted file mode 100644 index 3e98cca..0000000 --- a/lightpage.ui +++ /dev/null @@ -1,89 +0,0 @@ - - - lightPage - - - - 0 - 0 - 342 - 441 - - - - Form - - - - - 10 - 10 - 321 - 421 - - - - - - - - - - 200 - 280 - 101 - 61 - - - - - - - - - - 40 - 280 - 121 - 61 - - - - 卧室灯 ON - - - - - - 40 - 90 - 121 - 71 - - - - 客厅灯 ON - - - - - - 200 - 90 - 101 - 61 - - - - - - - lightPageLabel - bedroomLightONOFFBtn - bedroomLightONOFFPictureLabel - livingLightONOFFPictureLabel - livingLightONOFFBtn - - - - diff --git a/main.cpp b/main.cpp index 90b6d53..05ace16 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,11 @@ -#include "widget.h" +#include "mainmenu.h" + #include int main(int argc, char *argv[]) { QApplication a(argc, argv); - Widget w; + MainMenu w; w.show(); - return a.exec(); } diff --git a/mainmenu.cpp b/mainmenu.cpp new file mode 100644 index 0000000..15bce7c --- /dev/null +++ b/mainmenu.cpp @@ -0,0 +1,121 @@ +#include "mainmenu.h" +#include "ui_mainmenu.h" + +MainMenu::MainMenu(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainMenu) +{ + ui->setupUi(this); + + ui->lineEdit_2->setText("admin"); + ui->lineEdit->setText("123456"); + ui->lineEdit->setEchoMode(QLineEdit::Password); + this->setWindowIcon(QIcon(":/ico.png")); + this->setWindowTitle("快乐不起来啊"); + + this->setAutoFillBackground(true); + QPalette palette; + QPixmap pixmap(":/OIP-C3.jpg"); + palette.setBrush(QPalette::Window, QBrush(pixmap)); + this->setPalette(palette); +} + +MainMenu::~MainMenu() +{ + delete ui; +} + + +void MainMenu::on_pushButton_clicked() +{ + tcpSocket = new QTcpSocket; + QString ip = ui->lineEdit_3->text(); + tcpSocket->connectToHost(ip,7777); + + + + connect(tcpSocket, SIGNAL(connected()), this, SLOT(show_connected())); + connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(show_disconnected())); +} + +void MainMenu::on_checkBox_stateChanged(int arg1) +{ + if(arg1) + { + ui->lineEdit->setEchoMode(QLineEdit::Normal); + } + else if (!arg1) + { + ui->lineEdit->setEchoMode(QLineEdit::Password); + } + else { + qDebug("err: ui->lineEdit->setEchoMode(QLineEdit::Password);"); + return; + } + return ; +} +void MainMenu::show_connected() +{ + int ret = QMessageBox::information(this, tr("👨‍👩‍👦‍👦 登录成功"),tr("点击取消退出连接"), + QMessageBox::Ok, + QMessageBox::Cancel); + if(ret == QMessageBox::Cancel) + { + // tcpSocket->disconnected(); + delete tcpSocket; + return; + } + else { + + + //跳转到子界面 + SubWindow = new submenu; + connect(SubWindow,SIGNAL(widget_close()),this,SLOT(subWindowClosed() )); + SubWindow->show(); + this->hide(); +// this->close(); + } + +} +void MainMenu::show_disconnected() +{ + if(SubWindow!=NULL) + { + SubWindow->close(); + } + int ret = QMessageBox::information(this, tr("👨‍👩‍👦‍👦 连接断开"),tr("是否重新连接?"), + QMessageBox::Yes,QMessageBox::No,QMessageBox::Cancel); + if(ret == QMessageBox::Cancel) + { + return; + } + if(ret == QMessageBox::No) + { + // 退出处理? + // if(tcpSocket) + // { + // delete tcpSocket; + // } + // Sleep(20); + return; + } + else if(ret == QMessageBox::Yes) + { + ui->pushButton->click(); + } + else{ + qDebug("error:---"); + return ; + } +} +void MainMenu::Sleep(int msec) +{ + QTime dieTime = QTime::currentTime().addMSecs(msec); + while( QTime::currentTime() < dieTime ) + QCoreApplication::processEvents(QEventLoop::AllEvents, 100); +} +void MainMenu::subWindowClosed() +{ + show(); + tcpSocket->close(); +} diff --git a/mainmenu.h b/mainmenu.h new file mode 100644 index 0000000..3422c82 --- /dev/null +++ b/mainmenu.h @@ -0,0 +1,39 @@ +#ifndef MAINMENU_H +#define MAINMENU_H + +#include +#include +#include +#include // +#include //地址格式 +#include +#include + +#include "submenu.h" + +QT_BEGIN_NAMESPACE +namespace Ui { class MainMenu; } +QT_END_NAMESPACE + +class MainMenu : public QMainWindow +{ + Q_OBJECT + +public: + MainMenu(QWidget *parent = nullptr); + ~MainMenu(); + +private slots: + void on_pushButton_clicked(); + void on_checkBox_stateChanged(int arg1); + void show_connected(); + void show_disconnected(); + void Sleep(int msec); + void subWindowClosed(); + +private: + QTcpSocket * tcpSocket; + submenu *SubWindow = NULL; + Ui::MainMenu *ui; +}; +#endif // MAINMENU_H diff --git a/mainmenu.ui b/mainmenu.ui new file mode 100644 index 0000000..c5ae651 --- /dev/null +++ b/mainmenu.ui @@ -0,0 +1,163 @@ + + + MainMenu + + + + 0 + 0 + 800 + 600 + + + + MainMenu + + + + + + + Qt::Vertical + + + + 20 + 205 + + + + + + + + Qt::Horizontal + + + + 254 + 20 + + + + + + + + + + + + + + Lable {backgrond-color:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(0, 0, 0, 255), stop:0.19397 rgba(0, 0, 0, 255), stop:0.202312 rgba(122, 97, 0, 255), stop:0.495514 rgba(76, 58, 0, 255), stop:0.504819 rgba(255, 255, 255, 255), stop:0.79 rgba(255, 255, 255, 255), stop:1 rgba(255, 158, 158, 255))} + + + 账户: + + + + + + + 密码: + + + + + + + IP: + + + + + + + + + + + + + + + + + 172.27.128.1 + + + + + + + + + + + + + + + + 显示密码 + + + + + + + QPushButton{ color : red; } + + + 登录 + + + + + + + + + + + Qt::Horizontal + + + + 254 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 205 + + + + + + + + + + 0 + 0 + 800 + 23 + + + + + + + + diff --git a/picture.qrc b/picture.qrc deleted file mode 100644 index c841ded..0000000 --- a/picture.qrc +++ /dev/null @@ -1,14 +0,0 @@ - - - picture/light.png - picture/temperatureSymbol.png - picture/airconditioner.png - picture/camera.png - picture/humiditySymbol.png - picture/traycon.png - picture/lightON.png - picture/lightOFF.png - picture/airconditionerOFF.png - picture/airconditionerON.png - - diff --git a/picture/airconditioner.png b/picture/airconditioner.png deleted file mode 100644 index 0aea10f..0000000 Binary files a/picture/airconditioner.png and /dev/null differ diff --git a/picture/airconditionerOFF.png b/picture/airconditionerOFF.png deleted file mode 100644 index 8cfd0a2..0000000 Binary files a/picture/airconditionerOFF.png and /dev/null differ diff --git a/picture/airconditionerON.png b/picture/airconditionerON.png deleted file mode 100644 index bcca401..0000000 Binary files a/picture/airconditionerON.png and /dev/null differ diff --git a/picture/camera.png b/picture/camera.png deleted file mode 100644 index 3aaa614..0000000 Binary files a/picture/camera.png and /dev/null differ diff --git a/picture/humiditySymbol.png b/picture/humiditySymbol.png deleted file mode 100644 index e6b68be..0000000 Binary files a/picture/humiditySymbol.png and /dev/null differ diff --git a/picture/light.png b/picture/light.png deleted file mode 100644 index 3d8cadb..0000000 Binary files a/picture/light.png and /dev/null differ diff --git a/picture/lightOFF.png b/picture/lightOFF.png deleted file mode 100644 index 1d5e2dc..0000000 Binary files a/picture/lightOFF.png and /dev/null differ diff --git a/picture/lightON.png b/picture/lightON.png deleted file mode 100644 index f144dff..0000000 Binary files a/picture/lightON.png and /dev/null differ diff --git a/picture/temperatureSymbol.png b/picture/temperatureSymbol.png deleted file mode 100644 index fc72ccc..0000000 Binary files a/picture/temperatureSymbol.png and /dev/null differ diff --git a/picture/traycon.png b/picture/traycon.png deleted file mode 100644 index 36a7632..0000000 Binary files a/picture/traycon.png and /dev/null differ diff --git a/setsecurevalue.cpp b/setsecurevalue.cpp deleted file mode 100644 index f82013f..0000000 --- a/setsecurevalue.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "setsecurevalue.h" -#include "ui_setsecurevalue.h" - -#include -#include - -setSecureValue::setSecureValue(QWidget *parent) : - QWidget(parent), - ui(new Ui::setSecureValue) -{ - ui->setupUi(this); - - //设置窗口标题 - this->setWindowTitle("设置安全阈值"); - - //创建套接字,和A9服务器取得连接 - setValueSocket = new QTcpSocket(this); - setValueSocket->connectToHost("192.168.200.105", 7777); - connect(setValueSocket,SIGNAL(readyRead()),this,SLOT(recvServerDataSlot())); -} - -setSecureValue::~setSecureValue() -{ - delete ui; - setValueSocket->close(); - setValueSocket = NULL; -} - -void setSecureValue::on_setSecureValueReturnBtn_clicked() -{ - emit setSecureValueToWidgetSignal(); -} - -void setSecureValue::on_setSecureValueSubmitBtn_clicked() -{ - QString cmd = "//"; - QString MessageBuf = "SetSecureValue:"; - MessageBuf.append(ui->temMinComboBox->currentText()); - MessageBuf.append(cmd); - MessageBuf.append(ui->temMaxComboBox->currentText()); - MessageBuf.append(cmd); - MessageBuf.append(ui->humMinComboBox->currentText()); - MessageBuf.append(cmd); - MessageBuf.append(ui->humMaxComboBox->currentText()); - MessageBuf.append(cmd); - MessageBuf.append(ui->lightIntensityMinComboBox->currentText()); - MessageBuf.append(cmd); - MessageBuf.append(ui->lightIntensityMaxComboBox->currentText()); - MessageBuf.append(cmd); - MessageBuf.append(ui->smokeconcentrationMinComboBox->currentText()); - MessageBuf.append(cmd); - MessageBuf.append(ui->smokeconcentrationMaxComboBox->currentText()); - - QByteArray arr, recv; - arr.append(MessageBuf); - qDebug() << arr; - if(this->setValueSocket->write(arr) == -1) - { - int ret = QMessageBox::question(this, "提交失败", "你提交的数据并没有上传到服务器!!!", QMessageBox::Yes); - if(ret == QMessageBox::Yes) - { - emit setSecureValueToWidgetSignal(); - } - } - else - { - int ret = QMessageBox::question(this, "提交成功", "恭喜你成功提交数据到服务器!!!", QMessageBox::Yes); - if(ret == QMessageBox::Yes) - { - emit setSecureValueToWidgetSignal(); - } - } -} - -//接收来自服务器的信息 -void setSecureValue::recvServerDataSlot() -{ - int i = 0; - QByteArray arr = setValueSocket->readAll(); - for(i = 0; i < 11; i++) - { - qDebug() << "arr[i] = " << (int)arr[i]; - } - //qDebug() << "setvalue recv = " << arr; -} diff --git a/setsecurevalue.h b/setsecurevalue.h deleted file mode 100644 index 2917fd3..0000000 --- a/setsecurevalue.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef SETSECUREVALUE_H -#define SETSECUREVALUE_H - -#include -#include - -namespace Ui { -class setSecureValue; -} - -class setSecureValue : public QWidget -{ - Q_OBJECT - -public: - explicit setSecureValue(QWidget *parent = 0); - ~setSecureValue(); - -signals: - void setSecureValueToWidgetSignal(); - -private slots: - void on_setSecureValueReturnBtn_clicked(); - - void on_setSecureValueSubmitBtn_clicked(); - void recvServerDataSlot(); - -private: - Ui::setSecureValue *ui; - QTcpSocket * setValueSocket; -}; - -#endif // SETSECUREVALUE_H diff --git a/setsecurevalue.ui b/setsecurevalue.ui deleted file mode 100644 index 7f6cf56..0000000 --- a/setsecurevalue.ui +++ /dev/null @@ -1,1285 +0,0 @@ - - - setSecureValue - - - - 0 - 0 - 670 - 478 - - - - Form - - - - - 230 - 20 - 211 - 41 - - - - - 华文行楷 - 20 - - - - 设置安全阈值 - - - Qt::AlignCenter - - - - - - 30 - 80 - 51 - 31 - - - - - 华文行楷 - 16 - - - - color: rgb(255, 0, 0); - - - 温度 - - - - - - 170 - 120 - 87 - 22 - - - - - 18 - - - - - 19 - - - - - 20 - - - - - 21 - - - - - 22 - - - - - 23 - - - - - 24 - - - - - 25 - - - - - 26 - - - - - 27 - - - - - 28 - - - - - 29 - - - - - 30 - - - - - 31 - - - - - 32 - - - - - 33 - - - - - 34 - - - - - 35 - - - - - 36 - - - - - 37 - - - - - 38 - - - - - 39 - - - - - 40 - - - - - - - 90 - 120 - 72 - 21 - - - - 最小值: - - - - - - 90 - 170 - 72 - 15 - - - - 最大值: - - - - - - 170 - 170 - 87 - 22 - - - - - 18 - - - - - 19 - - - - - 20 - - - - - 21 - - - - - 22 - - - - - 23 - - - - - 24 - - - - - 25 - - - - - 26 - - - - - 27 - - - - - 28 - - - - - 29 - - - - - 30 - - - - - 31 - - - - - 32 - - - - - 33 - - - - - 34 - - - - - 35 - - - - - 36 - - - - - 37 - - - - - 38 - - - - - 39 - - - - - 40 - - - - - - - 440 - 170 - 72 - 15 - - - - 最大值: - - - - - - 440 - 120 - 72 - 21 - - - - 最小值: - - - - - - 380 - 80 - 51 - 31 - - - - - 华文行楷 - 16 - - - - color: rgb(255, 0, 0); - - - 湿度 - - - - - - 520 - 120 - 87 - 22 - - - - - 18 - - - - - 19 - - - - - 20 - - - - - 21 - - - - - 22 - - - - - 23 - - - - - 24 - - - - - 25 - - - - - 26 - - - - - 27 - - - - - 28 - - - - - 29 - - - - - 30 - - - - - 31 - - - - - 32 - - - - - 33 - - - - - 34 - - - - - 35 - - - - - 36 - - - - - 37 - - - - - 38 - - - - - 39 - - - - - 40 - - - - - - - 520 - 170 - 87 - 22 - - - - - 18 - - - - - 19 - - - - - 20 - - - - - 21 - - - - - 22 - - - - - 23 - - - - - 24 - - - - - 25 - - - - - 26 - - - - - 27 - - - - - 28 - - - - - 29 - - - - - 30 - - - - - 31 - - - - - 32 - - - - - 33 - - - - - 34 - - - - - 35 - - - - - 36 - - - - - 37 - - - - - 38 - - - - - 39 - - - - - 40 - - - - - - - 10 - 210 - 651 - 20 - - - - Qt::Horizontal - - - - - - 320 - 80 - 16 - 301 - - - - Qt::Vertical - - - - - - 90 - 340 - 72 - 15 - - - - 最大值: - - - - - - 90 - 290 - 72 - 21 - - - - 最小值: - - - - - - 30 - 250 - 121 - 31 - - - - - 华文行楷 - 16 - - - - color: rgb(255, 0, 0); - - - 光照强度 - - - - - - 170 - 290 - 87 - 22 - - - - - 18 - - - - - 19 - - - - - 20 - - - - - 21 - - - - - 22 - - - - - 23 - - - - - 24 - - - - - 25 - - - - - 26 - - - - - 27 - - - - - 28 - - - - - 29 - - - - - 30 - - - - - 31 - - - - - 32 - - - - - 33 - - - - - 34 - - - - - 35 - - - - - 36 - - - - - 37 - - - - - 38 - - - - - 39 - - - - - 40 - - - - - - - 170 - 340 - 87 - 22 - - - - - 18 - - - - - 19 - - - - - 20 - - - - - 21 - - - - - 22 - - - - - 23 - - - - - 24 - - - - - 25 - - - - - 26 - - - - - 27 - - - - - 28 - - - - - 29 - - - - - 30 - - - - - 31 - - - - - 32 - - - - - 33 - - - - - 34 - - - - - 35 - - - - - 36 - - - - - 37 - - - - - 38 - - - - - 39 - - - - - 40 - - - - - - - 420 - 340 - 72 - 15 - - - - 最大值: - - - - - - 360 - 250 - 121 - 31 - - - - - 华文行楷 - 16 - - - - color: rgb(255, 0, 0); - - - 烟雾浓度 - - - - - - 420 - 290 - 72 - 21 - - - - 最小值: - - - - - - 500 - 340 - 87 - 22 - - - - - 18 - - - - - 19 - - - - - 20 - - - - - 21 - - - - - 22 - - - - - 23 - - - - - 24 - - - - - 25 - - - - - 26 - - - - - 27 - - - - - 28 - - - - - 29 - - - - - 30 - - - - - 31 - - - - - 32 - - - - - 33 - - - - - 34 - - - - - 35 - - - - - 36 - - - - - 37 - - - - - 38 - - - - - 39 - - - - - 40 - - - - - - - 500 - 290 - 87 - 22 - - - - - 18 - - - - - 19 - - - - - 20 - - - - - 21 - - - - - 22 - - - - - 23 - - - - - 24 - - - - - 25 - - - - - 26 - - - - - 27 - - - - - 28 - - - - - 29 - - - - - 30 - - - - - 31 - - - - - 32 - - - - - 33 - - - - - 34 - - - - - 35 - - - - - 36 - - - - - 37 - - - - - 38 - - - - - 39 - - - - - 40 - - - - - - - 210 - 420 - 93 - 41 - - - - 提交 - - - - - - 350 - 420 - 93 - 41 - - - - 返回 - - - - - - diff --git a/smart_home.pro b/smart_home.pro deleted file mode 100644 index cdebd60..0000000 --- a/smart_home.pro +++ /dev/null @@ -1,44 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2018-08-27T13:31:18 -# -#------------------------------------------------- - -QT += core gui charts -QT += core gui network - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -TARGET = smart_home -TEMPLATE = app - -# The following define makes your compiler emit warnings if you use -# any feature of Qt which has been marked as deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - - -SOURCES += \ - main.cpp \ - widget.cpp \ - historydata.cpp \ - setsecurevalue.cpp - -HEADERS += \ - widget.h \ - historydata.h \ - setsecurevalue.h - -FORMS += \ - widget.ui \ - historydata.ui \ - setsecurevalue.ui - -RESOURCES += \ - picture.qrc diff --git a/smart_home.pro.user b/smart_home.pro.user deleted file mode 100644 index 7df78f1..0000000 --- a/smart_home.pro.user +++ /dev/null @@ -1,319 +0,0 @@ - - - - - - EnvironmentId - {24b86c58-28ab-4639-a69a-e65d01fa8313} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - -fno-delayed-template-parsing - - true - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.14.2 MinGW 32-bit - Desktop Qt 5.14.2 MinGW 32-bit - qt.qt5.5142.win32_mingw73_kit - 0 - 0 - 0 - - C:/Users/sn70315/Desktop/smart_home-master/build-smart_home-Desktop_Qt_5_14_2_MinGW_32_bit-Debug - - - true - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - C:/Users/sn70315/Desktop/smart_home-master/build-smart_home-Desktop_Qt_5_14_2_MinGW_32_bit-Release - - - true - QtProjectManager.QMakeBuildStep - false - - false - false - true - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - - - C:/Users/sn70315/Desktop/smart_home-master/build-smart_home-Desktop_Qt_5_14_2_MinGW_32_bit-Profile - - - true - QtProjectManager.QMakeBuildStep - true - - false - true - true - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:C:/Users/sn70315/Desktop/smart_home-master/smart_home_client/smart_home.pro - C:/Users/sn70315/Desktop/smart_home-master/smart_home_client/smart_home.pro - - false - - false - true - true - false - false - true - - C:/Users/sn70315/Desktop/smart_home-master/build-smart_home-Desktop_Qt_5_14_2_MinGW_32_bit-Debug - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/smart_home.pro.user.2bdcebe b/smart_home.pro.user.2bdcebe deleted file mode 100644 index 2ac75a5..0000000 --- a/smart_home.pro.user.2bdcebe +++ /dev/null @@ -1,318 +0,0 @@ - - - - - - EnvironmentId - {2bdcebe0-b828-44ab-aa41-e9b54419a45b} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.10.1 MinGW 32bit - Desktop Qt 5.10.1 MinGW 32bit - qt.qt5.5101.win32_mingw53_kit - 0 - 0 - 0 - - C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - 构建 - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - 清理 - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - 构建 - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - 清理 - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - 构建 - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - 清理 - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - 部署 - - ProjectExplorer.BuildSteps.Deploy - - 1 - 在本地部署 - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - smart_home - - Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Administrator/Desktop/1/smart_home.pro - true - - smart_home.pro - false - - C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Debug - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - diff --git a/smart_home.pro.user.2bdcebe.4.8-pre1 b/smart_home.pro.user.2bdcebe.4.8-pre1 deleted file mode 100644 index 90826d1..0000000 --- a/smart_home.pro.user.2bdcebe.4.8-pre1 +++ /dev/null @@ -1,318 +0,0 @@ - - - - - - EnvironmentId - {2bdcebe0-b828-44ab-aa41-e9b54419a45b} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.10.1 MinGW 32bit - Desktop Qt 5.10.1 MinGW 32bit - qt.qt5.5101.win32_mingw53_kit - 0 - 0 - 0 - - C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - 构建 - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - 清理 - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - 构建 - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - 清理 - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - 构建 - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - 清理 - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - 部署 - - ProjectExplorer.BuildSteps.Deploy - - 1 - 在本地部署 - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - smart_home - smart_home2 - Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Administrator/Desktop/smart_home/smart_home.pro - true - - smart_home.pro - false - - C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Debug - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - diff --git a/smart_home.pro.user.2fa79d3 b/smart_home.pro.user.2fa79d3 deleted file mode 100644 index be3f9b5..0000000 --- a/smart_home.pro.user.2fa79d3 +++ /dev/null @@ -1,318 +0,0 @@ - - - - - - EnvironmentId - {2fa79d37-8b3a-405c-bcf3-08028e95e509} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.11.1 MinGW 32bit - Desktop Qt 5.11.1 MinGW 32bit - qt.qt5.5111.win32_mingw53_kit - 0 - 0 - 0 - - D:/ubuntuTest/courseDesign/build-smart_home-Desktop_Qt_5_11_1_MinGW_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - D:/ubuntuTest/courseDesign/build-smart_home-Desktop_Qt_5_11_1_MinGW_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - true - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - D:/ubuntuTest/courseDesign/build-smart_home-Desktop_Qt_5_11_1_MinGW_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - true - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - 部署 - - ProjectExplorer.BuildSteps.Deploy - - 1 - 部署设置 - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - smart_home - - Qt4ProjectManager.Qt4RunConfiguration:D:/ubuntuTest/courseDesign/smart_home/smart_home.pro - true - - smart_home.pro - false - - D:/ubuntuTest/courseDesign/build-smart_home-Desktop_Qt_5_11_1_MinGW_32bit-Debug - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - diff --git a/sql.cpp b/sql.cpp new file mode 100644 index 0000000..2935ccf --- /dev/null +++ b/sql.cpp @@ -0,0 +1,99 @@ +#include "sql.h" + +sql::sql() +{ + //创建数据库 + QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); //添加驱动 + db.setDatabaseName("SmartGreenhouse.db"); //设置库名 + bool ok = db.open(); + if(!ok){ + qDebug("open failed"); + return ; + } + else { + qDebug()<<"open success"; + } + + //通过db创建表 + //db.exec("create table usr (name text, passwd text); "); + + + //通过query创建表 + QSqlQuery query; + ok = query.exec("create table if not exists user (id text, name text);"); + if(!ok){ + qDebug("failed to create user table"); + } + else { + // qDebug()<<"create table success"; + qDebug()<<"Student table created successfully"; + } + ok = query.exec("create table if not exists Data (temp text, hum text,light text,co2 text);"); + if(!ok){ + qDebug("failed to create Data table"); + } + else { + qDebug()<<"Data table created successfully"; + } + + + //插入数据库 + + /*QString id = ui->lineEdit->text(); + QString name = ui->lineEdit_2->text(); + + + QString sql = QString("insert into stu values ('%1','%2')").arg(id).arg(name); + + qDebug()<<"sql:"<lineEdit->text(); + + QString sql = QString("delete from stu where id='%1'").arg(id); + + qDebug()<<"sql:"< +//#include +#include +#include +#include +class sql +{ +public: + sql(); +}; + +#endif // SQL_H diff --git a/submenu.cpp b/submenu.cpp new file mode 100644 index 0000000..ad39428 --- /dev/null +++ b/submenu.cpp @@ -0,0 +1,92 @@ +#include "submenu.h" +#include "ui_submenu.h" + +submenu::submenu(QWidget *parent) : + QWidget(parent), + ui(new Ui::submenu) +{ + ui->setupUi(this); + this->setWindowIcon(QIcon(":/ico.png")); + this->setWindowTitle("风中有朵雨做的云"); + + /* 喷头状态 灯状态 风扇状态 温度值,湿度值,光照--勒克斯(Lux或Lx),被光均匀照射的物体,在1平方米面积上所得的光通量是1流明时,它的照度是1勒克斯 +fan 风扇 opf打开风扇 off关闭风扇 +led1 灯1 opl1打开灯1 ofl1关闭灯1 +led2 灯2 opl2打开灯2 ofl2 关闭灯2 +buzzer蜂鸣器 temp温度超过阈值 hum湿度超过阈值 light光照超过阈值 smoke烟雾浓度超过阈值 +rfid模块 +A9发命令到m0 +0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 +tag Id len date crc + 对齐 fan led1 led2 buzzer rfid 对齐 + opf off opl1 ofl1 opl2 ofl2 temp hum light smoke +dd 4 24 4 1 0 1 0 1 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + + + +表 2 +环境数据包 +0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 +tag id len date crc + 对齐 tem hum adc light smoke state rfid 对齐 + 1 h 1 h ch0 ch1 led fan buzz led2 +bb 4 24 4 0 20 0 23 1f 0 0 0 23 0 0 0 70 0 0 0 80 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 + +*/ + + + + + + + + + + + ui->stackedWidget->setCurrentWidget(ui->lightPage); + ui->lightBtn->setEnabled(false); + + +} + +submenu::~submenu() +{ + delete ui; +} + +void submenu::on_quitBtn_clicked() +{ + this->hide(); + emit widget_close(); + this->close(); +} + +void submenu::on_lightBtn_clicked() +{ + ui->stackedWidget->setCurrentWidget(ui->lightPage); + + //按下灯光按钮后让灯光按钮变成不可选状态,喷淋和风扇按钮变为可选状态 + ui->lightBtn->setEnabled(false); + ui->sprayBtn->setEnabled(true); + ui->fanBtn->setEnabled(true); +} + +void submenu::on_fanBtn_clicked() +{ + ui->stackedWidget->setCurrentWidget(ui->fanPage); + + //按下空调按钮后让风扇按钮变成不可选状态,灯光按钮和喷淋按钮变为可选状态 + ui->fanBtn->setEnabled(false); + ui->lightBtn->setEnabled(true); + ui->sprayBtn->setEnabled(true); +} + +void submenu::on_sprayBtn_clicked() +{ + ui->stackedWidget->setCurrentWidget(ui->sprayPage); + + //按下空调按钮后让喷淋按钮变成不可选状态,灯光按钮和风扇按钮变为可选状态 + ui->fanBtn->setEnabled(true); + ui->lightBtn->setEnabled(true); + ui->sprayBtn->setEnabled(false); +} diff --git a/submenu.h b/submenu.h new file mode 100644 index 0000000..3e346f0 --- /dev/null +++ b/submenu.h @@ -0,0 +1,35 @@ +#ifndef SUBMENU_H +#define SUBMENU_H + +#include + +namespace Ui { +class submenu; +} + +class submenu : public QWidget +{ + Q_OBJECT + +public: + explicit submenu(QWidget *parent = nullptr); + ~submenu(); + +private slots: + + void on_quitBtn_clicked(); + + void on_lightBtn_clicked(); + + void on_fanBtn_clicked(); + + void on_sprayBtn_clicked(); + +private: + Ui::submenu *ui; +signals: + void widget_close(void); + +}; + +#endif // SUBMENU_H diff --git a/widget.ui b/submenu.ui similarity index 68% rename from widget.ui rename to submenu.ui index bc9b300..94f6343 100644 --- a/widget.ui +++ b/submenu.ui @@ -1,140 +1,191 @@ - Widget - + submenu + 0 0 - 721 - 622 + 872 + 627 - - Widget + + + 872 + 627 + + + + 872 + 627 + + + + Form + + + background-color:rgb(170, 160, 84) + + + + + 760 + 590 + 75 + 23 + + + + 退出 + + - 10 + 30 90 - 701 - 461 + 811 + 491 - - background-color: rgba(255, 255, 255, 20); - - - + - 30 - 110 - 91 - 81 + 300 + 30 + 281 + 31 + + + 华文行楷 + 20 + + - + color:rgb(0, 85, 0); - + 科技改变未来 + + + Qt::AlignCenter - 30 - 210 - 93 - 41 + 80 + 180 + 51 + 21 - 灯光 + LED - + 140 - 110 - 91 - 81 - - - - - - - - - - 140 - 210 - 93 - 41 + 180 + 51 + 21 - 空调 + 风扇 - + - 250 - 210 - 93 - 41 + 200 + 180 + 51 + 21 - 摄像头 + 喷淋 - + - 250 - 110 - 91 - 81 + 80 + 360 + 121 + 31 + + + 华文行楷 + 14 + + - + 光照强度: - + - 20 - 100 - 331 - 161 + 80 + 310 + 121 + 31 + + + 华文行楷 + 14 + + - + 湿 度: + + + + + + 80 + 260 + 121 + 31 + + + + + 华文行楷 + 14 + + + + 温 度: - 350 - 100 + 430 + 110 20 441 @@ -146,8 +197,8 @@ - 20 - 260 + 80 + 230 321 16 @@ -156,94 +207,12 @@ Qt::Horizontal - - - - 170 - 330 - 101 - 31 - - - - - 华文行楷 - - - - - - - - - - 160 - 390 - 101 - 31 - - - - - 华文行楷 - - - - - - - - - - 280 - 280 - 61 - 31 - - - - - - - - - - 280 - 330 - 61 - 31 - - - - - - - - - - 280 - 390 - 61 - 31 - - - - - 10 - 75 - true - - - - Lux/lx - - - 20 - 450 - 331 + 80 + 420 + 321 16 @@ -251,50 +220,50 @@ Qt::Horizontal + + + + 290 + 490 + 81 + 31 + + + + 设置阈值 + + - 40 - 470 - 121 - 61 + 100 + 490 + 61 + 31 历史数据 - - - - 220 - 470 - 121 - 61 - - - - 设置安全阈值 - - - 370 - 100 + 470 + 110 331 441 - 1 + 0 - + - 190 - 150 + 180 + 160 101 61 @@ -303,24 +272,24 @@ - + - 30 - 150 - 121 - 71 + 40 + 170 + 91 + 41 - 客厅灯 ON + 光照灯 ON - + - 190 - 350 + 180 + 280 101 61 @@ -329,17 +298,17 @@ - + - 30 - 350 - 121 - 61 + 40 + 290 + 91 + 41 - 卧室灯 ON + 温控灯 ON @@ -368,8 +337,8 @@ - - + + 130 @@ -388,13 +357,13 @@ color: rgb(0, 85, 255); - 空调 + 风扇 Qt::AlignCenter - + 100 @@ -404,10 +373,10 @@ - 空调 ON + 风扇 ON - + 100 @@ -421,13 +390,39 @@ - - + + - 130 - 10 - 72 + 110 + 210 + 131 + 81 + + + + + + + + + + 110 + 350 + 131 + 61 + + + + 喷洒装置 ON + + + + + + 131 + 50 + 81 31 @@ -441,140 +436,19 @@ color: rgb(0, 85, 255); - 摄像头 + 喷洒装置 Qt::AlignCenter - - - - 0 - 40 - 331 - 401 - - - - - - - - - - 30 - 380 - 93 - 31 - - - - 开始 - - - - - - 220 - 380 - 93 - 31 - - - - 暂停 - - - - - - 220 - 20 - 281 - 31 - - - - - 华文行楷 - 20 - - - - color: rgb(255, 0, 0); - - - 智能家居控制平台 - - - Qt::AlignCenter - - - - - - 30 - 280 - 121 - 31 - - - - - 华文行楷 - 14 - - - - 温 度: - - - - - - 30 - 330 - 121 - 31 - - - - - 华文行楷 - 14 - - - - 湿 度: - - - - - - 30 - 390 - 121 - 31 - - - - - 华文行楷 - 14 - - - - 光照强度: - - - 170 - 280 + 190 + 260 101 31 @@ -583,32 +457,110 @@ - switchPictureLabel + + + + 190 + 310 + 101 + 31 + + + + + 华文行楷 + + + + + + + + + + 190 + 360 + 101 + 31 + + + + + 华文行楷 + + + + + + + + + + 310 + 360 + 61 + 31 + + + + + 10 + 75 + true + + + + Lux/lx + + + + + + 310 + 310 + 61 + 31 + + + + 0% + + + + + + 310 + 260 + 61 + 31 + + + + ℃ + + listView - lightPictureLabel + quitBtn + label_1 lightBtn - airconditionPicyureLabel - airconditionBtn - cameraBtn - cameraPictureLabel + fanBtn + sprayBtn + lightIntensityLabel + humidityLabel + temperationLabel line line_2 + line_3 + setSecureValueBtn + historyDataBtn + stackedWidget + TemDisplayLabel humidityDisplayLabel lightIntensityDisplayLabel - temperationSymbolLabel - humiditySymbolLabel lightIntensitySymbolLabel - line_3 - historyDataBtn - setSecureValueBtn - stackedWidget - label_2 - temperationLabel - humidityLabel - lightIntensityLabel - TemDisplayLabel + humiditySymbolLabel + temperationSymbolLabel - diff --git a/widget.cpp b/widget.cpp deleted file mode 100644 index fe28850..0000000 --- a/widget.cpp +++ /dev/null @@ -1,480 +0,0 @@ -#include "widget.h" -#include "ui_widget.h" - -#include -#include -#include -#include - -Widget::Widget(QWidget *parent) : - QWidget(parent), - ui(new Ui::Widget) -{ - ui->setupUi(this); - - //窗口名字 - this->setWindowTitle("智能家居控制平台"); - - //开关窗口背景 - - - //设置托盘 - setWindowIcon(QIcon(":/picture/traycon.png")); - trayIcon = new QSystemTrayIcon(QIcon(":/picture/traycon.png"), this); - - //设置系统托盘图标 - trayIcon->setToolTip("智能家居控制平台"); - QMenu * menu = new QMenu; - menu->addAction(tr("退出"), qApp, SLOT(quit())); - trayIcon->setContextMenu(menu); - - //创建套接字,和A9服务器取得连接 - parentSocket = new QTcpSocket(this); - parentSocket->connectToHost("192.168.200.105", 7777); - - - QByteArray ThisIsWidget; - ThisIsWidget.append("ThisIsWidget"); - qDebug() << "ThisIsWidget " << ThisIsWidget; - this->parentSocket->write(ThisIsWidget); - - //电灯图标 - lightPix.load(":/picture/light.png"); - ui->lightPictureLabel->setPixmap(lightPix); - ui->lightPictureLabel->setScaledContents(true); - - //空调图标 - airconditionPix.load(":/picture/airconditioner.png"); - ui->airconditionPicyureLabel->setPixmap(airconditionPix); - ui->airconditionPicyureLabel->setScaledContents(true); - - //摄像头图标 - cameraPix = new QPixmap(); - cameraPix->load(":/picture/camera.png"); - ui->cameraPictureLabel->setPixmap(*cameraPix); - ui->cameraPictureLabel->setScaledContents(true); - - //温度符号图标 - temperatureSymbol.load(":/picture/temperatureSymbol.png"); - ui->temperationSymbolLabel->setPixmap(temperatureSymbol); - ui->temperationSymbolLabel->setScaledContents(true); - - - //湿度符号图标 - humiditySymbol.load(":/picture/humiditySymbol.png"); - ui->humiditySymbolLabel->setPixmap(humiditySymbol); - ui->humiditySymbolLabel->setScaledContents(true); - - //设置电灯打开图标 - lightONPix.load(":/picture/lightON.png"); - - //设置电灯关闭图标 - lightOFFPix.load(":/picture/lightOFF.png"); - - //设置空调打开图标 - airconditionONPix.load(":/picture/airconditionerON.png"); - - //设置空调关闭图标 - airconditionOFFPix.load(":/picture/airconditionerOFF.png"); - - //摄像头配置 - cameraPix = new QPixmap(); - this->childSocket = NULL; - ui->cameraStartBtn->setEnabled(true);//开启视频按钮的初值给true - ui->cameraStopBtn->setEnabled(false);//关闭视频按钮的初值给false - ui->cameraPage->setMinimumSize(640,480); - ui->cameraPage->setMaximumSize(640,480); - ui->cameraShowPageLabel->setMinimumSize(480,320); - ui->cameraShowPageLabel->setMaximumSize(480,320); - - //接收到设置安全阈值页面发来的信号,并把页面从安全阈值设置页面切换成主页面 - connect(&setValue, SIGNAL(setSecureValueToWidgetSignal()), this, SLOT(setSecureValueTurnWidgetSlot())); - - //接收到历史数据页面发来的信号,并把页面从历史数据页面切换成主页面 - connect(&historyData, SIGNAL(historyDataToWidgetSignal()), this, SLOT(historyDataTurnWidgetSlot())); - - //接收来自服务器的信息 - connect(parentSocket, SIGNAL(readyRead()), this, SLOT(recvServerDataSlot())); - -} - -Widget::~Widget() -{ - delete ui; - parentSocket->close(); - parentSocket = NULL; -} - -void Widget::on_livingLightONOFFBtn_clicked() -{ - if(ui->livingLightONOFFBtn->text() == "客厅灯 ON") - { - //显示电灯打开的图标 - ui->livingLightONOFFPictureLabel->setPixmap(lightONPix); - ui->livingLightONOFFPictureLabel->setScaledContents(true); - - //改变电灯开关上的文本 - ui->livingLightONOFFBtn->setText("客厅灯 OFF"); - - //发送命令给A9服务器,打开客厅灯 - QByteArray openlivingroomLight; - openlivingroomLight.append("Livingroom:ON"); - qDebug() << "openlivingroomLight " << openlivingroomLight; - this->parentSocket->write(openlivingroomLight); - } - else if(ui->livingLightONOFFBtn->text() == "客厅灯 OFF") - { - //显示电灯关闭图标 - ui->livingLightONOFFPictureLabel->setPixmap(lightOFFPix); - ui->livingLightONOFFPictureLabel->setScaledContents(true); - - //改变电灯开关上的文本 - ui->livingLightONOFFBtn->setText("客厅灯 ON"); - - //发送命令给A9服务器,关闭客厅灯 - QByteArray closelivingroomLight; - closelivingroomLight.append("Livingroom:OFF"); - qDebug() << "closelivingroomLight " << closelivingroomLight; - this->parentSocket->write(closelivingroomLight); - } -} - -void Widget::on_bedroomLightONOFFBtn_clicked() -{ - if(ui->bedroomLightONOFFBtn->text() == "卧室灯 ON") - { - //显示电灯打开的图标 - ui->bedroomLightONOFFPictureLabel->setPixmap(lightONPix); - ui->bedroomLightONOFFPictureLabel->setScaledContents(true); - - //改变电灯开关上的文本 - ui->bedroomLightONOFFBtn->setText("卧室灯 OFF"); - - //发送命令给A9服务器,打开卧室灯 - QByteArray openBedroomLight; - openBedroomLight.append("Bedroom:ON"); - qDebug() << "openBedroomLight " << openBedroomLight; - this->parentSocket->write(openBedroomLight); - } - else if(ui->bedroomLightONOFFBtn->text() == "卧室灯 OFF") - { - //显示电灯关闭图标 - ui->bedroomLightONOFFPictureLabel->setPixmap(lightOFFPix); - ui->bedroomLightONOFFPictureLabel->setScaledContents(true); - - //改变电灯开关上的文本 - ui->bedroomLightONOFFBtn->setText("卧室灯 ON"); - - //发送命令给A9服务器,关闭卧室灯 - QByteArray closeBedroomLight; - closeBedroomLight.append("Bedroom:OFF"); - qDebug() << "closeBedroomLight " << closeBedroomLight; - this->parentSocket->write(closeBedroomLight); - } -} - -void Widget::on_lightBtn_clicked() -{ - ui->stackedWidget->setCurrentWidget(ui->lightPage); - - //按下灯光按钮后让灯光按钮变成不可选状态,空调和摄像头按钮变为可选状态 - ui->lightBtn->setEnabled(false); - ui->airconditionBtn->setEnabled(true); - ui->cameraBtn->setEnabled(true); -} - -void Widget::on_airconditionBtn_clicked() -{ - ui->stackedWidget->setCurrentWidget(ui->airconditionPage); - - //按下空调按钮后让空调按钮变成不可选状态,灯光按钮和摄像头按钮变为可选状态 - ui->airconditionBtn->setEnabled(false); - ui->lightBtn->setEnabled(true); - ui->cameraBtn->setEnabled(true); -} - -void Widget::on_cameraBtn_clicked() -{ - ui->stackedWidget->setCurrentWidget(ui->cameraPage); - - //按下摄像头按钮后摄像头按钮变为不可选状态,灯光和空调按钮变为可选状态 - ui->cameraBtn->setEnabled(false); - ui->lightBtn->setEnabled(true); - ui->airconditionBtn->setEnabled(true); -} - -void Widget::on_airconditionONOFFBtn_clicked() -{ - if(ui->airconditionONOFFBtn->text() == "空调 ON") - { - //显示空调开的图标 - ui->airconditionONOFFPictureLabel->setPixmap(airconditionONPix); - ui->airconditionONOFFPictureLabel->setScaledContents(true); - - //改变按钮上的文本为空调关闭 - ui->airconditionONOFFBtn->setText("空调 OFF"); - - //发送命令给A9服务器,打开空调 - QByteArray openAirconditionLight; - openAirconditionLight.append("Aircondition:ON"); - qDebug() << "openAirconditionLight " << openAirconditionLight; - this->parentSocket->write(openAirconditionLight); - } - else if(ui->airconditionONOFFBtn->text() == "空调 OFF") - { - //显示空调关闭的图标 - ui->airconditionONOFFPictureLabel->setPixmap(airconditionOFFPix); - ui->airconditionONOFFPictureLabel->setScaledContents(true); - - //改变按钮上的字 - ui->airconditionONOFFBtn->setText("空调 ON"); - - //发送命令给A9服务器,打开空调 - QByteArray closeAirconditionLight; - closeAirconditionLight.append("Aircondition:OFF"); - qDebug() << "closeAirconditionLight " << closeAirconditionLight; - this->parentSocket->write(closeAirconditionLight); - } -} - -//摄像头页面开始按钮 -void Widget::on_cameraStartBtn_clicked() -{ - if(NULL == this->childSocket) - { - this->childSocket = new QTcpSocket(); - this->childSocket->connectToHost("192.168.200.105",8888); - //发送信号者为socket这个实例,发送的信号是connected(),接收者为Form,槽函数为msconnected() - connect(this->childSocket,SIGNAL(connected()),this,SLOT(msconnected())); - connect(this->childSocket,SIGNAL(disconnected()),this,SLOT(msdisconnected())); - ui->cameraStartBtn->setEnabled(false);//开启视频后让此按钮不可选择 - ui->cameraStopBtn->setEnabled(true);//已经开启视频后让关闭视频按钮可选择(true) - } - else - { - ui->cameraStartBtn->setEnabled(false); - ui->cameraStopBtn->setEnabled(true); - timer->start(100); - } -} - - -void Widget::msconnected() -{ - qDebug() << "connected"; - timer = new QTimer(this); - connect(timer,SIGNAL(timeout()),this,SLOT(updatepic())); - timer->start(100); -} - -//发送不连接请求 -void Widget::msdisconnected() -{ - if(timer->isActive()) - timer->stop(); - ui->cameraStartBtn->setEnabled(true);//按下关闭视频按钮后让开启视频按钮可选择(true) - ui->cameraStopBtn->setEnabled(false);//按下关闭视频按钮后让关闭按钮不可选择(false) - this->childSocket->close(); - this->childSocket = NULL; -} - -//连续读取视频信息 -void Widget::updatepic() -{ - unsigned int ret; - const char *request = "pic"; //请求命令 - char response[20]; //服务器发给QT的回复 - char *len; // - unsigned int piclen; //图片长度 - char picbuf[1024 * 1024]; //存放图片 - - ret = this->childSocket->write(request, strlen(request)); //发送请求图片命令 - if (ret != strlen(request)) { - qDebug() << "send request failed"; - timer->stop(); - this->childSocket->close(); - } - - this->childSocket->flush(); //刷新socket - this->childSocket->waitForReadyRead(30000); - - memset(response, 0, sizeof(response)); - ret = this->childSocket->read(response, sizeof(response)); - if (ret != sizeof(response)) { - qDebug() << "recv response failed"; - timer->stop(); - this->childSocket->close(); - this->childSocket = NULL; - } - - len = strstr(response, "len"); - if (len == NULL) { - qDebug() << "response header is error"; - timer->stop(); - this->childSocket->close(); - this->childSocket = NULL; - } - - *len = '\0'; - //从response中读取图片长度 - piclen = atoi(response); - unsigned int total = 0; - //循环读取pic信息 - while (total < piclen) { - ret = this->childSocket->read(picbuf+total, piclen-total); - if (ret < 0) { - qDebug() << "recv pic failed" << ret; - timer->stop(); - this->childSocket->close(); - this->childSocket = NULL; - return; - } else if (ret == 0) { - this->childSocket->waitForReadyRead(30000); - continue; - } else - total += ret; - } - cameraPix->loadFromData((const uchar *)picbuf,piclen,"JPEG"); - ui->cameraShowPageLabel->setPixmap(*cameraPix); -} - -//暂停显示图像 -void Widget::on_cameraStopBtn_clicked() -{ - qDebug() << "total:----11--------------- "; - if(timer->isActive()) - timer->stop(); - qDebug() << "total:------------------- "; - ui->cameraStartBtn->setEnabled(true);//按下关闭视频按钮后让开启视频按钮变黑(true) - ui->cameraStopBtn->setEnabled(false);//按下关闭视频按钮后让关闭按钮变灰(false) -} - -//接收到设置安全阈值页面发来的信号,并把页面从安全阈值设置页面切换成主页面 -void Widget::setSecureValueTurnWidgetSlot() -{ - //隐藏设置安全阈值界面,显示主页面 - this->show(); - setValue.hide(); -} - -//设置安全阈值按钮,切换界面到设置安全阈值界面 -void Widget::on_setSecureValueBtn_clicked() -{ - //隐藏主页面,显示设置安全阈值界面 - this->hide(); - setValue.show(); -} - -//历史数据按钮,切换界面到历史数据界面 -void Widget::on_historyDataBtn_clicked() -{ - //隐藏主界面,显示历史数据界面 - this->hide(); - historyData.show(); -} - -//接收到历史数据页面发来的信号,并把页面从历史数据页面切换成主页面 -void Widget::historyDataTurnWidgetSlot() -{ - //隐藏历史数据页面,显示主页面 - this->show(); - historyData.hide(); -} - -//接收来自服务器的信息 -void Widget::recvServerDataSlot() -{ - int i = 0; - QByteArray arr = parentSocket->readAll(); - qDebug() << "widget recv = " << arr; - for(i = 0; i < 11; i++) - { - if(i == 0) - { - if((int)arr[i] == 1) - { - //显示电灯打开的图标 - ui->livingLightONOFFPictureLabel->setPixmap(lightONPix); - ui->livingLightONOFFPictureLabel->setScaledContents(true); - - //改变电灯开关上的文本 - ui->livingLightONOFFBtn->setText("客厅灯 OFF"); - } - else if((int)arr[i] == 0) - { - //显示电灯关闭图标 - ui->livingLightONOFFPictureLabel->setPixmap(lightOFFPix); - ui->livingLightONOFFPictureLabel->setScaledContents(true); - - //改变电灯开关上的文本 - ui->livingLightONOFFBtn->setText("客厅灯 ON"); - } - } - else if(i == 1) - { - if((int)arr[i] == 1) - { - //显示电灯打开的图标 - ui->bedroomLightONOFFPictureLabel->setPixmap(lightONPix); - ui->bedroomLightONOFFPictureLabel->setScaledContents(true); - - //改变电灯开关上的文本 - ui->bedroomLightONOFFBtn->setText("卧室灯 OFF"); - } - else if((int)arr[i] == 0) - { - //显示电灯关闭图标 - ui->bedroomLightONOFFPictureLabel->setPixmap(lightOFFPix); - ui->bedroomLightONOFFPictureLabel->setScaledContents(true); - - //改变电灯开关上的文本 - ui->bedroomLightONOFFBtn->setText("卧室灯 ON"); - } - } - else if(i == 2) - { - if((int)arr[i] == 1) - { - //显示空调开的图标 - ui->airconditionONOFFPictureLabel->setPixmap(airconditionONPix); - ui->airconditionONOFFPictureLabel->setScaledContents(true); - - //改变按钮上的文本为空调关闭 - ui->airconditionONOFFBtn->setText("空调 OFF"); - } - else if((int)arr[i] == 0) - { - //显示空调关闭的图标 - ui->airconditionONOFFPictureLabel->setPixmap(airconditionOFFPix); - ui->airconditionONOFFPictureLabel->setScaledContents(true); - - //改变按钮上的字 - ui->airconditionONOFFBtn->setText("空调 ON"); - } - } - else if(i == 3) - { - ui->TemDisplayLabel->setText(tr("%1").arg((float)(((int)arr[i] * 10 + (int)arr[i + 1]) / 10))); - } - else if(i == 5) - { - ui->humidityDisplayLabel->setText(tr("%1").arg((float)(((int)arr[i] * 10 + (int)arr[i + 1]) / 10))); - - } - else if(i == 7) - { - ui->lightIntensityDisplayLabel->setText(tr("%1").arg((int)(((int)arr[i + 3] << 24) + ((int)arr[i + 2]) << 16) + ((int)arr[i + 1] << 8) + (int)arr[i])); - } - } - -} - - -/*void Widget::on_realtimeDataBtn_clicked() -{ - //给服务器发命令,显示告诉这是主页面,然后显示实时数据 - QByteArray ThisIsWidget; - ThisIsWidget.append("ThisIsWidget"); - qDebug() << "ThisIsWidget " << ThisIsWidget; - this->parentSocket->write(ThisIsWidget); -}*/ diff --git a/widget.h b/widget.h deleted file mode 100644 index 1efe77c..0000000 --- a/widget.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef WIDGET_H -#define WIDGET_H - -#include -#include -#include -#include -#include -#include "setsecurevalue.h" -#include "historydata.h" - -namespace Ui { -class Widget; -} - -class Widget : public QWidget -{ - Q_OBJECT - -public: - explicit Widget(QWidget *parent = 0); - ~Widget(); - - -private slots: - - void on_livingLightONOFFBtn_clicked(); - - void on_bedroomLightONOFFBtn_clicked(); - - void on_lightBtn_clicked(); - - void on_airconditionBtn_clicked(); - - void on_cameraBtn_clicked(); - - void on_airconditionONOFFBtn_clicked(); - - void msconnected(); - - void msdisconnected(); - - void updatepic(); - - void on_cameraStartBtn_clicked(); - - void on_cameraStopBtn_clicked(); - - //接收到设置安全阈值页面发来的信号,并把页面从安全阈值设置页面切换成主页面 - void setSecureValueTurnWidgetSlot(); - - void on_setSecureValueBtn_clicked(); - - void on_historyDataBtn_clicked(); - - //接收到历史数据页面发来的信号,并把页面从历史数据页面切换成主页面 - void historyDataTurnWidgetSlot(); - - //接收来自服务器的信息 - void recvServerDataSlot(); - //void on_realtimeDataBtn_clicked(); - -private: - Ui::Widget *ui; - QPixmap lightPix; - QPixmap airconditionPix; - QPixmap *cameraPix; - QTcpSocket * parentSocket; - QTcpSocket * childSocket; - QTimer *timer; - QPixmap temperatureSymbol; - QPixmap humiditySymbol; - QSystemTrayIcon *trayIcon; - QPixmap lightONPix; - QPixmap lightOFFPix; - QPixmap airconditionONPix; - QPixmap airconditionOFFPix; - setSecureValue setValue; - historyData historyData; -}; - -#endif // WIDGET_H