1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "loggindialog.h"
6
7#include <QPushButton>
8
9LogginDialog::LogginDialog(QWidget *parent, Qt::WindowFlags f)
10 : QDialog(parent, f)
11 , titleLabel(new QLabel())
12 , nameEdit(new QLineEdit())
13 , passwdEdit(new QLineEdit())
14 , pbtOk(new QPushButton(QPushButton::tr("Ok")))
15{
16 setWindowFlag(Qt::FramelessWindowHint);
17 QHBoxLayout *hLayoutPbt = new QHBoxLayout();
18 QVBoxLayout *vLayoutMain = new QVBoxLayout();
19
20 QFont font1;
21 font1.setBold(true);
22 font1.setWeight(QFont::Bold);
23 titleLabel->setFont(font1);
24 titleLabel->setObjectName("HeaderTitle");
25 titleLabel->setAlignment(Qt::AlignCenter);
26 pbtOk->setFixedWidth(60);
27 pbtOk->setEnabled(false);
28 nameEdit->setPlaceholderText("User");
29 passwdEdit->setPlaceholderText("Password");
30 passwdEdit->setEchoMode(QLineEdit::EchoMode::Password);
31 QObject::connect(nameEdit, &QLineEdit::textChanged, [=](const QString &text){
32 Q_UNUSED(text);
33 if (!nameEdit->text().isEmpty() && !passwdEdit->text().isEmpty()){
34 pbtOk->setEnabled(true);
35 } else {
36 pbtOk->setEnabled(false);
37 }
38 });
39 QObject::connect(passwdEdit, &QLineEdit::textChanged, [=](const QString &text){
40 Q_UNUSED(text);
41 if (!nameEdit->text().isEmpty() && !passwdEdit->text().isEmpty()){
42 pbtOk->setEnabled(true);
43 } else {
44 pbtOk->setEnabled(false);
45 }
46 });
47 QObject::connect(pbtOk, &QPushButton::pressed, this, &LogginDialog::logginOk);
48
49 hLayoutPbt->addStrut(10);
50 hLayoutPbt->addWidget(pbtOk);
51 hLayoutPbt->setAlignment(Qt::AlignRight);
52 vLayoutMain->addWidget(titleLabel);
53 vLayoutMain->addWidget(nameEdit);
54 vLayoutMain->addWidget(passwdEdit);
55 vLayoutMain->addLayout(hLayoutPbt);
56 setLayout(vLayoutMain);
57}
58
59void LogginDialog::setName(const QString &name)
60{
61 nameEdit->setText(name);
62}
63
64QString LogginDialog::name() const
65{
66 return nameEdit->text();
67}
68
69void LogginDialog::setPasswd(const QString &name)
70{
71 passwdEdit->setText(name);
72}
73
74QString LogginDialog::passwd() const
75{
76 return passwdEdit->text();
77}
78
79void LogginDialog::setTitleText(const QString &name)
80{
81 titleLabel->setText(name);
82}
83
84QString LogginDialog::titleText() const
85{
86 return titleLabel->text();
87}
88