2016-10-20 16:32:15 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-10-20 16:32:15 +00:00
|
|
|
*/
|
|
|
|
#include "stickers_box.h"
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_document.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-10-20 16:32:15 +00:00
|
|
|
#include "mainwidget.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "chat_helpers/stickers.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "boxes/sticker_set_box.h"
|
2016-10-20 16:32:15 +00:00
|
|
|
#include "apiwrap.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2016-10-20 16:32:15 +00:00
|
|
|
#include "dialogs/dialogs_layout.h"
|
2016-10-27 21:19:38 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "styles/style_chat_helpers.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2017-08-05 20:01:20 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2016-11-16 16:04:25 +00:00
|
|
|
#include "ui/effects/ripple_animation.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
#include "ui/effects/slide_animation.h"
|
2016-11-22 09:48:13 +00:00
|
|
|
#include "ui/widgets/discrete_sliders.h"
|
2017-08-05 20:01:20 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "auth_session.h"
|
2017-08-05 20:01:20 +00:00
|
|
|
#include "messenger.h"
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
constexpr auto kArchivedLimitFirstRequest = 10;
|
|
|
|
constexpr auto kArchivedLimitPerPage = 30;
|
|
|
|
constexpr auto kHandleMegagroupSetAddressChangeTimeout = TimeMs(1000);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
int stickerPacksCount(bool includeArchivedOfficial) {
|
|
|
|
auto result = 0;
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &order = Auth().data().stickerSetsOrder();
|
|
|
|
auto &sets = Auth().data().stickerSets();
|
2016-11-22 09:48:13 +00:00
|
|
|
for (auto i = 0, l = order.size(); i < l; ++i) {
|
2016-10-20 16:32:15 +00:00
|
|
|
auto it = sets.constFind(order.at(i));
|
|
|
|
if (it != sets.cend()) {
|
2016-11-22 09:48:13 +00:00
|
|
|
if (!(it->flags & MTPDstickerSet::Flag::f_archived) || ((it->flags & MTPDstickerSet::Flag::f_official) && includeArchivedOfficial)) {
|
2016-10-20 16:32:15 +00:00
|
|
|
++result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
class StickersBox::CounterWidget : public Ui::RpWidget {
|
2016-11-22 09:48:13 +00:00
|
|
|
public:
|
|
|
|
CounterWidget(QWidget *parent);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2017-11-05 17:07:27 +00:00
|
|
|
void setCounter(int counter);
|
2016-11-22 09:48:13 +00:00
|
|
|
|
|
|
|
QString _text;
|
|
|
|
Dialogs::Layout::UnreadBadgeStyle _st;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
StickersBox::CounterWidget::CounterWidget(QWidget *parent)
|
|
|
|
: RpWidget(parent) {
|
2016-11-22 09:48:13 +00:00
|
|
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
|
|
|
|
_st.sizeId = Dialogs::Layout::UnreadBadgeInStickersBox;
|
|
|
|
_st.textTop = st::stickersFeaturedBadgeTextTop;
|
|
|
|
_st.size = st::stickersFeaturedBadgeSize;
|
|
|
|
_st.padding = st::stickersFeaturedBadgePadding;
|
|
|
|
_st.font = st::stickersFeaturedBadgeFont;
|
|
|
|
|
2017-12-22 07:05:20 +00:00
|
|
|
Auth().data().featuredStickerSetsUnreadCountValue(
|
|
|
|
) | rpl::start_with_next([this](int count) {
|
|
|
|
setCounter(count);
|
|
|
|
update();
|
|
|
|
}, lifetime());
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::CounterWidget::setCounter(int counter) {
|
|
|
|
_text = (counter > 0) ? QString::number(counter) : QString();
|
|
|
|
auto dummy = QImage(1, 1, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
Painter p(&dummy);
|
|
|
|
|
|
|
|
auto newWidth = 0;
|
|
|
|
Dialogs::Layout::paintUnreadCount(p, _text, 0, 0, _st, &newWidth);
|
|
|
|
|
|
|
|
resize(newWidth, st::stickersFeaturedBadgeSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::CounterWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
if (!_text.isEmpty()) {
|
|
|
|
auto unreadRight = rtl() ? 0 : width();
|
|
|
|
auto unreadTop = 0;
|
|
|
|
Dialogs::Layout::paintUnreadCount(p, _text, unreadRight, unreadTop, _st);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
template <typename ...Args>
|
|
|
|
StickersBox::Tab::Tab(int index, Args&&... args)
|
|
|
|
: _index(index)
|
2017-02-21 13:45:56 +00:00
|
|
|
, _widget(std::forward<Args>(args)...)
|
2016-12-13 17:07:56 +00:00
|
|
|
, _weak(_widget) {
|
|
|
|
}
|
|
|
|
|
|
|
|
object_ptr<StickersBox::Inner> StickersBox::Tab::takeWidget() {
|
2017-02-21 13:45:56 +00:00
|
|
|
return std::move(_widget);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Tab::returnWidget(object_ptr<Inner> widget) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_widget = std::move(widget);
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(_widget == _weak);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Tab::saveScrollTop() {
|
|
|
|
_scrollTop = widget()->getVisibleTop();
|
|
|
|
}
|
|
|
|
|
|
|
|
StickersBox::StickersBox(QWidget*, Section section)
|
|
|
|
: _tabs(this, st::stickersTabs)
|
2016-11-22 09:48:13 +00:00
|
|
|
, _unreadBadge(this)
|
2016-10-20 16:32:15 +00:00
|
|
|
, _section(section)
|
2016-11-22 09:48:13 +00:00
|
|
|
, _installed(0, this, Section::Installed)
|
|
|
|
, _featured(1, this, Section::Featured)
|
|
|
|
, _archived(2, this, Section::Archived) {
|
2017-04-08 15:20:12 +00:00
|
|
|
_tabs->setRippleTopRoundRadius(st::boxRadius);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
StickersBox::StickersBox(QWidget*, not_null<ChannelData*> megagroup)
|
2017-08-05 10:48:21 +00:00
|
|
|
: _section(Section::Installed)
|
|
|
|
, _installed(0, this, megagroup)
|
|
|
|
, _megagroupSet(megagroup) {
|
2017-08-05 20:01:20 +00:00
|
|
|
subscribe(_installed.widget()->scrollToY, [this](int y) { onScrollToY(y); });
|
2017-08-05 10:48:21 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void StickersBox::getArchivedDone(uint64 offsetId, const MTPmessages_ArchivedStickers &result) {
|
|
|
|
_archivedRequestId = 0;
|
2016-11-22 09:48:13 +00:00
|
|
|
_archivedLoaded = true;
|
2016-10-20 16:32:15 +00:00
|
|
|
if (result.type() != mtpc_messages_archivedStickers) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &stickers = result.c_messages_archivedStickers();
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &archived = Auth().data().archivedStickerSetsOrderRef();
|
2016-10-20 16:32:15 +00:00
|
|
|
if (offsetId) {
|
|
|
|
auto index = archived.indexOf(offsetId);
|
|
|
|
if (index >= 0) {
|
|
|
|
archived = archived.mid(0, index + 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
archived.clear();
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
auto addedSet = false;
|
|
|
|
auto changedSets = false;
|
2018-03-02 17:17:33 +00:00
|
|
|
for_const (const auto &stickerSet, stickers.vsets.v) {
|
2016-10-20 16:32:15 +00:00
|
|
|
const MTPDstickerSet *setData = nullptr;
|
|
|
|
switch (stickerSet.type()) {
|
|
|
|
case mtpc_stickerSetCovered: {
|
|
|
|
auto &d = stickerSet.c_stickerSetCovered();
|
|
|
|
if (d.vset.type() == mtpc_stickerSet) {
|
|
|
|
setData = &d.vset.c_stickerSet();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_stickerSetMultiCovered: {
|
|
|
|
auto &d = stickerSet.c_stickerSetMultiCovered();
|
|
|
|
if (d.vset.type() == mtpc_stickerSet) {
|
|
|
|
setData = &d.vset.c_stickerSet();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
if (!setData) continue;
|
|
|
|
|
2017-08-02 20:57:49 +00:00
|
|
|
if (auto set = Stickers::FeedSet(*setData)) {
|
2016-10-20 16:32:15 +00:00
|
|
|
auto index = archived.indexOf(set->id);
|
|
|
|
if (archived.isEmpty() || index != archived.size() - 1) {
|
2016-12-13 17:07:56 +00:00
|
|
|
changedSets = true;
|
2016-10-20 16:32:15 +00:00
|
|
|
if (index < archived.size() - 1) {
|
|
|
|
archived.removeAt(index);
|
|
|
|
}
|
|
|
|
archived.push_back(set->id);
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_archived.widget()->appendSet(*set)) {
|
2016-11-22 09:48:13 +00:00
|
|
|
addedSet = true;
|
|
|
|
if (set->stickers.isEmpty() || (set->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().scheduleStickerSetRequest(set->id, set->access);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
if (addedSet) {
|
2016-12-13 17:07:56 +00:00
|
|
|
_archived.widget()->updateSize();
|
2016-11-22 09:48:13 +00:00
|
|
|
} else {
|
2018-03-02 17:17:33 +00:00
|
|
|
_allArchivedLoaded = stickers.vsets.v.isEmpty()
|
|
|
|
|| (!changedSets && offsetId != 0);
|
2016-12-21 15:05:58 +00:00
|
|
|
if (changedSets) {
|
2016-12-13 17:07:56 +00:00
|
|
|
loadMoreArchived();
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refreshTabs();
|
|
|
|
_someArchivedLoaded = true;
|
|
|
|
if (_section == Section::Archived && addedSet) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestStickerSets();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void StickersBox::prepare() {
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_section == Section::Installed) {
|
2017-08-05 10:48:21 +00:00
|
|
|
if (_tabs) {
|
|
|
|
Local::readArchivedStickers();
|
|
|
|
} else {
|
|
|
|
setTitle(langFactory(lng_stickers_group_set));
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
} else if (_section == Section::Archived) {
|
2016-11-22 09:48:13 +00:00
|
|
|
requestArchivedSets();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_tabs) {
|
2017-11-05 17:07:27 +00:00
|
|
|
if (Auth().data().archivedStickerSetsOrder().isEmpty()) {
|
2017-08-05 10:48:21 +00:00
|
|
|
preloadArchivedSets();
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
setNoContentMargin(true);
|
2017-12-22 07:05:20 +00:00
|
|
|
_tabs->sectionActivated(
|
|
|
|
) | rpl::start_with_next(
|
|
|
|
[this] { switchTab(); },
|
|
|
|
lifetime());
|
2016-11-22 09:48:13 +00:00
|
|
|
refreshTabs();
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_installed.widget() && _section != Section::Installed) _installed.widget()->hide();
|
|
|
|
if (_featured.widget() && _section != Section::Featured) _featured.widget()->hide();
|
2017-09-09 09:04:20 +00:00
|
|
|
if (_archived.widget() && _section != Section::Archived) _archived.widget()->hide();
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_featured.widget()) {
|
|
|
|
_featured.widget()->setInstallSetCallback([this](uint64 setId) { installSet(setId); });
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2017-08-05 10:48:21 +00:00
|
|
|
if (_archived.widget()) {
|
|
|
|
_archived.widget()->setInstallSetCallback([this](uint64 setId) { installSet(setId); });
|
|
|
|
_archived.widget()->setLoadMoreCallback([this] { loadMoreArchived(); });
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
if (_megagroupSet) {
|
|
|
|
addButton(langFactory(lng_settings_save), [this] { _installed.widget()->saveGroupSet(); closeBox(); });
|
|
|
|
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
|
|
|
} else {
|
|
|
|
addButton(langFactory(lng_about_done), [this] { closeBox(); });
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_section == Section::Installed) {
|
|
|
|
_tab = &_installed;
|
2016-10-20 16:32:15 +00:00
|
|
|
} else if (_section == Section::Archived) {
|
2016-11-22 09:48:13 +00:00
|
|
|
_tab = &_archived;
|
|
|
|
} else { // _section == Section::Featured
|
|
|
|
_tab = &_featured;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
setInnerWidget(_tab->takeWidget(), getTopSkip());
|
2017-09-09 09:04:20 +00:00
|
|
|
setDimensions(st::boxWideWidth, st::boxMaxListHeight);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2017-12-22 07:05:20 +00:00
|
|
|
Auth().data().stickersUpdated(
|
|
|
|
) | rpl::start_with_next(
|
|
|
|
[this] { handleStickersUpdated(); },
|
|
|
|
lifetime());
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().updateStickers();
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_installed.widget()) {
|
|
|
|
connect(_installed.widget(), SIGNAL(draggingScrollDelta(int)), this, SLOT(onDraggingScrollDelta(int)));
|
2017-08-13 16:09:14 +00:00
|
|
|
if (!_megagroupSet) {
|
2018-03-29 19:49:31 +00:00
|
|
|
boxClosing() | rpl::start_with_next([=] {
|
|
|
|
saveChanges();
|
|
|
|
}, lifetime());
|
2017-08-13 16:09:14 +00:00
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_tabs) {
|
|
|
|
_tabs->raise();
|
2016-12-31 13:34:41 +00:00
|
|
|
_unreadBadge->raise();
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
rebuildList();
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::refreshTabs() {
|
|
|
|
if (!_tabs) return;
|
|
|
|
|
|
|
|
_tabIndices.clear();
|
|
|
|
auto sections = QStringList();
|
|
|
|
sections.push_back(lang(lng_stickers_installed_tab).toUpper());
|
|
|
|
_tabIndices.push_back(Section::Installed);
|
2017-11-05 17:07:27 +00:00
|
|
|
if (!Auth().data().featuredStickerSetsOrder().isEmpty()) {
|
2016-11-22 09:48:13 +00:00
|
|
|
sections.push_back(lang(lng_stickers_featured_tab).toUpper());
|
|
|
|
_tabIndices.push_back(Section::Featured);
|
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
if (!Auth().data().archivedStickerSetsOrder().isEmpty()) {
|
2016-11-22 09:48:13 +00:00
|
|
|
sections.push_back(lang(lng_stickers_archived_tab).toUpper());
|
|
|
|
_tabIndices.push_back(Section::Archived);
|
|
|
|
}
|
|
|
|
_tabs->setSections(sections);
|
|
|
|
if ((_tab == &_archived && !_tabIndices.contains(Section::Archived))
|
|
|
|
|| (_tab == &_featured && !_tabIndices.contains(Section::Featured))) {
|
|
|
|
switchTab();
|
2017-04-11 14:02:11 +00:00
|
|
|
} else if (_tab == &_archived) {
|
|
|
|
_tabs->setActiveSectionFast(_tabIndices.indexOf(Section::Archived));
|
|
|
|
} else if (_tab == &_featured) {
|
|
|
|
_tabs->setActiveSectionFast(_tabIndices.indexOf(Section::Featured));
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
updateTabsGeometry();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void StickersBox::loadMoreArchived() {
|
|
|
|
if (_section != Section::Archived || _allArchivedLoaded || _archivedRequestId) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
uint64 lastId = 0;
|
2017-11-05 17:07:27 +00:00
|
|
|
for (auto setIt = Auth().data().archivedStickerSetsOrder().cend(), e = Auth().data().archivedStickerSetsOrder().cbegin(); setIt != e;) {
|
2016-12-13 17:07:56 +00:00
|
|
|
--setIt;
|
2017-11-05 17:07:27 +00:00
|
|
|
auto it = Auth().data().stickerSets().constFind(*setIt);
|
|
|
|
if (it != Auth().data().stickerSets().cend()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (it->flags & MTPDstickerSet::Flag::f_archived) {
|
|
|
|
lastId = it->id;
|
|
|
|
break;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-25 15:42:01 +00:00
|
|
|
_archivedRequestId = MTP::send(MTPmessages_GetArchivedStickers(MTP_flags(0), MTP_long(lastId), MTP_int(kArchivedLimitPerPage)), rpcDone(&StickersBox::getArchivedDone, lastId));
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2016-11-22 09:48:13 +00:00
|
|
|
|
|
|
|
Painter p(this);
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
if (_slideAnimation) {
|
2016-12-13 17:07:56 +00:00
|
|
|
_slideAnimation->paintFrame(p, 0, getTopSkip(), width(), getms());
|
2016-11-24 19:28:23 +00:00
|
|
|
if (!_slideAnimation->animating()) {
|
|
|
|
_slideAnimation.reset();
|
2016-12-13 17:07:56 +00:00
|
|
|
setInnerVisible(true);
|
2016-11-22 09:48:13 +00:00
|
|
|
update();
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::updateTabsGeometry() {
|
|
|
|
if (!_tabs) return;
|
|
|
|
|
|
|
|
_tabs->resizeToWidth(_tabIndices.size() * width() / 3);
|
|
|
|
_unreadBadge->setVisible(_tabIndices.contains(Section::Featured));
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
setInnerTopSkip(getTopSkip());
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
auto featuredLeft = width() / 3;
|
|
|
|
auto featuredRight = 2 * width() / 3;
|
2016-12-13 17:07:56 +00:00
|
|
|
auto featuredTextWidth = st::stickersTabs.labelFont->width(lang(lng_stickers_featured_tab).toUpper());
|
2016-11-22 09:48:13 +00:00
|
|
|
auto featuredTextRight = featuredLeft + (featuredRight - featuredLeft - featuredTextWidth) / 2 + featuredTextWidth;
|
|
|
|
auto unreadBadgeLeft = featuredTextRight - st::stickersFeaturedBadgeSkip;
|
|
|
|
auto unreadBadgeTop = st::stickersFeaturedBadgeTop;
|
|
|
|
if (unreadBadgeLeft + _unreadBadge->width() > featuredRight) {
|
|
|
|
unreadBadgeLeft = featuredRight - _unreadBadge->width();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
_unreadBadge->moveToLeft(unreadBadgeLeft, unreadBadgeTop);
|
|
|
|
|
|
|
|
_tabs->moveToLeft(0, 0);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
int StickersBox::getTopSkip() const {
|
2017-09-09 09:04:20 +00:00
|
|
|
return _tabs ? (_tabs->height() - st::lineWidth) : 0;
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::switchTab() {
|
|
|
|
if (!_tabs) return;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
auto tab = _tabs->activeSection();
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(tab >= 0 && tab < _tabIndices.size());
|
2016-11-22 09:48:13 +00:00
|
|
|
auto newSection = _tabIndices[tab];
|
|
|
|
|
|
|
|
auto newTab = _tab;
|
|
|
|
if (newSection == Section::Installed) {
|
|
|
|
newTab = &_installed;
|
|
|
|
} else if (newSection == Section::Featured) {
|
|
|
|
newTab = &_featured;
|
|
|
|
} else if (newSection == Section::Archived) {
|
|
|
|
newTab = &_archived;
|
|
|
|
requestArchivedSets();
|
|
|
|
}
|
2017-03-28 12:30:38 +00:00
|
|
|
if (_tab == newTab) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_tab == &_installed) {
|
|
|
|
_localOrder = _tab->widget()->getFullOrder();
|
|
|
|
_localRemoved = _tab->widget()->getRemovedSets();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2017-03-28 12:30:38 +00:00
|
|
|
auto wasCache = grabContentCache();
|
|
|
|
auto wasIndex = _tab->index();
|
|
|
|
_tab->saveScrollTop();
|
|
|
|
auto widget = takeInnerWidget<Inner>();
|
|
|
|
widget->setParent(this);
|
|
|
|
widget->hide();
|
|
|
|
_tab->returnWidget(std::move(widget));
|
|
|
|
_tab = newTab;
|
|
|
|
_section = newSection;
|
|
|
|
setInnerWidget(_tab->takeWidget(), getTopSkip());
|
|
|
|
_tabs->raise();
|
|
|
|
_unreadBadge->raise();
|
|
|
|
_tab->widget()->show();
|
|
|
|
rebuildList();
|
|
|
|
onScrollToY(_tab->getScrollTop());
|
2017-04-11 14:02:11 +00:00
|
|
|
setInnerVisible(true);
|
2017-03-28 12:30:38 +00:00
|
|
|
auto nowCache = grabContentCache();
|
|
|
|
auto nowIndex = _tab->index();
|
|
|
|
|
|
|
|
_slideAnimation = std::make_unique<Ui::SlideAnimation>();
|
|
|
|
_slideAnimation->setSnapshots(std::move(wasCache), std::move(nowCache));
|
|
|
|
auto slideLeft = wasIndex > nowIndex;
|
|
|
|
_slideAnimation->start(slideLeft, [this] { update(); }, st::slideDuration);
|
|
|
|
setInnerVisible(false);
|
|
|
|
|
|
|
|
setFocus();
|
|
|
|
update();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
QPixmap StickersBox::grabContentCache() {
|
|
|
|
_tabs->hide();
|
2016-12-13 17:07:56 +00:00
|
|
|
auto result = grabInnerCache();
|
2016-11-22 09:48:13 +00:00
|
|
|
_tabs->show();
|
2017-02-21 14:37:53 +00:00
|
|
|
return result;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::installSet(uint64 setId) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSetsRef();
|
2016-11-22 09:48:13 +00:00
|
|
|
auto it = sets.find(setId);
|
|
|
|
if (it == sets.cend()) {
|
|
|
|
rebuildList();
|
|
|
|
return;
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_localRemoved.contains(setId)) {
|
|
|
|
_localRemoved.removeOne(setId);
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_installed.widget()) _installed.widget()->setRemovedSets(_localRemoved);
|
|
|
|
if (_featured.widget()) _featured.widget()->setRemovedSets(_localRemoved);
|
|
|
|
_archived.widget()->setRemovedSets(_localRemoved);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2018-01-25 12:28:48 +00:00
|
|
|
if (!(it->flags & MTPDstickerSet::Flag::f_installed_date)
|
|
|
|
|| (it->flags & MTPDstickerSet::Flag::f_archived)) {
|
|
|
|
MTP::send(
|
|
|
|
MTPmessages_InstallStickerSet(
|
|
|
|
Stickers::inputSetId(*it),
|
|
|
|
MTP_boolFalse()),
|
|
|
|
rpcDone(&StickersBox::installDone),
|
|
|
|
rpcFail(&StickersBox::installFail, setId));
|
2016-11-19 14:47:28 +00:00
|
|
|
|
2017-08-02 20:57:49 +00:00
|
|
|
Stickers::InstallLocally(setId);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::installDone(const MTPmessages_StickerSetInstallResult &result) {
|
|
|
|
if (result.type() == mtpc_messages_stickerSetInstallResultArchive) {
|
2018-01-25 12:28:48 +00:00
|
|
|
Stickers::ApplyArchivedResult(
|
|
|
|
result.c_messages_stickerSetInstallResultArchive());
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
bool StickersBox::installFail(uint64 setId, const RPCError &error) {
|
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSetsRef();
|
2016-11-22 09:48:13 +00:00
|
|
|
auto it = sets.find(setId);
|
|
|
|
if (it == sets.cend()) {
|
|
|
|
rebuildList();
|
|
|
|
return true;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2017-08-02 20:57:49 +00:00
|
|
|
Stickers::UndoInstallLocally(setId);
|
2016-11-22 09:48:13 +00:00
|
|
|
return true;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::preloadArchivedSets() {
|
2017-09-03 19:48:52 +00:00
|
|
|
if (!_tabs) return;
|
2016-11-22 09:48:13 +00:00
|
|
|
if (!_archivedRequestId) {
|
2017-03-25 15:42:01 +00:00
|
|
|
_archivedRequestId = MTP::send(MTPmessages_GetArchivedStickers(MTP_flags(0), MTP_long(0), MTP_int(kArchivedLimitFirstRequest)), rpcDone(&StickersBox::getArchivedDone, 0ULL));
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::requestArchivedSets() {
|
|
|
|
// Reload the archived list.
|
|
|
|
if (!_archivedLoaded) {
|
|
|
|
preloadArchivedSets();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSets();
|
|
|
|
for_const (auto setId, Auth().data().archivedStickerSetsOrder()) {
|
2016-11-22 09:48:13 +00:00
|
|
|
auto it = sets.constFind(setId);
|
|
|
|
if (it != sets.cend()) {
|
|
|
|
if (it->stickers.isEmpty() && (it->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().scheduleStickerSetRequest(setId, it->access);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestStickerSets();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_tabs) {
|
|
|
|
updateTabsGeometry();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_titleShadow) {
|
|
|
|
_titleShadow->setGeometry(0, 0, width(), st::lineWidth);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_installed.widget()) _installed.widget()->resize(width(), _installed.widget()->height());
|
|
|
|
if (_featured.widget()) _featured.widget()->resize(width(), _featured.widget()->height());
|
2017-08-05 10:48:21 +00:00
|
|
|
if (_archived.widget()) _archived.widget()->resize(width(), _archived.widget()->height());
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 10:48:21 +00:00
|
|
|
void StickersBox::handleStickersUpdated() {
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_section == Section::Installed || _section == Section::Featured) {
|
|
|
|
rebuildList();
|
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
_tab->widget()->updateRows();
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
if (Auth().data().archivedStickerSetsOrder().isEmpty()) {
|
2016-11-22 09:48:13 +00:00
|
|
|
preloadArchivedSets();
|
|
|
|
} else {
|
|
|
|
refreshTabs();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-22 13:30:27 +00:00
|
|
|
void StickersBox::rebuildList(Tab *tab) {
|
|
|
|
if (!tab) tab = _tab;
|
|
|
|
|
|
|
|
if (tab == &_installed) {
|
|
|
|
_localOrder = tab->widget()->getFullOrder();
|
|
|
|
_localRemoved = tab->widget()->getRemovedSets();
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2016-12-22 13:30:27 +00:00
|
|
|
tab->widget()->rebuild();
|
|
|
|
if (tab == &_installed) {
|
|
|
|
tab->widget()->setFullOrder(_localOrder);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-12-22 13:30:27 +00:00
|
|
|
tab->widget()->setRemovedSets(_localRemoved);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 16:09:14 +00:00
|
|
|
void StickersBox::saveChanges() {
|
2016-12-22 13:30:27 +00:00
|
|
|
// Make sure that our changes in other tabs are applied in the Installed tab.
|
|
|
|
rebuildList(&_installed);
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_someArchivedLoaded) {
|
|
|
|
Local::writeArchivedStickers();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2017-08-04 14:54:32 +00:00
|
|
|
if (AuthSession::Exists()) {
|
|
|
|
Auth().api().saveStickerSets(_installed.widget()->getOrder(), _installed.widget()->getRemovedSets());
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::setInnerFocus() {
|
|
|
|
if (_megagroupSet) {
|
|
|
|
_installed.widget()->setInnerFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
StickersBox::~StickersBox() = default;
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
StickersBox::Inner::Row::Row(
|
|
|
|
uint64 id,
|
|
|
|
uint64 accessHash,
|
|
|
|
DocumentData *sticker,
|
|
|
|
int32 count,
|
|
|
|
const QString &title,
|
|
|
|
int titleWidth,
|
|
|
|
bool installed,
|
|
|
|
bool official,
|
|
|
|
bool unread,
|
|
|
|
bool archived,
|
|
|
|
bool removed,
|
|
|
|
int32 pixw,
|
|
|
|
int32 pixh)
|
|
|
|
: id(id)
|
|
|
|
, accessHash(accessHash)
|
2017-08-05 20:01:20 +00:00
|
|
|
, sticker(sticker)
|
|
|
|
, count(count)
|
|
|
|
, title(title)
|
|
|
|
, titleWidth(titleWidth)
|
|
|
|
, installed(installed)
|
|
|
|
, official(official)
|
|
|
|
, unread(unread)
|
|
|
|
, archived(archived)
|
|
|
|
, removed(removed)
|
|
|
|
, pixw(pixw)
|
|
|
|
, pixh(pixh) {
|
|
|
|
}
|
|
|
|
|
|
|
|
StickersBox::Inner::Row::~Row() = default;
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
StickersBox::Inner::Inner(QWidget *parent, StickersBox::Section section) : TWidget(parent)
|
2016-10-20 16:32:15 +00:00
|
|
|
, _section(section)
|
|
|
|
, _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom())
|
|
|
|
, _a_shifting(animation(this, &Inner::step_shifting))
|
2016-12-13 17:07:56 +00:00
|
|
|
, _itemsTop(st::membersMarginTop)
|
2016-11-22 09:48:13 +00:00
|
|
|
, _addText(lang(lng_stickers_featured_add).toUpper())
|
|
|
|
, _addWidth(st::stickersTrendingAdd.font->width(_addText))
|
|
|
|
, _undoText(lang(lng_stickers_return).toUpper())
|
2016-12-13 17:07:56 +00:00
|
|
|
, _undoWidth(st::stickersUndoRemove.font->width(_undoText)) {
|
2016-10-20 16:32:15 +00:00
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
StickersBox::Inner::Inner(QWidget *parent, not_null<ChannelData*> megagroup) : TWidget(parent)
|
2017-08-05 10:48:21 +00:00
|
|
|
, _section(StickersBox::Section::Installed)
|
|
|
|
, _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom())
|
|
|
|
, _a_shifting(animation(this, &Inner::step_shifting))
|
|
|
|
, _itemsTop(st::membersMarginTop)
|
2017-08-05 20:01:20 +00:00
|
|
|
, _megagroupSet(megagroup)
|
|
|
|
, _megagroupSetInput(_megagroupSet->mgInfo->stickerSet)
|
|
|
|
, _megagroupSetField(this, st::groupStickersField, [] { return qsl("stickerset"); }, QString(), true)
|
|
|
|
, _megagroupDivider(this)
|
|
|
|
, _megagroupSubTitle(this, lang(lng_stickers_group_from_your), Ui::FlatLabel::InitType::Simple, st::boxTitle) {
|
|
|
|
_megagroupSetField->setLinkPlaceholder(Messenger::Instance().createInternalLink(qsl("addstickers/")));
|
|
|
|
_megagroupSetField->setPlaceholderHidden(false);
|
|
|
|
_megagroupSetAddressChangedTimer.setCallback([this] { handleMegagroupSetAddressChange(); });
|
2017-11-05 17:07:27 +00:00
|
|
|
connect(
|
|
|
|
_megagroupSetField,
|
|
|
|
&Ui::MaskedInputField::changed,
|
2018-05-31 12:20:28 +00:00
|
|
|
[=] {
|
2017-11-05 17:07:27 +00:00
|
|
|
_megagroupSetAddressChangedTimer.callOnce(
|
|
|
|
kHandleMegagroupSetAddressChangeTimeout);
|
|
|
|
});
|
|
|
|
connect(
|
|
|
|
_megagroupSetField,
|
|
|
|
&Ui::MaskedInputField::submitted,
|
2018-05-31 12:20:28 +00:00
|
|
|
[=] {
|
2017-11-05 17:07:27 +00:00
|
|
|
_megagroupSetAddressChangedTimer.cancel();
|
|
|
|
handleMegagroupSetAddressChange();
|
|
|
|
});
|
2017-08-05 20:01:20 +00:00
|
|
|
|
2017-08-05 10:48:21 +00:00
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void StickersBox::Inner::setup() {
|
2017-08-04 14:54:32 +00:00
|
|
|
subscribe(Auth().downloaderTaskFinished(), [this] {
|
2016-11-22 09:48:13 +00:00
|
|
|
update();
|
|
|
|
readVisibleSets();
|
|
|
|
});
|
2016-10-20 16:32:15 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::Inner::setInnerFocus() {
|
|
|
|
if (_megagroupSetField) {
|
|
|
|
_megagroupSetField->setFocusFast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void StickersBox::Inner::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2018-09-21 07:12:53 +00:00
|
|
|
if (_a_shifting.animating()) {
|
|
|
|
_a_shifting.step();
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
auto clip = e->rect();
|
2016-11-16 16:04:25 +00:00
|
|
|
auto ms = getms();
|
2017-08-05 20:01:20 +00:00
|
|
|
p.fillRect(clip, st::boxBg);
|
|
|
|
p.setClipRect(clip);
|
|
|
|
|
|
|
|
if (_megagroupSelectedSet) {
|
|
|
|
auto setTop = _megagroupDivider->y() - _rowHeight;
|
|
|
|
p.translate(0, setTop);
|
|
|
|
paintRow(p, _megagroupSelectedSet.get(), -1, ms);
|
|
|
|
p.translate(0, -setTop);
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
auto y = _itemsTop;
|
2017-08-05 20:01:20 +00:00
|
|
|
if (_rows.empty()) {
|
2016-10-20 16:32:15 +00:00
|
|
|
p.setFont(st::noContactsFont);
|
|
|
|
p.setPen(st::noContactsColor);
|
|
|
|
p.drawText(QRect(0, y, width(), st::noContactsHeight), lang(lng_contacts_loading), style::al_center);
|
|
|
|
} else {
|
|
|
|
p.translate(0, _itemsTop);
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
int32 yFrom = clip.y() - _itemsTop, yTo = clip.y() + clip.height() - _itemsTop;
|
2016-10-20 16:32:15 +00:00
|
|
|
int32 from = floorclamp(yFrom - _rowHeight, _rowHeight, 0, _rows.size());
|
|
|
|
int32 to = ceilclamp(yTo + _rowHeight, _rowHeight, 0, _rows.size());
|
|
|
|
p.translate(0, from * _rowHeight);
|
|
|
|
for (int32 i = from; i < to; ++i) {
|
|
|
|
if (i != _above) {
|
2017-08-05 20:01:20 +00:00
|
|
|
paintRow(p, _rows[i].get(), i, ms);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
p.translate(0, _rowHeight);
|
|
|
|
}
|
|
|
|
if (from <= _above && _above < to) {
|
|
|
|
p.translate(0, (_above - to) * _rowHeight);
|
2017-08-05 20:01:20 +00:00
|
|
|
paintRow(p, _rows[_above].get(), _above, ms);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::Inner::resizeEvent(QResizeEvent *e) {
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::updateControlsGeometry() {
|
|
|
|
if (_megagroupSet) {
|
|
|
|
auto top = st::groupStickersFieldPadding.top();
|
|
|
|
auto fieldLeft = st::boxLayerTitlePosition.x();
|
|
|
|
_megagroupSetField->setGeometryToLeft(fieldLeft, top, width() - fieldLeft - st::groupStickersFieldPadding.right(), _megagroupSetField->height());
|
|
|
|
top += _megagroupSetField->height() + st::groupStickersFieldPadding.bottom();
|
|
|
|
if (_megagroupSelectedRemove) {
|
|
|
|
_megagroupSelectedShadow->setGeometryToLeft(0, top, width(), st::lineWidth);
|
|
|
|
top += st::lineWidth;
|
|
|
|
_megagroupSelectedRemove->moveToRight(st::groupStickersRemovePosition.x(), top + st::groupStickersRemovePosition.y());
|
|
|
|
top += _rowHeight;
|
|
|
|
}
|
|
|
|
_megagroupDivider->setGeometryToLeft(0, top, width(), _megagroupDivider->height());
|
|
|
|
top += _megagroupDivider->height();
|
2017-11-22 09:03:36 +00:00
|
|
|
_megagroupSubTitle->resizeToNaturalWidth(width() - 2 * st::boxLayerTitlePosition.x());
|
2017-08-05 20:01:20 +00:00
|
|
|
_megagroupSubTitle->moveToLeft(st::boxLayerTitlePosition.x(), top + st::boxLayerTitlePosition.y());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
QRect StickersBox::Inner::relativeButtonRect(bool removeButton) const {
|
|
|
|
auto buttonw = st::stickersRemove.width;
|
|
|
|
auto buttonh = st::stickersRemove.height;
|
|
|
|
auto buttonshift = st::stickersRemoveSkip;
|
|
|
|
if (!removeButton) {
|
|
|
|
auto &st = (_section == Section::Installed) ? st::stickersUndoRemove : st::stickersTrendingAdd;
|
|
|
|
auto textWidth = (_section == Section::Installed) ? _undoWidth : _addWidth;
|
|
|
|
buttonw = textWidth - st.width;
|
|
|
|
buttonh = st.height;
|
|
|
|
buttonshift = 0;
|
|
|
|
}
|
|
|
|
auto buttonx = width() - st::contactsPadding.right() - st::contactsCheckPosition.x() - buttonw + buttonshift;
|
|
|
|
auto buttony = st::contactsPadding.top() + (st::contactsPhotoSize - buttonh) / 2;
|
|
|
|
return QRect(buttonx, buttony, buttonw, buttonh);
|
2016-11-16 16:04:25 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::Inner::paintRow(Painter &p, Row *set, int index, TimeMs ms) {
|
|
|
|
auto xadd = 0, yadd = qRound(set->yadd.current());
|
2016-10-20 16:32:15 +00:00
|
|
|
if (xadd || yadd) p.translate(xadd, yadd);
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
if (_megagroupSet) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto selectedIndex = [&] {
|
|
|
|
if (auto index = base::get_if<int>(&_selected)) {
|
|
|
|
return *index;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}();
|
|
|
|
if (index >= 0 && index == selectedIndex) {
|
2017-08-05 20:01:20 +00:00
|
|
|
p.fillRect(0, 0, width(), _rowHeight, st::contactsBgOver);
|
|
|
|
if (set->ripple) {
|
|
|
|
set->ripple->paint(p, 0, 0, width(), ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_section == Section::Installed) {
|
2017-08-05 20:01:20 +00:00
|
|
|
if (index >= 0 && index == _above) {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto current = _aboveShadowFadeOpacity.current();
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_started >= 0) {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto reachedOpacity = aboveShadowOpacity();
|
|
|
|
if (reachedOpacity > current) {
|
|
|
|
_aboveShadowFadeOpacity = anim::value(reachedOpacity, reachedOpacity);
|
|
|
|
current = reachedOpacity;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
auto row = myrtlrect(st::contactsPadding.left() / 2, st::contactsPadding.top() / 2, width() - (st::contactsPadding.left() / 2) - _scrollbar - st::contactsPadding.left() / 2, _rowHeight - ((st::contactsPadding.top() + st::contactsPadding.bottom()) / 2));
|
2016-10-20 16:32:15 +00:00
|
|
|
p.setOpacity(current);
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::Shadow::paint(p, row, width(), st::boxRoundShadow);
|
2016-10-20 16:32:15 +00:00
|
|
|
p.setOpacity(1);
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
App::roundRect(p, row, st::boxBg, BoxCorners);
|
|
|
|
|
|
|
|
p.setOpacity(1. - current);
|
2017-08-05 20:01:20 +00:00
|
|
|
paintFakeButton(p, set, index, ms);
|
2016-12-13 17:07:56 +00:00
|
|
|
p.setOpacity(1.);
|
2017-08-05 10:48:21 +00:00
|
|
|
} else if (!_megagroupSet) {
|
2017-08-05 20:01:20 +00:00
|
|
|
paintFakeButton(p, set, index, ms);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2017-08-05 10:48:21 +00:00
|
|
|
} else if (!_megagroupSet) {
|
2017-08-05 20:01:20 +00:00
|
|
|
paintFakeButton(p, set, index, ms);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
if (set->removed && _section == Section::Installed) {
|
2016-10-20 16:32:15 +00:00
|
|
|
p.setOpacity(st::stickersRowDisabledOpacity);
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
|
|
|
|
auto stickerx = st::contactsPadding.left();
|
|
|
|
|
2017-08-05 10:48:21 +00:00
|
|
|
if (!_megagroupSet && _section == Section::Installed) {
|
2016-11-22 09:48:13 +00:00
|
|
|
stickerx += st::stickersReorderIcon.width() + st::stickersReorderSkip;
|
2017-08-05 20:01:20 +00:00
|
|
|
if (!set->isRecentSet()) {
|
2016-11-22 09:48:13 +00:00
|
|
|
st::stickersReorderIcon.paint(p, st::contactsPadding.left(), (_rowHeight - st::stickersReorderIcon.height()) / 2, width());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
if (set->sticker) {
|
2018-07-13 21:25:47 +00:00
|
|
|
const auto origin = Data::FileOriginStickerSet(
|
|
|
|
set->id,
|
|
|
|
set->accessHash);
|
|
|
|
set->sticker->thumb->load(origin);
|
|
|
|
auto pix = set->sticker->thumb->pix(origin, set->pixw, set->pixh);
|
2017-08-05 20:01:20 +00:00
|
|
|
p.drawPixmapLeft(stickerx + (st::contactsPhotoSize - set->pixw) / 2, st::contactsPadding.top() + (st::contactsPhotoSize - set->pixh) / 2, width(), pix);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
int namex = stickerx + st::contactsPhotoSize + st::contactsPadding.left();
|
2016-10-20 16:32:15 +00:00
|
|
|
int namey = st::contactsPadding.top() + st::contactsNameTop;
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
int statusx = namex;
|
|
|
|
int statusy = st::contactsPadding.top() + st::contactsStatusTop;
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setFont(st::contactsNameStyle.font);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::contactsNameFg);
|
2017-08-05 20:01:20 +00:00
|
|
|
p.drawTextLeft(namex, namey, width(), set->title, set->titleWidth);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
if (set->unread) {
|
2016-10-20 16:32:15 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::stickersFeaturedUnreadBg);
|
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
2017-08-05 20:01:20 +00:00
|
|
|
p.drawEllipse(rtlrect(namex + set->titleWidth + st::stickersFeaturedUnreadSkip, namey + st::stickersFeaturedUnreadTop, st::stickersFeaturedUnreadSize, st::stickersFeaturedUnreadSize, width()));
|
2016-12-03 12:10:35 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
auto statusText = (set->count > 0) ? lng_stickers_count(lt_count, set->count) : lang(lng_contacts_loading);
|
2017-06-02 11:46:02 +00:00
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
p.setFont(st::contactsStatusFont);
|
|
|
|
p.setPen(st::contactsStatusFg);
|
2017-06-02 11:46:02 +00:00
|
|
|
p.drawTextLeft(statusx, statusy, width(), statusText);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
p.setOpacity(1);
|
|
|
|
if (xadd || yadd) p.translate(-xadd, -yadd);
|
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::Inner::paintFakeButton(Painter &p, Row *set, int index, TimeMs ms) {
|
2016-11-22 09:48:13 +00:00
|
|
|
auto removeButton = (_section == Section::Installed && !set->removed);
|
|
|
|
auto rect = relativeButtonRect(removeButton);
|
|
|
|
if (_section != Section::Installed && set->installed && !set->archived && !set->removed) {
|
|
|
|
// Checkbox after installed from Trending or Archived.
|
|
|
|
int checkx = width() - (st::contactsPadding.right() + st::contactsCheckPosition.x() + (rect.width() + st::stickersFeaturedInstalled.width()) / 2);
|
|
|
|
int checky = st::contactsPadding.top() + (st::contactsPhotoSize - st::stickersFeaturedInstalled.height()) / 2;
|
|
|
|
st::stickersFeaturedInstalled.paint(p, QPoint(checkx, checky), width());
|
|
|
|
} else {
|
|
|
|
auto selected = (index == _actionSel && _actionDown < 0) || (index == _actionDown);
|
|
|
|
if (removeButton) {
|
|
|
|
// Trash icon button when not disabled in Installed.
|
|
|
|
if (set->ripple) {
|
|
|
|
set->ripple->paint(p, rect.x(), rect.y(), width(), ms);
|
|
|
|
if (set->ripple->empty()) {
|
|
|
|
set->ripple.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto &icon = selected ? st::stickersRemove.iconOver : st::stickersRemove.icon;
|
|
|
|
auto position = st::stickersRemove.iconPosition;
|
|
|
|
if (position.x() < 0) position.setX((rect.width() - icon.width()) / 2);
|
|
|
|
if (position.y() < 0) position.setY((rect.height() - icon.height()) / 2);
|
|
|
|
icon.paint(p, rect.topLeft() + position, ms);
|
|
|
|
} else {
|
|
|
|
// Round button ADD when not installed from Trending or Archived.
|
|
|
|
// Or round button UNDO after disabled from Installed.
|
|
|
|
auto &st = (_section == Section::Installed) ? st::stickersUndoRemove : st::stickersTrendingAdd;
|
|
|
|
auto textWidth = (_section == Section::Installed) ? _undoWidth : _addWidth;
|
|
|
|
auto &text = (_section == Section::Installed) ? _undoText : _addText;
|
|
|
|
auto &textBg = selected ? st.textBgOver : st.textBg;
|
|
|
|
App::roundRect(p, myrtlrect(rect), textBg, ImageRoundRadius::Small);
|
|
|
|
if (set->ripple) {
|
|
|
|
set->ripple->paint(p, rect.x(), rect.y(), width(), ms);
|
|
|
|
if (set->ripple->empty()) {
|
|
|
|
set->ripple.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p.setFont(st.font);
|
|
|
|
p.setPen(selected ? st.textFgOver : st.textFg);
|
|
|
|
p.drawTextLeft(rect.x() - (st.width / 2), rect.y() + st.textTop, width(), text, textWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void StickersBox::Inner::mousePressEvent(QMouseEvent *e) {
|
|
|
|
if (_dragging >= 0) mouseReleaseEvent(e);
|
|
|
|
_mouse = e->globalPos();
|
|
|
|
onUpdateSelected();
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
setPressed(_selected);
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_actionSel >= 0) {
|
2016-11-16 16:04:25 +00:00
|
|
|
setActionDown(_actionSel);
|
2016-10-20 16:32:15 +00:00
|
|
|
update(0, _itemsTop + _actionSel * _rowHeight, width(), _rowHeight);
|
2017-11-05 17:07:27 +00:00
|
|
|
} else if (auto selectedIndex = base::get_if<int>(&_selected)) {
|
|
|
|
if (_section == Section::Installed && !_rows[*selectedIndex]->isRecentSet() && _inDragArea) {
|
|
|
|
_above = _dragging = _started = *selectedIndex;
|
|
|
|
_dragStart = mapFromGlobal(_mouse);
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
void StickersBox::Inner::setActionDown(int newActionDown) {
|
|
|
|
if (_actionDown == newActionDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_actionDown >= 0 && _actionDown < _rows.size()) {
|
|
|
|
update(0, _itemsTop + _actionDown * _rowHeight, width(), _rowHeight);
|
2017-08-05 20:01:20 +00:00
|
|
|
auto &set = _rows[_actionDown];
|
2016-11-16 16:04:25 +00:00
|
|
|
if (set->ripple) {
|
|
|
|
set->ripple->lastStop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_actionDown = newActionDown;
|
|
|
|
if (_actionDown >= 0 && _actionDown < _rows.size()) {
|
|
|
|
update(0, _itemsTop + _actionDown * _rowHeight, width(), _rowHeight);
|
2017-08-05 20:01:20 +00:00
|
|
|
auto &set = _rows[_actionDown];
|
2016-11-22 09:48:13 +00:00
|
|
|
auto removeButton = (_section == Section::Installed && !set->removed);
|
2016-11-16 16:04:25 +00:00
|
|
|
if (!set->ripple) {
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_section == Section::Installed) {
|
|
|
|
if (set->removed) {
|
|
|
|
auto rippleSize = QSize(_undoWidth - st::stickersUndoRemove.width, st::stickersUndoRemove.height);
|
|
|
|
auto rippleMask = Ui::RippleAnimation::roundRectMask(rippleSize, st::buttonRadius);
|
2017-02-21 13:45:56 +00:00
|
|
|
ensureRipple(st::stickersUndoRemove.ripple, std::move(rippleMask), removeButton);
|
2016-11-22 09:48:13 +00:00
|
|
|
} else {
|
|
|
|
auto rippleSize = st::stickersRemove.rippleAreaSize;
|
|
|
|
auto rippleMask = Ui::RippleAnimation::ellipseMask(QSize(rippleSize, rippleSize));
|
2017-02-21 13:45:56 +00:00
|
|
|
ensureRipple(st::stickersRemove.ripple, std::move(rippleMask), removeButton);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
} else if (!set->installed || set->archived || set->removed) {
|
|
|
|
auto rippleSize = QSize(_addWidth - st::stickersTrendingAdd.width, st::stickersTrendingAdd.height);
|
|
|
|
auto rippleMask = Ui::RippleAnimation::roundRectMask(rippleSize, st::buttonRadius);
|
2017-02-21 13:45:56 +00:00
|
|
|
ensureRipple(st::stickersTrendingAdd.ripple, std::move(rippleMask), removeButton);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (set->ripple) {
|
|
|
|
auto rect = relativeButtonRect(removeButton);
|
|
|
|
set->ripple->add(mapFromGlobal(QCursor::pos()) - QPoint(myrtlrect(rect).x(), _itemsTop + _actionDown * _rowHeight + rect.y()));
|
2016-11-16 16:04:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
void StickersBox::Inner::setSelected(SelectedRow selected) {
|
2017-08-05 20:01:20 +00:00
|
|
|
if (_selected == selected) {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
if ((_megagroupSet || _section != Section::Installed)
|
|
|
|
&& ((_selected.has_value() || _pressed.has_value()) != (selected.has_value() || _pressed.has_value()))) {
|
|
|
|
if (!_inDragArea) {
|
|
|
|
setCursor((selected.has_value() || _pressed.has_value())
|
|
|
|
? style::cur_pointer
|
|
|
|
: style::cur_default);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto countSelectedIndex = [&] {
|
|
|
|
if (auto index = base::get_if<int>(&_selected)) {
|
|
|
|
return *index;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
auto selectedIndex = countSelectedIndex();
|
|
|
|
if (_megagroupSet && selectedIndex >= 0 && selectedIndex < _rows.size()) {
|
|
|
|
update(0, _itemsTop + selectedIndex * _rowHeight, width(), _rowHeight);
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
_selected = selected;
|
2017-11-05 17:07:27 +00:00
|
|
|
selectedIndex = countSelectedIndex();
|
|
|
|
if (_megagroupSet && selectedIndex >= 0 && selectedIndex < _rows.size()) {
|
|
|
|
update(0, _itemsTop + selectedIndex * _rowHeight, width(), _rowHeight);
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
void StickersBox::Inner::setPressed(SelectedRow pressed) {
|
2017-08-05 20:01:20 +00:00
|
|
|
if (_pressed == pressed) {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
auto countPressedIndex = [&] {
|
|
|
|
if (auto index = base::get_if<int>(&_pressed)) {
|
|
|
|
return *index;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
auto pressedIndex = countPressedIndex();
|
|
|
|
if (_megagroupSet && pressedIndex >= 0 && pressedIndex < _rows.size()) {
|
|
|
|
update(0, _itemsTop + pressedIndex * _rowHeight, width(), _rowHeight);
|
|
|
|
auto &set = _rows[pressedIndex];
|
2017-08-05 20:01:20 +00:00
|
|
|
if (set->ripple) {
|
|
|
|
set->ripple->lastStop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_pressed = pressed;
|
2017-11-05 17:07:27 +00:00
|
|
|
pressedIndex = countPressedIndex();
|
|
|
|
if (_megagroupSet && pressedIndex >= 0 && pressedIndex < _rows.size()) {
|
|
|
|
update(0, _itemsTop + pressedIndex * _rowHeight, width(), _rowHeight);
|
|
|
|
auto &set = _rows[pressedIndex];
|
2017-08-05 20:01:20 +00:00
|
|
|
auto rippleMask = Ui::RippleAnimation::rectMask(QSize(width(), _rowHeight));
|
2017-11-05 17:07:27 +00:00
|
|
|
if (!_rows[pressedIndex]->ripple) {
|
|
|
|
_rows[pressedIndex]->ripple = std::make_unique<Ui::RippleAnimation>(st::contactsRipple, std::move(rippleMask), [this, pressedIndex] {
|
|
|
|
update(0, _itemsTop + pressedIndex * _rowHeight, width(), _rowHeight);
|
2017-08-05 20:01:20 +00:00
|
|
|
});
|
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
_rows[pressedIndex]->ripple->add(mapFromGlobal(QCursor::pos()) - QPoint(0, _itemsTop + pressedIndex * _rowHeight));
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::Inner::ensureRipple(const style::RippleAnimation &st, QImage mask, bool removeButton) {
|
2017-08-05 20:01:20 +00:00
|
|
|
_rows[_actionDown]->ripple = std::make_unique<Ui::RippleAnimation>(st, std::move(mask), [this, index = _actionDown, removeButton] {
|
2016-11-22 09:48:13 +00:00
|
|
|
update(myrtlrect(relativeButtonRect(removeButton).translated(0, _itemsTop + index * _rowHeight)));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void StickersBox::Inner::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
_mouse = e->globalPos();
|
|
|
|
onUpdateSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::onUpdateSelected() {
|
2016-12-01 19:20:33 +00:00
|
|
|
auto local = mapFromGlobal(_mouse);
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_dragging >= 0) {
|
2016-12-01 19:20:33 +00:00
|
|
|
auto shift = 0;
|
|
|
|
auto ms = getms();
|
2016-10-20 16:32:15 +00:00
|
|
|
int firstSetIndex = 0;
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_rows.at(firstSetIndex)->isRecentSet()) {
|
2016-10-20 16:32:15 +00:00
|
|
|
++firstSetIndex;
|
|
|
|
}
|
|
|
|
if (_dragStart.y() > local.y() && _dragging > 0) {
|
|
|
|
shift = -floorclamp(_dragStart.y() - local.y() + (_rowHeight / 2), _rowHeight, 0, _dragging - firstSetIndex);
|
|
|
|
for (int32 from = _dragging, to = _dragging + shift; from > to; --from) {
|
|
|
|
qSwap(_rows[from], _rows[from - 1]);
|
2016-12-05 11:01:08 +00:00
|
|
|
_rows[from]->yadd = anim::value(_rows[from]->yadd.current() - _rowHeight, 0);
|
2016-10-20 16:32:15 +00:00
|
|
|
_animStartTimes[from] = ms;
|
|
|
|
}
|
|
|
|
} else if (_dragStart.y() < local.y() && _dragging + 1 < _rows.size()) {
|
|
|
|
shift = floorclamp(local.y() - _dragStart.y() + (_rowHeight / 2), _rowHeight, 0, _rows.size() - _dragging - 1);
|
|
|
|
for (int32 from = _dragging, to = _dragging + shift; from < to; ++from) {
|
|
|
|
qSwap(_rows[from], _rows[from + 1]);
|
2016-12-05 11:01:08 +00:00
|
|
|
_rows[from]->yadd = anim::value(_rows[from]->yadd.current() + _rowHeight, 0);
|
2016-10-20 16:32:15 +00:00
|
|
|
_animStartTimes[from] = ms;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (shift) {
|
|
|
|
_dragging += shift;
|
|
|
|
_above = _dragging;
|
|
|
|
_dragStart.setY(_dragStart.y() + shift * _rowHeight);
|
|
|
|
if (!_a_shifting.animating()) {
|
|
|
|
_a_shifting.start();
|
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
_rows[_dragging]->yadd = anim::value(local.y() - _dragStart.y(), local.y() - _dragStart.y());
|
2016-10-20 16:32:15 +00:00
|
|
|
_animStartTimes[_dragging] = 0;
|
2017-01-30 15:27:13 +00:00
|
|
|
_a_shifting.step(ms, true);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
auto countDraggingScrollDelta = [this, local] {
|
|
|
|
if (local.y() < _visibleTop) {
|
|
|
|
return local.y() - _visibleTop;
|
|
|
|
} else if (local.y() >= _visibleBottom) {
|
|
|
|
return local.y() + 1 - _visibleBottom;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
emit draggingScrollDelta(countDraggingScrollDelta());
|
2016-10-20 16:32:15 +00:00
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
bool in = rect().marginsRemoved(QMargins(0, _itemsTop, 0, st::membersMarginBottom)).contains(local);
|
2017-11-05 17:07:27 +00:00
|
|
|
auto selected = SelectedRow();
|
2016-11-22 09:48:13 +00:00
|
|
|
auto actionSel = -1;
|
|
|
|
auto inDragArea = false;
|
2017-08-05 20:01:20 +00:00
|
|
|
if (in && !_rows.empty()) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto selectedIndex = floorclamp(local.y() - _itemsTop, _rowHeight, 0, _rows.size() - 1);
|
|
|
|
selected = selectedIndex;
|
|
|
|
local.setY(local.y() - _itemsTop - selectedIndex * _rowHeight);
|
|
|
|
auto &set = _rows[selectedIndex];
|
2017-08-05 10:48:21 +00:00
|
|
|
if (!_megagroupSet && (_section == Section::Installed || !set->installed || set->archived || set->removed)) {
|
2016-11-22 09:48:13 +00:00
|
|
|
auto removeButton = (_section == Section::Installed && !set->removed);
|
|
|
|
auto rect = myrtlrect(relativeButtonRect(removeButton));
|
2017-11-05 17:07:27 +00:00
|
|
|
actionSel = rect.contains(local) ? selectedIndex : -1;
|
2016-10-20 16:32:15 +00:00
|
|
|
} else {
|
2016-11-22 09:48:13 +00:00
|
|
|
actionSel = -1;
|
|
|
|
}
|
2017-08-05 10:48:21 +00:00
|
|
|
if (!_megagroupSet && _section == Section::Installed && !set->isRecentSet()) {
|
2016-11-22 09:48:13 +00:00
|
|
|
auto dragAreaWidth = st::contactsPadding.left() + st::stickersReorderIcon.width() + st::stickersReorderSkip;
|
|
|
|
auto dragArea = myrtlrect(0, 0, dragAreaWidth, _rowHeight);
|
|
|
|
inDragArea = dragArea.contains(local);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
} else if (_megagroupSelectedSet) {
|
|
|
|
auto setTop = _megagroupDivider->y() - _rowHeight;
|
|
|
|
if (QRect(0, setTop, width(), _rowHeight).contains(local)) {
|
|
|
|
selected = MegagroupSet();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
setSelected(selected);
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_inDragArea != inDragArea) {
|
|
|
|
_inDragArea = inDragArea;
|
2017-11-05 17:07:27 +00:00
|
|
|
setCursor(_inDragArea
|
|
|
|
? style::cur_sizeall
|
|
|
|
: ((_selected.has_value() || _pressed.has_value())
|
|
|
|
? style::cur_pointer
|
|
|
|
: style::cur_default));
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
setActionSel(actionSel);
|
2016-12-13 17:07:56 +00:00
|
|
|
emit draggingScrollDelta(0);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 StickersBox::Inner::aboveShadowOpacity() const {
|
|
|
|
if (_above < 0) return 0;
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto dx = 0;
|
|
|
|
auto dy = qAbs(_above * _rowHeight + qRound(_rows[_above]->yadd.current()) - _started * _rowHeight);
|
2016-10-20 16:32:15 +00:00
|
|
|
return qMin((dx + dy) * 2. / _rowHeight, 1.);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto pressed = std::exchange(_pressed, SelectedRow());
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
if (_section != Section::Installed && !_selected.has_value() && pressed.has_value()) {
|
2016-10-20 16:32:15 +00:00
|
|
|
setCursor(style::cur_default);
|
|
|
|
}
|
|
|
|
|
|
|
|
_mouse = e->globalPos();
|
|
|
|
onUpdateSelected();
|
|
|
|
if (_actionDown == _actionSel && _actionSel >= 0) {
|
|
|
|
if (_section == Section::Installed) {
|
2016-11-22 09:48:13 +00:00
|
|
|
setRowRemoved(_actionDown, !_rows[_actionDown]->removed);
|
|
|
|
} else if (_installSetCallback) {
|
|
|
|
_installSetCallback(_rows[_actionDown]->id);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
} else if (_dragging >= 0) {
|
|
|
|
QPoint local(mapFromGlobal(_mouse));
|
2016-12-05 11:01:08 +00:00
|
|
|
_rows[_dragging]->yadd.start(0.);
|
2016-10-20 16:32:15 +00:00
|
|
|
_aboveShadowFadeStart = _animStartTimes[_dragging] = getms();
|
2016-12-05 11:01:08 +00:00
|
|
|
_aboveShadowFadeOpacity = anim::value(aboveShadowOpacity(), 0);
|
2016-10-20 16:32:15 +00:00
|
|
|
if (!_a_shifting.animating()) {
|
|
|
|
_a_shifting.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
_dragging = _started = -1;
|
|
|
|
} else if (pressed == _selected && _actionSel < 0 && _actionDown < 0) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto selectedIndex = [&] {
|
|
|
|
if (auto index = base::get_if<int>(&_selected)) {
|
|
|
|
return *index;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}();
|
|
|
|
auto getSetByRow = [&](const Row &row) -> const Stickers::Set* {
|
|
|
|
auto &sets = Auth().data().stickerSetsRef();
|
|
|
|
if (!row.isRecentSet()) {
|
|
|
|
auto it = sets.find(row.id);
|
2016-12-09 06:19:55 +00:00
|
|
|
if (it != sets.cend()) {
|
2017-11-05 17:07:27 +00:00
|
|
|
return &*it;
|
2016-12-09 06:19:55 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
auto showSetByRow = [&](const Row &row) {
|
|
|
|
if (auto set = getSetByRow(row)) {
|
|
|
|
setSelected(SelectedRow());
|
|
|
|
Ui::show(
|
|
|
|
Box<StickerSetBox>(Stickers::inputSetId(*set)),
|
|
|
|
LayerOption::KeepOther);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (selectedIndex >= 0 && !_inDragArea) {
|
|
|
|
auto &row = *_rows[selectedIndex];
|
|
|
|
if (_megagroupSet) {
|
|
|
|
if (auto set = getSetByRow(row)) {
|
|
|
|
setMegagroupSelectedSet(MTP_inputStickerSetID(
|
|
|
|
MTP_long(set->id),
|
|
|
|
MTP_long(set->access)));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
showSetByRow(row);
|
|
|
|
}
|
|
|
|
} else if (_megagroupSelectedSet && _selected.is<MegagroupSet>()) {
|
|
|
|
showSetByRow(*_megagroupSelectedSet);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-16 16:04:25 +00:00
|
|
|
setActionDown(-1);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::Inner::saveGroupSet() {
|
|
|
|
Expects(_megagroupSet != nullptr);
|
|
|
|
auto oldId = (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) ? _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID().vid.v : 0;
|
|
|
|
auto newId = (_megagroupSetInput.type() == mtpc_inputStickerSetID) ? _megagroupSetInput.c_inputStickerSetID().vid.v : 0;
|
|
|
|
if (newId != oldId) {
|
|
|
|
Auth().api().setGroupStickerSet(_megagroupSet, _megagroupSetInput);
|
2017-09-16 16:53:41 +00:00
|
|
|
Auth().api().stickerSetInstalled(Stickers::MegagroupSetId);
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::Inner::setRowRemoved(int index, bool removed) {
|
2017-08-05 20:01:20 +00:00
|
|
|
auto &row = _rows[index];
|
2016-11-22 09:48:13 +00:00
|
|
|
if (row->removed != removed) {
|
|
|
|
row->removed = removed;
|
|
|
|
row->ripple.reset();
|
|
|
|
update(0, _itemsTop + index * _rowHeight, width(), _rowHeight);
|
|
|
|
onUpdateSelected();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void StickersBox::Inner::leaveEventHook(QEvent *e) {
|
2016-11-22 09:48:13 +00:00
|
|
|
_mouse = QPoint(-1, -1);
|
|
|
|
onUpdateSelected();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::Inner::leaveToChildEvent(QEvent *e, QWidget *child) {
|
|
|
|
_mouse = QPoint(-1, -1);
|
|
|
|
onUpdateSelected();
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void StickersBox::Inner::step_shifting(TimeMs ms, bool timer) {
|
2018-09-20 16:39:59 +00:00
|
|
|
if (anim::Disabled()) {
|
|
|
|
ms += st::stickersRowDuration;
|
|
|
|
}
|
2016-12-01 19:20:33 +00:00
|
|
|
auto animating = false;
|
|
|
|
auto updateMin = -1;
|
|
|
|
auto updateMax = 0;
|
|
|
|
for (auto i = 0, l = _animStartTimes.size(); i < l; ++i) {
|
|
|
|
auto start = _animStartTimes.at(i);
|
2016-10-20 16:32:15 +00:00
|
|
|
if (start) {
|
|
|
|
if (updateMin < 0) updateMin = i;
|
|
|
|
updateMax = i;
|
|
|
|
if (start + st::stickersRowDuration > ms && ms >= start) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_rows[i]->yadd.update(float64(ms - start) / st::stickersRowDuration, anim::sineInOut);
|
2016-10-20 16:32:15 +00:00
|
|
|
animating = true;
|
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
_rows[i]->yadd.finish();
|
2016-10-20 16:32:15 +00:00
|
|
|
_animStartTimes[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_aboveShadowFadeStart) {
|
|
|
|
if (updateMin < 0 || updateMin > _above) updateMin = _above;
|
|
|
|
if (updateMax < _above) updateMin = _above;
|
|
|
|
if (_aboveShadowFadeStart + st::stickersRowDuration > ms && ms > _aboveShadowFadeStart) {
|
|
|
|
_aboveShadowFadeOpacity.update(float64(ms - _aboveShadowFadeStart) / st::stickersRowDuration, anim::sineInOut);
|
|
|
|
animating = true;
|
|
|
|
} else {
|
|
|
|
_aboveShadowFadeOpacity.finish();
|
|
|
|
_aboveShadowFadeStart = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (timer) {
|
|
|
|
if (_dragging >= 0) {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (updateMin < 0 || updateMin > _dragging) {
|
|
|
|
updateMin = _dragging;
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
if (updateMax < _dragging) updateMax = _dragging;
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
if (updateMin == 1 && _rows[0]->isRecentSet()) {
|
|
|
|
updateMin = 0; // Repaint from the very top of the content.
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
if (updateMin >= 0) {
|
|
|
|
update(0, _itemsTop + _rowHeight * (updateMin - 1), width(), _rowHeight * (updateMax - updateMin + 3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!animating) {
|
|
|
|
_above = _dragging;
|
|
|
|
_a_shifting.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::clear() {
|
|
|
|
_rows.clear();
|
|
|
|
_animStartTimes.clear();
|
|
|
|
_aboveShadowFadeStart = 0;
|
2016-12-05 11:01:08 +00:00
|
|
|
_aboveShadowFadeOpacity = anim::value();
|
2016-10-20 16:32:15 +00:00
|
|
|
_a_shifting.stop();
|
|
|
|
_above = _dragging = _started = -1;
|
2017-11-05 17:07:27 +00:00
|
|
|
setSelected(SelectedRow());
|
|
|
|
setPressed(SelectedRow());
|
2016-10-20 16:32:15 +00:00
|
|
|
setActionSel(-1);
|
2017-08-05 20:01:20 +00:00
|
|
|
setActionDown(-1);
|
2016-10-20 16:32:15 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::setActionSel(int32 actionSel) {
|
|
|
|
if (actionSel != _actionSel) {
|
|
|
|
if (_actionSel >= 0) update(0, _itemsTop + _actionSel * _rowHeight, width(), _rowHeight);
|
|
|
|
_actionSel = actionSel;
|
|
|
|
if (_actionSel >= 0) update(0, _itemsTop + _actionSel * _rowHeight, width(), _rowHeight);
|
|
|
|
if (_section == Section::Installed) {
|
|
|
|
setCursor((_actionSel >= 0 && (_actionDown < 0 || _actionDown == _actionSel)) ? style::cur_pointer : style::cur_default);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
void StickersBox::Inner::AddressField::correctValue(
|
|
|
|
const QString &was,
|
|
|
|
int wasCursor,
|
|
|
|
QString &now,
|
|
|
|
int &nowCursor) {
|
|
|
|
auto newText = now;
|
|
|
|
auto newCursor = nowCursor;
|
|
|
|
auto removeFromBeginning = {
|
|
|
|
qstr("http://"),
|
|
|
|
qstr("https://"),
|
|
|
|
qstr("www.t.me/"),
|
|
|
|
qstr("www.telegram.me/"),
|
|
|
|
qstr("www.telegram.dog/"),
|
|
|
|
qstr("t.me/"),
|
|
|
|
qstr("telegram.me/"),
|
|
|
|
qstr("telegram.dog/"),
|
|
|
|
qstr("addstickers/"),
|
|
|
|
};
|
|
|
|
for (auto &removePhrase : removeFromBeginning) {
|
|
|
|
if (newText.startsWith(removePhrase)) {
|
|
|
|
newText = newText.mid(removePhrase.size());
|
|
|
|
newCursor = newText.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setCorrectedText(now, nowCursor, newText, newCursor);
|
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::Inner::handleMegagroupSetAddressChange() {
|
|
|
|
auto text = _megagroupSetField->getLastText().trimmed();
|
|
|
|
if (text.isEmpty()) {
|
|
|
|
if (_megagroupSelectedSet) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto it = Auth().data().stickerSets().constFind(_megagroupSelectedSet->id);
|
|
|
|
if (it != Auth().data().stickerSets().cend() && !it->shortName.isEmpty()) {
|
2017-08-05 20:01:20 +00:00
|
|
|
setMegagroupSelectedSet(MTP_inputStickerSetEmpty());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!_megagroupSetRequestId) {
|
|
|
|
_megagroupSetRequestId = request(MTPmessages_GetStickerSet(MTP_inputStickerSetShortName(MTP_string(text)))).done([this](const MTPmessages_StickerSet &result) {
|
|
|
|
_megagroupSetRequestId = 0;
|
|
|
|
auto set = Stickers::FeedSetFull(result);
|
|
|
|
setMegagroupSelectedSet(MTP_inputStickerSetID(MTP_long(set->id), MTP_long(set->access)));
|
|
|
|
}).fail([this](const RPCError &error) {
|
|
|
|
_megagroupSetRequestId = 0;
|
|
|
|
setMegagroupSelectedSet(MTP_inputStickerSetEmpty());
|
|
|
|
}).send();
|
|
|
|
} else {
|
|
|
|
_megagroupSetAddressChangedTimer.callOnce(kHandleMegagroupSetAddressChangeTimeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::rebuildMegagroupSet() {
|
|
|
|
Expects(_megagroupSet != nullptr);
|
|
|
|
if (_megagroupSetInput.type() != mtpc_inputStickerSetID) {
|
|
|
|
if (_megagroupSelectedSet) {
|
|
|
|
_megagroupSetField->setText(QString());
|
2017-09-30 19:20:40 +00:00
|
|
|
_megagroupSetField->finishAnimating();
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
_megagroupSelectedSet.reset();
|
|
|
|
_megagroupSelectedRemove.destroy();
|
|
|
|
_megagroupSelectedShadow.destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto &set = _megagroupSetInput.c_inputStickerSetID();
|
|
|
|
auto setId = set.vid.v;
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSets();
|
2017-08-05 20:01:20 +00:00
|
|
|
auto it = sets.find(setId);
|
|
|
|
if (it == sets.cend() || (it->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) {
|
|
|
|
Auth().api().scheduleStickerSetRequest(set.vid.v, set.vaccess_hash.v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto maxNameWidth = countMaxNameWidth();
|
|
|
|
auto titleWidth = 0;
|
|
|
|
auto title = fillSetTitle(*it, maxNameWidth, &titleWidth);
|
|
|
|
auto count = fillSetCount(*it);
|
|
|
|
auto sticker = (DocumentData*)nullptr;
|
|
|
|
auto pixw = 0, pixh = 0;
|
|
|
|
fillSetCover(*it, &sticker, &pixw, &pixh);
|
|
|
|
auto installed = true, official = false, unread = false, archived = false, removed = false;
|
|
|
|
if (!_megagroupSelectedSet || _megagroupSelectedSet->id != it->id) {
|
|
|
|
_megagroupSetField->setText(it->shortName);
|
2017-09-30 19:20:40 +00:00
|
|
|
_megagroupSetField->finishAnimating();
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
2018-07-13 21:25:47 +00:00
|
|
|
_megagroupSelectedSet = std::make_unique<Row>(
|
|
|
|
it->id,
|
|
|
|
it->access,
|
|
|
|
sticker,
|
|
|
|
count,
|
|
|
|
title,
|
|
|
|
titleWidth,
|
|
|
|
installed,
|
|
|
|
official,
|
|
|
|
unread,
|
|
|
|
archived,
|
|
|
|
removed,
|
|
|
|
pixw,
|
|
|
|
pixh);
|
2017-08-05 20:01:20 +00:00
|
|
|
_itemsTop += st::lineWidth + _rowHeight;
|
|
|
|
|
|
|
|
if (!_megagroupSelectedRemove) {
|
|
|
|
_megagroupSelectedRemove.create(this, st::groupStickersRemove);
|
2017-11-27 11:43:57 +00:00
|
|
|
_megagroupSelectedRemove->show(anim::type::instant);
|
2017-08-05 20:01:20 +00:00
|
|
|
_megagroupSelectedRemove->setClickedCallback([this] {
|
|
|
|
setMegagroupSelectedSet(MTP_inputStickerSetEmpty());
|
|
|
|
});
|
|
|
|
_megagroupSelectedShadow.create(this);
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void StickersBox::Inner::rebuild() {
|
2016-12-13 17:07:56 +00:00
|
|
|
_itemsTop = st::membersMarginTop;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
if (_megagroupSet) {
|
|
|
|
_itemsTop += st::groupStickersFieldPadding.top() + _megagroupSetField->height() + st::groupStickersFieldPadding.bottom();
|
|
|
|
_itemsTop += _megagroupDivider->height() + st::groupStickersSubTitleHeight;
|
|
|
|
rebuildMegagroupSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto maxNameWidth = countMaxNameWidth();
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
clear();
|
2017-11-22 09:03:36 +00:00
|
|
|
auto &order = ([&]() -> const Stickers::Order & {
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_section == Section::Installed) {
|
2017-11-22 09:03:36 +00:00
|
|
|
auto &result = Auth().data().stickerSetsOrder();
|
|
|
|
if (_megagroupSet && result.empty()) {
|
|
|
|
return Auth().data().featuredStickerSetsOrder();
|
|
|
|
}
|
|
|
|
return result;
|
2016-10-20 16:32:15 +00:00
|
|
|
} else if (_section == Section::Featured) {
|
2017-11-05 17:07:27 +00:00
|
|
|
return Auth().data().featuredStickerSetsOrder();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
return Auth().data().archivedStickerSetsOrder();
|
2016-10-20 16:32:15 +00:00
|
|
|
})();
|
|
|
|
_rows.reserve(order.size() + 1);
|
|
|
|
_animStartTimes.reserve(order.size() + 1);
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSets();
|
2017-11-22 09:03:36 +00:00
|
|
|
if (_megagroupSet) {
|
|
|
|
auto usingFeatured = Auth().data().stickerSetsOrder().empty();
|
|
|
|
_megagroupSubTitle->setText(lang(usingFeatured
|
|
|
|
? lng_stickers_group_from_featured
|
|
|
|
: lng_stickers_group_from_your));
|
|
|
|
updateControlsGeometry();
|
|
|
|
} else if (_section == Section::Installed) {
|
2016-10-20 16:32:15 +00:00
|
|
|
auto cloudIt = sets.constFind(Stickers::CloudRecentSetId);
|
|
|
|
if (cloudIt != sets.cend() && !cloudIt->stickers.isEmpty()) {
|
|
|
|
rebuildAppendSet(cloudIt.value(), maxNameWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for_const (auto setId, order) {
|
|
|
|
auto it = sets.constFind(setId);
|
|
|
|
if (it == sets.cend()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
rebuildAppendSet(it.value(), maxNameWidth);
|
|
|
|
|
|
|
|
if (it->stickers.isEmpty() || (it->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) {
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().scheduleStickerSetRequest(it->id, it->access);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-04 14:54:32 +00:00
|
|
|
Auth().api().requestStickerSets();
|
2016-10-20 16:32:15 +00:00
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::Inner::setMegagroupSelectedSet(const MTPInputStickerSet &set) {
|
|
|
|
_megagroupSetInput = set;
|
|
|
|
rebuild();
|
|
|
|
scrollToY.notify(0, true);
|
|
|
|
onUpdateSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::setMinHeight(int newWidth, int minHeight) {
|
|
|
|
_minHeight = minHeight;
|
|
|
|
updateSize(newWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::updateSize(int newWidth) {
|
|
|
|
auto naturalHeight = _itemsTop + int(_rows.size()) * _rowHeight + st::membersMarginBottom;
|
|
|
|
resize(newWidth ? newWidth : width(), qMax(_minHeight, naturalHeight));
|
2017-11-22 09:03:36 +00:00
|
|
|
updateControlsGeometry();
|
2016-12-13 17:07:56 +00:00
|
|
|
checkLoadMore();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::updateRows() {
|
|
|
|
int maxNameWidth = countMaxNameWidth();
|
2017-11-05 17:07:27 +00:00
|
|
|
auto &sets = Auth().data().stickerSets();
|
2017-08-05 20:01:20 +00:00
|
|
|
for_const (auto &row, _rows) {
|
2016-10-20 16:32:15 +00:00
|
|
|
auto it = sets.constFind(row->id);
|
|
|
|
if (it != sets.cend()) {
|
|
|
|
auto &set = it.value();
|
|
|
|
if (!row->sticker) {
|
2017-08-05 20:01:20 +00:00
|
|
|
auto sticker = (DocumentData*)nullptr;
|
|
|
|
auto pixw = 0, pixh = 0;
|
2016-10-20 16:32:15 +00:00
|
|
|
fillSetCover(set, &sticker, &pixw, &pixh);
|
|
|
|
if (sticker) {
|
|
|
|
row->sticker = sticker;
|
|
|
|
row->pixw = pixw;
|
|
|
|
row->pixh = pixh;
|
|
|
|
}
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
if (!row->isRecentSet()) {
|
|
|
|
auto wasInstalled = row->installed;
|
|
|
|
auto wasArchived = row->archived;
|
|
|
|
fillSetFlags(set, &row->installed, &row->official, &row->unread, &row->archived);
|
|
|
|
if (_section == Section::Installed) {
|
|
|
|
row->archived = false;
|
|
|
|
}
|
|
|
|
if (row->installed != wasInstalled || row->archived != wasArchived) {
|
|
|
|
row->ripple.reset();
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
row->title = fillSetTitle(set, maxNameWidth, &row->titleWidth);
|
|
|
|
row->count = fillSetCount(set);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StickersBox::Inner::appendSet(const Stickers::Set &set) {
|
2017-08-05 20:01:20 +00:00
|
|
|
for_const (auto &row, _rows) {
|
2016-10-20 16:32:15 +00:00
|
|
|
if (row->id == set.id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rebuildAppendSet(set, countMaxNameWidth());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int StickersBox::Inner::countMaxNameWidth() const {
|
|
|
|
int namex = st::contactsPadding.left() + st::contactsPhotoSize + st::contactsPadding.left();
|
2017-11-05 17:07:27 +00:00
|
|
|
if (!_megagroupSet && _section == Section::Installed) {
|
|
|
|
namex += st::stickersReorderIcon.width() + st::stickersReorderSkip;
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
int namew = st::boxWideWidth - namex - st::contactsPadding.right() - st::contactsCheckPosition.x();
|
|
|
|
if (_section == Section::Installed) {
|
2017-11-05 17:07:27 +00:00
|
|
|
if (!_megagroupSet) {
|
|
|
|
namew -= _undoWidth - st::stickersUndoRemove.width;
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
} else {
|
2016-11-22 09:48:13 +00:00
|
|
|
namew -= _addWidth - st::stickersTrendingAdd.width;
|
|
|
|
if (_section == Section::Featured) {
|
|
|
|
namew -= st::stickersFeaturedUnreadSize + st::stickersFeaturedUnreadSkip;
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
return namew;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::rebuildAppendSet(const Stickers::Set &set, int maxNameWidth) {
|
2016-11-22 09:48:13 +00:00
|
|
|
bool installed = true, official = true, unread = false, archived = false, removed = false;
|
|
|
|
if (set.id != Stickers::CloudRecentSetId) {
|
|
|
|
fillSetFlags(set, &installed, &official, &unread, &archived);
|
|
|
|
}
|
|
|
|
if (_section == Section::Installed && archived) {
|
2016-10-20 16:32:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData *sticker = nullptr;
|
|
|
|
int pixw = 0, pixh = 0;
|
|
|
|
fillSetCover(set, &sticker, &pixw, &pixh);
|
|
|
|
|
|
|
|
int titleWidth = 0;
|
|
|
|
QString title = fillSetTitle(set, maxNameWidth, &titleWidth);
|
|
|
|
int count = fillSetCount(set);
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
_rows.push_back(std::make_unique<Row>(
|
|
|
|
set.id,
|
|
|
|
set.access,
|
|
|
|
sticker,
|
|
|
|
count,
|
|
|
|
title,
|
|
|
|
titleWidth,
|
|
|
|
installed,
|
|
|
|
official,
|
|
|
|
unread,
|
|
|
|
archived,
|
|
|
|
removed,
|
|
|
|
pixw,
|
|
|
|
pixh));
|
2016-10-20 16:32:15 +00:00
|
|
|
_animStartTimes.push_back(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::fillSetCover(const Stickers::Set &set, DocumentData **outSticker, int *outWidth, int *outHeight) const {
|
|
|
|
if (set.stickers.isEmpty()) {
|
|
|
|
*outSticker = nullptr;
|
|
|
|
*outWidth = *outHeight = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto sticker = *outSticker = set.stickers.front();
|
|
|
|
|
|
|
|
auto pixw = sticker->thumb->width();
|
|
|
|
auto pixh = sticker->thumb->height();
|
|
|
|
if (pixw > st::contactsPhotoSize) {
|
|
|
|
if (pixw > pixh) {
|
|
|
|
pixh = (pixh * st::contactsPhotoSize) / pixw;
|
|
|
|
pixw = st::contactsPhotoSize;
|
|
|
|
} else {
|
|
|
|
pixw = (pixw * st::contactsPhotoSize) / pixh;
|
|
|
|
pixh = st::contactsPhotoSize;
|
|
|
|
}
|
|
|
|
} else if (pixh > st::contactsPhotoSize) {
|
|
|
|
pixw = (pixw * st::contactsPhotoSize) / pixh;
|
|
|
|
pixh = st::contactsPhotoSize;
|
|
|
|
}
|
|
|
|
*outWidth = pixw;
|
|
|
|
*outHeight = pixh;
|
|
|
|
}
|
|
|
|
|
|
|
|
int StickersBox::Inner::fillSetCount(const Stickers::Set &set) const {
|
|
|
|
int result = set.stickers.isEmpty() ? set.count : set.stickers.size(), added = 0;
|
|
|
|
if (set.id == Stickers::CloudRecentSetId) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto customIt = Auth().data().stickerSets().constFind(Stickers::CustomSetId);
|
|
|
|
if (customIt != Auth().data().stickerSets().cend()) {
|
2016-10-20 16:32:15 +00:00
|
|
|
added = customIt->stickers.size();
|
2017-12-11 14:45:29 +00:00
|
|
|
for_const (auto &sticker, Stickers::GetRecentPack()) {
|
2016-10-20 16:32:15 +00:00
|
|
|
if (customIt->stickers.indexOf(sticker.first) < 0) {
|
|
|
|
++added;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2017-12-11 14:45:29 +00:00
|
|
|
added = Stickers::GetRecentPack().size();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result + added;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString StickersBox::Inner::fillSetTitle(const Stickers::Set &set, int maxNameWidth, int *outTitleWidth) const {
|
|
|
|
auto result = set.title;
|
2016-12-23 13:21:01 +00:00
|
|
|
int titleWidth = st::contactsNameStyle.font->width(result);
|
2016-10-20 16:32:15 +00:00
|
|
|
if (titleWidth > maxNameWidth) {
|
2016-12-23 13:21:01 +00:00
|
|
|
result = st::contactsNameStyle.font->elided(result, maxNameWidth);
|
|
|
|
titleWidth = st::contactsNameStyle.font->width(result);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
if (outTitleWidth) {
|
|
|
|
*outTitleWidth = titleWidth;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-01-25 12:28:48 +00:00
|
|
|
void StickersBox::Inner::fillSetFlags(
|
|
|
|
const Stickers::Set &set,
|
|
|
|
bool *outInstalled,
|
|
|
|
bool *outOfficial,
|
|
|
|
bool *outUnread,
|
|
|
|
bool *outArchived) {
|
|
|
|
*outInstalled = (set.flags & MTPDstickerSet::Flag::f_installed_date);
|
2016-11-22 09:48:13 +00:00
|
|
|
*outOfficial = (set.flags & MTPDstickerSet::Flag::f_official);
|
|
|
|
*outArchived = (set.flags & MTPDstickerSet::Flag::f_archived);
|
|
|
|
if (_section == Section::Featured) {
|
|
|
|
*outUnread = (set.flags & MTPDstickerSet_ClientFlag::f_unread);
|
|
|
|
} else {
|
|
|
|
*outUnread = false;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
template <typename Check>
|
|
|
|
Stickers::Order StickersBox::Inner::collectSets(Check check) const {
|
2016-10-20 16:32:15 +00:00
|
|
|
Stickers::Order result;
|
|
|
|
result.reserve(_rows.size());
|
2017-08-05 20:01:20 +00:00
|
|
|
for_const (auto &row, _rows) {
|
|
|
|
if (check(row.get())) {
|
2016-11-22 09:48:13 +00:00
|
|
|
result.push_back(row->id);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
Stickers::Order StickersBox::Inner::getOrder() const {
|
|
|
|
return collectSets([](Row *row) {
|
|
|
|
return !row->archived && !row->removed && !row->isRecentSet();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Stickers::Order StickersBox::Inner::getFullOrder() const {
|
|
|
|
return collectSets([](Row *row) {
|
|
|
|
return !row->isRecentSet();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Stickers::Order StickersBox::Inner::getRemovedSets() const {
|
|
|
|
return collectSets([](Row *row) {
|
|
|
|
return row->removed;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
int StickersBox::Inner::getRowIndex(uint64 setId) const {
|
2017-08-05 20:01:20 +00:00
|
|
|
for (auto i = 0, count = int(_rows.size()); i != count; ++i) {
|
|
|
|
auto &row = _rows[i];
|
2016-11-22 09:48:13 +00:00
|
|
|
if (row->id == setId) {
|
|
|
|
return i;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::setFullOrder(const Stickers::Order &order) {
|
|
|
|
for_const (auto setId, order) {
|
|
|
|
auto index = getRowIndex(setId);
|
|
|
|
if (index >= 0) {
|
2017-08-05 20:01:20 +00:00
|
|
|
auto row = std::move(_rows[index]);
|
2016-11-22 09:48:13 +00:00
|
|
|
auto count = _rows.size();
|
|
|
|
for (auto i = index + 1; i != count; ++i) {
|
2017-08-05 20:01:20 +00:00
|
|
|
_rows[i - 1] = std::move(_rows[i]);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2017-08-05 20:01:20 +00:00
|
|
|
_rows[count - 1] = std::move(row);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::setRemovedSets(const Stickers::Order &removed) {
|
2017-08-05 20:01:20 +00:00
|
|
|
for (auto i = 0, count = int(_rows.size()); i != count; ++i) {
|
2016-11-22 09:48:13 +00:00
|
|
|
setRowRemoved(i, removed.contains(_rows[i]->id));
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
void StickersBox::Inner::visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) {
|
2016-12-13 17:07:56 +00:00
|
|
|
_visibleTop = visibleTop;
|
|
|
|
_visibleBottom = visibleBottom;
|
|
|
|
updateScrollbarWidth();
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_section == Section::Featured) {
|
|
|
|
readVisibleSets();
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
checkLoadMore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::checkLoadMore() {
|
|
|
|
if (_loadMoreCallback) {
|
|
|
|
auto scrollHeight = (_visibleBottom - _visibleTop);
|
|
|
|
int scrollTop = _visibleTop, scrollTopMax = height() - scrollHeight;
|
|
|
|
if (scrollTop + PreloadHeightsCount * scrollHeight >= scrollTopMax) {
|
|
|
|
_loadMoreCallback();
|
|
|
|
}
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::readVisibleSets() {
|
|
|
|
auto itemsVisibleTop = _visibleTop - _itemsTop;
|
|
|
|
auto itemsVisibleBottom = _visibleBottom - _itemsTop;
|
|
|
|
int rowFrom = floorclamp(itemsVisibleTop, _rowHeight, 0, _rows.size());
|
|
|
|
int rowTo = ceilclamp(itemsVisibleBottom, _rowHeight, 0, _rows.size());
|
|
|
|
for (int i = rowFrom; i < rowTo; ++i) {
|
|
|
|
if (!_rows[i]->unread) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (i * _rowHeight < itemsVisibleTop || (i + 1) * _rowHeight > itemsVisibleBottom) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!_rows[i]->sticker || _rows[i]->sticker->thumb->loaded() || _rows[i]->sticker->loaded()) {
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().api().readFeaturedSetDelayed(_rows[i]->id);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void StickersBox::Inner::updateScrollbarWidth() {
|
|
|
|
auto width = (_visibleBottom - _visibleTop < height()) ? (st::boxLayerScroll.width - st::boxLayerScroll.deltax) : 0;
|
|
|
|
if (_scrollbar != width) {
|
|
|
|
_scrollbar = width;
|
|
|
|
update();
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StickersBox::Inner::~Inner() {
|
|
|
|
clear();
|
|
|
|
}
|