Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
SecurityCodeLayer Class Referencefinal

A security layer requiring the user to enter a 4-character security code. More...

#include <security_code_layer.h>

Inheritance diagram for SecurityCodeLayer:
Collaboration diagram for SecurityCodeLayer:

Classes

struct  SecurityCode
 Structure representing a security code and its associated hint. More...
 

Public Member Functions

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.
 
- Public Member Functions inherited from SecurityLayer
 SecurityLayer (QWidget *parent=nullptr)
 Constructs a SecurityLayer.
 
 ~SecurityLayer () override=default
 Virtual destructor. Ensures proper cleanup for derived classes.
 

Protected Member Functions

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.
 

Private Slots

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.
 

Private Member Functions

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.
 

Private Attributes

QList< QLineEdit * > code_inputs_
 List containing pointers to the four QLineEdit widgets for code input.
 
QString current_security_code_
 The currently active security code that the user needs to enter.
 
bool is_current_code_numeric_
 Flag indicating if the current_security_code_ is numeric only.
 
QLabel * security_code_hint_
 Label displaying the hint for the current security code.
 
QVector< SecurityCodesecurity_codes_
 Vector storing all available SecurityCode entries (code, hint, type).
 
TranslationManagertranslator_ = nullptr
 Pointer to the translation manager for handling UI translations.
 

Additional Inherited Members

- Signals inherited from SecurityLayer
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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ 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
parentOptional parent widget.
Here is the call graph for this function:

◆ ~SecurityCodeLayer()

SecurityCodeLayer::~SecurityCodeLayer ( )
override

Destructor.

Member Function Documentation

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
objThe object that generated the event.
eventThe 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.
Here is the caller graph for this function:

◆ GetRandomSecurityCode()

QString SecurityCodeLayer::GetRandomSecurityCode ( QString & hint,
bool & is_numeric )
private

Selects a random security code from the internal list.

Parameters
[out]hintThe hint associated with the selected code.
[out]is_numericTrue if the selected code is numeric, false otherwise.
Returns
The randomly selected 4-character security code string.
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ 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_onlyIf true, sets validators to accept only digits [0-9]. If false, accepts digits and uppercase letters [0-9A-Z].
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ 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_

QVector<SecurityCode> SecurityCodeLayer::security_codes_
private

Vector storing all available SecurityCode entries (code, hint, type).

◆ translator_

TranslationManager* SecurityCodeLayer::translator_ = nullptr
private

Pointer to the translation manager for handling UI translations.


The documentation for this class was generated from the following files: