From 0036c5de6691d50968e24c8be6cb198f04cd32be Mon Sep 17 00:00:00 2001 From: manongjohn Date: Nov 19 2019 04:24:43 +0000 Subject: Force drop file MoveAction to CopyAction --- diff --git a/toonz/sources/toonz/colormodelviewer.cpp b/toonz/sources/toonz/colormodelviewer.cpp index 730f77e..ae7a075 100644 --- a/toonz/sources/toonz/colormodelviewer.cpp +++ b/toonz/sources/toonz/colormodelviewer.cpp @@ -123,7 +123,10 @@ void ColorModelViewer::dragEnterEvent(QDragEnterEvent *event) { std::string type = fp.getType(); if (type == "scr" || type == "tpl") return; } - event->acceptProposedAction(); + // Force CopyAction + event->setDropAction(Qt::CopyAction); + // For files, don't accept original proposed action in case it's a move + event->accept(); } //----------------------------------------------------------------------------- @@ -138,7 +141,10 @@ void ColorModelViewer::dropEvent(QDropEvent *event) { loadImage(fp); setLevel(fp); } - event->acceptProposedAction(); + // Force CopyAction + event->setDropAction(Qt::CopyAction); + // For files, don't accept original proposed action in case it's a move + event->accept(); } } diff --git a/toonz/sources/toonz/dvitemview.cpp b/toonz/sources/toonz/dvitemview.cpp index debe1d7..e5c7240 100644 --- a/toonz/sources/toonz/dvitemview.cpp +++ b/toonz/sources/toonz/dvitemview.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include // for uint64_t @@ -1515,15 +1516,29 @@ void DvItemViewer::resetVerticalScrollBar() { //----------------------------------------------------------------------------- void DvItemViewer::dragEnterEvent(QDragEnterEvent *event) { - if (m_model && m_model->acceptDrop(event->mimeData())) - event->acceptProposedAction(); + const QMimeData *mimeData = event->mimeData(); + if (m_model && m_model->acceptDrop(mimeData)) { + if (acceptResourceOrFolderDrop(mimeData->urls())) { + // Force CopyAction + event->setDropAction(Qt::CopyAction); + event->accept(); + } else + event->acceptProposedAction(); + } } //----------------------------------------------------------------------------- void DvItemViewer::dropEvent(QDropEvent *event) { - if (m_model && m_model->drop(event->mimeData())) - event->acceptProposedAction(); + const QMimeData *mimeData = event->mimeData(); + if (m_model && m_model->drop(mimeData)) { + if (acceptResourceOrFolderDrop(mimeData->urls())) { + // Force CopyAction + event->setDropAction(Qt::CopyAction); + event->accept(); + } else + event->acceptProposedAction(); + } } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/flipbook.cpp b/toonz/sources/toonz/flipbook.cpp index 4bc2e62..98c2836 100644 --- a/toonz/sources/toonz/flipbook.cpp +++ b/toonz/sources/toonz/flipbook.cpp @@ -1760,7 +1760,8 @@ void ImageViewer::showHistogram() { void FlipBook::dragEnterEvent(QDragEnterEvent *e) { const QMimeData *mimeData = e->mimeData(); - if (!acceptResourceDrop(mimeData->urls()) && + bool isResourceDrop = acceptResourceDrop(mimeData->urls()); + if (!isResourceDrop && !mimeData->hasFormat("application/vnd.toonz.drawings") && !mimeData->hasFormat(CastItems::getMimeFormat())) return; @@ -1784,18 +1785,31 @@ void FlipBook::dragEnterEvent(QDragEnterEvent *e) { } } - e->acceptProposedAction(); + if (isResourceDrop) { + // Force CopyAction + e->setDropAction(Qt::CopyAction); + // For files, don't accept original proposed action in case it's a move + e->accept(); + } else + e->acceptProposedAction(); } //----------------------------------------------------------------------------- void FlipBook::dropEvent(QDropEvent *e) { const QMimeData *mimeData = e->mimeData(); + bool isResourceDrop = acceptResourceDrop(mimeData->urls()); if (mimeData->hasUrls()) { for (const QUrl &url : mimeData->urls()) { TFilePath fp(url.toLocalFile().toStdWString()); if (TFileType::getInfo(fp) != TFileType::UNKNOW_FILE) setLevel(fp); - e->acceptProposedAction(); + if (isResourceDrop) { + // Force CopyAction + e->setDropAction(Qt::CopyAction); + // For files, don't accept original proposed action in case it's a move + e->accept(); + } else + e->acceptProposedAction(); return; } } else if (mimeData->hasFormat( diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp index a0f6809..f9cd82a 100644 --- a/toonz/sources/toonz/sceneviewerevents.cpp +++ b/toonz/sources/toonz/sceneviewerevents.cpp @@ -1578,6 +1578,14 @@ void SceneViewer::dropEvent(QDropEvent *e) { } IoCmd::loadResources(args); + + if (acceptResourceOrFolderDrop(mimeData->urls())) { + // Force Copy Action + e->setDropAction(Qt::CopyAction); + // For files, don't accept original proposed action in case it's a move + e->accept(); + return; + } } e->acceptProposedAction(); } diff --git a/toonz/sources/toonz/xshcellviewer.cpp b/toonz/sources/toonz/xshcellviewer.cpp index eb0ed3e..f1a0269 100644 --- a/toonz/sources/toonz/xshcellviewer.cpp +++ b/toonz/sources/toonz/xshcellviewer.cpp @@ -3090,12 +3090,17 @@ void CellArea::contextMenuEvent(QContextMenuEvent *event) { //----------------------------------------------------------------------------- void CellArea::dragEnterEvent(QDragEnterEvent *e) { - if (acceptResourceOrFolderDrop(e->mimeData()->urls()) || + bool isResourceOrFolderDrop = + acceptResourceOrFolderDrop(e->mimeData()->urls()); + if (isResourceOrFolderDrop || e->mimeData()->hasFormat(CastItems::getMimeFormat()) || e->mimeData()->hasFormat("application/vnd.toonz.drawings")) { setDragTool(XsheetGUI::DragTool::makeDragAndDropDataTool(m_viewer)); + // For file dragging force CopyAction + if (isResourceOrFolderDrop) e->setDropAction(Qt::CopyAction); m_viewer->dragToolClick(e); - e->acceptProposedAction(); + // For files, don't accept original proposed action in case it's a move + isResourceOrFolderDrop ? e->accept() : e->acceptProposedAction(); } } @@ -3110,8 +3115,13 @@ void CellArea::dragLeaveEvent(QDragLeaveEvent *e) { void CellArea::dragMoveEvent(QDragMoveEvent *e) { if (!getDragTool()) return; + bool isResourceOrFolderDrop = + acceptResourceOrFolderDrop(e->mimeData()->urls()); + // For file dragging force CopyAction + if (isResourceOrFolderDrop) e->setDropAction(Qt::CopyAction); m_viewer->dragToolDrag(e); - e->acceptProposedAction(); + // For files, don't accept original proposed action in case it's a move + isResourceOrFolderDrop ? e->accept() : e->acceptProposedAction(); } //----------------------------------------------------------------------------- @@ -3122,8 +3132,13 @@ void CellArea::dropEvent(QDropEvent *e) { if (e->source() == this) { e->setDropAction(Qt::MoveAction); e->accept(); + } else if (acceptResourceOrFolderDrop(e->mimeData()->urls())) { + // For file dragging force CopyAction + e->setDropAction(Qt::CopyAction); + // For files, don't accept original proposed action in case it's a move + e->accept(); } else - e->acceptProposedAction(); + e->acceptProposedAction(); } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonzqt/paletteviewer.cpp b/toonz/sources/toonzqt/paletteviewer.cpp index 70ea76a..c0b03f6 100644 --- a/toonz/sources/toonzqt/paletteviewer.cpp +++ b/toonz/sources/toonzqt/paletteviewer.cpp @@ -703,7 +703,10 @@ void PaletteViewer::dragEnterEvent(QDragEnterEvent *event) { if (!path.getType().empty() && path.getType() != "tpl") return; } - event->acceptProposedAction(); + // Force CopyAction + event->setDropAction(Qt::CopyAction); + // For files, don't accept original proposed action in case it's a move + event->accept(); } //----------------------------------------------------------------------------- @@ -754,7 +757,10 @@ void PaletteViewer::dropEvent(QDropEvent *event) { } } } - event->acceptProposedAction(); + // Force CopyAction + event->setDropAction(Qt::CopyAction); + // For files, don't accept original proposed action in case it's a move + event->accept(); return; }