279 lines
7.2 KiB
C++
279 lines
7.2 KiB
C++
#include "widget.h"
|
|
#include "ui_widget.h"
|
|
#include<QMessageBox>
|
|
#include<QDebug>
|
|
#include <QSerialPort>
|
|
#include <QSerialPortInfo>
|
|
|
|
extern QString id;
|
|
extern QString id2;
|
|
extern QString id3;
|
|
extern QString id4;
|
|
extern QString id5;
|
|
extern QString id6;
|
|
extern QSqlDatabase db;
|
|
extern QSqlDatabase dbmic;
|
|
Widget::Widget(QWidget *parent)
|
|
: QWidget(parent)
|
|
, ui(new Ui::Widget)
|
|
{
|
|
ui->setupUi(this);
|
|
connectsql();
|
|
m_twobars=new twobars;
|
|
ui->pushButton->setFixedSize(150,50);
|
|
|
|
|
|
this->setWindowFlags(Qt::FramelessWindowHint); // 隐藏标题栏
|
|
// this->resize(1280, 720);
|
|
ui->lineEdit_2->setEchoMode(QLineEdit::Password);
|
|
ui->lineEdit->setFixedSize(150,37);
|
|
ui->lineEdit_2->setFixedSize(150,37);
|
|
this->setFixedSize(1920,1080);
|
|
this->showMaximized();
|
|
|
|
ui->label_11->setFixedSize(500,60);
|
|
ui->label_12->setFixedSize(496,409);
|
|
ui->frame_3->setFixedSize(500,330);
|
|
ui->radioButton->setFixedSize(20,20);
|
|
ui->label_12->setHidden(false);
|
|
ui->frame_3->setHidden(true);
|
|
m_msg=new msgbox_2;
|
|
connect(this,SIGNAL(zhuangtai(QString)), m_msg, SLOT(getzhuangtai(QString)));
|
|
QTimer::singleShot(3000, [=]() {
|
|
//
|
|
|
|
|
|
bool com1Found = false;
|
|
bool com3Found = false;
|
|
bool com5Found = false;
|
|
|
|
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
|
|
QSerialPort serial;
|
|
serial.setPort(info);
|
|
if (serial.open(QIODevice::ReadWrite)) {
|
|
QString portName = info.portName();
|
|
if (portName.compare("COM1", Qt::CaseInsensitive) == 0) {
|
|
com1Found = true;
|
|
} else if (portName.compare("COM3", Qt::CaseInsensitive) == 0) {
|
|
com3Found = true;
|
|
} else if (portName.compare("COM5", Qt::CaseInsensitive) == 0) {
|
|
com5Found = true;
|
|
}
|
|
serial.close();
|
|
}
|
|
}
|
|
|
|
QString message;
|
|
if (com1Found) {
|
|
message += "相机启动成功\n\n";
|
|
} else {
|
|
message += "相机启动失败\n";
|
|
}
|
|
|
|
if (com3Found) {
|
|
message += "光源连接成功\n\n";
|
|
} else {
|
|
message += "光源连接失败\n";
|
|
}
|
|
|
|
if (com5Found) {
|
|
message += "紫外灯连接成功\n";
|
|
} else {
|
|
message += "紫外灯连接失败\n";
|
|
}
|
|
|
|
emit zhuangtai(message);
|
|
m_msg->move(800,450);
|
|
m_msg->exec();
|
|
|
|
ui->label_12->setHidden(true);
|
|
|
|
|
|
|
|
|
|
ui->frame_3->setHidden(false);
|
|
});
|
|
|
|
connect(m_twobars, &twobars::denglu, this, [=](){
|
|
|
|
this->showMaximized();
|
|
});
|
|
connect(this,&Widget::zhu,m_twobars,&twobars::getzhu);
|
|
|
|
ui->frame->setFixedSize(300,43);
|
|
ui->frame_2->setFixedSize(300,43);
|
|
ui->pushButton->setFixedSize(300,35);
|
|
|
|
ui->label->setFixedSize(350,100);
|
|
ui->label_4->setFixedSize(30,30);
|
|
ui->label_5->setFixedSize(25,23);
|
|
ui->label_4->setScaledContents(true);
|
|
ui->label_5->setScaledContents(true);
|
|
// ui->label_3->setScaledContents(true);
|
|
ui->label_7->setScaledContents(true);
|
|
ui->label_2->setScaledContents(true);
|
|
ui->label->setScaledContents(true);
|
|
ui->label_2->setFixedHeight(30);
|
|
ui->label_7->setFixedHeight(30);
|
|
// m_twobars->showFullScreen();
|
|
setWindowIcon(QIcon("use/logo.ico"));
|
|
}
|
|
|
|
Widget::~Widget()
|
|
{
|
|
delete ui;
|
|
}
|
|
void Widget::mousePressEvent(QMouseEvent *event)
|
|
{
|
|
if (ui->frame->geometry().contains(event->pos())) {
|
|
// 判断是否是左键点击
|
|
if (event->button() == Qt::LeftButton) {
|
|
QPoint posInLabel = event->pos() - ui->frame->pos();
|
|
qDebug() << "在label_6内的左键点击坐标: " << posInLabel;
|
|
// x=posInLabel.x();
|
|
// y= posInLabel.y();
|
|
qDebug() << posInLabel.x();
|
|
qDebug() << posInLabel.y();
|
|
// ui->label_3->setHidden(true);
|
|
// ui->lineEdit->setHidden(false);
|
|
|
|
// 获取鼠标在全局屏幕上的坐标
|
|
QPoint globalPos = event->globalPos();
|
|
qDebug() << "在全局屏幕上的左键点击坐标: " << globalPos;
|
|
}
|
|
|
|
}
|
|
else if (ui->frame_2->geometry().contains(event->pos())) {
|
|
// 判断是否是左键点击
|
|
if (event->button() == Qt::LeftButton) {
|
|
QPoint posInLabel = event->pos() - ui->frame_2->pos();
|
|
qDebug() << "在label_6内的左键点击坐标: " << posInLabel;
|
|
// x=posInLabel.x();
|
|
// y= posInLabel.y();
|
|
qDebug() << posInLabel.x();
|
|
qDebug() << posInLabel.y();
|
|
// ui->label_3->setHidden(true);
|
|
// ui->lineEdit->setHidden(false);
|
|
|
|
// 获取鼠标在全局屏幕上的坐标
|
|
QPoint globalPos = event->globalPos();
|
|
qDebug() << "在全局屏幕上的左键点击坐标: " << globalPos;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
void Widget::on_pushButton_clicked()
|
|
{//登录
|
|
|
|
userslogin user(ui->lineEdit->text(),ui->lineEdit_2->text());
|
|
if(ui->lineEdit->text().isEmpty()==true)
|
|
{
|
|
QMessageBox::warning(this,"警告","用户名不能为空");
|
|
|
|
}
|
|
else if(ui->lineEdit_2->text().isEmpty()==true)
|
|
{
|
|
QMessageBox::warning(this,"警告","密码不能为空");
|
|
|
|
}
|
|
|
|
else if(signup(user))
|
|
{
|
|
|
|
qDebug()<<"登陆成功";
|
|
this->hide();
|
|
emit zhu();
|
|
ui->lineEdit_2->clear();
|
|
m_twobars->showFullScreen();
|
|
|
|
id=ui->lineEdit->text();
|
|
id2=ui->lineEdit->text();
|
|
id3=ui->lineEdit->text();
|
|
id4=ui->lineEdit->text();
|
|
id5=ui->lineEdit->text();
|
|
id6=ui->lineEdit->text();
|
|
m_twobars->getname();
|
|
}
|
|
else
|
|
{
|
|
QMessageBox::warning(this,"警告","密码或用户名错误");
|
|
qDebug()<<"登陆失败";
|
|
}
|
|
|
|
|
|
|
|
}
|
|
void Widget::connectsql()
|
|
{
|
|
|
|
db = QSqlDatabase::addDatabase("QSQLITE");
|
|
db.setDatabaseName("mic.db");
|
|
bool ok = db.open();
|
|
dbmic=db;
|
|
if (ok){
|
|
|
|
}
|
|
else {
|
|
QMessageBox::information(this, "infor", "open failed");
|
|
qDebug()<<"error open database because"<<db.lastError().text();
|
|
}
|
|
|
|
}
|
|
bool Widget::signup(userslogin user)
|
|
{
|
|
QString sql=QString("select password from users where id='%1'").arg(user.getid());
|
|
qDebug()<<sql;
|
|
QSqlQuery query;
|
|
|
|
if(query.exec(sql))
|
|
{
|
|
if(query.first()){
|
|
QString name=query.value(0).toString();
|
|
name=name.simplified();
|
|
qDebug()<<name;
|
|
/*remove(QRegExp("\\s"))*/;
|
|
if(name==user.getpassword())
|
|
|
|
{return true;}
|
|
else{ return false;}
|
|
}
|
|
else{return false;}
|
|
|
|
|
|
}
|
|
|
|
else
|
|
{
|
|
qDebug()<<"不执行";
|
|
return false;}
|
|
|
|
|
|
}
|
|
|
|
void Widget::on_toolButton_clicked()
|
|
{
|
|
int result = QMessageBox::information(NULL, "提示", "确定要退出运行吗", QMessageBox::Ok | QMessageBox::Cancel);
|
|
if (result == QMessageBox::Ok) {
|
|
|
|
|
|
QTimer::singleShot(500,this,[=](){qApp->quit();
|
|
|
|
}) ;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
void Widget::on_radioButton_clicked()
|
|
{
|
|
if(ui->radioButton->isChecked()){
|
|
ui->lineEdit_2->setEchoMode(QLineEdit::Normal);
|
|
}
|
|
else{
|
|
ui->lineEdit_2->setEchoMode(QLineEdit::Password);
|
|
}
|
|
}
|
|
|