From defa0ae4d063ea7239af987d2d6f6ab88cee576b Mon Sep 17 00:00:00 2001 From: John Preston <johnprestonmail@gmail.com> Date: Tue, 14 Nov 2017 12:15:14 +0400 Subject: [PATCH] Improve stickers list variable width support. --- .../chat_helpers/chat_helpers.style | 2 +- .../chat_helpers/stickers_list_widget.cpp | 28 ++++++++++++++--- .../chat_helpers/stickers_list_widget.h | 1 + .../chat_helpers/tabbed_selector.cpp | 31 ++++++++++++++----- .../chat_helpers/tabbed_selector.h | 1 + .../SourceFiles/window/window_controller.cpp | 4 +-- 6 files changed, 53 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/chat_helpers.style b/Telegram/SourceFiles/chat_helpers/chat_helpers.style index e5d3c2d70d..38f1253990 100644 --- a/Telegram/SourceFiles/chat_helpers/chat_helpers.style +++ b/Telegram/SourceFiles/chat_helpers/chat_helpers.style @@ -29,7 +29,7 @@ switchPmButton: RoundButton(defaultBoxButton) { textTop: 7px; } stickersRestrictedLabel: FlatLabel(defaultFlatLabel) { - minWidth: 320px; + minWidth: 200px; align: align(center); textFg: noContactsColor; } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 45bc8298c9..9a1c99f182 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -493,6 +493,10 @@ object_ptr<TabbedSelector::InnerFooter> StickersListWidget::createFooter() { void StickersListWidget::visibleTopBottomUpdated( int visibleTop, int visibleBottom) { + if (!_columnCount) { + return; + } + auto top = getVisibleTop(); Inner::visibleTopBottomUpdated(visibleTop, visibleBottom); if (_section == Section::Featured) { @@ -831,7 +835,9 @@ void StickersListWidget::paintMegagroupEmptySet(Painter &p, int y, bool buttonSe auto infoLeft = megagroupSetInfoLeft(); _megagroupSetAbout.drawLeft(p, infoLeft, y, width() - infoLeft, width()); - auto &textBg = buttonSelected ? st::stickerGroupCategoryAdd.textBgOver : st::stickerGroupCategoryAdd.textBg; + auto &textBg = buttonSelected + ? st::stickerGroupCategoryAdd.textBgOver + : st::stickerGroupCategoryAdd.textBg; auto button = _megagroupSetButtonRect.translated(0, y); App::roundRect(p, myrtlrect(button), textBg, ImageRoundRadius::Small); @@ -1146,6 +1152,9 @@ void StickersListWidget::resizeEvent(QResizeEvent *e) { _settings->moveToLeft( (width() - _settings->width()) / 2, height() / 3); + if (!_megagroupSetAbout.isEmpty()) { + refreshMegagroupSetGeometry(); + } } void StickersListWidget::leaveEventHook(QEvent *e) { @@ -1213,14 +1222,19 @@ void StickersListWidget::refreshStickers() { if (_footer && _columnCount > 0) { refreshFooterIcons(); } - - _settings->setVisible(_section == Section::Stickers && _mySets.isEmpty()); + refreshSettingsVisibility(); _lastMousePosition = QCursor::pos(); updateSelected(); update(); } +void StickersListWidget::refreshSettingsVisibility() { + auto visible = (_section == Section::Stickers) + && _mySets.isEmpty(); + _settings->setVisible(visible); +} + void StickersListWidget::refreshFooterIcons() { Expects(_columnCount > 0); @@ -1566,6 +1580,8 @@ void StickersListWidget::setSelected(OverState newSelected) { } else { rtlupdate(removeButtonRect(button->section)); } + } else if (base::get_if<OverGroupAdd>(&_selected)) { + rtlupdate(megagroupSetButtonRectFinal()); } }; updateSelected(); @@ -1607,6 +1623,7 @@ void StickersListWidget::showStickerSet(uint64 setId) { _section = Section::Featured; refreshRecentStickers(true); + refreshSettingsVisibility(); if (_footer) { _footer->refreshIcons(ValidateIconAnimations::Scroll); } @@ -1622,6 +1639,7 @@ void StickersListWidget::showStickerSet(uint64 setId) { if (needRefresh) { _section = Section::Stickers; refreshRecentStickers(true); + refreshSettingsVisibility(); } auto y = 0; @@ -1659,7 +1677,9 @@ void StickersListWidget::showMegagroupSet(ChannelData *megagroup) { _megagroupSet = megagroup; if (_megagroupSetAbout.isEmpty()) { - _megagroupSetAbout.setText(st::stickerGroupCategoryAbout, lang(lng_group_stickers_description)); + _megagroupSetAbout.setText( + st::stickerGroupCategoryAbout, + lang(lng_group_stickers_description)); _megagroupSetButtonText = lang(lng_group_stickers_add).toUpper(); refreshMegagroupSetGeometry(); } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index 874b95c947..07f61c80c9 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -167,6 +167,7 @@ private: Hidden, }; void refreshMegagroupStickers(GroupStickersPlace place); + void refreshSettingsVisibility(); void updateSelected(); void setSelected(OverState newSelected); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index d29597451a..cfd1828232 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -386,9 +386,7 @@ void TabbedSelector::resizeEvent(QResizeEvent *e) { updateScrollGeometry(); } _bottomShadow->setGeometry(_tabsSlider->x(), _scroll->y() + _scroll->height() - st::lineWidth, _tabsSlider->width(), st::lineWidth); - if (_restrictedLabel) { - _restrictedLabel->move((width() - _restrictedLabel->width()), (height() / 3 - _restrictedLabel->height() / 2)); - } + updateRestrictedLabelGeometry(); _footerTop = height() - st::emojiFooterHeight; for (auto &tab : _tabs) { @@ -399,6 +397,18 @@ void TabbedSelector::resizeEvent(QResizeEvent *e) { update(); } +void TabbedSelector::updateRestrictedLabelGeometry() { + if (!_restrictedLabel) { + return; + } + + auto labelWidth = width() - st::stickerPanPadding * 2; + _restrictedLabel->resizeToWidth(labelWidth); + _restrictedLabel->moveToLeft( + (width() - _restrictedLabel->width()) / 2, + (height() / 3 - _restrictedLabel->height() / 2)); +} + void TabbedSelector::paintEvent(QPaintEvent *e) { Painter p(this); @@ -554,11 +564,18 @@ void TabbedSelector::checkRestrictedPeer() { (_currentTabType == SelectorTab::Gifs) ? megagroup->restricted(ChannelRestriction::f_send_gifs) : false; if (restricted) { if (!_restrictedLabel) { - auto text = (_currentTabType == SelectorTab::Stickers) ? lang(lng_restricted_send_stickers) : - (_currentTabType == SelectorTab::Gifs) ? lang(lng_restricted_send_gifs) : QString(); - _restrictedLabel.create(this, text, Ui::FlatLabel::InitType::Simple, st::stickersRestrictedLabel); + auto text = (_currentTabType == SelectorTab::Stickers) + ? lang(lng_restricted_send_stickers) + : (_currentTabType == SelectorTab::Gifs) + ? lang(lng_restricted_send_gifs) + : QString(); + _restrictedLabel.create( + this, + text, + Ui::FlatLabel::InitType::Simple, + st::stickersRestrictedLabel); _restrictedLabel->show(); - _restrictedLabel->move((width() - _restrictedLabel->width()), (height() / 3 - _restrictedLabel->height() / 2)); + updateRestrictedLabelGeometry(); currentTab()->footer()->hide(); _scroll->hide(); _bottomShadow->hide(); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index c8c9c5d083..f6db7627f5 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -155,6 +155,7 @@ private: void checkRestrictedPeer(); bool isRestrictedView(); + void updateRestrictedLabelGeometry(); QImage grabForAnimation(); diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index ed6112ba5e..3af5a3610a 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -185,11 +185,11 @@ bool Controller::takeThirdSectionFromLayer() { } void Controller::resizeForThirdSection() { - auto layout = computeColumnLayout(); - if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn) { + if (Adaptive::ThreeColumn()) { return; } + auto layout = computeColumnLayout(); auto tabbedSelectorSectionEnabled = Auth().data().tabbedSelectorSectionEnabled(); auto thirdSectionInfoEnabled =