2017-12-28 13:06:06 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-12-28 13:06:06 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-12-28 13:06:06 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
#include "history/history_item_components.h"
|
2017-12-29 14:58:53 +00:00
|
|
|
#include "base/weak_ptr.h"
|
2017-12-28 14:58:34 +00:00
|
|
|
|
|
|
|
class SharedMediaWithLastSlice;
|
|
|
|
class UserPhotosSlice;
|
|
|
|
|
2017-12-28 13:06:06 +00:00
|
|
|
namespace Media {
|
|
|
|
namespace View {
|
|
|
|
|
2017-12-29 14:58:53 +00:00
|
|
|
class GroupThumbs : public base::has_weak_ptr {
|
2017-12-28 13:06:06 +00:00
|
|
|
public:
|
2017-12-29 14:58:53 +00:00
|
|
|
using Key = base::variant<PhotoId, FullMsgId>;
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
static void Refresh(
|
|
|
|
std::unique_ptr<GroupThumbs> &instance,
|
|
|
|
const SharedMediaWithLastSlice &slice,
|
|
|
|
int index,
|
|
|
|
int availableWidth);
|
|
|
|
static void Refresh(
|
|
|
|
std::unique_ptr<GroupThumbs> &instance,
|
|
|
|
const UserPhotosSlice &slice,
|
|
|
|
int index,
|
|
|
|
int availableWidth);
|
|
|
|
void clear();
|
2017-12-28 13:06:06 +00:00
|
|
|
|
|
|
|
void resizeToWidth(int newWidth);
|
|
|
|
int height() const;
|
2017-12-28 14:58:34 +00:00
|
|
|
bool hiding() const;
|
|
|
|
bool hidden() const;
|
|
|
|
void checkForAnimationStart();
|
|
|
|
|
|
|
|
void paint(Painter &p, int x, int y, int outerWidth, TimeMs ms);
|
2017-12-29 14:58:53 +00:00
|
|
|
ClickHandlerPtr getState(QPoint point) const;
|
2017-12-28 14:58:34 +00:00
|
|
|
|
|
|
|
rpl::producer<QRect> updateRequests() const {
|
|
|
|
return _updateRequests.events();
|
|
|
|
}
|
|
|
|
|
2017-12-29 14:58:53 +00:00
|
|
|
rpl::producer<Key> activateRequests() const {
|
|
|
|
return _activateStream.events();
|
|
|
|
}
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
rpl::lifetime &lifetime() {
|
|
|
|
return _lifetime;
|
|
|
|
}
|
2017-12-28 13:06:06 +00:00
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
using Context = base::optional_variant<PeerId, MessageGroupId>;
|
|
|
|
|
|
|
|
GroupThumbs(Context context);
|
|
|
|
~GroupThumbs();
|
2017-12-28 13:06:06 +00:00
|
|
|
|
|
|
|
private:
|
2017-12-28 14:58:34 +00:00
|
|
|
class Thumb;
|
|
|
|
|
|
|
|
template <typename Slice>
|
|
|
|
static void RefreshFromSlice(
|
|
|
|
std::unique_ptr<GroupThumbs> &instance,
|
|
|
|
const Slice &slice,
|
|
|
|
int index,
|
|
|
|
int availableWidth);
|
|
|
|
template <typename Slice>
|
|
|
|
void fillItems(const Slice &slice, int from, int index, int till);
|
|
|
|
void updateContext(Context context);
|
|
|
|
void markCacheStale();
|
|
|
|
not_null<Thumb*> validateCacheEntry(Key key);
|
|
|
|
std::unique_ptr<Thumb> createThumb(Key key);
|
|
|
|
std::unique_ptr<Thumb> createThumb(Key key, ImagePtr image);
|
|
|
|
|
|
|
|
void update();
|
|
|
|
void countUpdatedRect();
|
|
|
|
void animateAliveItems(int current);
|
|
|
|
void fillDyingItems(const std::vector<not_null<Thumb*>> &old);
|
|
|
|
void markAsDying(not_null<Thumb*> thumb);
|
|
|
|
void markRestAsDying();
|
|
|
|
void animatePreviouslyAlive(const std::vector<not_null<Thumb*>> &old);
|
|
|
|
void startDelayedAnimation();
|
|
|
|
|
|
|
|
Context _context;
|
|
|
|
bool _waitingForAnimationStart = true;
|
|
|
|
Animation _animation;
|
|
|
|
std::vector<not_null<Thumb*>> _items;
|
|
|
|
std::vector<not_null<Thumb*>> _dying;
|
|
|
|
base::flat_map<Key, std::unique_ptr<Thumb>> _cache;
|
|
|
|
int _width = 0;
|
2017-12-29 14:58:53 +00:00
|
|
|
QRect _updatedRect;
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
rpl::event_stream<QRect> _updateRequests;
|
2017-12-29 14:58:53 +00:00
|
|
|
rpl::event_stream<Key> _activateStream;
|
2017-12-28 14:58:34 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2017-12-28 13:06:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace View
|
|
|
|
} // namespace Media
|