|
Wavelength
Privacy-focused, cross-platform, and open-source communication application
|
A widget that acts as a placeholder for chat attachments before they are loaded. More...
#include <attachment_placeholder.h>
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. | |
| TranslationManager * | translator_ = nullptr |
| Translation manager for handling UI text translations. | |
| QByteArray | video_data_ |
| Temporary storage for video data when opening the player overlay. | |
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.
|
explicit |
Constructs an AttachmentPlaceholder widget. Initializes the UI elements (labels, button, container) and sets up connections. Automatically triggers loading after a short delay.
| filename | The original filename of the attachment. |
| type | The general type of the attachment (e.g., "image", "audio", "video", "gif"). Used for icon selection. |
| parent | Optional parent widget. |
|
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.
| dialog | The QDialog instance to adjust and show. |
| scroll_area | The QScrollArea containing the content. |
| content_widget | The widget displaying the actual content (image/GIF). |
| original_content_size | The original, unscaled size of the content widget. |
|
signal |
Emitted after the attachment content has been successfully loaded, set, and the layout updated.
|
overrideprivate |
Filters events, specifically handling mouse clicks on the video thumbnail label.
| watched | The object being watched. |
| event | The event being processed. |
|
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.
| video_data | The raw byte data of the video. |
| thumbnail_label | The QLabel widget to display the generated thumbnail. |
|
private |
Emits the attachmentLoaded signal after ensuring layout updates. Called internally after SetContent completes its delayed updates.
|
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.
| 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.
| attachment_id | The unique ID referencing the data in AttachmentDataStore. |
| mime_type | The MIME type of the attachment (e.g., "image/png", "audio/mpeg"). |
| void AttachmentPlaceholder::SetBase64Data | ( | const QString & | base64_data, |
| const QString & | mime_type ) |
Sets the attachment data directly as a base64 encoded string.
| base64_data | The base64 encoded attachment data. |
| mime_type | The MIME type of the attachment. |
| 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.
| content | The QWidget containing the loaded attachment content (e.g., ImageViewer, GifPlayer). |
|
slot |
Updates the UI to display an error message. Enables the retry button and shows the error message in the progress label.
| error_msg | The error message to display. |
| 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.
| loading | True if loading is in progress, false otherwise. |
|
slot |
Creates and displays a CyberAttachmentViewer containing an audio player. Uses InlineAudioPlayer.
| data | The raw byte data of the audio file. |
|
slot |
Creates and displays a CyberAttachmentViewer containing a GIF. Wraps an InlineGifPlayer in an AutoScalingAttachment to handle thumbnail scaling and click-to-enlarge.
| data | The raw byte data of the GIF. |
|
slot |
Creates and displays a CyberAttachmentViewer containing an image. Wraps an InlineImageViewer in an AutoScalingAttachment to handle thumbnail scaling and click-to-enlarge.
| data | The raw byte data of the image. |
|
slot |
Creates and displays a CyberAttachmentViewer containing a video preview (thumbnail + play button). Clicking the preview opens a VideoPlayerOverlay dialog.
| data | The raw byte data of the video file. |
|
slot |
Creates and shows a non-modal dialog to display the full-size attachment (image or GIF). Uses InlineImageViewer or InlineGifPlayer within a QScrollArea.
| data | The raw byte data of the attachment. |
| is_gif | True if the data represents a GIF, false otherwise. |
|
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 |
Stores the attachment ID if data is referenced from AttachmentDataStore.
|
private |
Stores the base64 encoded data if provided directly.
|
private |
Function object (lambda) storing the action to perform when the video thumbnail is clicked.
|
private |
Container widget holding the loaded attachment content.
|
private |
Layout for the content_container_.
|
private |
The original filename of the attachment.
|
private |
Flag indicating if attachment_id_ refers to data in AttachmentDataStore.
|
private |
Label displaying the attachment icon and filename.
|
private |
Flag indicating if the attachment content has been successfully loaded and set.
|
private |
Button to initiate loading or retry on error.
|
private |
The MIME type of the attachment (e.g., "image/png").
|
private |
Label displaying loading progress or error messages.
|
private |
Pointer to the QLabel used for the video thumbnail preview.
|
private |
Translation manager for handling UI text translations.
|
private |
Temporary storage for video data when opening the player overlay.