Refactor dialog package.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// Created by Krad on 2021/11/10.
|
||||
//
|
||||
#include "AccountFormDialog.h"
|
||||
#include "ChangePasswordFormDialog.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QUuid>
|
||||
@@ -10,286 +10,294 @@
|
||||
#include <QToolButton>
|
||||
#include <QPushButton>
|
||||
#include <QLineEdit>
|
||||
#include "ChangePasswordFormDialog.h"
|
||||
#include "event/EventCenter.h"
|
||||
#include "log/UserOperationLog.h"
|
||||
#include "db/SQLHelper.h"
|
||||
#include "models/User.h"
|
||||
#include "components/SlidePickerBox.h"
|
||||
#include "SelectDialog.h"
|
||||
#include "AlertDialog.h"
|
||||
|
||||
AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
||||
m_mode = mode;
|
||||
QVBoxLayout *layout = new QVBoxLayout(formWidget);
|
||||
AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::WindowFlags f)
|
||||
: GUIFormBaseDialog(parent, f)
|
||||
, mUserNameChanged(false)
|
||||
, mCommentChanged(false)
|
||||
, mRoleChanged(false)
|
||||
, mMode(mode)
|
||||
, mLeUserCode(new QLineEdit(this))
|
||||
, mLeUserName(new QLineEdit(this))
|
||||
, mLeComment(new QLineEdit(this))
|
||||
, mLePwd(nullptr)
|
||||
, mBtnPwd(nullptr)
|
||||
, mLblError(new QLabel(this))
|
||||
, mRefModel(nullptr)
|
||||
{
|
||||
auto layout = new QVBoxLayout(mFormWidget);
|
||||
layout->setSpacing(10);
|
||||
// add title
|
||||
QLabel *lbl_title = new QLabel(this);
|
||||
lbl_title->setAlignment(Qt::AlignCenter);
|
||||
lbl_title->setText(tr("Account"));
|
||||
lbl_title->setObjectName("title");
|
||||
layout->addWidget(lbl_title);
|
||||
|
||||
//add usercode
|
||||
QLabel *lbl_UserCode = new QLabel(this);
|
||||
lbl_UserCode->setText(tr("User ID"));
|
||||
le_UserCode = new QLineEdit(this);
|
||||
le_UserCode->setPlaceholderText(tr("Input User ID"));
|
||||
if (m_mode != New)le_UserCode->setEnabled(false);
|
||||
layout->addWidget(lbl_UserCode);
|
||||
layout->addWidget(le_UserCode);
|
||||
QLabel *lbl_endline1 = new QLabel(this);
|
||||
lbl_endline1->setObjectName("endline");
|
||||
layout->addWidget(lbl_endline1);
|
||||
|
||||
//add username
|
||||
QLabel *lbl_UserName = new QLabel(this);
|
||||
lbl_UserName->setText(tr("Name"));
|
||||
le_UserName = new QLineEdit(this);
|
||||
le_UserName->setPlaceholderText(tr("Input User name"));
|
||||
layout->addWidget(lbl_UserName);
|
||||
layout->addWidget(le_UserName);
|
||||
QLabel *lbl_endline2 = new QLabel(this);
|
||||
lbl_endline2->setObjectName("endline");
|
||||
layout->addWidget(lbl_endline2);
|
||||
|
||||
// add new mode
|
||||
if (m_mode == New) {
|
||||
//add password
|
||||
QLabel *lbl_Pwd = new QLabel(this);
|
||||
lbl_Pwd->setText(tr("Password"));
|
||||
layout->addWidget(lbl_Pwd);
|
||||
le_Pwd = new QLineEdit(this);
|
||||
le_Pwd->setPlaceholderText(tr("Input password"));
|
||||
le_Pwd->setEchoMode(QLineEdit::Password);
|
||||
layout->addWidget(le_Pwd);
|
||||
m_RoleID = User::getRoleID("doctor");
|
||||
QLabel *lbl_endline3 = new QLabel(this);
|
||||
lbl_endline3->setObjectName("endline");
|
||||
layout->addWidget(lbl_endline3);
|
||||
}
|
||||
|
||||
|
||||
//add Comment
|
||||
QLabel *lbl_Comment = new QLabel(this);
|
||||
lbl_Comment->setText(tr("Comment"));
|
||||
le_Comment = new QLineEdit(this);
|
||||
layout->addWidget(lbl_Comment);
|
||||
layout->addWidget(le_Comment);
|
||||
QLabel *lbl_endline0 = new QLabel(this);
|
||||
lbl_endline0->setObjectName("endline");
|
||||
layout->addWidget(lbl_endline0);
|
||||
|
||||
lbl_error = new QLabel(this);
|
||||
lbl_error->setObjectName("warn");
|
||||
lbl_error->setVisible(false);
|
||||
layout->addWidget(lbl_error);
|
||||
|
||||
|
||||
QHBoxLayout* hlayout = new QHBoxLayout;
|
||||
addTitleLabel(layout);
|
||||
initUserCodeUI(layout);
|
||||
initUserNameUI(layout);
|
||||
if (mMode == New) addNewModeUI(layout);
|
||||
addCommentLabel(layout);
|
||||
addWarnLabel(layout);
|
||||
auto hlayout = new QHBoxLayout;
|
||||
layout->addLayout(hlayout);
|
||||
|
||||
//add logout
|
||||
// QLabel *lbl_Logout = new QLabel(this);
|
||||
// lbl_Logout->setText(tr("Logout"));
|
||||
if (m_mode == Self)
|
||||
{
|
||||
QToolButton *btn_Logout = new QToolButton(this);
|
||||
btn_Logout->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
btn_Logout->setIcon(QIcon(":/icons/logout.png"));
|
||||
btn_Logout->setIconSize({30, 30});
|
||||
btn_Logout->setText(tr("Logout"));
|
||||
btn_Logout->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
|
||||
btn_Logout->setObjectName("editvalBtn");
|
||||
|
||||
hlayout->addWidget(btn_Logout);
|
||||
connect(btn_Logout, &QAbstractButton::clicked, [=]() {
|
||||
this->accept();
|
||||
LOG_USER_OPERATION(Logout);
|
||||
EventCenter::Default()->triggerEvent(GUIEvents::RequestLogin, nullptr, nullptr);
|
||||
});
|
||||
if (mMode == Self)addSelfModeUI(hlayout);
|
||||
if (mMode != New) {
|
||||
addButtonPwd(hlayout);
|
||||
addEndLine(layout);
|
||||
connect(mBtnPwd, &QPushButton::clicked, this, mMode == Self ?
|
||||
&AccountFormDialog::changeSelfPassword : &AccountFormDialog::resetUserPassword);
|
||||
}
|
||||
|
||||
// load current user data
|
||||
if (m_mode == Self && User::Current()) {
|
||||
le_UserCode->setText(User::Current()->getUserCode());
|
||||
le_UserName->setText(User::Current()->getUserName());
|
||||
m_UserID = User::Current()->getUserID();
|
||||
m_UserPwd = User::Current()->getPassword();
|
||||
}
|
||||
if (m_mode != New) {
|
||||
btn_Pwd = new QToolButton(this);
|
||||
btn_Pwd->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
btn_Pwd->setObjectName("editvalBtn");
|
||||
btn_Pwd->setIcon(QIcon(":/icons/edit.png"));
|
||||
btn_Pwd->setIconSize({30, 30});
|
||||
btn_Pwd->setText(m_mode == Self ? tr("Change Password") : tr("Reset Password"));
|
||||
btn_Pwd->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
hlayout->addWidget(btn_Pwd);
|
||||
QLabel *lbl_endline9 = new QLabel(this);
|
||||
lbl_endline9->setFixedHeight(2);
|
||||
lbl_endline9->setObjectName("endline");
|
||||
layout->addWidget(lbl_endline9);
|
||||
if (m_mode == Self) {
|
||||
connect(btn_Pwd, &QPushButton::clicked, [=]() {
|
||||
ChangePasswordFormDialog dia(this);
|
||||
dia.setGeometry(this->geometry());
|
||||
dia.setWindowModality(Qt::WindowModal);
|
||||
dia.exec();
|
||||
|
||||
});
|
||||
} else {
|
||||
connect(btn_Pwd, &QAbstractButton::clicked, [=]() {
|
||||
AlertDialog dialog(this);
|
||||
dialog.setGeometry(this->geometry());
|
||||
dialog.setButtonMode(OkAndCancel);
|
||||
dialog.setWindowModality(Qt::WindowModal);
|
||||
dialog.setAlertMessage(tr("Reset password to \"123456\" ?"));
|
||||
if (dialog.exec() == Accepted) {
|
||||
User user;
|
||||
dialog.setButtonMode(OkOnly);
|
||||
if (!User::getUser(m_UserID, user)) {
|
||||
dialog.setAlertMessage(tr("Inner error, can't find reference user!"));
|
||||
dialog.exec();
|
||||
return;
|
||||
}
|
||||
if (!user.resetPassword()) {
|
||||
dialog.setAlertMessage(tr("Submit change to database fail!"));
|
||||
dialog.exec();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
connect(le_Comment, &QLineEdit::textChanged, [=](const QString &text) {
|
||||
commentChanged = true;
|
||||
connect(mLeComment, &QLineEdit::textChanged, [=](const QString &text) {
|
||||
mCommentChanged = true;
|
||||
});
|
||||
connect(le_UserName, &QLineEdit::textChanged, [=](const QString &text) {
|
||||
m_NewUserName = text;
|
||||
userNameChanged = true;
|
||||
connect(mLeUserName, &QLineEdit::textChanged, [=](const QString &text) {
|
||||
mNewUserName = text;
|
||||
mUserNameChanged = true;
|
||||
});
|
||||
}
|
||||
|
||||
AccountFormDialog::~AccountFormDialog() {
|
||||
void AccountFormDialog::addEndLine(QVBoxLayout *layout) {
|
||||
auto lblEndline = new QLabel(this);
|
||||
lblEndline->setFixedHeight(2);
|
||||
lblEndline->setObjectName("endline");
|
||||
layout->addWidget(lblEndline);
|
||||
}
|
||||
|
||||
void AccountFormDialog::resetUserPassword() {
|
||||
AlertDialog dialog(this);
|
||||
dialog.setGeometry(geometry());
|
||||
dialog.setButtonMode(OkAndCancel);
|
||||
dialog.setWindowModality(Qt::WindowModal);
|
||||
dialog.setAlertMessage(tr("Reset password to \"123456\" ?"));
|
||||
if (dialog.exec() == Accepted) {
|
||||
User user;
|
||||
dialog.setButtonMode(OkOnly);
|
||||
if (!User::getUser(mUserID, user)) {
|
||||
dialog.setAlertMessage(tr("Inner error, can't find reference user!"));
|
||||
dialog.exec();
|
||||
return;
|
||||
}
|
||||
if (!user.resetPassword()) {
|
||||
dialog.setAlertMessage(tr("Submit change to database fail!"));
|
||||
dialog.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AccountFormDialog::changeSelfPassword() {
|
||||
ChangePasswordFormDialog dia(this);
|
||||
dia.setGeometry(geometry());
|
||||
dia.setWindowModality(Qt::WindowModal);
|
||||
dia.exec();
|
||||
}
|
||||
|
||||
void AccountFormDialog::addButtonPwd(QHBoxLayout *layout) {
|
||||
mBtnPwd = new QToolButton(this);
|
||||
mBtnPwd->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
mBtnPwd->setObjectName("editvalBtn");
|
||||
mBtnPwd->setIcon(QIcon(":/icons/edit.png"));
|
||||
mBtnPwd->setIconSize({30, 30});
|
||||
mBtnPwd->setText(mMode == Self ? tr("Change Password") : tr("Reset Password"));
|
||||
mBtnPwd->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
layout->addWidget(mBtnPwd);
|
||||
}
|
||||
|
||||
void AccountFormDialog::addWarnLabel(QVBoxLayout *layout) {
|
||||
mLblError->setObjectName("warn");
|
||||
mLblError->setVisible(false);
|
||||
layout->addWidget(mLblError);
|
||||
}
|
||||
|
||||
void AccountFormDialog::addCommentLabel(QVBoxLayout *layout) {
|
||||
auto lblComment = new QLabel(this);
|
||||
lblComment->setText(tr("Comment"));
|
||||
layout->addWidget(lblComment);
|
||||
layout->addWidget(mLeComment);
|
||||
addEndLine(layout);
|
||||
}
|
||||
|
||||
void AccountFormDialog::initUserNameUI(QVBoxLayout *layout) {
|
||||
auto lblUserName = new QLabel(this);
|
||||
lblUserName->setText(tr("Name"));
|
||||
|
||||
mLeUserName->setPlaceholderText(tr("Input User name"));
|
||||
layout->addWidget(lblUserName);
|
||||
layout->addWidget(mLeUserName);
|
||||
addEndLine(layout);
|
||||
}
|
||||
|
||||
void AccountFormDialog::initUserCodeUI(QVBoxLayout *layout) {
|
||||
auto lblUserCode = new QLabel(this);
|
||||
lblUserCode->setText(tr("User ID"));
|
||||
|
||||
mLeUserCode->setPlaceholderText(tr("Input User ID"));
|
||||
if (mMode != New)mLeUserCode->setEnabled(false);
|
||||
layout->addWidget(lblUserCode);
|
||||
layout->addWidget(mLeUserCode);
|
||||
addEndLine(layout);
|
||||
}
|
||||
|
||||
void AccountFormDialog::addTitleLabel(QVBoxLayout *layout) {
|
||||
auto lblTitle = new QLabel(this);
|
||||
lblTitle->setAlignment(Qt::AlignCenter);
|
||||
lblTitle->setText(tr("Account"));
|
||||
lblTitle->setObjectName("title");
|
||||
layout->addWidget(lblTitle);
|
||||
}
|
||||
|
||||
void AccountFormDialog::addSelfModeUI(QHBoxLayout *hlayout) {
|
||||
auto btnLogout = new QToolButton(this);
|
||||
btnLogout->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
btnLogout->setIcon(QIcon(":/icons/logout.png"));
|
||||
btnLogout->setIconSize({30, 30});
|
||||
btnLogout->setText(tr("Logout"));
|
||||
btnLogout->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
btnLogout->setObjectName("editvalBtn");
|
||||
|
||||
hlayout->addWidget(btnLogout);
|
||||
connect(btnLogout, &QAbstractButton::clicked, [=]() {
|
||||
accept();
|
||||
LOG_USER_OPERATION(Logout)
|
||||
EventCenter::Default()->triggerEvent(RequestLogin, nullptr, nullptr);
|
||||
});
|
||||
// load current user data
|
||||
if (User::Current()) {
|
||||
mLeUserCode->setText(User::Current()->getUserCode());
|
||||
mLeUserName->setText(User::Current()->getUserName());
|
||||
mUserID = User::Current()->getUserID();
|
||||
mUserPwd = User::Current()->getPassword();
|
||||
}
|
||||
}
|
||||
|
||||
void AccountFormDialog::addNewModeUI(QVBoxLayout *layout) {
|
||||
auto lblPwd = new QLabel(this);
|
||||
lblPwd->setText(tr("Password"));
|
||||
layout->addWidget(lblPwd);
|
||||
mLePwd = new QLineEdit(this);
|
||||
mLePwd->setPlaceholderText(tr("Input password"));
|
||||
mLePwd->setEchoMode(QLineEdit::Password);
|
||||
layout->addWidget(mLePwd);
|
||||
mRoleID = User::getRoleID("doctor");
|
||||
addEndLine(layout);
|
||||
}
|
||||
|
||||
bool AccountFormDialog::updateReferenceData() {
|
||||
if (m_mode == Self) {
|
||||
if (!this->userNameChanged && !this->commentChanged) return true;
|
||||
if (!this->userNameChanged) {
|
||||
if (m_NewUserName.isEmpty()) {
|
||||
if (mMode == Self) {
|
||||
if (!this->mUserNameChanged && !this->mCommentChanged) return true;
|
||||
if (!this->mUserNameChanged) {
|
||||
if (mNewUserName.isEmpty()) {
|
||||
warn(tr("User Name can't be empty!"));
|
||||
return false;
|
||||
}
|
||||
User::Current()->setUserName(m_NewUserName);
|
||||
User::Current()->setUserName(mNewUserName);
|
||||
}
|
||||
if (!this->commentChanged) User::Current()->setUserName(le_Comment->text());
|
||||
if (!this->mCommentChanged) User::Current()->setUserName(mLeComment->text());
|
||||
bool ret = User::Current()->submitChange();
|
||||
if (ret) {
|
||||
hideWarn();
|
||||
LOG_USER_OPERATION(ChangeUserName);
|
||||
LOG_USER_OPERATION(ChangeUserName)
|
||||
}
|
||||
else {
|
||||
warn(tr("Submit change to database fail!"));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else if (m_mode == Admin) {
|
||||
if (!this->userNameChanged && !this->roleChanged) return true;
|
||||
else if (mMode == Admin) {
|
||||
if (!this->mUserNameChanged && !this->mRoleChanged) return true;
|
||||
User user;
|
||||
if (!User::getUser(m_UserID, user)) return true;
|
||||
if (this->userNameChanged) {
|
||||
if (m_NewUserName.isEmpty()) {
|
||||
if (!User::getUser(mUserID, user)) return true;
|
||||
if (this->mUserNameChanged) {
|
||||
if (mNewUserName.isEmpty()) {
|
||||
warn(tr("User Name can't be empty!"));
|
||||
return false;
|
||||
}
|
||||
user.setUserName(m_NewUserName);
|
||||
user.setUserName(mNewUserName);
|
||||
}
|
||||
if (this->roleChanged) user.setRoleID(m_RoleID);
|
||||
if (!this->commentChanged) user.setComment(le_Comment->text());
|
||||
if (this->mRoleChanged) user.setRoleID(mRoleID);
|
||||
if (!this->mCommentChanged) user.setComment(mLeComment->text());
|
||||
bool ret = user.submitChange();
|
||||
if (ret) {
|
||||
LOG_USER_OPERATION(AdminChangeAcountInformation);
|
||||
LOG_USER_OPERATION(AdminChangeAcountInformation)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
//add new
|
||||
User user;
|
||||
if (le_UserCode->text().isEmpty()) {
|
||||
warn(tr("User ID can't be empty!"));
|
||||
return false;
|
||||
}
|
||||
if (le_UserName->text().isEmpty()) {
|
||||
warn(tr("User Name can't be empty!"));
|
||||
return false;
|
||||
}
|
||||
if (le_Pwd->text().isEmpty()) {
|
||||
warn(tr("Password can't be empty!"));
|
||||
return false;
|
||||
}
|
||||
if (!refmodel) {
|
||||
warn(tr("Inner error ,unset data model!"));
|
||||
return false;
|
||||
}
|
||||
if (User::existsUser(le_UserCode->text())) {
|
||||
warn(tr("User Id exists!"));
|
||||
return false;
|
||||
}
|
||||
hideWarn();
|
||||
user.setUserName(le_UserName->text());
|
||||
user.setPassword(User::getEncryptedPassword(le_Pwd->text()));
|
||||
user.setRoleID(m_RoleID);
|
||||
user.setComment(le_Comment->text());
|
||||
// User::insertUser(le_UserCode->text(),user);
|
||||
//add new
|
||||
User user;
|
||||
if (mLeUserCode->text().isEmpty()) {
|
||||
warn(tr("User ID can't be empty!"));
|
||||
return false;
|
||||
}
|
||||
if (mLeUserName->text().isEmpty()) {
|
||||
warn(tr("User Name can't be empty!"));
|
||||
return false;
|
||||
}
|
||||
if (mLePwd->text().isEmpty()) {
|
||||
warn(tr("Password can't be empty!"));
|
||||
return false;
|
||||
}
|
||||
if (!mRefModel) {
|
||||
warn(tr("Inner error ,unset data model!"));
|
||||
return false;
|
||||
}
|
||||
if (User::existsUser(mLeUserCode->text())) {
|
||||
warn(tr("User Id exists!"));
|
||||
return false;
|
||||
}
|
||||
hideWarn();
|
||||
user.setUserName(mLeUserName->text());
|
||||
user.setPassword(User::getEncryptedPassword(mLePwd->text()));
|
||||
user.setRoleID(mRoleID);
|
||||
user.setComment(mLeComment->text());
|
||||
// User::insertUser(le_UserCode->text(),user);
|
||||
|
||||
refmodel->insertRow(0);
|
||||
refmodel->setData(refmodel->index(0, 0), QUuid::createUuid().toString());
|
||||
refmodel->setData(refmodel->index(0, 1), le_UserCode->text());
|
||||
mRefModel->insertRow(0);
|
||||
mRefModel->setData(mRefModel->index(0, 0), QUuid::createUuid().toString());
|
||||
mRefModel->setData(mRefModel->index(0, 1), mLeUserCode->text());
|
||||
#define USER_READONLY_PROPERTY(name) name,
|
||||
#define USER_PROPERTY(name)\
|
||||
USER_READONLY_PROPERTY(name)
|
||||
|
||||
enum user_index {
|
||||
USER_PROPERTIES_MACRO()
|
||||
};
|
||||
enum user_index {
|
||||
USER_PROPERTIES_MACRO()
|
||||
};
|
||||
#undef USER_READONLY_PROPERTY
|
||||
#undef USER_PROPERTY
|
||||
|
||||
#define USER_READONLY_PROPERTY(name)
|
||||
#define USER_PROPERTY(name)\
|
||||
USER_READONLY_PROPERTY(name)\
|
||||
refmodel->setData(refmodel->index(0, name),user.get##name());
|
||||
USER_PROPERTIES_MACRO()
|
||||
mRefModel->setData(mRefModel->index(0, name),user.get##name());
|
||||
USER_PROPERTIES_MACRO()
|
||||
#undef USER_READONLY_PROPERTY
|
||||
#undef USER_PROPERTY
|
||||
|
||||
if (refmodel->submit()) {
|
||||
hideWarn();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
warn(tr("Submit to data base fail!"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (mRefModel->submit()) {
|
||||
hideWarn();
|
||||
return true;
|
||||
} else {
|
||||
warn(tr("Submit to data base fail!"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AccountFormDialog::setAccountInformation(const QMap<QString, QVariant>& values) {
|
||||
le_UserCode->setText(values["UserCode"].toString());
|
||||
le_UserName->setText(values["UserName"].toString());
|
||||
le_Comment->setText(values["Comment"].toString());
|
||||
m_UserID = values["UserID"].toString();
|
||||
m_UserPwd = values["Password"].toString();
|
||||
mLeUserCode->setText(values["UserCode"].toString());
|
||||
mLeUserName->setText(values["UserName"].toString());
|
||||
mLeComment->setText(values["Comment"].toString());
|
||||
mUserID = values["UserID"].toString();
|
||||
mUserPwd = values["Password"].toString();
|
||||
}
|
||||
|
||||
void AccountFormDialog::warn(QString msg) {
|
||||
lbl_error->setText(msg);
|
||||
lbl_error->setVisible(true);
|
||||
void AccountFormDialog::warn(const QString& msg) {
|
||||
mLblError->setText(msg);
|
||||
mLblError->setVisible(true);
|
||||
}
|
||||
|
||||
void AccountFormDialog::hideWarn() {
|
||||
this->lbl_error->setVisible(false);
|
||||
mLblError->setVisible(false);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ class QLabel;
|
||||
class QLineEdit;
|
||||
class QToolButton;
|
||||
class QSqlTableModel;
|
||||
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
#include "GUIFormBaseDialog.h"
|
||||
|
||||
enum AccountEditMode{
|
||||
@@ -17,32 +19,44 @@ class AccountFormDialog:public GUIFormBaseDialog{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AccountFormDialog(QWidget *parent = nullptr,AccountEditMode mode = Self,Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~AccountFormDialog();
|
||||
~AccountFormDialog() override = default;
|
||||
void setAccountInformation(const QMap<QString,QVariant>& values);
|
||||
void setReferenceModel(QSqlTableModel* model){
|
||||
refmodel = model;
|
||||
mRefModel = model;
|
||||
}
|
||||
protected:
|
||||
bool updateReferenceData() override;
|
||||
void warn(QString msg);
|
||||
void warn(const QString& msg);
|
||||
void hideWarn();
|
||||
private:
|
||||
QString m_UserID;
|
||||
QString m_UserPwd;
|
||||
QString m_RoleID;
|
||||
QString m_NewUserName;
|
||||
bool userNameChanged = false;
|
||||
bool commentChanged = false;
|
||||
bool roleChanged = false;
|
||||
AccountEditMode m_mode = Self;
|
||||
QLineEdit* le_UserCode = nullptr;
|
||||
QLineEdit* le_UserName = nullptr;
|
||||
QLineEdit* le_Comment = nullptr;
|
||||
QLineEdit* le_Pwd = nullptr;
|
||||
QToolButton* btn_Pwd = nullptr;
|
||||
void addEndLine(QVBoxLayout *layout);
|
||||
void addNewModeUI(QVBoxLayout *layout);
|
||||
void addSelfModeUI(QHBoxLayout *layout);
|
||||
void addTitleLabel(QVBoxLayout *layout);
|
||||
void initUserCodeUI(QVBoxLayout *layout);
|
||||
void initUserNameUI(QVBoxLayout *layout);
|
||||
void addCommentLabel(QVBoxLayout *layout);
|
||||
void addWarnLabel(QVBoxLayout *layout);
|
||||
void addButtonPwd(QHBoxLayout *layout);
|
||||
void changeSelfPassword();
|
||||
void resetUserPassword();
|
||||
QString mUserID;
|
||||
QString mUserPwd;
|
||||
QString mRoleID;
|
||||
QString mNewUserName;
|
||||
bool mUserNameChanged;
|
||||
bool mCommentChanged;
|
||||
bool mRoleChanged;
|
||||
AccountEditMode mMode;
|
||||
QLineEdit* mLeUserCode;
|
||||
QLineEdit* mLeUserName;
|
||||
QLineEdit* mLeComment;
|
||||
QLineEdit* mLePwd;
|
||||
QToolButton* mBtnPwd;
|
||||
|
||||
QLabel* mLblError;
|
||||
QSqlTableModel* mRefModel;
|
||||
|
||||
QLabel* lbl_error = nullptr;
|
||||
QSqlTableModel* refmodel = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2,33 +2,31 @@
|
||||
// Created by Krad on 2021/12/8.
|
||||
//
|
||||
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
#include <QtWidgets/QLabel>
|
||||
#include "AlertDialog.h"
|
||||
|
||||
AlertDialog::AlertDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
#include <QtWidgets/QLabel>
|
||||
|
||||
AlertDialog::AlertDialog(QWidget *parent, Qt::WindowFlags f)
|
||||
: GUIFormBaseDialog(parent, f)
|
||||
, mLblMsg(new QLabel(this))
|
||||
, mLblTitle (new QLabel(this))
|
||||
{
|
||||
this->setFixedHeight(180);
|
||||
this->setFixedWidth(400);
|
||||
QVBoxLayout* layout = new QVBoxLayout(formWidget);
|
||||
auto layout = new QVBoxLayout(mFormWidget);
|
||||
layout->setSpacing(10);
|
||||
// add title
|
||||
lbl_title = new QLabel(this);
|
||||
lbl_title->setAlignment(Qt::AlignCenter);
|
||||
lbl_title->setText(tr("Warning"));
|
||||
lbl_title->setObjectName("title");
|
||||
layout->addWidget(lbl_title);
|
||||
lbl_msg = new QLabel(this);
|
||||
layout->addWidget(lbl_msg);
|
||||
}
|
||||
|
||||
AlertDialog::~AlertDialog() {
|
||||
|
||||
}
|
||||
mLblTitle->setAlignment(Qt::AlignCenter);
|
||||
mLblTitle->setText(tr("Warning"));
|
||||
mLblTitle->setObjectName("title");
|
||||
layout->addWidget(mLblTitle);
|
||||
layout->addWidget(mLblMsg);}
|
||||
|
||||
void AlertDialog::setAlertMessage(const QString &msg) {
|
||||
this->lbl_msg->setText(msg);
|
||||
mLblMsg->setText(msg);
|
||||
}
|
||||
|
||||
void AlertDialog::setTitle(const QString &msg) {
|
||||
lbl_title->setText(msg);
|
||||
mLblTitle->setText(msg);
|
||||
}
|
||||
|
||||
@@ -10,15 +10,15 @@ class AlertDialog :public GUIFormBaseDialog{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AlertDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~AlertDialog();
|
||||
~AlertDialog() override = default;
|
||||
void setAlertMessage(const QString& msg);
|
||||
void setTitle(const QString& msg);
|
||||
protected:
|
||||
bool updateReferenceData() override{return true;}
|
||||
|
||||
private:
|
||||
QLabel* lbl_msg;
|
||||
QLabel* lbl_title;
|
||||
QLabel* mLblMsg;
|
||||
QLabel* mLblTitle;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -9,82 +9,88 @@
|
||||
#include "log/UserOperationLog.h"
|
||||
#include "ChangePasswordFormDialog.h"
|
||||
|
||||
ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget* parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
||||
QVBoxLayout* layout = new QVBoxLayout(formWidget);
|
||||
layout->setSpacing(10);
|
||||
// add title
|
||||
QLabel* lbl_title = new QLabel(this);
|
||||
lbl_title->setAlignment(Qt::AlignCenter);
|
||||
lbl_title->setText(tr("Change Password"));
|
||||
lbl_title->setObjectName("title");
|
||||
layout->addWidget(lbl_title);
|
||||
|
||||
//add old password
|
||||
QLabel* lbl_Old = new QLabel(this);
|
||||
lbl_Old->setText(tr("Current Password"));
|
||||
pwd = new QLineEdit(this);
|
||||
pwd->setEchoMode(QLineEdit::Password);
|
||||
layout->addWidget(lbl_Old);
|
||||
layout->addWidget(pwd);
|
||||
QLabel* lbl_endline1 = new QLabel(this);
|
||||
lbl_endline1->setObjectName("endline");
|
||||
layout->addWidget(lbl_endline1);
|
||||
|
||||
//add new password
|
||||
QLabel* lbl_New = new QLabel(this);
|
||||
lbl_New->setText(tr("New Password"));
|
||||
new_pwd = new QLineEdit(this);
|
||||
new_pwd->setEchoMode(QLineEdit::Password);
|
||||
layout->addWidget(lbl_New);
|
||||
layout->addWidget(new_pwd);
|
||||
QLabel* lbl_endline2 = new QLabel(this);
|
||||
lbl_endline2->setObjectName("endline");
|
||||
layout->addWidget(lbl_endline2);
|
||||
|
||||
//add confirm password
|
||||
QLabel* lbl_Confirm = new QLabel(this);
|
||||
lbl_Confirm->setText(tr("Confirm Password"));
|
||||
confirm_pwd = new QLineEdit(this);
|
||||
confirm_pwd->setEchoMode(QLineEdit::Password);
|
||||
layout->addWidget(lbl_Confirm);
|
||||
layout->addWidget(confirm_pwd);
|
||||
QLabel* lbl_endline3 = new QLabel(this);
|
||||
lbl_endline3->setObjectName("endline");
|
||||
layout->addWidget(lbl_endline3);
|
||||
|
||||
lbl_error = new QLabel(this);
|
||||
lbl_error->setObjectName("warn");
|
||||
layout->addWidget(lbl_error);
|
||||
ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget* parent, Qt::WindowFlags f)
|
||||
: GUIFormBaseDialog(parent, f)
|
||||
, mLEPasswd(new QLineEdit(this))
|
||||
, mLENewPasswd(new QLineEdit(this))
|
||||
, mLEConfirmPasswd(new QLineEdit(this))
|
||||
, mLblError(new QLabel(this))
|
||||
{
|
||||
initLayout();
|
||||
}
|
||||
|
||||
ChangePasswordFormDialog::~ChangePasswordFormDialog() {
|
||||
void ChangePasswordFormDialog::initLayout() {
|
||||
auto layout = new QVBoxLayout(mFormWidget);
|
||||
layout->setSpacing(10);
|
||||
// add title
|
||||
auto lblTitle = new QLabel(this);
|
||||
lblTitle->setAlignment(Qt::AlignCenter);
|
||||
lblTitle->setText(tr("Change Password"));
|
||||
lblTitle->setObjectName("title");
|
||||
layout->addWidget(lblTitle);
|
||||
|
||||
//add old password
|
||||
auto lblOld = new QLabel(this);
|
||||
lblOld->setText(tr("Current Password"));
|
||||
|
||||
mLEPasswd->setEchoMode(QLineEdit::Password);
|
||||
layout->addWidget(lblOld);
|
||||
layout->addWidget(mLEPasswd);
|
||||
auto lblEndline1 = new QLabel(this);
|
||||
lblEndline1->setObjectName("endline");
|
||||
layout->addWidget(lblEndline1);
|
||||
|
||||
//add new password
|
||||
auto lblNewPasswd = new QLabel(this);
|
||||
lblNewPasswd->setText(tr("New Password"));
|
||||
|
||||
mLENewPasswd->setEchoMode(QLineEdit::Password);
|
||||
layout->addWidget(lblNewPasswd);
|
||||
layout->addWidget(mLENewPasswd);
|
||||
auto lblEndline2 = new QLabel(this);
|
||||
lblEndline2->setObjectName("endline");
|
||||
layout->addWidget(lblEndline2);
|
||||
|
||||
//add confirm password
|
||||
auto lblConfirm = new QLabel(this);
|
||||
lblConfirm->setText(tr("Confirm Password"));
|
||||
|
||||
mLEConfirmPasswd->setEchoMode(QLineEdit::Password);
|
||||
layout->addWidget(lblConfirm);
|
||||
layout->addWidget(mLEConfirmPasswd);
|
||||
auto lblEndline3 = new QLabel(this);
|
||||
lblEndline3->setObjectName("endline");
|
||||
layout->addWidget(lblEndline3);
|
||||
|
||||
mLblError->setObjectName("warn");
|
||||
layout->addWidget(mLblError);
|
||||
}
|
||||
|
||||
|
||||
bool ChangePasswordFormDialog::updateReferenceData() {
|
||||
if (pwd->text().isEmpty())
|
||||
if (mLEPasswd->text().isEmpty())
|
||||
{
|
||||
lbl_error->setText(tr("Please enter your old password!"));
|
||||
mLblError->setText(tr("Please enter your old password!"));
|
||||
return false;
|
||||
}
|
||||
if (new_pwd->text().length() < 6) {
|
||||
lbl_error->setText(tr("New password should at least 6 characters!"));
|
||||
if (mLENewPasswd->text().length() < 6) {
|
||||
mLblError->setText(tr("New password should at least 6 characters!"));
|
||||
return false;
|
||||
}
|
||||
QString encryptPwd = User::getEncryptedPassword(pwd->text());
|
||||
QString encryptPwd = User::getEncryptedPassword(mLEPasswd->text());
|
||||
if (encryptPwd != User::Current()->getPassword())
|
||||
{
|
||||
lbl_error->setText(tr("Wrong password!"));
|
||||
mLblError->setText(tr("Wrong password!"));
|
||||
return false;
|
||||
}
|
||||
if (new_pwd->text() != confirm_pwd->text())
|
||||
if (mLENewPasswd->text() != mLEConfirmPasswd->text())
|
||||
{
|
||||
lbl_error->setText(tr("Your new password does not match!"));
|
||||
mLblError->setText(tr("Your new password does not match!"));
|
||||
return false;
|
||||
}
|
||||
User::Current()->setPassword(User::getEncryptedPassword(new_pwd->text()));
|
||||
User::Current()->setPassword(User::getEncryptedPassword(mLENewPasswd->text()));
|
||||
if (!User::Current()->submitChange()) {
|
||||
lbl_error->setText(tr("Database update error!"));
|
||||
mLblError->setText(tr("Database update error!"));
|
||||
User::Current()->restorePassword(encryptPwd);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -12,16 +12,19 @@ class ChangePasswordFormDialog:public GUIFormBaseDialog{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ChangePasswordFormDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~ChangePasswordFormDialog();
|
||||
~ChangePasswordFormDialog() override = default;
|
||||
|
||||
protected:
|
||||
bool updateReferenceData() override;
|
||||
|
||||
private:
|
||||
QLineEdit* pwd = nullptr;
|
||||
QLineEdit* new_pwd = nullptr;
|
||||
QLineEdit* confirm_pwd = nullptr;
|
||||
QLabel* lbl_error = nullptr;
|
||||
void initLayout();
|
||||
QLineEdit* mLEPasswd;
|
||||
QLineEdit* mLENewPasswd;
|
||||
QLineEdit* mLEConfirmPasswd;
|
||||
QLabel* mLblError;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -3,63 +3,52 @@
|
||||
//
|
||||
|
||||
#include "GUIFormBaseDialog.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
GUIFormBaseDialog::GUIFormBaseDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) {
|
||||
GUIFormBaseDialog::GUIFormBaseDialog(QWidget* parent, Qt::WindowFlags f)
|
||||
: QDialog(parent, f)
|
||||
, mFormWidget(new QWidget(this))
|
||||
, mBtnWidget(new QWidget(this))
|
||||
, mBtnCancel(new QPushButton(tr("Cancel"), mBtnWidget))
|
||||
, mBtnOk(new QPushButton(tr("OK"), mBtnWidget))
|
||||
{
|
||||
this->setObjectName("formDialog");
|
||||
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
|
||||
// this->setFixedSize(500,600);
|
||||
this->setFixedWidth(500);
|
||||
this->formWidget = new QWidget(this);
|
||||
this->formWidget->setObjectName("formWidget");
|
||||
|
||||
QVBoxLayout* vLayout = new QVBoxLayout(this);
|
||||
// vLayout->setContentsMargins(680,100,680,100);
|
||||
vLayout->addWidget(formWidget);
|
||||
|
||||
QWidget* btnWidget = new QWidget(this);
|
||||
vLayout->addWidget(btnWidget);
|
||||
QHBoxLayout* hLayout = new QHBoxLayout(btnWidget);
|
||||
btnOk = new QPushButton(btnWidget);
|
||||
btnOk->setText(tr("OK"));
|
||||
btnCancel = new QPushButton(btnWidget);
|
||||
btnCancel->setText(tr("Cancel"));
|
||||
hLayout->addWidget(btnOk);
|
||||
hLayout->addWidget(btnCancel);
|
||||
btnOk->setObjectName("btnOK");
|
||||
connect(btnOk, &QPushButton::clicked, [t = this]() {
|
||||
if (t->updateReferenceData())
|
||||
t->accept();
|
||||
});
|
||||
connect(btnCancel, &QPushButton::clicked, [t = this]() {
|
||||
t->reject();
|
||||
});
|
||||
}
|
||||
|
||||
GUIFormBaseDialog::~GUIFormBaseDialog() {
|
||||
|
||||
this->mFormWidget->setObjectName("formWidget");
|
||||
auto vLayout = new QVBoxLayout(this);
|
||||
vLayout->addWidget(mFormWidget);
|
||||
vLayout->addWidget(mBtnWidget);
|
||||
auto hLayout = new QHBoxLayout(mBtnWidget);
|
||||
hLayout->addWidget(mBtnOk);
|
||||
hLayout->addWidget(mBtnCancel);
|
||||
mBtnOk->setObjectName("btnOK");
|
||||
connect(mBtnOk, &QPushButton::clicked, [=]() {
|
||||
if (updateReferenceData()) accept();
|
||||
});
|
||||
connect(mBtnCancel, &QPushButton::clicked, [=]() {
|
||||
reject();
|
||||
});
|
||||
}
|
||||
|
||||
void GUIFormBaseDialog::setButtonMode(DialogButtonMode mode) {
|
||||
switch (mode) {
|
||||
case OkOnly:
|
||||
{
|
||||
btnOk->setVisible(true);
|
||||
btnCancel->setVisible(false);
|
||||
return;
|
||||
}
|
||||
case OkAndCancel:
|
||||
{
|
||||
btnOk->setVisible(true);
|
||||
btnCancel->setVisible(true);
|
||||
return;
|
||||
}
|
||||
case None:
|
||||
default:
|
||||
{
|
||||
btnOk->setVisible(false);
|
||||
btnCancel->setVisible(false);
|
||||
}
|
||||
}
|
||||
case OkOnly: {
|
||||
mBtnOk->setVisible(true);
|
||||
mBtnCancel->setVisible(false);
|
||||
return;
|
||||
}
|
||||
case OkAndCancel: {
|
||||
mBtnOk->setVisible(true);
|
||||
mBtnCancel->setVisible(true);
|
||||
return;
|
||||
}
|
||||
case None:
|
||||
default: {
|
||||
mBtnOk->setVisible(false);
|
||||
mBtnCancel->setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,15 +13,16 @@ class GUIFormBaseDialog: public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GUIFormBaseDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~GUIFormBaseDialog();
|
||||
~GUIFormBaseDialog() override = default;
|
||||
void setButtonMode(DialogButtonMode mode);
|
||||
protected:
|
||||
virtual bool updateReferenceData(){
|
||||
return false;
|
||||
};
|
||||
QWidget* formWidget = nullptr;
|
||||
QPushButton* btnCancel = nullptr;
|
||||
QPushButton* btnOk = nullptr;
|
||||
QWidget* mFormWidget;
|
||||
QWidget* mBtnWidget;
|
||||
QPushButton* mBtnCancel;
|
||||
QPushButton* mBtnOk;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -3,20 +3,19 @@
|
||||
//
|
||||
|
||||
#include "SelectDialog.h"
|
||||
|
||||
#include "components/SlidePickerBox.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
SelectDialog::SelectDialog(QWidget* parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
||||
SelectDialog::SelectDialog(QWidget* parent, Qt::WindowFlags f)
|
||||
: GUIFormBaseDialog(parent, f)
|
||||
, mPickBox(new SlidePickerBox(mFormWidget))
|
||||
{
|
||||
|
||||
this->setFixedSize(360, 380);
|
||||
QVBoxLayout* layout = new QVBoxLayout(formWidget);
|
||||
box = new SlidePickerBox(formWidget);
|
||||
box->setObjectName("slider_one");
|
||||
layout->addWidget(box);
|
||||
|
||||
}
|
||||
|
||||
SelectDialog::~SelectDialog() {
|
||||
auto layout = new QVBoxLayout(mFormWidget);
|
||||
mPickBox->setObjectName("slider_one");
|
||||
layout->addWidget(mPickBox);
|
||||
|
||||
}
|
||||
|
||||
@@ -25,13 +24,13 @@ bool SelectDialog::updateReferenceData() {
|
||||
}
|
||||
|
||||
void SelectDialog::setValues(const QStringList& dates) {
|
||||
box->setItems(dates);
|
||||
mPickBox->setItems(dates);
|
||||
}
|
||||
|
||||
QString SelectDialog::getSelectedValue() {
|
||||
return box->getSelectedValue();
|
||||
return mPickBox->getSelectedValue();
|
||||
}
|
||||
|
||||
void SelectDialog::setSelectedValue(const QString& val) {
|
||||
box->setSelectedValue(val);
|
||||
mPickBox->setSelectedValue(val);
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ class SelectDialog :public GUIFormBaseDialog{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SelectDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~SelectDialog() override;
|
||||
~SelectDialog() override = default;
|
||||
void setValues(const QStringList& values);
|
||||
QString getSelectedValue();
|
||||
void setSelectedValue(const QString& val);
|
||||
protected:
|
||||
bool updateReferenceData() override;
|
||||
SlidePickerBox* box = nullptr;
|
||||
SlidePickerBox* mPickBox;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -4,40 +4,51 @@
|
||||
#include "event/EventCenter.h"
|
||||
#include <QToolButton>
|
||||
#include <QHBoxLayout>
|
||||
GUIMessageDialog::GUIMessageDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::GUIMessageDialog)
|
||||
GUIMessageDialog::GUIMessageDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, mUI(new Ui::GUIMessageDialog)
|
||||
, mBtnMain(new QToolButton(this))
|
||||
, mBtnAppend(new QToolButton(this))
|
||||
, mFrameIndex(0)
|
||||
, mTimerID(-1)
|
||||
, mPending(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
mUI->setupUi(this);
|
||||
this->setObjectName("MessageDialog");
|
||||
this->setWindowFlags (Qt :: FramelessWindowHint | Qt :: Dialog);
|
||||
this->showFullScreen ();
|
||||
ui->lbl_msg->setVisible(false);
|
||||
ui->lbl_progressicon->setVisible(false);
|
||||
btn_main = new QToolButton(this);
|
||||
btn_main->setObjectName("btn_main");
|
||||
btn_main->setVisible(false);
|
||||
btn_main->setText("OK");
|
||||
btn_Append = new QToolButton(this);
|
||||
btn_Append->setObjectName("btn_main");
|
||||
btn_Append->setVisible(false);
|
||||
btn_Append->setText("Stop");
|
||||
QWidget* btnContainer = new QWidget(this);
|
||||
QHBoxLayout* hlayout = new QHBoxLayout(btnContainer);
|
||||
hlayout->setMargin(0);
|
||||
hlayout->addWidget(btn_main);
|
||||
hlayout->addWidget(btn_Append);
|
||||
|
||||
ui->widget_2->layout()->addWidget(btnContainer);
|
||||
initBaseLayout();
|
||||
this->setWindowOpacity(0.6);
|
||||
for (int i=1; i<=6;i++)
|
||||
initLoadingFrameString();
|
||||
}
|
||||
|
||||
void GUIMessageDialog::initBaseLayout() {
|
||||
mUI->lblMsg->setVisible(false);
|
||||
mUI->lblProgressIcon->setVisible(false);
|
||||
mBtnMain->setObjectName("btn_main");
|
||||
mBtnMain->setVisible(false);
|
||||
mBtnMain->setText("OK");
|
||||
mBtnAppend->setObjectName("btn_main");
|
||||
mBtnAppend->setVisible(false);
|
||||
mBtnAppend->setText("Stop");
|
||||
auto btnContainer = new QWidget(this);
|
||||
auto hLayout = new QHBoxLayout(btnContainer);
|
||||
hLayout->setMargin(0);
|
||||
hLayout->addWidget(mBtnMain);
|
||||
hLayout->addWidget(mBtnAppend);
|
||||
|
||||
mUI->btnContainerWidget->layout()->addWidget(btnContainer);
|
||||
}
|
||||
|
||||
void GUIMessageDialog::initLoadingFrameString(){
|
||||
for (int i=1; i <= 6; i++)
|
||||
{
|
||||
QString str(" ");
|
||||
for(int j=0;j<i;j++)
|
||||
{
|
||||
str[j]='.';
|
||||
}
|
||||
frame.append(str);
|
||||
mFrame.append(str);
|
||||
}
|
||||
for (int i=1; i<=6;i++)
|
||||
{
|
||||
@@ -46,60 +57,60 @@ GUIMessageDialog::GUIMessageDialog(QWidget *parent) :
|
||||
{
|
||||
str[j]=' ';
|
||||
}
|
||||
frame.append(str);
|
||||
mFrame.append(str);
|
||||
}
|
||||
}
|
||||
|
||||
GUIMessageDialog::~GUIMessageDialog()
|
||||
{
|
||||
delete ui;
|
||||
delete mUI;
|
||||
}
|
||||
|
||||
void GUIMessageDialog::timerEvent(QTimerEvent *event) {
|
||||
if (frameIndex>11) frameIndex = frameIndex % 12;
|
||||
ui->lbl_progressicon->setText(frame[frameIndex++]);
|
||||
if (mFrameIndex > 11) mFrameIndex = mFrameIndex % 12;
|
||||
mUI->lblProgressIcon->setText(mFrame[mFrameIndex++]);
|
||||
this->update();
|
||||
}
|
||||
|
||||
void GUIMessageDialog::stopLoading() {
|
||||
if (timerID!=-1){
|
||||
killTimer(timerID);
|
||||
timerID=-1;
|
||||
if (mTimerID != -1){
|
||||
killTimer(mTimerID);
|
||||
mTimerID=-1;
|
||||
}
|
||||
disconnect(btn_main,0,0,0);
|
||||
ui->lbl_progressicon->setVisible(false);
|
||||
disconnect(mBtnMain, nullptr, nullptr, nullptr);
|
||||
mUI->lblProgressIcon->setVisible(false);
|
||||
}
|
||||
|
||||
void GUIMessageDialog::startLoading() {
|
||||
ui->lbl_progressicon->setVisible(true);
|
||||
disconnect(btn_main,0,0,0);
|
||||
connect(btn_main,&QToolButton::clicked,[=](){
|
||||
if (timerID != -1){
|
||||
killTimer(timerID);
|
||||
timerID = -1;
|
||||
mUI->lblProgressIcon->setVisible(true);
|
||||
disconnect(mBtnMain, nullptr, nullptr, nullptr);
|
||||
connect(mBtnMain, &QToolButton::clicked, [=](){
|
||||
if (mTimerID != -1){
|
||||
killTimer(mTimerID);
|
||||
mTimerID = -1;
|
||||
}
|
||||
accept();
|
||||
EventCenter::Default()->triggerEvent(GUIEvents::RequestStop, nullptr, nullptr);
|
||||
LOG_USER_OPERATION(Stop);
|
||||
});
|
||||
timerID = startTimer(100);
|
||||
btn_main->setText("Stop");
|
||||
btn_main->setVisible(true);
|
||||
mTimerID = startTimer(100);
|
||||
mBtnMain->setText("Stop");
|
||||
mBtnMain->setVisible(true);
|
||||
}
|
||||
|
||||
void GUIMessageDialog::showMessage(QString msg) {
|
||||
ui->lbl_msg->setVisible(true);
|
||||
ui->lbl_msg->setText(msg);
|
||||
void GUIMessageDialog::showMessage(const QString& msg) {
|
||||
mUI->lblMsg->setVisible(true);
|
||||
mUI->lblMsg->setText(msg);
|
||||
}
|
||||
|
||||
void GUIMessageDialog::showExitButton() {
|
||||
btn_main->setText("OK");
|
||||
btn_main->setVisible(true);
|
||||
disconnect(btn_main,0,0,0);
|
||||
connect(btn_main,&QToolButton::clicked,[=](){
|
||||
if (timerID != -1){
|
||||
killTimer(timerID);
|
||||
timerID = -1;
|
||||
mBtnMain->setText("OK");
|
||||
mBtnMain->setVisible(true);
|
||||
disconnect(mBtnMain, nullptr, nullptr, nullptr);
|
||||
connect(mBtnMain, &QToolButton::clicked, [=](){
|
||||
if (mTimerID != -1){
|
||||
killTimer(mTimerID);
|
||||
mTimerID = -1;
|
||||
}
|
||||
accept();
|
||||
LOG_USER_OPERATION(ConfirmError);
|
||||
@@ -107,13 +118,13 @@ void GUIMessageDialog::showExitButton() {
|
||||
}
|
||||
|
||||
void GUIMessageDialog::hideMessage() {
|
||||
ui->lbl_msg->setVisible(false);
|
||||
ui->lbl_msg->setText("");
|
||||
mUI->lblMsg->setVisible(false);
|
||||
mUI->lblMsg->setText("");
|
||||
}
|
||||
|
||||
void GUIMessageDialog::hideExitButton() {
|
||||
btn_main->setVisible(false);
|
||||
disconnect(btn_main,0,0,0);
|
||||
mBtnMain->setVisible(false);
|
||||
disconnect(mBtnMain, nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void GUIMessageDialog::setOpacity(double opacity) {
|
||||
@@ -121,18 +132,18 @@ void GUIMessageDialog::setOpacity(double opacity) {
|
||||
}
|
||||
|
||||
void GUIMessageDialog::startPending() {
|
||||
disconnect(btn_Append,0,0,0);
|
||||
connect(btn_Append,&QToolButton::clicked,[=](){
|
||||
disconnect(mBtnAppend, nullptr, nullptr, nullptr);
|
||||
connect(mBtnAppend, &QToolButton::clicked, [=](){
|
||||
EventCenter::Default()->triggerEvent(GUIEvents::RequestContinueScan, nullptr, nullptr);
|
||||
stopPending();
|
||||
});
|
||||
btn_Append->setText("Next");
|
||||
btn_Append->setVisible(true);
|
||||
pending = true;
|
||||
mBtnAppend->setText("Next");
|
||||
mBtnAppend->setVisible(true);
|
||||
mPending = true;
|
||||
}
|
||||
|
||||
void GUIMessageDialog::stopPending() {
|
||||
disconnect(btn_Append,0,0,0);
|
||||
btn_Append->setVisible(false);
|
||||
pending = false;
|
||||
disconnect(mBtnAppend, nullptr, nullptr, nullptr);
|
||||
mBtnAppend->setVisible(false);
|
||||
mPending = false;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ class GUIMessageDialog : public QDialog
|
||||
|
||||
public:
|
||||
explicit GUIMessageDialog(QWidget *parent = nullptr);
|
||||
~GUIMessageDialog();
|
||||
void showMessage(QString msg);
|
||||
~GUIMessageDialog() override;
|
||||
void showMessage(const QString& msg);
|
||||
void hideMessage();
|
||||
void showExitButton();
|
||||
void hideExitButton();
|
||||
@@ -23,19 +23,21 @@ public:
|
||||
void startPending();
|
||||
void stopPending();
|
||||
bool Pending(){
|
||||
return pending;
|
||||
return mPending;
|
||||
}
|
||||
void setOpacity(double);
|
||||
protected:
|
||||
void timerEvent(QTimerEvent* event) override ;
|
||||
private:
|
||||
Ui::GUIMessageDialog *ui;
|
||||
QList<QString> frame;
|
||||
QToolButton *btn_main;
|
||||
QToolButton *btn_Append;
|
||||
int frameIndex=0;
|
||||
int timerID = -1;
|
||||
bool pending = false;
|
||||
void initBaseLayout();
|
||||
void initLoadingFrameString();
|
||||
Ui::GUIMessageDialog *mUI;
|
||||
QList<QString> mFrame;
|
||||
QToolButton *mBtnMain;
|
||||
QToolButton *mBtnAppend;
|
||||
int mFrameIndex;
|
||||
int mTimerID;
|
||||
bool mPending;
|
||||
};
|
||||
|
||||
#endif // GUIMESSAGEDIALOG_H
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<widget class="QWidget" name="innerWidget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<widget class="QWidget" name="btnContainerWidget" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
@@ -58,7 +58,7 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lbl_msg">
|
||||
<widget class="QLabel" name="lblMsg">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
@@ -71,7 +71,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lbl_progressicon">
|
||||
<widget class="QLabel" name="lblProgressIcon">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
|
||||
Reference in New Issue
Block a user