diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index f0900e98eb..a212fd4c2d 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/stickers/data_stickers.h" #include "data/stickers/data_custom_emoji.h" // AllowEmojiWithoutPremium. #include "boxes/premium_preview_box.h" +#include "history/history_view_swipe.h" #include "lang/lang_keys.h" #include "mainwindow.h" #include "apiwrap.h" @@ -522,6 +523,7 @@ TabbedSelector::TabbedSelector( if (hasEmojiTab()) { emoji()->refreshEmoji(); } + setupSwipe(); //setAttribute(Qt::WA_AcceptTouchEvents); setAttribute(Qt::WA_OpaquePaintEvent, false); showAll(); @@ -530,6 +532,48 @@ TabbedSelector::TabbedSelector( TabbedSelector::~TabbedSelector() = default; +void TabbedSelector::setupSwipe() { + HistoryView::SetupSwipeHandler(this, _scroll.data(), [=]( + HistoryView::ChatPaintGestureHorizontalData data) { + if (data.translation != 0) { + if (!_swipeBackData.callback) { + _swipeBackData = HistoryView::SetupSwipeBack( + this, + [=]() -> std::pair { + return { + st::historyForwardChooseBg->c, + st::historyForwardChooseFg->c, + }; + }, + data.translation < 0); + } + _swipeBackData.callback(data); + return; + } else if (_swipeBackData.lifetime) { + _swipeBackData = {}; + } + }, [=](int, Qt::LayoutDirection direction) { + if (!_tabsSlider) { + return HistoryView::SwipeHandlerFinishData(); + } + const auto activeSection = _tabsSlider->activeSection(); + const auto isToLeft = direction == Qt::RightToLeft; + if ((isToLeft && activeSection > 0) + || (!isToLeft && activeSection < _tabs.size() - 1)) { + return HistoryView::DefaultSwipeBackHandlerFinishData([=] { + if (_tabsSlider + && _tabsSlider->activeSection() == activeSection) { + _swipeBackData = {}; + _tabsSlider->setActiveSection(isToLeft + ? activeSection - 1 + : activeSection + 1); + } + }); + } + return HistoryView::SwipeHandlerFinishData(); + }, nullptr); +} + const style::EmojiPan &TabbedSelector::st() const { return _st; } diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index ad8821d846..6670039c38 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/animations.h" #include "ui/effects/message_sending_animation_common.h" #include "ui/effects/panel_animation.h" +#include "history/history_view_swipe_data.h" #include "ui/cached_round_corners.h" #include "mtproto/sender.h" #include "base/object_ptr.h" @@ -287,12 +288,16 @@ private: not_null gifs() const; not_null masks() const; + void setupSwipe(); + const style::EmojiPan &_st; const ComposeFeatures _features; const std::shared_ptr _show; const PauseReason _level = {}; const Fn _customTextColor; + HistoryView::SwipeBackResult _swipeBackData; + Mode _mode = Mode::Full; int _roundRadius = 0; int _footerTop = 0;