mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
fix: reordering crashes
This commit is contained in:
parent
5a015888d4
commit
3a9899529a
1 changed files with 52 additions and 64 deletions
|
@ -2038,9 +2038,7 @@ void SendFilesBox::moveFile(int from, int to) {
|
||||||
|
|
||||||
if (from == to) return;
|
if (from == to) return;
|
||||||
|
|
||||||
std::swap(_list.files[from], _list.files[to]);
|
refreshAllAfterChanges(std::min(from, to), [=] { std::swap(_list.files[from], _list.files[to]); });
|
||||||
|
|
||||||
refreshAllAfterChanges(std::min(from, to));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendFilesBox::setupDragForBlock(not_null<Ui::RpWidget*> w, int index) {
|
void SendFilesBox::setupDragForBlock(not_null<Ui::RpWidget*> w, int index) {
|
||||||
|
@ -2049,74 +2047,64 @@ void SendFilesBox::setupDragForBlock(not_null<Ui::RpWidget*> w, int index) {
|
||||||
const auto pressed = w->lifetime().make_state<rpl::variable<bool>>(false);
|
const auto pressed = w->lifetime().make_state<rpl::variable<bool>>(false);
|
||||||
const auto pressPos = w->lifetime().make_state<rpl::variable<QPoint>>();
|
const auto pressPos = w->lifetime().make_state<rpl::variable<QPoint>>();
|
||||||
|
|
||||||
base::install_event_filter(
|
w->events(
|
||||||
w,
|
) | rpl::start_with_next(
|
||||||
[=](not_null<QEvent*> e)
|
[=](not_null<QEvent *> e)
|
||||||
{
|
{
|
||||||
switch (e->type()) {
|
switch (e->type()) {
|
||||||
case QEvent::MouseButtonPress: {
|
case QEvent::MouseButtonPress: {
|
||||||
const auto ev = static_cast<QMouseEvent*>(e.get());
|
const auto ev = static_cast<QMouseEvent *>(e.get());
|
||||||
if (ev->button() == Qt::LeftButton) {
|
if (ev->button() == Qt::LeftButton) {
|
||||||
pressed->force_assign(true);
|
pressed->force_assign(true);
|
||||||
pressPos->force_assign(ev->pos());
|
pressPos->force_assign(ev->pos());
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QEvent::MouseMove: {
|
|
||||||
if (pressed->current()) {
|
|
||||||
const auto ev = static_cast<QMouseEvent*>(e.get());
|
|
||||||
if ((ev->pos() - pressPos->current()).manhattanLength()
|
|
||||||
>= QApplication::startDragDistance()) {
|
|
||||||
pressed->force_assign(false);
|
|
||||||
|
|
||||||
const auto drag = std::make_unique<QDrag>(w);
|
|
||||||
auto mime = std::make_unique<QMimeData>();
|
|
||||||
mime->setData(kDragMime, QByteArray::number(index));
|
|
||||||
drag->setMimeData(mime.release());
|
|
||||||
drag->setPixmap(w->grab());
|
|
||||||
drag->setHotSpot(ev->pos());
|
|
||||||
drag->exec(Qt::MoveAction);
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
case QEvent::MouseMove: {
|
||||||
}
|
if (pressed->current()) {
|
||||||
case QEvent::MouseButtonRelease: pressed->force_assign(false);
|
const auto ev = static_cast<QMouseEvent *>(e.get());
|
||||||
break;
|
if ((ev->pos() - pressPos->current()).manhattanLength() >=
|
||||||
|
QApplication::startDragDistance()) {
|
||||||
|
pressed->force_assign(false);
|
||||||
|
|
||||||
case QEvent::DragEnter:
|
const auto drag = new QDrag(w);
|
||||||
case QEvent::DragMove: {
|
auto mime = std::make_unique<QMimeData>();
|
||||||
const auto ev = static_cast<QDragMoveEvent*>(e.get());
|
mime->setData(kDragMime, QByteArray::number(index));
|
||||||
if (ev->mimeData()->hasFormat(kDragMime)) {
|
drag->setMimeData(mime.release());
|
||||||
const auto from = ev->mimeData()
|
drag->setPixmap(w->grab());
|
||||||
->data(kDragMime).toInt();
|
drag->setHotSpot(ev->pos());
|
||||||
if (isFileBlock(from) && isFileBlock(index)) {
|
drag->exec(Qt::MoveAction);
|
||||||
ev->acceptProposedAction();
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
case QEvent::MouseButtonRelease: pressed->force_assign(false); break;
|
||||||
}
|
|
||||||
case QEvent::Drop: {
|
|
||||||
const auto ev = static_cast<QDropEvent*>(e.get());
|
|
||||||
if (ev->mimeData()->hasFormat(kDragMime)) {
|
|
||||||
const auto from = ev->mimeData()
|
|
||||||
->data(kDragMime).toInt();
|
|
||||||
if (isFileBlock(from) && isFileBlock(index)) {
|
|
||||||
const auto dest = index;
|
|
||||||
QMetaObject::invokeMethod(
|
|
||||||
this,
|
|
||||||
[this, from, dest]
|
|
||||||
{
|
|
||||||
moveFile(from, dest);
|
|
||||||
},
|
|
||||||
Qt::QueuedConnection);
|
|
||||||
|
|
||||||
ev->acceptProposedAction();
|
case QEvent::DragEnter:
|
||||||
|
case QEvent::DragMove: {
|
||||||
|
const auto ev = static_cast<QDragMoveEvent *>(e.get());
|
||||||
|
if (ev->mimeData()->hasFormat(kDragMime)) {
|
||||||
|
const auto from = ev->mimeData()->data(kDragMime).toInt();
|
||||||
|
if (isFileBlock(from) && isFileBlock(index)) {
|
||||||
|
ev->acceptProposedAction();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
case QEvent::Drop: {
|
||||||
|
const auto ev = static_cast<QDropEvent *>(e.get());
|
||||||
|
if (ev->mimeData()->hasFormat(kDragMime)) {
|
||||||
|
const auto from = ev->mimeData()->data(kDragMime).toInt();
|
||||||
|
if (isFileBlock(from) && isFileBlock(index)) {
|
||||||
|
crl::on_main(this, [=] { moveFile(from, index); });
|
||||||
|
ev->acceptProposedAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
default: break;
|
return base::EventFilterResult::Continue;
|
||||||
}
|
},
|
||||||
return base::EventFilterResult::Continue;
|
w->lifetime());
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue