From ffd8fd3bfb5147ba1c237a4372e93868ed0c1ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 6 Nov 2022 11:48:27 +0100 Subject: [PATCH] Fix Drag&Drop in the comics grid view --- YACReaderLibrary/qml/GridComicsView.qml | 80 ++++++++++++------------ YACReaderLibrary/qml/GridComicsView6.qml | 80 ++++++++++++------------ 2 files changed, 80 insertions(+), 80 deletions(-) diff --git a/YACReaderLibrary/qml/GridComicsView.qml b/YACReaderLibrary/qml/GridComicsView.qml index eb8915b6..1786fca0 100644 --- a/YACReaderLibrary/qml/GridComicsView.qml +++ b/YACReaderLibrary/qml/GridComicsView.qml @@ -413,46 +413,6 @@ SplitView { grid.contentX = grid.originX } - DropArea { - anchors.fill: parent - - onEntered: { - if(drag.hasUrls) - { - if(dropManager.canDropUrls(drag.urls, drag.action)) - { - drag.accepted = true; - }else - drag.accepted = false; - } - else if (dropManager.canDropFormats(drag.formats)) { - drag.accepted = true; - } else - drag.accepted = false; - } - - onDropped: { - if(drop.hasUrls && dropManager.canDropUrls(drop.urls, drop.action)) - { - dropManager.droppedFiles(drop.urls, drop.action); - } - else{ - if (dropManager.canDropFormats(drop.formats)) - { - var destItem = grid.itemAt(drop.x,drop.y + grid.contentY); - var destLocalX = grid.mapToItem(destItem,drop.x,drop.y + grid.contentY).x - var realIndex = grid.indexAt(drop.x,drop.y + grid.contentY); - - if(realIndex === -1) - realIndex = grid.count - 1; - - var destIndex = destLocalX < (grid.cellWidth / 2) ? realIndex : realIndex + 1; - dropManager.droppedComicsForResortingAt(drop.getDataAsString(), destIndex); - } - } - } - } - property Component currentComicView: Component { id: currentComicView Rectangle { @@ -809,6 +769,46 @@ SplitView { currentIndexHelper.setCurrentIndex(ci); grid.currentIndex = ci; } + + DropArea { + anchors.fill: parent + + onEntered: drag => { + if(drag.hasUrls) + { + if(dropManager.canDropUrls(drag.urls, drag.action)) + { + drag.accepted = true; + }else + drag.accepted = false; + } + else if (dropManager.canDropFormats(drag.formats)) { + drag.accepted = true; + } else + drag.accepted = false; + } + + onDropped: drop => { + if(drop.hasUrls && dropManager.canDropUrls(drop.urls, drop.action)) + { + dropManager.droppedFiles(drop.urls, drop.action); + } + else{ + if (dropManager.canDropFormats(drop.formats)) + { + var destItem = grid.itemAt(drop.x,drop.y + grid.contentY); + var destLocalX = grid.mapToItem(destItem,drop.x,drop.y + grid.contentY).x + var realIndex = grid.indexAt(drop.x,drop.y + grid.contentY); + + if(realIndex === -1) + realIndex = grid.count - 1; + + var destIndex = destLocalX < (grid.cellWidth / 2) ? realIndex : realIndex + 1; + dropManager.droppedComicsForResortingAt("", destIndex); + } + } + } + } } } } diff --git a/YACReaderLibrary/qml/GridComicsView6.qml b/YACReaderLibrary/qml/GridComicsView6.qml index f50e3652..10294fc0 100644 --- a/YACReaderLibrary/qml/GridComicsView6.qml +++ b/YACReaderLibrary/qml/GridComicsView6.qml @@ -416,46 +416,6 @@ SplitView { grid.contentX = grid.originX } - DropArea { - anchors.fill: parent - - onEntered: { - if(drag.hasUrls) - { - if(dropManager.canDropUrls(drag.urls, drag.action)) - { - drag.accepted = true; - }else - drag.accepted = false; - } - else if (dropManager.canDropFormats(drag.formats)) { - drag.accepted = true; - } else - drag.accepted = false; - } - - onDropped: { - if(drop.hasUrls && dropManager.canDropUrls(drop.urls, drop.action)) - { - dropManager.droppedFiles(drop.urls, drop.action); - } - else{ - if (dropManager.canDropFormats(drop.formats)) - { - var destItem = grid.itemAt(drop.x,drop.y + grid.contentY); - var destLocalX = grid.mapToItem(destItem,drop.x,drop.y + grid.contentY).x - var realIndex = grid.indexAt(drop.x,drop.y + grid.contentY); - - if(realIndex === -1) - realIndex = grid.count - 1; - - var destIndex = destLocalX < (grid.cellWidth / 2) ? realIndex : realIndex + 1; - dropManager.droppedComicsForResortingAt(drop.getDataAsString(), destIndex); - } - } - } - } - property Component currentComicView: Component { id: currentComicView Rectangle { @@ -816,6 +776,46 @@ SplitView { currentIndexHelper.setCurrentIndex(ci); grid.currentIndex = ci; } + + DropArea { + anchors.fill: parent + + onEntered: drag => { + if(drag.hasUrls) + { + if(dropManager.canDropUrls(drag.urls, drag.action)) + { + drag.accepted = true; + }else + drag.accepted = false; + } + else if (dropManager.canDropFormats(drag.formats)) { + drag.accepted = true; + } else + drag.accepted = false; + } + + onDropped: drop => { + if(drop.hasUrls && dropManager.canDropUrls(drop.urls, drop.action)) + { + dropManager.droppedFiles(drop.urls, drop.action); + } + else{ + if (dropManager.canDropFormats(drop.formats)) + { + var destItem = grid.itemAt(drop.x,drop.y + grid.contentY); + var destLocalX = grid.mapToItem(destItem,drop.x,drop.y + grid.contentY).x + var realIndex = grid.indexAt(drop.x,drop.y + grid.contentY); + + if(realIndex === -1) + realIndex = grid.count - 1; + + var destIndex = destLocalX < (grid.cellWidth / 2) ? realIndex : realIndex + 1; + dropManager.droppedComicsForResortingAt("", destIndex); + } + } + } + } } } }