|
Wavelength
Privacy-focused, cross-platform, and open-source communication application
|
The main view for displaying and interacting with a specific Wavelength chat session. More...
#include <chat_view.h>
Public Slots | |
| void | AttachFile () |
| Opens a file dialog to allow the user to select a file for sending. If a file is selected, initiates the file sending process via WavelengthMessageService and displays an initial progress message in the message area. | |
Signals | |
| void | wavelengthAborted () |
| Emitted when the user aborts the connection or the Wavelength is closed by the host. Signals the parent view to switch back. | |
Public Member Functions | |
| ChatView (QWidget *parent=nullptr) | |
| Constructs a WavelengthChatView. Initializes the UI elements (labels, message area, input fields, buttons), sets up layouts, initializes audio components (input/output, format, sounds), connects signals/slots for user interaction and backend events, and starts timers for time display and random visual effects. | |
| void | Clear () |
| Clears the view and resets its state. Resets the current frequency, clears the message area, header, and input field, and hides the view. | |
| double | GetScanlineOpacity () const |
| Gets the current opacity of the scanline effect. | |
| void | OnMessageReceived (const QString &frequency, const QString &message) |
| Handles displaying a received message for the current Wavelength. Adds the message to the message_area_ if the frequency matches the current one. Triggers a visual activity effect. | |
| void | OnMessageSent (const QString &frequency, const QString &message) const |
| Handles displaying a message sent by the local user on the current Wavelength. Adds the message to the message_area_ if the frequency matches the current one. | |
| void | OnWavelengthClosed (const QString &frequency) |
| Handles the event when the host closes the current Wavelength. Updates the status indicator, displays a system message, and schedules the view to be cleared, and the wavelengthAborted() signal to be emitted after a delay. Does nothing if the frequency doesn't match or if the local user initiated the closure. | |
| void | SetScanlineOpacity (double opacity) |
| Sets the opacity of the scanline effect. Triggers a repaint of the widget. | |
| void | SetWavelength (const QString &frequency, const QString &name=QString()) |
| Configures the view for a specific Wavelength. Sets the header title with the frequency and optional name, clears the message area, displays a connection message, resets PTT state, enables controls, triggers a connection visual effect, and makes the view visible. | |
| ~ChatView () override | |
| Destructor. Stops audio input/output and cleans up audio resources. | |
Protected Member Functions | |
| void | paintEvent (QPaintEvent *event) override |
| Overridden paint event handler. Draws the custom cyberpunk border, AR markers, and scanline effect. | |
Properties | |
| double | scanlineOpacity |
| Property controlling the opacity of the animated scanline effect (0.0 to 1.0). Animatable. | |
Private Types | |
| enum | PttState { Idle , Requesting , Transmitting , Receiving } |
| Enum representing the possible states of the Push-to-Talk (PTT) functionality. More... | |
Private Slots | |
| void | AbortWavelength () |
| Initiates the process of leaving or closing the current Wavelength. Updates the status indicator, calls the appropriate method on WavelengthSessionCoordinator (CloseWavelength if hosted, LeaveWavelength otherwise), emits wavelengthAborted(), and schedules the view to be cleared after a short delay. | |
| void | OnAudioDataReceived (const QString &frequency, const QByteArray &audio_data) const |
| Slot called when binary audio data is received from the server. If the frequency matches and the state is Received, writes the data to the audio output device, calculates the amplitude of the received audio, and updates the audio visualization in the message area. | |
| void | OnPttButtonPressed () |
| Slot called when the PTT button is pressed. Plays the PTT activation sound, sets the state to Requesting, updates the button appearance, and sends a PTT request to the server via WavelengthMessageService. | |
| void | OnPttButtonReleased () |
| Slot called when the PTT button is released. Plays the PTT deactivation sound. If transmitting, stops audio input and sends a PTT release message. Resets the PTT state to Idle and updates the button appearance. | |
| void | OnPttDenied (const QString &frequency, const QString &reason) |
| Slot called when the server denies the PTT request. If the frequency matches and the state is Requested, displays a system message with the reason, resets the PTT state to Idle, and updates the button appearance. | |
| void | OnPttGranted (const QString &frequency) |
| Slot called when the server grants the PTT request. If the frequency matches and the state is Requested, sets the state to Transmitting, updates the button appearance, starts audio input, and updates the message area to show the local user is transmitting. | |
| void | OnPttStartReceiving (const QString &frequency, const QString &sender_id) |
| Slot called when another user starts transmitting PTT on the current Wavelength. If the state is Idle, sets the state to Receiving, updates the button appearance (disabling it), starts audio output, and updates the message area to show the remote sender's ID. | |
| void | OnPttStopReceiving (const QString &frequency) |
| Slot called when the remote user stops transmitting PTT. If the frequency matches and the state is Receiving, stops audio output, resets the PTT state to Idle, updates the button appearance, clears the transmitting user display in the message area, and resets the audio amplitude visualization. | |
| void | OnReadyReadInput () const |
| Slot called when the audio input device has data ready to be read. Reads all available audio data, sends it to the server via WavelengthMessageService, calculates the amplitude, and updates the local audio visualization in the message area. | |
| void | SendMessage () const |
| Sends the text message currently in the input field. Clears the input field and sends the message via WavelengthMessageService. | |
| void | TriggerActivityEffect () |
| Triggers a subtle scanline effect animation when there is activity (e.g., a message received). | |
| void | TriggerConnectionEffect () |
| Triggers a more pronounced scanline effect animation when connecting to a Wavelength. | |
| void | TriggerVisualEffect () |
| Triggers a random, brief increase in the scanline effect opacity. | |
| void | UpdateProgressMessage (const QString &message_id, const QString &message) const |
| Slot to update a message in the message area, typically used for file transfer progress. Finds the message by its ID and updates its content. | |
Private Member Functions | |
| qreal | CalculateAmplitude (const QByteArray &buffer) const |
| Calculates the Root Mean Square (RMS) amplitude of a raw audio buffer. Used for audio visualization. Assumes 16-bit signed integer PCM data. | |
| void | InitializeAudio () |
| Initializes the audio format and creates QAudioInput/QAudioOutput objects. Determines supported formats and sets buffer sizes. | |
| void | ResetStatusIndicator () const |
| Resets the status_indicator_ label to its default "CONNECTION ACTIVE" state and style. | |
| void | StartAudioInput () |
| Starts capturing audio from the microphone if PTT state is Transmitting. Connects the readyRead signal to OnReadyReadInput(). | |
| void | StartAudioOutput () |
| Starts audio playback if PTT state is Receiving. Prepares the audio output device to receive data. | |
| void | StopAudioInput () |
| Stops capturing audio from the microphone. Disconnects signals and resets the input device pointer. | |
| void | StopAudioOutput () |
| Stops audio playback. Resets the output device pointer. | |
| void | UpdatePttButtonState () const |
| Updates the appearance and enabled state of the PTT button based on the current ptt_state_. Also enables/disables other input controls (text field, send/attach buttons) accordingly. | |
Private Attributes | |
| QPushButton * | abort_button_ |
| Button to disconnect from the current Wavelength. | |
| QPushButton * | attach_button_ |
| Button to open the file attachment dialog. | |
| QAudioFormat | audio_format_ |
| The audio format used for both input and output (PCM, 16 kHz, 16-bit mono). | |
| QAudioInput * | audio_input_ |
| Object managing audio input from the microphone. | |
| QAudioOutput * | audio_output_ |
| Object managing audio output to the speakers. | |
| QString | current_frequency_ = "-1.0" |
| The frequency of the Wavelength currently displayed in this view. "-1.0" if inactive. | |
| QString | current_transmitter_id_ |
| Stores the ID of the user currently transmitting audio (if receiving). | |
| QLabel * | header_label_ |
| Label displaying the Wavelength frequency and name. | |
| QIODevice * | input_device_ |
| I/O device providing access to the raw audio stream from audio_input_. | |
| QLineEdit * | input_field_ |
| Input field for typing text messages. | |
| bool | is_aborting_ = false |
| Flag indicating if the view is in the process of aborting the connection (prevents duplicate actions). | |
| StreamDisplay * | message_area_ |
| Custom widget for displaying the stream of messages and audio visualization. | |
| QIODevice * | output_device_ |
| I/O device providing access to the raw audio stream for audio_output_. | |
| QPushButton * | ptt_button_ |
| Button for Push-to-Talk functionality. | |
| QSoundEffect * | ptt_off_sound_ |
| Sound effect played when the PTT button is released. | |
| QSoundEffect * | ptt_on_sound_ |
| Sound effect played when the PTT button is pressed. | |
| PttState | ptt_state_ |
| Current state of the Push-to-Talk interaction. | |
| double | scanline_opacity_ |
| Current opacity level for the scanline effect overlay. | |
| QPushButton * | send_button_ |
| Button to send the text message in the input field. | |
| QLabel * | status_indicator_ |
| Label indicating the connection status ("CONNECTION ACTIVE", "ABORTING", etc.). | |
| TranslationManager * | translator_ |
| Pointer to the translation manager for handling UI translations. | |
The main view for displaying and interacting with a specific Wavelength chat session.
This widget provides the user interface for a single chat, including:
|
private |
Enum representing the possible states of the Push-to-Talk (PTT) functionality.
|
explicit |
Constructs a WavelengthChatView. Initializes the UI elements (labels, message area, input fields, buttons), sets up layouts, initializes audio components (input/output, format, sounds), connects signals/slots for user interaction and backend events, and starts timers for time display and random visual effects.
| parent | Optional parent widget. |
|
override |
Destructor. Stops audio input/output and cleans up audio resources.
|
privateslot |
Initiates the process of leaving or closing the current Wavelength. Updates the status indicator, calls the appropriate method on WavelengthSessionCoordinator (CloseWavelength if hosted, LeaveWavelength otherwise), emits wavelengthAborted(), and schedules the view to be cleared after a short delay.
|
slot |
Opens a file dialog to allow the user to select a file for sending. If a file is selected, initiates the file sending process via WavelengthMessageService and displays an initial progress message in the message area.
|
nodiscardprivate |
Calculates the Root Mean Square (RMS) amplitude of a raw audio buffer. Used for audio visualization. Assumes 16-bit signed integer PCM data.
| buffer | The raw audio data. |
| void ChatView::Clear | ( | ) |
Clears the view and resets its state. Resets the current frequency, clears the message area, header, and input field, and hides the view.
|
inlinenodiscard |
Gets the current opacity of the scanline effect.
|
private |
Initializes the audio format and creates QAudioInput/QAudioOutput objects. Determines supported formats and sets buffer sizes.
|
privateslot |
Slot called when binary audio data is received from the server. If the frequency matches and the state is Received, writes the data to the audio output device, calculates the amplitude of the received audio, and updates the audio visualization in the message area.
| frequency | The frequency the audio data belongs to. |
| audio_data | The raw audio data chunk. |
| void ChatView::OnMessageReceived | ( | const QString & | frequency, |
| const QString & | message ) |
Handles displaying a received message for the current Wavelength. Adds the message to the message_area_ if the frequency matches the current one. Triggers a visual activity effect.
| frequency | The frequency the message was received on. |
| message | The content of the message. |
| void ChatView::OnMessageSent | ( | const QString & | frequency, |
| const QString & | message ) const |
Handles displaying a message sent by the local user on the current Wavelength. Adds the message to the message_area_ if the frequency matches the current one.
| frequency | The frequency the message was sent on. |
| message | The content of the message. |
|
privateslot |
Slot called when the PTT button is pressed. Plays the PTT activation sound, sets the state to Requesting, updates the button appearance, and sends a PTT request to the server via WavelengthMessageService.
|
privateslot |
Slot called when the PTT button is released. Plays the PTT deactivation sound. If transmitting, stops audio input and sends a PTT release message. Resets the PTT state to Idle and updates the button appearance.
|
privateslot |
Slot called when the server denies the PTT request. If the frequency matches and the state is Requested, displays a system message with the reason, resets the PTT state to Idle, and updates the button appearance.
| frequency | The frequency for which PTT was denied. |
| reason | The reason for denial provided by the server. |
|
privateslot |
Slot called when the server grants the PTT request. If the frequency matches and the state is Requested, sets the state to Transmitting, updates the button appearance, starts audio input, and updates the message area to show the local user is transmitting.
| frequency | The frequency for which PTT was granted. |
|
privateslot |
Slot called when another user starts transmitting PTT on the current Wavelength. If the state is Idle, sets the state to Receiving, updates the button appearance (disabling it), starts audio output, and updates the message area to show the remote sender's ID.
| frequency | The frequency on which transmission started. |
| sender_id | The identifier of the user transmitting. |
|
privateslot |
Slot called when the remote user stops transmitting PTT. If the frequency matches and the state is Receiving, stops audio output, resets the PTT state to Idle, updates the button appearance, clears the transmitting user display in the message area, and resets the audio amplitude visualization.
| frequency | The frequency on which transmission stopped. |
|
privateslot |
Slot called when the audio input device has data ready to be read. Reads all available audio data, sends it to the server via WavelengthMessageService, calculates the amplitude, and updates the local audio visualization in the message area.
| void ChatView::OnWavelengthClosed | ( | const QString & | frequency | ) |
Handles the event when the host closes the current Wavelength. Updates the status indicator, displays a system message, and schedules the view to be cleared, and the wavelengthAborted() signal to be emitted after a delay. Does nothing if the frequency doesn't match or if the local user initiated the closure.
| frequency | The frequency of the closed Wavelength. |
|
overrideprotected |
Overridden paint event handler. Draws the custom cyberpunk border, AR markers, and scanline effect.
| event | The paint event. |
|
private |
Resets the status_indicator_ label to its default "CONNECTION ACTIVE" state and style.
|
privateslot |
Sends the text message currently in the input field. Clears the input field and sends the message via WavelengthMessageService.
| void ChatView::SetScanlineOpacity | ( | double | opacity | ) |
Sets the opacity of the scanline effect. Triggers a repaint of the widget.
| opacity | The desired opacity (0.0 to 1.0). |
| void ChatView::SetWavelength | ( | const QString & | frequency, |
| const QString & | name = QString() ) |
Configures the view for a specific Wavelength. Sets the header title with the frequency and optional name, clears the message area, displays a connection message, resets PTT state, enables controls, triggers a connection visual effect, and makes the view visible.
| frequency | The frequency of the Wavelength. |
| name | Optional name associated with the Wavelength. |
|
private |
Starts capturing audio from the microphone if PTT state is Transmitting. Connects the readyRead signal to OnReadyReadInput().
|
private |
Starts audio playback if PTT state is Receiving. Prepares the audio output device to receive data.
|
private |
Stops capturing audio from the microphone. Disconnects signals and resets the input device pointer.
|
private |
Stops audio playback. Resets the output device pointer.
|
privateslot |
Triggers a subtle scanline effect animation when there is activity (e.g., a message received).
|
privateslot |
Triggers a more pronounced scanline effect animation when connecting to a Wavelength.
|
privateslot |
Triggers a random, brief increase in the scanline effect opacity.
|
privateslot |
Slot to update a message in the message area, typically used for file transfer progress. Finds the message by its ID and updates its content.
| message_id | The unique identifier of the message to update. |
| message | The new content for the message. |
|
private |
Updates the appearance and enabled state of the PTT button based on the current ptt_state_. Also enables/disables other input controls (text field, send/attach buttons) accordingly.
|
signal |
Emitted when the user aborts the connection or the Wavelength is closed by the host. Signals the parent view to switch back.
|
private |
Button to disconnect from the current Wavelength.
|
private |
Button to open the file attachment dialog.
|
private |
The audio format used for both input and output (PCM, 16 kHz, 16-bit mono).
|
private |
Object managing audio input from the microphone.
|
private |
Object managing audio output to the speakers.
|
private |
The frequency of the Wavelength currently displayed in this view. "-1.0" if inactive.
|
private |
Stores the ID of the user currently transmitting audio (if receiving).
|
private |
Label displaying the Wavelength frequency and name.
|
private |
I/O device providing access to the raw audio stream from audio_input_.
|
private |
Input field for typing text messages.
|
private |
Flag indicating if the view is in the process of aborting the connection (prevents duplicate actions).
|
private |
Custom widget for displaying the stream of messages and audio visualization.
|
private |
I/O device providing access to the raw audio stream for audio_output_.
|
private |
Button for Push-to-Talk functionality.
|
private |
Sound effect played when the PTT button is released.
|
private |
Sound effect played when the PTT button is pressed.
|
private |
Current state of the Push-to-Talk interaction.
|
private |
Current opacity level for the scanline effect overlay.
|
private |
Button to send the text message in the input field.
|
private |
Label indicating the connection status ("CONNECTION ACTIVE", "ABORTING", etc.).
|
private |
Pointer to the translation manager for handling UI translations.
|
readwrite |
Property controlling the opacity of the animated scanline effect (0.0 to 1.0). Animatable.