mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added implementation of drag'n'drop in section of scheduled messages.
This commit is contained in:
parent
24d02d5461
commit
42a2286230
3 changed files with 51 additions and 18 deletions
|
@ -49,7 +49,8 @@ DragArea::Areas DragArea::SetupDragAreaToContainer(
|
||||||
auto &lifetime = container->lifetime();
|
auto &lifetime = container->lifetime();
|
||||||
container->setAcceptDrops(true);
|
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());
|
const auto attachDragPhoto = Ui::CreateChild<DragArea>(container.get());
|
||||||
|
|
||||||
attachDragDocument->hide();
|
attachDragDocument->hide();
|
||||||
|
@ -183,34 +184,37 @@ DragArea::Areas DragArea::SetupDragAreaToContainer(
|
||||||
e->acceptProposedAction();
|
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(
|
container->events(
|
||||||
) | rpl::filter([=](not_null<QEvent*> event) {
|
) | rpl::filter([=](not_null<QEvent*> event) {
|
||||||
return ranges::contains(kDragAreaEvents, event->type());
|
return ranges::contains(kDragAreaEvents, event->type());
|
||||||
}) | rpl::start_with_next([=](not_null<QEvent*> event) {
|
}) | rpl::start_with_next([=](not_null<QEvent*> event) {
|
||||||
const auto type = event->type();
|
const auto type = event->type();
|
||||||
|
|
||||||
if (type == QEvent::DragEnter) {
|
if (processDragEvents(event)) {
|
||||||
dragEnterEvent(static_cast<QDragEnterEvent*>(event.get()));
|
return;
|
||||||
} else if (type == QEvent::DragLeave) {
|
} else if (type == QEvent::Leave
|
||||||
dragLeaveEvent(static_cast<QDragLeaveEvent*>(event.get()));
|
|| type == QEvent::MouseButtonRelease) {
|
||||||
} else if (type == QEvent::Drop) {
|
|
||||||
dropEvent(static_cast<QDropEvent*>(event.get()));
|
|
||||||
} else if (type == QEvent::Leave) {
|
|
||||||
resetDragStateIfNeeded();
|
|
||||||
} else if (type == QEvent::MouseButtonRelease) {
|
|
||||||
resetDragStateIfNeeded();
|
resetDragStateIfNeeded();
|
||||||
}
|
}
|
||||||
}, lifetime);
|
}, lifetime);
|
||||||
|
|
||||||
const auto eventFilter = [=](not_null<QEvent*> event) {
|
const auto eventFilter = [=](not_null<QEvent*> event) {
|
||||||
const auto type = event->type();
|
processDragEvents(event);
|
||||||
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()));
|
|
||||||
}
|
|
||||||
return base::EventFilterResult::Continue;
|
return base::EventFilterResult::Continue;
|
||||||
};
|
};
|
||||||
base::install_event_filter(attachDragDocument, eventFilter);
|
base::install_event_filter(attachDragDocument, eventFilter);
|
||||||
|
|
|
@ -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_list_widget.h"
|
||||||
#include "history/view/history_view_schedule_box.h"
|
#include "history/view/history_view_schedule_box.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
|
#include "history/history_drag_area.h"
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "chat_helpers/message_field.h" // SendMenuType.
|
#include "chat_helpers/message_field.h" // SendMenuType.
|
||||||
|
#include "ui/delayed_activation.h"
|
||||||
#include "ui/widgets/scroll_area.h"
|
#include "ui/widgets/scroll_area.h"
|
||||||
#include "ui/widgets/shadow.h"
|
#include "ui/widgets/shadow.h"
|
||||||
#include "ui/layers/generic_box.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 "base/call_delayed.h"
|
||||||
#include "core/file_utilities.h"
|
#include "core/file_utilities.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "data/data_scheduled_messages.h"
|
#include "data/data_scheduled_messages.h"
|
||||||
|
@ -1010,6 +1013,11 @@ void ScheduledWidget::showAnimatedHook(
|
||||||
void ScheduledWidget::showFinishedHook() {
|
void ScheduledWidget::showFinishedHook() {
|
||||||
_topBar->setAnimatingMode(false);
|
_topBar->setAnimatingMode(false);
|
||||||
_composeControls->showFinished();
|
_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) {
|
bool ScheduledWidget::floatPlayerHandleWheelEvent(QEvent *e) {
|
||||||
|
@ -1172,4 +1180,23 @@ void ScheduledWidget::clearSelected() {
|
||||||
_inner->cancelSelection();
|
_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
|
} // namespace HistoryView
|
||||||
|
|
|
@ -129,6 +129,8 @@ private:
|
||||||
|
|
||||||
void setupComposeControls();
|
void setupComposeControls();
|
||||||
|
|
||||||
|
void setupDragArea();
|
||||||
|
|
||||||
void setupScrollDownButton();
|
void setupScrollDownButton();
|
||||||
void scrollDownClicked();
|
void scrollDownClicked();
|
||||||
void scrollDownAnimationFinish();
|
void scrollDownAnimationFinish();
|
||||||
|
|
Loading…
Add table
Reference in a new issue