tdesktop/Telegram/SourceFiles/history/view/media/history_view_gif.h

236 lines
6.5 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "history/view/media/history_view_file.h"
#include "media/streaming/media_streaming_common.h"
2020-05-29 16:08:18 +02:00
class Image;
struct HistoryMessageVia;
struct HistoryMessageReply;
struct HistoryMessageForwarded;
2019-12-17 12:11:10 +01:00
class Painter;
namespace Data {
class DocumentMedia;
} // namespace Data
namespace Media {
2019-02-27 12:36:19 +01:00
namespace View {
class PlaybackProgress;
} // namespace View
} // namespace Media
namespace Media {
namespace Streaming {
class Instance;
struct Update;
struct Information;
enum class Error;
} // namespace Streaming
} // namespace Media
namespace HistoryView {
class TranscribeButton;
class Gif final : public File {
public:
Gif(
not_null<Element*> parent,
2019-12-17 12:11:10 +01:00
not_null<HistoryItem*> realParent,
2022-12-12 19:57:17 +01:00
not_null<DocumentData*> document,
bool spoiler);
~Gif();
void draw(Painter &p, const PaintContext &context) const override;
TextState textState(QPoint point, StateRequest request) const override;
void clickHandlerPressedChanged(
const ClickHandlerPtr &p,
bool pressed) override;
[[nodiscard]] TextSelection adjustSelection(
TextSelection selection,
TextSelectType type) const override {
return _caption.adjustSelection(selection, type);
}
uint16 fullSelectionLength() const override {
return _caption.length();
}
bool hasTextForCopy() const override {
return !_caption.isEmpty();
}
TextForMimeData selectedText(TextSelection selection) const override;
2023-10-31 19:37:59 +01:00
SelectedQuote selectedQuote(TextSelection selection) const override;
TextSelection selectionFromQuote(
2023-10-31 19:37:59 +01:00
not_null<HistoryItem*> item,
const TextWithEntities &quote) const override;
bool uploading() const override;
DocumentData *getDocument() const override {
return _data;
}
2019-12-20 15:13:55 +01:00
bool fullFeaturedGrouped(RectParts sides) const;
2020-10-29 16:21:16 +01:00
QSize sizeForGroupingOptimal(int maxWidth) const override;
QSize sizeForGrouping(int width) const override;
2019-12-17 12:11:10 +01:00
void drawGrouped(
Painter &p,
const PaintContext &context,
2019-12-17 12:11:10 +01:00
const QRect &geometry,
2019-12-20 15:13:55 +01:00
RectParts sides,
2022-10-03 10:41:51 +02:00
Ui::BubbleRounding rounding,
float64 highlightOpacity,
2019-12-17 12:11:10 +01:00
not_null<uint64*> cacheKey,
not_null<QPixmap*> cache) const override;
2019-12-17 12:11:10 +01:00
TextState getStateGrouped(
const QRect &geometry,
2019-12-20 15:13:55 +01:00
RectParts sides,
2019-12-17 12:11:10 +01:00
QPoint point,
StateRequest request) const override;
2019-12-17 12:11:10 +01:00
void stopAnimation() override;
void checkAnimation() override;
TextWithEntities getCaption() const override {
return _caption.toTextWithEntities();
}
2022-12-12 19:57:17 +01:00
void hideSpoilers() override;
bool needsBubble() const override;
bool unwrapped() const override;
bool customInfoLayout() const override {
return _caption.isEmpty();
}
QRect contentRectForReactions() const override;
std::optional<int> reactionButtonCenterOverride() const override;
QPoint resolveCustomInfoRightBottom() const override;
QString additionalInfoString() const override;
bool skipBubbleTail() const override {
2020-09-03 09:19:02 +02:00
return isRoundedInBubbleBottom() && _caption.isEmpty();
}
bool isReadyForOpen() const override;
void parentTextUpdated() override;
2020-05-26 15:40:36 +02:00
bool hasHeavyPart() const override;
void unloadHeavyPart() override;
void refreshParentId(not_null<HistoryItem*> realParent) override;
[[nodiscard]] static bool CanPlayInline(not_null<DocumentData*> document);
private:
2019-12-18 19:48:07 +01:00
struct Streamed;
2020-05-22 20:01:04 +02:00
void validateVideoThumbnail() const;
[[nodiscard]] QSize countThumbSize(int &inOutWidthMax) const;
[[nodiscard]] int adjustHeightForLessCrop(
QSize dimensions,
QSize current) const;
2020-05-22 20:01:04 +02:00
float64 dataProgress() const override;
bool dataFinished() const override;
bool dataLoaded() const override;
void ensureDataMediaCreated() const;
2020-05-22 20:01:04 +02:00
void dataMediaCreated() const;
void refreshCaption();
2019-08-01 13:42:24 +02:00
[[nodiscard]] bool autoplayEnabled() const;
void playAnimation(bool autoplay) override;
QSize countOptimalSize() override;
QSize countCurrentSize(int newWidth) override;
QSize videoSize() const;
::Media::Streaming::Instance *activeRoundStreamed() const;
2019-12-18 19:48:07 +01:00
Streamed *activeOwnStreamed() const;
2019-12-11 15:01:11 +01:00
::Media::Streaming::Instance *activeCurrentStreamed() const;
::Media::View::PlaybackProgress *videoPlayback() const;
2019-12-12 14:26:53 +01:00
void createStreamedPlayer();
void checkStreamedIsStarted() const;
2019-12-12 14:26:53 +01:00
void startStreamedPlayer() const;
2019-12-18 19:48:07 +01:00
void setStreamed(std::unique_ptr<Streamed> value);
void handleStreamingUpdate(::Media::Streaming::Update &&update);
void handleStreamingError(::Media::Streaming::Error &&error);
void streamingReady(::Media::Streaming::Information &&info);
2019-12-18 19:48:07 +01:00
void repaintStreamedContent();
void ensureTranscribeButton() const;
void paintTranscribe(
Painter &p,
int x,
int y,
bool right,
const PaintContext &context) const;
[[nodiscard]] bool needInfoDisplay() const;
[[nodiscard]] bool needCornerStatusDisplay() const;
[[nodiscard]] int additionalWidth(
const HistoryMessageVia *via,
const HistoryMessageReply *reply,
const HistoryMessageForwarded *forwarded) const;
[[nodiscard]] int additionalWidth() const;
[[nodiscard]] bool isUnwrapped() const;
void validateThumbCache(
QSize outer,
bool isEllipse,
std::optional<Ui::BubbleRounding> rounding) const;
[[nodiscard]] QImage prepareThumbCache(QSize outer) const;
2022-12-13 07:29:48 +01:00
void validateSpoilerImageCache(
QSize outer,
std::optional<Ui::BubbleRounding> rounding) const;
2019-12-17 12:11:10 +01:00
void validateGroupedCache(
const QRect &geometry,
2022-10-03 10:41:51 +02:00
Ui::BubbleRounding rounding,
2019-12-17 12:11:10 +01:00
not_null<uint64*> cacheKey,
not_null<QPixmap*> cache) const;
2022-05-10 16:22:28 +02:00
void setStatusSize(int64 newSize) const;
2019-12-17 12:11:10 +01:00
void updateStatusText() const;
[[nodiscard]] QSize sizeForAspectRatio() const;
2019-12-17 12:11:10 +01:00
void validateRoundingMask(QSize size) const;
2019-12-17 12:11:10 +01:00
[[nodiscard]] bool downloadInCorner() const;
void drawCornerStatus(
Painter &p,
const PaintContext &context,
QPoint position) const;
2019-12-17 12:11:10 +01:00
[[nodiscard]] TextState cornerStatusTextState(
QPoint point,
2019-12-20 15:13:55 +01:00
StateRequest request,
QPoint position) const;
2019-12-17 12:11:10 +01:00
2023-07-05 17:52:22 +02:00
void togglePollingStory(bool enabled) const;
const not_null<DocumentData*> _data;
const FullStoryId _storyId;
2019-06-12 15:26:04 +02:00
Ui::Text::String _caption;
2019-12-18 19:48:07 +01:00
std::unique_ptr<Streamed> _streamed;
2022-12-12 19:57:17 +01:00
const std::unique_ptr<MediaSpoiler> _spoiler;
mutable std::unique_ptr<TranscribeButton> _transcribe;
mutable std::shared_ptr<Data::DocumentMedia> _dataMedia;
2020-05-22 20:01:04 +02:00
mutable std::unique_ptr<Image> _videoThumbnailFrame;
2019-12-17 12:11:10 +01:00
QString _downloadSize;
mutable QImage _thumbCache;
mutable QImage _roundingMask;
mutable std::optional<Ui::BubbleRounding> _thumbCacheRounding;
mutable bool _thumbCacheBlurred : 1 = false;
mutable bool _thumbIsEllipse : 1 = false;
2023-07-05 17:52:22 +02:00
mutable bool _pollingStory : 1 = false;
};
} // namespace HistoryView