A widget for displaying static images (PNG, JPEG, etc.) within a chat interface.
More...
#include <image_viewer.h>
|
| void | imageInfoReady (int width, int height, bool has_alpha) |
| | Emitted after the image information (dimensions, alpha) has been successfully received from the decoder.
|
| |
| void | imageLoaded () |
| | Emitted after the image has been successfully decoded and set in the QLabel. Can be used by parent widgets to adjust layout once the image is ready for display.
|
| |
|
| | ImageViewer (const QByteArray &image_data, QWidget *parent=nullptr) |
| | Constructs an InlineImageViewer widget. Initializes the UI (QLabel), creates the ImageDecoder instance, connects signals and triggers asynchronous decoding of the image data.
|
| |
| void | ReleaseResources () |
| | Releases resources held by the ImageDecoder. Resets the shared pointer to the decoder.
|
| |
| QSize | sizeHint () const override |
| | Provides a size hint based on the original dimensions of the loaded image. Returns the actual image size once loaded, otherwise falls back to the default QFrame size hint.
|
| |
| | ~ImageViewer () override |
| | Destructor. Ensures resources are released by calling ReleaseResources().
|
| |
|
| void | HandleError (const QString &message) |
| | Slot connected to the decoder's error signal. Logs the error and displays an error message in the QLabel. Sets a minimum size to ensure the error message is visible.
|
| |
| void | HandleImageInfo (int width, int height, bool has_alpha) |
| | Slot connected to the decoder's imageInfo signal. Stores the image dimensions and alpha channel information. Emits the imageInfoReady() signal.
|
| |
| void | HandleImageReady (const QImage &image) |
| | Slot connected to the decoder's imageReady signal. Stores the decoded image, sets it as the pixmap for the internal QLabel, updates the widget's geometry, and emits the imageLoaded() signal. Relies on the QLabel's setScaledContents(true) for display scaling.
|
| |
| void | LoadImage () const |
| | Initiates the image decoding process by calling Decode() on the ImageDecoder. Called asynchronously via QTimer::singleShot after the constructor finishes.
|
| |
|
| std::shared_ptr< ImageDecoder > | decoder_ |
| | Shared pointer to the ImageDecoder instance responsible for decoding.
|
| |
| bool | has_alpha_ = false |
| | Flag indicating if the image has an alpha channel. Set by HandleImageInfo.
|
| |
| QByteArray | image_data_ |
| | Stores the raw image data passed in the constructor.
|
| |
| int | image_height_ = 0 |
| | Original height of the image in pixels. Set by HandleImageInfo.
|
| |
| QLabel * | image_label_ |
| | QLabel used to display the image. ScaledContents is enabled.
|
| |
| int | image_width_ = 0 |
| | Original width of the image in pixels. Set by HandleImageInfo.
|
| |
| QImage | original_image_ |
| | Stores the original, unscaled decoded image.
|
| |
| TranslationManager * | translator_ = nullptr |
| | Pointer to the translation manager for handling UI translations.
|
| |
A widget for displaying static images (PNG, JPEG, etc.) within a chat interface.
This class uses ImageDecoder (which relies on Qt's image loading) to decode image data. It displays the image within a QLabel, automatically scaling the content to fit the label's size while preserving an aspect ratio (due to QLabel's setScaledContents(true)). It provides signals for when the image is loaded and when its information (size, alpha) is available.
◆ ImageViewer()
| ImageViewer::ImageViewer |
( |
const QByteArray & | image_data, |
|
|
QWidget * | parent = nullptr ) |
|
explicit |
Constructs an InlineImageViewer widget. Initializes the UI (QLabel), creates the ImageDecoder instance, connects signals and triggers asynchronous decoding of the image data.
- Parameters
-
| image_data | The raw image data to be displayed. |
| parent | Optional parent widget. |
◆ ~ImageViewer()
| ImageViewer::~ImageViewer |
( |
| ) |
|
|
inlineoverride |
◆ HandleError
| void ImageViewer::HandleError |
( |
const QString & | message | ) |
|
|
privateslot |
Slot connected to the decoder's error signal. Logs the error and displays an error message in the QLabel. Sets a minimum size to ensure the error message is visible.
- Parameters
-
| message | The error message from the decoder. |
◆ HandleImageInfo
| void ImageViewer::HandleImageInfo |
( |
int | width, |
|
|
int | height, |
|
|
bool | has_alpha ) |
|
privateslot |
Slot connected to the decoder's imageInfo signal. Stores the image dimensions and alpha channel information. Emits the imageInfoReady() signal.
- Parameters
-
| width | The width of the image in pixels. |
| height | The height of the image in pixels. |
| has_alpha | True if the image has an alpha channel. |
◆ HandleImageReady
| void ImageViewer::HandleImageReady |
( |
const QImage & | image | ) |
|
|
privateslot |
Slot connected to the decoder's imageReady signal. Stores the decoded image, sets it as the pixmap for the internal QLabel, updates the widget's geometry, and emits the imageLoaded() signal. Relies on the QLabel's setScaledContents(true) for display scaling.
- Parameters
-
| image | The successfully decoded QImage. |
◆ imageInfoReady
| void ImageViewer::imageInfoReady |
( |
int | width, |
|
|
int | height, |
|
|
bool | has_alpha ) |
|
signal |
Emitted after the image information (dimensions, alpha) has been successfully received from the decoder.
- Parameters
-
| width | The width of the image in pixels. |
| height | The height of the image in pixels. |
| has_alpha | True if the image has an alpha channel. |
◆ imageLoaded
| void ImageViewer::imageLoaded |
( |
| ) |
|
|
signal |
Emitted after the image has been successfully decoded and set in the QLabel. Can be used by parent widgets to adjust layout once the image is ready for display.
◆ LoadImage
| void ImageViewer::LoadImage |
( |
| ) |
const |
|
privateslot |
Initiates the image decoding process by calling Decode() on the ImageDecoder. Called asynchronously via QTimer::singleShot after the constructor finishes.
◆ ReleaseResources()
| void ImageViewer::ReleaseResources |
( |
| ) |
|
Releases resources held by the ImageDecoder. Resets the shared pointer to the decoder.
◆ sizeHint()
| QSize ImageViewer::sizeHint |
( |
| ) |
const |
|
nodiscardoverride |
Provides a size hint based on the original dimensions of the loaded image. Returns the actual image size once loaded, otherwise falls back to the default QFrame size hint.
- Returns
- The recommended QSize for the widget (original image size).
◆ decoder_
Shared pointer to the ImageDecoder instance responsible for decoding.
◆ has_alpha_
| bool ImageViewer::has_alpha_ = false |
|
private |
Flag indicating if the image has an alpha channel. Set by HandleImageInfo.
◆ image_data_
| QByteArray ImageViewer::image_data_ |
|
private |
Stores the raw image data passed in the constructor.
◆ image_height_
| int ImageViewer::image_height_ = 0 |
|
private |
Original height of the image in pixels. Set by HandleImageInfo.
◆ image_label_
| QLabel* ImageViewer::image_label_ |
|
private |
QLabel used to display the image. ScaledContents is enabled.
◆ image_width_
| int ImageViewer::image_width_ = 0 |
|
private |
Original width of the image in pixels. Set by HandleImageInfo.
◆ original_image_
| QImage ImageViewer::original_image_ |
|
private |
Stores the original, unscaled decoded image.
◆ translator_
Pointer to the translation manager for handling UI translations.
The documentation for this class was generated from the following files: