tdesktop/Telegram/SourceFiles/boxes/stickers_box.h

187 lines
4.0 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"
#include "ui/widgets/fields/special_fields.h"
2016-11-22 09:48:13 +00:00
namespace style {
struct RippleAnimation;
2023-08-09 10:46:30 +00:00
struct PeerListItem;
2016-11-22 09:48:13 +00:00
} // namespace style
namespace Ui {
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 ChatHelpers {
class Show;
} // namespace ChatHelpers
2019-08-06 16:40:08 +00:00
namespace Main {
class Session;
} // namespace Main
namespace Data {
class DocumentMedia;
enum class StickersType : uchar;
} // 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*,
std::shared_ptr<ChatHelpers::Show> show,
2021-03-30 14:54:11 +00:00
Section section,
bool masks = false);
2019-08-06 16:40:08 +00:00
StickersBox(
QWidget*,
std::shared_ptr<ChatHelpers::Show> show,
not_null<ChannelData*> megagroup);
StickersBox(
QWidget*,
std::shared_ptr<ChatHelpers::Show> show,
2022-08-15 08:33:24 +00:00
const QVector<MTPStickerSetCovered> &attachedSets);
StickersBox(
QWidget*,
std::shared_ptr<ChatHelpers::Show> show,
const std::vector<StickerSetIdentifier> &emojiSets);
~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;
2023-08-09 10:46:30 +00:00
const style::PeerListItem &_st;
const std::shared_ptr<ChatHelpers::Show> _show;
const not_null<Main::Session*> _session;
MTP::Sender _api;
2019-08-06 16:40:08 +00:00
object_ptr<Ui::SettingsSlider> _tabs = { nullptr };
QList<Section> _tabIndices;
bool _ignoreTabActivation = false;
class CounterWidget;
object_ptr<CounterWidget> _unreadBadge = { nullptr };
Section _section;
2021-03-30 14:54:11 +00:00
const bool _isMasks;
2022-07-27 09:26:22 +00:00
const bool _isEmoji;
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 Data::StickersType _attachedType = {};
2022-08-15 08:33:24 +00:00
const QVector<MTPStickerSetCovered> _attachedSets;
const std::vector<StickerSetIdentifier> _emojiSets;
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;
};