Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
image_viewer.h
Go to the documentation of this file.
1#ifndef INLINE_IMAGE_VIEWER_H
2#define INLINE_IMAGE_VIEWER_H
3
4#include <QFrame>
5
6class QLabel;
7class ImageDecoder;
9
18class ImageViewer final : public QFrame {
19 Q_OBJECT
20
21public:
29 explicit ImageViewer(const QByteArray &image_data, QWidget *parent = nullptr);
30
34 ~ImageViewer() override {
36 }
37
42 void ReleaseResources();
43
49 [[nodiscard]] QSize sizeHint() const override;
50
51private slots:
56 void LoadImage() const;
57
65 void HandleImageReady(const QImage &image);
66
73 void HandleError(const QString &message);
74
83 void HandleImageInfo(int width, int height, bool has_alpha);
84
85signals:
92 void imageInfoReady(int width, int height, bool has_alpha);
93
99
100private:
104 std::shared_ptr<ImageDecoder> decoder_;
106 QByteArray image_data_;
109
115 bool has_alpha_ = false;
118};
119
120#endif // INLINE_IMAGE_VIEWER_H
Decodes image data using Qt's built-in image loading capabilities.
Definition image_decoder.h:14
void HandleError(const QString &message)
Slot connected to the decoder's error signal. Logs the error and displays an error message in the QLa...
Definition image_viewer.cpp:68
int image_height_
Original height of the image in pixels. Set by HandleImageInfo.
Definition image_viewer.h:113
TranslationManager * translator_
Pointer to the translation manager for handling UI translations.
Definition image_viewer.h:117
void imageLoaded()
Emitted after the image has been successfully decoded and set in the QLabel. Can be used by parent wi...
void LoadImage() const
Initiates the image decoding process by calling Decode() on the ImageDecoder. Called asynchronously v...
Definition image_viewer.cpp:51
~ImageViewer() override
Destructor. Ensures resources are released by calling ReleaseResources().
Definition image_viewer.h:34
void imageInfoReady(int width, int height, bool has_alpha)
Emitted after the image information (dimensions, alpha) has been successfully received from the decod...
QSize sizeHint() const override
Provides a size hint based on the original dimensions of the loaded image. Returns the actual image s...
Definition image_viewer.cpp:44
ImageViewer(const QByteArray &image_data, QWidget *parent=nullptr)
Constructs an InlineImageViewer widget. Initializes the UI (QLabel), creates the ImageDecoder instanc...
Definition image_viewer.cpp:11
QLabel * image_label_
QLabel used to display the image. ScaledContents is enabled.
Definition image_viewer.h:102
bool has_alpha_
Flag indicating if the image has an alpha channel. Set by HandleImageInfo.
Definition image_viewer.h:115
QByteArray image_data_
Stores the raw image data passed in the constructor.
Definition image_viewer.h:106
void ReleaseResources()
Releases resources held by the ImageDecoder. Resets the shared pointer to the decoder.
Definition image_viewer.cpp:37
void HandleImageReady(const QImage &image)
Slot connected to the decoder's imageReady signal. Stores the decoded image, sets it as the pixmap fo...
Definition image_viewer.cpp:56
QImage original_image_
Stores the original, unscaled decoded image.
Definition image_viewer.h:108
void HandleImageInfo(int width, int height, bool has_alpha)
Slot connected to the decoder's imageInfo signal. Stores the image dimensions and alpha channel infor...
Definition image_viewer.cpp:75
int image_width_
Original width of the image in pixels. Set by HandleImageInfo.
Definition image_viewer.h:111
std::shared_ptr< ImageDecoder > decoder_
Shared pointer to the ImageDecoder instance responsible for decoding.
Definition image_viewer.h:104
Manages the loading and delivery of translations for applications.
Definition translation_manager.h:15