Added ability to switch tab in tabbed selector with swipe.

This commit is contained in:
23rd 2025-02-18 21:43:48 +03:00 committed by John Preston
parent 4c74cbbbe9
commit acb0b029b9
2 changed files with 49 additions and 0 deletions

View file

@ -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<QColor, QColor> {
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;
}

View file

@ -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<GifsListWidget*> gifs() const;
not_null<StickersListWidget*> masks() const;
void setupSwipe();
const style::EmojiPan &_st;
const ComposeFeatures _features;
const std::shared_ptr<Show> _show;
const PauseReason _level = {};
const Fn<QColor()> _customTextColor;
HistoryView::SwipeBackResult _swipeBackData;
Mode _mode = Mode::Full;
int _roundRadius = 0;
int _footerTop = 0;