2017-03-29 17:04:00 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-03-29 17:04:00 +03:00
|
|
|
*/
|
2017-04-06 17:38:10 +03:00
|
|
|
#include "chat_helpers/stickers_list_widget.h"
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-09-26 14:49:16 +03:00
|
|
|
#include "data/data_document.h"
|
2018-01-04 13:22:53 +03:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 15:09:48 +04:00
|
|
|
#include "data/data_channel.h"
|
2017-03-29 17:04:00 +03:00
|
|
|
#include "ui/widgets/buttons.h"
|
2019-04-01 21:44:54 +04:00
|
|
|
#include "ui/effects/animations.h"
|
2017-03-29 17:04:00 +03:00
|
|
|
#include "ui/effects/ripple_animation.h"
|
2018-10-23 13:44:42 +04:00
|
|
|
#include "ui/image/image.h"
|
2019-06-28 16:26:03 +02:00
|
|
|
#include "lottie/lottie_multi_player.h"
|
2019-07-02 13:46:37 +02:00
|
|
|
#include "lottie/lottie_single_player.h"
|
2019-06-28 16:26:03 +02:00
|
|
|
#include "lottie/lottie_animation.h"
|
2017-03-29 17:04:00 +03:00
|
|
|
#include "boxes/stickers_box.h"
|
|
|
|
#include "inline_bots/inline_bot_result.h"
|
2017-04-06 17:38:10 +03:00
|
|
|
#include "chat_helpers/stickers.h"
|
2017-03-29 17:04:00 +03:00
|
|
|
#include "storage/localstorage.h"
|
2017-04-13 11:27:10 +03:00
|
|
|
#include "lang/lang_keys.h"
|
2017-03-29 17:04:00 +03:00
|
|
|
#include "mainwindow.h"
|
2017-03-29 18:09:16 +03:00
|
|
|
#include "dialogs/dialogs_layout.h"
|
2017-04-06 17:38:10 +03:00
|
|
|
#include "boxes/sticker_set_box.h"
|
2017-03-29 18:09:16 +03:00
|
|
|
#include "boxes/stickers_box.h"
|
2017-04-06 17:38:10 +03:00
|
|
|
#include "boxes/confirm_box.h"
|
2019-06-25 14:25:02 +02:00
|
|
|
#include "window/window_session_controller.h" // GifPauseReason.
|
2019-07-24 13:45:24 +02:00
|
|
|
#include "main/main_session.h"
|
2017-08-03 14:52:56 +02:00
|
|
|
#include "observer_peer.h"
|
|
|
|
#include "apiwrap.h"
|
2019-09-13 09:06:02 +03:00
|
|
|
#include "app.h"
|
2017-11-12 13:54:18 +04:00
|
|
|
#include "styles/style_chat_helpers.h"
|
|
|
|
#include "styles/style_window.h"
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2019-09-04 10:19:15 +03:00
|
|
|
#include <QtWidgets/QApplication>
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
namespace ChatHelpers {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kInlineItemsMaxPerRow = 5;
|
2018-03-02 20:17:33 +03:00
|
|
|
constexpr auto kSearchRequestDelay = 400;
|
2018-03-07 15:04:05 +03:00
|
|
|
constexpr auto kRecentDisplayLimit = 20;
|
2018-03-02 20:17:33 +03:00
|
|
|
|
|
|
|
bool SetInMyList(MTPDstickerSet::Flags flags) {
|
|
|
|
return (flags & MTPDstickerSet::Flag::f_installed_date)
|
|
|
|
&& !(flags & MTPDstickerSet::Flag::f_archived);
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
struct StickerIcon {
|
|
|
|
StickerIcon(uint64 setId) : setId(setId) {
|
|
|
|
}
|
2019-03-22 13:24:56 +04:00
|
|
|
StickerIcon(
|
|
|
|
uint64 setId,
|
|
|
|
ImagePtr thumbnail,
|
|
|
|
DocumentData *sticker,
|
|
|
|
int pixw,
|
|
|
|
int pixh)
|
2018-03-02 20:17:33 +03:00
|
|
|
: setId(setId)
|
2019-03-22 13:24:56 +04:00
|
|
|
, thumbnail(thumbnail)
|
2018-03-02 20:17:33 +03:00
|
|
|
, sticker(sticker)
|
|
|
|
, pixw(pixw)
|
|
|
|
, pixh(pixh) {
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
uint64 setId = 0;
|
2019-03-22 13:24:56 +04:00
|
|
|
ImagePtr thumbnail;
|
2019-07-02 13:46:37 +02:00
|
|
|
mutable Lottie::SinglePlayer *lottie = nullptr;
|
2017-03-29 18:09:16 +03:00
|
|
|
DocumentData *sticker = nullptr;
|
2017-08-03 14:52:56 +02:00
|
|
|
ChannelData *megagroup = nullptr;
|
2017-03-29 18:09:16 +03:00
|
|
|
int pixw = 0;
|
|
|
|
int pixh = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-07-02 13:46:37 +02:00
|
|
|
class StickersListWidget::Footer
|
|
|
|
: public TabbedSelector::InnerFooter
|
|
|
|
, private base::Subscriber {
|
2017-03-29 17:04:00 +03:00
|
|
|
public:
|
2019-07-02 13:46:37 +02:00
|
|
|
explicit Footer(not_null<StickersListWidget*> parent);
|
2017-03-29 18:09:16 +03:00
|
|
|
|
|
|
|
void preloadImages();
|
2018-03-26 00:34:13 +04:00
|
|
|
void validateSelectedIcon(
|
|
|
|
uint64 setId,
|
|
|
|
ValidateIconAnimations animations);
|
2017-03-29 18:09:16 +03:00
|
|
|
void refreshIcons(ValidateIconAnimations animations);
|
2017-04-11 17:02:11 +03:00
|
|
|
bool hasOnlyFeaturedSets() const;
|
2017-03-29 18:09:16 +03:00
|
|
|
|
|
|
|
void leaveToChildEvent(QEvent *e, QWidget *child) override;
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void stealFocus();
|
|
|
|
void returnFocus();
|
|
|
|
void setLoading(bool loading);
|
|
|
|
|
2019-07-02 13:46:37 +02:00
|
|
|
void clearLottieData();
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2018-03-02 20:17:33 +03:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2017-03-29 18:09:16 +03:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
bool event(QEvent *e) override;
|
|
|
|
|
|
|
|
void processHideFinished() override;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
private:
|
2018-03-02 20:17:33 +03:00
|
|
|
enum class SpecialOver {
|
|
|
|
None,
|
|
|
|
Search,
|
|
|
|
Settings,
|
|
|
|
};
|
|
|
|
using OverState = base::variant<SpecialOver, int>;
|
|
|
|
|
2019-07-02 13:46:37 +02:00
|
|
|
struct LottieIcon {
|
|
|
|
std::unique_ptr<Lottie::SinglePlayer> player;
|
|
|
|
bool stale = false;
|
|
|
|
rpl::lifetime lifetime;
|
|
|
|
};
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
template <typename Callback>
|
|
|
|
void enumerateVisibleIcons(Callback callback);
|
|
|
|
|
2019-04-01 21:44:54 +04:00
|
|
|
bool iconsAnimationCallback(crl::time now);
|
2018-03-02 20:17:33 +03:00
|
|
|
void setSelectedIcon(
|
|
|
|
int newSelected,
|
|
|
|
ValidateIconAnimations animations);
|
2019-07-02 13:46:37 +02:00
|
|
|
void validateIconLottieAnimation(const StickerIcon &icon);
|
2017-03-29 18:09:16 +03:00
|
|
|
|
2018-03-26 00:34:13 +04:00
|
|
|
void refreshIconsGeometry(ValidateIconAnimations animations);
|
2019-07-02 13:46:37 +02:00
|
|
|
void refillLottieData();
|
2017-03-29 18:09:16 +03:00
|
|
|
void updateSelected();
|
2019-07-02 13:46:37 +02:00
|
|
|
void updateSetIcon(uint64 setId);
|
2018-03-02 20:17:33 +03:00
|
|
|
void finishDragging();
|
2017-03-29 18:09:16 +03:00
|
|
|
void paintStickerSettingsIcon(Painter &p) const;
|
2018-03-02 20:17:33 +03:00
|
|
|
void paintSearchIcon(Painter &p) const;
|
2017-03-29 18:09:16 +03:00
|
|
|
void paintFeaturedStickerSetsBadge(Painter &p, int iconLeft) const;
|
2018-03-02 20:17:33 +03:00
|
|
|
void paintSetIcon(Painter &p, const StickerIcon &icon, int x) const;
|
|
|
|
void paintSelectionBar(Painter &p) const;
|
|
|
|
void paintLeftRightFading(Painter &p) const;
|
|
|
|
|
|
|
|
void initSearch();
|
|
|
|
void toggleSearch(bool visible);
|
|
|
|
void resizeSearchControls();
|
|
|
|
void scrollByWheelEvent(not_null<QWheelEvent*> e);
|
2017-03-29 18:09:16 +03:00
|
|
|
|
2019-08-06 17:40:08 +01:00
|
|
|
const not_null<StickersListWidget*> _pan;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
static constexpr auto kVisibleIconsCount = 8;
|
|
|
|
|
|
|
|
QList<StickerIcon> _icons;
|
2019-07-02 13:46:37 +02:00
|
|
|
mutable base::flat_map<uint64, LottieIcon> _lottieData;
|
2018-03-02 20:17:33 +03:00
|
|
|
OverState _iconOver = SpecialOver::None;
|
2017-03-29 18:09:16 +03:00
|
|
|
int _iconSel = 0;
|
2018-03-02 20:17:33 +03:00
|
|
|
OverState _iconDown = SpecialOver::None;
|
2017-03-29 18:09:16 +03:00
|
|
|
bool _iconsDragging = false;
|
2019-04-01 21:44:54 +04:00
|
|
|
Ui::Animations::Basic _iconsAnimation;
|
2017-03-29 18:09:16 +03:00
|
|
|
QPoint _iconsMousePos, _iconsMouseDown;
|
|
|
|
int _iconsLeft = 0;
|
2017-11-12 13:54:18 +04:00
|
|
|
int _iconsRight = 0;
|
2017-03-29 18:09:16 +03:00
|
|
|
int _iconsTop = 0;
|
|
|
|
int _iconsStartX = 0;
|
|
|
|
int _iconsMax = 0;
|
|
|
|
anim::value _iconsX;
|
|
|
|
anim::value _iconSelX;
|
2019-02-19 10:57:53 +04:00
|
|
|
crl::time _iconsStartAnim = 0;
|
2017-03-29 18:09:16 +03:00
|
|
|
|
|
|
|
bool _horizontal = false;
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
bool _searchShown = false;
|
|
|
|
object_ptr<Ui::InputField> _searchField = { nullptr };
|
|
|
|
object_ptr<Ui::CrossButton> _searchCancel = { nullptr };
|
|
|
|
QPointer<QWidget> _focusTakenFrom;
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
};
|
|
|
|
|
2019-06-25 14:25:02 +02:00
|
|
|
auto StickersListWidget::PrepareStickers(const Stickers::Pack &pack)
|
|
|
|
-> std::vector<Sticker> {
|
|
|
|
return ranges::view::all(
|
|
|
|
pack
|
|
|
|
) | ranges::view::transform([](DocumentData *document) {
|
|
|
|
return Sticker{ document };
|
|
|
|
}) | ranges::to_vector;
|
|
|
|
}
|
|
|
|
|
2017-12-18 14:38:14 +04:00
|
|
|
StickersListWidget::Set::Set(
|
|
|
|
uint64 id,
|
|
|
|
MTPDstickerSet::Flags flags,
|
|
|
|
const QString &title,
|
2018-03-08 14:37:01 +03:00
|
|
|
const QString &shortName,
|
2019-03-22 13:24:56 +04:00
|
|
|
ImagePtr thumbnail,
|
2018-03-02 20:17:33 +03:00
|
|
|
bool externalLayout,
|
2018-03-08 14:12:30 +03:00
|
|
|
int count,
|
2019-06-25 14:25:02 +02:00
|
|
|
std::vector<Sticker> &&stickers)
|
2017-12-18 14:38:14 +04:00
|
|
|
: id(id)
|
|
|
|
, flags(flags)
|
|
|
|
, title(title)
|
2018-03-08 14:37:01 +03:00
|
|
|
, shortName(shortName)
|
2019-03-22 13:24:56 +04:00
|
|
|
, thumbnail(thumbnail)
|
2019-06-25 14:25:02 +02:00
|
|
|
, stickers(std::move(stickers))
|
2018-03-08 14:12:30 +03:00
|
|
|
, externalLayout(externalLayout)
|
|
|
|
, count(count) {
|
2017-12-18 14:38:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
StickersListWidget::Set::Set(Set &&other) = default;
|
|
|
|
StickersListWidget::Set &StickersListWidget::Set::operator=(
|
|
|
|
Set &&other) = default;
|
|
|
|
StickersListWidget::Set::~Set() = default;
|
|
|
|
|
2019-07-02 13:46:37 +02:00
|
|
|
StickersListWidget::Footer::Footer(not_null<StickersListWidget*> parent)
|
|
|
|
: InnerFooter(parent)
|
2017-03-29 18:09:16 +03:00
|
|
|
, _pan(parent)
|
2019-04-01 21:44:54 +04:00
|
|
|
, _iconsAnimation([=](crl::time now) {
|
|
|
|
return iconsAnimationCallback(now);
|
|
|
|
}) {
|
2017-03-29 18:09:16 +03:00
|
|
|
setMouseTracking(true);
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
_iconsLeft = _iconsRight = st::emojiCategorySkip + st::stickerIconWidth;
|
2017-04-09 21:06:06 +03:00
|
|
|
|
2019-07-24 13:13:51 +02:00
|
|
|
subscribe(_pan->session().downloaderTaskFinished(), [=] {
|
2017-04-09 21:06:06 +03:00
|
|
|
update();
|
|
|
|
});
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
|
2019-07-02 13:46:37 +02:00
|
|
|
void StickersListWidget::Footer::clearLottieData() {
|
|
|
|
for (auto &icon : _icons) {
|
|
|
|
icon.lottie = nullptr;
|
|
|
|
}
|
|
|
|
_lottieData.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::refillLottieData() {
|
|
|
|
for (auto &item : _lottieData) {
|
|
|
|
item.second.stale = true;
|
|
|
|
}
|
|
|
|
for (auto &icon : _icons) {
|
|
|
|
const auto i = _lottieData.find(icon.setId);
|
|
|
|
if (i == end(_lottieData)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
icon.lottie = i->second.player.get();
|
|
|
|
i->second.stale = false;
|
|
|
|
}
|
|
|
|
for (auto i = begin(_lottieData); i != end(_lottieData);) {
|
|
|
|
if (i->second.stale) {
|
|
|
|
i = _lottieData.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::Footer::initSearch() {
|
|
|
|
_searchField.create(
|
|
|
|
this,
|
|
|
|
st::gifsSearchField,
|
2019-06-18 16:07:45 +02:00
|
|
|
tr::lng_stickers_search_sets());
|
2018-03-02 20:17:33 +03:00
|
|
|
_searchCancel.create(this, st::gifsSearchCancel);
|
|
|
|
_searchField->show();
|
|
|
|
_searchCancel->show(anim::type::instant);
|
|
|
|
|
|
|
|
const auto cancelSearch = [=] {
|
|
|
|
if (_searchField->getLastText().isEmpty()) {
|
|
|
|
toggleSearch(false);
|
|
|
|
} else {
|
|
|
|
_searchField->setText(QString());
|
|
|
|
}
|
|
|
|
};
|
2018-05-31 15:20:28 +03:00
|
|
|
connect(_searchField, &Ui::InputField::submitted, [=] {
|
2018-03-02 20:17:33 +03:00
|
|
|
_pan->sendSearchRequest();
|
|
|
|
});
|
2018-05-31 15:20:28 +03:00
|
|
|
connect(_searchField, &Ui::InputField::cancelled, cancelSearch);
|
|
|
|
connect(_searchField, &Ui::InputField::changed, [=] {
|
2018-03-02 20:17:33 +03:00
|
|
|
_pan->searchForSets(_searchField->getLastText());
|
|
|
|
});
|
|
|
|
_searchCancel->setClickedCallback(cancelSearch);
|
|
|
|
|
|
|
|
resizeSearchControls();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::toggleSearch(bool visible) {
|
|
|
|
if (_searchShown == visible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_searchShown = visible;
|
|
|
|
if (_searchShown) {
|
|
|
|
initSearch();
|
|
|
|
stealFocus();
|
|
|
|
} else if (_searchField) {
|
|
|
|
returnFocus();
|
|
|
|
_searchField.destroy();
|
|
|
|
_searchCancel.destroy();
|
|
|
|
_focusTakenFrom = nullptr;
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::stealFocus() {
|
|
|
|
if (_searchField) {
|
|
|
|
if (!_focusTakenFrom) {
|
|
|
|
_focusTakenFrom = QApplication::focusWidget();
|
|
|
|
}
|
|
|
|
_searchField->setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::returnFocus() {
|
|
|
|
if (_searchField && _focusTakenFrom) {
|
|
|
|
if (_searchField->hasFocus()) {
|
|
|
|
_focusTakenFrom->setFocus();
|
|
|
|
}
|
|
|
|
_focusTakenFrom = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
template <typename Callback>
|
|
|
|
void StickersListWidget::Footer::enumerateVisibleIcons(Callback callback) {
|
|
|
|
auto iconsX = qRound(_iconsX.current());
|
2017-11-12 13:54:18 +04:00
|
|
|
auto index = iconsX / st::stickerIconWidth;
|
|
|
|
auto x = _iconsLeft - (iconsX % st::stickerIconWidth);
|
|
|
|
auto first = floorclamp(iconsX, st::stickerIconWidth, 0, _icons.size());
|
|
|
|
auto last = ceilclamp(iconsX + width(), st::stickerIconWidth, 0, _icons.size());
|
|
|
|
for (auto index = first; index != last; ++index) {
|
2017-03-29 18:09:16 +03:00
|
|
|
callback(_icons[index], x);
|
2017-11-12 13:54:18 +04:00
|
|
|
x += st::stickerIconWidth;
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::preloadImages() {
|
2019-07-02 13:46:37 +02:00
|
|
|
enumerateVisibleIcons([](const StickerIcon &icon, int x) {
|
2019-01-25 18:37:28 +04:00
|
|
|
if (const auto sticker = icon.sticker) {
|
2019-03-22 13:24:56 +04:00
|
|
|
const auto origin = sticker->stickerSetOrigin();
|
|
|
|
if (icon.thumbnail) {
|
|
|
|
icon.thumbnail->load(origin);
|
|
|
|
} else {
|
|
|
|
sticker->loadThumbnail(origin);
|
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
void StickersListWidget::Footer::validateSelectedIcon(
|
|
|
|
uint64 setId,
|
|
|
|
ValidateIconAnimations animations) {
|
2018-04-15 10:47:15 +04:00
|
|
|
auto favedIconIndex = -1;
|
|
|
|
auto newSelected = -1;
|
2017-03-29 18:09:16 +03:00
|
|
|
for (auto i = 0, l = _icons.size(); i != l; ++i) {
|
2018-06-03 20:58:28 +03:00
|
|
|
if (_icons[i].setId == setId
|
|
|
|
|| (_icons[i].setId == Stickers::FavedSetId
|
|
|
|
&& setId == Stickers::RecentSetId)) {
|
2018-03-02 20:17:33 +03:00
|
|
|
newSelected = i;
|
2017-03-29 18:09:16 +03:00
|
|
|
break;
|
2018-04-15 10:47:15 +04:00
|
|
|
} else if (_icons[i].setId == Stickers::FavedSetId) {
|
|
|
|
favedIconIndex = i;
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
}
|
2018-04-15 10:47:15 +04:00
|
|
|
setSelectedIcon(
|
|
|
|
(newSelected >= 0
|
|
|
|
? newSelected
|
|
|
|
: (favedIconIndex >= 0) ? favedIconIndex : 0),
|
|
|
|
animations);
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::setSelectedIcon(
|
|
|
|
int newSelected,
|
|
|
|
ValidateIconAnimations animations) {
|
|
|
|
if (_iconSel == newSelected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_iconSel = newSelected;
|
|
|
|
auto iconSelXFinal = _iconSel * st::stickerIconWidth;
|
|
|
|
if (animations == ValidateIconAnimations::Full) {
|
|
|
|
_iconSelX.start(iconSelXFinal);
|
|
|
|
} else {
|
|
|
|
_iconSelX = anim::value(iconSelXFinal, iconSelXFinal);
|
|
|
|
}
|
|
|
|
auto iconsCountForCentering = (2 * _iconSel + 1);
|
|
|
|
auto iconsWidthForCentering = iconsCountForCentering
|
|
|
|
* st::stickerIconWidth;
|
|
|
|
auto iconsXFinal = snap(
|
|
|
|
(_iconsLeft + iconsWidthForCentering + _iconsRight - width()) / 2,
|
|
|
|
0,
|
|
|
|
_iconsMax);
|
|
|
|
if (animations == ValidateIconAnimations::None) {
|
|
|
|
_iconsX = anim::value(iconsXFinal, iconsXFinal);
|
2019-04-01 21:44:54 +04:00
|
|
|
_iconsAnimation.stop();
|
2018-03-02 20:17:33 +03:00
|
|
|
} else {
|
|
|
|
_iconsX.start(iconsXFinal);
|
2019-02-19 10:57:53 +04:00
|
|
|
_iconsStartAnim = crl::now();
|
2019-04-01 21:44:54 +04:00
|
|
|
_iconsAnimation.start();
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
2018-03-02 20:17:33 +03:00
|
|
|
updateSelected();
|
|
|
|
update();
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::processHideFinished() {
|
2018-03-02 20:17:33 +03:00
|
|
|
_iconOver = _iconDown = SpecialOver::None;
|
2017-03-29 18:09:16 +03:00
|
|
|
_iconsStartAnim = 0;
|
2019-04-01 21:44:54 +04:00
|
|
|
_iconsAnimation.stop();
|
2017-03-29 18:09:16 +03:00
|
|
|
_iconsX.finish();
|
|
|
|
_iconSelX.finish();
|
|
|
|
_horizontal = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::leaveToChildEvent(QEvent *e, QWidget *child) {
|
|
|
|
_iconsMousePos = QCursor::pos();
|
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::Footer::setLoading(bool loading) {
|
|
|
|
if (_searchCancel) {
|
|
|
|
_searchCancel->setLoadingAnimation(loading);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
void StickersListWidget::Footer::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
paintSearchIcon(p);
|
|
|
|
|
|
|
|
if (_icons.isEmpty() || _searchShown) {
|
2017-03-29 18:09:16 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-11 17:02:11 +03:00
|
|
|
if (!hasOnlyFeaturedSets()) {
|
|
|
|
paintStickerSettingsIcon(p);
|
|
|
|
}
|
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
auto clip = QRect(
|
|
|
|
_iconsLeft,
|
|
|
|
_iconsTop,
|
2018-03-02 20:17:33 +03:00
|
|
|
width() - _iconsLeft - _iconsRight,
|
2017-11-12 13:54:18 +04:00
|
|
|
st::emojiFooterHeight);
|
2018-03-02 20:17:33 +03:00
|
|
|
if (rtl()) {
|
|
|
|
clip.moveLeft(width() - _iconsLeft - clip.width());
|
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
p.setClipRect(clip);
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
enumerateVisibleIcons([&](const StickerIcon &icon, int x) {
|
|
|
|
paintSetIcon(p, icon, x);
|
2017-03-29 18:09:16 +03:00
|
|
|
});
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
paintSelectionBar(p);
|
|
|
|
paintLeftRightFading(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::paintSelectionBar(Painter &p) const {
|
|
|
|
auto selxrel = _iconsLeft + qRound(_iconSelX.current());
|
|
|
|
auto selx = selxrel - qRound(_iconsX.current());
|
|
|
|
if (rtl()) {
|
|
|
|
selx = width() - selx - st::stickerIconWidth;
|
|
|
|
}
|
|
|
|
p.fillRect(
|
|
|
|
selx,
|
|
|
|
_iconsTop + st::emojiFooterHeight - st::stickerIconPadding,
|
|
|
|
st::stickerIconWidth,
|
|
|
|
st::stickerIconSel,
|
|
|
|
st::stickerIconSelColor);
|
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::Footer::paintLeftRightFading(Painter &p) const {
|
2017-03-29 18:09:16 +03:00
|
|
|
auto o_left = snap(_iconsX.current() / st::stickerIconLeft.width(), 0., 1.);
|
|
|
|
if (o_left > 0) {
|
|
|
|
p.setOpacity(o_left);
|
2019-09-13 15:22:54 +03:00
|
|
|
st::stickerIconLeft.fill(p, style::rtlrect(_iconsLeft, _iconsTop, st::stickerIconLeft.width(), st::emojiFooterHeight, width()));
|
2017-03-29 18:09:16 +03:00
|
|
|
p.setOpacity(1.);
|
|
|
|
}
|
|
|
|
auto o_right = snap((_iconsMax - _iconsX.current()) / st::stickerIconRight.width(), 0., 1.);
|
|
|
|
if (o_right > 0) {
|
|
|
|
p.setOpacity(o_right);
|
2019-09-13 15:22:54 +03:00
|
|
|
st::stickerIconRight.fill(p, style::rtlrect(width() - _iconsRight - st::stickerIconRight.width(), _iconsTop, st::stickerIconRight.width(), st::emojiFooterHeight, width()));
|
2017-03-29 18:09:16 +03:00
|
|
|
p.setOpacity(1.);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::Footer::resizeEvent(QResizeEvent *e) {
|
|
|
|
if (_searchField) {
|
|
|
|
resizeSearchControls();
|
|
|
|
}
|
2018-03-26 00:34:13 +04:00
|
|
|
refreshIconsGeometry(ValidateIconAnimations::None);
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::resizeSearchControls() {
|
|
|
|
Expects(_searchField != nullptr);
|
|
|
|
Expects(_searchCancel != nullptr);
|
|
|
|
|
|
|
|
const auto fieldWidth = width()
|
|
|
|
- st::gifsSearchFieldPosition.x()
|
|
|
|
- st::gifsSearchCancelPosition.x()
|
|
|
|
- st::gifsSearchCancel.width;
|
|
|
|
_searchField->resizeToWidth(fieldWidth);
|
|
|
|
_searchField->moveToLeft(st::gifsSearchFieldPosition.x(), st::gifsSearchFieldPosition.y());
|
|
|
|
_searchCancel->moveToRight(st::gifsSearchCancelPosition.x(), st::gifsSearchCancelPosition.y());
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
void StickersListWidget::Footer::mousePressEvent(QMouseEvent *e) {
|
|
|
|
if (e->button() != Qt::LeftButton) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_iconsMousePos = e ? e->globalPos() : QCursor::pos();
|
|
|
|
updateSelected();
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
if (_iconOver == SpecialOver::Settings) {
|
2019-08-06 17:40:08 +01:00
|
|
|
Ui::show(Box<StickersBox>(
|
|
|
|
&_pan->controller()->session(),
|
|
|
|
(hasOnlyFeaturedSets()
|
|
|
|
? StickersBox::Section::Featured
|
|
|
|
: StickersBox::Section::Installed)));
|
2018-03-02 20:17:33 +03:00
|
|
|
} else if (_iconOver == SpecialOver::Search) {
|
|
|
|
toggleSearch(true);
|
2017-03-29 18:09:16 +03:00
|
|
|
} else {
|
|
|
|
_iconDown = _iconOver;
|
|
|
|
_iconsMouseDown = _iconsMousePos;
|
|
|
|
_iconsStartX = qRound(_iconsX.current());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
_iconsMousePos = e ? e->globalPos() : QCursor::pos();
|
|
|
|
updateSelected();
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
if (!_iconsDragging
|
|
|
|
&& !_icons.isEmpty()
|
|
|
|
&& base::get_if<int>(&_iconDown) != nullptr) {
|
2017-03-29 18:09:16 +03:00
|
|
|
if ((_iconsMousePos - _iconsMouseDown).manhattanLength() >= QApplication::startDragDistance()) {
|
|
|
|
_iconsDragging = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_iconsDragging) {
|
|
|
|
auto newX = snap(_iconsStartX + (rtl() ? -1 : 1) * (_iconsMouseDown.x() - _iconsMousePos.x()), 0, _iconsMax);
|
|
|
|
if (newX != qRound(_iconsX.current())) {
|
|
|
|
_iconsX = anim::value(newX, newX);
|
|
|
|
_iconsStartAnim = 0;
|
2019-04-01 21:44:54 +04:00
|
|
|
_iconsAnimation.stop();
|
2017-03-29 18:09:16 +03:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
if (_icons.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto wasDown = std::exchange(_iconDown, SpecialOver::None);
|
2017-03-29 18:09:16 +03:00
|
|
|
|
|
|
|
_iconsMousePos = e ? e->globalPos() : QCursor::pos();
|
|
|
|
if (_iconsDragging) {
|
2018-03-02 20:17:33 +03:00
|
|
|
finishDragging();
|
|
|
|
return;
|
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
updateSelected();
|
|
|
|
if (wasDown == _iconOver) {
|
|
|
|
if (const auto index = base::get_if<int>(&_iconOver)) {
|
|
|
|
_iconSelX = anim::value(
|
|
|
|
*index * st::stickerIconWidth,
|
|
|
|
*index * st::stickerIconWidth);
|
|
|
|
_pan->showStickerSet(_icons[*index].setId);
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::Footer::finishDragging() {
|
|
|
|
auto newX = snap(_iconsStartX + _iconsMouseDown.x() - _iconsMousePos.x(), 0, _iconsMax);
|
|
|
|
if (newX != qRound(_iconsX.current())) {
|
|
|
|
_iconsX = anim::value(newX, newX);
|
|
|
|
_iconsStartAnim = 0;
|
2019-04-01 21:44:54 +04:00
|
|
|
_iconsAnimation.stop();
|
2018-03-02 20:17:33 +03:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
_iconsDragging = false;
|
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
bool StickersListWidget::Footer::event(QEvent *e) {
|
|
|
|
if (e->type() == QEvent::TouchBegin) {
|
|
|
|
} else if (e->type() == QEvent::Wheel) {
|
2018-03-02 20:17:33 +03:00
|
|
|
if (!_icons.isEmpty()
|
|
|
|
&& (base::get_if<int>(&_iconOver) != nullptr)
|
|
|
|
&& (_iconDown == SpecialOver::None)) {
|
|
|
|
scrollByWheelEvent(static_cast<QWheelEvent*>(e));
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
}
|
2017-09-20 21:40:23 +03:00
|
|
|
return InnerFooter::event(e);
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::Footer::scrollByWheelEvent(
|
|
|
|
not_null<QWheelEvent*> e) {
|
|
|
|
auto horizontal = (e->angleDelta().x() != 0 || e->orientation() == Qt::Horizontal);
|
|
|
|
auto vertical = (e->angleDelta().y() != 0 || e->orientation() == Qt::Vertical);
|
|
|
|
if (horizontal) {
|
|
|
|
_horizontal = true;
|
|
|
|
}
|
|
|
|
auto newX = qRound(_iconsX.current());
|
|
|
|
if (/*_horizontal && */horizontal) {
|
|
|
|
newX = snap(newX - (rtl() ? -1 : 1) * (e->pixelDelta().x() ? e->pixelDelta().x() : e->angleDelta().x()), 0, _iconsMax);
|
|
|
|
} else if (/*!_horizontal && */vertical) {
|
|
|
|
newX = snap(newX - (e->pixelDelta().y() ? e->pixelDelta().y() : e->angleDelta().y()), 0, _iconsMax);
|
|
|
|
}
|
|
|
|
if (newX != qRound(_iconsX.current())) {
|
|
|
|
_iconsX = anim::value(newX, newX);
|
|
|
|
_iconsStartAnim = 0;
|
2019-04-01 21:44:54 +04:00
|
|
|
_iconsAnimation.stop();
|
2018-03-02 20:17:33 +03:00
|
|
|
updateSelected();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
void StickersListWidget::Footer::updateSelected() {
|
|
|
|
if (_iconDown >= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto p = mapFromGlobal(_iconsMousePos);
|
2018-03-02 20:17:33 +03:00
|
|
|
auto x = p.x(), y = p.y();
|
2017-03-29 18:09:16 +03:00
|
|
|
if (rtl()) x = width() - x;
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto settingsLeft = width() - _iconsRight;
|
|
|
|
const auto searchLeft = _iconsLeft - st::stickerIconWidth;
|
|
|
|
auto newOver = OverState(SpecialOver::None);
|
|
|
|
if (x >= searchLeft
|
|
|
|
&& x < searchLeft + st::stickerIconWidth
|
|
|
|
&& y >= _iconsTop
|
|
|
|
&& y < _iconsTop + st::emojiFooterHeight) {
|
|
|
|
newOver = SpecialOver::Search;
|
|
|
|
} else if (x >= settingsLeft
|
2017-11-12 13:54:18 +04:00
|
|
|
&& x < settingsLeft + st::stickerIconWidth
|
|
|
|
&& y >= _iconsTop
|
|
|
|
&& y < _iconsTop + st::emojiFooterHeight) {
|
2017-04-11 17:02:11 +03:00
|
|
|
if (!_icons.isEmpty() && !hasOnlyFeaturedSets()) {
|
2018-03-02 20:17:33 +03:00
|
|
|
newOver = SpecialOver::Settings;
|
2017-04-11 17:02:11 +03:00
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
} else if (!_icons.isEmpty()) {
|
2017-11-12 13:54:18 +04:00
|
|
|
if (y >= _iconsTop
|
|
|
|
&& y < _iconsTop + st::emojiFooterHeight
|
2018-03-02 20:17:33 +03:00
|
|
|
&& x >= _iconsLeft
|
2018-03-26 00:34:13 +04:00
|
|
|
&& x < width() - _iconsRight) {
|
2018-03-02 20:17:33 +03:00
|
|
|
x += qRound(_iconsX.current()) - _iconsLeft;
|
2018-03-26 00:34:13 +04:00
|
|
|
if (x < _icons.size() * st::stickerIconWidth) {
|
|
|
|
newOver = qFloor(x / st::stickerIconWidth);
|
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newOver != _iconOver) {
|
2018-03-02 20:17:33 +03:00
|
|
|
if (newOver == SpecialOver::None) {
|
2017-03-29 18:09:16 +03:00
|
|
|
setCursor(style::cur_default);
|
2018-03-02 20:17:33 +03:00
|
|
|
} else if (_iconOver == SpecialOver::None) {
|
2017-03-29 18:09:16 +03:00
|
|
|
setCursor(style::cur_pointer);
|
|
|
|
}
|
|
|
|
_iconOver = newOver;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
void StickersListWidget::Footer::refreshIcons(
|
|
|
|
ValidateIconAnimations animations) {
|
2017-03-29 18:09:16 +03:00
|
|
|
_pan->fillIcons(_icons);
|
2019-07-02 13:46:37 +02:00
|
|
|
refillLottieData();
|
2018-03-26 00:34:13 +04:00
|
|
|
refreshIconsGeometry(animations);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::refreshIconsGeometry(
|
|
|
|
ValidateIconAnimations animations) {
|
|
|
|
_iconOver = _iconDown = SpecialOver::None;
|
2017-03-29 18:09:16 +03:00
|
|
|
_iconsX.finish();
|
|
|
|
_iconSelX.finish();
|
|
|
|
_iconsStartAnim = 0;
|
2019-04-01 21:44:54 +04:00
|
|
|
_iconsAnimation.stop();
|
2017-11-12 13:54:18 +04:00
|
|
|
_iconsMax = std::max(
|
2018-03-02 20:17:33 +03:00
|
|
|
_iconsLeft + int(_icons.size()) * st::stickerIconWidth + _iconsRight - width(),
|
2017-11-12 13:54:18 +04:00
|
|
|
0);
|
2017-03-29 18:09:16 +03:00
|
|
|
if (_iconsX.current() > _iconsMax) {
|
|
|
|
_iconsX = anim::value(_iconsMax, _iconsMax);
|
|
|
|
}
|
|
|
|
updateSelected();
|
|
|
|
_pan->validateSelectedIcon(animations);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-04-11 17:02:11 +03:00
|
|
|
bool StickersListWidget::Footer::hasOnlyFeaturedSets() const {
|
|
|
|
return (_icons.size() == 1) && (_icons[0].setId == Stickers::FeaturedSetId);
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
void StickersListWidget::Footer::paintStickerSettingsIcon(Painter &p) const {
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto settingsLeft = width() - _iconsRight;
|
2017-11-12 13:54:18 +04:00
|
|
|
st::stickersSettings.paint(p, settingsLeft + (st::stickerIconWidth - st::stickersSettings.width()) / 2, _iconsTop + st::emojiCategory.iconPosition.y(), width());
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::Footer::paintSearchIcon(Painter &p) const {
|
|
|
|
const auto searchLeft = _iconsLeft - st::stickerIconWidth;
|
|
|
|
st::stickersSearch.paint(p, searchLeft + (st::stickerIconWidth - st::stickersSearch.width()) / 2, _iconsTop + st::emojiCategory.iconPosition.y(), width());
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
void StickersListWidget::Footer::paintFeaturedStickerSetsBadge(Painter &p, int iconLeft) const {
|
2019-07-24 13:13:51 +02:00
|
|
|
if (const auto unread = _pan->session().data().featuredStickerSetsUnreadCount()) {
|
2017-03-29 18:09:16 +03:00
|
|
|
Dialogs::Layout::UnreadBadgeStyle unreadSt;
|
|
|
|
unreadSt.sizeId = Dialogs::Layout::UnreadBadgeInStickersPanel;
|
|
|
|
unreadSt.size = st::stickersSettingsUnreadSize;
|
2017-11-12 13:54:18 +04:00
|
|
|
int unreadRight = iconLeft + st::stickerIconWidth - st::stickersSettingsUnreadPosition.x();
|
2017-03-29 18:09:16 +03:00
|
|
|
if (rtl()) unreadRight = width() - unreadRight;
|
|
|
|
int unreadTop = _iconsTop + st::stickersSettingsUnreadPosition.y();
|
|
|
|
Dialogs::Layout::paintUnreadCount(p, QString::number(unread), unreadRight, unreadTop, unreadSt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 13:46:37 +02:00
|
|
|
void StickersListWidget::Footer::validateIconLottieAnimation(
|
|
|
|
const StickerIcon &icon) {
|
|
|
|
if (icon.lottie
|
2019-07-02 15:20:04 +02:00
|
|
|
|| !Stickers::HasLottieThumbnail(icon.thumbnail, icon.sticker)) {
|
2019-07-02 13:46:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto player = Stickers::LottieThumbnail(
|
2019-07-02 15:20:04 +02:00
|
|
|
icon.thumbnail,
|
2019-07-02 13:46:37 +02:00
|
|
|
icon.sticker,
|
|
|
|
Stickers::LottieSize::StickersFooter,
|
2019-07-02 15:41:50 +02:00
|
|
|
QSize(
|
|
|
|
st::stickerIconWidth - 2 * st::stickerIconPadding,
|
|
|
|
st::emojiFooterHeight - 2 * st::stickerIconPadding
|
|
|
|
) * cIntRetinaFactor(),
|
2019-07-02 13:46:37 +02:00
|
|
|
_pan->getLottieRenderer());
|
|
|
|
if (!player) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
icon.lottie = player.get();
|
|
|
|
const auto id = icon.setId;
|
|
|
|
const auto [i, ok] = _lottieData.emplace(
|
|
|
|
id,
|
|
|
|
LottieIcon{ std::move(player) });
|
|
|
|
Assert(ok);
|
|
|
|
|
|
|
|
icon.lottie->updates(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
updateSetIcon(id);
|
|
|
|
}, i->second.lifetime);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::Footer::updateSetIcon(uint64 setId) {
|
|
|
|
enumerateVisibleIcons([&](const StickerIcon &icon, int x) {
|
|
|
|
if (icon.setId != setId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
update(x, _iconsTop, st::stickerIconWidth, st::emojiFooterHeight);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::Footer::paintSetIcon(
|
|
|
|
Painter &p,
|
|
|
|
const StickerIcon &icon,
|
|
|
|
int x) const {
|
|
|
|
if (icon.sticker) {
|
2018-07-14 00:25:47 +03:00
|
|
|
const auto origin = icon.sticker->stickerSetOrigin();
|
2019-03-22 13:24:56 +04:00
|
|
|
const auto thumb = icon.thumbnail
|
|
|
|
? icon.thumbnail.get()
|
|
|
|
: icon.sticker->thumbnail();
|
2019-07-02 13:46:37 +02:00
|
|
|
if (!thumb) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
thumb->load(origin);
|
|
|
|
const_cast<Footer*>(this)->validateIconLottieAnimation(icon);
|
|
|
|
if (!icon.lottie) {
|
2019-07-02 15:20:04 +02:00
|
|
|
if (!thumb->loaded()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p.drawPixmapLeft(
|
|
|
|
x + (st::stickerIconWidth - icon.pixw) / 2,
|
|
|
|
_iconsTop + (st::emojiFooterHeight - icon.pixh) / 2,
|
|
|
|
width(),
|
|
|
|
thumb->pix(origin, icon.pixw, icon.pixh));
|
2019-07-02 13:46:37 +02:00
|
|
|
} else if (icon.lottie->ready()) {
|
2019-07-02 15:41:50 +02:00
|
|
|
const auto frame = icon.lottie->frame();
|
2019-07-02 13:46:37 +02:00
|
|
|
const auto size = frame.size() / cIntRetinaFactor();
|
|
|
|
p.drawImage(
|
|
|
|
QRect(
|
|
|
|
x + (st::stickerIconWidth - size.width()) / 2,
|
|
|
|
_iconsTop + (st::emojiFooterHeight - size.height()) / 2,
|
|
|
|
size.width(),
|
|
|
|
size.height()),
|
|
|
|
frame);
|
|
|
|
const auto paused = _pan->controller()->isGifPausedAtLeastFor(
|
|
|
|
Window::GifPauseReason::SavedGifs);
|
|
|
|
if (!paused) {
|
|
|
|
icon.lottie->markFrameShown();
|
|
|
|
}
|
2019-01-25 18:37:28 +04:00
|
|
|
}
|
2018-03-02 20:17:33 +03:00
|
|
|
} else if (icon.megagroup) {
|
|
|
|
icon.megagroup->paintUserpicLeft(p, x + (st::stickerIconWidth - st::stickerGroupCategorySize) / 2, _iconsTop + (st::emojiFooterHeight - st::stickerGroupCategorySize) / 2, width(), st::stickerGroupCategorySize);
|
|
|
|
} else {
|
|
|
|
auto getSpecialSetIcon = [](uint64 setId) {
|
|
|
|
if (setId == Stickers::FeaturedSetId) {
|
|
|
|
return &st::stickersTrending;
|
2018-03-08 15:12:20 +03:00
|
|
|
//} else if (setId == Stickers::FavedSetId) {
|
|
|
|
// return &st::stickersFaved;
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
|
|
|
return &st::emojiRecent;
|
|
|
|
};
|
|
|
|
auto paintedIcon = getSpecialSetIcon(icon.setId);
|
|
|
|
paintedIcon->paint(p, x + (st::stickerIconWidth - paintedIcon->width()) / 2, _iconsTop + st::emojiCategory.iconPosition.y(), width());
|
|
|
|
if (icon.setId == Stickers::FeaturedSetId) {
|
|
|
|
paintFeaturedStickerSetsBadge(p, x);
|
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 21:44:54 +04:00
|
|
|
bool StickersListWidget::Footer::iconsAnimationCallback(crl::time now) {
|
2018-09-20 19:39:59 +03:00
|
|
|
if (anim::Disabled()) {
|
2019-04-01 21:44:54 +04:00
|
|
|
now += st::stickerIconMove;
|
2018-09-20 19:39:59 +03:00
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
if (_iconsStartAnim) {
|
2019-04-01 21:44:54 +04:00
|
|
|
const auto dt = (now - _iconsStartAnim) / float64(st::stickerIconMove);
|
|
|
|
if (dt >= 1.) {
|
2017-03-29 18:09:16 +03:00
|
|
|
_iconsStartAnim = 0;
|
|
|
|
_iconsX.finish();
|
|
|
|
_iconSelX.finish();
|
|
|
|
} else {
|
|
|
|
_iconsX.update(dt, anim::linear);
|
|
|
|
_iconSelX.update(dt, anim::linear);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 21:44:54 +04:00
|
|
|
update();
|
2017-03-29 18:09:16 +03:00
|
|
|
|
2019-04-01 21:44:54 +04:00
|
|
|
return (_iconsStartAnim != 0);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2019-06-06 13:21:40 +03:00
|
|
|
StickersListWidget::StickersListWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller)
|
|
|
|
: Inner(parent, controller)
|
2017-03-29 17:04:00 +03:00
|
|
|
, _section(Section::Stickers)
|
2017-11-12 13:54:18 +04:00
|
|
|
, _megagroupSetAbout(st::columnMinimalWidthThird - st::emojiScroll.width - st::emojiPanHeaderLeft)
|
2019-06-19 17:09:03 +02:00
|
|
|
, _addText(tr::lng_stickers_featured_add(tr::now).toUpper())
|
2017-03-29 17:04:00 +03:00
|
|
|
, _addWidth(st::stickersTrendingAdd.font->width(_addText))
|
2019-06-19 17:09:03 +02:00
|
|
|
, _settings(this, tr::lng_stickers_you_have(tr::now))
|
2018-11-21 22:14:48 +04:00
|
|
|
, _previewTimer([=] { showPreview(); })
|
2018-03-02 20:17:33 +03:00
|
|
|
, _searchRequestTimer([=] { sendSearchRequest(); }) {
|
2017-03-29 17:04:00 +03:00
|
|
|
setMouseTracking(true);
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
|
2019-08-06 17:40:08 +01:00
|
|
|
_settings->addClickHandler([=] {
|
|
|
|
Ui::show(Box<StickersBox>(
|
|
|
|
&controller->session(),
|
|
|
|
StickersBox::Section::Installed));
|
2018-11-21 22:14:48 +04:00
|
|
|
});
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2019-07-24 13:13:51 +02:00
|
|
|
subscribe(session().downloaderTaskFinished(), [=] {
|
2018-10-23 15:12:30 +04:00
|
|
|
if (isVisible()) {
|
|
|
|
update();
|
2019-07-01 14:38:10 +02:00
|
|
|
readVisibleFeatured(getVisibleTop(), getVisibleBottom());
|
2018-10-23 15:12:30 +04:00
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
});
|
2017-08-03 14:52:56 +02:00
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::ChannelStickersChanged, [this](const Notify::PeerUpdate &update) {
|
|
|
|
if (update.peer == _megagroupSet) {
|
|
|
|
refreshStickers();
|
|
|
|
}
|
|
|
|
}));
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2019-07-24 13:45:24 +02:00
|
|
|
Main::Session &StickersListWidget::session() const {
|
2019-07-24 13:13:51 +02:00
|
|
|
return controller()->session();
|
|
|
|
}
|
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
rpl::producer<not_null<DocumentData*>> StickersListWidget::chosen() const {
|
|
|
|
return _chosen.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> StickersListWidget::scrollUpdated() const {
|
|
|
|
return _scrollUpdated.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> StickersListWidget::checkForHide() const {
|
|
|
|
return _checkForHide.events();
|
|
|
|
}
|
|
|
|
|
2017-04-08 18:20:12 +03:00
|
|
|
object_ptr<TabbedSelector::InnerFooter> StickersListWidget::createFooter() {
|
2017-03-29 18:09:16 +03:00
|
|
|
Expects(_footer == nullptr);
|
2018-11-21 22:14:48 +04:00
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
auto result = object_ptr<Footer>(this);
|
|
|
|
_footer = result;
|
|
|
|
return std::move(result);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2017-09-13 19:57:44 +03:00
|
|
|
void StickersListWidget::visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) {
|
|
|
|
Inner::visibleTopBottomUpdated(visibleTop, visibleBottom);
|
2017-03-29 17:04:00 +03:00
|
|
|
if (_section == Section::Featured) {
|
2019-07-01 14:38:10 +02:00
|
|
|
checkVisibleFeatured(visibleTop, visibleBottom);
|
2019-07-01 13:20:53 +02:00
|
|
|
} else {
|
2019-07-01 14:38:10 +02:00
|
|
|
checkVisibleLottie();
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
validateSelectedIcon(ValidateIconAnimations::Full);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2019-07-01 14:38:10 +02:00
|
|
|
void StickersListWidget::checkVisibleFeatured(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) {
|
|
|
|
readVisibleFeatured(visibleTop, visibleBottom);
|
|
|
|
|
|
|
|
const auto visibleHeight = visibleBottom - visibleTop;
|
|
|
|
const auto rowHeight = featuredRowHeight();
|
|
|
|
const auto destroyAbove = floorclamp(visibleTop - visibleHeight, rowHeight, 0, _featuredSets.size());
|
|
|
|
const auto destroyBelow = ceilclamp(visibleBottom + visibleHeight, rowHeight, 0, _featuredSets.size());
|
|
|
|
for (auto i = 0; i != destroyAbove; ++i) {
|
|
|
|
destroyLottieIn(_featuredSets[i]);
|
|
|
|
}
|
|
|
|
for (auto i = destroyBelow; i != _featuredSets.size(); ++i) {
|
|
|
|
destroyLottieIn(_featuredSets[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::readVisibleFeatured(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) {
|
|
|
|
const auto rowHeight = featuredRowHeight();
|
|
|
|
const auto rowFrom = floorclamp(visibleTop, rowHeight, 0, _featuredSets.size());
|
|
|
|
const auto rowTo = ceilclamp(visibleBottom, rowHeight, 0, _featuredSets.size());
|
|
|
|
for (auto i = rowFrom; i < rowTo; ++i) {
|
2017-03-29 17:04:00 +03:00
|
|
|
auto &set = _featuredSets[i];
|
|
|
|
if (!(set.flags & MTPDstickerSet_ClientFlag::f_unread)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-07-01 14:38:10 +02:00
|
|
|
if (i * rowHeight < visibleTop || (i + 1) * rowHeight > visibleBottom) {
|
2017-03-29 17:04:00 +03:00
|
|
|
continue;
|
|
|
|
}
|
2019-06-25 14:25:02 +02:00
|
|
|
int count = qMin(int(set.stickers.size()), _columnCount);
|
2017-03-29 17:04:00 +03:00
|
|
|
int loaded = 0;
|
|
|
|
for (int j = 0; j < count; ++j) {
|
2019-06-25 14:25:02 +02:00
|
|
|
if (!set.stickers[j].document->hasThumbnail()
|
|
|
|
|| set.stickers[j].document->thumbnail()->loaded()
|
|
|
|
|| set.stickers[j].document->loaded()) {
|
2017-03-29 17:04:00 +03:00
|
|
|
++loaded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (loaded == count) {
|
2019-07-24 13:13:51 +02:00
|
|
|
session().api().readFeaturedSetDelayed(set.id);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int StickersListWidget::featuredRowHeight() const {
|
2017-11-12 13:54:18 +04:00
|
|
|
return st::stickersTrendingHeader
|
|
|
|
+ _singleSize.height()
|
|
|
|
+ st::stickersTrendingSkip;
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Callback>
|
|
|
|
bool StickersListWidget::enumerateSections(Callback callback) const {
|
|
|
|
auto info = SectionInfo();
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto &sets = shownSets();
|
|
|
|
for (auto i = 0; i != sets.size(); ++i) {
|
|
|
|
auto &set = sets[i];
|
2017-03-29 17:04:00 +03:00
|
|
|
info.section = i;
|
2019-06-25 14:25:02 +02:00
|
|
|
info.count = set.stickers.size();
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto titleSkip = set.externalLayout
|
|
|
|
? st::stickersTrendingHeader
|
|
|
|
: setHasTitle(set)
|
|
|
|
? st::emojiPanHeader
|
|
|
|
: st::stickerPanPadding;
|
|
|
|
info.rowsTop = info.top + titleSkip;
|
|
|
|
if (set.externalLayout) {
|
|
|
|
info.rowsCount = 1;
|
|
|
|
info.rowsBottom = info.top + featuredRowHeight();
|
|
|
|
} else if (set.id == Stickers::MegagroupSetId && !info.count) {
|
2017-08-03 14:52:56 +02:00
|
|
|
info.rowsCount = 0;
|
|
|
|
info.rowsBottom = info.rowsTop + _megagroupSetButtonRect.y() + _megagroupSetButtonRect.height() + st::stickerGroupCategoryAddMargin.bottom();
|
|
|
|
} else {
|
2017-11-12 13:54:18 +04:00
|
|
|
info.rowsCount = (info.count / _columnCount) + ((info.count % _columnCount) ? 1 : 0);
|
|
|
|
info.rowsBottom = info.rowsTop + info.rowsCount * _singleSize.height();
|
2017-08-03 14:52:56 +02:00
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
if (!callback(info)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
info.top = info.rowsBottom;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
StickersListWidget::SectionInfo StickersListWidget::sectionInfo(int section) const {
|
2018-03-02 20:17:33 +03:00
|
|
|
Expects(section >= 0 && section < shownSets().size());
|
2019-06-28 16:26:03 +02:00
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
auto result = SectionInfo();
|
|
|
|
enumerateSections([searchForSection = section, &result](const SectionInfo &info) {
|
|
|
|
if (info.section == searchForSection) {
|
|
|
|
result = info;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
StickersListWidget::SectionInfo StickersListWidget::sectionInfoByOffset(int yOffset) const {
|
|
|
|
auto result = SectionInfo();
|
|
|
|
enumerateSections([this, &result, yOffset](const SectionInfo &info) {
|
2018-03-02 20:17:33 +03:00
|
|
|
if (yOffset < info.rowsBottom || info.section == shownSets().size() - 1) {
|
2017-03-29 17:04:00 +03:00
|
|
|
result = info;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
int StickersListWidget::countDesiredHeight(int newWidth) {
|
|
|
|
if (newWidth <= st::stickerPanWidthMin) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
auto availableWidth = newWidth - (st::stickerPanPadding - st::buttonRadius);
|
2017-11-12 21:46:20 +04:00
|
|
|
auto columnCount = availableWidth / st::stickerPanWidthMin;
|
|
|
|
auto singleWidth = availableWidth / columnCount;
|
2017-11-12 13:54:18 +04:00
|
|
|
auto fullWidth = (st::buttonRadius + newWidth + st::emojiScroll.width);
|
2017-11-12 21:46:20 +04:00
|
|
|
auto rowsRight = (fullWidth - columnCount * singleWidth) / 2;
|
2017-11-12 13:54:18 +04:00
|
|
|
accumulate_max(rowsRight, st::emojiScroll.width);
|
|
|
|
_rowsLeft = fullWidth
|
2017-11-12 21:46:20 +04:00
|
|
|
- columnCount * singleWidth
|
2017-11-12 13:54:18 +04:00
|
|
|
- rowsRight
|
|
|
|
- st::buttonRadius;
|
|
|
|
_singleSize = QSize(singleWidth, singleWidth);
|
2017-11-12 21:46:20 +04:00
|
|
|
setColumnCount(columnCount);
|
|
|
|
|
2017-09-16 19:53:41 +03:00
|
|
|
auto visibleHeight = minimalHeight();
|
2018-03-02 20:17:33 +03:00
|
|
|
auto minimalHeight = (visibleHeight - st::stickerPanPadding);
|
|
|
|
auto countResult = [this](int minimalLastHeight) {
|
|
|
|
const auto &sets = shownSets();
|
|
|
|
if (sets.empty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const auto info = sectionInfo(sets.size() - 1);
|
|
|
|
return info.top
|
|
|
|
+ qMax(info.rowsBottom - info.top, minimalLastHeight);
|
2017-03-29 17:04:00 +03:00
|
|
|
};
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto minimalLastHeight = (_section == Section::Stickers)
|
|
|
|
? minimalHeight
|
|
|
|
: 0;
|
|
|
|
return qMax(minimalHeight, countResult(minimalLastHeight))
|
|
|
|
+ st::stickerPanPadding;
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::installedLocally(uint64 setId) {
|
|
|
|
_installedLocallySets.insert(setId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::notInstalledLocally(uint64 setId) {
|
|
|
|
_installedLocallySets.remove(setId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::clearInstalledLocally() {
|
|
|
|
if (!_installedLocallySets.empty()) {
|
|
|
|
_installedLocallySets.clear();
|
|
|
|
refreshStickers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::sendSearchRequest() {
|
|
|
|
if (_searchRequestId || _searchNextQuery.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_searchRequestTimer.cancel();
|
|
|
|
_searchQuery = _searchNextQuery;
|
|
|
|
|
|
|
|
auto it = _searchCache.find(_searchQuery);
|
|
|
|
if (it != _searchCache.cend()) {
|
|
|
|
_footer->setLoading(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_footer->setLoading(true);
|
|
|
|
const auto hash = int32(0);
|
|
|
|
_searchRequestId = request(MTPmessages_SearchStickerSets(
|
|
|
|
MTP_flags(0),
|
|
|
|
MTP_string(_searchQuery),
|
|
|
|
MTP_int(hash)
|
|
|
|
)).done([=](const MTPmessages_FoundStickerSets &result) {
|
|
|
|
searchResultsDone(result);
|
|
|
|
}).fail([this](const RPCError &error) {
|
|
|
|
// show error?
|
|
|
|
_footer->setLoading(false);
|
|
|
|
_searchRequestId = 0;
|
|
|
|
}).handleAllErrors().send();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::searchForSets(const QString &query) {
|
|
|
|
const auto cleaned = query.trimmed();
|
|
|
|
if (cleaned.isEmpty()) {
|
|
|
|
cancelSetsSearch();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_searchQuery != cleaned) {
|
|
|
|
_footer->setLoading(false);
|
|
|
|
if (const auto requestId = base::take(_searchRequestId)) {
|
|
|
|
request(requestId).cancel();
|
|
|
|
}
|
|
|
|
if (_searchCache.find(cleaned) != _searchCache.cend()) {
|
|
|
|
_searchRequestTimer.cancel();
|
|
|
|
_searchQuery = _searchNextQuery = cleaned;
|
|
|
|
} else {
|
|
|
|
_searchNextQuery = cleaned;
|
|
|
|
_searchRequestTimer.callOnce(kSearchRequestDelay);
|
|
|
|
}
|
|
|
|
showSearchResults();
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::cancelSetsSearch() {
|
|
|
|
_footer->setLoading(false);
|
|
|
|
if (const auto requestId = base::take(_searchRequestId)) {
|
|
|
|
request(requestId).cancel();
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2018-03-02 20:17:33 +03:00
|
|
|
_searchRequestTimer.cancel();
|
|
|
|
_searchQuery = _searchNextQuery = QString();
|
|
|
|
_searchCache.clear();
|
|
|
|
refreshSearchRows(nullptr);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::showSearchResults() {
|
|
|
|
refreshSearchRows();
|
2018-11-21 22:14:48 +04:00
|
|
|
scrollTo(0);
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::refreshSearchRows() {
|
|
|
|
auto it = _searchCache.find(_searchQuery);
|
|
|
|
auto sets = (it != end(_searchCache))
|
|
|
|
? &it->second
|
|
|
|
: nullptr;
|
|
|
|
refreshSearchRows(sets);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::refreshSearchRows(
|
2018-06-04 22:48:17 +03:00
|
|
|
const std::vector<uint64> *cloudSets) {
|
2018-03-02 20:17:33 +03:00
|
|
|
clearSelection();
|
|
|
|
|
2019-07-01 17:34:29 +02:00
|
|
|
const auto wasSection = _section;
|
|
|
|
const auto guard = gsl::finally([&] {
|
|
|
|
if (_section == wasSection && _section == Section::Search) {
|
|
|
|
refillLottieData();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
_searchSets.clear();
|
|
|
|
fillLocalSearchRows(_searchNextQuery);
|
|
|
|
|
2018-03-15 02:33:28 +03:00
|
|
|
if (!cloudSets && _searchNextQuery.isEmpty()) {
|
2018-03-02 20:17:33 +03:00
|
|
|
showStickerSet(!_mySets.empty()
|
|
|
|
? _mySets[0].id
|
|
|
|
: Stickers::FeaturedSetId);
|
|
|
|
return;
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2019-07-01 17:34:29 +02:00
|
|
|
setSection(Section::Search);
|
2018-03-02 20:17:33 +03:00
|
|
|
if (cloudSets) {
|
|
|
|
fillCloudSearchRows(*cloudSets);
|
|
|
|
}
|
|
|
|
if (_footer) {
|
|
|
|
_footer->refreshIcons(ValidateIconAnimations::Scroll);
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
_lastMousePosition = QCursor::pos();
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
resizeToWidth(width());
|
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::fillLocalSearchRows(const QString &query) {
|
|
|
|
const auto searchWordsList = TextUtilities::PrepareSearchWords(query);
|
|
|
|
if (searchWordsList.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto searchWordInTitle = [](
|
|
|
|
const QStringList &titleWords,
|
|
|
|
const QString &searchWord) {
|
|
|
|
for (const auto &titleWord : titleWords) {
|
|
|
|
if (titleWord.startsWith(searchWord)) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2018-03-02 20:17:33 +03:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
auto allSearchWordsInTitle = [&](
|
|
|
|
const QStringList &titleWords) {
|
|
|
|
for (const auto &searchWord : searchWordsList) {
|
|
|
|
if (!searchWordInTitle(titleWords, searchWord)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2018-03-02 20:17:33 +03:00
|
|
|
return true;
|
|
|
|
};
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2019-07-24 13:13:51 +02:00
|
|
|
const auto &sets = session().data().stickerSets();
|
2018-03-02 20:17:33 +03:00
|
|
|
for (const auto &[setId, titleWords] : _searchIndex) {
|
|
|
|
if (allSearchWordsInTitle(titleWords)) {
|
|
|
|
if (const auto it = sets.find(setId); it != sets.end()) {
|
|
|
|
addSearchRow(&*it);
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::fillCloudSearchRows(
|
2018-06-04 22:48:17 +03:00
|
|
|
const std::vector<uint64> &cloudSets) {
|
2019-07-24 13:13:51 +02:00
|
|
|
const auto &sets = session().data().stickerSets();
|
2018-06-04 22:48:17 +03:00
|
|
|
for (const auto setId : cloudSets) {
|
|
|
|
if (const auto it = sets.find(setId); it != sets.end()) {
|
|
|
|
addSearchRow(&*it);
|
|
|
|
}
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::addSearchRow(not_null<const Stickers::Set*> set) {
|
2019-03-22 13:24:56 +04:00
|
|
|
_searchSets.emplace_back(
|
2018-03-02 20:17:33 +03:00
|
|
|
set->id,
|
|
|
|
set->flags,
|
|
|
|
set->title,
|
2018-03-08 14:37:01 +03:00
|
|
|
set->shortName,
|
2019-03-22 13:24:56 +04:00
|
|
|
set->thumbnail,
|
2018-03-02 20:17:33 +03:00
|
|
|
!SetInMyList(set->flags),
|
2018-03-08 14:12:30 +03:00
|
|
|
set->count,
|
2019-06-25 14:25:02 +02:00
|
|
|
PrepareStickers(set->stickers.empty()
|
|
|
|
? set->covers
|
|
|
|
: set->stickers));
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
auto StickersListWidget::shownSets() const -> const std::vector<Set> & {
|
|
|
|
switch (_section) {
|
|
|
|
case Section::Featured: return _featuredSets;
|
|
|
|
case Section::Search: return _searchSets;
|
|
|
|
case Section::Stickers: return _mySets;
|
|
|
|
}
|
|
|
|
Unexpected("Section in StickersListWidget.");
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
auto StickersListWidget::shownSets() -> std::vector<Set> & {
|
|
|
|
switch (_section) {
|
|
|
|
case Section::Featured: return _featuredSets;
|
|
|
|
case Section::Search: return _searchSets;
|
|
|
|
case Section::Stickers: return _mySets;
|
|
|
|
}
|
|
|
|
Unexpected("Section in StickersListWidget.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::searchResultsDone(
|
|
|
|
const MTPmessages_FoundStickerSets &result) {
|
|
|
|
_footer->setLoading(false);
|
|
|
|
_searchRequestId = 0;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
if (result.type() == mtpc_messages_foundStickerSetsNotModified) {
|
|
|
|
LOG(("API Error: "
|
|
|
|
"messages.foundStickerSetsNotModified not expected."));
|
|
|
|
return;
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
Assert(result.type() == mtpc_messages_foundStickerSets);
|
|
|
|
|
|
|
|
auto it = _searchCache.find(_searchQuery);
|
|
|
|
if (it == _searchCache.cend()) {
|
|
|
|
it = _searchCache.emplace(
|
|
|
|
_searchQuery,
|
2018-06-04 22:48:17 +03:00
|
|
|
std::vector<uint64>()).first;
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
|
|
|
auto &d = result.c_messages_foundStickerSets();
|
2019-07-05 15:38:38 +02:00
|
|
|
for (const auto &stickerSet : d.vsets().v) {
|
2018-03-02 20:17:33 +03:00
|
|
|
const MTPDstickerSet *setData = nullptr;
|
|
|
|
Stickers::Pack covers;
|
|
|
|
switch (stickerSet.type()) {
|
|
|
|
case mtpc_stickerSetCovered: {
|
|
|
|
auto &d = stickerSet.c_stickerSetCovered();
|
2019-07-05 15:38:38 +02:00
|
|
|
if (d.vset().type() == mtpc_stickerSet) {
|
|
|
|
setData = &d.vset().c_stickerSet();
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_stickerSetMultiCovered: {
|
|
|
|
auto &d = stickerSet.c_stickerSetMultiCovered();
|
2019-07-05 15:38:38 +02:00
|
|
|
if (d.vset().type() == mtpc_stickerSet) {
|
|
|
|
setData = &d.vset().c_stickerSet();
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
2019-07-05 15:38:38 +02:00
|
|
|
for (const auto &cover : d.vcovers().v) {
|
2019-07-24 13:13:51 +02:00
|
|
|
const auto document = session().data().processDocument(cover);
|
2018-03-02 20:17:33 +03:00
|
|
|
if (document->sticker()) {
|
|
|
|
covers.push_back(document);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
if (!setData) continue;
|
|
|
|
|
|
|
|
if (const auto set = Stickers::FeedSet(*setData)) {
|
|
|
|
if (!covers.empty()) {
|
|
|
|
set->covers = covers;
|
|
|
|
}
|
|
|
|
if (set->stickers.empty() && set->covers.empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-06-04 22:48:17 +03:00
|
|
|
it->second.push_back(set->id);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
}
|
2018-03-02 20:17:33 +03:00
|
|
|
showSearchResults();
|
|
|
|
}
|
|
|
|
|
|
|
|
int StickersListWidget::stickersLeft() const {
|
|
|
|
return _rowsLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect StickersListWidget::stickerRect(int section, int sel) {
|
|
|
|
auto info = sectionInfo(section);
|
2019-06-25 14:25:02 +02:00
|
|
|
if (sel >= shownSets()[section].stickers.size()) {
|
|
|
|
sel -= shownSets()[section].stickers.size();
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
|
|
|
auto countTillItem = (sel - (sel % _columnCount));
|
|
|
|
auto rowsToSkip = (countTillItem / _columnCount) + ((countTillItem % _columnCount) ? 1 : 0);
|
|
|
|
auto x = stickersLeft() + ((sel % _columnCount) * _singleSize.width());
|
|
|
|
auto y = info.rowsTop + rowsToSkip * _singleSize.height();
|
|
|
|
return QRect(QPoint(x, y), _singleSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
auto clip = e->rect();
|
|
|
|
p.fillRect(clip, st::emojiPanBg);
|
|
|
|
|
|
|
|
paintStickers(p, clip);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::paintStickers(Painter &p, QRect clip) {
|
2017-11-12 13:54:18 +04:00
|
|
|
auto fromColumn = floorclamp(clip.x() - stickersLeft(), _singleSize.width(), 0, _columnCount);
|
|
|
|
auto toColumn = ceilclamp(clip.x() + clip.width() - stickersLeft(), _singleSize.width(), 0, _columnCount);
|
2017-03-29 17:04:00 +03:00
|
|
|
if (rtl()) {
|
|
|
|
qSwap(fromColumn, toColumn);
|
2017-11-12 13:54:18 +04:00
|
|
|
fromColumn = _columnCount - fromColumn;
|
|
|
|
toColumn = _columnCount - toColumn;
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
auto &sets = shownSets();
|
2017-03-29 18:09:16 +03:00
|
|
|
auto selectedSticker = base::get_if<OverSticker>(&_selected);
|
2017-08-14 13:38:23 +03:00
|
|
|
auto selectedButton = base::get_if<OverButton>(_pressed ? &_pressed : &_selected);
|
2018-03-02 20:17:33 +03:00
|
|
|
|
|
|
|
if (sets.empty() && _section == Section::Search) {
|
|
|
|
paintEmptySearchResults(p);
|
|
|
|
}
|
|
|
|
enumerateSections([&](const SectionInfo &info) {
|
2017-03-29 17:04:00 +03:00
|
|
|
if (clip.top() >= info.rowsBottom) {
|
|
|
|
return true;
|
|
|
|
} else if (clip.top() + clip.height() <= info.top) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-02 20:17:33 +03:00
|
|
|
auto &set = sets[info.section];
|
|
|
|
if (set.externalLayout) {
|
2018-03-08 14:12:30 +03:00
|
|
|
const auto size = (set.flags
|
|
|
|
& MTPDstickerSet_ClientFlag::f_not_loaded)
|
|
|
|
? set.count
|
2019-06-25 14:25:02 +02:00
|
|
|
: int(set.stickers.size());
|
2018-03-02 20:17:33 +03:00
|
|
|
|
|
|
|
auto widthForTitle = stickersRight() - (st::emojiPanHeaderLeft - st::buttonRadius);
|
|
|
|
if (featuredHasAddButton(info.section)) {
|
|
|
|
auto add = featuredAddRect(info.section);
|
|
|
|
auto selected = selectedButton ? (selectedButton->section == info.section) : false;
|
|
|
|
auto &textBg = selected ? st::stickersTrendingAdd.textBgOver : st::stickersTrendingAdd.textBg;
|
|
|
|
|
|
|
|
App::roundRect(p, myrtlrect(add), textBg, ImageRoundRadius::Small);
|
|
|
|
if (set.ripple) {
|
2019-04-02 13:13:30 +04:00
|
|
|
set.ripple->paint(p, add.x(), add.y(), width());
|
2018-03-02 20:17:33 +03:00
|
|
|
if (set.ripple->empty()) {
|
|
|
|
set.ripple.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p.setFont(st::stickersTrendingAdd.font);
|
|
|
|
p.setPen(selected ? st::stickersTrendingAdd.textFgOver : st::stickersTrendingAdd.textFg);
|
|
|
|
p.drawTextLeft(add.x() - (st::stickersTrendingAdd.width / 2), add.y() + st::stickersTrendingAdd.textTop, width(), _addText, _addWidth);
|
|
|
|
|
|
|
|
widthForTitle -= add.width() - (st::stickersTrendingAdd.width / 2);
|
|
|
|
} else {
|
|
|
|
auto add = featuredAddRect(info.section);
|
|
|
|
int checkx = add.left() + (add.width() - st::stickersFeaturedInstalled.width()) / 2;
|
|
|
|
int checky = add.top() + (add.height() - st::stickersFeaturedInstalled.height()) / 2;
|
|
|
|
st::stickersFeaturedInstalled.paint(p, QPoint(checkx, checky), width());
|
|
|
|
}
|
|
|
|
if (set.flags & MTPDstickerSet_ClientFlag::f_unread) {
|
|
|
|
widthForTitle -= st::stickersFeaturedUnreadSize + st::stickersFeaturedUnreadSkip;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto titleText = set.title;
|
|
|
|
auto titleWidth = st::stickersTrendingHeaderFont->width(titleText);
|
|
|
|
if (titleWidth > widthForTitle) {
|
|
|
|
titleText = st::stickersTrendingHeaderFont->elided(titleText, widthForTitle);
|
|
|
|
titleWidth = st::stickersTrendingHeaderFont->width(titleText);
|
|
|
|
}
|
|
|
|
p.setFont(st::stickersTrendingHeaderFont);
|
|
|
|
p.setPen(st::stickersTrendingHeaderFg);
|
|
|
|
p.drawTextLeft(st::emojiPanHeaderLeft - st::buttonRadius, info.top + st::stickersTrendingHeaderTop, width(), titleText, titleWidth);
|
|
|
|
|
|
|
|
if (set.flags & MTPDstickerSet_ClientFlag::f_unread) {
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::stickersFeaturedUnreadBg);
|
|
|
|
|
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
2019-09-13 15:22:54 +03:00
|
|
|
p.drawEllipse(style::rtlrect(st::emojiPanHeaderLeft - st::buttonRadius + titleWidth + st::stickersFeaturedUnreadSkip, info.top + st::stickersTrendingHeaderTop + st::stickersFeaturedUnreadTop, st::stickersFeaturedUnreadSize, st::stickersFeaturedUnreadSize, width()));
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-19 18:39:25 +02:00
|
|
|
auto statusText = (size > 0) ? tr::lng_stickers_count(tr::now, lt_count, size) : tr::lng_contacts_loading(tr::now);
|
2018-03-02 20:17:33 +03:00
|
|
|
p.setFont(st::stickersTrendingSubheaderFont);
|
|
|
|
p.setPen(st::stickersTrendingSubheaderFg);
|
|
|
|
p.drawTextLeft(st::emojiPanHeaderLeft - st::buttonRadius, info.top + st::stickersTrendingSubheaderTop, width(), statusText);
|
|
|
|
|
|
|
|
if (info.rowsTop >= clip.y() + clip.height()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = fromColumn; j < toColumn; ++j) {
|
|
|
|
int index = j;
|
|
|
|
if (index >= size) break;
|
|
|
|
|
|
|
|
auto selected = selectedSticker ? (selectedSticker->section == info.section && selectedSticker->index == index) : false;
|
|
|
|
auto deleteSelected = false;
|
2019-06-25 14:25:02 +02:00
|
|
|
paintSticker(p, set, info.rowsTop, info.section, index, selected, deleteSelected);
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
2019-07-01 13:20:53 +02:00
|
|
|
markLottieFrameShown(set);
|
2018-03-02 20:17:33 +03:00
|
|
|
return true;
|
|
|
|
}
|
2017-08-03 10:09:33 +02:00
|
|
|
if (setHasTitle(set) && clip.top() < info.rowsTop) {
|
2017-03-29 18:09:16 +03:00
|
|
|
auto titleText = set.title;
|
|
|
|
auto titleWidth = st::stickersTrendingHeaderFont->width(titleText);
|
|
|
|
auto widthForTitle = stickersRight() - (st::emojiPanHeaderLeft - st::buttonRadius);
|
|
|
|
if (hasRemoveButton(info.section)) {
|
|
|
|
auto remove = removeButtonRect(info.section);
|
|
|
|
auto selected = selectedButton ? (selectedButton->section == info.section) : false;
|
|
|
|
if (set.ripple) {
|
2019-04-02 13:13:30 +04:00
|
|
|
set.ripple->paint(p, remove.x() + st::stickerPanRemoveSet.rippleAreaPosition.x(), remove.y() + st::stickerPanRemoveSet.rippleAreaPosition.y(), width());
|
2017-03-29 18:09:16 +03:00
|
|
|
if (set.ripple->empty()) {
|
|
|
|
set.ripple.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(selected ? st::stickerPanRemoveSet.iconOver : st::stickerPanRemoveSet.icon).paint(p, remove.topLeft() + st::stickerPanRemoveSet.iconPosition, width());
|
|
|
|
|
|
|
|
widthForTitle -= remove.width();
|
|
|
|
}
|
|
|
|
if (titleWidth > widthForTitle) {
|
|
|
|
titleText = st::stickersTrendingHeaderFont->elided(titleText, widthForTitle);
|
|
|
|
titleWidth = st::stickersTrendingHeaderFont->width(titleText);
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
p.setFont(st::emojiPanHeaderFont);
|
|
|
|
p.setPen(st::emojiPanHeaderFg);
|
2017-03-29 18:09:16 +03:00
|
|
|
p.drawTextLeft(st::emojiPanHeaderLeft - st::buttonRadius, info.top + st::emojiPanHeaderTop, width(), titleText, titleWidth);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2019-07-01 13:20:53 +02:00
|
|
|
if (clip.top() + clip.height() <= info.rowsTop) {
|
|
|
|
return true;
|
|
|
|
} else if (set.id == Stickers::MegagroupSetId && set.stickers.empty()) {
|
|
|
|
auto buttonSelected = (base::get_if<OverGroupAdd>(&_selected) != nullptr);
|
|
|
|
paintMegagroupEmptySet(p, info.rowsTop, buttonSelected);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
auto special = (set.flags & MTPDstickerSet::Flag::f_official) != 0;
|
|
|
|
auto fromRow = floorclamp(clip.y() - info.rowsTop, _singleSize.height(), 0, info.rowsCount);
|
|
|
|
auto toRow = ceilclamp(clip.y() + clip.height() - info.rowsTop, _singleSize.height(), 0, info.rowsCount);
|
|
|
|
for (int i = fromRow; i < toRow; ++i) {
|
|
|
|
for (int j = fromColumn; j < toColumn; ++j) {
|
|
|
|
int index = i * _columnCount + j;
|
|
|
|
if (index >= info.count) break;
|
|
|
|
|
|
|
|
auto selected = selectedSticker ? (selectedSticker->section == info.section && selectedSticker->index == index) : false;
|
|
|
|
auto deleteSelected = selected && selectedSticker->overDelete;
|
|
|
|
paintSticker(p, set, info.rowsTop, info.section, index, selected, deleteSelected);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
}
|
2019-07-01 13:20:53 +02:00
|
|
|
markLottieFrameShown(set);
|
2017-03-29 17:04:00 +03:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-01 13:20:53 +02:00
|
|
|
void StickersListWidget::markLottieFrameShown(Set &set) {
|
2019-07-01 17:34:29 +02:00
|
|
|
if (const auto player = set.lottiePlayer) {
|
2019-07-01 13:20:53 +02:00
|
|
|
const auto paused = controller()->isGifPausedAtLeastFor(
|
|
|
|
Window::GifPauseReason::SavedGifs);
|
|
|
|
if (!paused) {
|
|
|
|
player->markFrameShown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-01 14:38:10 +02:00
|
|
|
void StickersListWidget::checkVisibleLottie() {
|
2019-07-01 13:20:53 +02:00
|
|
|
if (shownSets().empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-07-01 14:38:10 +02:00
|
|
|
const auto visibleTop = getVisibleTop();
|
2019-07-01 13:20:53 +02:00
|
|
|
const auto visibleBottom = getVisibleBottom();
|
2019-07-01 14:38:10 +02:00
|
|
|
const auto destroyAfterDistance = (visibleBottom - visibleTop) * 2;
|
|
|
|
const auto destroyAbove = visibleTop - destroyAfterDistance;
|
|
|
|
const auto destroyBelow = visibleBottom + destroyAfterDistance;
|
|
|
|
enumerateSections([&](const SectionInfo &info) {
|
|
|
|
if (destroyBelow <= info.rowsTop
|
|
|
|
|| destroyAbove >= info.rowsBottom) {
|
|
|
|
destroyLottieIn(shownSets()[info.section]);
|
|
|
|
} else if ((visibleTop > info.rowsTop && visibleTop < info.rowsBottom)
|
|
|
|
|| (visibleBottom > info.rowsTop
|
|
|
|
&& visibleBottom < info.rowsBottom)) {
|
|
|
|
pauseInvisibleLottieIn(info);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::destroyLottieIn(Set &set) {
|
|
|
|
if (!set.lottiePlayer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
set.lottiePlayer = nullptr;
|
|
|
|
for (auto &sticker : set.stickers) {
|
|
|
|
sticker.animated = nullptr;
|
2019-07-01 13:20:53 +02:00
|
|
|
}
|
2019-07-01 17:34:29 +02:00
|
|
|
_lottieData.remove(set.id);
|
2019-07-01 13:20:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::pauseInvisibleLottieIn(const SectionInfo &info) {
|
|
|
|
auto &set = shownSets()[info.section];
|
2019-07-01 17:34:29 +02:00
|
|
|
const auto player = set.lottiePlayer;
|
2019-07-01 13:20:53 +02:00
|
|
|
if (!player) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto pauseInRows = [&](int fromRow, int tillRow) {
|
|
|
|
Expects(fromRow <= tillRow);
|
|
|
|
|
|
|
|
for (auto i = fromRow; i != tillRow; ++i) {
|
|
|
|
for (auto j = 0; j != _columnCount; ++j) {
|
|
|
|
const auto index = i * _columnCount + j;
|
|
|
|
if (index >= info.count) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (const auto animated = set.stickers[index].animated) {
|
|
|
|
player->pause(animated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto visibleTop = getVisibleTop();
|
|
|
|
const auto visibleBottom = getVisibleBottom();
|
|
|
|
if (visibleTop >= info.rowsTop + _singleSize.height()
|
|
|
|
&& visibleTop < info.rowsBottom) {
|
|
|
|
const auto pauseHeight = (visibleTop - info.rowsTop);
|
|
|
|
const auto pauseRows = std::min(
|
|
|
|
pauseHeight / _singleSize.height(),
|
|
|
|
info.rowsCount);
|
|
|
|
pauseInRows(0, pauseRows);
|
|
|
|
}
|
|
|
|
if (visibleBottom > info.rowsTop
|
|
|
|
&& visibleBottom + _singleSize.height() <= info.rowsBottom) {
|
|
|
|
const auto pauseHeight = (info.rowsBottom - visibleBottom);
|
|
|
|
const auto pauseRows = std::min(
|
|
|
|
pauseHeight / _singleSize.height(),
|
|
|
|
info.rowsCount);
|
|
|
|
pauseInRows(info.rowsCount - pauseRows, info.rowsCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::paintEmptySearchResults(Painter &p) {
|
|
|
|
const auto iconLeft = (width() - st::stickersEmpty.width()) / 2;
|
|
|
|
const auto iconTop = (height() / 3) - (st::stickersEmpty.height() / 2);
|
|
|
|
st::stickersEmpty.paint(p, iconLeft, iconTop, width());
|
|
|
|
|
2019-06-19 17:09:03 +02:00
|
|
|
const auto text = tr::lng_stickers_nothing_found(tr::now);
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto textWidth = st::normalFont->width(text);
|
|
|
|
p.setFont(st::normalFont);
|
|
|
|
p.setPen(st::windowSubTextFg);
|
|
|
|
p.drawTextLeft(
|
|
|
|
(width() - textWidth) / 2,
|
2018-03-08 15:12:20 +03:00
|
|
|
iconTop + st::stickersEmpty.height() - st::normalFont->height,
|
2018-03-02 20:17:33 +03:00
|
|
|
width(),
|
|
|
|
text,
|
|
|
|
textWidth);
|
|
|
|
}
|
|
|
|
|
2017-08-03 14:52:56 +02:00
|
|
|
int StickersListWidget::megagroupSetInfoLeft() const {
|
|
|
|
return st::emojiPanHeaderLeft - st::buttonRadius;
|
|
|
|
}
|
|
|
|
|
2019-04-02 13:13:30 +04:00
|
|
|
void StickersListWidget::paintMegagroupEmptySet(Painter &p, int y, bool buttonSelected) {
|
2019-08-16 15:44:20 +03:00
|
|
|
p.setPen(st::emojiPanHeaderFg);
|
|
|
|
|
2017-08-03 14:52:56 +02:00
|
|
|
auto infoLeft = megagroupSetInfoLeft();
|
|
|
|
_megagroupSetAbout.drawLeft(p, infoLeft, y, width() - infoLeft, width());
|
|
|
|
|
2017-11-14 12:15:14 +04:00
|
|
|
auto &textBg = buttonSelected
|
|
|
|
? st::stickerGroupCategoryAdd.textBgOver
|
|
|
|
: st::stickerGroupCategoryAdd.textBg;
|
2017-08-03 14:52:56 +02:00
|
|
|
|
|
|
|
auto button = _megagroupSetButtonRect.translated(0, y);
|
|
|
|
App::roundRect(p, myrtlrect(button), textBg, ImageRoundRadius::Small);
|
|
|
|
if (_megagroupSetButtonRipple) {
|
2019-04-02 13:13:30 +04:00
|
|
|
_megagroupSetButtonRipple->paint(p, button.x(), button.y(), width());
|
2017-08-03 14:52:56 +02:00
|
|
|
if (_megagroupSetButtonRipple->empty()) {
|
|
|
|
_megagroupSetButtonRipple.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p.setFont(st::stickerGroupCategoryAdd.font);
|
|
|
|
p.setPen(buttonSelected ? st::stickerGroupCategoryAdd.textFgOver : st::stickerGroupCategoryAdd.textFg);
|
|
|
|
p.drawTextLeft(button.x() - (st::stickerGroupCategoryAdd.width / 2), button.y() + st::stickerGroupCategoryAdd.textTop, width(), _megagroupSetButtonText, _megagroupSetButtonTextWidth);
|
|
|
|
}
|
|
|
|
|
2019-06-28 16:26:03 +02:00
|
|
|
void StickersListWidget::ensureLottiePlayer(Set &set) {
|
|
|
|
if (set.lottiePlayer) {
|
|
|
|
return;
|
|
|
|
}
|
2019-07-01 17:34:29 +02:00
|
|
|
const auto [i, ok] = _lottieData.emplace(
|
|
|
|
set.id,
|
|
|
|
LottieSet{ std::make_unique<Lottie::MultiPlayer>(
|
2019-07-05 19:15:25 +02:00
|
|
|
Lottie::Quality::Default,
|
2019-07-01 17:34:29 +02:00
|
|
|
getLottieRenderer()) });
|
|
|
|
Assert(ok);
|
|
|
|
const auto raw = set.lottiePlayer = i->second.player.get();
|
|
|
|
|
|
|
|
raw->updates(
|
2019-06-28 16:26:03 +02:00
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
const auto &sets = shownSets();
|
|
|
|
enumerateSections([&](const SectionInfo &info) {
|
2019-07-01 17:34:29 +02:00
|
|
|
if (shownSets()[info.section].lottiePlayer == raw) {
|
2019-06-28 16:26:03 +02:00
|
|
|
update(
|
|
|
|
0,
|
|
|
|
info.rowsTop,
|
|
|
|
width(),
|
|
|
|
info.rowsBottom - info.rowsTop);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2019-07-01 17:34:29 +02:00
|
|
|
},i->second.lifetime);
|
2019-06-28 16:26:03 +02:00
|
|
|
}
|
|
|
|
|
2019-06-25 14:25:02 +02:00
|
|
|
void StickersListWidget::setupLottie(Set &set, int section, int index) {
|
|
|
|
auto &sticker = set.stickers[index];
|
|
|
|
const auto document = sticker.document;
|
|
|
|
|
2019-06-28 16:26:03 +02:00
|
|
|
ensureLottiePlayer(set);
|
|
|
|
sticker.animated = Stickers::LottieAnimationFromDocument(
|
2019-07-01 17:34:29 +02:00
|
|
|
set.lottiePlayer,
|
2019-06-26 19:14:46 +02:00
|
|
|
document,
|
2019-06-28 13:33:47 +02:00
|
|
|
Stickers::LottieSize::StickersPanel,
|
2019-06-26 19:14:46 +02:00
|
|
|
boundingBoxSize() * cIntRetinaFactor());
|
2019-07-01 17:34:29 +02:00
|
|
|
_lottieData[set.id].items.emplace(
|
|
|
|
document->id,
|
|
|
|
LottieSet::Item{ sticker.animated });
|
2019-06-25 14:25:02 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 12:01:04 +02:00
|
|
|
QSize StickersListWidget::boundingBoxSize() const {
|
|
|
|
return QSize(
|
|
|
|
_singleSize.width() - st::buttonRadius * 2,
|
|
|
|
_singleSize.height() - st::buttonRadius * 2);
|
|
|
|
}
|
|
|
|
|
2019-06-25 14:25:02 +02:00
|
|
|
void StickersListWidget::paintSticker(Painter &p, Set &set, int y, int section, int index, bool selected, bool deleteSelected) {
|
|
|
|
auto &sticker = set.stickers[index];
|
|
|
|
const auto document = sticker.document;
|
|
|
|
if (!document->sticker()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (document->sticker()->animated
|
|
|
|
&& !sticker.animated
|
|
|
|
&& document->loaded()) {
|
|
|
|
setupLottie(set, section, index);
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
int row = (index / _columnCount), col = (index % _columnCount);
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
auto pos = QPoint(stickersLeft() + col * _singleSize.width(), y + row * _singleSize.height());
|
2017-03-29 17:04:00 +03:00
|
|
|
if (selected) {
|
|
|
|
auto tl = pos;
|
2017-11-12 13:54:18 +04:00
|
|
|
if (rtl()) tl.setX(width() - tl.x() - _singleSize.width());
|
|
|
|
App::roundRect(p, QRect(tl, _singleSize), st::emojiPanHover, StickerHoverCorners);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2019-01-25 18:37:28 +04:00
|
|
|
document->checkStickerSmall();
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2019-07-19 17:19:13 +02:00
|
|
|
auto w = 1;
|
|
|
|
auto h = 1;
|
|
|
|
if (sticker.animated && !document->dimensions.isEmpty()) {
|
|
|
|
const auto request = Lottie::FrameRequest{ boundingBoxSize() * cIntRetinaFactor() };
|
|
|
|
const auto size = request.size(document->dimensions) / cIntRetinaFactor();
|
|
|
|
w = std::max(size.width(), 1);
|
|
|
|
h = std::max(size.height(), 1);
|
|
|
|
} else {
|
|
|
|
auto coef = qMin((_singleSize.width() - st::buttonRadius * 2) / float64(document->dimensions.width()), (_singleSize.height() - st::buttonRadius * 2) / float64(document->dimensions.height()));
|
|
|
|
if (coef > 1) coef = 1;
|
|
|
|
w = std::max(qRound(coef * document->dimensions.width()), 1);
|
|
|
|
h = std::max(qRound(coef * document->dimensions.height()), 1);
|
|
|
|
}
|
2017-11-12 13:54:18 +04:00
|
|
|
auto ppos = pos + QPoint((_singleSize.width() - w) / 2, (_singleSize.height() - h) / 2);
|
2019-06-25 14:25:02 +02:00
|
|
|
if (sticker.animated && sticker.animated->ready()) {
|
|
|
|
auto request = Lottie::FrameRequest();
|
2019-06-26 12:01:04 +02:00
|
|
|
request.box = boundingBoxSize() * cIntRetinaFactor();
|
2019-06-28 13:33:47 +02:00
|
|
|
const auto frame = sticker.animated->frame(request);
|
2019-06-25 14:25:02 +02:00
|
|
|
p.drawImage(
|
2019-06-28 13:33:47 +02:00
|
|
|
QRect(ppos, frame.size() / cIntRetinaFactor()),
|
|
|
|
frame);
|
2019-07-01 13:20:53 +02:00
|
|
|
|
|
|
|
set.lottiePlayer->unpause(sticker.animated);
|
2019-06-25 14:25:02 +02:00
|
|
|
} else if (const auto image = document->getStickerSmall()) {
|
2017-11-13 21:40:25 +04:00
|
|
|
if (image->loaded()) {
|
|
|
|
p.drawPixmapLeft(
|
|
|
|
ppos,
|
|
|
|
width(),
|
2018-07-14 00:25:47 +03:00
|
|
|
image->pixSingle(
|
|
|
|
document->stickerSetOrigin(),
|
|
|
|
w,
|
|
|
|
h,
|
|
|
|
w,
|
|
|
|
h,
|
|
|
|
ImageRoundRadius::None));
|
2017-11-13 21:40:25 +04:00
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2017-08-03 10:09:33 +02:00
|
|
|
if (selected && stickerHasDeleteButton(set, index)) {
|
2017-11-12 13:54:18 +04:00
|
|
|
auto xPos = pos + QPoint(_singleSize.width() - st::stickerPanDeleteIconBg.width(), 0);
|
2017-09-05 19:34:36 +03:00
|
|
|
p.setOpacity(deleteSelected ? st::stickerPanDeleteOpacityBgOver : st::stickerPanDeleteOpacityBg);
|
|
|
|
st::stickerPanDeleteIconBg.paint(p, xPos, width());
|
|
|
|
p.setOpacity(deleteSelected ? st::stickerPanDeleteOpacityFgOver : st::stickerPanDeleteOpacityFg);
|
|
|
|
st::stickerPanDeleteIconFg.paint(p, xPos, width());
|
|
|
|
p.setOpacity(1.);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
int StickersListWidget::stickersRight() const {
|
2017-11-12 13:54:18 +04:00
|
|
|
return stickersLeft() + (_columnCount * _singleSize.width());
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
bool StickersListWidget::featuredHasAddButton(int index) const {
|
2018-03-02 20:17:33 +03:00
|
|
|
if (index < 0
|
|
|
|
|| index >= shownSets().size()
|
|
|
|
|| !shownSets()[index].externalLayout) {
|
2017-03-29 17:04:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto flags = shownSets()[index].flags;
|
|
|
|
return !SetInMyList(flags);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QRect StickersListWidget::featuredAddRect(int index) const {
|
2017-03-29 18:09:16 +03:00
|
|
|
auto addw = _addWidth - st::stickersTrendingAdd.width;
|
|
|
|
auto addh = st::stickersTrendingAdd.height;
|
|
|
|
auto addx = stickersRight() - addw;
|
2018-03-02 20:17:33 +03:00
|
|
|
auto addy = sectionInfo(index).top + st::stickersTrendingAddTop;
|
2017-03-29 17:04:00 +03:00
|
|
|
return QRect(addx, addy, addw, addh);
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
bool StickersListWidget::hasRemoveButton(int index) const {
|
2018-03-02 20:17:33 +03:00
|
|
|
if (index < 0 || index >= shownSets().size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto &set = shownSets()[index];
|
|
|
|
if (set.externalLayout) {
|
2017-03-29 18:09:16 +03:00
|
|
|
return false;
|
|
|
|
}
|
2017-08-03 14:52:56 +02:00
|
|
|
auto flags = set.flags;
|
|
|
|
if (!(flags & MTPDstickerSet_ClientFlag::f_special)) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-08-05 12:48:21 +02:00
|
|
|
if (set.id == Stickers::MegagroupSetId) {
|
2017-08-17 12:06:26 +03:00
|
|
|
Assert(_megagroupSet != nullptr);
|
2018-03-02 20:17:33 +03:00
|
|
|
if (index + 1 != shownSets().size()) {
|
2017-08-05 22:01:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
2019-06-25 14:25:02 +02:00
|
|
|
return !set.stickers.empty() && _megagroupSet->canEditStickers();
|
2017-08-03 14:52:56 +02:00
|
|
|
}
|
|
|
|
return false;
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QRect StickersListWidget::removeButtonRect(int index) const {
|
|
|
|
auto buttonw = st::stickerPanRemoveSet.width;
|
|
|
|
auto buttonh = st::stickerPanRemoveSet.height;
|
|
|
|
auto buttonx = stickersRight() - buttonw;
|
|
|
|
auto buttony = sectionInfo(index).top + (st::emojiPanHeader - buttonh) / 2;
|
|
|
|
return QRect(buttonx, buttony, buttonw, buttonh);
|
|
|
|
}
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void StickersListWidget::mousePressEvent(QMouseEvent *e) {
|
|
|
|
if (e->button() != Qt::LeftButton) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
_lastMousePosition = e->globalPos();
|
2017-03-29 17:04:00 +03:00
|
|
|
updateSelected();
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
setPressed(_selected);
|
2017-03-29 17:04:00 +03:00
|
|
|
ClickHandler::pressed();
|
2018-11-21 22:14:48 +04:00
|
|
|
_previewTimer.callOnce(QApplication::startDragTime());
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
void StickersListWidget::setPressed(OverState newPressed) {
|
|
|
|
if (auto button = base::get_if<OverButton>(&_pressed)) {
|
|
|
|
auto &sets = shownSets();
|
2017-08-17 12:06:26 +03:00
|
|
|
Assert(button->section >= 0 && button->section < sets.size());
|
2017-03-29 18:09:16 +03:00
|
|
|
auto &set = sets[button->section];
|
2017-03-29 17:04:00 +03:00
|
|
|
if (set.ripple) {
|
|
|
|
set.ripple->lastStop();
|
|
|
|
}
|
2017-08-03 14:52:56 +02:00
|
|
|
} else if (base::get_if<OverGroupAdd>(&_pressed)) {
|
|
|
|
if (_megagroupSetButtonRipple) {
|
|
|
|
_megagroupSetButtonRipple->lastStop();
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
_pressed = newPressed;
|
|
|
|
if (auto button = base::get_if<OverButton>(&_pressed)) {
|
|
|
|
auto &sets = shownSets();
|
2017-08-17 12:06:26 +03:00
|
|
|
Assert(button->section >= 0 && button->section < sets.size());
|
2017-03-29 18:09:16 +03:00
|
|
|
auto &set = sets[button->section];
|
2017-03-29 17:04:00 +03:00
|
|
|
if (!set.ripple) {
|
2017-03-29 18:09:16 +03:00
|
|
|
set.ripple = createButtonRipple(button->section);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
set.ripple->add(mapFromGlobal(QCursor::pos()) - buttonRippleTopLeft(button->section));
|
2017-08-03 14:52:56 +02:00
|
|
|
} else if (base::get_if<OverGroupAdd>(&_pressed)) {
|
|
|
|
if (!_megagroupSetButtonRipple) {
|
|
|
|
auto maskSize = _megagroupSetButtonRect.size();
|
|
|
|
auto mask = Ui::RippleAnimation::roundRectMask(maskSize, st::buttonRadius);
|
|
|
|
_megagroupSetButtonRipple = std::make_unique<Ui::RippleAnimation>(st::stickerGroupCategoryAdd.ripple, std::move(mask), [this] {
|
|
|
|
rtlupdate(megagroupSetButtonRectFinal());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
_megagroupSetButtonRipple->add(mapFromGlobal(QCursor::pos()) - myrtlrect(megagroupSetButtonRectFinal()).topLeft());
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 14:52:56 +02:00
|
|
|
QRect StickersListWidget::megagroupSetButtonRectFinal() const {
|
|
|
|
auto result = QRect();
|
|
|
|
if (_section == Section::Stickers) {
|
|
|
|
enumerateSections([this, &result](const SectionInfo &info) {
|
2018-03-02 20:17:33 +03:00
|
|
|
if (shownSets()[info.section].id == Stickers::MegagroupSetId) {
|
2017-08-03 14:52:56 +02:00
|
|
|
result = _megagroupSetButtonRect.translated(0, info.rowsTop);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-12-18 14:38:14 +04:00
|
|
|
std::unique_ptr<Ui::RippleAnimation> StickersListWidget::createButtonRipple(int section) {
|
2018-03-02 20:17:33 +03:00
|
|
|
Expects(section >= 0 && section < shownSets().size());
|
|
|
|
|
|
|
|
if (shownSets()[section].externalLayout) {
|
2017-03-29 18:09:16 +03:00
|
|
|
auto maskSize = QSize(_addWidth - st::stickersTrendingAdd.width, st::stickersTrendingAdd.height);
|
|
|
|
auto mask = Ui::RippleAnimation::roundRectMask(maskSize, st::buttonRadius);
|
2017-12-18 14:38:14 +04:00
|
|
|
return std::make_unique<Ui::RippleAnimation>(
|
2017-12-18 13:07:18 +04:00
|
|
|
st::stickersTrendingAdd.ripple,
|
|
|
|
std::move(mask),
|
|
|
|
[this, section] { rtlupdate(featuredAddRect(section)); });
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
auto maskSize = QSize(st::stickerPanRemoveSet.rippleAreaSize, st::stickerPanRemoveSet.rippleAreaSize);
|
|
|
|
auto mask = Ui::RippleAnimation::ellipseMask(maskSize);
|
2017-12-18 14:38:14 +04:00
|
|
|
return std::make_unique<Ui::RippleAnimation>(
|
2017-12-18 13:07:18 +04:00
|
|
|
st::stickerPanRemoveSet.ripple,
|
|
|
|
std::move(mask),
|
|
|
|
[this, section] { rtlupdate(removeButtonRect(section)); });
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QPoint StickersListWidget::buttonRippleTopLeft(int section) const {
|
2018-03-02 20:17:33 +03:00
|
|
|
Expects(section >= 0 && section < shownSets().size());
|
|
|
|
|
|
|
|
if (shownSets()[section].externalLayout) {
|
2017-03-29 18:09:16 +03:00
|
|
|
return myrtlrect(featuredAddRect(section)).topLeft();
|
|
|
|
}
|
|
|
|
return myrtlrect(removeButtonRect(section)).topLeft() + st::stickerPanRemoveSet.rippleAreaPosition;
|
|
|
|
}
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) {
|
2018-11-21 22:14:48 +04:00
|
|
|
_previewTimer.cancel();
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
auto pressed = _pressed;
|
2018-09-21 19:28:46 +03:00
|
|
|
setPressed(std::nullopt);
|
2017-03-29 18:09:16 +03:00
|
|
|
if (pressed != _selected) {
|
2017-03-29 17:04:00 +03:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto activated = ClickHandler::unpressed();
|
|
|
|
if (_previewShown) {
|
|
|
|
_previewShown = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
_lastMousePosition = e->globalPos();
|
2017-03-29 17:04:00 +03:00
|
|
|
updateSelected();
|
|
|
|
|
|
|
|
auto &sets = shownSets();
|
2017-08-14 13:38:23 +03:00
|
|
|
if (pressed && pressed == _selected) {
|
2017-03-29 18:09:16 +03:00
|
|
|
if (auto sticker = base::get_if<OverSticker>(&pressed)) {
|
2017-08-17 12:06:26 +03:00
|
|
|
Assert(sticker->section >= 0 && sticker->section < sets.size());
|
2017-03-29 18:09:16 +03:00
|
|
|
auto &set = sets[sticker->section];
|
2019-06-25 14:25:02 +02:00
|
|
|
Assert(sticker->index >= 0 && sticker->index < set.stickers.size());
|
2017-08-03 10:09:33 +02:00
|
|
|
if (stickerHasDeleteButton(set, sticker->index) && sticker->overDelete) {
|
|
|
|
if (set.id == Stickers::RecentSetId) {
|
|
|
|
removeRecentSticker(sticker->section, sticker->index);
|
|
|
|
} else if (set.id == Stickers::FavedSetId) {
|
|
|
|
removeFavedSticker(sticker->section, sticker->index);
|
|
|
|
} else {
|
|
|
|
Unexpected("Single sticker delete click.");
|
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-09-10 00:48:34 +03:00
|
|
|
const auto document = set.stickers[sticker->index].document;
|
|
|
|
if (e->modifiers() & Qt::ControlModifier) {
|
|
|
|
if (document->sticker()
|
|
|
|
&& document->sticker()->set.type() != mtpc_inputStickerSetEmpty) {
|
|
|
|
_displayingSet = true;
|
|
|
|
checkHideWithBox(StickerSetBox::Show(
|
|
|
|
controller(),
|
|
|
|
document));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_chosen.fire_copy(document);
|
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
} else if (auto set = base::get_if<OverSet>(&pressed)) {
|
2017-08-17 12:06:26 +03:00
|
|
|
Assert(set->section >= 0 && set->section < sets.size());
|
2017-04-09 21:06:06 +03:00
|
|
|
displaySet(sets[set->section].id);
|
2017-03-29 18:09:16 +03:00
|
|
|
} else if (auto button = base::get_if<OverButton>(&pressed)) {
|
2017-08-17 12:06:26 +03:00
|
|
|
Assert(button->section >= 0 && button->section < sets.size());
|
2018-03-02 20:17:33 +03:00
|
|
|
if (sets[button->section].externalLayout) {
|
2017-04-09 21:06:06 +03:00
|
|
|
installSet(sets[button->section].id);
|
2017-08-05 12:48:21 +02:00
|
|
|
} else if (sets[button->section].id == Stickers::MegagroupSetId) {
|
2019-06-25 14:25:02 +02:00
|
|
|
auto removeLocally = sets[button->section].stickers.empty()
|
2017-08-05 22:01:20 +02:00
|
|
|
|| !_megagroupSet->canEditStickers();
|
|
|
|
removeMegagroupSet(removeLocally);
|
2017-03-29 18:09:16 +03:00
|
|
|
} else {
|
2017-04-09 21:06:06 +03:00
|
|
|
removeSet(sets[button->section].id);
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
2017-08-03 14:52:56 +02:00
|
|
|
} else if (base::get_if<OverGroupAdd>(&pressed)) {
|
2017-08-05 12:48:21 +02:00
|
|
|
Ui::show(Box<StickersBox>(_megagroupSet));
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::validateSelectedIcon(
|
|
|
|
ValidateIconAnimations animations) {
|
|
|
|
if (_footer) {
|
|
|
|
_footer->validateSelectedIcon(
|
|
|
|
currentSet(getVisibleTop()),
|
|
|
|
animations);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void StickersListWidget::removeRecentSticker(int section, int index) {
|
2017-12-18 14:38:14 +04:00
|
|
|
if ((_section != Section::Stickers)
|
|
|
|
|| (section >= int(_mySets.size()))
|
|
|
|
|| (_mySets[section].id != Stickers::RecentSetId)) {
|
2017-03-29 17:04:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearSelection();
|
|
|
|
bool refresh = false;
|
2019-07-01 17:34:29 +02:00
|
|
|
const auto &sticker = _mySets[section].stickers[index];
|
2019-06-25 14:25:02 +02:00
|
|
|
const auto document = sticker.document;
|
2017-12-11 18:45:29 +04:00
|
|
|
auto &recent = Stickers::GetRecentPack();
|
2017-03-29 17:04:00 +03:00
|
|
|
for (int32 i = 0, l = recent.size(); i < l; ++i) {
|
2019-06-25 14:25:02 +02:00
|
|
|
if (recent.at(i).first == document) {
|
2017-03-29 17:04:00 +03:00
|
|
|
recent.removeAt(i);
|
|
|
|
Local::writeUserSettings();
|
|
|
|
refresh = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-07-24 13:13:51 +02:00
|
|
|
auto &sets = session().data().stickerSetsRef();
|
2017-03-29 17:04:00 +03:00
|
|
|
auto it = sets.find(Stickers::CustomSetId);
|
|
|
|
if (it != sets.cend()) {
|
|
|
|
for (int i = 0, l = it->stickers.size(); i < l; ++i) {
|
2019-06-25 14:25:02 +02:00
|
|
|
if (it->stickers.at(i) == document) {
|
2017-03-29 17:04:00 +03:00
|
|
|
it->stickers.removeAt(i);
|
|
|
|
if (it->stickers.isEmpty()) {
|
|
|
|
sets.erase(it);
|
|
|
|
}
|
|
|
|
Local::writeInstalledStickers();
|
|
|
|
refresh = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (refresh) {
|
|
|
|
refreshRecentStickers();
|
|
|
|
updateSelected();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 10:09:33 +02:00
|
|
|
void StickersListWidget::removeFavedSticker(int section, int index) {
|
2017-12-18 14:38:14 +04:00
|
|
|
if ((_section != Section::Stickers)
|
|
|
|
|| (section >= int(_mySets.size()))
|
|
|
|
|| (_mySets[section].id != Stickers::FavedSetId)) {
|
2017-08-03 10:09:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearSelection();
|
2019-07-01 17:34:29 +02:00
|
|
|
const auto &sticker = _mySets[section].stickers[index];
|
2019-06-25 14:25:02 +02:00
|
|
|
const auto document = sticker.document;
|
|
|
|
Stickers::SetFaved(document, false);
|
2019-07-24 13:13:51 +02:00
|
|
|
session().api().toggleFavedSticker(
|
2019-06-25 14:25:02 +02:00
|
|
|
document,
|
2018-07-16 22:41:43 +03:00
|
|
|
Data::FileOriginStickerSet(Stickers::FavedSetId, 0),
|
|
|
|
false);
|
2017-08-03 10:09:33 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 21:46:20 +04:00
|
|
|
void StickersListWidget::setColumnCount(int count) {
|
2017-11-14 14:26:12 +04:00
|
|
|
Expects(count > 0);
|
|
|
|
|
2017-11-12 21:46:20 +04:00
|
|
|
if (_columnCount != count) {
|
|
|
|
_columnCount = count;
|
|
|
|
refreshFooterIcons();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void StickersListWidget::mouseMoveEvent(QMouseEvent *e) {
|
2017-03-29 18:09:16 +03:00
|
|
|
_lastMousePosition = e->globalPos();
|
2017-03-29 17:04:00 +03:00
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::resizeEvent(QResizeEvent *e) {
|
2017-11-12 13:54:18 +04:00
|
|
|
_settings->moveToLeft(
|
|
|
|
(width() - _settings->width()) / 2,
|
|
|
|
height() / 3);
|
2017-11-14 12:15:14 +04:00
|
|
|
if (!_megagroupSetAbout.isEmpty()) {
|
|
|
|
refreshMegagroupSetGeometry();
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::leaveEventHook(QEvent *e) {
|
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::leaveToChildEvent(QEvent *e, QWidget *child) {
|
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::enterFromChildEvent(QEvent *e, QWidget *child) {
|
2017-03-29 18:09:16 +03:00
|
|
|
_lastMousePosition = QCursor::pos();
|
2017-03-29 17:04:00 +03:00
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::clearSelection() {
|
2018-09-21 19:28:46 +03:00
|
|
|
setPressed(std::nullopt);
|
|
|
|
setSelected(std::nullopt);
|
2017-03-29 17:04:00 +03:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-04-08 18:20:12 +03:00
|
|
|
TabbedSelector::InnerFooter *StickersListWidget::getFooter() const {
|
2017-03-29 18:09:16 +03:00
|
|
|
return _footer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::processHideFinished() {
|
2017-03-29 17:04:00 +03:00
|
|
|
clearSelection();
|
2019-07-01 17:34:29 +02:00
|
|
|
clearLottieData();
|
2019-07-02 13:46:37 +02:00
|
|
|
if (_footer) {
|
|
|
|
_footer->clearLottieData();
|
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::processPanelHideFinished() {
|
|
|
|
clearInstalledLocally();
|
2019-07-01 17:34:29 +02:00
|
|
|
clearLottieData();
|
2019-07-02 13:46:37 +02:00
|
|
|
if (_footer) {
|
|
|
|
_footer->clearLottieData();
|
|
|
|
}
|
2017-05-17 23:59:43 +03:00
|
|
|
// Preserve panel state through visibility toggles.
|
|
|
|
//// Reset to the recent stickers section.
|
|
|
|
//if (_section == Section::Featured && (!_footer || !_footer->hasOnlyFeaturedSets())) {
|
2019-07-01 17:34:29 +02:00
|
|
|
// setSection(Section::Stickers);
|
2017-05-17 23:59:43 +03:00
|
|
|
// validateSelectedIcon(ValidateIconAnimations::None);
|
|
|
|
//}
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2019-07-01 17:34:29 +02:00
|
|
|
void StickersListWidget::setSection(Section section) {
|
|
|
|
if (_section == section) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
clearLottieData();
|
|
|
|
_section = section;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::clearLottieData() {
|
|
|
|
for (auto &set : shownSets()) {
|
|
|
|
destroyLottieIn(set);
|
|
|
|
}
|
|
|
|
_lottieData.clear();
|
|
|
|
}
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void StickersListWidget::refreshStickers() {
|
2017-03-29 18:09:16 +03:00
|
|
|
clearSelection();
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2019-07-01 17:34:29 +02:00
|
|
|
refreshMySets();
|
|
|
|
refreshFeaturedSets();
|
|
|
|
refreshSearchSets();
|
|
|
|
refillLottieData();
|
|
|
|
|
|
|
|
resizeToWidth(width());
|
|
|
|
|
|
|
|
if (_footer) {
|
|
|
|
refreshFooterIcons();
|
|
|
|
}
|
|
|
|
refreshSettingsVisibility();
|
|
|
|
|
|
|
|
_lastMousePosition = QCursor::pos();
|
|
|
|
updateSelected();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::refreshMySets() {
|
2017-03-29 17:04:00 +03:00
|
|
|
_mySets.clear();
|
2017-08-20 09:23:33 +03:00
|
|
|
_favedStickersMap.clear();
|
2019-07-24 13:13:51 +02:00
|
|
|
_mySets.reserve(session().data().stickerSetsOrder().size() + 3);
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-08-02 18:07:28 +03:00
|
|
|
refreshFavedStickers();
|
2017-08-20 09:23:33 +03:00
|
|
|
refreshRecentStickers(false);
|
2017-08-05 16:04:18 +02:00
|
|
|
refreshMegagroupStickers(GroupStickersPlace::Visible);
|
2019-07-24 13:13:51 +02:00
|
|
|
for (const auto setId : session().data().stickerSetsOrder()) {
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto externalLayout = false;
|
|
|
|
appendSet(_mySets, setId, externalLayout, AppendSkip::Archived);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2017-08-05 16:04:18 +02:00
|
|
|
refreshMegagroupStickers(GroupStickersPlace::Hidden);
|
2019-07-01 17:34:29 +02:00
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2019-07-01 17:34:29 +02:00
|
|
|
void StickersListWidget::refreshFeaturedSets() {
|
2017-03-29 17:04:00 +03:00
|
|
|
_featuredSets.clear();
|
2019-07-24 13:13:51 +02:00
|
|
|
_featuredSets.reserve(session().data().featuredStickerSetsOrder().size());
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2019-07-24 13:13:51 +02:00
|
|
|
for (const auto setId : session().data().featuredStickerSetsOrder()) {
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto externalLayout = true;
|
|
|
|
appendSet(_featuredSets, setId, externalLayout, AppendSkip::Installed);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::refreshSearchSets() {
|
|
|
|
refreshSearchIndex();
|
|
|
|
|
2019-07-24 13:13:51 +02:00
|
|
|
const auto &sets = session().data().stickerSets();
|
2018-03-02 20:17:33 +03:00
|
|
|
for (auto &set : _searchSets) {
|
|
|
|
if (const auto it = sets.find(set.id); it != sets.end()) {
|
|
|
|
set.flags = it->flags;
|
|
|
|
if (!it->stickers.empty()) {
|
2019-07-01 17:34:29 +02:00
|
|
|
set.lottiePlayer = nullptr;
|
2019-06-25 14:25:02 +02:00
|
|
|
set.stickers = PrepareStickers(it->stickers);
|
2018-03-02 20:17:33 +03:00
|
|
|
}
|
|
|
|
if (!SetInMyList(set.flags)) {
|
|
|
|
_installedLocallySets.remove(set.id);
|
|
|
|
set.externalLayout = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::refreshSearchIndex() {
|
|
|
|
_searchIndex.clear();
|
|
|
|
for (const auto &set : _mySets) {
|
2018-03-15 02:33:28 +03:00
|
|
|
if (set.flags & MTPDstickerSet_ClientFlag::f_special) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const auto string = set.title + ' ' + set.shortName;
|
|
|
|
const auto list = TextUtilities::PrepareSearchWords(string);
|
2018-03-02 20:17:33 +03:00
|
|
|
_searchIndex.emplace_back(set.id, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-01 17:34:29 +02:00
|
|
|
void StickersListWidget::refillLottieData() {
|
|
|
|
for (auto &set : _lottieData) {
|
|
|
|
set.second.stale = true;
|
|
|
|
}
|
|
|
|
for (auto &set : shownSets()) {
|
|
|
|
refillLottieData(set);
|
|
|
|
}
|
|
|
|
for (auto i = begin(_lottieData); i != end(_lottieData);) {
|
|
|
|
if (i->second.stale) {
|
|
|
|
i = _lottieData.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::refillLottieData(Set &set) {
|
|
|
|
const auto i = _lottieData.find(set.id);
|
|
|
|
if (i == end(_lottieData)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
i->second.stale = true;
|
|
|
|
auto &items = i->second.items;
|
|
|
|
for (auto &item : items) {
|
|
|
|
item.second.stale = true;
|
|
|
|
}
|
|
|
|
for (auto &sticker : set.stickers) {
|
|
|
|
const auto j = items.find(sticker.document->id);
|
|
|
|
if (j != end(items)) {
|
|
|
|
sticker.animated = j->second.animation;
|
|
|
|
i->second.stale = j->second.stale = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i->second.stale) {
|
|
|
|
_lottieData.erase(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (auto j = begin(items); j != end(items);) {
|
|
|
|
if (j->second.stale) {
|
|
|
|
j = items.erase(j);
|
|
|
|
} else {
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set.lottiePlayer = i->second.player.get();
|
|
|
|
}
|
|
|
|
|
2017-11-14 12:15:14 +04:00
|
|
|
void StickersListWidget::refreshSettingsVisibility() {
|
2017-12-18 14:38:14 +04:00
|
|
|
const auto visible = (_section == Section::Stickers) && _mySets.empty();
|
2017-11-14 12:15:14 +04:00
|
|
|
_settings->setVisible(visible);
|
|
|
|
}
|
|
|
|
|
2017-11-12 21:46:20 +04:00
|
|
|
void StickersListWidget::refreshFooterIcons() {
|
|
|
|
_footer->refreshIcons(ValidateIconAnimations::None);
|
|
|
|
if (_footer->hasOnlyFeaturedSets() && _section != Section::Featured) {
|
|
|
|
showStickerSet(Stickers::FeaturedSetId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void StickersListWidget::preloadImages() {
|
|
|
|
auto &sets = shownSets();
|
|
|
|
for (int i = 0, l = sets.size(), k = 0; i < l; ++i) {
|
2019-06-25 14:25:02 +02:00
|
|
|
int count = sets[i].stickers.size();
|
2018-03-02 20:17:33 +03:00
|
|
|
if (sets[i].externalLayout) {
|
2017-11-12 13:54:18 +04:00
|
|
|
accumulate_min(count, _columnCount);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
for (int j = 0; j != count; ++j) {
|
2017-11-12 13:54:18 +04:00
|
|
|
if (++k > _columnCount * (_columnCount + 1)) break;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2019-06-25 14:25:02 +02:00
|
|
|
const auto document = sets[i].stickers[j].document;
|
2018-07-14 00:25:47 +03:00
|
|
|
if (!document || !document->sticker()) continue;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2019-01-25 18:37:28 +04:00
|
|
|
document->checkStickerSmall();
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2017-11-12 13:54:18 +04:00
|
|
|
if (k > _columnCount * (_columnCount + 1)) break;
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
if (_footer) {
|
|
|
|
_footer->preloadImages();
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64 StickersListWidget::currentSet(int yOffset) const {
|
|
|
|
if (_section == Section::Featured) {
|
|
|
|
return Stickers::FeaturedSetId;
|
|
|
|
}
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto &sets = shownSets();
|
|
|
|
return sets.empty()
|
2017-12-18 14:38:14 +04:00
|
|
|
? Stickers::RecentSetId
|
2018-03-02 20:17:33 +03:00
|
|
|
: sets[sectionInfoByOffset(yOffset).section].id;
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2017-12-18 14:38:14 +04:00
|
|
|
void StickersListWidget::appendSet(
|
|
|
|
std::vector<Set> &to,
|
|
|
|
uint64 setId,
|
2018-03-02 20:17:33 +03:00
|
|
|
bool externalLayout,
|
2017-12-18 14:38:14 +04:00
|
|
|
AppendSkip skip) {
|
2019-07-24 13:13:51 +02:00
|
|
|
auto &sets = session().data().stickerSets();
|
2017-03-29 17:04:00 +03:00
|
|
|
auto it = sets.constFind(setId);
|
2018-01-25 15:28:48 +03:00
|
|
|
if (it == sets.cend() || it->stickers.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((skip == AppendSkip::Archived)
|
|
|
|
&& (it->flags & MTPDstickerSet::Flag::f_archived)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((skip == AppendSkip::Installed)
|
|
|
|
&& (it->flags & MTPDstickerSet::Flag::f_installed_date)
|
|
|
|
&& !(it->flags & MTPDstickerSet::Flag::f_archived)) {
|
2017-03-29 17:04:00 +03:00
|
|
|
if (!_installedLocallySets.contains(setId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-22 13:24:56 +04:00
|
|
|
to.emplace_back(
|
2018-01-25 15:28:48 +03:00
|
|
|
it->id,
|
|
|
|
it->flags,
|
|
|
|
it->title,
|
2018-03-08 14:37:01 +03:00
|
|
|
it->shortName,
|
2019-03-22 13:24:56 +04:00
|
|
|
it->thumbnail,
|
2018-03-02 20:17:33 +03:00
|
|
|
externalLayout,
|
2018-03-08 14:12:30 +03:00
|
|
|
it->count,
|
2019-06-25 14:25:02 +02:00
|
|
|
PrepareStickers(it->stickers));
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::refreshRecent() {
|
|
|
|
if (_section == Section::Stickers) {
|
|
|
|
refreshRecentStickers();
|
|
|
|
}
|
2017-04-24 18:59:54 +03:00
|
|
|
if (_footer && _footer->hasOnlyFeaturedSets() && _section != Section::Featured) {
|
|
|
|
showStickerSet(Stickers::FeaturedSetId);
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2019-06-25 14:25:02 +02:00
|
|
|
auto StickersListWidget::collectRecentStickers() -> std::vector<Sticker> {
|
2017-03-29 17:04:00 +03:00
|
|
|
_custom.clear();
|
2019-06-25 14:25:02 +02:00
|
|
|
auto result = std::vector<Sticker>();
|
2018-03-07 15:04:05 +03:00
|
|
|
|
2019-07-24 13:13:51 +02:00
|
|
|
const auto &sets = session().data().stickerSets();
|
2019-06-25 14:25:02 +02:00
|
|
|
const auto &recent = Stickers::GetRecentPack();
|
|
|
|
const auto customIt = sets.constFind(Stickers::CustomSetId);
|
|
|
|
const auto cloudIt = sets.constFind(Stickers::CloudRecentSetId);
|
2018-03-07 15:04:05 +03:00
|
|
|
const auto customCount = (customIt != sets.cend())
|
|
|
|
? customIt->stickers.size()
|
|
|
|
: 0;
|
|
|
|
const auto cloudCount = (cloudIt != sets.cend())
|
|
|
|
? cloudIt->stickers.size()
|
|
|
|
: 0;
|
|
|
|
result.reserve(cloudCount + recent.size() + customCount);
|
|
|
|
_custom.reserve(cloudCount + recent.size() + customCount);
|
2017-08-20 09:23:33 +03:00
|
|
|
|
2018-03-07 15:04:05 +03:00
|
|
|
auto add = [&](not_null<DocumentData*> document, bool custom) {
|
|
|
|
if (result.size() >= kRecentDisplayLimit) {
|
|
|
|
return;
|
|
|
|
}
|
2019-06-25 14:25:02 +02:00
|
|
|
const auto i = ranges::find(result, document, &Sticker::document);
|
|
|
|
if (i != end(result)) {
|
|
|
|
const auto index = (i - begin(result));
|
2018-03-07 15:04:05 +03:00
|
|
|
if (index >= cloudCount && custom) {
|
|
|
|
// Mark stickers from local recent as custom.
|
|
|
|
_custom[index] = true;
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2018-03-07 15:04:05 +03:00
|
|
|
} else if (!_favedStickersMap.contains(document)) {
|
2019-06-25 14:25:02 +02:00
|
|
|
result.push_back(Sticker{ document });
|
2018-03-07 15:04:05 +03:00
|
|
|
_custom.push_back(custom);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (cloudCount > 0) {
|
2019-06-25 14:25:02 +02:00
|
|
|
for (const auto document : cloudIt->stickers) {
|
2018-03-07 15:04:05 +03:00
|
|
|
add(document, false);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2017-08-20 09:23:33 +03:00
|
|
|
}
|
2019-06-25 14:25:02 +02:00
|
|
|
for (const auto &recentSticker : recent) {
|
2018-03-07 15:04:05 +03:00
|
|
|
add(recentSticker.first, false);
|
2017-08-20 09:23:33 +03:00
|
|
|
}
|
2018-03-07 15:04:05 +03:00
|
|
|
if (customCount > 0) {
|
2019-06-25 14:25:02 +02:00
|
|
|
for (const auto document : customIt->stickers) {
|
2018-03-07 15:04:05 +03:00
|
|
|
add(document, true);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2017-08-20 09:23:33 +03:00
|
|
|
}
|
2018-03-07 15:04:05 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::refreshRecentStickers(bool performResize) {
|
|
|
|
clearSelection();
|
|
|
|
|
|
|
|
auto recentPack = collectRecentStickers();
|
2017-08-20 09:23:33 +03:00
|
|
|
auto recentIt = std::find_if(_mySets.begin(), _mySets.end(), [](auto &set) {
|
|
|
|
return set.id == Stickers::RecentSetId;
|
|
|
|
});
|
|
|
|
if (!recentPack.empty()) {
|
|
|
|
if (recentIt == _mySets.end()) {
|
2018-03-08 14:37:01 +03:00
|
|
|
const auto shortName = QString();
|
2019-03-22 13:24:56 +04:00
|
|
|
const auto thumbnail = ImagePtr();
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto externalLayout = false;
|
2019-03-22 13:24:56 +04:00
|
|
|
_mySets.emplace_back(
|
2018-03-02 20:17:33 +03:00
|
|
|
Stickers::RecentSetId,
|
|
|
|
(MTPDstickerSet::Flag::f_official
|
|
|
|
| MTPDstickerSet_ClientFlag::f_special),
|
2019-06-19 17:09:03 +02:00
|
|
|
tr::lng_recent_stickers(tr::now),
|
2018-03-08 14:37:01 +03:00
|
|
|
shortName,
|
2019-03-22 13:24:56 +04:00
|
|
|
thumbnail,
|
2018-03-02 20:17:33 +03:00
|
|
|
externalLayout,
|
2018-03-08 14:12:30 +03:00
|
|
|
recentPack.size(),
|
2019-06-25 14:25:02 +02:00
|
|
|
std::move(recentPack));
|
2017-03-29 17:04:00 +03:00
|
|
|
} else {
|
2019-07-01 17:34:29 +02:00
|
|
|
recentIt->lottiePlayer = nullptr;
|
2019-06-25 14:25:02 +02:00
|
|
|
recentIt->stickers = std::move(recentPack);
|
2019-07-01 17:34:29 +02:00
|
|
|
refillLottieData(*recentIt);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2017-08-20 09:23:33 +03:00
|
|
|
} else if (recentIt != _mySets.end()) {
|
2019-07-01 17:34:29 +02:00
|
|
|
_lottieData.remove(recentIt->id);
|
2017-08-20 09:23:33 +03:00
|
|
|
_mySets.erase(recentIt);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (performResize && (_section == Section::Stickers || _section == Section::Featured)) {
|
2017-11-12 13:54:18 +04:00
|
|
|
resizeToWidth(width());
|
2017-03-29 17:04:00 +03:00
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 18:07:28 +03:00
|
|
|
void StickersListWidget::refreshFavedStickers() {
|
|
|
|
clearSelection();
|
2019-07-24 13:13:51 +02:00
|
|
|
auto &sets = session().data().stickerSets();
|
2017-08-02 22:57:49 +02:00
|
|
|
auto it = sets.constFind(Stickers::FavedSetId);
|
2017-08-02 18:07:28 +03:00
|
|
|
if (it == sets.cend() || it->stickers.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto externalLayout = false;
|
2018-03-08 14:37:01 +03:00
|
|
|
const auto shortName = QString();
|
2019-03-22 13:24:56 +04:00
|
|
|
const auto thumbnail = ImagePtr();
|
|
|
|
_mySets.emplace_back(
|
2018-03-02 20:17:33 +03:00
|
|
|
Stickers::FavedSetId,
|
|
|
|
(MTPDstickerSet::Flag::f_official
|
|
|
|
| MTPDstickerSet_ClientFlag::f_special),
|
|
|
|
Lang::Hard::FavedSetTitle(),
|
2018-03-08 14:37:01 +03:00
|
|
|
shortName,
|
2019-03-22 13:24:56 +04:00
|
|
|
thumbnail,
|
2018-03-02 20:17:33 +03:00
|
|
|
externalLayout,
|
2018-03-08 14:12:30 +03:00
|
|
|
it->count,
|
2019-06-25 14:25:02 +02:00
|
|
|
PrepareStickers(it->stickers));
|
2017-08-20 09:23:33 +03:00
|
|
|
_favedStickersMap = base::flat_set<not_null<DocumentData*>> { it->stickers.begin(), it->stickers.end() };
|
2017-08-02 18:07:28 +03:00
|
|
|
}
|
|
|
|
|
2017-08-05 16:04:18 +02:00
|
|
|
void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) {
|
2017-08-03 14:52:56 +02:00
|
|
|
if (!_megagroupSet) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-05 22:01:20 +02:00
|
|
|
auto canEdit = _megagroupSet->canEditStickers();
|
|
|
|
auto isShownHere = [place](bool hidden) {
|
|
|
|
return (hidden == (place == GroupStickersPlace::Hidden));
|
|
|
|
};
|
2017-08-03 14:52:56 +02:00
|
|
|
if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetEmpty) {
|
2017-08-05 22:01:20 +02:00
|
|
|
if (canEdit) {
|
2019-07-24 13:13:51 +02:00
|
|
|
auto hidden = session().settings().isGroupStickersSectionHidden(_megagroupSet->id);
|
2017-08-05 22:01:20 +02:00
|
|
|
if (isShownHere(hidden)) {
|
2018-03-08 14:37:01 +03:00
|
|
|
const auto shortName = QString();
|
2019-03-22 13:24:56 +04:00
|
|
|
const auto thumbnail = ImagePtr();
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto externalLayout = false;
|
2018-03-08 14:12:30 +03:00
|
|
|
const auto count = 0;
|
2019-03-22 13:24:56 +04:00
|
|
|
_mySets.emplace_back(
|
2018-03-02 20:17:33 +03:00
|
|
|
Stickers::MegagroupSetId,
|
|
|
|
MTPDstickerSet_ClientFlag::f_special | 0,
|
2019-06-19 17:09:03 +02:00
|
|
|
tr::lng_group_stickers(tr::now),
|
2019-03-22 13:24:56 +04:00
|
|
|
shortName,
|
|
|
|
thumbnail,
|
2018-03-08 14:12:30 +03:00
|
|
|
externalLayout,
|
2019-03-22 13:24:56 +04:00
|
|
|
count);
|
2017-08-05 16:04:18 +02:00
|
|
|
}
|
2017-08-03 14:52:56 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-07-24 13:13:51 +02:00
|
|
|
auto hidden = session().settings().isGroupStickersSectionHidden(_megagroupSet->id);
|
2017-08-05 22:01:20 +02:00
|
|
|
auto removeHiddenForGroup = [this, &hidden] {
|
|
|
|
if (hidden) {
|
2019-07-24 13:13:51 +02:00
|
|
|
session().settings().removeGroupStickersSectionHidden(_megagroupSet->id);
|
2017-08-05 22:01:20 +02:00
|
|
|
Local::writeUserSettings();
|
|
|
|
hidden = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (canEdit && hidden) {
|
|
|
|
removeHiddenForGroup();
|
2017-08-05 16:04:18 +02:00
|
|
|
}
|
2019-03-26 10:38:54 +04:00
|
|
|
if (_megagroupSet->mgInfo->stickerSet.type() != mtpc_inputStickerSetID) {
|
|
|
|
return;
|
2017-08-03 14:52:56 +02:00
|
|
|
}
|
2019-03-26 10:38:54 +04:00
|
|
|
auto &set = _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID();
|
2019-07-24 13:13:51 +02:00
|
|
|
auto &sets = session().data().stickerSets();
|
2019-07-05 15:38:38 +02:00
|
|
|
auto it = sets.constFind(set.vid().v);
|
2019-03-26 10:38:54 +04:00
|
|
|
if (it != sets.cend()) {
|
|
|
|
auto isInstalled = (it->flags & MTPDstickerSet::Flag::f_installed_date)
|
|
|
|
&& !(it->flags & MTPDstickerSet::Flag::f_archived);
|
|
|
|
if (isInstalled && !canEdit) {
|
|
|
|
removeHiddenForGroup();
|
|
|
|
} else if (isShownHere(hidden)) {
|
|
|
|
const auto shortName = QString();
|
|
|
|
const auto thumbnail = ImagePtr();
|
|
|
|
const auto externalLayout = false;
|
|
|
|
_mySets.emplace_back(
|
|
|
|
Stickers::MegagroupSetId,
|
|
|
|
MTPDstickerSet_ClientFlag::f_special | 0,
|
2019-06-19 17:09:03 +02:00
|
|
|
tr::lng_group_stickers(tr::now),
|
2019-03-26 10:38:54 +04:00
|
|
|
shortName,
|
|
|
|
thumbnail,
|
|
|
|
externalLayout,
|
|
|
|
it->count,
|
2019-06-25 14:25:02 +02:00
|
|
|
PrepareStickers(it->stickers));
|
2019-03-26 10:38:54 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if (!isShownHere(hidden)
|
2019-07-05 15:38:38 +02:00
|
|
|
|| _megagroupSetIdRequested == set.vid().v) {
|
2017-08-05 22:01:20 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-07-05 15:38:38 +02:00
|
|
|
_megagroupSetIdRequested = set.vid().v;
|
2019-03-26 10:38:54 +04:00
|
|
|
request(MTPmessages_GetStickerSet(
|
|
|
|
_megagroupSet->mgInfo->stickerSet
|
|
|
|
)).done([=](const MTPmessages_StickerSet &result) {
|
|
|
|
if (const auto set = Stickers::FeedSetFull(result)) {
|
2017-08-03 14:52:56 +02:00
|
|
|
refreshStickers();
|
2019-03-26 10:38:54 +04:00
|
|
|
if (set->id == _megagroupSetIdRequested) {
|
|
|
|
_megagroupSetIdRequested = 0;
|
|
|
|
} else {
|
|
|
|
LOG(("API Error: Got different set."));
|
|
|
|
}
|
2017-08-03 14:52:56 +02:00
|
|
|
}
|
2017-08-05 22:01:20 +02:00
|
|
|
}).send();
|
2017-08-03 14:52:56 +02:00
|
|
|
}
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void StickersListWidget::fillIcons(QList<StickerIcon> &icons) {
|
|
|
|
icons.clear();
|
|
|
|
icons.reserve(_mySets.size() + 1);
|
2019-07-24 13:13:51 +02:00
|
|
|
if (session().data().featuredStickerSetsUnreadCount()
|
2018-03-02 20:17:33 +03:00
|
|
|
&& !_featuredSets.empty()) {
|
2017-03-29 17:04:00 +03:00
|
|
|
icons.push_back(StickerIcon(Stickers::FeaturedSetId));
|
|
|
|
}
|
|
|
|
|
2017-08-02 18:19:11 +03:00
|
|
|
auto i = 0;
|
|
|
|
if (i != _mySets.size() && _mySets[i].id == Stickers::FavedSetId) {
|
|
|
|
++i;
|
|
|
|
icons.push_back(StickerIcon(Stickers::FavedSetId));
|
|
|
|
}
|
2017-08-20 09:23:33 +03:00
|
|
|
if (i != _mySets.size() && _mySets[i].id == Stickers::RecentSetId) {
|
|
|
|
++i;
|
2018-06-03 20:58:28 +03:00
|
|
|
if (icons.empty() || icons.back().setId != Stickers::FavedSetId) {
|
2018-03-08 15:12:20 +03:00
|
|
|
icons.push_back(StickerIcon(Stickers::RecentSetId));
|
|
|
|
}
|
2017-08-20 09:23:33 +03:00
|
|
|
}
|
2017-08-02 18:19:11 +03:00
|
|
|
for (auto l = _mySets.size(); i != l; ++i) {
|
2017-08-05 12:48:21 +02:00
|
|
|
if (_mySets[i].id == Stickers::MegagroupSetId) {
|
|
|
|
icons.push_back(StickerIcon(Stickers::MegagroupSetId));
|
2017-08-03 14:52:56 +02:00
|
|
|
icons.back().megagroup = _megagroupSet;
|
|
|
|
continue;
|
|
|
|
}
|
2019-03-22 13:24:56 +04:00
|
|
|
const auto thumbnail = _mySets[i].thumbnail;
|
2019-06-25 14:25:02 +02:00
|
|
|
const auto s = _mySets[i].stickers[0].document;
|
2019-03-22 13:24:56 +04:00
|
|
|
const auto availw = st::stickerIconWidth - 2 * st::stickerIconPadding;
|
|
|
|
const auto availh = st::emojiFooterHeight - 2 * st::stickerIconPadding;
|
|
|
|
const auto size = thumbnail
|
|
|
|
? thumbnail->size()
|
|
|
|
: s->hasThumbnail()
|
2019-01-25 18:37:28 +04:00
|
|
|
? s->thumbnail()->size()
|
|
|
|
: QSize();
|
|
|
|
auto thumbw = size.width(), thumbh = size.height(), pixw = 1, pixh = 1;
|
2017-08-02 18:19:11 +03:00
|
|
|
if (availw * thumbh > availh * thumbw) {
|
|
|
|
pixh = availh;
|
|
|
|
pixw = (pixh * thumbw) / thumbh;
|
|
|
|
} else {
|
|
|
|
pixw = availw;
|
|
|
|
pixh = thumbw ? ((pixw * thumbh) / thumbw) : 1;
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2017-08-02 18:19:11 +03:00
|
|
|
if (pixw < 1) pixw = 1;
|
|
|
|
if (pixh < 1) pixh = 1;
|
2019-03-22 13:24:56 +04:00
|
|
|
icons.push_back(StickerIcon(
|
|
|
|
_mySets[i].id,
|
|
|
|
thumbnail,
|
|
|
|
s,
|
|
|
|
pixw,
|
|
|
|
pixh));
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2019-07-24 13:13:51 +02:00
|
|
|
if (!session().data().featuredStickerSetsUnreadCount()
|
2017-12-18 14:38:14 +04:00
|
|
|
&& !_featuredSets.empty()) {
|
2017-03-29 17:04:00 +03:00
|
|
|
icons.push_back(StickerIcon(Stickers::FeaturedSetId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
bool StickersListWidget::preventAutoHide() {
|
2019-09-10 00:48:34 +03:00
|
|
|
return _removingSetId != 0 || _displayingSet != 0;
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void StickersListWidget::updateSelected() {
|
2017-08-14 13:38:23 +03:00
|
|
|
if (_pressed && !_previewShown) {
|
2017-03-29 17:04:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-21 19:28:46 +03:00
|
|
|
auto newSelected = OverState { std::nullopt };
|
2017-03-29 18:09:16 +03:00
|
|
|
auto p = mapFromGlobal(_lastMousePosition);
|
|
|
|
if (!rect().contains(p)
|
|
|
|
|| p.y() < getVisibleTop() || p.y() >= getVisibleBottom()
|
|
|
|
|| !isVisible()) {
|
|
|
|
clearSelection();
|
|
|
|
return;
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
auto &sets = shownSets();
|
|
|
|
auto sx = (rtl() ? width() - p.x() : p.x()) - stickersLeft();
|
2018-03-02 20:17:33 +03:00
|
|
|
if (!shownSets().empty()) {
|
2017-03-29 17:04:00 +03:00
|
|
|
auto info = sectionInfoByOffset(p.y());
|
2017-03-29 18:09:16 +03:00
|
|
|
auto section = info.section;
|
2017-03-29 17:04:00 +03:00
|
|
|
if (p.y() >= info.top && p.y() < info.rowsTop) {
|
2017-03-29 18:09:16 +03:00
|
|
|
if (hasRemoveButton(section) && myrtlrect(removeButtonRect(section)).contains(p.x(), p.y())) {
|
|
|
|
newSelected = OverButton { section };
|
2018-03-02 20:17:33 +03:00
|
|
|
} else if (featuredHasAddButton(section) && myrtlrect(featuredAddRect(section)).contains(p.x(), p.y())) {
|
|
|
|
newSelected = OverButton{ section };
|
2017-08-03 14:52:56 +02:00
|
|
|
} else if (!(sets[section].flags & MTPDstickerSet_ClientFlag::f_special)) {
|
2017-03-29 18:09:16 +03:00
|
|
|
newSelected = OverSet { section };
|
2017-08-05 22:01:20 +02:00
|
|
|
} else if (sets[section].id == Stickers::MegagroupSetId
|
2019-06-25 14:25:02 +02:00
|
|
|
&& (_megagroupSet->canEditStickers() || !sets[section].stickers.empty())) {
|
2017-08-05 22:01:20 +02:00
|
|
|
newSelected = OverSet { section };
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
} else if (p.y() >= info.rowsTop && p.y() < info.rowsBottom && sx >= 0) {
|
|
|
|
auto yOffset = p.y() - info.rowsTop;
|
2017-03-29 18:09:16 +03:00
|
|
|
auto &set = sets[section];
|
2019-06-25 14:25:02 +02:00
|
|
|
if (set.id == Stickers::MegagroupSetId && set.stickers.empty()) {
|
2017-08-03 14:52:56 +02:00
|
|
|
if (_megagroupSetButtonRect.contains(stickersLeft() + sx, yOffset)) {
|
|
|
|
newSelected = OverGroupAdd {};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
auto special = ((set.flags & MTPDstickerSet::Flag::f_official) != 0);
|
2017-11-12 13:54:18 +04:00
|
|
|
auto rowIndex = qFloor(yOffset / _singleSize.height());
|
|
|
|
auto columnIndex = qFloor(sx / _singleSize.width());
|
|
|
|
auto index = rowIndex * _columnCount + columnIndex;
|
2019-06-25 14:25:02 +02:00
|
|
|
if (index >= 0 && index < set.stickers.size()) {
|
2017-08-03 14:52:56 +02:00
|
|
|
auto overDelete = false;
|
|
|
|
if (stickerHasDeleteButton(set, index)) {
|
2017-11-12 13:54:18 +04:00
|
|
|
auto inx = sx - (columnIndex * _singleSize.width());
|
|
|
|
auto iny = yOffset - (rowIndex * _singleSize.height());
|
|
|
|
if (inx >= _singleSize.width() - st::stickerPanDeleteIconBg.width() && iny < st::stickerPanDeleteIconBg.height()) {
|
2017-08-03 14:52:56 +02:00
|
|
|
overDelete = true;
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2017-08-03 14:52:56 +02:00
|
|
|
newSelected = OverSticker { section, index, overDelete };
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
setSelected(newSelected);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2017-08-03 10:09:33 +02:00
|
|
|
bool StickersListWidget::setHasTitle(const Set &set) const {
|
2017-08-20 09:23:33 +03:00
|
|
|
if (set.id == Stickers::FavedSetId) {
|
|
|
|
return false;
|
|
|
|
} else if (set.id == Stickers::RecentSetId) {
|
|
|
|
return !_mySets.empty() && _mySets[0].id == Stickers::FavedSetId;
|
|
|
|
}
|
|
|
|
return true;
|
2017-08-03 10:09:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool StickersListWidget::stickerHasDeleteButton(const Set &set, int index) const {
|
|
|
|
if (set.id == Stickers::RecentSetId) {
|
2017-08-17 12:06:26 +03:00
|
|
|
Assert(index >= 0 && index < _custom.size());
|
2017-08-03 10:09:33 +02:00
|
|
|
return _custom[index];
|
|
|
|
}
|
|
|
|
return (set.id == Stickers::FavedSetId);
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
void StickersListWidget::setSelected(OverState newSelected) {
|
2017-03-29 17:04:00 +03:00
|
|
|
if (_selected != newSelected) {
|
2017-08-14 13:38:23 +03:00
|
|
|
setCursor(newSelected ? style::cur_pointer : style::cur_default);
|
2017-03-29 18:09:16 +03:00
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
auto &sets = shownSets();
|
2018-03-02 20:17:33 +03:00
|
|
|
auto updateSelected = [&]() {
|
2017-03-29 18:09:16 +03:00
|
|
|
if (auto sticker = base::get_if<OverSticker>(&_selected)) {
|
|
|
|
rtlupdate(stickerRect(sticker->section, sticker->index));
|
|
|
|
} else if (auto button = base::get_if<OverButton>(&_selected)) {
|
2018-03-02 20:17:33 +03:00
|
|
|
if (button->section >= 0
|
|
|
|
&& button->section < sets.size()
|
|
|
|
&& sets[button->section].externalLayout) {
|
2017-03-29 18:09:16 +03:00
|
|
|
rtlupdate(featuredAddRect(button->section));
|
|
|
|
} else {
|
2017-05-03 16:56:14 +03:00
|
|
|
rtlupdate(removeButtonRect(button->section));
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
2017-11-14 12:15:14 +04:00
|
|
|
} else if (base::get_if<OverGroupAdd>(&_selected)) {
|
|
|
|
rtlupdate(megagroupSetButtonRectFinal());
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
updateSelected();
|
|
|
|
_selected = newSelected;
|
|
|
|
updateSelected();
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
if (_previewShown && _pressed != _selected) {
|
2019-06-25 14:25:02 +02:00
|
|
|
if (const auto sticker = base::get_if<OverSticker>(&_selected)) {
|
2017-03-29 18:09:16 +03:00
|
|
|
_pressed = _selected;
|
2017-08-17 12:06:26 +03:00
|
|
|
Assert(sticker->section >= 0 && sticker->section < sets.size());
|
2019-06-25 14:25:02 +02:00
|
|
|
const auto &set = sets[sticker->section];
|
|
|
|
Assert(sticker->index >= 0 && sticker->index < set.stickers.size());
|
|
|
|
const auto document = set.stickers[sticker->index].document;
|
2019-06-29 13:29:04 +03:00
|
|
|
if (const auto w = App::wnd()) {
|
|
|
|
w->showMediaPreview(document->stickerSetOrigin(), document);
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
void StickersListWidget::showPreview() {
|
|
|
|
if (const auto sticker = base::get_if<OverSticker>(&_pressed)) {
|
|
|
|
const auto &sets = shownSets();
|
2017-08-17 12:06:26 +03:00
|
|
|
Assert(sticker->section >= 0 && sticker->section < sets.size());
|
2018-11-21 22:14:48 +04:00
|
|
|
const auto &set = sets[sticker->section];
|
2019-06-25 14:25:02 +02:00
|
|
|
Assert(sticker->index >= 0 && sticker->index < set.stickers.size());
|
|
|
|
const auto document = set.stickers[sticker->index].document;
|
2019-06-29 13:29:04 +03:00
|
|
|
if (const auto w = App::wnd()) {
|
|
|
|
w->showMediaPreview(document->stickerSetOrigin(), document);
|
|
|
|
_previewShown = true;
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-28 16:26:03 +02:00
|
|
|
auto StickersListWidget::getLottieRenderer()
|
|
|
|
-> std::shared_ptr<Lottie::FrameRenderer> {
|
|
|
|
if (auto result = _lottieRenderer.lock()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
auto result = Lottie::MakeFrameRenderer();
|
|
|
|
_lottieRenderer = result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void StickersListWidget::showStickerSet(uint64 setId) {
|
|
|
|
clearSelection();
|
|
|
|
|
|
|
|
if (setId == Stickers::FeaturedSetId) {
|
|
|
|
if (_section != Section::Featured) {
|
2019-07-01 17:34:29 +02:00
|
|
|
setSection(Section::Featured);
|
2017-03-29 17:04:00 +03:00
|
|
|
refreshRecentStickers(true);
|
2017-11-14 12:15:14 +04:00
|
|
|
refreshSettingsVisibility();
|
2017-03-29 18:09:16 +03:00
|
|
|
if (_footer) {
|
|
|
|
_footer->refreshIcons(ValidateIconAnimations::Scroll);
|
|
|
|
}
|
2017-03-29 17:04:00 +03:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
scrollTo(0);
|
|
|
|
_scrollUpdated.fire({});
|
2017-03-29 17:04:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto needRefresh = (_section != Section::Stickers);
|
|
|
|
if (needRefresh) {
|
2019-07-01 17:34:29 +02:00
|
|
|
setSection(Section::Stickers);
|
2017-03-29 17:04:00 +03:00
|
|
|
refreshRecentStickers(true);
|
2017-11-14 12:15:14 +04:00
|
|
|
refreshSettingsVisibility();
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
auto y = 0;
|
|
|
|
enumerateSections([this, setId, &y](const SectionInfo &info) {
|
2018-03-02 20:17:33 +03:00
|
|
|
if (shownSets()[info.section].id == setId) {
|
2017-03-29 17:04:00 +03:00
|
|
|
y = info.top;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2018-11-21 22:14:48 +04:00
|
|
|
scrollTo(y);
|
|
|
|
_scrollUpdated.fire({});
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
if (needRefresh && _footer) {
|
|
|
|
_footer->refreshIcons(ValidateIconAnimations::Scroll);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
_lastMousePosition = QCursor::pos();
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-08-03 14:52:56 +02:00
|
|
|
void StickersListWidget::refreshMegagroupSetGeometry() {
|
|
|
|
auto left = megagroupSetInfoLeft();
|
|
|
|
auto availableWidth = (width() - left);
|
|
|
|
auto top = _megagroupSetAbout.countHeight(availableWidth) + st::stickerGroupCategoryAddMargin.top();
|
|
|
|
_megagroupSetButtonTextWidth = st::stickerGroupCategoryAdd.font->width(_megagroupSetButtonText);
|
|
|
|
auto buttonWidth = _megagroupSetButtonTextWidth - st::stickerGroupCategoryAdd.width;
|
|
|
|
_megagroupSetButtonRect = QRect(left, top, buttonWidth, st::stickerGroupCategoryAdd.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::showMegagroupSet(ChannelData *megagroup) {
|
|
|
|
Expects(!megagroup || megagroup->isMegagroup());
|
2018-03-02 20:17:33 +03:00
|
|
|
|
2017-08-03 14:52:56 +02:00
|
|
|
if (_megagroupSet != megagroup) {
|
|
|
|
_megagroupSet = megagroup;
|
|
|
|
|
|
|
|
if (_megagroupSetAbout.isEmpty()) {
|
2017-11-14 12:15:14 +04:00
|
|
|
_megagroupSetAbout.setText(
|
|
|
|
st::stickerGroupCategoryAbout,
|
2019-06-19 17:09:03 +02:00
|
|
|
tr::lng_group_stickers_description(tr::now));
|
|
|
|
_megagroupSetButtonText = tr::lng_group_stickers_add(tr::now).toUpper();
|
2017-08-03 14:52:56 +02:00
|
|
|
refreshMegagroupSetGeometry();
|
|
|
|
}
|
|
|
|
_megagroupSetButtonRipple.reset();
|
|
|
|
|
|
|
|
refreshStickers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::afterShown() {
|
|
|
|
if (_footer) {
|
|
|
|
_footer->stealFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::beforeHiding() {
|
|
|
|
if (_footer) {
|
|
|
|
_footer->returnFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-05 12:48:21 +02:00
|
|
|
void StickersListWidget::displaySet(uint64 setId) {
|
2017-08-05 22:01:20 +02:00
|
|
|
if (setId == Stickers::MegagroupSetId) {
|
|
|
|
if (_megagroupSet->canEditStickers()) {
|
2019-09-10 00:48:34 +03:00
|
|
|
_displayingSet = true;
|
|
|
|
checkHideWithBox(Ui::show(
|
|
|
|
Box<StickersBox>(_megagroupSet),
|
|
|
|
LayerOption::KeepOther).data());
|
2017-08-05 22:01:20 +02:00
|
|
|
return;
|
|
|
|
} else if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) {
|
2019-07-05 15:38:38 +02:00
|
|
|
setId = _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID().vid().v;
|
2017-08-05 22:01:20 +02:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-07-24 13:13:51 +02:00
|
|
|
auto &sets = session().data().stickerSets();
|
2017-03-29 18:09:16 +03:00
|
|
|
auto it = sets.constFind(setId);
|
|
|
|
if (it != sets.cend()) {
|
2019-09-10 00:48:34 +03:00
|
|
|
_displayingSet = true;
|
|
|
|
checkHideWithBox(Ui::show(
|
2019-06-24 17:09:37 +02:00
|
|
|
Box<StickerSetBox>(controller(), Stickers::inputSetId(*it)),
|
2019-09-10 00:48:34 +03:00
|
|
|
LayerOption::KeepOther).data());
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 00:48:34 +03:00
|
|
|
void StickersListWidget::checkHideWithBox(QPointer<BoxContent> box) {
|
|
|
|
if (!box) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
connect(box, &QObject::destroyed, this, [=] {
|
|
|
|
_displayingSet = false;
|
|
|
|
_checkForHide.fire({});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-05 12:48:21 +02:00
|
|
|
void StickersListWidget::installSet(uint64 setId) {
|
2019-07-24 13:13:51 +02:00
|
|
|
auto &sets = session().data().stickerSets();
|
2017-03-29 18:09:16 +03:00
|
|
|
auto it = sets.constFind(setId);
|
|
|
|
if (it != sets.cend()) {
|
2018-03-02 20:17:33 +03:00
|
|
|
const auto input = Stickers::inputSetId(*it);
|
|
|
|
if ((it->flags & MTPDstickerSet_ClientFlag::f_not_loaded)
|
|
|
|
|| it->stickers.empty()) {
|
|
|
|
request(MTPmessages_GetStickerSet(
|
|
|
|
input
|
|
|
|
)).done([=](const MTPmessages_StickerSet &result) {
|
|
|
|
Stickers::FeedSetFull(result);
|
|
|
|
sendInstallRequest(setId, input);
|
|
|
|
}).send();
|
|
|
|
} else {
|
|
|
|
sendInstallRequest(setId, input);
|
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:17:33 +03:00
|
|
|
void StickersListWidget::sendInstallRequest(
|
|
|
|
uint64 setId,
|
|
|
|
const MTPInputStickerSet &input) {
|
|
|
|
request(MTPmessages_InstallStickerSet(
|
|
|
|
input,
|
|
|
|
MTP_bool(false)
|
|
|
|
)).done([=](const MTPmessages_StickerSetInstallResult &result) {
|
|
|
|
if (result.type() == mtpc_messages_stickerSetInstallResultArchive) {
|
|
|
|
Stickers::ApplyArchivedResult(result.c_messages_stickerSetInstallResultArchive());
|
|
|
|
}
|
|
|
|
}).fail([=](const RPCError &error) {
|
|
|
|
notInstalledLocally(setId);
|
|
|
|
Stickers::UndoInstallLocally(setId);
|
|
|
|
}).send();
|
|
|
|
|
|
|
|
installedLocally(setId);
|
|
|
|
Stickers::InstallLocally(setId);
|
|
|
|
}
|
|
|
|
|
2017-08-05 22:01:20 +02:00
|
|
|
void StickersListWidget::removeMegagroupSet(bool locally) {
|
|
|
|
if (locally) {
|
2019-07-24 13:13:51 +02:00
|
|
|
session().settings().setGroupStickersSectionHidden(_megagroupSet->id);
|
2017-08-05 16:04:18 +02:00
|
|
|
Local::writeUserSettings();
|
|
|
|
refreshStickers();
|
|
|
|
return;
|
2017-08-05 12:48:21 +02:00
|
|
|
}
|
|
|
|
_removingSetId = Stickers::MegagroupSetId;
|
2019-06-19 17:09:03 +02:00
|
|
|
Ui::show(Box<ConfirmBox>(tr::lng_stickers_remove_group_set(tr::now), crl::guard(this, [this, group = _megagroupSet] {
|
2017-08-05 12:48:21 +02:00
|
|
|
Expects(group->mgInfo != nullptr);
|
2018-11-26 15:00:31 +04:00
|
|
|
|
2017-08-05 12:48:21 +02:00
|
|
|
if (group->mgInfo->stickerSet.type() != mtpc_inputStickerSetEmpty) {
|
2019-07-24 13:13:51 +02:00
|
|
|
session().api().setGroupStickerSet(group, MTP_inputStickerSetEmpty());
|
2017-08-05 12:48:21 +02:00
|
|
|
}
|
|
|
|
Ui::hideLayer();
|
|
|
|
_removingSetId = 0;
|
2018-11-21 22:14:48 +04:00
|
|
|
_checkForHide.fire({});
|
2018-06-04 18:35:11 +03:00
|
|
|
}), crl::guard(this, [this] {
|
2017-08-05 12:48:21 +02:00
|
|
|
_removingSetId = 0;
|
2018-11-21 22:14:48 +04:00
|
|
|
_checkForHide.fire({});
|
2017-08-05 12:48:21 +02:00
|
|
|
})));
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersListWidget::removeSet(uint64 setId) {
|
2019-07-24 13:13:51 +02:00
|
|
|
auto &sets = session().data().stickerSets();
|
2017-03-29 18:09:16 +03:00
|
|
|
auto it = sets.constFind(setId);
|
2017-04-09 21:06:06 +03:00
|
|
|
if (it != sets.cend()) {
|
2017-03-29 18:09:16 +03:00
|
|
|
_removingSetId = it->id;
|
2019-06-19 18:39:25 +02:00
|
|
|
auto text = tr::lng_stickers_remove_pack(tr::now, lt_sticker_pack, it->title);
|
2019-06-19 17:09:03 +02:00
|
|
|
Ui::show(Box<ConfirmBox>(text, tr::lng_stickers_remove_pack_confirm(tr::now), crl::guard(this, [=] {
|
2017-03-29 18:09:16 +03:00
|
|
|
Ui::hideLayer();
|
2019-07-24 13:13:51 +02:00
|
|
|
auto &sets = session().data().stickerSetsRef();
|
2017-03-29 18:09:16 +03:00
|
|
|
auto it = sets.find(_removingSetId);
|
2017-04-09 21:06:06 +03:00
|
|
|
if (it != sets.cend()) {
|
2017-03-29 18:09:16 +03:00
|
|
|
if (it->id && it->access) {
|
|
|
|
request(MTPmessages_UninstallStickerSet(MTP_inputStickerSetID(MTP_long(it->id), MTP_long(it->access)))).send();
|
|
|
|
} else if (!it->shortName.isEmpty()) {
|
|
|
|
request(MTPmessages_UninstallStickerSet(MTP_inputStickerSetShortName(MTP_string(it->shortName)))).send();
|
|
|
|
}
|
2017-04-09 21:06:06 +03:00
|
|
|
auto writeRecent = false;
|
2017-12-11 18:45:29 +04:00
|
|
|
auto &recent = Stickers::GetRecentPack();
|
2017-04-09 21:06:06 +03:00
|
|
|
for (auto i = recent.begin(); i != recent.cend();) {
|
2017-03-29 18:09:16 +03:00
|
|
|
if (it->stickers.indexOf(i->first) >= 0) {
|
|
|
|
i = recent.erase(i);
|
|
|
|
writeRecent = true;
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2018-01-25 15:28:48 +03:00
|
|
|
it->flags &= ~MTPDstickerSet::Flag::f_installed_date;
|
|
|
|
it->installDate = TimeId(0);
|
2018-03-02 20:17:33 +03:00
|
|
|
//
|
|
|
|
// Set can be in search results.
|
|
|
|
//
|
|
|
|
//if (!(it->flags & MTPDstickerSet_ClientFlag::f_featured)
|
|
|
|
// && !(it->flags & MTPDstickerSet_ClientFlag::f_special)) {
|
|
|
|
// sets.erase(it);
|
|
|
|
//}
|
2019-07-24 13:13:51 +02:00
|
|
|
int removeIndex = session().data().stickerSetsOrder().indexOf(_removingSetId);
|
|
|
|
if (removeIndex >= 0) session().data().stickerSetsOrderRef().removeAt(removeIndex);
|
2017-03-29 18:09:16 +03:00
|
|
|
refreshStickers();
|
|
|
|
Local::writeInstalledStickers();
|
|
|
|
if (writeRecent) Local::writeUserSettings();
|
|
|
|
}
|
|
|
|
_removingSetId = 0;
|
2018-11-21 22:14:48 +04:00
|
|
|
_checkForHide.fire({});
|
|
|
|
}), crl::guard(this, [=] {
|
2017-03-29 18:09:16 +03:00
|
|
|
_removingSetId = 0;
|
2018-11-21 22:14:48 +04:00
|
|
|
_checkForHide.fire({});
|
2017-03-29 18:09:16 +03:00
|
|
|
})));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-05 22:01:20 +02:00
|
|
|
StickersListWidget::~StickersListWidget() = default;
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
} // namespace ChatHelpers
|