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

A widget that acts as a placeholder for chat attachments before they are loaded. More...

#include <attachment_placeholder.h>

Inheritance diagram for AttachmentPlaceholder:
Collaboration diagram for AttachmentPlaceholder:

Public Slots

void AdjustAndShowDialog (QDialog *dialog, const QScrollArea *scroll_area, QWidget *content_widget, QSize original_content_size) const
 Adjusts the size and position of the full-size dialog and shows it. Calculates the preferred dialog size based on the original content size, limits it to the available screen geometry, centers it, and makes it visible. Sets the content widget to its original fixed size to ensure scrollbars appear correctly if needed.
 
void GenerateThumbnail (const QByteArray &video_data, QLabel *thumbnail_label)
 Generates a thumbnail image from the first frame of a video in a background thread. Uses VideoDecoder to extract the frame and updates the provided QLabel with the thumbnail. Adds a play icon overlay to the thumbnail.
 
void SetError (const QString &error_msg)
 Updates the UI to display an error message. Enables the retry button and shows the error message in the progress label.
 
void ShowCyberAudio (const QByteArray &data)
 Creates and displays a CyberAttachmentViewer containing an audio player. Uses InlineAudioPlayer.
 
void ShowCyberGif (const QByteArray &data)
 Creates and displays a CyberAttachmentViewer containing a GIF. Wraps an InlineGifPlayer in an AutoScalingAttachment to handle thumbnail scaling and click-to-enlarge.
 
void ShowCyberImage (const QByteArray &data)
 Creates and displays a CyberAttachmentViewer containing an image. Wraps an InlineImageViewer in an AutoScalingAttachment to handle thumbnail scaling and click-to-enlarge.
 
void ShowCyberVideo (const QByteArray &data)
 Creates and displays a CyberAttachmentViewer containing a video preview (thumbnail + play button). Clicking the preview opens a VideoPlayerOverlay dialog.
 
void ShowFullSizeDialog (const QByteArray &data, bool is_gif)
 Creates and shows a non-modal dialog to display the full-size attachment (image or GIF). Uses InlineImageViewer or InlineGifPlayer within a QScrollArea.
 

Signals

void attachmentLoaded ()
 Emitted after the attachment content has been successfully loaded, set, and the layout updated.
 

Public Member Functions

 AttachmentPlaceholder (const QString &filename, const QString &type, QWidget *parent=nullptr)
 Constructs an AttachmentPlaceholder widget. Initializes the UI elements (labels, button, container) and sets up connections. Automatically triggers loading after a short delay.
 
void SetAttachmentReference (const QString &attachment_id, const QString &mime_type)
 Sets the reference ID and MIME type for an attachment whose data is stored in AttachmentDataStore.
 
void SetBase64Data (const QString &base64_data, const QString &mime_type)
 Sets the attachment data directly as a base64 encoded string.
 
void SetContent (QWidget *content)
 Sets the actual content widget to be displayed within the placeholder. Replaces any existing content, hides loading indicators, makes the content visible, adjusts layout and size policies, and emits attachmentLoaded() after a short delay.
 
void SetLoading (bool loading) const
 Updates the UI elements to reflect the loading state. Disables/enables the load button and shows/hides the progress label with appropriate text.
 
QSize sizeHint () const override
 Provides a size hint for the placeholder widget. Returns a base size if no content is loaded, otherwise calculates a size based on the content's size hint plus space for labels/buttons.
 

Private Slots

void onLoadButtonClicked ()
 Slot triggered when the load/retry button is clicked or automatically after initialization. Initiates the attachment loading process by adding a task to the AttachmentQueueManager. Determines whether to fetch data from AttachmentDataStore or use directly provided base64 data.
 

Private Member Functions

bool eventFilter (QObject *watched, QEvent *event) override
 Filters events, specifically handling mouse clicks on the video thumbnail label.
 
void NotifyLoaded ()
 Emits the attachmentLoaded signal after ensuring layout updates. Called internally after SetContent completes its delayed updates.
 

Private Attributes

QString attachment_id_
 Stores the attachment ID if data is referenced from AttachmentDataStore.
 
QString base64_data_
 Stores the base64 encoded data if provided directly.
 
std::function< void()> ClickHandler_
 Function object (lambda) storing the action to perform when the video thumbnail is clicked.
 
QWidget * content_container_
 Container widget holding the loaded attachment content.
 
QVBoxLayout * content_layout_
 Layout for the content_container_.
 
QString filename_
 The original filename of the attachment.
 
bool has_reference_ = false
 Flag indicating if attachment_id_ refers to data in AttachmentDataStore.
 
QLabel * info_label_
 Label displaying the attachment icon and filename.
 
bool is_loaded_
 Flag indicating if the attachment content has been successfully loaded and set.
 
QPushButton * load_button_
 Button to initiate loading or retry on error.
 
QString mime_type_
 The MIME type of the attachment (e.g., "image/png").
 
QLabel * progress_label_
 Label displaying loading progress or error messages.
 
QLabel * thumbnail_label_ = nullptr
 Pointer to the QLabel used for the video thumbnail preview.
 
TranslationManagertranslator_ = nullptr
 Translation manager for handling UI text translations.
 
QByteArray video_data_
 Temporary storage for video data when opening the player overlay.
 

Detailed Description

A widget that acts as a placeholder for chat attachments before they are loaded.

This class displays information about an attachment (filename, type icon) and provides a mechanism to load and display the actual content (image, GIF, audio, video). It handles fetching data (either directly provided or via AttachmentDataStore), decoding, selecting the appropriate viewer widget, and managing the loading state (progress, errors). It also provides functionality to show attachments in a full-size dialog.

Constructor & Destructor Documentation

◆ AttachmentPlaceholder()

AttachmentPlaceholder::AttachmentPlaceholder ( const QString & filename,
const QString & type,
QWidget * parent = nullptr )
explicit

Constructs an AttachmentPlaceholder widget. Initializes the UI elements (labels, button, container) and sets up connections. Automatically triggers loading after a short delay.

Parameters
filenameThe original filename of the attachment.
typeThe general type of the attachment (e.g., "image", "audio", "video", "gif"). Used for icon selection.
parentOptional parent widget.
Here is the call graph for this function:

Member Function Documentation

◆ AdjustAndShowDialog

void AttachmentPlaceholder::AdjustAndShowDialog ( QDialog * dialog,
const QScrollArea * scroll_area,
QWidget * content_widget,
QSize original_content_size ) const
slot

Adjusts the size and position of the full-size dialog and shows it. Calculates the preferred dialog size based on the original content size, limits it to the available screen geometry, centers it, and makes it visible. Sets the content widget to its original fixed size to ensure scrollbars appear correctly if needed.

Parameters
dialogThe QDialog instance to adjust and show.
scroll_areaThe QScrollArea containing the content.
content_widgetThe widget displaying the actual content (image/GIF).
original_content_sizeThe original, unscaled size of the content widget.
Here is the caller graph for this function:

◆ attachmentLoaded

void AttachmentPlaceholder::attachmentLoaded ( )
signal

Emitted after the attachment content has been successfully loaded, set, and the layout updated.

Here is the caller graph for this function:

◆ eventFilter()

bool AttachmentPlaceholder::eventFilter ( QObject * watched,
QEvent * event )
overrideprivate

Filters events, specifically handling mouse clicks on the video thumbnail label.

Parameters
watchedThe object being watched.
eventThe event being processed.
Returns
True if the event was handled (thumbnail clicked), false otherwise.

◆ GenerateThumbnail

void AttachmentPlaceholder::GenerateThumbnail ( const QByteArray & video_data,
QLabel * thumbnail_label )
slot

Generates a thumbnail image from the first frame of a video in a background thread. Uses VideoDecoder to extract the frame and updates the provided QLabel with the thumbnail. Adds a play icon overlay to the thumbnail.

Parameters
video_dataThe raw byte data of the video.
thumbnail_labelThe QLabel widget to display the generated thumbnail.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NotifyLoaded()

void AttachmentPlaceholder::NotifyLoaded ( )
private

Emits the attachmentLoaded signal after ensuring layout updates. Called internally after SetContent completes its delayed updates.

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

◆ onLoadButtonClicked

void AttachmentPlaceholder::onLoadButtonClicked ( )
privateslot

Slot triggered when the load/retry button is clicked or automatically after initialization. Initiates the attachment loading process by adding a task to the AttachmentQueueManager. Determines whether to fetch data from AttachmentDataStore or use directly provided base64 data.

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

◆ SetAttachmentReference()

void AttachmentPlaceholder::SetAttachmentReference ( const QString & attachment_id,
const QString & mime_type )

Sets the reference ID and MIME type for an attachment whose data is stored in AttachmentDataStore.

Parameters
attachment_idThe unique ID referencing the data in AttachmentDataStore.
mime_typeThe MIME type of the attachment (e.g., "image/png", "audio/mpeg").

◆ SetBase64Data()

void AttachmentPlaceholder::SetBase64Data ( const QString & base64_data,
const QString & mime_type )

Sets the attachment data directly as a base64 encoded string.

Parameters
base64_dataThe base64 encoded attachment data.
mime_typeThe MIME type of the attachment.

◆ SetContent()

void AttachmentPlaceholder::SetContent ( QWidget * content)

Sets the actual content widget to be displayed within the placeholder. Replaces any existing content, hides loading indicators, makes the content visible, adjusts layout and size policies, and emits attachmentLoaded() after a short delay.

Parameters
contentThe QWidget containing the loaded attachment content (e.g., ImageViewer, GifPlayer).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetError

void AttachmentPlaceholder::SetError ( const QString & error_msg)
slot

Updates the UI to display an error message. Enables the retry button and shows the error message in the progress label.

Parameters
error_msgThe error message to display.

◆ SetLoading()

void AttachmentPlaceholder::SetLoading ( bool loading) const

Updates the UI elements to reflect the loading state. Disables/enables the load button and shows/hides the progress label with appropriate text.

Parameters
loadingTrue if loading is in progress, false otherwise.
Here is the caller graph for this function:

◆ ShowCyberAudio

void AttachmentPlaceholder::ShowCyberAudio ( const QByteArray & data)
slot

Creates and displays a CyberAttachmentViewer containing an audio player. Uses InlineAudioPlayer.

Parameters
dataThe raw byte data of the audio file.
Here is the call graph for this function:

◆ ShowCyberGif

void AttachmentPlaceholder::ShowCyberGif ( const QByteArray & data)
slot

Creates and displays a CyberAttachmentViewer containing a GIF. Wraps an InlineGifPlayer in an AutoScalingAttachment to handle thumbnail scaling and click-to-enlarge.

Parameters
dataThe raw byte data of the GIF.
Here is the call graph for this function:

◆ ShowCyberImage

void AttachmentPlaceholder::ShowCyberImage ( const QByteArray & data)
slot

Creates and displays a CyberAttachmentViewer containing an image. Wraps an InlineImageViewer in an AutoScalingAttachment to handle thumbnail scaling and click-to-enlarge.

Parameters
dataThe raw byte data of the image.
Here is the call graph for this function:

◆ ShowCyberVideo

void AttachmentPlaceholder::ShowCyberVideo ( const QByteArray & data)
slot

Creates and displays a CyberAttachmentViewer containing a video preview (thumbnail + play button). Clicking the preview opens a VideoPlayerOverlay dialog.

Parameters
dataThe raw byte data of the video file.
Here is the call graph for this function:

◆ ShowFullSizeDialog

void AttachmentPlaceholder::ShowFullSizeDialog ( const QByteArray & data,
bool is_gif )
slot

Creates and shows a non-modal dialog to display the full-size attachment (image or GIF). Uses InlineImageViewer or InlineGifPlayer within a QScrollArea.

Parameters
dataThe raw byte data of the attachment.
is_gifTrue if the data represents a GIF, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sizeHint()

QSize AttachmentPlaceholder::sizeHint ( ) const
override

Provides a size hint for the placeholder widget. Returns a base size if no content is loaded, otherwise calculates a size based on the content's size hint plus space for labels/buttons.

Returns
The recommended size for the widget.

Member Data Documentation

◆ attachment_id_

QString AttachmentPlaceholder::attachment_id_
private

Stores the attachment ID if data is referenced from AttachmentDataStore.

◆ base64_data_

QString AttachmentPlaceholder::base64_data_
private

Stores the base64 encoded data if provided directly.

◆ ClickHandler_

std::function<void()> AttachmentPlaceholder::ClickHandler_
private

Function object (lambda) storing the action to perform when the video thumbnail is clicked.

◆ content_container_

QWidget* AttachmentPlaceholder::content_container_
private

Container widget holding the loaded attachment content.

◆ content_layout_

QVBoxLayout* AttachmentPlaceholder::content_layout_
private

Layout for the content_container_.

◆ filename_

QString AttachmentPlaceholder::filename_
private

The original filename of the attachment.

◆ has_reference_

bool AttachmentPlaceholder::has_reference_ = false
private

Flag indicating if attachment_id_ refers to data in AttachmentDataStore.

◆ info_label_

QLabel* AttachmentPlaceholder::info_label_
private

Label displaying the attachment icon and filename.

◆ is_loaded_

bool AttachmentPlaceholder::is_loaded_
private

Flag indicating if the attachment content has been successfully loaded and set.

◆ load_button_

QPushButton* AttachmentPlaceholder::load_button_
private

Button to initiate loading or retry on error.

◆ mime_type_

QString AttachmentPlaceholder::mime_type_
private

The MIME type of the attachment (e.g., "image/png").

◆ progress_label_

QLabel* AttachmentPlaceholder::progress_label_
private

Label displaying loading progress or error messages.

◆ thumbnail_label_

QLabel* AttachmentPlaceholder::thumbnail_label_ = nullptr
private

Pointer to the QLabel used for the video thumbnail preview.

◆ translator_

TranslationManager* AttachmentPlaceholder::translator_ = nullptr
private

Translation manager for handling UI text translations.

◆ video_data_

QByteArray AttachmentPlaceholder::video_data_
private

Temporary storage for video data when opening the player overlay.


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