Skip to content

Commit 0a182a9

Browse files
committed
feat: unlock animation plus some cleanup
1 parent c6fd2e8 commit 0a182a9

File tree

2 files changed

+75
-58
lines changed

2 files changed

+75
-58
lines changed

src/lock.cpp

Lines changed: 71 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
#include "lock.h"
22
#include "ui_lock.h"
33
#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-
104
#include <QGraphicsOpacityEffect>
5+
#include <QKeyEvent>
116
#include <QPropertyAnimation>
12-
#endif
7+
8+
#include "X11/XKBlib.h" // keep this header at bottom
139

1410
Lock::Lock(QWidget *parent) : QWidget(parent), ui(new Ui::Lock) {
1511
ui->setupUi(this);
@@ -20,76 +16,100 @@ Lock::Lock(QWidget *parent) : QWidget(parent), ui(new Ui::Lock) {
2016
QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
2117
ui->centerWidget->setGraphicsEffect(eff);
2218

23-
animate();
19+
animateIn();
2420

2521
if (settings.value("asdfg").isValid() == false) {
2622
signUp();
2723
} else {
2824
lock_app();
2925
}
3026
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);)");
3531
ui->caps1->setStyleSheet(capsStyle);
3632
ui->caps2->setStyleSheet(capsStyle);
3733
ui->signup_warning->setStyleSheet(capsStyle);
3834
ui->wrong->setStyleSheet(capsStyle);
3935
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+
})");
4239
}
4340
}
4441

4542
void Lock::signUp() {
4643
isLocked = false;
4744
ui->signup->show();
4845
ui->login->hide();
49-
animate();
46+
animateIn();
5047
ui->passcode1->setFocus();
5148
}
5249

53-
void Lock::animate() {
50+
void Lock::animateIn() {
5451
ui->centerWidget->hide();
5552
QPropertyAnimation *a =
5653
new QPropertyAnimation(ui->centerWidget->graphicsEffect(), "opacity");
57-
a->setDuration(400);
54+
a->setDuration(500);
5855
a->setStartValue(0);
5956
a->setEndValue(1);
60-
a->setEasingCurve(QEasingCurve::InCurve);
57+
a->setEasingCurve(QEasingCurve::InCubic);
6158
a->start(QPropertyAnimation::DeleteWhenStopped);
6259
ui->centerWidget->show();
6360
}
6461

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+
6580
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{\nborder-radius: "
80-
"5px;\nbackground-image:url(:/icons/"
81-
"texture.png);\nbackground-color:palette(shadow);\n}");
82-
ui->widget->setStyleSheet(
83-
"QWidget#widget{\nborder-radius: "
84-
"5px;\nbackground-image:url(:/icons/"
85-
"texture.png);\nbackground-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") {
9081

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+
})");
93113
}
94114

95115
Lock::~Lock() { delete ui; }
@@ -112,6 +132,11 @@ void Lock::keyReleaseEvent(QKeyEvent *event) {
112132

113133
bool Lock::event(QEvent *e) { return QWidget::event(e); }
114134

135+
bool Lock::getIsLocked() const
136+
{
137+
return isLocked;
138+
}
139+
115140
void Lock::on_passcode1_textChanged(const QString &arg1) {
116141
if (arg1.contains(" ")) {
117142
ui->passcode1->setText(arg1.simplified());
@@ -141,8 +166,6 @@ void Lock::on_setPass_clicked() {
141166
ui->login->show();
142167
ui->passcodeLogin->setFocus();
143168
}
144-
} else {
145-
return;
146169
}
147170
}
148171

@@ -152,11 +175,8 @@ void Lock::on_unlock_clicked() {
152175
QString password =
153176
QByteArray::fromBase64(settings.value("asdfg").toByteArray());
154177
if (ui->passcodeLogin->text() == password && check_password_set()) {
155-
ui->login->hide();
156-
ui->signup->hide();
157-
ui->passcodeLogin->clear();
158178
isLocked = false;
159-
this->hide();
179+
animateOut();
160180
emit unLocked();
161181
} else {
162182
ui->wrong->show();
@@ -178,17 +198,13 @@ void Lock::lock_app() {
178198
ui->login->show();
179199
isLocked = true;
180200
this->show();
181-
animate();
201+
animateIn();
182202
ui->passcodeLogin->setFocus();
183203
}
184204

185205
void Lock::on_passcodeLogin_returnPressed() { on_unlock_clicked(); }
186206

187207
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...)
192208
Display *d = XOpenDisplay((char *)0);
193209
bool caps_state = false;
194210
if (d) {
@@ -197,7 +213,6 @@ bool Lock::getCapsLockOn() {
197213
caps_state = (n & 0x01) == 1;
198214
}
199215
return caps_state;
200-
#endif
201216
}
202217

203218
void Lock::on_cancelSetting_clicked() {

src/lock.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Lock : public QWidget {
1414
public:
1515
explicit Lock(QWidget *parent = nullptr);
1616
~Lock();
17-
bool isLocked = true;
17+
bool getIsLocked() const;
1818

1919
private slots:
2020
void on_passcode1_textChanged(const QString &arg1);
@@ -27,7 +27,8 @@ private slots:
2727
bool getCapsLockOn();
2828
void checkCaps();
2929
void on_cancelSetting_clicked();
30-
void animate();
30+
void animateIn();
31+
void animateOut();
3132
public slots:
3233
void lock_app();
3334
void applyThemeQuirks();
@@ -44,6 +45,7 @@ protected slots:
4445

4546
private:
4647
Ui::Lock *ui;
48+
bool isLocked = true;
4749
QSettings settings;
4850
};
4951

0 commit comments

Comments
 (0)