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
|
|
|
*/
|
|
|
|
#include "media/view/media_view_group_thumbs.h"
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
#include "data/data_shared_media.h"
|
|
|
|
#include "data/data_user_photos.h"
|
|
|
|
#include "data/data_photo.h"
|
2020-05-25 14:16:04 +00:00
|
|
|
#include "data/data_photo_media.h"
|
2017-12-28 14:58:34 +00:00
|
|
|
#include "data/data_document.h"
|
2020-04-15 14:06:34 +00:00
|
|
|
#include "data/data_document_media.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "data/data_media_types.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "data/data_session.h"
|
2018-10-24 13:09:31 +00:00
|
|
|
#include "data/data_web_page.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_file_origin.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2019-08-02 13:21:09 +00:00
|
|
|
#include "history/view/media/history_view_media.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2021-05-07 14:33:53 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2021-03-15 15:00:32 +00:00
|
|
|
#include "core/crash_reports.h"
|
2020-02-03 09:26:37 +00:00
|
|
|
#include "styles/style_media_view.h"
|
2017-12-28 14:58:34 +00:00
|
|
|
|
2017-12-28 13:06:06 +00:00
|
|
|
namespace Media {
|
|
|
|
namespace View {
|
2017-12-28 14:58:34 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
constexpr auto kThumbDuration = crl::time(150);
|
2017-12-28 13:06:06 +00:00
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
int Round(float64 value) {
|
2021-09-27 08:13:57 +00:00
|
|
|
return int(base::SafeRound(value));
|
2017-12-28 13:06:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
using Context = GroupThumbs::Context;
|
|
|
|
using Key = GroupThumbs::Key;
|
|
|
|
|
2021-07-12 07:13:58 +00:00
|
|
|
#if 0
|
2021-03-15 15:00:32 +00:00
|
|
|
[[nodiscard]] QString DebugSerializeMsgId(FullMsgId itemId) {
|
2021-04-01 21:04:10 +00:00
|
|
|
return QString("msg%1_%2").arg(itemId.channel.bare).arg(itemId.msg);
|
2021-03-15 15:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] QString DebugSerializePeer(PeerId peerId) {
|
|
|
|
return peerIsUser(peerId)
|
2021-04-01 21:04:10 +00:00
|
|
|
? QString("user%1").arg(peerToUser(peerId).bare)
|
2021-03-15 15:00:32 +00:00
|
|
|
: peerIsChat(peerId)
|
2021-04-01 21:04:10 +00:00
|
|
|
? QString("chat%1").arg(peerToChat(peerId).bare)
|
|
|
|
: QString("channel%1").arg(peerToChannel(peerId).bare);
|
2021-03-15 15:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] QString DebugSerializeKey(const Key &key) {
|
|
|
|
return v::match(key, [&](PhotoId photoId) {
|
|
|
|
return QString("photo%1").arg(photoId);
|
|
|
|
}, [](FullMsgId itemId) {
|
|
|
|
return DebugSerializeMsgId(itemId);
|
|
|
|
}, [&](GroupThumbs::CollageKey key) {
|
|
|
|
return QString("collage%1").arg(key.index);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] QString DebugSerializeContext(const Context &context) {
|
|
|
|
return v::match(context, [](PeerId peerId) {
|
|
|
|
return DebugSerializePeer(peerId);
|
|
|
|
}, [](MessageGroupId groupId) {
|
|
|
|
return QString("group_%1_%2"
|
|
|
|
).arg(DebugSerializePeer(groupId.peer)
|
|
|
|
).arg(groupId.value);
|
|
|
|
}, [](FullMsgId item) {
|
|
|
|
return DebugSerializeMsgId(item);
|
|
|
|
}, [](v::null_t) -> QString {
|
|
|
|
return "null";
|
|
|
|
});
|
|
|
|
}
|
2021-07-12 07:13:58 +00:00
|
|
|
#endif
|
2021-03-15 15:00:32 +00:00
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
Data::FileOrigin ComputeFileOrigin(const Key &key, const Context &context) {
|
2020-08-31 08:14:53 +00:00
|
|
|
return v::match(key, [&](PhotoId photoId) {
|
2020-08-31 09:04:17 +00:00
|
|
|
return v::match(context, [&](PeerId peerId) {
|
2018-07-13 21:25:47 +00:00
|
|
|
return peerIsUser(peerId)
|
|
|
|
? Data::FileOriginUserPhoto(peerToUser(peerId), photoId)
|
|
|
|
: Data::FileOrigin(Data::FileOriginPeerPhoto(peerId));
|
2018-10-24 13:09:31 +00:00
|
|
|
}, [](auto&&) {
|
2018-07-13 21:25:47 +00:00
|
|
|
return Data::FileOrigin();
|
|
|
|
});
|
|
|
|
}, [](FullMsgId itemId) {
|
|
|
|
return Data::FileOrigin(itemId);
|
2018-10-24 13:09:31 +00:00
|
|
|
}, [&](GroupThumbs::CollageKey) {
|
2020-08-31 09:04:17 +00:00
|
|
|
return v::match(context, [](const GroupThumbs::CollageSlice &slice) {
|
2018-10-24 13:09:31 +00:00
|
|
|
return Data::FileOrigin(slice.context);
|
|
|
|
}, [](auto&&) {
|
|
|
|
return Data::FileOrigin();
|
|
|
|
});
|
2018-07-13 21:25:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-08 15:17:33 +00:00
|
|
|
Context ComputeContext(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const SharedMediaWithLastSlice &slice,
|
|
|
|
int index) {
|
2017-12-28 14:58:34 +00:00
|
|
|
Expects(index >= 0 && index < slice.size());
|
|
|
|
|
|
|
|
const auto value = slice[index];
|
2020-08-31 08:14:53 +00:00
|
|
|
if (const auto photo = std::get_if<not_null<PhotoData*>>(&value)) {
|
2017-12-28 14:58:34 +00:00
|
|
|
if (const auto peer = (*photo)->peer) {
|
|
|
|
return peer->id;
|
|
|
|
}
|
2020-08-31 08:14:53 +00:00
|
|
|
return v::null;
|
|
|
|
} else if (const auto msgId = std::get_if<FullMsgId>(&value)) {
|
2020-06-08 15:17:33 +00:00
|
|
|
if (const auto item = session->data().message(*msgId)) {
|
2021-11-07 08:06:00 +00:00
|
|
|
if (item->isService()) {
|
2017-12-28 14:58:34 +00:00
|
|
|
return item->history()->peer->id;
|
|
|
|
} else if (const auto groupId = item->groupId()) {
|
|
|
|
return groupId;
|
|
|
|
}
|
|
|
|
}
|
2020-08-31 08:14:53 +00:00
|
|
|
return v::null;
|
2017-12-28 14:58:34 +00:00
|
|
|
}
|
|
|
|
Unexpected("Variant in ComputeContext(SharedMediaWithLastSlice::Value)");
|
|
|
|
}
|
|
|
|
|
2020-06-08 15:17:33 +00:00
|
|
|
Context ComputeContext(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const UserPhotosSlice &slice,
|
|
|
|
int index) {
|
2017-12-28 14:58:34 +00:00
|
|
|
return peerFromUser(slice.key().userId);
|
|
|
|
}
|
|
|
|
|
2020-06-08 15:17:33 +00:00
|
|
|
Context ComputeContext(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const GroupThumbs::CollageSlice &slice,
|
|
|
|
int index) {
|
2018-10-24 13:09:31 +00:00
|
|
|
return slice.context;
|
|
|
|
}
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
Key ComputeKey(const SharedMediaWithLastSlice &slice, int index) {
|
|
|
|
Expects(index >= 0 && index < slice.size());
|
|
|
|
|
|
|
|
const auto value = slice[index];
|
2020-08-31 08:14:53 +00:00
|
|
|
if (const auto photo = std::get_if<not_null<PhotoData*>>(&value)) {
|
2017-12-28 14:58:34 +00:00
|
|
|
return (*photo)->id;
|
2020-08-31 08:14:53 +00:00
|
|
|
} else if (const auto msgId = std::get_if<FullMsgId>(&value)) {
|
2017-12-28 14:58:34 +00:00
|
|
|
return *msgId;
|
|
|
|
}
|
2020-06-08 15:17:33 +00:00
|
|
|
Unexpected("Variant in ComputeKey(SharedMediaWithLastSlice::Value)");
|
2017-12-28 14:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Key ComputeKey(const UserPhotosSlice &slice, int index) {
|
|
|
|
return slice[index];
|
|
|
|
}
|
|
|
|
|
2018-10-24 13:09:31 +00:00
|
|
|
Key ComputeKey(const GroupThumbs::CollageSlice &slice, int index) {
|
|
|
|
return GroupThumbs::CollageKey{ index };
|
|
|
|
}
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
int ComputeThumbsLimit(int availableWidth) {
|
|
|
|
const auto singleWidth = st::mediaviewGroupWidth
|
|
|
|
+ 2 * st::mediaviewGroupSkip;
|
|
|
|
const auto currentWidth = st::mediaviewGroupWidthMax
|
|
|
|
+ 2 * st::mediaviewGroupSkipCurrent;
|
|
|
|
const auto skipForAnimation = 2 * singleWidth;
|
|
|
|
const auto leftWidth = availableWidth
|
|
|
|
- currentWidth
|
|
|
|
- skipForAnimation;
|
|
|
|
return std::max(leftWidth / (2 * singleWidth), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
class GroupThumbs::Thumb {
|
|
|
|
public:
|
|
|
|
enum class State {
|
|
|
|
Unknown,
|
|
|
|
Current,
|
|
|
|
Alive,
|
|
|
|
Dying,
|
|
|
|
};
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
Thumb(Key key, Fn<void()> handler);
|
2018-07-13 21:25:47 +00:00
|
|
|
Thumb(
|
|
|
|
Key key,
|
2020-05-25 14:16:04 +00:00
|
|
|
not_null<PhotoData*> photo,
|
2018-07-13 21:25:47 +00:00
|
|
|
Data::FileOrigin origin,
|
|
|
|
Fn<void()> handler);
|
2020-04-15 14:06:34 +00:00
|
|
|
Thumb(
|
|
|
|
Key key,
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
Data::FileOrigin origin,
|
|
|
|
Fn<void()> handler);
|
2017-12-28 14:58:34 +00:00
|
|
|
|
|
|
|
int leftToUpdate() const;
|
|
|
|
int rightToUpdate() const;
|
|
|
|
|
|
|
|
void animateToLeft(not_null<Thumb*> next);
|
|
|
|
void animateToRight(not_null<Thumb*> prev);
|
|
|
|
|
|
|
|
void setState(State state);
|
|
|
|
State state() const;
|
|
|
|
bool removed() const;
|
|
|
|
|
|
|
|
void paint(Painter &p, int x, int y, int outerWidth, float64 progress);
|
2017-12-29 14:58:53 +00:00
|
|
|
ClickHandlerPtr getState(QPoint point) const;
|
2017-12-28 14:58:34 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QSize wantedPixSize() const;
|
|
|
|
void validateImage();
|
|
|
|
int currentLeft() const;
|
|
|
|
int currentWidth() const;
|
|
|
|
int finalLeft() const;
|
|
|
|
int finalWidth() const;
|
|
|
|
void animateTo(int left, int width);
|
|
|
|
|
2017-12-29 14:58:53 +00:00
|
|
|
ClickHandlerPtr _link;
|
2017-12-28 14:58:34 +00:00
|
|
|
const Key _key;
|
2020-04-15 14:06:34 +00:00
|
|
|
std::shared_ptr<Data::DocumentMedia> _documentMedia;
|
2020-05-25 14:16:04 +00:00
|
|
|
std::shared_ptr<Data::PhotoMedia> _photoMedia;
|
2019-01-25 14:37:28 +00:00
|
|
|
Image *_image = nullptr;
|
2018-07-13 21:25:47 +00:00
|
|
|
Data::FileOrigin _origin;
|
2017-12-28 14:58:34 +00:00
|
|
|
State _state = State::Alive;
|
|
|
|
QPixmap _full;
|
|
|
|
int _fullWidth = 0;
|
2017-12-29 14:58:53 +00:00
|
|
|
bool _hiding = false;
|
2017-12-28 14:58:34 +00:00
|
|
|
|
|
|
|
anim::value _left = { 0. };
|
|
|
|
anim::value _width = { 0. };
|
2017-12-29 14:58:53 +00:00
|
|
|
anim::value _opacity = { 0., 1. };
|
2017-12-28 14:58:34 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
GroupThumbs::Thumb::Thumb(Key key, Fn<void()> handler)
|
|
|
|
: _key(key) {
|
|
|
|
_link = std::make_shared<LambdaClickHandler>(std::move(handler));
|
|
|
|
validateImage();
|
|
|
|
}
|
|
|
|
|
2017-12-29 14:58:53 +00:00
|
|
|
GroupThumbs::Thumb::Thumb(
|
|
|
|
Key key,
|
2020-05-25 14:16:04 +00:00
|
|
|
not_null<PhotoData*> photo,
|
2018-07-13 21:25:47 +00:00
|
|
|
Data::FileOrigin origin,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> handler)
|
2017-12-28 14:58:34 +00:00
|
|
|
: _key(key)
|
2020-05-25 14:16:04 +00:00
|
|
|
, _photoMedia(photo->createMediaView())
|
2018-07-13 21:25:47 +00:00
|
|
|
, _origin(origin) {
|
2017-12-29 14:58:53 +00:00
|
|
|
_link = std::make_shared<LambdaClickHandler>(std::move(handler));
|
2020-05-25 14:16:04 +00:00
|
|
|
_photoMedia->wanted(Data::PhotoSize::Thumbnail, origin);
|
2017-12-28 14:58:34 +00:00
|
|
|
validateImage();
|
|
|
|
}
|
|
|
|
|
2020-04-15 14:06:34 +00:00
|
|
|
GroupThumbs::Thumb::Thumb(
|
|
|
|
Key key,
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
Data::FileOrigin origin,
|
|
|
|
Fn<void()> handler)
|
|
|
|
: _key(key)
|
|
|
|
, _documentMedia(document->createMediaView())
|
|
|
|
, _origin(origin) {
|
|
|
|
_link = std::make_shared<LambdaClickHandler>(std::move(handler));
|
|
|
|
_documentMedia->thumbnailWanted(origin);
|
|
|
|
validateImage();
|
|
|
|
}
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
QSize GroupThumbs::Thumb::wantedPixSize() const {
|
2019-01-25 14:37:28 +00:00
|
|
|
const auto originalWidth = _image ? std::max(_image->width(), 1) : 1;
|
|
|
|
const auto originalHeight = _image ? std::max(_image->height(), 1) : 1;
|
2017-12-28 14:58:34 +00:00
|
|
|
const auto pixHeight = st::mediaviewGroupHeight;
|
|
|
|
const auto pixWidth = originalWidth * pixHeight / originalHeight;
|
|
|
|
return { pixWidth, pixHeight };
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::Thumb::validateImage() {
|
2020-05-25 14:16:04 +00:00
|
|
|
if (!_image) {
|
|
|
|
if (_photoMedia) {
|
|
|
|
_image = _photoMedia->image(Data::PhotoSize::Thumbnail);
|
|
|
|
} else if (_documentMedia) {
|
|
|
|
_image = _documentMedia->thumbnail();
|
|
|
|
}
|
2020-04-15 14:06:34 +00:00
|
|
|
}
|
2019-01-25 14:37:28 +00:00
|
|
|
if (!_full.isNull() || !_image) {
|
2017-12-28 14:58:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto pixSize = wantedPixSize();
|
|
|
|
if (pixSize.width() > st::mediaviewGroupWidthMax) {
|
|
|
|
const auto originalWidth = _image->width();
|
|
|
|
const auto originalHeight = _image->height();
|
|
|
|
const auto takeWidth = originalWidth * st::mediaviewGroupWidthMax
|
|
|
|
/ pixSize.width();
|
2020-12-22 09:45:50 +00:00
|
|
|
auto original = _image->original();
|
|
|
|
original.setDevicePixelRatio(cRetinaFactor());
|
2021-05-07 14:33:53 +00:00
|
|
|
_full = Ui::PixmapFromImage(original.copy(
|
2017-12-28 14:58:34 +00:00
|
|
|
(originalWidth - takeWidth) / 2,
|
|
|
|
0,
|
|
|
|
takeWidth,
|
|
|
|
originalHeight
|
|
|
|
).scaled(
|
|
|
|
st::mediaviewGroupWidthMax * cIntRetinaFactor(),
|
|
|
|
pixSize.height() * cIntRetinaFactor(),
|
|
|
|
Qt::IgnoreAspectRatio,
|
|
|
|
Qt::SmoothTransformation));
|
|
|
|
} else {
|
2022-01-21 12:31:39 +00:00
|
|
|
_full = _image->pixNoCache(pixSize * style::DevicePixelRatio());
|
2017-12-28 14:58:34 +00:00
|
|
|
}
|
2020-12-22 09:45:50 +00:00
|
|
|
_fullWidth = std::min(
|
|
|
|
wantedPixSize().width(),
|
|
|
|
st::mediaviewGroupWidthMax);
|
2017-12-28 14:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GroupThumbs::Thumb::leftToUpdate() const {
|
|
|
|
return Round(std::min(_left.from(), _left.to()));
|
|
|
|
}
|
|
|
|
|
|
|
|
int GroupThumbs::Thumb::rightToUpdate() const {
|
|
|
|
return Round(std::max(
|
|
|
|
_left.from() + _width.from(),
|
|
|
|
_left.to() + _width.to()));
|
|
|
|
}
|
|
|
|
|
|
|
|
int GroupThumbs::Thumb::currentLeft() const {
|
|
|
|
return Round(_left.current());
|
|
|
|
}
|
|
|
|
|
|
|
|
int GroupThumbs::Thumb::currentWidth() const {
|
|
|
|
return Round(_width.current());
|
|
|
|
}
|
|
|
|
|
|
|
|
int GroupThumbs::Thumb::finalLeft() const {
|
|
|
|
return Round(_left.to());
|
|
|
|
}
|
|
|
|
|
|
|
|
int GroupThumbs::Thumb::finalWidth() const {
|
|
|
|
return Round(_width.to());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::Thumb::setState(State state) {
|
|
|
|
const auto isNewThumb = (_state == State::Alive);
|
|
|
|
_state = state;
|
|
|
|
if (_state == State::Current) {
|
|
|
|
if (isNewThumb) {
|
|
|
|
_opacity = anim::value(1.);
|
|
|
|
_left = anim::value(-_fullWidth / 2);
|
|
|
|
_width = anim::value(_fullWidth);
|
|
|
|
} else {
|
2017-12-29 14:58:53 +00:00
|
|
|
_opacity.start(1.);
|
2017-12-28 14:58:34 +00:00
|
|
|
}
|
2017-12-29 14:58:53 +00:00
|
|
|
_hiding = false;
|
2017-12-28 14:58:34 +00:00
|
|
|
animateTo(-_fullWidth / 2, _fullWidth);
|
|
|
|
} else if (_state == State::Alive) {
|
2017-12-29 14:58:53 +00:00
|
|
|
_opacity.start(0.7);
|
|
|
|
_hiding = false;
|
2017-12-28 14:58:34 +00:00
|
|
|
} else if (_state == State::Dying) {
|
2017-12-29 14:58:53 +00:00
|
|
|
_opacity.start(0.);
|
|
|
|
_hiding = true;
|
2017-12-28 14:58:34 +00:00
|
|
|
_left.restart();
|
|
|
|
_width.restart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::Thumb::animateTo(int left, int width) {
|
|
|
|
_left.start(left);
|
|
|
|
_width.start(width);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::Thumb::animateToLeft(not_null<Thumb*> next) {
|
|
|
|
const auto width = st::mediaviewGroupWidth;
|
|
|
|
if (_state == State::Alive) {
|
|
|
|
// New item animation, start exactly from the next, move only.
|
|
|
|
_left = anim::value(next->currentLeft() - width);
|
|
|
|
_width = anim::value(width);
|
|
|
|
} else if (_state == State::Unknown) {
|
|
|
|
// Existing item animation.
|
|
|
|
setState(State::Alive);
|
|
|
|
}
|
|
|
|
const auto skip1 = st::mediaviewGroupSkip;
|
|
|
|
const auto skip2 = (next->state() == State::Current)
|
|
|
|
? st::mediaviewGroupSkipCurrent
|
|
|
|
: st::mediaviewGroupSkip;
|
|
|
|
animateTo(next->finalLeft() - width - skip1 - skip2, width);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::Thumb::animateToRight(not_null<Thumb*> prev) {
|
|
|
|
const auto width = st::mediaviewGroupWidth;
|
|
|
|
if (_state == State::Alive) {
|
|
|
|
// New item animation, start exactly from the next, move only.
|
|
|
|
_left = anim::value(prev->currentLeft() + prev->currentWidth());
|
|
|
|
_width = anim::value(width);
|
|
|
|
} else if (_state == State::Unknown) {
|
|
|
|
// Existing item animation.
|
|
|
|
setState(State::Alive);
|
|
|
|
}
|
|
|
|
const auto skip1 = st::mediaviewGroupSkip;
|
|
|
|
const auto skip2 = (prev->state() == State::Current)
|
|
|
|
? st::mediaviewGroupSkipCurrent
|
|
|
|
: st::mediaviewGroupSkip;
|
|
|
|
animateTo(prev->finalLeft() + prev->finalWidth() + skip1 + skip2, width);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto GroupThumbs::Thumb::state() const -> State {
|
|
|
|
return _state;
|
|
|
|
}
|
2017-12-28 13:06:06 +00:00
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
bool GroupThumbs::Thumb::removed() const {
|
|
|
|
return (_state == State::Dying) && _hiding && !_opacity.current();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::Thumb::paint(
|
|
|
|
Painter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
float64 progress) {
|
|
|
|
validateImage();
|
|
|
|
|
|
|
|
_opacity.update(progress, anim::linear);
|
|
|
|
_left.update(progress, anim::linear);
|
|
|
|
_width.update(progress, anim::linear);
|
|
|
|
|
|
|
|
const auto left = x + currentLeft();
|
|
|
|
const auto width = currentWidth();
|
|
|
|
const auto opacity = p.opacity();
|
|
|
|
p.setOpacity(_opacity.current() * opacity);
|
|
|
|
if (width == _fullWidth) {
|
|
|
|
p.drawPixmap(left, y, _full);
|
|
|
|
} else {
|
|
|
|
const auto takeWidth = width * cIntRetinaFactor();
|
|
|
|
const auto from = QRect(
|
|
|
|
(_full.width() - takeWidth) / 2,
|
|
|
|
0,
|
|
|
|
takeWidth,
|
|
|
|
_full.height());
|
|
|
|
const auto to = QRect(left, y, width, st::mediaviewGroupHeight);
|
|
|
|
p.drawPixmap(to, _full, from);
|
|
|
|
}
|
|
|
|
p.setOpacity(opacity);
|
|
|
|
}
|
|
|
|
|
2017-12-29 14:58:53 +00:00
|
|
|
ClickHandlerPtr GroupThumbs::Thumb::getState(QPoint point) const {
|
|
|
|
if (_state != State::Alive) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const auto left = finalLeft();
|
|
|
|
const auto width = finalWidth();
|
|
|
|
return QRect(left, 0, width, st::mediaviewGroupHeight).contains(point)
|
|
|
|
? _link
|
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
2018-10-24 13:09:31 +00:00
|
|
|
int GroupThumbs::CollageSlice::size() const {
|
|
|
|
return data->items.size();
|
|
|
|
}
|
|
|
|
|
2020-06-08 15:17:33 +00:00
|
|
|
GroupThumbs::GroupThumbs(not_null<Main::Session*> session, Context context)
|
|
|
|
: _session(session)
|
|
|
|
, _context(context) {
|
2017-12-28 14:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::updateContext(Context context) {
|
|
|
|
if (_context != context) {
|
|
|
|
clear();
|
|
|
|
_context = context;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Slice>
|
|
|
|
void GroupThumbs::RefreshFromSlice(
|
2020-06-08 15:17:33 +00:00
|
|
|
not_null<Main::Session*> session,
|
2017-12-28 14:58:34 +00:00
|
|
|
std::unique_ptr<GroupThumbs> &instance,
|
|
|
|
const Slice &slice,
|
|
|
|
int index,
|
|
|
|
int availableWidth) {
|
2020-06-08 15:17:33 +00:00
|
|
|
const auto context = ComputeContext(session, slice, index);
|
2017-12-28 14:58:34 +00:00
|
|
|
if (instance) {
|
|
|
|
instance->updateContext(context);
|
|
|
|
}
|
2020-08-31 09:04:17 +00:00
|
|
|
if (v::is_null(context)) {
|
2017-12-28 14:58:34 +00:00
|
|
|
if (instance) {
|
|
|
|
instance->resizeToWidth(availableWidth);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto limit = ComputeThumbsLimit(availableWidth);
|
|
|
|
const auto from = [&] {
|
|
|
|
const auto edge = std::max(index - limit, 0);
|
|
|
|
for (auto result = index; result != edge; --result) {
|
2020-06-08 15:17:33 +00:00
|
|
|
if (ComputeContext(session, slice, result - 1) != context) {
|
2017-12-28 14:58:34 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return edge;
|
|
|
|
}();
|
|
|
|
const auto till = [&] {
|
|
|
|
const auto edge = std::min(index + limit + 1, slice.size());
|
|
|
|
for (auto result = index + 1; result != edge; ++result) {
|
2020-06-08 15:17:33 +00:00
|
|
|
if (ComputeContext(session, slice, result) != context) {
|
2017-12-28 14:58:34 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return edge;
|
|
|
|
}();
|
|
|
|
if (from + 1 < till) {
|
|
|
|
if (!instance) {
|
2020-06-08 15:17:33 +00:00
|
|
|
instance = std::make_unique<GroupThumbs>(session, context);
|
2017-12-28 14:58:34 +00:00
|
|
|
}
|
|
|
|
instance->fillItems(slice, from, index, till);
|
|
|
|
instance->resizeToWidth(availableWidth);
|
|
|
|
} else if (instance) {
|
|
|
|
instance->clear();
|
|
|
|
instance->resizeToWidth(availableWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-12 07:13:58 +00:00
|
|
|
#if 0
|
2021-03-15 15:00:32 +00:00
|
|
|
template <typename Slice>
|
|
|
|
void ValidateSlice(
|
|
|
|
const Slice &slice,
|
|
|
|
const Context &context,
|
|
|
|
int from,
|
|
|
|
int index,
|
|
|
|
int till) {
|
|
|
|
auto keys = base::flat_set<Key>();
|
|
|
|
for (auto i = from; i != till; ++i) {
|
|
|
|
const auto key = ComputeKey(slice, i);
|
|
|
|
if (keys.contains(key)) {
|
|
|
|
// All items should be unique!
|
|
|
|
auto strings = QStringList();
|
|
|
|
strings.reserve(till - from);
|
|
|
|
for (auto i = from; i != till; ++i) {
|
|
|
|
strings.push_back(DebugSerializeKey(ComputeKey(slice, i)));
|
|
|
|
}
|
|
|
|
CrashReports::SetAnnotation(
|
|
|
|
"keys",
|
|
|
|
QString("%1:%2-(%3)-%4:"
|
|
|
|
).arg(DebugSerializeContext(context)
|
|
|
|
).arg(from
|
|
|
|
).arg(index
|
|
|
|
).arg(till) + strings.join(","));
|
2021-03-18 14:05:43 +00:00
|
|
|
if (Logs::DebugEnabled()) {
|
|
|
|
Unexpected("Bad slice in GroupThumbs.");
|
|
|
|
}
|
|
|
|
break;
|
2021-03-15 15:00:32 +00:00
|
|
|
} else {
|
|
|
|
keys.emplace(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-12 07:13:58 +00:00
|
|
|
#endif
|
2021-03-15 15:00:32 +00:00
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
template <typename Slice>
|
|
|
|
void GroupThumbs::fillItems(
|
|
|
|
const Slice &slice,
|
|
|
|
int from,
|
|
|
|
int index,
|
|
|
|
int till) {
|
|
|
|
Expects(from <= index);
|
|
|
|
Expects(index < till);
|
|
|
|
Expects(from + 1 < till);
|
|
|
|
|
|
|
|
const auto current = (index - from);
|
|
|
|
const auto old = base::take(_items);
|
|
|
|
|
2021-03-19 10:11:28 +00:00
|
|
|
//ValidateSlice(slice, _context, from, index, till);
|
2021-03-15 15:00:32 +00:00
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
markCacheStale();
|
|
|
|
_items.reserve(till - from);
|
|
|
|
for (auto i = from; i != till; ++i) {
|
|
|
|
_items.push_back(validateCacheEntry(ComputeKey(slice, i)));
|
|
|
|
}
|
|
|
|
animateAliveItems(current);
|
|
|
|
fillDyingItems(old);
|
|
|
|
startDelayedAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::animateAliveItems(int current) {
|
|
|
|
Expects(current >= 0 && current < _items.size());
|
|
|
|
|
|
|
|
_items[current]->setState(Thumb::State::Current);
|
|
|
|
for (auto i = current; i != 0;) {
|
|
|
|
const auto prev = _items[i];
|
|
|
|
const auto item = _items[--i];
|
|
|
|
item->animateToLeft(prev);
|
|
|
|
}
|
|
|
|
for (auto i = current + 1; i != _items.size(); ++i) {
|
|
|
|
const auto prev = _items[i - 1];
|
|
|
|
const auto item = _items[i];
|
|
|
|
item->animateToRight(prev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::fillDyingItems(const std::vector<not_null<Thumb*>> &old) {
|
2021-03-19 10:11:28 +00:00
|
|
|
//Expects(_cache.size() >= _items.size());
|
2021-03-15 15:00:32 +00:00
|
|
|
|
2021-03-19 10:11:28 +00:00
|
|
|
if (_cache.size() >= _items.size()) {
|
|
|
|
_dying.reserve(_cache.size() - _items.size());
|
|
|
|
}
|
2017-12-28 14:58:34 +00:00
|
|
|
animatePreviouslyAlive(old);
|
|
|
|
markRestAsDying();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::markRestAsDying() {
|
2021-03-19 10:11:28 +00:00
|
|
|
//Expects(_cache.size() >= _items.size());
|
2021-03-15 15:00:32 +00:00
|
|
|
|
2021-03-19 10:11:28 +00:00
|
|
|
if (_cache.size() >= _items.size()) {
|
|
|
|
_dying.reserve(_cache.size() - _items.size());
|
|
|
|
}
|
2017-12-29 18:47:49 +00:00
|
|
|
for (const auto &cacheItem : _cache) {
|
|
|
|
const auto &thumb = cacheItem.second;
|
2017-12-28 14:58:34 +00:00
|
|
|
const auto state = thumb->state();
|
|
|
|
if (state == Thumb::State::Unknown) {
|
|
|
|
markAsDying(thumb.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::markAsDying(not_null<Thumb*> thumb) {
|
|
|
|
thumb->setState(Thumb::State::Dying);
|
|
|
|
_dying.push_back(thumb.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::animatePreviouslyAlive(
|
|
|
|
const std::vector<not_null<Thumb*>> &old) {
|
|
|
|
auto toRight = false;
|
|
|
|
for (auto i = 0; i != old.size(); ++i) {
|
|
|
|
const auto item = old[i];
|
|
|
|
if (item->state() == Thumb::State::Unknown) {
|
|
|
|
if (toRight) {
|
|
|
|
markAsDying(item);
|
|
|
|
item->animateToRight(old[i - 1]);
|
|
|
|
}
|
|
|
|
} else if (!toRight) {
|
|
|
|
for (auto j = i; j != 0;) {
|
|
|
|
const auto next = old[j];
|
|
|
|
const auto prev = old[--j];
|
|
|
|
markAsDying(prev);
|
|
|
|
prev->animateToLeft(next);
|
|
|
|
}
|
|
|
|
toRight = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
auto GroupThumbs::createThumb(Key key)
|
|
|
|
-> std::unique_ptr<Thumb> {
|
2020-08-31 08:14:53 +00:00
|
|
|
if (const auto photoId = std::get_if<PhotoId>(&key)) {
|
2020-06-08 15:17:33 +00:00
|
|
|
const auto photo = _session->data().photo(*photoId);
|
2020-05-25 14:16:04 +00:00
|
|
|
return createThumb(key, photo);
|
2020-08-31 08:14:53 +00:00
|
|
|
} else if (const auto msgId = std::get_if<FullMsgId>(&key)) {
|
2020-06-08 15:17:33 +00:00
|
|
|
if (const auto item = _session->data().message(*msgId)) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto media = item->media()) {
|
|
|
|
if (const auto photo = media->photo()) {
|
2020-05-25 14:16:04 +00:00
|
|
|
return createThumb(key, photo);
|
2018-01-14 16:02:25 +00:00
|
|
|
} else if (const auto document = media->document()) {
|
2020-04-15 14:06:34 +00:00
|
|
|
return createThumb(key, document);
|
2017-12-28 14:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-25 14:37:28 +00:00
|
|
|
return createThumb(key, nullptr);
|
2020-08-31 08:14:53 +00:00
|
|
|
} else if (const auto collageKey = std::get_if<CollageKey>(&key)) {
|
2020-08-31 09:04:17 +00:00
|
|
|
if (const auto itemId = std::get_if<FullMsgId>(&_context)) {
|
2020-06-08 15:17:33 +00:00
|
|
|
if (const auto item = _session->data().message(*itemId)) {
|
2018-10-24 13:09:31 +00:00
|
|
|
if (const auto media = item->media()) {
|
|
|
|
if (const auto page = media->webpage()) {
|
|
|
|
return createThumb(
|
|
|
|
key,
|
|
|
|
page->collage,
|
|
|
|
collageKey->index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-25 14:37:28 +00:00
|
|
|
return createThumb(key, nullptr);
|
2017-12-28 14:58:34 +00:00
|
|
|
}
|
|
|
|
Unexpected("Value of Key in GroupThumbs::createThumb()");
|
|
|
|
}
|
|
|
|
|
2018-10-24 13:09:31 +00:00
|
|
|
auto GroupThumbs::createThumb(
|
|
|
|
Key key,
|
|
|
|
const WebPageCollage &collage,
|
|
|
|
int index)
|
|
|
|
-> std::unique_ptr<Thumb> {
|
|
|
|
if (index < 0 || index >= collage.items.size()) {
|
2019-01-25 14:37:28 +00:00
|
|
|
return createThumb(key, nullptr);
|
2018-10-24 13:09:31 +00:00
|
|
|
}
|
|
|
|
const auto &item = collage.items[index];
|
2020-08-31 08:14:53 +00:00
|
|
|
if (const auto photo = std::get_if<PhotoData*>(&item)) {
|
2020-05-25 14:16:04 +00:00
|
|
|
return createThumb(key, (*photo));
|
2020-08-31 08:14:53 +00:00
|
|
|
} else if (const auto document = std::get_if<DocumentData*>(&item)) {
|
2020-04-15 14:06:34 +00:00
|
|
|
return createThumb(key, (*document));
|
2018-10-24 13:09:31 +00:00
|
|
|
}
|
2019-01-25 14:37:28 +00:00
|
|
|
return createThumb(key, nullptr);
|
2018-10-24 13:09:31 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
auto GroupThumbs::createThumb(Key key, std::nullptr_t)
|
|
|
|
-> std::unique_ptr<Thumb> {
|
|
|
|
const auto weak = base::make_weak(this);
|
|
|
|
const auto origin = ComputeFileOrigin(key, _context);
|
|
|
|
return std::make_unique<Thumb>(key, [=] {
|
|
|
|
if (const auto strong = weak.get()) {
|
|
|
|
strong->_activateStream.fire_copy(key);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
auto GroupThumbs::createThumb(Key key, not_null<PhotoData*> photo)
|
2017-12-28 14:58:34 +00:00
|
|
|
-> std::unique_ptr<Thumb> {
|
2017-12-29 14:58:53 +00:00
|
|
|
const auto weak = base::make_weak(this);
|
2018-07-13 21:25:47 +00:00
|
|
|
const auto origin = ComputeFileOrigin(key, _context);
|
2020-05-25 14:16:04 +00:00
|
|
|
return std::make_unique<Thumb>(key, photo, origin, [=] {
|
2017-12-29 14:58:53 +00:00
|
|
|
if (const auto strong = weak.get()) {
|
|
|
|
strong->_activateStream.fire_copy(key);
|
|
|
|
}
|
|
|
|
});
|
2017-12-28 14:58:34 +00:00
|
|
|
}
|
|
|
|
|
2020-04-15 14:06:34 +00:00
|
|
|
auto GroupThumbs::createThumb(Key key, not_null<DocumentData*> document)
|
|
|
|
-> std::unique_ptr<Thumb> {
|
|
|
|
const auto weak = base::make_weak(this);
|
|
|
|
const auto origin = ComputeFileOrigin(key, _context);
|
|
|
|
return std::make_unique<Thumb>(key, document, origin, [=] {
|
|
|
|
if (const auto strong = weak.get()) {
|
|
|
|
strong->_activateStream.fire_copy(key);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
auto GroupThumbs::validateCacheEntry(Key key) -> not_null<Thumb*> {
|
|
|
|
const auto i = _cache.find(key);
|
|
|
|
return (i != _cache.end())
|
|
|
|
? i->second.get()
|
|
|
|
: _cache.emplace(key, createThumb(key)).first->second.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::markCacheStale() {
|
2018-01-09 17:08:31 +00:00
|
|
|
_dying.clear();
|
2017-12-29 18:47:49 +00:00
|
|
|
for (const auto &cacheItem : _cache) {
|
|
|
|
const auto &thumb = cacheItem.second;
|
2017-12-28 14:58:34 +00:00
|
|
|
thumb->setState(Thumb::State::Unknown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::Refresh(
|
2020-06-08 15:17:33 +00:00
|
|
|
not_null<Main::Session*> session,
|
2017-12-28 14:58:34 +00:00
|
|
|
std::unique_ptr<GroupThumbs> &instance,
|
|
|
|
const SharedMediaWithLastSlice &slice,
|
|
|
|
int index,
|
|
|
|
int availableWidth) {
|
2020-06-08 15:17:33 +00:00
|
|
|
RefreshFromSlice(session, instance, slice, index, availableWidth);
|
2017-12-28 14:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::Refresh(
|
2020-06-08 15:17:33 +00:00
|
|
|
not_null<Main::Session*> session,
|
2017-12-28 14:58:34 +00:00
|
|
|
std::unique_ptr<GroupThumbs> &instance,
|
|
|
|
const UserPhotosSlice &slice,
|
|
|
|
int index,
|
|
|
|
int availableWidth) {
|
2020-06-08 15:17:33 +00:00
|
|
|
RefreshFromSlice(session, instance, slice, index, availableWidth);
|
2017-12-28 14:58:34 +00:00
|
|
|
}
|
|
|
|
|
2018-10-24 13:09:31 +00:00
|
|
|
void GroupThumbs::Refresh(
|
2020-06-08 15:17:33 +00:00
|
|
|
not_null<Main::Session*> session,
|
2018-10-24 13:09:31 +00:00
|
|
|
std::unique_ptr<GroupThumbs> &instance,
|
|
|
|
const CollageSlice &slice,
|
|
|
|
int index,
|
|
|
|
int availableWidth) {
|
2020-06-08 15:17:33 +00:00
|
|
|
RefreshFromSlice(session, instance, slice, index, availableWidth);
|
2018-10-24 13:09:31 +00:00
|
|
|
}
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
void GroupThumbs::clear() {
|
|
|
|
if (_items.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
base::take(_items);
|
|
|
|
markCacheStale();
|
|
|
|
markRestAsDying();
|
|
|
|
startDelayedAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::startDelayedAnimation() {
|
2019-04-02 09:13:30 +00:00
|
|
|
_animation.stop();
|
2017-12-28 14:58:34 +00:00
|
|
|
_waitingForAnimationStart = true;
|
|
|
|
countUpdatedRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupThumbs::resizeToWidth(int newWidth) {
|
|
|
|
_width = newWidth;
|
2017-12-28 13:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GroupThumbs::height() const {
|
2017-12-28 14:58:34 +00:00
|
|
|
return st::mediaviewGroupPadding.top()
|
|
|
|
+ st::mediaviewGroupHeight
|
|
|
|
+ st::mediaviewGroupPadding.bottom();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GroupThumbs::hiding() const {
|
|
|
|
return _items.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GroupThumbs::hidden() const {
|
|
|
|
return hiding() && !_waitingForAnimationStart && !_animation.animating();
|
2017-12-28 13:06:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
void GroupThumbs::checkForAnimationStart() {
|
|
|
|
if (_waitingForAnimationStart) {
|
|
|
|
_waitingForAnimationStart = false;
|
2019-02-27 11:36:19 +00:00
|
|
|
_animation.start([=] { update(); }, 0., 1., kThumbDuration);
|
2017-12-28 14:58:34 +00:00
|
|
|
}
|
2017-12-28 13:06:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
void GroupThumbs::update() {
|
|
|
|
if (_cache.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_updateRequests.fire_copy(_updatedRect);
|
|
|
|
}
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
void GroupThumbs::paint(Painter &p, int x, int y, int outerWidth) {
|
2017-12-28 14:58:34 +00:00
|
|
|
const auto progress = _waitingForAnimationStart
|
|
|
|
? 0.
|
2019-04-02 09:13:30 +00:00
|
|
|
: _animation.value(1.);
|
2017-12-28 14:58:34 +00:00
|
|
|
x += (_width / 2);
|
|
|
|
y += st::mediaviewGroupPadding.top();
|
|
|
|
for (auto i = _cache.begin(); i != _cache.end();) {
|
|
|
|
const auto &thumb = i->second;
|
|
|
|
thumb->paint(p, x, y, outerWidth, progress);
|
|
|
|
if (thumb->removed()) {
|
|
|
|
_dying.erase(
|
|
|
|
ranges::remove(
|
|
|
|
_dying,
|
|
|
|
thumb.get(),
|
|
|
|
[](not_null<Thumb*> thumb) { return thumb.get(); }),
|
|
|
|
_dying.end());
|
|
|
|
i = _cache.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-29 14:58:53 +00:00
|
|
|
ClickHandlerPtr GroupThumbs::getState(QPoint point) const {
|
|
|
|
point -= QPoint((_width / 2), st::mediaviewGroupPadding.top());
|
2017-12-29 18:47:49 +00:00
|
|
|
for (const auto &cacheItem : _cache) {
|
|
|
|
const auto &thumb = cacheItem.second;
|
2017-12-29 14:58:53 +00:00
|
|
|
if (auto link = thumb->getState(point)) {
|
|
|
|
return link;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
void GroupThumbs::countUpdatedRect() {
|
|
|
|
if (_cache.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto min = _width;
|
|
|
|
auto max = 0;
|
|
|
|
const auto left = [](const auto &cacheItem) {
|
|
|
|
const auto &[key, thumb] = cacheItem;
|
|
|
|
return thumb->leftToUpdate();
|
|
|
|
};
|
|
|
|
const auto right = [](const auto &cacheItem) {
|
|
|
|
const auto &[key, thumb] = cacheItem;
|
|
|
|
return thumb->rightToUpdate();
|
|
|
|
};
|
|
|
|
accumulate_min(min, left(*ranges::max_element(
|
|
|
|
_cache,
|
|
|
|
std::greater<>(),
|
|
|
|
left)));
|
|
|
|
accumulate_max(max, right(*ranges::max_element(
|
|
|
|
_cache,
|
|
|
|
std::less<>(),
|
|
|
|
right)));
|
|
|
|
_updatedRect = QRect(
|
|
|
|
min,
|
|
|
|
st::mediaviewGroupPadding.top(),
|
|
|
|
max - min,
|
|
|
|
st::mediaviewGroupHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupThumbs::~GroupThumbs() = default;
|
|
|
|
|
2017-12-28 13:06:06 +00:00
|
|
|
} // namespace View
|
|
|
|
} // namespace Media
|