Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
security_code_layer.h
Go to the documentation of this file.
1#ifndef SECURITY_CODE_LAYER_H
2#define SECURITY_CODE_LAYER_H
3
4#include "../security_layer.h"
5
6class QLabel;
7class QLineEdit;
9
19class SecurityCodeLayer final : public SecurityLayer {
20 Q_OBJECT
21
22public:
29 explicit SecurityCodeLayer(QWidget *parent = nullptr);
30
34 ~SecurityCodeLayer() override;
35
42 void Initialize() override;
43
48 void Reset() override;
49
50private slots:
56 void CheckSecurityCode();
57
64 void OnDigitEntered();
65
66protected:
76 bool eventFilter(QObject *obj, QEvent *event) override;
77
78private:
82 struct SecurityCode {
84 QString code;
86 QString hint;
89
96 SecurityCode(const QString &c, const QString &h, const bool num = true)
97 : code(c), hint(h), is_numeric(num) {
98 }
99 };
100
107 QString GetRandomSecurityCode(QString &hint, bool &is_numeric);
108
113 void ResetInputs();
114
119 QString GetEnteredCode() const;
120
126 void ShowErrorEffect();
127
132 void SetInputValidators(bool numeric_only);
133
135 QList<QLineEdit *> code_inputs_;
142
144 QVector<SecurityCode> security_codes_;
147};
148
149#endif // SECURITY_CODE_LAYER_H
void ShowErrorEffect()
Triggers a visual error effect on the input fields. Temporarily changes the background and border col...
Definition security_code_layer.cpp:302
bool is_current_code_numeric_
Flag indicating if the current_security_code_ is numeric only.
Definition security_code_layer.h:141
~SecurityCodeLayer() override
Destructor.
Definition security_code_layer.cpp:123
QVector< SecurityCode > security_codes_
Vector storing all available SecurityCode entries (code, hint, type).
Definition security_code_layer.h:144
QLabel * security_code_hint_
Label displaying the hint for the current security code.
Definition security_code_layer.h:137
void Reset() override
Resets the layer to its initial state. Clears input fields, resets their styles, clears the hint,...
Definition security_code_layer.cpp:145
void SetInputValidators(bool numeric_only)
Sets the input validators for all code input fields based on whether the current code is numeric.
Definition security_code_layer.cpp:180
QList< QLineEdit * > code_inputs_
List containing pointers to the four QLineEdit widgets for code input.
Definition security_code_layer.h:135
QString GetEnteredCode() const
Gets the code currently entered by the user by concatenating the text from all input fields.
Definition security_code_layer.cpp:294
QString GetRandomSecurityCode(QString &hint, bool &is_numeric)
Selects a random security code from the internal list.
Definition security_code_layer.cpp:345
QString current_security_code_
The currently active security code that the user needs to enter.
Definition security_code_layer.h:139
void OnDigitEntered()
Slot called when the text in any input field changes. Handles automatic focus progression to the next...
Definition security_code_layer.cpp:192
SecurityCodeLayer(QWidget *parent=nullptr)
Constructs a SecurityCodeLayer. Initializes the UI elements (title, instructions, input fields,...
Definition security_code_layer.cpp:15
void Initialize() override
Initializes the layer for display. Resets the input fields, selects a new random security code and hi...
Definition security_code_layer.cpp:126
bool eventFilter(QObject *obj, QEvent *event) override
Filters events for the input fields to handle navigation keys. Intercepts KeyPress events for QLineEd...
Definition security_code_layer.cpp:224
void CheckSecurityCode()
Checks if the entered code matches the current security code. Called when all input fields are filled...
Definition security_code_layer.cpp:254
TranslationManager * translator_
Pointer to the translation manager for handling UI translations.
Definition security_code_layer.h:146
void ResetInputs()
Clears all input fields and resets their styles to the default (error/red) state. Sets focus on the f...
Definition security_code_layer.cpp:154
SecurityLayer(QWidget *parent=nullptr)
Constructs a SecurityLayer.
Definition security_layer.h:20
Manages the loading and delivery of translations for applications.
Definition translation_manager.h:15
SecurityCode(const QString &c, const QString &h, const bool num=true)
Constructs a SecurityCode entry.
Definition security_code_layer.h:96
QString hint
A hint related to the security code.
Definition security_code_layer.h:86
QString code
The 4-character security code (can be digits or letters).
Definition security_code_layer.h:84
bool is_numeric
Flag indicating if the code consists only of digits.
Definition security_code_layer.h:88