Moved mask management to separate box.
This commit is contained in:
parent
2a3115f461
commit
2d17bd02a3
|
@ -368,7 +368,8 @@ void StickersBox::Tab::saveScrollTop() {
|
||||||
StickersBox::StickersBox(
|
StickersBox::StickersBox(
|
||||||
QWidget*,
|
QWidget*,
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
Section section)
|
Section section,
|
||||||
|
bool masks)
|
||||||
: _controller(controller)
|
: _controller(controller)
|
||||||
, _api(&controller->session().mtp())
|
, _api(&controller->session().mtp())
|
||||||
, _tabs(this, st::stickersTabs)
|
, _tabs(this, st::stickersTabs)
|
||||||
|
@ -376,10 +377,11 @@ StickersBox::StickersBox(
|
||||||
this,
|
this,
|
||||||
controller->session().data().stickers().featuredSetsUnreadCountValue())
|
controller->session().data().stickers().featuredSetsUnreadCountValue())
|
||||||
, _section(section)
|
, _section(section)
|
||||||
, _installed(0, this, controller, Section::Installed)
|
, _isMasks(masks)
|
||||||
, _masks(1, this, controller, Section::Masks)
|
, _installed(_isMasks ? Tab() : Tab(0, this, controller, Section::Installed))
|
||||||
, _featured(2, this, controller, Section::Featured)
|
, _masks(_isMasks ? Tab(0, this, controller, Section::Masks) : Tab())
|
||||||
, _archived(3, this, controller, Section::Archived) {
|
, _featured(_isMasks ? Tab() : Tab(1, this, controller, Section::Featured))
|
||||||
|
, _archived((_isMasks ? 1 : 2), this, controller, Section::Archived) {
|
||||||
_tabs->setRippleTopRoundRadius(st::boxRadius);
|
_tabs->setRippleTopRoundRadius(st::boxRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,6 +392,7 @@ StickersBox::StickersBox(
|
||||||
: _controller(controller)
|
: _controller(controller)
|
||||||
, _api(&controller->session().mtp())
|
, _api(&controller->session().mtp())
|
||||||
, _section(Section::Installed)
|
, _section(Section::Installed)
|
||||||
|
, _isMasks(false)
|
||||||
, _installed(0, this, controller, megagroup)
|
, _installed(0, this, controller, megagroup)
|
||||||
, _megagroupSet(megagroup) {
|
, _megagroupSet(megagroup) {
|
||||||
_installed.widget()->scrollsToY(
|
_installed.widget()->scrollsToY(
|
||||||
|
@ -405,6 +408,7 @@ StickersBox::StickersBox(
|
||||||
: _controller(controller)
|
: _controller(controller)
|
||||||
, _api(&controller->session().mtp())
|
, _api(&controller->session().mtp())
|
||||||
, _section(Section::Attached)
|
, _section(Section::Attached)
|
||||||
|
, _isMasks(false)
|
||||||
, _attached(0, this, controller, Section::Attached)
|
, _attached(0, this, controller, Section::Attached)
|
||||||
, _attachedSets(attachedSets) {
|
, _attachedSets(attachedSets) {
|
||||||
}
|
}
|
||||||
|
@ -621,21 +625,27 @@ void StickersBox::prepare() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void StickersBox::refreshTabs() {
|
void StickersBox::refreshTabs() {
|
||||||
if (!_tabs) return;
|
if (!_tabs) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &stickers = session().data().stickers();
|
||||||
|
|
||||||
_tabIndices.clear();
|
_tabIndices.clear();
|
||||||
auto sections = std::vector<QString>();
|
auto sections = std::vector<QString>();
|
||||||
|
if (_installed.widget()) {
|
||||||
sections.push_back(tr::lng_stickers_installed_tab(tr::now).toUpper());
|
sections.push_back(tr::lng_stickers_installed_tab(tr::now).toUpper());
|
||||||
_tabIndices.push_back(Section::Installed);
|
_tabIndices.push_back(Section::Installed);
|
||||||
if (!session().data().stickers().maskSetsOrder().isEmpty()) {
|
}
|
||||||
|
if (!stickers.maskSetsOrder().isEmpty() && _masks.widget()) {
|
||||||
sections.push_back(tr::lng_stickers_masks_tab(tr::now).toUpper());
|
sections.push_back(tr::lng_stickers_masks_tab(tr::now).toUpper());
|
||||||
_tabIndices.push_back(Section::Masks);
|
_tabIndices.push_back(Section::Masks);
|
||||||
}
|
}
|
||||||
if (!session().data().stickers().featuredSetsOrder().isEmpty()) {
|
if (!stickers.featuredSetsOrder().isEmpty() && _featured.widget()) {
|
||||||
sections.push_back(tr::lng_stickers_featured_tab(tr::now).toUpper());
|
sections.push_back(tr::lng_stickers_featured_tab(tr::now).toUpper());
|
||||||
_tabIndices.push_back(Section::Featured);
|
_tabIndices.push_back(Section::Featured);
|
||||||
}
|
}
|
||||||
if (!session().data().stickers().archivedSetsOrder().isEmpty()) {
|
if (!stickers.archivedSetsOrder().isEmpty() && _archived.widget()) {
|
||||||
sections.push_back(tr::lng_stickers_archived_tab(tr::now).toUpper());
|
sections.push_back(tr::lng_stickers_archived_tab(tr::now).toUpper());
|
||||||
_tabIndices.push_back(Section::Archived);
|
_tabIndices.push_back(Section::Archived);
|
||||||
}
|
}
|
||||||
|
@ -701,7 +711,7 @@ void StickersBox::paintEvent(QPaintEvent *e) {
|
||||||
void StickersBox::updateTabsGeometry() {
|
void StickersBox::updateTabsGeometry() {
|
||||||
if (!_tabs) return;
|
if (!_tabs) return;
|
||||||
|
|
||||||
const auto maxTabs = 4;
|
const auto maxTabs = _isMasks ? 2 : 3;
|
||||||
|
|
||||||
_tabs->resizeToWidth(_tabIndices.size() * width() / maxTabs);
|
_tabs->resizeToWidth(_tabIndices.size() * width() / maxTabs);
|
||||||
_unreadBadge->setVisible(_tabIndices.contains(Section::Featured));
|
_unreadBadge->setVisible(_tabIndices.contains(Section::Featured));
|
||||||
|
@ -935,23 +945,30 @@ void StickersBox::rebuildList(Tab *tab) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void StickersBox::saveChanges() {
|
void StickersBox::saveChanges() {
|
||||||
|
const auto installed = _installed.widget();
|
||||||
|
const auto masks = _masks.widget();
|
||||||
|
|
||||||
// Make sure that our changes in other tabs are applied in the Installed tab.
|
// Make sure that our changes in other tabs are applied in the Installed tab.
|
||||||
|
if (installed) {
|
||||||
rebuildList(&_installed);
|
rebuildList(&_installed);
|
||||||
|
}
|
||||||
|
if (masks) {
|
||||||
rebuildList(&_masks);
|
rebuildList(&_masks);
|
||||||
|
}
|
||||||
|
|
||||||
if (_someArchivedLoaded) {
|
if (_someArchivedLoaded) {
|
||||||
session().local().writeArchivedStickers();
|
session().local().writeArchivedStickers();
|
||||||
}
|
}
|
||||||
if (const auto widget = _installed.widget()) {
|
if (installed) {
|
||||||
session().api().saveStickerSets(
|
session().api().saveStickerSets(
|
||||||
widget->getOrder(),
|
installed->getOrder(),
|
||||||
widget->getRemovedSets(),
|
installed->getRemovedSets(),
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
if (const auto widget = _masks.widget()) {
|
if (masks) {
|
||||||
session().api().saveStickerSets(
|
session().api().saveStickerSets(
|
||||||
widget->getOrder(),
|
masks->getOrder(),
|
||||||
widget->getRemovedSets(),
|
masks->getRemovedSets(),
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,8 @@ public:
|
||||||
StickersBox(
|
StickersBox(
|
||||||
QWidget*,
|
QWidget*,
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
Section section);
|
Section section,
|
||||||
|
bool masks = false);
|
||||||
StickersBox(
|
StickersBox(
|
||||||
QWidget*,
|
QWidget*,
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
|
@ -145,6 +146,7 @@ private:
|
||||||
object_ptr<CounterWidget> _unreadBadge = { nullptr };
|
object_ptr<CounterWidget> _unreadBadge = { nullptr };
|
||||||
|
|
||||||
Section _section;
|
Section _section;
|
||||||
|
const bool _isMasks;
|
||||||
|
|
||||||
Tab _installed;
|
Tab _installed;
|
||||||
Tab _masks;
|
Tab _masks;
|
||||||
|
|
|
@ -128,6 +128,8 @@ public:
|
||||||
|
|
||||||
void clearHeavyData();
|
void clearHeavyData();
|
||||||
|
|
||||||
|
rpl::producer<> openSettingsRequests() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
|
@ -197,6 +199,8 @@ private:
|
||||||
object_ptr<Ui::CrossButton> _searchCancel = { nullptr };
|
object_ptr<Ui::CrossButton> _searchCancel = { nullptr };
|
||||||
QPointer<QWidget> _focusTakenFrom;
|
QPointer<QWidget> _focusTakenFrom;
|
||||||
|
|
||||||
|
rpl::event_stream<> _openSettingsRequests;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto StickersListWidget::PrepareStickers(
|
auto StickersListWidget::PrepareStickers(
|
||||||
|
@ -527,6 +531,10 @@ void StickersListWidget::Footer::resizeSearchControls() {
|
||||||
_searchCancel->moveToRight(st::gifsSearchCancelPosition.x(), st::gifsSearchCancelPosition.y());
|
_searchCancel->moveToRight(st::gifsSearchCancelPosition.x(), st::gifsSearchCancelPosition.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<> StickersListWidget::Footer::openSettingsRequests() const {
|
||||||
|
return _openSettingsRequests.events();
|
||||||
|
}
|
||||||
|
|
||||||
void StickersListWidget::Footer::mousePressEvent(QMouseEvent *e) {
|
void StickersListWidget::Footer::mousePressEvent(QMouseEvent *e) {
|
||||||
if (e->button() != Qt::LeftButton) {
|
if (e->button() != Qt::LeftButton) {
|
||||||
return;
|
return;
|
||||||
|
@ -535,11 +543,7 @@ void StickersListWidget::Footer::mousePressEvent(QMouseEvent *e) {
|
||||||
updateSelected();
|
updateSelected();
|
||||||
|
|
||||||
if (_iconOver == SpecialOver::Settings) {
|
if (_iconOver == SpecialOver::Settings) {
|
||||||
_pan->controller()->show(Box<StickersBox>(
|
_openSettingsRequests.fire({});
|
||||||
_pan->controller(),
|
|
||||||
(hasOnlyFeaturedSets()
|
|
||||||
? StickersBox::Section::Featured
|
|
||||||
: StickersBox::Section::Installed)));
|
|
||||||
} else if (_iconOver == SpecialOver::Search) {
|
} else if (_iconOver == SpecialOver::Search) {
|
||||||
toggleSearch(true);
|
toggleSearch(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -916,8 +920,10 @@ StickersListWidget::StickersListWidget(
|
||||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||||
|
|
||||||
_settings->addClickHandler([=] {
|
_settings->addClickHandler([=] {
|
||||||
|
using Section = StickersBox::Section;
|
||||||
controller->show(
|
controller->show(
|
||||||
Box<StickersBox>(controller, StickersBox::Section::Installed));
|
Box<StickersBox>(controller, Section::Installed, _isMasks),
|
||||||
|
Ui::LayerOption::KeepOther);
|
||||||
});
|
});
|
||||||
|
|
||||||
session().downloaderTaskFinished(
|
session().downloaderTaskFinished(
|
||||||
|
@ -967,6 +973,20 @@ object_ptr<TabbedSelector::InnerFooter> StickersListWidget::createFooter() {
|
||||||
|
|
||||||
auto result = object_ptr<Footer>(this);
|
auto result = object_ptr<Footer>(this);
|
||||||
_footer = result;
|
_footer = result;
|
||||||
|
|
||||||
|
_footer->openSettingsRequests(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
const auto onlyFeatured = _footer->hasOnlyFeaturedSets();
|
||||||
|
Ui::show(Box<StickersBox>(
|
||||||
|
controller(),
|
||||||
|
(onlyFeatured
|
||||||
|
? StickersBox::Section::Featured
|
||||||
|
: _isMasks
|
||||||
|
? StickersBox::Section::Masks
|
||||||
|
: StickersBox::Section::Installed),
|
||||||
|
onlyFeatured ? false : _isMasks),
|
||||||
|
Ui::LayerOption::KeepOther);
|
||||||
|
}, _footer->lifetime());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue