1
1
#include " lock.h"
2
2
#include " ui_lock.h"
3
3
#include < QDebug>
4
- #include < QKeyEvent>
5
- #ifdef Q_OS_WIN32
6
- #include < Windows.h>
7
- #else
8
- #include < X11/XKBlib.h> // apt install libx11-dev
9
-
10
4
#include < QGraphicsOpacityEffect>
5
+ #include < QKeyEvent>
11
6
#include < QPropertyAnimation>
12
- #endif
7
+
8
+ #include " X11/XKBlib.h" // keep this header at bottom
13
9
14
10
Lock::Lock (QWidget *parent) : QWidget(parent), ui(new Ui::Lock) {
15
11
ui->setupUi (this );
@@ -20,76 +16,100 @@ Lock::Lock(QWidget *parent) : QWidget(parent), ui(new Ui::Lock) {
20
16
QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect (this );
21
17
ui->centerWidget ->setGraphicsEffect (eff);
22
18
23
- animate ();
19
+ animateIn ();
24
20
25
21
if (settings.value (" asdfg" ).isValid () == false ) {
26
22
signUp ();
27
23
} else {
28
24
lock_app ();
29
25
}
30
26
checkCaps ();
31
- QString capsStyle = QString (" background-color: palette(window);"
32
- " padding:4px;"
33
- " border-radius: 2px;"
34
- " color:palette(window-text);" );
27
+ QString capsStyle = QString (R"( background-color: palette(window);
28
+ padding: 4px;
29
+ border-radius: 2px;
30
+ color: palette(window-text);) " );
35
31
ui->caps1 ->setStyleSheet (capsStyle);
36
32
ui->caps2 ->setStyleSheet (capsStyle);
37
33
ui->signup_warning ->setStyleSheet (capsStyle);
38
34
ui->wrong ->setStyleSheet (capsStyle);
39
35
foreach (QLineEdit *le, this ->findChildren <QLineEdit *>()) {
40
- le->setStyleSheet (
41
- " QLineEdit[echoMode=\" 2\" ]{lineedit-password-character: 9899}" );
36
+ le->setStyleSheet (R"( QLineEdit[echoMode="2"]{
37
+ lineedit-password-character: 9899;
38
+ })" );
42
39
}
43
40
}
44
41
45
42
void Lock::signUp () {
46
43
isLocked = false ;
47
44
ui->signup ->show ();
48
45
ui->login ->hide ();
49
- animate ();
46
+ animateIn ();
50
47
ui->passcode1 ->setFocus ();
51
48
}
52
49
53
- void Lock::animate () {
50
+ void Lock::animateIn () {
54
51
ui->centerWidget ->hide ();
55
52
QPropertyAnimation *a =
56
53
new QPropertyAnimation (ui->centerWidget ->graphicsEffect (), " opacity" );
57
- a->setDuration (400 );
54
+ a->setDuration (500 );
58
55
a->setStartValue (0 );
59
56
a->setEndValue (1 );
60
- a->setEasingCurve (QEasingCurve::InCurve );
57
+ a->setEasingCurve (QEasingCurve::InCubic );
61
58
a->start (QPropertyAnimation::DeleteWhenStopped);
62
59
ui->centerWidget ->show ();
63
60
}
64
61
62
+ void Lock::animateOut () {
63
+ ui->centerWidget ->show ();
64
+ QPropertyAnimation *a =
65
+ new QPropertyAnimation (ui->centerWidget ->graphicsEffect (), " opacity" );
66
+ a->setDuration (500 );
67
+ a->setStartValue (1 );
68
+ a->setEndValue (0 );
69
+ a->setEasingCurve (QEasingCurve::OutCubic);
70
+ connect (a, &QPropertyAnimation::finished, this , [=] {
71
+ ui->login ->hide ();
72
+ ui->signup ->hide ();
73
+ ui->passcodeLogin ->clear ();
74
+ ui->centerWidget ->hide ();
75
+ this ->hide ();
76
+ });
77
+ a->start (QPropertyAnimation::DeleteWhenStopped);
78
+ }
79
+
65
80
void Lock::applyThemeQuirks () {
66
- // little quirks
67
-
68
- ui->label_4 ->setStyleSheet (
69
- " color:#c2c5d1;padding: 0px 8px 0px 8px;background:transparent;" );
70
- ui->label_3 ->setStyleSheet (
71
- " color:#c2c5d1;padding: 0px 8px 0px 8px;background:transparent;" );
72
-
73
- ui->login ->setStyleSheet (" QWidget#login{background-color:palette(window);"
74
- " background-image:url(:/icons/wa_bg.png)};" );
75
- ui->signup ->setStyleSheet (" QWidget#signup{background-color:palette(window);"
76
- " background-image:url(:/icons/wa_bg.png)};" );
77
-
78
- ui->widget_2 ->setStyleSheet (
79
- " QWidget#widget_2{\n border-radius: "
80
- " 5px;\n background-image:url(:/icons/"
81
- " texture.png);\n background-color:palette(shadow);\n }" );
82
- ui->widget ->setStyleSheet (
83
- " QWidget#widget{\n border-radius: "
84
- " 5px;\n background-image:url(:/icons/"
85
- " texture.png);\n background-color:palette(shadow);\n }" );
86
-
87
- ui->centerWidget ->setStyleSheet (
88
- " QWidget#centerWidget{background-image:url(:/icons/wa_bg.png)}" );
89
- if (settings.value (" windowTheme" , " light" ).toString () == " dark" ) {
90
81
91
- } else {
92
- }
82
+ QString lblStyle = QString (R"( color: #c2c5d1;
83
+ padding: 0px 8px 0px 8px;
84
+ background: transparent;)" );
85
+ ui->label_4 ->setStyleSheet (lblStyle);
86
+ ui->label_3 ->setStyleSheet (lblStyle);
87
+
88
+ ui->login ->setStyleSheet (R"( QWidget#login {
89
+ background-color: palette(window);
90
+ background-image: url(":/icons/wa_bg.png");
91
+ })" );
92
+
93
+ ui->signup ->setStyleSheet (R"( QWidget#signup {
94
+ background-color: palette(window);
95
+ background-image: url(":/icons/wa_bg.png");
96
+ })" );
97
+
98
+ ui->widget_2 ->setStyleSheet (R"( QWidget#widget_2 {
99
+ border-radius: 5px;
100
+ background-image: url(":/icons/texture.png");
101
+ background-color: palette(shadow);
102
+ })" );
103
+
104
+ ui->widget ->setStyleSheet (R"( QWidget#widget{
105
+ border-radius: 5px;
106
+ background-image:url(":/icons/texture.png");
107
+ background-color:palette(shadow);
108
+ })" );
109
+
110
+ ui->centerWidget ->setStyleSheet (R"( QWidget#centerWidget {
111
+ background-image: url(":/icons/wa_bg.png");
112
+ })" );
93
113
}
94
114
95
115
Lock::~Lock () { delete ui; }
@@ -112,6 +132,11 @@ void Lock::keyReleaseEvent(QKeyEvent *event) {
112
132
113
133
bool Lock::event (QEvent *e) { return QWidget::event (e); }
114
134
135
+ bool Lock::getIsLocked () const
136
+ {
137
+ return isLocked;
138
+ }
139
+
115
140
void Lock::on_passcode1_textChanged (const QString &arg1) {
116
141
if (arg1.contains (" " )) {
117
142
ui->passcode1 ->setText (arg1.simplified ());
@@ -141,8 +166,6 @@ void Lock::on_setPass_clicked() {
141
166
ui->login ->show ();
142
167
ui->passcodeLogin ->setFocus ();
143
168
}
144
- } else {
145
- return ;
146
169
}
147
170
}
148
171
@@ -152,11 +175,8 @@ void Lock::on_unlock_clicked() {
152
175
QString password =
153
176
QByteArray::fromBase64 (settings.value (" asdfg" ).toByteArray ());
154
177
if (ui->passcodeLogin ->text () == password && check_password_set ()) {
155
- ui->login ->hide ();
156
- ui->signup ->hide ();
157
- ui->passcodeLogin ->clear ();
158
178
isLocked = false ;
159
- this -> hide ();
179
+ animateOut ();
160
180
emit unLocked ();
161
181
} else {
162
182
ui->wrong ->show ();
@@ -178,17 +198,13 @@ void Lock::lock_app() {
178
198
ui->login ->show ();
179
199
isLocked = true ;
180
200
this ->show ();
181
- animate ();
201
+ animateIn ();
182
202
ui->passcodeLogin ->setFocus ();
183
203
}
184
204
185
205
void Lock::on_passcodeLogin_returnPressed () { on_unlock_clicked (); }
186
206
187
207
bool Lock::getCapsLockOn () {
188
- // platform dependent method of determining if CAPS LOCK is on
189
- #ifdef Q_OS_WIN32 // MS Windows version
190
- return GetKeyState (VK_CAPITAL) == 1 ;
191
- #else // X11 version (Linux/Unix/Mac OS X/etc...)
192
208
Display *d = XOpenDisplay ((char *)0 );
193
209
bool caps_state = false ;
194
210
if (d) {
@@ -197,7 +213,6 @@ bool Lock::getCapsLockOn() {
197
213
caps_state = (n & 0x01 ) == 1 ;
198
214
}
199
215
return caps_state;
200
- #endif
201
216
}
202
217
203
218
void Lock::on_cancelSetting_clicked () {
0 commit comments