You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
167 lines
4.8 KiB
167 lines
4.8 KiB
#include "logindialog.h"
|
|
#include "ui_logindialog.h"
|
|
#include <QNetworkAccessManager>
|
|
#include <QNetworkRequest>
|
|
#include <QUrlQuery>
|
|
#include <QNetworkReply>
|
|
#include <QJsonDocument>
|
|
#include <QJsonParseError>
|
|
#include <QJsonObject>
|
|
#include <QMessageBox>
|
|
#include "iconhelper.h"
|
|
#include "quihelper.h"
|
|
|
|
LoginDialog::LoginDialog(QWidget *parent) :
|
|
QDialog(parent),
|
|
ui(new Ui::LoginDialog)
|
|
{
|
|
ui->setupUi(this);
|
|
Init();
|
|
InitStyle();
|
|
this->installEventFilter(this);
|
|
m_UserData.SetManagerType(ManagerType::Ruoyi);
|
|
GetVerificationCode();
|
|
}
|
|
|
|
LoginDialog::~LoginDialog()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
bool LoginDialog::eventFilter(QObject *watched, QEvent *event)
|
|
{
|
|
QWidget *w = (QWidget *)watched;
|
|
if(w->property("form") != "title")
|
|
{
|
|
return QObject::eventFilter(watched, event);
|
|
}
|
|
if (!w->property("canMove").toBool())
|
|
{
|
|
return QObject::eventFilter(watched, event);
|
|
}
|
|
|
|
static QPoint mousePoint;
|
|
static bool mousePressed = false;
|
|
|
|
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
|
if (mouseEvent->type() == QEvent::MouseButtonPress) {
|
|
if (mouseEvent->button() == Qt::LeftButton) {
|
|
mousePressed = true;
|
|
mousePoint = mouseEvent->globalPos() - this->pos();
|
|
}
|
|
} else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
|
|
mousePressed = false;
|
|
} else if (mouseEvent->type() == QEvent::MouseMove) {
|
|
if (mousePressed) {
|
|
this->move(mouseEvent->globalPos() - mousePoint);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return QObject::eventFilter(watched, event);
|
|
}
|
|
|
|
|
|
void LoginDialog::Init()
|
|
{
|
|
//设置无边框
|
|
QUIHelper::setFramelessForm(this);
|
|
//设置图标
|
|
IconHelper::setIcon(ui->btnMenu_Min, 0xf068);
|
|
IconHelper::setIcon(ui->btnMenu_Close, 0xf00d);
|
|
|
|
//ui->widgetMenu->setVisible(false);
|
|
ui->widgetTitle->setProperty("form", "title");
|
|
ui->widgetTitle->setProperty("canMove",true);
|
|
//关联事件过滤器用于双击放大
|
|
ui->widgetTitle->installEventFilter(this);
|
|
ui->widgetTop->setProperty("nav", "top");
|
|
|
|
QFont font;
|
|
font.setPixelSize(25);
|
|
ui->labTitle->setFont(font);
|
|
ui->labTitle->setText(tr("mojin login"));
|
|
this->setWindowTitle(ui->labTitle->text());
|
|
}
|
|
|
|
void LoginDialog::InitStyle()
|
|
{
|
|
//加载样式表
|
|
QString qss;
|
|
QFile file(":/qss/blacksoft.css");
|
|
if (file.open(QFile::ReadOnly)) {
|
|
qss = QLatin1String(file.readAll());
|
|
QString paletteColor = qss.mid(20, 7);
|
|
qApp->setPalette(QPalette(paletteColor));
|
|
qApp->setStyleSheet(qss);
|
|
file.close();
|
|
}
|
|
|
|
//先从样式表中取出对应的颜色
|
|
QString textColor, panelColor, borderColor, normalColorStart, normalColorEnd, darkColorStart, darkColorEnd, highColor;
|
|
getQssColor(qss, textColor, panelColor, borderColor, normalColorStart, normalColorEnd, darkColorStart, darkColorEnd, highColor);
|
|
|
|
//将对应颜色设置到控件
|
|
this->borderColor = highColor;
|
|
this->normalBgColor = normalColorStart;
|
|
this->darkBgColor = panelColor;
|
|
this->normalTextColor = textColor;
|
|
this->darkTextColor = normalTextColor;
|
|
}
|
|
|
|
void LoginDialog::on_pushButton_cancle_clicked()
|
|
{
|
|
this->reject();
|
|
}
|
|
|
|
void LoginDialog::on_btnMenu_Min_clicked()
|
|
{
|
|
showMinimized();
|
|
}
|
|
|
|
void LoginDialog::on_btnMenu_Close_clicked()
|
|
{
|
|
close();
|
|
}
|
|
|
|
|
|
void LoginDialog::GetVerificationCode()
|
|
{
|
|
QPixmap pix = m_UserData.GetVerificationCode();
|
|
ui->label_code->setPixmap(pix.scaledToHeight(34));
|
|
}
|
|
|
|
void LoginDialog::on_pushButton_login_clicked()
|
|
{
|
|
m_UserInfo = m_UserData.Login(ui->username->text(),ui->password->text(),ui->code->text());
|
|
qDebug() << __FUNCTION__ << " login finished: "<< m_UserInfo.userName << m_UserInfo.token << m_UserInfo.uuid;
|
|
if(m_UserInfo.token.isEmpty())
|
|
{
|
|
QMessageBox::about(this,tr("Login"),tr("Login Error."));
|
|
}
|
|
this->accept();
|
|
}
|
|
|
|
void LoginDialog::getQssColor(const QString &qss, const QString &flag, QString &color)
|
|
{
|
|
int index = qss.indexOf(flag);
|
|
if (index >= 0) {
|
|
color = qss.mid(index + flag.length(), 7);
|
|
}
|
|
//qDebug() << TIMEMS << flag << color;
|
|
}
|
|
|
|
void LoginDialog::getQssColor(const QString &qss, QString &textColor, QString &panelColor,
|
|
QString &borderColor, QString &normalColorStart, QString &normalColorEnd,
|
|
QString &darkColorStart, QString &darkColorEnd, QString &highColor)
|
|
{
|
|
getQssColor(qss, "TextColor:", textColor);
|
|
getQssColor(qss, "PanelColor:", panelColor);
|
|
getQssColor(qss, "BorderColor:", borderColor);
|
|
getQssColor(qss, "NormalColorStart:", normalColorStart);
|
|
getQssColor(qss, "NormalColorEnd:", normalColorEnd);
|
|
getQssColor(qss, "DarkColorStart:", darkColorStart);
|
|
getQssColor(qss, "DarkColorEnd:", darkColorEnd);
|
|
getQssColor(qss, "HighColor:", highColor);
|
|
}
|