| 1 |
/* |
| 2 |
* |
| 3 |
* |
| 4 |
* Copyright (C) 2023, KylinSoft Co., Ltd. |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 3 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* Authors: Zhen Sun <[email protected]> |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "widget.h" |
| 24 |
#include <QBoxLayout> |
| 25 |
|
| 26 |
Widget::Widget(QWidget *parent) |
| 27 |
: KWidget(parent) |
| 28 |
{ |
| 29 |
QVBoxLayout *vLayout = new QVBoxLayout(); |
| 30 |
QHBoxLayout *hLayout = new QHBoxLayout(); |
| 31 |
m_pInfoLabel = new QLabel("请设置密码:", this); |
| 32 |
m_pLineEdit = new QLineEdit(this); |
| 33 |
m_pLineEdit->setEchoMode(QLineEdit::Password); |
| 34 |
hLayout->addWidget(m_pInfoLabel); |
| 35 |
hLayout->addWidget(m_pLineEdit); |
| 36 |
vLayout->addStretch(); |
| 37 |
vLayout->addLayout(hLayout); |
| 38 |
hLayout = new QHBoxLayout(); |
| 39 |
m_pBar = new KSecurityLevelBar(this); // 构建一个安全等级提示条 |
| 40 |
m_pBar->hide(); // 隐藏安全等级提示条 |
| 41 |
hLayout->addWidget(m_pBar); |
| 42 |
vLayout->addLayout(hLayout); |
| 43 |
vLayout->addStretch(); |
| 44 |
baseBar()->setLayout(vLayout); |
| 45 |
|
| 46 |
// 连接槽函数,根据输入密码的长度来设置安全等级进度条的等级并显示。 |
| 47 |
connect(m_pLineEdit, &QLineEdit::textChanged, this, [=]() { |
| 48 |
int length = m_pLineEdit->text().length(); |
| 49 |
if (length < 8) |
| 50 |
m_pBar->setSecurityLevel(SecurityLevel::Low); // 设置安全等级 |
| 51 |
else if (length >= 8 && length < 12) |
| 52 |
m_pBar->setSecurityLevel(SecurityLevel::Medium); |
| 53 |
else |
| 54 |
m_pBar->setSecurityLevel(SecurityLevel::High); |
| 55 |
m_pBar->show(); |
| 56 |
}); |
| 57 |
} |
| 58 |
|
| 59 |
Widget::~Widget() |
| 60 |
{ |
| 61 |
} |