A security layer requiring the user to enter a 4-character security code.
More...
#include <security_code_layer.h>
|
| void | Initialize () override |
| | Initializes the layer for display. Resets the input fields, selects a new random security code and hint, sets appropriate input validators (numeric or alphanumeric), displays the hint, resets opacity, and sets focus to the first input field.
|
| |
| void | Reset () override |
| | Resets the layer to its initial state. Clears input fields, resets their styles, clears the hint, resets opacity, and sets focus.
|
| |
| | SecurityCodeLayer (QWidget *parent=nullptr) |
| | Constructs a SecurityCodeLayer. Initializes the UI elements (title, instructions, input fields, hint label) and layout. Populates the internal list of possible security codes and hints.
|
| |
| | ~SecurityCodeLayer () override |
| | Destructor.
|
| |
| | SecurityLayer (QWidget *parent=nullptr) |
| | Constructs a SecurityLayer.
|
| |
| | ~SecurityLayer () override=default |
| | Virtual destructor. Ensures proper cleanup for derived classes.
|
| |
|
| bool | eventFilter (QObject *obj, QEvent *event) override |
| | Filters events for the input fields to handle navigation keys. Intercepts KeyPress events for QLineEdit objects in code_inputs_. Handles Left/Right arrow keys for focus movement and Backspace for moving focus to the previous field and clearing it if the current field is empty.
|
| |
|
| void | CheckSecurityCode () |
| | Checks if the entered code matches the current security code. Called when all input fields are filled. Triggers success (color change, fade out) or error (visual effect, reset) accordingly.
|
| |
| void | OnDigitEntered () |
| | Slot called when the text in any input field changes. Handles automatic focus progression to the next field when a character is entered. Converts input to uppercase if the code is alphanumeric. Calls CheckSecurityCode() if all fields become filled.
|
| |
|
| QString | GetEnteredCode () const |
| | Gets the code currently entered by the user by concatenating the text from all input fields.
|
| |
| QString | GetRandomSecurityCode (QString &hint, bool &is_numeric) |
| | Selects a random security code from the internal list.
|
| |
| void | ResetInputs () |
| | Clears all input fields and resets their styles to the default (error/red) state. Sets focus on the first input field.
|
| |
| void | SetInputValidators (bool numeric_only) |
| | Sets the input validators for all code input fields based on whether the current code is numeric.
|
| |
| void | ShowErrorEffect () |
| | Triggers a visual error effect on the input fields. Temporarily changes the background and border color of the input fields to indicate an error, then resets the fields and their styles after a short delay.
|
| |
|
| void | layerCompleted () |
| | Emitted when the user successfully completes the security challenge presented by this layer.
|
| |
| void | layerFailed () |
| | Emitted when the user fails the security challenge (e.g., incorrect code, timeout, collision). Note: Not all layers currently implement failure conditions that emit this signal.
|
| |
A security layer requiring the user to enter a 4-character security code.
This layer presents four input fields for the user to enter a randomly selected security code (either numeric or alphanumeric). It provides a hint related to the code. Input validation, navigation between fields (using arrows and backspace), and automatic focus progression are handled. Upon correct code entry, the layer fades out and emits the layerCompleted() signal. Incorrect entry triggers a visual error effect.
◆ SecurityCodeLayer()
| SecurityCodeLayer::SecurityCodeLayer |
( |
QWidget * | parent = nullptr | ) |
|
|
explicit |
Constructs a SecurityCodeLayer. Initializes the UI elements (title, instructions, input fields, hint label) and layout. Populates the internal list of possible security codes and hints.
- Parameters
-
| parent | Optional parent widget. |
◆ ~SecurityCodeLayer()
| SecurityCodeLayer::~SecurityCodeLayer |
( |
| ) |
|
|
override |
◆ CheckSecurityCode
| void SecurityCodeLayer::CheckSecurityCode |
( |
| ) |
|
|
privateslot |
Checks if the entered code matches the current security code. Called when all input fields are filled. Triggers success (color change, fade out) or error (visual effect, reset) accordingly.
◆ eventFilter()
| bool SecurityCodeLayer::eventFilter |
( |
QObject * | obj, |
|
|
QEvent * | event ) |
|
overrideprotected |
Filters events for the input fields to handle navigation keys. Intercepts KeyPress events for QLineEdit objects in code_inputs_. Handles Left/Right arrow keys for focus movement and Backspace for moving focus to the previous field and clearing it if the current field is empty.
- Parameters
-
| obj | The object that generated the event. |
| event | The event being processed. |
- Returns
- True if the event was handled and should be filtered out, false otherwise.
◆ GetEnteredCode()
| QString SecurityCodeLayer::GetEnteredCode |
( |
| ) |
const |
|
private |
Gets the code currently entered by the user by concatenating the text from all input fields.
- Returns
- The 4-character code string entered by the user.
◆ GetRandomSecurityCode()
| QString SecurityCodeLayer::GetRandomSecurityCode |
( |
QString & | hint, |
|
|
bool & | is_numeric ) |
|
private |
Selects a random security code from the internal list.
- Parameters
-
| [out] | hint | The hint associated with the selected code. |
| [out] | is_numeric | True if the selected code is numeric, false otherwise. |
- Returns
- The randomly selected 4-character security code string.
◆ Initialize()
| void SecurityCodeLayer::Initialize |
( |
| ) |
|
|
overridevirtual |
Initializes the layer for display. Resets the input fields, selects a new random security code and hint, sets appropriate input validators (numeric or alphanumeric), displays the hint, resets opacity, and sets focus to the first input field.
Implements SecurityLayer.
◆ OnDigitEntered
| void SecurityCodeLayer::OnDigitEntered |
( |
| ) |
|
|
privateslot |
Slot called when the text in any input field changes. Handles automatic focus progression to the next field when a character is entered. Converts input to uppercase if the code is alphanumeric. Calls CheckSecurityCode() if all fields become filled.
◆ Reset()
| void SecurityCodeLayer::Reset |
( |
| ) |
|
|
overridevirtual |
Resets the layer to its initial state. Clears input fields, resets their styles, clears the hint, resets opacity, and sets focus.
Implements SecurityLayer.
◆ ResetInputs()
| void SecurityCodeLayer::ResetInputs |
( |
| ) |
|
|
private |
Clears all input fields and resets their styles to the default (error/red) state. Sets focus on the first input field.
◆ SetInputValidators()
| void SecurityCodeLayer::SetInputValidators |
( |
bool | numeric_only | ) |
|
|
private |
Sets the input validators for all code input fields based on whether the current code is numeric.
- Parameters
-
| numeric_only | If true, sets validators to accept only digits [0-9]. If false, accepts digits and uppercase letters [0-9A-Z]. |
◆ ShowErrorEffect()
| void SecurityCodeLayer::ShowErrorEffect |
( |
| ) |
|
|
private |
Triggers a visual error effect on the input fields. Temporarily changes the background and border color of the input fields to indicate an error, then resets the fields and their styles after a short delay.
◆ code_inputs_
| QList<QLineEdit *> SecurityCodeLayer::code_inputs_ |
|
private |
List containing pointers to the four QLineEdit widgets for code input.
◆ current_security_code_
| QString SecurityCodeLayer::current_security_code_ |
|
private |
The currently active security code that the user needs to enter.
◆ is_current_code_numeric_
| bool SecurityCodeLayer::is_current_code_numeric_ |
|
private |
Flag indicating if the current_security_code_ is numeric only.
◆ security_code_hint_
| QLabel* SecurityCodeLayer::security_code_hint_ |
|
private |
Label displaying the hint for the current security code.
◆ security_codes_
Vector storing all available SecurityCode entries (code, hint, type).
◆ translator_
Pointer to the translation manager for handling UI translations.
The documentation for this class was generated from the following files: