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

A security layer implementing a typing verification test. More...

#include <typing_test_layer.h>

Inheritance diagram for TypingTestLayer:
Collaboration diagram for TypingTestLayer:

Public Member Functions

void Initialize () override
 Initializes the layer for display. Resets the layer state, sets focus on the hidden input field, and ensures the layer is fully opaque.
 
void Reset () override
 Resets the layer to its initial state. Clears the input field, resets progress tracking, generates a new text passage, updates the display, resets UI element styles, and ensures the layer is fully opaque.
 
 TypingTestLayer (QWidget *parent=nullptr)
 Constructs a TypingTestLayer. Initializes the UI elements (title, instructions, text display panel, hidden input field), sets up the layout, connects the input field's textChanged signal, and generates the initial text passage.
 
 ~TypingTestLayer () 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.
 

Private Slots

void OnTextChanged (const QString &text)
 Slot called when the text in the hidden_input_ field changes. Validates the entered text against the target text passage. Updates the display highlighting based on the current correct position. If the entire text is typed correctly, marks the test as completed, updates styles, and triggers the fade-out animation. Prevents incorrect input.
 
void UpdateHighlight () const
 Updates the text display label after the test is successfully completed. Sets the entire text to green.
 

Private Member Functions

void GenerateWords ()
 Generates a random text passage composed of words from a predefined pool. Ensures the generated text fits within the display area (approximately 3 lines) and avoids excessive repetition of words. Stores the generated words in words_ and the full passage in full_text_.
 
void UpdateDisplayText () const
 Updates the display_text_label_ with formatted rich text. Highlights correctly typed characters in green, the current character with a red background, and the remaining characters in gray, based on current_position_.
 

Private Attributes

int current_position_
 Index of the next character the user needs to type correctly in full_text_.
 
QLabel * display_text_label_
 Label displaying the text passage to be typed, with dynamic highlighting.
 
QString full_text_
 The complete text passage the user needs to type.
 
QLineEdit * hidden_input_
 Hidden input field used to capture user keystrokes without being visible.
 
QLabel * instructions_label_
 Label displaying instructions for the user.
 
bool test_completed_
 Flag indicating if the user has successfully completed the typing test.
 
bool test_started_
 Flag indicating if the user has started typing.
 
QLabel * title_label_
 Label displaying the layer title ("TYPING VERIFICATION TEST").
 
QStringList words_
 List of words composing the current text passage.
 

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 implementing a typing verification test.

This layer presents the user with a randomly generated text passage (composed of common English words) that they must type accurately. The layer tracks the user's progress, highlighting correctly typed characters in green and the current character with a red background. Input is captured via a hidden QLineEdit. Upon successful completion of the typing test, the UI elements turn green, and the layer fades out, emitting the layerCompleted() signal. Incorrect input is prevented.

Constructor & Destructor Documentation

◆ TypingTestLayer()

TypingTestLayer::TypingTestLayer ( QWidget * parent = nullptr)
explicit

Constructs a TypingTestLayer. Initializes the UI elements (title, instructions, text display panel, hidden input field), sets up the layout, connects the input field's textChanged signal, and generates the initial text passage.

Parameters
parentOptional parent widget.
Here is the call graph for this function:

◆ ~TypingTestLayer()

TypingTestLayer::~TypingTestLayer ( )
override

Destructor.

Member Function Documentation

◆ GenerateWords()

void TypingTestLayer::GenerateWords ( )
private

Generates a random text passage composed of words from a predefined pool. Ensures the generated text fits within the display area (approximately 3 lines) and avoids excessive repetition of words. Stores the generated words in words_ and the full passage in full_text_.

Here is the caller graph for this function:

◆ Initialize()

void TypingTestLayer::Initialize ( )
overridevirtual

Initializes the layer for display. Resets the layer state, sets focus on the hidden input field, and ensures the layer is fully opaque.

Implements SecurityLayer.

Here is the call graph for this function:

◆ OnTextChanged

void TypingTestLayer::OnTextChanged ( const QString & text)
privateslot

Slot called when the text in the hidden_input_ field changes. Validates the entered text against the target text passage. Updates the display highlighting based on the current correct position. If the entire text is typed correctly, marks the test as completed, updates styles, and triggers the fade-out animation. Prevents incorrect input.

Parameters
textThe current text in the hidden input field.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Reset()

void TypingTestLayer::Reset ( )
overridevirtual

Resets the layer to its initial state. Clears the input field, resets progress tracking, generates a new text passage, updates the display, resets UI element styles, and ensures the layer is fully opaque.

Implements SecurityLayer.

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

◆ UpdateDisplayText()

void TypingTestLayer::UpdateDisplayText ( ) const
private

Updates the display_text_label_ with formatted rich text. Highlights correctly typed characters in green, the current character with a red background, and the remaining characters in gray, based on current_position_.

Here is the caller graph for this function:

◆ UpdateHighlight

void TypingTestLayer::UpdateHighlight ( ) const
privateslot

Updates the text display label after the test is successfully completed. Sets the entire text to green.

Here is the caller graph for this function:

Member Data Documentation

◆ current_position_

int TypingTestLayer::current_position_
private

Index of the next character the user needs to type correctly in full_text_.

◆ display_text_label_

QLabel* TypingTestLayer::display_text_label_
private

Label displaying the text passage to be typed, with dynamic highlighting.

◆ full_text_

QString TypingTestLayer::full_text_
private

The complete text passage the user needs to type.

◆ hidden_input_

QLineEdit* TypingTestLayer::hidden_input_
private

Hidden input field used to capture user keystrokes without being visible.

◆ instructions_label_

QLabel* TypingTestLayer::instructions_label_
private

Label displaying instructions for the user.

◆ test_completed_

bool TypingTestLayer::test_completed_
private

Flag indicating if the user has successfully completed the typing test.

◆ test_started_

bool TypingTestLayer::test_started_
private

Flag indicating if the user has started typing.

◆ title_label_

QLabel* TypingTestLayer::title_label_
private

Label displaying the layer title ("TYPING VERIFICATION TEST").

◆ words_

QStringList TypingTestLayer::words_
private

List of words composing the current text passage.


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