mirror of https://github.com/procxx/kepka.git
Don't stop GIFs when TabbedSection is opened.
Also improve the appearance of Stickers and GIFs tabs with no items.
This commit is contained in:
parent
891d200e2d
commit
0e2c282476
|
@ -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";
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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>(StickersBox::Section::Installed));
|
||||
Ui::show(Box<StickersBox>(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();
|
||||
|
|
|
@ -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<Window::Controller*> con
|
|||
}
|
||||
|
||||
TabbedPanel::TabbedPanel(QWidget *parent, gsl::not_null<Window::Controller*> controller, object_ptr<TabbedSelector> 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<TabbedSelector> TabbedPanel::takeSelector() {
|
||||
auto result = std::move(_selector);
|
||||
hideAnimated();
|
||||
return result;
|
||||
if (!isHidden() && !_hiding) {
|
||||
startOpacityAnimation(true);
|
||||
}
|
||||
return std::move(_selector);
|
||||
}
|
||||
|
||||
QPointer<TabbedSelector> TabbedPanel::getSelector() const {
|
||||
|
|
|
@ -106,6 +106,7 @@ private:
|
|||
bool preventAutoHide() const;
|
||||
void updateContentHeight();
|
||||
|
||||
gsl::not_null<Window::Controller*> _controller;
|
||||
object_ptr<TabbedSelector> _selector;
|
||||
|
||||
int _contentMaxHeight = 0;
|
||||
|
|
|
@ -42,6 +42,8 @@ TabbedSection::TabbedSection(QWidget *parent, gsl::not_null<Window::Controller*>
|
|||
_cancelledCallback();
|
||||
}
|
||||
});
|
||||
_selector->setAfterShownCallback(base::lambda<void(EmojiPanelTab)>());
|
||||
_selector->setBeforeHidingCallback(base::lambda<void(EmojiPanelTab)>());
|
||||
|
||||
setAttribute(Qt::WA_OpaquePaintEvent, true);
|
||||
}
|
||||
|
@ -59,6 +61,7 @@ void TabbedSection::resizeEvent(QResizeEvent *e) {
|
|||
}
|
||||
|
||||
object_ptr<TabbedSelector> TabbedSection::takeSelector() {
|
||||
_selector->beforeHiding();
|
||||
return std::move(_selector);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -66,6 +66,14 @@ public:
|
|||
return _a_slide.animating();
|
||||
}
|
||||
|
||||
using TabType = EmojiPanelTab;
|
||||
void setAfterShownCallback(base::lambda<void(TabType)> callback) {
|
||||
_afterShownCallback = std::move(callback);
|
||||
}
|
||||
void setBeforeHidingCallback(base::lambda<void(TabType)> 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<Tab, Tab::kCount> _tabs;
|
||||
TabType _currentTabType = TabType::Emoji;
|
||||
|
||||
base::lambda<void(TabType)> _afterShownCallback;
|
||||
base::lambda<void(TabType)> _beforeHidingCallback;
|
||||
|
||||
};
|
||||
|
||||
class TabbedSelector::Inner : public TWidget {
|
||||
|
|
Loading…
Reference in New Issue