2016-10-20 16:32:15 +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.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
#include "boxes/abstractbox.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;
|
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
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum class Section {
|
|
|
|
Installed,
|
|
|
|
Featured,
|
|
|
|
Archived,
|
|
|
|
ArchivedPart,
|
|
|
|
};
|
2016-12-13 17:07:56 +00:00
|
|
|
StickersBox(QWidget*, Section section);
|
|
|
|
StickersBox(QWidget*, const Stickers::Order &archivedIds);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void closeHook() 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;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
private slots:
|
|
|
|
void onStickersUpdated();
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
private:
|
2016-11-22 09:48:13 +00:00
|
|
|
void refreshTabs();
|
2016-10-20 16:32:15 +00:00
|
|
|
void rebuildList();
|
2016-11-22 09:48:13 +00:00
|
|
|
void updateTabsGeometry();
|
|
|
|
void switchTab();
|
|
|
|
void installSet(uint64 setId);
|
2016-12-13 17:07:56 +00:00
|
|
|
int getTopSkip() const;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
QPixmap grabContentCache();
|
|
|
|
|
|
|
|
void installDone(const MTPmessages_StickerSetInstallResult &result);
|
|
|
|
bool installFail(uint64 setId, const RPCError &error);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void preloadArchivedSets();
|
|
|
|
void requestArchivedSets();
|
2016-12-13 17:07:56 +00:00
|
|
|
void loadMoreArchived();
|
2016-10-20 16:32:15 +00:00
|
|
|
void getArchivedDone(uint64 offsetId, const MTPmessages_ArchivedStickers &result);
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::SettingsSlider> _tabs = { nullptr };
|
2016-11-22 09:48:13 +00:00
|
|
|
QList<Section> _tabIndices;
|
|
|
|
|
|
|
|
class CounterWidget;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<CounterWidget> _unreadBadge = { nullptr };
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
Section _section;
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
Tab _installed;
|
|
|
|
Tab _featured;
|
|
|
|
Tab _archived;
|
|
|
|
Tab *_tab = nullptr;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
std_::unique_ptr<Ui::SlideAnimation> _slideAnimation;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<BoxLayerTitleShadow> _titleShadow = { nullptr };
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
int _aboutWidth = 0;
|
|
|
|
Text _about;
|
|
|
|
int _aboutHeight = 0;
|
|
|
|
|
|
|
|
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.
|
2016-11-22 09:48:13 +00:00
|
|
|
class StickersBox::Inner : public TWidget, private base::Subscriber {
|
2016-10-20 16:32:15 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
using Section = StickersBox::Section;
|
|
|
|
Inner(QWidget *parent, Section section);
|
|
|
|
Inner(QWidget *parent, const Stickers::Order &archivedIds);
|
|
|
|
|
|
|
|
void rebuild();
|
|
|
|
void updateSize();
|
|
|
|
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);
|
|
|
|
|
|
|
|
void setInstallSetCallback(base::lambda<void(uint64 setId)> &&callback) {
|
|
|
|
_installSetCallback = std_::move(callback);
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
void setLoadMoreCallback(base::lambda<void()> &&callback) {
|
|
|
|
_loadMoreCallback = std_::move(callback);
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
void setVisibleTopBottom(int visibleTop, int visibleBottom) override;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
int getVisibleTop() const {
|
|
|
|
return _visibleTop;
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
~Inner();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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:
|
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);
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
void setActionDown(int newActionDown);
|
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
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void step_shifting(TimeMs ms, bool timer);
|
|
|
|
void paintRow(Painter &p, int index, TimeMs ms);
|
|
|
|
void paintFakeButton(Painter &p, int index, TimeMs ms);
|
2016-10-20 16:32:15 +00:00
|
|
|
void clear();
|
|
|
|
void setActionSel(int32 actionSel);
|
|
|
|
float64 aboveShadowOpacity() const;
|
|
|
|
|
|
|
|
void readVisibleSets();
|
|
|
|
|
|
|
|
Section _section;
|
|
|
|
Stickers::Order _archivedIds;
|
|
|
|
|
|
|
|
int32 _rowHeight;
|
2016-11-22 09:48:13 +00:00
|
|
|
struct Row {
|
|
|
|
Row(uint64 id, 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)
|
2016-10-20 16:32:15 +00:00
|
|
|
, sticker(sticker)
|
|
|
|
, count(count)
|
|
|
|
, title(title)
|
|
|
|
, titleWidth(titleWidth)
|
|
|
|
, installed(installed)
|
|
|
|
, official(official)
|
|
|
|
, unread(unread)
|
2016-11-22 09:48:13 +00:00
|
|
|
, archived(archived)
|
|
|
|
, removed(removed)
|
2016-10-20 16:32:15 +00:00
|
|
|
, pixw(pixw)
|
|
|
|
, pixh(pixh)
|
|
|
|
, yadd(0, 0) {
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
bool isRecentSet() const {
|
|
|
|
return (id == Stickers::CloudRecentSetId);
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
uint64 id;
|
|
|
|
DocumentData *sticker;
|
|
|
|
int32 count;
|
|
|
|
QString title;
|
|
|
|
int titleWidth;
|
2016-11-22 09:48:13 +00:00
|
|
|
bool installed, official, unread, archived, removed;
|
2016-10-20 16:32:15 +00:00
|
|
|
int32 pixw, pixh;
|
2016-12-05 11:01:08 +00:00
|
|
|
anim::value yadd;
|
2016-11-16 16:04:25 +00:00
|
|
|
QSharedPointer<Ui::RippleAnimation> ripple;
|
2016-10-20 16:32:15 +00:00
|
|
|
};
|
2016-11-22 09:48:13 +00:00
|
|
|
using Rows = QList<Row*>;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
void rebuildAppendSet(const Stickers::Set &set, int maxNameWidth);
|
|
|
|
void fillSetCover(const Stickers::Set &set, DocumentData **outSticker, int *outWidth, int *outHeight) const;
|
|
|
|
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);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
int countMaxNameWidth() const;
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
Rows _rows;
|
2016-12-01 19:20:33 +00:00
|
|
|
QList<TimeMs> _animStartTimes;
|
|
|
|
TimeMs _aboveShadowFadeStart = 0;
|
2016-12-05 11:01:08 +00:00
|
|
|
anim::value _aboveShadowFadeOpacity;
|
2016-12-07 13:32:25 +00:00
|
|
|
BasicAnimation _a_shifting;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
base::lambda<void(uint64 setId)> _installSetCallback;
|
2016-12-13 17:07:56 +00:00
|
|
|
base::lambda<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;
|
|
|
|
int _selected = -1;
|
|
|
|
int _pressed = -1;
|
2016-10-20 16:32:15 +00:00
|
|
|
QPoint _dragStart;
|
|
|
|
int _started = -1;
|
|
|
|
int _dragging = -1;
|
|
|
|
int _above = -1;
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
int _scrollbar = 0;
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
};
|