diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 1c881e2ed5..828eedbf1b 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -919,6 +919,8 @@ PRIVATE history/history_unread_things.h history/history_view_highlight_manager.cpp history/history_view_highlight_manager.h + history/history_view_swipe_back_session.cpp + history/history_view_swipe_back_session.h history/history_widget.cpp history/history_widget.h info/bot/earn/info_bot_earn_list.cpp diff --git a/Telegram/SourceFiles/history/history_view_swipe_back_session.cpp b/Telegram/SourceFiles/history/history_view_swipe_back_session.cpp new file mode 100644 index 0000000000..179c1bea9a --- /dev/null +++ b/Telegram/SourceFiles/history/history_view_swipe_back_session.cpp @@ -0,0 +1,55 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "history/history_view_swipe_back_session.h" + +#include "history/history_view_swipe_data.h" +#include "history/history_view_swipe.h" +#include "history/view/history_view_list_widget.h" +#include "ui/chat/chat_style.h" +#include "window/window_session_controller.h" + +namespace Window { + +void SetupSwipeBackSection( + not_null parent, + not_null scroll, + not_null list) { + const auto swipeBackData + = list->lifetime().make_state(); + HistoryView::SetupSwipeHandler(parent, scroll, [=]( + HistoryView::ChatPaintGestureHorizontalData data) { + if (data.translation > 0) { + if (!swipeBackData->callback) { + const auto color = [=]() -> std::pair { + const auto c = list->delegate()->listPreparePaintContext({ + .theme = list->delegate()->listChatTheme(), + }); + return { + c.st->msgServiceBg()->c, + c.st->msgServiceFg()->c, + }; + }; + (*swipeBackData) = HistoryView::SetupSwipeBack(parent, color); + } + swipeBackData->callback(data); + return; + } else if (swipeBackData->lifetime) { + (*swipeBackData) = {}; + } + }, [=](int, Qt::LayoutDirection direction) { + if (direction != Qt::RightToLeft) { + return HistoryView::SwipeHandlerFinishData(); + } + return HistoryView::SwipeHandlerFinishData{ + .callback = [=] { list->controller()->showBackFromStack(); }, + .msgBareId = HistoryView::kMsgBareIdSwipeBack, + }; + }, list->touchMaybeSelectingValue()); +} + +} // namespace Window diff --git a/Telegram/SourceFiles/history/history_view_swipe_back_session.h b/Telegram/SourceFiles/history/history_view_swipe_back_session.h new file mode 100644 index 0000000000..8d65f684e9 --- /dev/null +++ b/Telegram/SourceFiles/history/history_view_swipe_back_session.h @@ -0,0 +1,30 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +class WindowListDelegate; + +namespace HistoryView { +class ListWidget; +} // namespace HistoryView + +namespace Ui { +class RpWidget; +class ScrollArea; +} // namespace Ui + +namespace Window { + +class SectionWidget; + +void SetupSwipeBackSection( + not_null parent, + not_null scroll, + not_null list); + +} // namespace Window diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp index 7a9ecd8dcc..b8c380c5c1 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_item_components.h" #include "history/history_item.h" +#include "history/history_view_swipe_back_session.h" #include "ui/boxes/confirm_box.h" #include "ui/widgets/scroll_area.h" #include "ui/widgets/shadow.h" @@ -173,6 +174,7 @@ PinnedWidget::PinnedWidget( setupClearButton(); setupTranslateBar(); + Window::SetupSwipeBackSection(this, _scroll.get(), _inner); } PinnedWidget::~PinnedWidget() = default; diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 6313d88d0b..729b6f24a2 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_drag_area.h" #include "history/history_item_helpers.h" // GetErrorForSending. +#include "history/history_view_swipe_back_session.h" #include "menu/menu_send.h" // SendMenu::Type. #include "ui/widgets/buttons.h" #include "ui/widgets/tooltip.h" @@ -245,6 +246,7 @@ ScheduledWidget::ScheduledWidget( _inner->setEmptyInfoWidget(std::move(emptyInfo)); } setupComposeControls(); + Window::SetupSwipeBackSection(this, _scroll, _inner); } ScheduledWidget::~ScheduledWidget() = default; diff --git a/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp b/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp index 283e3747a5..793133bbd0 100644 --- a/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_list_widget.h" #include "history/history.h" #include "history/history_item.h" +#include "history/history_view_swipe_back_session.h" #include "lang/lang_keys.h" #include "ui/chat/chat_style.h" #include "ui/widgets/buttons.h" @@ -146,6 +147,7 @@ SublistWidget::SublistWidget( setupShortcuts(); setupTranslateBar(); + Window::SetupSwipeBackSection(this, _scroll.get(), _inner); } SublistWidget::~SublistWidget() = default;