修复登录界面的返回类型

master
donghualin 2 years ago
parent 3d6bdadaac
commit fa00de132e
  1. 9
      dp4-login-plugin/dp4_login_module.cpp
  2. 3
      dp4-login-plugin/dp4_login_module.h
  3. 69
      dp4-login-plugin/dp4loginwidget.cpp
  4. 9
      dp4-login-plugin/dp4loginwidget.h
  5. 1
      example/loginwidget.cpp

@ -17,11 +17,9 @@ Dp4LoginModule::Dp4LoginModule(QObject *parent)
, m_callbackFun(nullptr) , m_callbackFun(nullptr)
, m_callbackData(new AuthCallbackData) , m_callbackData(new AuthCallbackData)
, m_messageCallbackFunc(nullptr) , m_messageCallbackFunc(nullptr)
, m_dp4Widget(nullptr)
{ {
setObjectName(QStringLiteral("Dp4LoginModule")); setObjectName(QStringLiteral("Dp4LoginModule"));
installTranslator(); installTranslator();
m_dp4Widget = new Dp4LoginWidget;
// 以下部分爲測試代碼,具體如何寫請根據實際的業務來處理即可 // 以下部分爲測試代碼,具體如何寫請根據實際的業務來處理即可
/*m_callbackData->account = "uos"; /*m_callbackData->account = "uos";
m_callbackData->token = "1"; m_callbackData->token = "1";
@ -42,7 +40,9 @@ void Dp4LoginModule::init()
QWidget *Dp4LoginModule::content() QWidget *Dp4LoginModule::content()
{ {
return m_dp4Widget; // 此处返回窗体必须从此处创建,因为该插件是在子线程中加载,而窗体需要在主线程中显示,因此此处第一次获取的时候再返回它的窗体即可
static Dp4LoginWidget dp4Widget;
return &dp4Widget;
} }
void Dp4LoginModule::reset() void Dp4LoginModule::reset()
@ -96,7 +96,10 @@ std::string Dp4LoginModule::onMessage(const std::string &message)
retDataObj["ShowSwitchButton"] = false; retDataObj["ShowSwitchButton"] = false;
retDataObj["ShowLockButton"] = false; retDataObj["ShowLockButton"] = false;
retDataObj["DefaultAuthLevel"] = DefaultAuthLevel::StrongDefault; retDataObj["DefaultAuthLevel"] = DefaultAuthLevel::StrongDefault;
retDataObj["showBackGroundColor"] = false;
retDataObj["AuthType"] = AuthType::AT_Custom; retDataObj["AuthType"] = AuthType::AT_Custom;
retDataObj["width"] = content()->width();
retDataObj["height"] = content()->height();
retObj["Data"] = retDataObj; retObj["Data"] = retDataObj;
} else if (cmdType == "StartAuth") { } else if (cmdType == "StartAuth") {

@ -26,7 +26,7 @@ public:
void init() override; void init() override;
ModuleType type() const override ModuleType type() const override
{ return IpcAssistLoginType; } { return CustomLoginType; }
inline QString key() const override inline QString key() const override
{ return "dp4-login"; } { return "dp4-login"; }
QWidget *content() override; QWidget *content() override;
@ -42,7 +42,6 @@ private:
AuthCallbackFun m_callbackFun; AuthCallbackFun m_callbackFun;
AuthCallbackData *m_callbackData; AuthCallbackData *m_callbackData;
MessageCallbackFun m_messageCallbackFunc; MessageCallbackFun m_messageCallbackFunc;
Dp4LoginWidget *m_dp4Widget;
}; };
} }

@ -9,6 +9,7 @@
#include <QAction> #include <QAction>
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton> #include <QPushButton>
#include <QEvent>
#include <QDebug> #include <QDebug>
Dp4LoginWidget::Dp4LoginWidget(QWidget *parent) Dp4LoginWidget::Dp4LoginWidget(QWidget *parent)
@ -37,37 +38,59 @@ void Dp4LoginWidget::ResetPassword()
void Dp4LoginWidget::initUi() void Dp4LoginWidget::initUi()
{ {
QWidget *top = new QWidget(this); m_topWidget = new QWidget(this);
m_layout = new QVBoxLayout(m_topWidget);
QVBoxLayout *layout = new QVBoxLayout(this); m_layout->setContentsMargins(100, 0, 100, 0);//left,top,right,bottom
layout->setContentsMargins(100,0,100,50);//left,top,right,bottom QPixmap pixmap(USER_ICON);
QLabel *pic = new QLabel(top); m_labelImage = new QLabel(m_topWidget);
pic->setPixmap(QPixmap(USER_ICON)); m_labelImage->setPixmap(pixmap);
layout->addWidget(pic, 0, Qt::AlignCenter); m_labelImage->setMinimumHeight(pixmap.height());
layout->addWidget(new QLabel(tr("Other User")), 0, Qt::AlignCenter); m_layout->addWidget(m_labelImage, 0, Qt::AlignHCenter);
m_username = new QLineEdit(top); m_labelOtherUser = new QLabel(tr("Other User"), this);
m_layout->addWidget(m_labelOtherUser, 0, Qt::AlignCenter);
m_username = new QLineEdit(m_topWidget);
m_username->setPlaceholderText(tr("Username")); m_username->setPlaceholderText(tr("Username"));
m_username->setStyleSheet("background-color:royalblue;"); m_username->setStyleSheet("background-color:royalblue;");
layout->addWidget(m_username); m_layout->addWidget(m_username);
m_password = new QLineEdit(top); m_password = new QLineEdit(m_topWidget);
m_password->setPlaceholderText(tr("Password")); m_password->setPlaceholderText(tr("Password"));
m_password->setEchoMode(QLineEdit::PasswordEchoOnEdit); m_password->setEchoMode(QLineEdit::PasswordEchoOnEdit);
m_password->setStyleSheet("background-color:royalblue;"); m_password->setStyleSheet("background-color:royalblue;");
connect(m_password->addAction(QIcon::fromTheme("media-playback-start"),QLineEdit::TrailingPosition), &QAction::triggered, this, [=](){this->Logon();}); connect(m_password->addAction(QIcon::fromTheme("media-playback-start"), QLineEdit::TrailingPosition), &QAction::triggered, this, [=](){this->Logon();});
layout->addWidget(m_password); m_layout->addWidget(m_password);
m_environment = new QComboBox(top); m_environment = new QComboBox(m_topWidget);
m_environment->addItem(tr("Production")); m_environment->addItem(tr("Production"));
m_environment->addItem(tr("Development")); m_environment->addItem(tr("Development"));
m_environment->setStyleSheet("background-color:royalblue;"); m_environment->setStyleSheet("background-color:royalblue;");
layout->addWidget(m_environment); m_layout->addWidget(m_environment);
QPushButton *pb = new QPushButton(tr("Forget Password"),top); m_pbForgetPassword = new QPushButton(tr("Forget Password"), m_topWidget);
pb->setFlat(true); m_pbForgetPassword->setFlat(true);
connect(pb, &QPushButton::released,this,[=](){ this->ResetPassword(); }); connect(m_pbForgetPassword, &QPushButton::released, this, [this] { this->ResetPassword(); });
layout->addWidget(pb); m_layout->addWidget(m_pbForgetPassword);
QString warningText = QString(tr("When you click the '➔' button or press 'Enter', indicates you understand and accept the following usage policy.")) + "\n\n" QString warningText = QString(tr("When you click the '➔' button or press 'Enter', indicates you understand and accept the following usage policy.")) + "\n\n"
+ QString(tr("'Unauthorized use of this Computer Terminal is a Criminal Offence under the Laws of Hong Kong.'")); + QString(tr("'Unauthorized use of this Computer Terminal is a Criminal Offence under the Laws of Hong Kong.'"));
QLabel *labelText = new QLabel(top); m_labelText = new QLabel(m_topWidget);
labelText->setWordWrap(true); m_labelText->setWordWrap(true);
labelText->setText(warningText); m_labelText->setText(warningText);
layout->addWidget(labelText); m_layout->addWidget(m_labelText);
m_layout->addStretch();
m_labelText->installEventFilter(this);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(m_topWidget);
}
bool Dp4LoginWidget::eventFilter(QObject *watchd, QEvent *event)
{
if (watchd == m_labelText && event->type() == QEvent::Resize) {
int height = m_labelImage->height() + m_labelOtherUser->height() +
m_username->height() + m_password->height() +
m_environment->height() + m_pbForgetPassword->height() +
m_labelText->height() + m_layout->spacing() * 6 +
m_layout->contentsMargins().top() + m_layout->contentsMargins().bottom();
m_topWidget->setFixedHeight(height);
}
return QWidget::eventFilter(watchd, event);
} }

@ -9,17 +9,24 @@ class Dp4LoginWidget : public QWidget
public: public:
explicit Dp4LoginWidget(QWidget *parent = nullptr); explicit Dp4LoginWidget(QWidget *parent = nullptr);
~Dp4LoginWidget(); ~Dp4LoginWidget() override;
private: private:
void Logon(); void Logon();
void ResetPassword(); void ResetPassword();
void initUi(); void initUi();
bool eventFilter(QObject *watchd, QEvent *event) override;
private: private:
QWidget *m_topWidget;
class QLabel *m_labelImage;
QLabel *m_labelOtherUser;
QLabel *m_labelText;
class QVBoxLayout *m_layout;
class QComboBox *m_environment; class QComboBox *m_environment;
class QLineEdit *m_username; class QLineEdit *m_username;
class QLineEdit *m_password; class QLineEdit *m_password;
class QPushButton *m_pbForgetPassword;
}; };
#endif // TESTWIDGET_H #endif // TESTWIDGET_H

@ -15,4 +15,5 @@ LoginWidget::LoginWidget(QWidget *parent)
LoginWidget::~LoginWidget() LoginWidget::~LoginWidget()
{ {
m_dp4module->content()->setParent(nullptr);
} }

Loading…
Cancel
Save