Added support of drag events to back button in dialogs list.

This commit is contained in:
23rd 2022-12-06 12:56:36 +03:00
parent 1b364f2621
commit 6bd2be0aee
2 changed files with 44 additions and 0 deletions

View File

@ -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<rpl::lifetime>();
_back->setAcceptDrops(true);
_back->events(
) | rpl::filter([=](not_null<QEvent*> e) {
return e->type() == QEvent::DragEnter;
}) | rpl::start_with_next([=](not_null<QEvent*> e) {
using namespace Storage;
const auto d = static_cast<QDragEnterEvent*>(e.get());
const auto data = d->mimeData();
if (ComputeMimeDataState(data) == MimeDataState::None) {
return;
}
const auto timer = _backLifetime.make_state<base::Timer>([=] {
backClicked();
});
timer->callOnce(ChoosePeerByDragTimeout);
d->setDropAction(Qt::CopyAction);
d->accept();
_back->events(
) | rpl::filter([=](not_null<QEvent*> e) {
return e->type() == QEvent::DragMove
|| e->type() == QEvent::DragLeave;
}) | rpl::start_with_next([=](not_null<QEvent*> 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<PeerData*> user) const {
const auto peer = _activeChat.key.peer();
if (!peer || _activeChat.key.topic() || !user->isUser()) {

View File

@ -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