#include "dp4loginwidget.h" #include #include #include #include #include #include #include #include #include #include #include #include Dp4LoginWidget::Dp4LoginWidget(QWidget *parent) : QWidget(parent) , m_environment(nullptr) , m_username(nullptr) , m_password(nullptr) { initUi(); } Dp4LoginWidget::~Dp4LoginWidget() { } void Dp4LoginWidget::Logon() { QMessageBox(QMessageBox::Information, tr("Logon"), tr("Environment:") + m_environment->currentText() + "\n" + tr("Username:") + m_username->text() + "\nPassword:" + m_password->text()).exec(); } void Dp4LoginWidget::ResetPassword() { QMessageBox(QMessageBox::Information,tr("Forget Password"),tr("Forget Password")).exec(); // QMessageBox(QMessageBox::Information,QIcon::themeName(),QIcon::themeSearchPaths().join("\n")).exec(); } void Dp4LoginWidget::initUi() { m_topWidget = new QWidget(this); m_layout = new QVBoxLayout(m_topWidget); m_layout->setContentsMargins(100, 0, 100, 0);//left,top,right,bottom QPixmap pixmap(USER_ICON); m_labelImage = new QLabel(m_topWidget); m_labelImage->setPixmap(pixmap); m_labelImage->setMinimumHeight(pixmap.height()); m_layout->addWidget(m_labelImage, 0, Qt::AlignHCenter); 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->setStyleSheet("background-color:royalblue;"); m_layout->addWidget(m_username); m_password = new QLineEdit(m_topWidget); m_password->setPlaceholderText(tr("Password")); m_password->setEchoMode(QLineEdit::PasswordEchoOnEdit); m_password->setStyleSheet("background-color:royalblue;"); connect(m_password->addAction(QIcon::fromTheme("media-playback-start"), QLineEdit::TrailingPosition), &QAction::triggered, this, [=](){this->Logon();}); m_layout->addWidget(m_password); m_environment = new QComboBox(m_topWidget); m_environment->addItem(tr("Production")); m_environment->addItem(tr("Development")); m_environment->setStyleSheet("background-color:royalblue;"); m_layout->addWidget(m_environment); m_pbForgetPassword = new QPushButton(tr("Forget Password"), m_topWidget); m_pbForgetPassword->setFlat(true); connect(m_pbForgetPassword, &QPushButton::released, this, [this] { this->ResetPassword(); }); 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(tr("'Unauthorized use of this Computer Terminal is a Criminal Offence under the Laws of Hong Kong.'")); m_labelText = new QLabel(m_topWidget); m_labelText->setWordWrap(true); m_labelText->setText(warningText); 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); }