Fix glitch in AssetsView when dragging files onto it

Moved the DropArea from the AssetDelegate into the AssetsView, so that
moving the cursor through the delegates no longer denies and then
permits dragging. This glitch happened because the DropArea was inside
the delegate, while the TreeView also has rowSpacing, which are areas
that do not belong to the delegates, and for which you don't normally
have drag & drop support.

Task-number: QDS-8232
Change-Id: If49a384f25bb870105448156f436e048479e880c
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Samuel Ghinet
2022-12-01 22:05:55 +02:00
parent 6ae064619f
commit 7e5ecfe8bc
2 changed files with 96 additions and 38 deletions

View File

@@ -12,7 +12,7 @@ TreeViewDelegate {
required property Item assetsRoot required property Item assetsRoot
property bool hasChildWithDropHover: false property bool hasChildWithDropHover: false
property bool isHoveringDrop: false property bool isHighlighted: false
readonly property string suffix: model.fileName.substr(-4) readonly property string suffix: model.fileName.substr(-4)
readonly property bool isFont: root.suffix === ".ttf" || root.suffix === ".otf" readonly property bool isFont: root.suffix === ".ttf" || root.suffix === ".otf"
readonly property bool isEffect: root.suffix === ".qep" readonly property bool isEffect: root.suffix === ".qep"
@@ -74,7 +74,7 @@ TreeViewDelegate {
id: bg id: bg
color: { color: {
if (root.__isDirectory && (root.isHoveringDrop || root.hasChildWithDropHover)) if (root.__isDirectory && (root.isHighlighted || root.hasChildWithDropHover))
return StudioTheme.Values.themeInteraction return StudioTheme.Values.themeInteraction
if (!root.__isDirectory && root.assetsView.selectedAssets[root.__itemPath]) if (!root.__isDirectory && root.assetsView.selectedAssets[root.__itemPath])
@@ -120,40 +120,6 @@ TreeViewDelegate {
} }
} }
DropArea {
id: treeDropArea
enabled: true
anchors.fill: parent
onEntered: (drag) => {
root.assetsRoot.updateDropExtFiles(drag)
root.isHoveringDrop = drag.accepted && root.assetsRoot.dropSimpleExtFiles.length > 0
if (root.isHoveringDrop)
root.assetsView.startDropHoverOver(root.__currentRow)
}
onDropped: (drag) => {
root.isHoveringDrop = false
root.assetsView.endDropHover(root.__currentRow)
let dirPath = root.__isDirectory
? model.filePath
: assetsModel.parentDirPath(model.filePath);
rootView.emitExtFilesDrop(root.assetsRoot.dropSimpleExtFiles,
root.assetsRoot.dropComplexExtFiles,
dirPath)
}
onExited: {
if (root.isHoveringDrop) {
root.isHoveringDrop = false
root.assetsView.endDropHover(root.__currentRow)
}
}
}
MouseArea { MouseArea {
id: mouseArea id: mouseArea
@@ -247,6 +213,14 @@ TreeViewDelegate {
} }
} // MouseArea } // MouseArea
function getDirPath()
{
if (root.__isDirectory)
return model.filePath
else
return assetsModel.parentDirPath(model.filePath)
}
function __openContextMenuForCurrentRow() function __openContextMenuForCurrentRow()
{ {
let modelIndex = assetsModel.indexForPath(model.filePath) let modelIndex = assetsModel.indexForPath(model.filePath)

View File

@@ -250,8 +250,12 @@ TreeView {
function startDropHoverOver(row) function startDropHoverOver(row)
{ {
let index = root.__modelIndex(row) let index = root.__modelIndex(row)
if (assetsModel.isDirectory(index)) if (assetsModel.isDirectory(index)) {
let item = root.__getDelegateItemForIndex(index)
if (item)
item.isHighlighted = true
return return
}
let parentItem = root.__getDelegateParentForIndex(index) let parentItem = root.__getDelegateParentForIndex(index)
if (parentItem) if (parentItem)
@@ -261,8 +265,12 @@ TreeView {
function endDropHover(row) function endDropHover(row)
{ {
let index = root.__modelIndex(row) let index = root.__modelIndex(row)
if (assetsModel.isDirectory(index)) if (assetsModel.isDirectory(index)) {
let item = root.__getDelegateItemForIndex(index)
if (item)
item.isHighlighted = false
return return
}
let parentItem = root.__getDelegateParentForIndex(index) let parentItem = root.__getDelegateParentForIndex(index)
if (parentItem) if (parentItem)
@@ -292,6 +300,12 @@ TreeView {
return root.itemAtCell(parentCell) return root.itemAtCell(parentCell)
} }
function __getDelegateItemForIndex(index)
{
let cell = root.cellAtIndex(index)
return root.itemAtCell(cell)
}
function __modelIndex(row) function __modelIndex(row)
{ {
// The modelIndex() function exists since 6.3. In Qt 6.3, this modelIndex() function was a // The modelIndex() function exists since 6.3. In Qt 6.3, this modelIndex() function was a
@@ -303,6 +317,76 @@ TreeView {
return root.modelIndex(row, 0) return root.modelIndex(row, 0)
} }
DropArea {
id: dropArea
enabled: true
anchors.fill: parent
property bool __isHoveringDrop: false
property int __rowHoveringOver: -1
function __rowAndItem(drag)
{
let pos = dropArea.mapToItem(root, drag.x, drag.y)
let cell = root.cellAtPos(pos.x, pos.y, true)
let item = root.itemAtCell(cell)
return [cell.y, item]
}
onEntered: (drag) => {
root.assetsRoot.updateDropExtFiles(drag)
let [row, item] = dropArea.__rowAndItem(drag)
dropArea.__isHoveringDrop = drag.accepted && root.assetsRoot.dropSimpleExtFiles.length > 0
if (item && dropArea.__isHoveringDrop)
root.startDropHoverOver(row)
dropArea.__rowHoveringOver = row
}
onDropped: (drag) => {
let [row, item] = dropArea.__rowAndItem(drag)
if (item) {
root.endDropHover(row)
let dirPath = item.getDirPath()
rootView.emitExtFilesDrop(root.assetsRoot.dropSimpleExtFiles,
root.assetsRoot.dropComplexExtFiles,
dirPath)
}
dropArea.__isHoveringDrop = false
dropArea.__rowHoveringOver = -1
}
onPositionChanged: (drag) => {
let [row, item] = dropArea.__rowAndItem(drag)
if (dropArea.__rowHoveringOver !== row && dropArea.__rowHoveringOver > -1) {
root.endDropHover(dropArea.__rowHoveringOver)
if (item)
root.startDropHoverOver(row)
}
dropArea.__rowHoveringOver = row
}
onExited: {
if (!dropArea.__isHoveringDrop || dropArea.__rowHoveringOver === -1)
return
root.endDropHover(dropArea.__rowHoveringOver)
dropArea.__isHoveringDrop = false
dropArea.__rowHoveringOver = -1
}
}
delegate: AssetDelegate { delegate: AssetDelegate {
assetsView: root assetsView: root
assetsRoot: root.assetsRoot assetsRoot: root.assetsRoot