From 6bd2be0aeeb9fafe950f9e3793c731fae7a035ad Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 6 Dec 2022 12:56:36 +0300 Subject: [PATCH] Added support of drag events to back button in dialogs list. --- .../view/history_view_top_bar_widget.cpp | 41 +++++++++++++++++++ .../view/history_view_top_bar_widget.h | 3 ++ 2 files changed, 44 insertions(+) diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 7a5374f616..061962850f 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_memento.h" #include "info/info_controller.h" #include "info/profile/info_profile_values.h" +#include "storage/storage_media_prepare.h" #include "storage/storage_shared_media.h" #include "mainwidget.h" #include "mainwindow.h" @@ -782,6 +783,7 @@ void TopBarWidget::setActiveChat( updateOnlineDisplay(); updateControlsVisibility(); refreshUnreadBadge(); + setupDragOnBackButton(); } void TopBarWidget::handleEmojiInteractionSeen(const QString &emoticon) { @@ -1444,6 +1446,45 @@ void TopBarWidget::updateInfoToggleActive() { _infoToggle->setRippleColorOverride(rippleOverride); } +void TopBarWidget::setupDragOnBackButton() { + _backLifetime.destroy(); + if (_activeChat.section != Section::ChatsList) { + _back->setAcceptDrops(false); + return; + } + const auto lifetime = _backLifetime.make_state(); + _back->setAcceptDrops(true); + _back->events( + ) | rpl::filter([=](not_null e) { + return e->type() == QEvent::DragEnter; + }) | rpl::start_with_next([=](not_null e) { + using namespace Storage; + const auto d = static_cast(e.get()); + const auto data = d->mimeData(); + if (ComputeMimeDataState(data) == MimeDataState::None) { + return; + } + const auto timer = _backLifetime.make_state([=] { + backClicked(); + }); + timer->callOnce(ChoosePeerByDragTimeout); + d->setDropAction(Qt::CopyAction); + d->accept(); + _back->events( + ) | rpl::filter([=](not_null e) { + return e->type() == QEvent::DragMove + || e->type() == QEvent::DragLeave; + }) | rpl::start_with_next([=](not_null e) { + if (e->type() == QEvent::DragMove) { + timer->callOnce(ChoosePeerByDragTimeout); + } else if (e->type() == QEvent::DragLeave) { + timer->cancel(); + lifetime->destroy(); + } + }, *lifetime); + }, _backLifetime); +} + bool TopBarWidget::trackOnlineOf(not_null user) const { const auto peer = _activeChat.key.peer(); if (!peer || _activeChat.key.topic() || !user->isUser()) { diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h index 614d7ade0b..6d7316f6a0 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h @@ -134,6 +134,7 @@ private: void updateControlsGeometry(); void slideAnimationCallback(); void updateInfoToggleActive(); + void setupDragOnBackButton(); void call(); void groupCall(); @@ -252,6 +253,8 @@ private: rpl::event_stream<> _clearSelection; rpl::event_stream<> _cancelChooseForReport; + rpl::lifetime _backLifetime; + }; } // namespace HistoryView