pull/37/head
大耳刮子 3 years ago
parent e39ee0bc6c
commit 4cc1d21c74

@ -1,32 +0,0 @@
#ifndef LOGIN_H
#define LOGIN_H
#include <QMainWindow>
#include "ui_login.h"
namespace Ui {
class Login;
}
class Login : public QMainWindow
{
Q_OBJECT
public:
explicit Login(QWidget *parent = nullptr);
~Login();
private:
Ui::Login *ui;
bool isPressedWidget;
QPoint m_lastPos;
void initWindow();
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void setWindowState();
void setBtnAndLabelState();
};
#endif // LOGIN_H

@ -0,0 +1,40 @@
#ifndef LOGINUI_H
#define LOGINUI_H
#include <QMainWindow>
#include "ui_loginui.h"
#include <iostream>
#include <cstring>
using namespace std;
namespace Ui {
class LoginUi;
}
class LoginUi : public QMainWindow
{
Q_OBJECT
public:
explicit LoginUi(QWidget *parent = nullptr);
~LoginUi();
private:
Ui::LoginUi *ui;
bool isPressedWidget;
QPoint m_lastPos;
void initWindow();
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void setWindowState();
void setBtnAndLabelState();
bool verifyAccount(string usr, string pwd);
void changetoMainwindow();
};
#endif // LOGINUI_H

@ -1,35 +1,36 @@
#include "../include/Air_Ground_CEC/login.h" #include "../include/Air_Ground_CEC/loginui.h"
#include "../include/Air_Ground_CEC/mainwindow.hpp"
#include <QMovie> #include <QMovie>
#include <QWidget> #include <QWidget>
#include <QMouseEvent> #include <QMouseEvent>
Login::Login(QWidget *parent) : LoginUi::LoginUi(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::Login) ui(new Ui::LoginUi)
{ {
ui->setupUi(this); ui->setupUi(this);
initWindow(); initWindow();
} }
Login::~Login() LoginUi::~LoginUi()
{ {
delete ui; delete ui;
} }
void Login::initWindow(){ void LoginUi::initWindow(){
setWindowState(); setWindowState();
setBtnAndLabelState(); setBtnAndLabelState();
} }
void Login::setWindowState(){ void LoginUi::setWindowState(){
this->setAttribute(Qt::WA_TranslucentBackground); this->setAttribute(Qt::WA_TranslucentBackground);
this->setWindowFlags(Qt::FramelessWindowHint);//隐藏边框 this->setWindowFlags(Qt::FramelessWindowHint);//隐藏边框
} }
void Login::setBtnAndLabelState(){ void LoginUi::setBtnAndLabelState(){
QMovie* movie = new QMovie("://images/background.gif"); QMovie* movie = new QMovie("://images/background.gif");
ui->label_video->setMovie(movie); ui->label_video->setMovie(movie);
movie->start(); movie->start();
@ -47,14 +48,18 @@ void Login::setBtnAndLabelState(){
connect(ui->btnWinClose, &QPushButton::clicked, this, [=]() { this->close(); }); connect(ui->btnWinClose, &QPushButton::clicked, this, [=]() { this->close(); });
connect(ui->btnWinClose_2, &QPushButton::clicked, this, [=]() { this->close(); }); connect(ui->btnWinClose_2, &QPushButton::clicked, this, [=]() { this->close(); });
connect(ui->btnLogin, &QPushButton::clicked, this, [=]() {
changetoMainwindow();}
);
} }
void Login::mousePressEvent(QMouseEvent *event) { void LoginUi::mousePressEvent(QMouseEvent *event) {
m_lastPos = event->globalPos(); m_lastPos = event->globalPos();
isPressedWidget = true; // 当前鼠标按下的即是QWidget而非界面上布局的其它控件 isPressedWidget = true; // 当前鼠标按下的即是QWidget而非界面上布局的其它控件
} }
void Login::mouseMoveEvent(QMouseEvent *event) { void LoginUi::mouseMoveEvent(QMouseEvent *event) {
if (isPressedWidget) { if (isPressedWidget) {
this->move(this->x() + (event->globalX() - m_lastPos.x()), this->move(this->x() + (event->globalX() - m_lastPos.x()),
this->y() + (event->globalY() - m_lastPos.y())); this->y() + (event->globalY() - m_lastPos.y()));
@ -62,8 +67,30 @@ void Login::mouseMoveEvent(QMouseEvent *event) {
} }
} }
void Login::mouseReleaseEvent(QMouseEvent *event) { void LoginUi::mouseReleaseEvent(QMouseEvent *event) {
// 其实这里的mouseReleaseEvent函数可以不用重写 // 其实这里的mouseReleaseEvent函数可以不用重写
m_lastPos = event->globalPos(); m_lastPos = event->globalPos();
isPressedWidget = false; // 鼠标松开时置为false isPressedWidget = false; // 鼠标松开时置为false
} }
bool LoginUi::verifyAccount(string usr, string pwd){
if (usr == "admin" && pwd == "admin"){
return true;
}
return false;
}
void LoginUi::changetoMainwindow(){
this->close();
MainWindow CEC(0,0,0);
CEC.show();
}

@ -1,5 +1,5 @@
#include "../include/Air_Ground_CEC/mainwindow.hpp" #include "../include/Air_Ground_CEC/mainwindow.hpp"
#include "../include/Air_Ground_CEC/login.h" #include "../include/Air_Ground_CEC/loginui.h"
#include <QApplication> #include <QApplication>
@ -15,7 +15,7 @@ int main(int argc, char** argv)
//MainWindow CEC(0,0,0); //MainWindow CEC(0,0,0);
//CEC.show(); //CEC.show();
Login a(0); LoginUi a(0);
a.show(); a.show();
return app.exec(); return app.exec();

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>Login</class> <class>LoginUi</class>
<widget class="QWidget" name="Login"> <widget class="QWidget" name="LoginUi">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@ -841,8 +841,8 @@ background-color:none</string>
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>579</width> <width>205</width>
<height>196</height> <height>104</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@ -902,8 +902,8 @@ background-color:none</string>
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>579</width> <width>88</width>
<height>196</height> <height>88</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@ -926,7 +926,7 @@ background-color:none</string>
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>565</width> <width>267</width>
<height>312</height> <height>312</height>
</rect> </rect>
</property> </property>
@ -1251,8 +1251,8 @@ background-color:none</string>
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>579</width> <width>313</width>
<height>196</height> <height>133</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
Loading…
Cancel
Save