tdesktop/Telegram/SourceFiles/boxes/stickers_box.h

176 lines
3.7 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
2017-04-06 14:38:10 +00:00
#include "boxes/abstract_box.h"
2017-08-05 20:01:20 +00:00
#include "base/timer.h"
#include "mtproto/sender.h"
#include "data/stickers/data_stickers_set.h"
#include "ui/effects/animations.h"
2019-09-16 11:14:06 +00:00
#include "ui/special_fields.h"
2016-11-22 09:48:13 +00:00
namespace style {
struct RippleAnimation;
} // namespace style
namespace Ui {
2021-10-18 22:28:08 +00:00
class ConfirmBox;
class PlainShadow;
class RippleAnimation;
2016-11-22 09:48:13 +00:00
class SettingsSlider;
2016-11-24 19:28:23 +00:00
class SlideAnimation;
2017-08-05 20:01:20 +00:00
class CrossButton;
2019-09-18 11:19:05 +00:00
class BoxContentDivider;
} // namespace Ui
namespace Window {
class SessionController;
} // namespace Window
2019-08-06 16:40:08 +00:00
namespace Main {
class Session;
} // namespace Main
namespace Data {
class DocumentMedia;
} // namespace Data
namespace Lottie {
class SinglePlayer;
} // namespace Lottie
2020-05-28 11:58:50 +00:00
namespace Stickers {
class Set;
} // namespace Stickers
class StickersBox final : public Ui::BoxContent {
public:
enum class Section {
Installed,
Featured,
Archived,
Attached,
Masks,
};
2019-08-06 16:40:08 +00:00
StickersBox(
QWidget*,
not_null<Window::SessionController*> controller,
2021-03-30 14:54:11 +00:00
Section section,
bool masks = false);
2019-08-06 16:40:08 +00:00
StickersBox(
QWidget*,
not_null<Window::SessionController*> controller,
not_null<ChannelData*> megagroup);
StickersBox(
QWidget*,
not_null<Window::SessionController*> controller,
2019-08-06 16:40:08 +00:00
const MTPVector<MTPStickerSetCovered> &attachedSets);
~StickersBox();
[[nodiscard]] Main::Session &session() const;
2017-08-05 20:01:20 +00:00
void setInnerFocus() override;
protected:
void prepare() override;
void resizeEvent(QResizeEvent *e) override;
void paintEvent(QPaintEvent *e) override;
private:
class Inner;
class Tab {
public:
Tab() = default;
2016-11-22 09:48:13 +00:00
template <typename ...Args>
Tab(int index, Args&&... args);
object_ptr<Inner> takeWidget();
void returnWidget(object_ptr<Inner> widget);
[[nodiscard]] Inner *widget() const;
[[nodiscard]] int index() const;
void saveScrollTop();
int getScrollTop() const {
return _scrollTop;
2016-11-22 09:48:13 +00:00
}
private:
const int _index = 0;
object_ptr<Inner> _widget = { nullptr };
QPointer<Inner> _weak;
int _scrollTop = 0;
2016-11-22 09:48:13 +00:00
};
2017-08-05 10:48:21 +00:00
void handleStickersUpdated();
void refreshTabs();
void rebuildList(Tab *tab = nullptr);
void updateTabsGeometry();
void switchTab();
void installSet(uint64 setId);
int getTopSkip() const;
void saveChanges();
QPixmap grabContentCache();
void installDone(const MTPmessages_StickerSetInstallResult &result);
2021-03-12 12:48:00 +00:00
void installFail(const MTP::Error &error, uint64 setId);
void preloadArchivedSets();
void requestArchivedSets();
void loadMoreArchived();
void getArchivedDone(
const MTPmessages_ArchivedStickers &result,
uint64 offsetId);
void showAttachedStickers();
2021-03-30 15:51:45 +00:00
const Data::StickersSetsOrder &archivedSetsOrder() const;
Data::StickersSetsOrder &archivedSetsOrderRef();
std::array<Inner*, 5> widgets() const;
const not_null<Window::SessionController*> _controller;
MTP::Sender _api;
2019-08-06 16:40:08 +00:00
object_ptr<Ui::SettingsSlider> _tabs = { nullptr };
QList<Section> _tabIndices;
class CounterWidget;
object_ptr<CounterWidget> _unreadBadge = { nullptr };
Section _section;
2021-03-30 14:54:11 +00:00
const bool _isMasks;
2016-11-22 09:48:13 +00:00
Tab _installed;
Tab _masks;
2016-11-22 09:48:13 +00:00
Tab _featured;
Tab _archived;
Tab _attached;
2016-11-22 09:48:13 +00:00
Tab *_tab = nullptr;
const MTPVector<MTPStickerSetCovered> _attachedSets;
2017-08-05 10:48:21 +00:00
ChannelData *_megagroupSet = nullptr;
std::unique_ptr<Ui::SlideAnimation> _slideAnimation;
object_ptr<Ui::PlainShadow> _titleShadow = { nullptr };
mtpRequestId _archivedRequestId = 0;
2016-11-22 09:48:13 +00:00
bool _archivedLoaded = false;
bool _allArchivedLoaded = false;
2016-11-22 09:48:13 +00:00
bool _someArchivedLoaded = false;
Data::StickersSetsOrder _localOrder;
Data::StickersSetsOrder _localRemoved;
};