commit 11fd76dc392990345bdd0911ff3423d470331813 Author: Lee Date: Thu Jan 20 15:18:42 2022 +0800 UI change 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/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/main.cpp b/main.cpp new file mode 100644 index 0000000..05ace16 --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainmenu.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + 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/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..79f8f28 --- /dev/null +++ b/submenu.cpp @@ -0,0 +1,23 @@ +#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("风中有朵雨做的云"); +} + +submenu::~submenu() +{ + delete ui; +} + +void submenu::on_pushButton_clicked() +{ + this->hide(); + emit widget_close(); + this->close(); +} diff --git a/submenu.h b/submenu.h new file mode 100644 index 0000000..365192b --- /dev/null +++ b/submenu.h @@ -0,0 +1,28 @@ +#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_pushButton_clicked(); + +private: + Ui::submenu *ui; +signals: + void widget_close(void); + +}; + +#endif // SUBMENU_H diff --git a/submenu.ui b/submenu.ui new file mode 100644 index 0000000..246a89f --- /dev/null +++ b/submenu.ui @@ -0,0 +1,32 @@ + + + submenu + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 160 + 240 + 75 + 23 + + + + 退出 + + + + + +