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

152 lines
3.8 KiB
C
Raw Normal View History

2017-12-13 18:10:48 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2017-12-13 18:10:48 +00:00
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
2017-12-13 18:10:48 +00:00
*/
#pragma once
#include "history/view/media/history_view_media.h"
2017-12-13 18:10:48 +00:00
#include "data/data_document.h"
#include "data/data_photo.h"
namespace Data {
class Media;
} // namespace Data
namespace HistoryView {
class GroupedMedia : public Media {
2017-12-13 18:10:48 +00:00
public:
static constexpr auto kMaxSize = 10;
GroupedMedia(
not_null<Element*> parent,
const std::vector<std::unique_ptr<Data::Media>> &medias);
GroupedMedia(
not_null<Element*> parent,
const std::vector<not_null<HistoryItem*>> &items);
2020-05-26 13:40:36 +00:00
~GroupedMedia();
2017-12-13 18:10:48 +00:00
void refreshParentId(not_null<HistoryItem*> realParent) override;
2017-12-13 18:10:48 +00:00
void drawHighlight(
Painter &p,
const PaintContext &context,
int top) const override;
void draw(Painter &p, const PaintContext &context) const override;
PointState pointState(QPoint point) const override;
TextState textState(
2017-12-13 18:10:48 +00:00
QPoint point,
StateRequest request) const override;
2017-12-13 18:10:48 +00:00
bool toggleSelectionByHandlerClick(
const ClickHandlerPtr &p) const override;
bool dragItemByHandler(const ClickHandlerPtr &p) const override;
[[nodiscard]] TextSelection adjustSelection(
TextSelection selection,
TextSelectType type) const override;
uint16 fullSelectionLength() const override;
bool hasTextForCopy() const override;
2017-12-13 18:10:48 +00:00
2017-12-19 16:57:42 +00:00
PhotoData *getPhoto() const override;
DocumentData *getDocument() const override;
TextForMimeData selectedText(TextSelection selection) const override;
2017-12-13 18:10:48 +00:00
std::vector<Ui::BubbleSelectionInterval> getBubbleSelectionIntervals(
2020-10-06 18:27:26 +00:00
TextSelection selection) const override;
2017-12-13 18:10:48 +00:00
void clickHandlerActiveChanged(
const ClickHandlerPtr &p,
bool active) override;
void clickHandlerPressedChanged(
const ClickHandlerPtr &p,
bool pressed) override;
TextWithEntities getCaption() const override;
2017-12-13 18:10:48 +00:00
Storage::SharedMediaTypesMask sharedMediaTypes() const override;
bool overrideEditedDate() const override {
return true;
}
HistoryMessageEdited *displayedEditBadge() const override;
2017-12-13 18:10:48 +00:00
bool skipBubbleTail() const override {
2020-10-06 18:27:26 +00:00
return (_mode == Mode::Grid)
&& isRoundedInBubbleBottom()
&& _caption.isEmpty();
2017-12-13 18:10:48 +00:00
}
void updateNeedBubbleState() override;
bool needsBubble() const override;
bool customInfoLayout() const override {
return _caption.isEmpty() && (_mode != Mode::Column);
2017-12-13 18:10:48 +00:00
}
bool allowsFastShare() const override {
return true;
}
bool customHighlight() const override {
return true;
}
2017-12-13 18:10:48 +00:00
2019-12-25 09:01:49 +00:00
void stopAnimation() override;
void checkAnimation() override;
2020-05-26 13:40:36 +00:00
bool hasHeavyPart() const override;
2019-12-25 09:01:49 +00:00
void unloadHeavyPart() override;
void parentTextUpdated() override;
2017-12-13 18:10:48 +00:00
private:
2020-10-06 18:27:26 +00:00
enum class Mode : char {
Grid,
Column,
2020-10-06 18:27:26 +00:00
};
struct Part {
Part(
not_null<Element*> parent,
not_null<Data::Media*> media);
2017-12-13 18:10:48 +00:00
not_null<HistoryItem*> item;
std::unique_ptr<Media> content;
2017-12-13 18:10:48 +00:00
RectParts sides = RectPart::None;
QRect initialGeometry;
QRect geometry;
mutable uint64 cacheKey = 0;
mutable QPixmap cache;
};
2020-10-06 18:27:26 +00:00
[[nodiscard]] static Mode DetectMode(not_null<Data::Media*> media);
template <typename DataMediaRange>
bool applyGroup(const DataMediaRange &medias);
template <typename DataMediaRange>
bool validateGroupParts(const DataMediaRange &medias) const;
QSize countOptimalSize() override;
QSize countCurrentSize(int newWidth) override;
bool needInfoDisplay() const;
2017-12-13 18:10:48 +00:00
bool computeNeedBubble() const;
not_null<Media*> main() const;
TextState getPartState(
2017-12-16 07:20:04 +00:00
QPoint point,
StateRequest request) const;
2017-12-13 18:10:48 +00:00
2019-12-20 14:13:55 +00:00
[[nodiscard]] RectParts cornersFromSides(RectParts sides) const;
2020-10-19 15:37:59 +00:00
[[nodiscard]] QMargins groupedPadding() const;
2019-12-20 14:13:55 +00:00
2019-06-12 13:26:04 +00:00
Ui::Text::String _caption;
HistoryItem *_captionItem = nullptr;
std::vector<Part> _parts;
2020-10-06 18:27:26 +00:00
Mode _mode = Mode::Grid;
2017-12-13 18:10:48 +00:00
bool _needBubble = false;
};
} // namespace HistoryView