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
|
|
|
*/
|
|
|
|
#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"
|
2017-11-05 17:07:27 +00:00
|
|
|
#include "chat_helpers/stickers.h"
|
2019-04-01 17:44:54 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2017-11-05 17:07:27 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
class ConfirmBox;
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
namespace style {
|
|
|
|
struct RippleAnimation;
|
|
|
|
} // namespace style
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
namespace Ui {
|
|
|
|
class PlainShadow;
|
2016-11-16 16:04:25 +00:00
|
|
|
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;
|
2016-10-20 16:32:15 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
class StickersBox : public BoxContent, public RPCSender {
|
2016-10-20 16:32:15 +00:00
|
|
|
public:
|
|
|
|
enum class Section {
|
|
|
|
Installed,
|
|
|
|
Featured,
|
|
|
|
Archived,
|
2019-03-10 12:55:24 +00:00
|
|
|
Attached,
|
2016-10-20 16:32:15 +00:00
|
|
|
};
|
2016-12-13 17:07:56 +00:00
|
|
|
StickersBox(QWidget*, Section section);
|
2017-08-17 08:31:24 +00:00
|
|
|
StickersBox(QWidget*, not_null<ChannelData*> megagroup);
|
2019-03-10 12:55:24 +00:00
|
|
|
StickersBox(QWidget*, const MTPVector<MTPStickerSetCovered> &attachedSets);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void setInnerFocus() override;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
~StickersBox();
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
protected:
|
2016-12-13 17:07:56 +00:00
|
|
|
void prepare() override;
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
class Inner;
|
2016-12-13 17:07:56 +00:00
|
|
|
class Tab {
|
|
|
|
public:
|
|
|
|
Tab() = default;
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
template <typename ...Args>
|
2016-12-13 17:07:56 +00:00
|
|
|
Tab(int index, Args&&... args);
|
|
|
|
|
|
|
|
object_ptr<Inner> takeWidget();
|
|
|
|
void returnWidget(object_ptr<Inner> widget);
|
|
|
|
|
|
|
|
Inner *widget() {
|
|
|
|
return _weak;
|
|
|
|
}
|
|
|
|
int index() const {
|
|
|
|
return _index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void saveScrollTop();
|
|
|
|
int getScrollTop() const {
|
|
|
|
return _scrollTop;
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
private:
|
|
|
|
int _index = 0;
|
|
|
|
object_ptr<Inner> _widget = { nullptr };
|
|
|
|
QPointer<Inner> _weak;
|
|
|
|
int _scrollTop = 0;
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
};
|
2016-12-22 13:30:27 +00:00
|
|
|
|
2017-08-05 10:48:21 +00:00
|
|
|
void handleStickersUpdated();
|
2016-12-22 13:30:27 +00:00
|
|
|
void refreshTabs();
|
|
|
|
void rebuildList(Tab *tab = nullptr);
|
|
|
|
void updateTabsGeometry();
|
|
|
|
void switchTab();
|
|
|
|
void installSet(uint64 setId);
|
|
|
|
int getTopSkip() const;
|
2017-08-13 16:09:14 +00:00
|
|
|
void saveChanges();
|
2016-12-22 13:30:27 +00:00
|
|
|
|
|
|
|
QPixmap grabContentCache();
|
|
|
|
|
|
|
|
void installDone(const MTPmessages_StickerSetInstallResult &result);
|
|
|
|
bool installFail(uint64 setId, const RPCError &error);
|
|
|
|
|
|
|
|
void preloadArchivedSets();
|
|
|
|
void requestArchivedSets();
|
|
|
|
void loadMoreArchived();
|
|
|
|
void getArchivedDone(uint64 offsetId, const MTPmessages_ArchivedStickers &result);
|
2019-03-10 12:55:24 +00:00
|
|
|
void showAttachedStickers();
|
2016-12-22 13:30:27 +00:00
|
|
|
|
|
|
|
object_ptr<Ui::SettingsSlider> _tabs = { nullptr };
|
|
|
|
QList<Section> _tabIndices;
|
|
|
|
|
|
|
|
class CounterWidget;
|
|
|
|
object_ptr<CounterWidget> _unreadBadge = { nullptr };
|
|
|
|
|
|
|
|
Section _section;
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
Tab _installed;
|
|
|
|
Tab _featured;
|
|
|
|
Tab _archived;
|
2019-03-10 12:55:24 +00:00
|
|
|
Tab _attached;
|
2016-11-22 09:48:13 +00:00
|
|
|
Tab *_tab = nullptr;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2019-03-10 12:55:24 +00:00
|
|
|
const MTPVector<MTPStickerSetCovered> _attachedSets;
|
|
|
|
|
2017-08-05 10:48:21 +00:00
|
|
|
ChannelData *_megagroupSet = nullptr;
|
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<Ui::SlideAnimation> _slideAnimation;
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Ui::PlainShadow> _titleShadow = { nullptr };
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
mtpRequestId _archivedRequestId = 0;
|
2016-11-22 09:48:13 +00:00
|
|
|
bool _archivedLoaded = false;
|
2016-10-20 16:32:15 +00:00
|
|
|
bool _allArchivedLoaded = false;
|
2016-11-22 09:48:13 +00:00
|
|
|
bool _someArchivedLoaded = false;
|
|
|
|
|
|
|
|
Stickers::Order _localOrder;
|
|
|
|
Stickers::Order _localRemoved;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
int stickerPacksCount(bool includeArchivedOfficial = false);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
// This class is hold in header because it requires Qt preprocessing.
|
2019-07-02 13:20:04 +00:00
|
|
|
class StickersBox::Inner
|
|
|
|
: public Ui::RpWidget
|
|
|
|
, private base::Subscriber
|
|
|
|
, private MTP::Sender {
|
2016-10-20 16:32:15 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
using Section = StickersBox::Section;
|
|
|
|
Inner(QWidget *parent, Section section);
|
2017-08-17 08:31:24 +00:00
|
|
|
Inner(QWidget *parent, not_null<ChannelData*> megagroup);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
base::Observable<int> scrollToY;
|
|
|
|
void setInnerFocus();
|
|
|
|
|
|
|
|
void saveGroupSet();
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void rebuild();
|
2017-08-05 20:01:20 +00:00
|
|
|
void updateSize(int newWidth = 0);
|
2016-10-20 16:32:15 +00:00
|
|
|
void updateRows(); // refresh only pack cover stickers
|
|
|
|
bool appendSet(const Stickers::Set &set);
|
|
|
|
|
|
|
|
Stickers::Order getOrder() const;
|
2016-11-22 09:48:13 +00:00
|
|
|
Stickers::Order getFullOrder() const;
|
|
|
|
Stickers::Order getRemovedSets() const;
|
|
|
|
|
|
|
|
void setFullOrder(const Stickers::Order &order);
|
|
|
|
void setRemovedSets(const Stickers::Order &removed);
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setInstallSetCallback(Fn<void(uint64 setId)> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_installSetCallback = std::move(callback);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2018-06-04 15:35:11 +00:00
|
|
|
void setLoadMoreCallback(Fn<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_loadMoreCallback = std::move(callback);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void setMinHeight(int newWidth, int minHeight);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
int getVisibleTop() const {
|
|
|
|
return _visibleTop;
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
~Inner();
|
|
|
|
|
|
|
|
protected:
|
2017-09-13 16:57:44 +00:00
|
|
|
void visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) override;
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2017-08-05 20:01:20 +00:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2016-10-20 16:32:15 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
2017-02-11 11:24:37 +00:00
|
|
|
void leaveEventHook(QEvent *e) override;
|
2017-08-05 20:01:20 +00:00
|
|
|
void leaveToChildEvent(QEvent *e, QWidget *child) override;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
signals:
|
2016-12-13 17:07:56 +00:00
|
|
|
void draggingScrollDelta(int delta);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void onUpdateSelected();
|
|
|
|
|
|
|
|
private:
|
2017-08-05 20:01:20 +00:00
|
|
|
struct Row {
|
2018-07-13 21:25:47 +00:00
|
|
|
Row(
|
|
|
|
uint64 id,
|
|
|
|
uint64 accessHash,
|
2019-03-22 09:33:13 +00:00
|
|
|
ImagePtr thumbnail,
|
2018-07-13 21:25:47 +00:00
|
|
|
DocumentData *sticker,
|
|
|
|
int32 count,
|
|
|
|
const QString &title,
|
|
|
|
int titleWidth,
|
|
|
|
bool installed,
|
|
|
|
bool official,
|
|
|
|
bool unread,
|
|
|
|
bool archived,
|
|
|
|
bool removed,
|
|
|
|
int32 pixw,
|
|
|
|
int32 pixh);
|
2017-08-05 20:01:20 +00:00
|
|
|
bool isRecentSet() const {
|
|
|
|
return (id == Stickers::CloudRecentSetId);
|
|
|
|
}
|
|
|
|
~Row();
|
|
|
|
|
|
|
|
uint64 id = 0;
|
2018-07-13 21:25:47 +00:00
|
|
|
uint64 accessHash = 0;
|
2019-03-22 09:33:13 +00:00
|
|
|
ImagePtr thumbnail;
|
2017-08-05 20:01:20 +00:00
|
|
|
DocumentData *sticker = nullptr;
|
|
|
|
int32 count = 0;
|
|
|
|
QString title;
|
|
|
|
int titleWidth = 0;
|
|
|
|
bool installed = false;
|
|
|
|
bool official = false;
|
|
|
|
bool unread = false;
|
|
|
|
bool archived = false;
|
|
|
|
bool removed = false;
|
|
|
|
int32 pixw = 0;
|
|
|
|
int32 pixh = 0;
|
|
|
|
anim::value yadd;
|
|
|
|
std::unique_ptr<Ui::RippleAnimation> ripple;
|
2019-07-02 13:20:04 +00:00
|
|
|
std::unique_ptr<Lottie::SinglePlayer> lottie;
|
2017-08-05 20:01:20 +00:00
|
|
|
};
|
2017-11-05 17:07:27 +00:00
|
|
|
struct MegagroupSet {
|
|
|
|
inline bool operator==(const MegagroupSet &other) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
inline bool operator!=(const MegagroupSet &other) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
using SelectedRow = base::optional_variant<MegagroupSet, int>;
|
|
|
|
class AddressField : public Ui::UsernameInput {
|
|
|
|
public:
|
|
|
|
using UsernameInput::UsernameInput;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void correctValue(
|
|
|
|
const QString &was,
|
|
|
|
int wasCursor,
|
|
|
|
QString &now,
|
|
|
|
int &nowCursor) override;
|
|
|
|
|
|
|
|
};
|
2017-08-05 20:01:20 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
template <typename Check>
|
|
|
|
Stickers::Order collectSets(Check check) const;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void checkLoadMore();
|
|
|
|
void updateScrollbarWidth();
|
2016-11-22 09:48:13 +00:00
|
|
|
int getRowIndex(uint64 setId) const;
|
|
|
|
void setRowRemoved(int index, bool removed);
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
void setSelected(SelectedRow selected);
|
2016-11-16 16:04:25 +00:00
|
|
|
void setActionDown(int newActionDown);
|
2017-11-05 17:07:27 +00:00
|
|
|
void setPressed(SelectedRow pressed);
|
2016-10-20 16:32:15 +00:00
|
|
|
void setup();
|
2016-11-22 09:48:13 +00:00
|
|
|
QRect relativeButtonRect(bool removeButton) const;
|
|
|
|
void ensureRipple(const style::RippleAnimation &st, QImage mask, bool removeButton);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
bool shiftingAnimationCallback(crl::time now);
|
2019-07-02 13:20:04 +00:00
|
|
|
void paintRow(Painter &p, not_null<Row*> set, int index);
|
|
|
|
void paintRowThumbnail(Painter &p, not_null<Row*> set, int left);
|
|
|
|
void paintFakeButton(Painter &p, not_null<Row*> set, int index);
|
2016-10-20 16:32:15 +00:00
|
|
|
void clear();
|
|
|
|
void setActionSel(int32 actionSel);
|
|
|
|
float64 aboveShadowOpacity() const;
|
2019-07-02 13:20:04 +00:00
|
|
|
void validateLottieAnimation(not_null<Row*> set);
|
|
|
|
void updateRowThumbnail(not_null<Row*> set);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
void readVisibleSets();
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void updateControlsGeometry();
|
2016-10-20 16:32:15 +00:00
|
|
|
void rebuildAppendSet(const Stickers::Set &set, int maxNameWidth);
|
2019-03-22 09:33:13 +00:00
|
|
|
void fillSetCover(const Stickers::Set &set, ImagePtr *thumbnail, DocumentData **outSticker, int *outWidth, int *outHeight) const;
|
2016-10-20 16:32:15 +00:00
|
|
|
int fillSetCount(const Stickers::Set &set) const;
|
|
|
|
QString fillSetTitle(const Stickers::Set &set, int maxNameWidth, int *outTitleWidth) const;
|
2016-11-22 09:48:13 +00:00
|
|
|
void fillSetFlags(const Stickers::Set &set, bool *outInstalled, bool *outOfficial, bool *outUnread, bool *outArchived);
|
2017-08-05 20:01:20 +00:00
|
|
|
void rebuildMegagroupSet();
|
2017-11-05 17:07:27 +00:00
|
|
|
void fixupMegagroupSetAddress();
|
2017-08-05 20:01:20 +00:00
|
|
|
void handleMegagroupSetAddressChange();
|
|
|
|
void setMegagroupSelectedSet(const MTPInputStickerSet &set);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
int countMaxNameWidth() const;
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
Section _section;
|
|
|
|
|
|
|
|
int32 _rowHeight;
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<Row>> _rows;
|
2019-04-01 17:44:54 +00:00
|
|
|
std::vector<crl::time> _shiftingStartTimes;
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time _aboveShadowFadeStart = 0;
|
2016-12-05 11:01:08 +00:00
|
|
|
anim::value _aboveShadowFadeOpacity;
|
2019-04-01 17:44:54 +00:00
|
|
|
Ui::Animations::Basic _shiftingAnimation;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(uint64 setId)> _installSetCallback;
|
|
|
|
Fn<void()> _loadMoreCallback;
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
int _visibleTop = 0;
|
|
|
|
int _visibleBottom = 0;
|
|
|
|
int _itemsTop = 0;
|
|
|
|
|
|
|
|
int _actionSel = -1;
|
|
|
|
int _actionDown = -1;
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
QString _addText;
|
|
|
|
int _addWidth = 0;
|
|
|
|
QString _undoText;
|
|
|
|
int _undoWidth = 0;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
int _buttonHeight = 0;
|
|
|
|
|
|
|
|
QPoint _mouse;
|
2016-11-22 09:48:13 +00:00
|
|
|
bool _inDragArea = false;
|
2017-11-05 17:07:27 +00:00
|
|
|
SelectedRow _selected;
|
|
|
|
SelectedRow _pressed;
|
2016-10-20 16:32:15 +00:00
|
|
|
QPoint _dragStart;
|
|
|
|
int _started = -1;
|
|
|
|
int _dragging = -1;
|
|
|
|
int _above = -1;
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
int _minHeight = 0;
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
int _scrollbar = 0;
|
2017-08-05 10:48:21 +00:00
|
|
|
ChannelData *_megagroupSet = nullptr;
|
2017-08-05 20:01:20 +00:00
|
|
|
MTPInputStickerSet _megagroupSetInput = MTP_inputStickerSetEmpty();
|
|
|
|
std::unique_ptr<Row> _megagroupSelectedSet;
|
2017-11-05 17:07:27 +00:00
|
|
|
object_ptr<AddressField> _megagroupSetField = { nullptr };
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Ui::PlainShadow> _megagroupSelectedShadow = { nullptr };
|
2017-08-05 20:01:20 +00:00
|
|
|
object_ptr<Ui::CrossButton> _megagroupSelectedRemove = { nullptr };
|
|
|
|
object_ptr<BoxContentDivider> _megagroupDivider = { nullptr };
|
|
|
|
object_ptr<Ui::FlatLabel> _megagroupSubTitle = { nullptr };
|
|
|
|
base::Timer _megagroupSetAddressChangedTimer;
|
|
|
|
mtpRequestId _megagroupSetRequestId = 0;
|
2016-11-16 16:04:25 +00:00
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
};
|