-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpasswordlineedit.cpp
More file actions
122 lines (116 loc) · 3.94 KB
/
passwordlineedit.cpp
File metadata and controls
122 lines (116 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "passwordlineedit.h"
PasswordLineEdit::PasswordLineEdit(QWidget *parent) : QLineEdit(parent)
{
setEchoMode(QLineEdit::Password);
m_changeStatusBtn = new QPushButton(this);
m_workLayout = new QHBoxLayout;
m_svgHandler = new SVGHandler(this);
m_changeStatusBtn->setCursor(Qt::PointingHandCursor);
m_changeStatusBtn->setCheckable(true);
m_changeStatusBtn->setFlat(true);
m_changeStatusBtn->setFixedSize(32,32);
QPixmap pixmap = m_svgHandler->loadSvg(":/new/image/invisible.svg");
m_changeStatusBtn->setIcon(pixmap);
connect(m_changeStatusBtn,&QPushButton::toggled,[this] (bool checked) {
if(checked) {
setEchoMode(QLineEdit::Normal);
QPixmap pixmap = m_svgHandler->loadSvg(":/new/image/visible.svg");
m_changeStatusBtn->setIcon(pixmap);
} else {
setEchoMode(QLineEdit::Password);
QPixmap pixmap = m_svgHandler->loadSvg(":/new/image/invisible.svg");
m_changeStatusBtn->setIcon(pixmap);
}
}); //点击后可见或者不可见
m_changeStatusBtn->setStyleSheet("QPushButton{width: 16px;height: 16px;qproperty-flat: true;"
"margin-right: 8px;border: none;border-width: 0;"
"background: transparent;}");
m_workLayout->addStretch();
m_workLayout->addWidget(m_changeStatusBtn);
m_workLayout->setMargin(0);
connect(this,&PasswordLineEdit::textChanged,[this] (const QString &text) {
bool uper = false;
bool normal = false;
bool number = false;
bool line = false;
for(QChar c:text) {
if(c>='A' && c <= 'Z') {
uper = true;
continue;
}
if(c>='a' && c <='z') {
normal = true;
continue;
}
if(c>='0' && c<='9') {
number = true;
continue;
}
}
if(text.length() >= 6) {
line = true;
}
bool ok = uper && number && line == true ?true:normal && number && line;
if(ok) {
emit verify_text();
} else {
emit false_text();
}
});
m_changeStatusBtn->setFocusPolicy(Qt::NoFocus);
setLayout(m_workLayout);
}
/* 获取密码显示按钮 */
QPushButton* PasswordLineEdit::get_visble() {
return m_changeStatusBtn;
}
/* 密码检测模块 */
bool PasswordLineEdit::check() {
bool uper = false;
bool normal = false;
bool number = false;
bool line = false;
if(this->text() != "") {
QString str = this->text();
for(QChar c:str) {
if(c>='A' && c <= 'Z') {
uper = true;
continue;
}
if(c>='a' && c <='z') {
normal = true;
continue;
}
if(c>='0' && c<='9') {
number = true;
continue;
}
}
if(text().length() >= 6) {
line = true;
}
} else {
return false;
}
bool ok = uper && number && line == true ?true:normal && number && line;
return ok;
}