Added implementation of drag'n'drop in section of scheduled messages.

This commit is contained in:
23rd 2020-06-10 14:46:27 +03:00
parent 24d02d5461
commit 42a2286230
3 changed files with 51 additions and 18 deletions

View File

@ -49,7 +49,8 @@ DragArea::Areas DragArea::SetupDragAreaToContainer(
auto &lifetime = container->lifetime();
container->setAcceptDrops(true);
const auto attachDragDocument = Ui::CreateChild<DragArea>(container.get());
const auto attachDragDocument =
Ui::CreateChild<DragArea>(container.get());
const auto attachDragPhoto = Ui::CreateChild<DragArea>(container.get());
attachDragDocument->hide();
@ -183,34 +184,37 @@ DragArea::Areas DragArea::SetupDragAreaToContainer(
e->acceptProposedAction();
};
const auto processDragEvents = [=](not_null<QEvent*> event) {
switch (event->type()) {
case QEvent::DragEnter:
dragEnterEvent(static_cast<QDragEnterEvent*>(event.get()));
return true;
case QEvent::DragLeave:
dragLeaveEvent(static_cast<QDragLeaveEvent*>(event.get()));
return true;
case QEvent::Drop:
dropEvent(static_cast<QDropEvent*>(event.get()));
return true;
};
return false;
};
container->events(
) | rpl::filter([=](not_null<QEvent*> event) {
return ranges::contains(kDragAreaEvents, event->type());
}) | rpl::start_with_next([=](not_null<QEvent*> event) {
const auto type = event->type();
if (type == QEvent::DragEnter) {
dragEnterEvent(static_cast<QDragEnterEvent*>(event.get()));
} else if (type == QEvent::DragLeave) {
dragLeaveEvent(static_cast<QDragLeaveEvent*>(event.get()));
} else if (type == QEvent::Drop) {
dropEvent(static_cast<QDropEvent*>(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<QEvent*> event) {
const auto type = event->type();
if (type == QEvent::DragEnter) {
dragEnterEvent(static_cast<QDragEnterEvent*>(event.get()));
} else if (type == QEvent::DragLeave) {
dragLeaveEvent(static_cast<QDragLeaveEvent*>(event.get()));
} else if (type == QEvent::Drop) {
dropEvent(static_cast<QDropEvent*>(event.get()));
}
processDragEvents(event);
return base::EventFilterResult::Continue;
};
base::install_event_filter(attachDragDocument, eventFilter);

View File

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

View File

@ -129,6 +129,8 @@ private:
void setupComposeControls();
void setupDragArea();
void setupScrollDownButton();
void scrollDownClicked();
void scrollDownAnimationFinish();