Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
gif_player.h
Go to the documentation of this file.
1#ifndef INLINE_GIF_PLAYER_H
2#define INLINE_GIF_PLAYER_H
3
4#include <QFrame>
5
6class GifDecoder;
7class QLabel;
9
18class GifPlayer final : public QFrame {
19 Q_OBJECT
20
21public:
30 explicit GifPlayer(const QByteArray &gif_data, QWidget *parent = nullptr);
31
35 ~GifPlayer() override {
37 }
38
43 void ReleaseResources();
44
50 [[nodiscard]] QSize sizeHint() const override;
51
57 void StartPlayback();
58
64 void StopPlayback();
65
66protected:
72 void enterEvent(QEvent *event) override;
73
79 void leaveEvent(QEvent *event) override;
80
81private slots:
88 void DisplayThumbnail(const QImage &frame);
89
96 void UpdateFrame(const QImage &frame) const;
97
103 void HandleError(const QString &message);
104
114 void HandleGifInfo(int width, int height, double duration, double frame_rate);
115
116signals:
121 void gifLoaded();
122
123private:
125 QLabel *gif_label_;
127 std::shared_ptr<GifDecoder> decoder_;
128
130 QByteArray gif_data_;
131
133 int gif_width_ = 0;
135 int gif_height_ = 0;
137 double gif_duration_ = 0;
139 double frame_rate_ = 0;
143 bool is_playing_ = false;
148};
149
150#endif //INLINE_GIF_PLAYER_H
Decodes GIF data frame by frame using FFmpeg libraries in a separate thread.
Definition gif_decoder.h:29
double current_position_
Current playback position in seconds. Updated by UpdatePosition.
Definition gif_player.h:141
std::shared_ptr< GifDecoder > decoder_
Shared pointer to the GifDecoder instance responsible for decoding.
Definition gif_player.h:127
void HandleGifInfo(int width, int height, double duration, double frame_rate)
Slot connected to the decoder's gifInfo signal. Stores the GIF's dimensions, duration,...
Definition gif_player.cpp:114
void leaveEvent(QEvent *event) override
Handles mouse leave events. Calls StopPlayback() to pause animation when the mouse cursor leaves the ...
Definition gif_player.cpp:84
void DisplayThumbnail(const QImage &frame)
Slot connected to the decoder's firstFrameReady signal. Displays the provided frame as a static thumb...
Definition gif_player.cpp:89
double gif_duration_
Total duration of the GIF in seconds. Set by HandleGifInfo.
Definition gif_player.h:137
QSize sizeHint() const override
Provides a size hint based on the original dimensions of the GIF. Returns the actual GIF width and he...
Definition gif_player.cpp:58
void UpdateFrame(const QImage &frame) const
Slot connected to the decoder's frameReady signal. Updates the QLabel to display the new frame,...
Definition gif_player.cpp:102
void HandleError(const QString &message)
Slot connected to the decoder's error signal. Logs the error message and displays it in the QLabel....
Definition gif_player.cpp:107
QLabel * gif_label_
QLabel used to display the GIF frames. ScaledContents is enabled.
Definition gif_player.h:125
QPixmap thumbnail_pixmap_
Stores the first frame as a QPixmap for efficient display as a thumbnail.
Definition gif_player.h:145
TranslationManager * translator_
Pointer to the translation manager for handling UI translations.
Definition gif_player.h:147
QByteArray gif_data_
Stores the raw GIF data passed in the constructor.
Definition gif_player.h:130
void ReleaseResources()
Stops the decoder thread, waits for it to finish (with timeout), and resets the decoder pointer....
Definition gif_player.cpp:47
void StartPlayback()
Starts or resumes GIF playback. Sets the is_playing_ flag and calls Resume() on the GifDecoder....
Definition gif_player.cpp:65
void gifLoaded()
Emitted after the GIF information (dimensions, duration, etc.) has been successfully received from th...
int gif_height_
Original height of the GIF in pixels. Set by HandleGifInfo.
Definition gif_player.h:135
double frame_rate_
Average frame rate of the GIF. Set by HandleGifInfo.
Definition gif_player.h:139
void enterEvent(QEvent *event) override
Handles mouse enter events. Calls StartPlayback() to begin animation when the mouse cursor enters the...
Definition gif_player.cpp:79
bool is_playing_
Flag indicating if the GIF is currently playing (mouse hover).
Definition gif_player.h:143
void StopPlayback()
Stops or pauses GIF playback. Clears the is_playing_ flag and calls Pause() on the GifDecoder....
Definition gif_player.cpp:72
GifPlayer(const QByteArray &gif_data, QWidget *parent=nullptr)
Constructs an InlineGifPlayer widget. Initializes the UI (QLabel for display), creates the GifDecoder...
Definition gif_player.cpp:11
int gif_width_
Original width of the GIF in pixels. Set by HandleGifInfo.
Definition gif_player.h:133
~GifPlayer() override
Destructor. Ensures resources are released by calling ReleaseResources().
Definition gif_player.h:35
Manages the loading and delivery of translations for applications.
Definition translation_manager.h:15