From 42a22862304be04d0b19bd811ef16aa4eaa71ce6 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 10 Jun 2020 14:46:27 +0300 Subject: [PATCH] Added implementation of drag'n'drop in section of scheduled messages. --- .../SourceFiles/history/history_drag_area.cpp | 40 ++++++++++--------- .../view/history_view_scheduled_section.cpp | 27 +++++++++++++ .../view/history_view_scheduled_section.h | 2 + 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/history/history_drag_area.cpp b/Telegram/SourceFiles/history/history_drag_area.cpp index b7e4be0bb7..d8d27c62f1 100644 --- a/Telegram/SourceFiles/history/history_drag_area.cpp +++ b/Telegram/SourceFiles/history/history_drag_area.cpp @@ -49,7 +49,8 @@ DragArea::Areas DragArea::SetupDragAreaToContainer( auto &lifetime = container->lifetime(); container->setAcceptDrops(true); - const auto attachDragDocument = Ui::CreateChild(container.get()); + const auto attachDragDocument = + Ui::CreateChild(container.get()); const auto attachDragPhoto = Ui::CreateChild(container.get()); attachDragDocument->hide(); @@ -183,34 +184,37 @@ DragArea::Areas DragArea::SetupDragAreaToContainer( e->acceptProposedAction(); }; + const auto processDragEvents = [=](not_null event) { + switch (event->type()) { + case QEvent::DragEnter: + dragEnterEvent(static_cast(event.get())); + return true; + case QEvent::DragLeave: + dragLeaveEvent(static_cast(event.get())); + return true; + case QEvent::Drop: + dropEvent(static_cast(event.get())); + return true; + }; + return false; + }; + container->events( ) | rpl::filter([=](not_null event) { return ranges::contains(kDragAreaEvents, event->type()); }) | rpl::start_with_next([=](not_null event) { const auto type = event->type(); - if (type == QEvent::DragEnter) { - dragEnterEvent(static_cast(event.get())); - } else if (type == QEvent::DragLeave) { - dragLeaveEvent(static_cast(event.get())); - } else if (type == QEvent::Drop) { - dropEvent(static_cast(event.get())); - } else if (type == QEvent::Leave) { - resetDragStateIfNeeded(); - } else if (type == QEvent::MouseButtonRelease) { + if (processDragEvents(event)) { + return; + } else if (type == QEvent::Leave + || type == QEvent::MouseButtonRelease) { resetDragStateIfNeeded(); } }, lifetime); const auto eventFilter = [=](not_null event) { - const auto type = event->type(); - if (type == QEvent::DragEnter) { - dragEnterEvent(static_cast(event.get())); - } else if (type == QEvent::DragLeave) { - dragLeaveEvent(static_cast(event.get())); - } else if (type == QEvent::Drop) { - dropEvent(static_cast(event.get())); - } + processDragEvents(event); return base::EventFilterResult::Continue; }; base::install_event_filter(attachDragDocument, eventFilter); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index ea53f2fea4..2ed3917946 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -12,8 +12,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_list_widget.h" #include "history/view/history_view_schedule_box.h" #include "history/history.h" +#include "history/history_drag_area.h" #include "history/history_item.h" #include "chat_helpers/message_field.h" // SendMenuType. +#include "ui/delayed_activation.h" #include "ui/widgets/scroll_area.h" #include "ui/widgets/shadow.h" #include "ui/layers/generic_box.h" @@ -34,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/call_delayed.h" #include "core/file_utilities.h" #include "main/main_session.h" +#include "mainwindow.h" #include "data/data_session.h" #include "data/data_user.h" #include "data/data_scheduled_messages.h" @@ -1010,6 +1013,11 @@ void ScheduledWidget::showAnimatedHook( void ScheduledWidget::showFinishedHook() { _topBar->setAnimatingMode(false); _composeControls->showFinished(); + + // We should setup the drag area only after + // the section animation is finished, + // because after that the method showChildren() is called. + setupDragArea(); } bool ScheduledWidget::floatPlayerHandleWheelEvent(QEvent *e) { @@ -1172,4 +1180,23 @@ void ScheduledWidget::clearSelected() { _inner->cancelSelection(); } +void ScheduledWidget::setupDragArea() { + const auto areas = DragArea::SetupDragAreaToContainer( + this, + [=] { return !_history; }, + nullptr, + [=] { updateControlsGeometry(); }); + + const auto droppedCallback = [=](CompressConfirm compressed) { + return [=](const QMimeData *data) { + confirmSendingFiles(data, compressed); + const auto window = controller()->widget(); + window->activateWindow(); + Ui::ActivateWindowDelayed(window); + }; + }; + areas.document->setDroppedCallback(droppedCallback(CompressConfirm::No)); + areas.photo->setDroppedCallback(droppedCallback(CompressConfirm::Yes)); +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h index 385d5b7ac1..57353c9c88 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h @@ -129,6 +129,8 @@ private: void setupComposeControls(); + void setupDragArea(); + void setupScrollDownButton(); void scrollDownClicked(); void scrollDownAnimationFinish();