From 0e2c282476a0b2bf753adb00a18e800238a957a4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 11 Apr 2017 17:02:11 +0300 Subject: [PATCH] Don't stop GIFs when TabbedSection is opened. Also improve the appearance of Stickers and GIFs tabs with no items. --- Telegram/Resources/langs/lang.strings | 3 ++- Telegram/SourceFiles/boxes/stickers_box.cpp | 5 ++++ .../chat_helpers/gifs_list_widget.cpp | 5 ++-- .../chat_helpers/stickers_list_widget.cpp | 23 +++++++++++++++---- .../SourceFiles/chat_helpers/tabbed_panel.cpp | 19 ++++++++++++--- .../SourceFiles/chat_helpers/tabbed_panel.h | 1 + .../chat_helpers/tabbed_section.cpp | 3 +++ .../chat_helpers/tabbed_selector.cpp | 13 +++++++---- .../chat_helpers/tabbed_selector.h | 12 +++++++++- 9 files changed, 66 insertions(+), 18 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 9f2fe54dd..c6fe0a516 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -781,8 +781,9 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org "lng_switch_gifs" = "GIFs"; "lng_stickers_featured_add" = "Add"; "lng_gifs_search" = "Search GIFs"; +"lng_gifs_no_saved" = "You have no saved GIFs yet."; -"lng_inline_bot_no_results" = "No results"; +"lng_inline_bot_no_results" = "No results."; "lng_inline_bot_via" = "via {inline_bot}"; "lng_box_remove" = "Remove"; diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index 2ee50b6d1..364268982 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -301,6 +301,10 @@ void StickersBox::refreshTabs() { if ((_tab == &_archived && !_tabIndices.contains(Section::Archived)) || (_tab == &_featured && !_tabIndices.contains(Section::Featured))) { switchTab(); + } else if (_tab == &_archived) { + _tabs->setActiveSectionFast(_tabIndices.indexOf(Section::Archived)); + } else if (_tab == &_featured) { + _tabs->setActiveSectionFast(_tabIndices.indexOf(Section::Featured)); } updateTabsGeometry(); } @@ -410,6 +414,7 @@ void StickersBox::switchTab() { _tab->widget()->show(); rebuildList(); onScrollToY(_tab->getScrollTop()); + setInnerVisible(true); auto nowCache = grabContentCache(); auto nowIndex = _tab->index(); diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 12aacca18..e06fc42bd 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -254,7 +254,8 @@ void GifsListWidget::paintInlineItems(Painter &p, QRect clip) { if (_rows.isEmpty()) { p.setFont(st::normalFont); p.setPen(st::noContactsColor); - p.drawText(QRect(0, 0, width(), (height() / 3) * 2 + st::normalFont->height), lang(lng_inline_bot_no_results), style::al_center); + auto text = lang(_inlineQuery.isEmpty() ? lng_gifs_no_saved : lng_inline_bot_no_results); + p.drawText(QRect(0, 0, width(), (height() / 3) * 2 + st::normalFont->height), text, style::al_center); return; } auto gifPaused = controller()->isGifPausedAtLeastFor(Window::GifPauseReason::SavedGifs); @@ -392,7 +393,6 @@ TabbedSelector::InnerFooter *GifsListWidget::getFooter() const { void GifsListWidget::processHideFinished() { clearSelection(); - controller()->disableGifPauseReason(Window::GifPauseReason::SavedGifs); } void GifsListWidget::processPanelHideFinished() { @@ -753,7 +753,6 @@ void GifsListWidget::afterShown() { if (_footer) { _footer->stealFocus(); } - controller()->enableGifPauseReason(Window::GifPauseReason::SavedGifs); } void GifsListWidget::beforeHiding() { diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index aa69d2356..85049a9c8 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -61,6 +61,7 @@ public: void preloadImages(); void validateSelectedIcon(uint64 setId, ValidateIconAnimations animations); void refreshIcons(ValidateIconAnimations animations); + bool hasOnlyFeaturedSets() const; void leaveToChildEvent(QEvent *e, QWidget *child) override; @@ -184,12 +185,15 @@ void StickersListWidget::Footer::leaveToChildEvent(QEvent *e, QWidget *child) { void StickersListWidget::Footer::paintEvent(QPaintEvent *e) { Painter p(this); - paintStickerSettingsIcon(p); if (_icons.isEmpty()) { return; } + if (!hasOnlyFeaturedSets()) { + paintStickerSettingsIcon(p); + } + auto selxrel = _iconsLeft + qRound(_iconSelX.current()); auto selx = selxrel - qRound(_iconsX.current()); @@ -242,7 +246,7 @@ void StickersListWidget::Footer::mousePressEvent(QMouseEvent *e) { updateSelected(); if (_iconOver == _icons.size()) { - Ui::show(Box(StickersBox::Section::Installed)); + Ui::show(Box(hasOnlyFeaturedSets() ? StickersBox::Section::Featured : StickersBox::Section::Installed)); } else { _iconDown = _iconOver; _iconsMouseDown = _iconsMousePos; @@ -336,7 +340,9 @@ void StickersListWidget::Footer::updateSelected() { if (rtl()) x = width() - x; x -= _iconsLeft; if (x >= st::emojiCategory.width * (kVisibleIconsCount - 1) && x < st::emojiCategory.width * kVisibleIconsCount && y >= _iconsTop && y < _iconsTop + st::emojiCategory.height) { - newOver = _icons.size(); + if (!_icons.isEmpty() && !hasOnlyFeaturedSets()) { + newOver = _icons.size(); + } } else if (!_icons.isEmpty()) { if (y >= _iconsTop && y < _iconsTop + st::emojiCategory.height && x >= 0 && x < (kVisibleIconsCount - 1) * st::emojiCategory.width && x < _icons.size() * st::emojiCategory.width) { x += qRound(_iconsX.current()); @@ -373,6 +379,10 @@ void StickersListWidget::Footer::refreshIcons(ValidateIconAnimations animations) update(); } +bool StickersListWidget::Footer::hasOnlyFeaturedSets() const { + return (_icons.size() == 1) && (_icons[0].setId == Stickers::FeaturedSetId); +} + void StickersListWidget::Footer::paintStickerSettingsIcon(Painter &p) const { int settingsLeft = _iconsLeft + (kVisibleIconsCount - 1) * st::emojiCategory.width; st::stickersSettings.paint(p, settingsLeft + st::emojiCategory.iconPosition.x(), _iconsTop + st::emojiCategory.iconPosition.y(), width()); @@ -1029,12 +1039,15 @@ void StickersListWidget::refreshStickers() { resize(width(), newHeight); } - _settings->setVisible(_section == Section::Stickers && _mySets.isEmpty()); - if (_footer) { _footer->refreshIcons(ValidateIconAnimations::None); + if (_footer->hasOnlyFeaturedSets() && _section != Section::Featured) { + showStickerSet(Stickers::FeaturedSetId); + } } + _settings->setVisible(_section == Section::Stickers && _mySets.isEmpty()); + _lastMousePosition = QCursor::pos(); updateSelected(); update(); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp index 89a1e614c..a68750269 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp @@ -23,6 +23,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/widgets/shadow.h" #include "styles/style_chat_helpers.h" #include "chat_helpers/tabbed_selector.h" +#include "window/window_controller.h" #include "mainwindow.h" namespace ChatHelpers { @@ -37,9 +38,20 @@ TabbedPanel::TabbedPanel(QWidget *parent, gsl::not_null con } TabbedPanel::TabbedPanel(QWidget *parent, gsl::not_null controller, object_ptr selector) : TWidget(parent) +, _controller(controller) , _selector(std::move(selector)) { _selector->setParent(this); _selector->setRoundRadius(st::buttonRadius); + _selector->setAfterShownCallback([this](EmojiPanelTab tab) { + if (tab == EmojiPanelTab::Gifs) { + _controller->enableGifPauseReason(Window::GifPauseReason::SavedGifs); + } + }); + _selector->setBeforeHidingCallback([this](EmojiPanelTab tab) { + if (tab == EmojiPanelTab::Gifs) { + _controller->disableGifPauseReason(Window::GifPauseReason::SavedGifs); + } + }); resize(QRect(0, 0, st::emojiPanWidth, st::emojiPanMaxHeight).marginsAdded(innerPadding()).size()); @@ -307,9 +319,10 @@ void TabbedPanel::toggleAnimated() { } object_ptr TabbedPanel::takeSelector() { - auto result = std::move(_selector); - hideAnimated(); - return result; + if (!isHidden() && !_hiding) { + startOpacityAnimation(true); + } + return std::move(_selector); } QPointer TabbedPanel::getSelector() const { diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.h b/Telegram/SourceFiles/chat_helpers/tabbed_panel.h index 2319b113b..fcbfa5722 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.h @@ -106,6 +106,7 @@ private: bool preventAutoHide() const; void updateContentHeight(); + gsl::not_null _controller; object_ptr _selector; int _contentMaxHeight = 0; diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_section.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_section.cpp index 1ed102d5f..5e7ac4e30 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_section.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_section.cpp @@ -42,6 +42,8 @@ TabbedSection::TabbedSection(QWidget *parent, gsl::not_null _cancelledCallback(); } }); + _selector->setAfterShownCallback(base::lambda()); + _selector->setBeforeHidingCallback(base::lambda()); setAttribute(Qt::WA_OpaquePaintEvent, true); } @@ -59,6 +61,7 @@ void TabbedSection::resizeEvent(QResizeEvent *e) { } object_ptr TabbedSection::takeSelector() { + _selector->beforeHiding(); return std::move(_selector); } diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index 7170784a0..822e4b354 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -377,8 +377,7 @@ void TabbedSelector::paintEvent(QPaintEvent *e) { paintSlideFrame(p, ms); if (!_a_slide.animating()) { _slideAnimation.reset(); - showAll(); - currentTab()->widget()->afterShown(); + afterShown(); emit slideFinished(); } } else { @@ -482,6 +481,9 @@ void TabbedSelector::showStarted() { void TabbedSelector::beforeHiding() { if (!_scroll->isHidden()) { currentTab()->widget()->beforeHiding(); + if (_beforeHidingCallback) { + _beforeHidingCallback(_currentTabType); + } } } @@ -489,6 +491,9 @@ void TabbedSelector::afterShown() { if (!_a_slide.animating()) { showAll(); currentTab()->widget()->afterShown(); + if (_afterShownCallback) { + _afterShownCallback(_currentTabType); + } } } @@ -555,9 +560,7 @@ void TabbedSelector::switchTab() { auto wasTab = _currentTabType; currentTab()->saveScrollTop(); - if (!_scroll->isHidden()) { - currentTab()->widget()->beforeHiding(); - } + beforeHiding(); auto wasCache = grabForAnimation(); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index 4ae1febb0..8df73f7e3 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -66,6 +66,14 @@ public: return _a_slide.animating(); } + using TabType = EmojiPanelTab; + void setAfterShownCallback(base::lambda callback) { + _afterShownCallback = std::move(callback); + } + void setBeforeHidingCallback(base::lambda callback) { + _beforeHidingCallback = std::move(callback); + } + ~TabbedSelector(); class Inner; @@ -91,7 +99,6 @@ signals: void checkForHide(); private: - using TabType = EmojiPanelTab; class Tab { public: static constexpr auto kCount = 3; @@ -173,6 +180,9 @@ private: std::array _tabs; TabType _currentTabType = TabType::Emoji; + base::lambda _afterShownCallback; + base::lambda _beforeHidingCallback; + }; class TabbedSelector::Inner : public TWidget {