diff --git a/share/qtcreator/qmldesigner/itemLibraryQmlSources/AssetDelegate.qml b/share/qtcreator/qmldesigner/itemLibraryQmlSources/AssetDelegate.qml index a28becff06b..7bfec10aa32 100644 --- a/share/qtcreator/qmldesigner/itemLibraryQmlSources/AssetDelegate.qml +++ b/share/qtcreator/qmldesigner/itemLibraryQmlSources/AssetDelegate.qml @@ -12,7 +12,7 @@ TreeViewDelegate { required property Item assetsRoot property bool hasChildWithDropHover: false - property bool isHoveringDrop: false + property bool isHighlighted: false readonly property string suffix: model.fileName.substr(-4) readonly property bool isFont: root.suffix === ".ttf" || root.suffix === ".otf" readonly property bool isEffect: root.suffix === ".qep" @@ -74,7 +74,7 @@ TreeViewDelegate { id: bg color: { - if (root.__isDirectory && (root.isHoveringDrop || root.hasChildWithDropHover)) + if (root.__isDirectory && (root.isHighlighted || root.hasChildWithDropHover)) return StudioTheme.Values.themeInteraction 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 { id: mouseArea @@ -247,6 +213,14 @@ TreeViewDelegate { } } // MouseArea + function getDirPath() + { + if (root.__isDirectory) + return model.filePath + else + return assetsModel.parentDirPath(model.filePath) + } + function __openContextMenuForCurrentRow() { let modelIndex = assetsModel.indexForPath(model.filePath) diff --git a/share/qtcreator/qmldesigner/itemLibraryQmlSources/AssetsView.qml b/share/qtcreator/qmldesigner/itemLibraryQmlSources/AssetsView.qml index 782cca5ebc6..dcffab432be 100644 --- a/share/qtcreator/qmldesigner/itemLibraryQmlSources/AssetsView.qml +++ b/share/qtcreator/qmldesigner/itemLibraryQmlSources/AssetsView.qml @@ -250,8 +250,12 @@ TreeView { function startDropHoverOver(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 + } let parentItem = root.__getDelegateParentForIndex(index) if (parentItem) @@ -261,8 +265,12 @@ TreeView { function endDropHover(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 + } let parentItem = root.__getDelegateParentForIndex(index) if (parentItem) @@ -292,6 +300,12 @@ TreeView { return root.itemAtCell(parentCell) } + function __getDelegateItemForIndex(index) + { + let cell = root.cellAtIndex(index) + return root.itemAtCell(cell) + } + function __modelIndex(row) { // 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) } + 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 { assetsView: root assetsRoot: root.assetsRoot