* Refactor windows package.
This commit is contained in:
153
src/windows/LoginDialog.cpp
Normal file
153
src/windows/LoginDialog.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
#include "LoginDialog.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QToolButton>
|
||||
#include <QFrame>
|
||||
#include <QInputMethodEvent>
|
||||
#include <QtWidgets/QLabel>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
#include "guimacros.h"
|
||||
#include "event/EventCenter.h"
|
||||
#include "db/SQLHelper.h"
|
||||
#include "utilities/InputObject.h"
|
||||
#include "models/User.h"
|
||||
#include "log/UserOperationLog.h"
|
||||
#include "json/jsonobject.h"
|
||||
#include "dialogs/guimessagedialog.h"
|
||||
|
||||
LoginDialog::LoginDialog(QWidget* aParent)
|
||||
: QDialog(aParent)
|
||||
, mVMainLayout(new QVBoxLayout(this))
|
||||
, mDialogTitle(new QLabel(this))
|
||||
, mDialogFrame(new QFrame(this))
|
||||
, mDialogContentsLayout(new QVBoxLayout(mDialogFrame))
|
||||
, mAccountEdit(new QLineEdit(mDialogFrame))
|
||||
, mPasswordEdit(new QLineEdit(mDialogFrame))
|
||||
, mLoginButton(nullptr)
|
||||
, mErrorMessage(new QLabel(this))
|
||||
{
|
||||
initializeAllWidget();
|
||||
setWindowFlags(windowFlags() | Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
|
||||
mAccountEdit->setText(JsonObject::Instance()->defaultUser());
|
||||
}
|
||||
|
||||
LoginDialog::~LoginDialog()
|
||||
{
|
||||
}
|
||||
|
||||
void LoginDialog::initializeAllWidget()
|
||||
{
|
||||
this->setObjectName("loginform");
|
||||
|
||||
initializeTitle();
|
||||
initializeDialogFrame();
|
||||
initializeLayout();
|
||||
initializeEdit();
|
||||
initializeLoginButton();
|
||||
initializeErrorMessage();
|
||||
|
||||
connect(EventCenter::Default(), &EventCenter::DeviceErrorRaise, [=](QObject* parent, QObject* msg) {
|
||||
if (!this->isVisible()) return;
|
||||
//默认旧模式
|
||||
GUIMessageDialog msgDialog(this);
|
||||
msgDialog.setOpacity(1.0);
|
||||
if (msg)
|
||||
{
|
||||
QString* str = (QString*)msg;
|
||||
msgDialog.showMessage(*str);
|
||||
}
|
||||
else
|
||||
{
|
||||
msgDialog.showMessage("Something went error!");
|
||||
}
|
||||
msgDialog.stopLoading();
|
||||
msgDialog.showExitButton();
|
||||
msgDialog.exec();
|
||||
});
|
||||
}
|
||||
|
||||
void LoginDialog::initializeLayout()
|
||||
{
|
||||
mVMainLayout->setContentsMargins(0, 0, 0, 0);
|
||||
mVMainLayout->setSpacing(0);
|
||||
mVMainLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
||||
mVMainLayout->addWidget(mDialogTitle, 0, Qt::AlignCenter);
|
||||
mVMainLayout->addWidget(mDialogFrame, 0, Qt::AlignCenter);
|
||||
mVMainLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
||||
|
||||
mDialogContentsLayout->setSpacing(30);
|
||||
mDialogContentsLayout->setContentsMargins(20, 60, 20, 20);
|
||||
}
|
||||
|
||||
void LoginDialog::initializeTitle()
|
||||
{
|
||||
mDialogTitle->setObjectName("title");
|
||||
mDialogTitle->setText(tr("U S C T"));
|
||||
}
|
||||
|
||||
void LoginDialog::initializeDialogFrame()
|
||||
{
|
||||
mDialogFrame->setObjectName("login_frame_username");
|
||||
}
|
||||
|
||||
void LoginDialog::initializeEdit()
|
||||
{
|
||||
mAccountEdit->setObjectName("combobox_UserName");
|
||||
mAccountEdit->setPlaceholderText(tr("Username"));
|
||||
mDialogContentsLayout->addWidget(mAccountEdit);
|
||||
mPasswordEdit->setObjectName("edt_Password");
|
||||
mPasswordEdit->setEchoMode(QLineEdit::Password);
|
||||
mPasswordEdit->setPlaceholderText(tr("Password"));
|
||||
mDialogContentsLayout->addWidget(mPasswordEdit);
|
||||
}
|
||||
|
||||
void LoginDialog::initializeLoginButton()
|
||||
{
|
||||
ADD_TOOL_BTN_TO_LAYOUT(login, ":/icons/login.png", mDialogContentsLayout);
|
||||
btnlogin->setText(tr("Login"));
|
||||
mDialogContentsLayout->removeWidget(btnlogin);
|
||||
mDialogContentsLayout->addWidget(btnlogin, 0, Qt::AlignCenter);
|
||||
mLoginButton = btnlogin;
|
||||
btnlogin->setObjectName("btnlogin");
|
||||
connect(mLoginButton, SIGNAL(clicked()), this, SLOT(doLogin()));
|
||||
}
|
||||
|
||||
void LoginDialog::initializeErrorMessage()
|
||||
{
|
||||
mErrorMessage->setObjectName("warn");
|
||||
mErrorMessage->setText("Login failed, username or password error!");
|
||||
mErrorMessage->setVisible(false);
|
||||
mDialogContentsLayout->addWidget(mErrorMessage, 0, Qt::AlignCenter);
|
||||
}
|
||||
|
||||
void LoginDialog::clearInputData()
|
||||
{
|
||||
mAccountEdit->clear();
|
||||
mPasswordEdit->clear();
|
||||
}
|
||||
|
||||
|
||||
void LoginDialog::doLogin()
|
||||
{
|
||||
QString strUserCode = mAccountEdit->text();
|
||||
QString strPassWord = mPasswordEdit->text();
|
||||
|
||||
QString encryptedPassword = strPassWord;
|
||||
strPassWord = "123456";
|
||||
|
||||
QString encryptPwd = User::getEncryptedPassword(strPassWord);
|
||||
if (User::QueryUser(strUserCode, encryptPwd))
|
||||
{
|
||||
accept();
|
||||
LOG_USER_OPERATION(Login);
|
||||
JsonObject::Instance()->setDefaultUser(strUserCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
mErrorMessage->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user