2015-05-19 15:46:45 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2015-05-19 15:46:45 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2015-05-19 15:46:45 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "abstractbox.h"
|
2016-09-26 12:09:59 +00:00
|
|
|
#include "core/vector_of_moveable.h"
|
2015-05-19 15:46:45 +00:00
|
|
|
|
2016-07-15 15:58:52 +00:00
|
|
|
class ConfirmBox;
|
|
|
|
|
2016-09-26 13:57:08 +00:00
|
|
|
class StickerSetInner : public ScrolledWidget, public RPCSender, private base::Subscriber {
|
2015-05-19 15:46:45 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
StickerSetInner(const MTPInputStickerSet &set);
|
|
|
|
|
|
|
|
bool loaded() const;
|
|
|
|
int32 notInstalled() const;
|
2015-07-21 15:35:08 +00:00
|
|
|
bool official() const;
|
2015-05-19 15:46:45 +00:00
|
|
|
QString title() const;
|
|
|
|
QString shortName() const;
|
|
|
|
|
2016-09-11 08:38:14 +00:00
|
|
|
void setVisibleTopBottom(int visibleTop, int visibleBottom) override;
|
2015-05-19 15:46:45 +00:00
|
|
|
void install();
|
|
|
|
|
|
|
|
~StickerSetInner();
|
|
|
|
|
2016-09-11 08:38:14 +00:00
|
|
|
protected:
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private slots:
|
2016-02-17 16:37:21 +00:00
|
|
|
void onPreview();
|
|
|
|
|
2015-05-19 15:46:45 +00:00
|
|
|
signals:
|
|
|
|
void updateButtons();
|
|
|
|
void installed(uint64 id);
|
|
|
|
|
|
|
|
private:
|
2016-09-11 08:38:14 +00:00
|
|
|
void updateSelected();
|
|
|
|
void startOverAnimation(int index, float64 from, float64 to);
|
|
|
|
int stickerFromGlobalPos(const QPoint &p) const;
|
2016-02-17 16:37:21 +00:00
|
|
|
|
2015-05-19 15:46:45 +00:00
|
|
|
void gotSet(const MTPmessages_StickerSet &set);
|
|
|
|
bool failedSet(const RPCError &error);
|
|
|
|
|
2016-07-18 15:39:10 +00:00
|
|
|
void installDone(const MTPmessages_StickerSetInstallResult &result);
|
2016-07-14 11:59:55 +00:00
|
|
|
bool installFail(const RPCError &error);
|
2015-05-19 15:46:45 +00:00
|
|
|
|
2016-09-19 10:18:21 +00:00
|
|
|
bool isMasksSet() const {
|
|
|
|
return (_setFlags & MTPDstickerSet::Flag::f_masks);
|
|
|
|
}
|
|
|
|
|
2016-09-26 12:09:59 +00:00
|
|
|
std_::vector_of_moveable<FloatAnimation> _packOvers;
|
2015-05-19 15:46:45 +00:00
|
|
|
StickerPack _pack;
|
2016-01-09 12:51:42 +00:00
|
|
|
StickersByEmojiMap _emoji;
|
2016-06-27 16:25:21 +00:00
|
|
|
bool _loaded = false;
|
|
|
|
uint64 _setId = 0;
|
|
|
|
uint64 _setAccess = 0;
|
2015-05-19 15:46:45 +00:00
|
|
|
QString _title, _setTitle, _setShortName;
|
2016-06-27 16:25:21 +00:00
|
|
|
int32 _setCount = 0;
|
|
|
|
int32 _setHash = 0;
|
|
|
|
MTPDstickerSet::Flags _setFlags = 0;
|
2015-05-19 15:46:45 +00:00
|
|
|
|
2016-09-11 08:38:14 +00:00
|
|
|
int _visibleTop = 0;
|
|
|
|
int _visibleBottom = 0;
|
2015-05-19 15:46:45 +00:00
|
|
|
MTPInputStickerSet _input;
|
|
|
|
|
2016-06-27 16:25:21 +00:00
|
|
|
mtpRequestId _installRequest = 0;
|
2016-02-17 16:37:21 +00:00
|
|
|
|
2016-09-11 08:38:14 +00:00
|
|
|
int _selected = -1;
|
|
|
|
|
2016-02-17 16:37:21 +00:00
|
|
|
QTimer _previewTimer;
|
2016-09-11 08:38:14 +00:00
|
|
|
int _previewShown = -1;
|
|
|
|
|
2015-05-19 15:46:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class StickerSetBox : public ScrollableBox, public RPCSender {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
StickerSetBox(const MTPInputStickerSet &set);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void onStickersUpdated();
|
|
|
|
void onAddStickers();
|
|
|
|
void onShareStickers();
|
|
|
|
void onUpdateButtons();
|
|
|
|
|
|
|
|
void onScroll();
|
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
private slots:
|
|
|
|
void onInstalled(uint64 id);
|
2015-05-19 15:46:45 +00:00
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
signals:
|
2015-05-19 15:46:45 +00:00
|
|
|
void installed(uint64 id);
|
|
|
|
|
|
|
|
protected:
|
2016-08-16 16:53:10 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
|
|
|
void showAll() override;
|
2015-05-19 15:46:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
StickerSetInner _inner;
|
2015-10-11 08:37:24 +00:00
|
|
|
ScrollableBoxShadow _shadow;
|
2015-10-12 21:02:10 +00:00
|
|
|
BoxButton _add, _share, _cancel, _done;
|
2015-10-11 08:37:24 +00:00
|
|
|
QString _title;
|
2016-06-28 18:05:38 +00:00
|
|
|
|
2015-05-19 15:46:45 +00:00
|
|
|
};
|
2015-12-02 17:17:53 +00:00
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
namespace internal {
|
|
|
|
class StickersInner;
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
class StickersBox : public ItemListBox, public RPCSender {
|
2015-12-02 17:17:53 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-06-28 18:05:38 +00:00
|
|
|
enum class Section {
|
|
|
|
Installed,
|
|
|
|
Featured,
|
2016-07-18 15:39:10 +00:00
|
|
|
Archived,
|
|
|
|
ArchivedPart,
|
2016-06-28 18:05:38 +00:00
|
|
|
};
|
|
|
|
StickersBox(Section section = Section::Installed);
|
2016-07-18 15:39:10 +00:00
|
|
|
StickersBox(const Stickers::Order &archivedIds);
|
|
|
|
|
2016-07-21 10:09:47 +00:00
|
|
|
~StickersBox();
|
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
public slots:
|
|
|
|
void onStickersUpdated();
|
|
|
|
|
|
|
|
void onCheckDraggingScroll(int localY);
|
|
|
|
void onNoDraggingScroll();
|
|
|
|
void onScrollTimer();
|
|
|
|
|
|
|
|
void onSave();
|
|
|
|
|
2016-07-21 13:57:31 +00:00
|
|
|
private slots:
|
|
|
|
void onScroll();
|
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
protected:
|
2016-08-16 16:53:10 +00:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
void closePressed() override;
|
|
|
|
void showAll() override;
|
2016-06-28 18:05:38 +00:00
|
|
|
|
|
|
|
private:
|
2016-07-18 15:39:10 +00:00
|
|
|
void setup();
|
2016-06-28 18:05:38 +00:00
|
|
|
int32 countHeight() const;
|
2016-07-21 13:57:31 +00:00
|
|
|
void rebuildList();
|
2016-06-28 18:05:38 +00:00
|
|
|
|
2016-07-18 15:39:10 +00:00
|
|
|
void disenableDone(const MTPmessages_StickerSetInstallResult &result, mtpRequestId req);
|
2016-06-28 18:05:38 +00:00
|
|
|
bool disenableFail(const RPCError &error, mtpRequestId req);
|
|
|
|
void reorderDone(const MTPBool &result);
|
|
|
|
bool reorderFail(const RPCError &result);
|
|
|
|
void saveOrder();
|
|
|
|
|
2016-09-10 20:54:59 +00:00
|
|
|
void updateVisibleTopBottom();
|
2016-07-21 13:57:31 +00:00
|
|
|
void checkLoadMoreArchived();
|
|
|
|
void getArchivedDone(uint64 offsetId, const MTPmessages_ArchivedStickers &result);
|
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
Section _section;
|
|
|
|
|
|
|
|
ChildWidget<internal::StickersInner> _inner;
|
|
|
|
ChildWidget<BoxButton> _save = { nullptr };
|
|
|
|
ChildWidget<BoxButton> _cancel = { nullptr };
|
2016-09-29 11:37:16 +00:00
|
|
|
OrderedSet<mtpRequestId> _disenableRequests;
|
2016-07-18 15:39:10 +00:00
|
|
|
mtpRequestId _reorderRequest = 0;
|
|
|
|
ChildWidget<PlainShadow> _topShadow = { nullptr };
|
2016-06-28 18:05:38 +00:00
|
|
|
ChildWidget<ScrollableBoxShadow> _bottomShadow = { nullptr };
|
|
|
|
|
|
|
|
QTimer _scrollTimer;
|
2016-07-18 15:39:10 +00:00
|
|
|
int32 _scrollDelta = 0;
|
2016-06-28 18:05:38 +00:00
|
|
|
|
|
|
|
int _aboutWidth = 0;
|
|
|
|
Text _about;
|
|
|
|
int _aboutHeight = 0;
|
|
|
|
|
2016-07-21 13:57:31 +00:00
|
|
|
mtpRequestId _archivedRequestId = 0;
|
|
|
|
bool _allArchivedLoaded = false;
|
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int32 stickerPacksCount(bool includeDisabledOfficial = false);
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
2016-09-26 13:57:08 +00:00
|
|
|
class StickersInner : public ScrolledWidget, public RPCSender, private base::Subscriber {
|
2016-06-28 18:05:38 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
using Section = StickersBox::Section;
|
|
|
|
StickersInner(Section section);
|
2016-07-18 15:39:10 +00:00
|
|
|
StickersInner(const Stickers::Order &archivedIds);
|
2016-01-09 12:51:42 +00:00
|
|
|
|
2015-12-02 17:17:53 +00:00
|
|
|
void rebuild();
|
2016-07-21 13:57:31 +00:00
|
|
|
void updateSize();
|
|
|
|
void updateRows(); // refresh only pack cover stickers
|
|
|
|
bool appendSet(const Stickers::Set &set);
|
2015-12-02 17:17:53 +00:00
|
|
|
bool savingStart() {
|
|
|
|
if (_saving) return false;
|
|
|
|
_saving = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-18 15:39:10 +00:00
|
|
|
Stickers::Order getOrder() const;
|
|
|
|
Stickers::Order getDisabledSets() const;
|
2015-12-02 17:17:53 +00:00
|
|
|
|
|
|
|
void setVisibleScrollbar(int32 width);
|
2016-09-10 20:54:59 +00:00
|
|
|
void setVisibleTopBottom(int visibleTop, int visibleBottom) override;
|
2015-12-02 17:17:53 +00:00
|
|
|
|
|
|
|
~StickersInner();
|
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void leaveEvent(QEvent *e) override;
|
2015-12-02 17:17:53 +00:00
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
signals:
|
2015-12-02 17:17:53 +00:00
|
|
|
void checkDraggingScroll(int localY);
|
|
|
|
void noDraggingScroll();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void onUpdateSelected();
|
2016-07-15 15:58:52 +00:00
|
|
|
void onClearRecent();
|
|
|
|
void onClearBoxDestroyed(QObject *box);
|
2015-12-02 17:17:53 +00:00
|
|
|
|
2016-09-10 20:54:59 +00:00
|
|
|
private slots:
|
|
|
|
void onImageLoaded();
|
|
|
|
|
2015-12-02 17:17:53 +00:00
|
|
|
private:
|
2016-07-18 15:39:10 +00:00
|
|
|
void setup();
|
2016-07-21 13:57:31 +00:00
|
|
|
void paintButton(Painter &p, int y, bool selected, const QString &text, int badgeCounter) const;
|
2015-12-02 17:17:53 +00:00
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
void step_shifting(uint64 ms, bool timer);
|
2015-12-02 17:17:53 +00:00
|
|
|
void paintRow(Painter &p, int32 index);
|
|
|
|
void clear();
|
2016-06-28 18:05:38 +00:00
|
|
|
void setActionSel(int32 actionSel);
|
2015-12-02 17:17:53 +00:00
|
|
|
float64 aboveShadowOpacity() const;
|
|
|
|
|
2016-09-10 20:54:59 +00:00
|
|
|
void readVisibleSets();
|
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
void installSet(uint64 setId);
|
2016-07-18 15:39:10 +00:00
|
|
|
void installDone(const MTPmessages_StickerSetInstallResult &result);
|
2016-07-14 11:59:55 +00:00
|
|
|
bool installFail(uint64 setId, const RPCError &error);
|
2016-06-28 18:05:38 +00:00
|
|
|
|
|
|
|
Section _section;
|
2016-07-18 15:39:10 +00:00
|
|
|
Stickers::Order _archivedIds;
|
2016-06-28 18:05:38 +00:00
|
|
|
|
2015-12-02 17:17:53 +00:00
|
|
|
int32 _rowHeight;
|
|
|
|
struct StickerSetRow {
|
2016-09-10 20:54:59 +00:00
|
|
|
StickerSetRow(uint64 id, DocumentData *sticker, int32 count, const QString &title, int titleWidth, bool installed, bool official, bool unread, bool disabled, bool recent, int32 pixw, int32 pixh) : id(id)
|
2015-12-02 17:17:53 +00:00
|
|
|
, sticker(sticker)
|
|
|
|
, count(count)
|
|
|
|
, title(title)
|
2016-09-10 20:54:59 +00:00
|
|
|
, titleWidth(titleWidth)
|
2016-06-28 18:05:38 +00:00
|
|
|
, installed(installed)
|
2015-12-06 15:50:02 +00:00
|
|
|
, official(official)
|
2016-06-28 18:05:38 +00:00
|
|
|
, unread(unread)
|
2015-12-02 17:17:53 +00:00
|
|
|
, disabled(disabled)
|
2016-07-15 15:58:52 +00:00
|
|
|
, recent(recent)
|
2015-12-02 17:17:53 +00:00
|
|
|
, pixw(pixw)
|
|
|
|
, pixh(pixh)
|
|
|
|
, yadd(0, 0) {
|
|
|
|
}
|
|
|
|
uint64 id;
|
|
|
|
DocumentData *sticker;
|
|
|
|
int32 count;
|
|
|
|
QString title;
|
2016-09-10 20:54:59 +00:00
|
|
|
int titleWidth;
|
2016-07-15 15:58:52 +00:00
|
|
|
bool installed, official, unread, disabled, recent;
|
2015-12-02 17:17:53 +00:00
|
|
|
int32 pixw, pixh;
|
2015-12-05 12:37:08 +00:00
|
|
|
anim::ivalue yadd;
|
2015-12-02 17:17:53 +00:00
|
|
|
};
|
2016-07-18 15:39:10 +00:00
|
|
|
using StickerSetRows = QList<StickerSetRow*>;
|
|
|
|
|
|
|
|
void rebuildAppendSet(const Stickers::Set &set, int maxNameWidth);
|
2016-07-21 13:57:31 +00:00
|
|
|
void fillSetCover(const Stickers::Set &set, DocumentData **outSticker, int *outWidth, int *outHeight) const;
|
|
|
|
int fillSetCount(const Stickers::Set &set) const;
|
2016-09-10 20:54:59 +00:00
|
|
|
QString fillSetTitle(const Stickers::Set &set, int maxNameWidth, int *outTitleWidth) const;
|
2016-07-21 13:57:31 +00:00
|
|
|
void fillSetFlags(const Stickers::Set &set, bool *outRecent, bool *outInstalled, bool *outOfficial, bool *outUnread, bool *outDisabled);
|
|
|
|
|
|
|
|
int countMaxNameWidth() const;
|
2016-07-18 15:39:10 +00:00
|
|
|
|
2015-12-02 17:17:53 +00:00
|
|
|
StickerSetRows _rows;
|
|
|
|
QList<uint64> _animStartTimes;
|
2016-06-28 18:05:38 +00:00
|
|
|
uint64 _aboveShadowFadeStart = 0;
|
|
|
|
anim::fvalue _aboveShadowFadeOpacity = { 0., 0. };
|
2015-12-02 17:17:53 +00:00
|
|
|
Animation _a_shifting;
|
|
|
|
|
2016-09-10 20:54:59 +00:00
|
|
|
int _visibleTop = 0;
|
|
|
|
int _visibleBottom = 0;
|
|
|
|
int _itemsTop = 0;
|
2015-12-06 15:50:02 +00:00
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
bool _saving = false;
|
2015-12-02 17:17:53 +00:00
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
int _actionSel = -1;
|
|
|
|
int _actionDown = -1;
|
2015-12-02 17:17:53 +00:00
|
|
|
|
2016-07-15 15:58:52 +00:00
|
|
|
int _clearWidth, _removeWidth, _returnWidth, _restoreWidth;
|
|
|
|
|
|
|
|
ConfirmBox *_clearBox = nullptr;
|
2015-12-02 17:17:53 +00:00
|
|
|
|
2016-07-21 13:57:31 +00:00
|
|
|
int _buttonHeight = 0;
|
|
|
|
bool _hasFeaturedButton = false;
|
|
|
|
bool _hasArchivedButton = false;
|
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
QPoint _mouse;
|
2016-07-21 13:57:31 +00:00
|
|
|
int _selected = -3; // -2 - featured stickers button, -1 - archived stickers button
|
2016-06-28 18:05:38 +00:00
|
|
|
int _pressed = -2;
|
|
|
|
QPoint _dragStart;
|
|
|
|
int _started = -1;
|
|
|
|
int _dragging = -1;
|
|
|
|
int _above = -1;
|
2015-12-02 17:17:53 +00:00
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
BoxShadow _aboveShadow;
|
2015-12-06 15:50:02 +00:00
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
int32 _scrollbar = 0;
|
2015-12-02 17:17:53 +00:00
|
|
|
};
|
|
|
|
|
2016-06-28 18:05:38 +00:00
|
|
|
} // namespace internal
|