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 <QWidget>
#include <QMouseEvent>
Login::Login(QWidget *parent) :
LoginUi::LoginUi(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Login)
ui(new Ui::LoginUi)
{
ui->setupUi(this);
initWindow();
}
Login::~Login()
LoginUi::~LoginUi()
{
delete ui;
}
void Login::initWindow(){
void LoginUi::initWindow(){
setWindowState();
setBtnAndLabelState();
}
void Login::setWindowState(){
void LoginUi::setWindowState(){
this->setAttribute(Qt::WA_TranslucentBackground);
this->setWindowFlags(Qt::FramelessWindowHint);//隐藏边框
}
void Login::setBtnAndLabelState(){
void LoginUi::setBtnAndLabelState(){
QMovie* movie = new QMovie("://images/background.gif");
ui->label_video->setMovie(movie);
movie->start();
@ -47,14 +48,18 @@ void Login::setBtnAndLabelState(){
connect(ui->btnWinClose, &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();
isPressedWidget = true; // 当前鼠标按下的即是QWidget而非界面上布局的其它控件
}
void Login::mouseMoveEvent(QMouseEvent *event) {
void LoginUi::mouseMoveEvent(QMouseEvent *event) {
if (isPressedWidget) {
this->move(this->x() + (event->globalX() - m_lastPos.x()),
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函数可以不用重写
m_lastPos = event->globalPos();
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/login.h"
#include "../include/Air_Ground_CEC/loginui.h"
#include <QApplication>
@ -15,7 +15,7 @@ int main(int argc, char** argv)
//MainWindow CEC(0,0,0);
//CEC.show();
Login a(0);
LoginUi a(0);
a.show();
return app.exec();

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