forked from qt-creator/qt-creator
QmlDesigner: Allow folders drag & drop in Asset Library
Fixes: QDS-13465 Change-Id: Ib9f30f18cf927417037dfa4c79b53534d2ad8e86 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -101,21 +101,9 @@ TreeViewDelegate {
|
||||
: "transparent"
|
||||
}
|
||||
border.width: StudioTheme.Values.border
|
||||
border.color: {
|
||||
if (root.__isDirectory && (root.isHighlighted || root.hasChildWithDropHover))
|
||||
return StudioTheme.Values.themeInteraction
|
||||
|
||||
if (!root.__isDirectory && root.assetsView.selectedAssets[root.__itemPath])
|
||||
return StudioTheme.Values.themeInteraction
|
||||
|
||||
if (mouseArea.containsMouse)
|
||||
return StudioTheme.Values.themeSectionHeadBackground
|
||||
|
||||
return root.__isDirectory
|
||||
? StudioTheme.Values.themeSectionHeadBackground
|
||||
border.color: root.assetsView.selectedAssets[root.__itemPath] ? StudioTheme.Values.themeInteraction
|
||||
: "transparent"
|
||||
}
|
||||
}
|
||||
|
||||
contentItem: Text {
|
||||
id: assetLabel
|
||||
@@ -158,14 +146,19 @@ TreeViewDelegate {
|
||||
mouseArea.allowTooltip = false
|
||||
AssetsLibraryBackend.tooltipBackend.hideTooltip()
|
||||
|
||||
if (root.__isDirectory)
|
||||
return
|
||||
|
||||
var ctrlDown = mouse.modifiers & Qt.ControlModifier
|
||||
|
||||
if (mouse.button === Qt.LeftButton) {
|
||||
if (root.__isDirectory) {
|
||||
// ensure only one directory can be selected
|
||||
root.assetsView.clearSelectedAssets()
|
||||
root.currFileSelected = true
|
||||
} else {
|
||||
if (!root.assetsView.isAssetSelected(root.__itemPath) && !ctrlDown)
|
||||
root.assetsView.clearSelectedAssets()
|
||||
root.currFileSelected = ctrlDown ? !root.assetsView.isAssetSelected(root.__itemPath) : true
|
||||
}
|
||||
|
||||
root.assetsView.setAssetSelected(root.__itemPath, root.currFileSelected)
|
||||
|
||||
if (root.currFileSelected) {
|
||||
@@ -356,8 +349,8 @@ TreeViewDelegate {
|
||||
|
||||
onEntered: (drag) => {
|
||||
root.assetsRoot.updateDropExtFiles(drag)
|
||||
|
||||
drag.accepted |= (drag.formats[0] === "application/vnd.qtdesignstudio.assets")
|
||||
drag.accepted |= drag.formats[0] === "application/vnd.qtdesignstudio.assets"
|
||||
&& !root.assetsModel.isSameOrDescendantPath(drag.urls[0], root.__itemPath)
|
||||
|
||||
if (root.__isDirectory)
|
||||
root.isHighlighted = drag.accepted
|
||||
|
@@ -83,9 +83,7 @@ TreeView {
|
||||
interval: 200
|
||||
repeat: false
|
||||
|
||||
onTriggered: {
|
||||
root.updateRows()
|
||||
}
|
||||
onTriggered: root.updateRows()
|
||||
}
|
||||
|
||||
Connections {
|
||||
|
@@ -22,5 +22,7 @@
|
||||
<file>images/asset_ktx.png</file>
|
||||
<file>images/asset_ktx@2x.png</file>
|
||||
<file>images/asset_ktx_128.png</file>
|
||||
<file>images/asset_folder.png</file>
|
||||
<file>images/asset_folder@2x.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@@ -110,6 +110,8 @@ QPair<QPixmap, qint64> AssetsLibraryIconProvider::fetchPixmap(const QString &id,
|
||||
type = "video";
|
||||
else if (asset.isEffect())
|
||||
type = QmlDesigner::ModelNodeOperations::getEffectIcon(id);
|
||||
else if (asset.isFolder())
|
||||
type = "folder";
|
||||
|
||||
QString pathTemplate = QString(":/AssetsLibrary/images/asset_%1%2.png").arg(type);
|
||||
QString path = pathTemplate.arg('_' + QString::number(requestedSize.width()));
|
||||
|
@@ -197,6 +197,14 @@ bool AssetsLibraryModel::allFilePathsAreComposedEffects(const QStringList &fileP
|
||||
});
|
||||
}
|
||||
|
||||
bool AssetsLibraryModel::isSameOrDescendantPath(const QUrl &source, const QString &target) const
|
||||
{
|
||||
Utils::FilePath srcPath = Utils::FilePath::fromUrl(source);
|
||||
Utils::FilePath targetPath = Utils::FilePath::fromString(target);
|
||||
|
||||
return targetPath.isChildOf(srcPath);
|
||||
}
|
||||
|
||||
bool AssetsLibraryModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||
{
|
||||
QString path = m_sourceFsModel->filePath(sourceParent);
|
||||
|
@@ -50,6 +50,7 @@ public:
|
||||
Q_INVOKABLE bool deleteFolderRecursively(const QModelIndex &folderIndex);
|
||||
Q_INVOKABLE bool allFilePathsAreTextures(const QStringList &filePaths) const;
|
||||
Q_INVOKABLE bool allFilePathsAreComposedEffects(const QStringList &filePaths) const;
|
||||
Q_INVOKABLE bool isSameOrDescendantPath(const QUrl &source, const QString &target) const;
|
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override
|
||||
{
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 180 B |
Binary file not shown.
After Width: | Height: | Size: 232 B |
@@ -207,10 +207,18 @@ bool Asset::isValidTextureSource()
|
||||
return isImage() || isTexture3D();
|
||||
}
|
||||
|
||||
bool Asset::isFolder() const
|
||||
{
|
||||
return m_type == Asset::Type::Folder;
|
||||
}
|
||||
|
||||
void Asset::resolveType()
|
||||
{
|
||||
if (m_suffix.isEmpty())
|
||||
if (m_suffix.isEmpty()) {
|
||||
m_type = Asset::Type::Folder;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (supportedImageSuffixes().contains(m_suffix))
|
||||
m_type = Asset::Type::Image;
|
||||
|
@@ -24,7 +24,8 @@ public:
|
||||
Audio,
|
||||
Video,
|
||||
Texture3D,
|
||||
Effect };
|
||||
Effect,
|
||||
Folder };
|
||||
|
||||
Asset(const QString &filePath);
|
||||
|
||||
@@ -60,6 +61,7 @@ public:
|
||||
bool isEffect() const;
|
||||
bool isSupported() const;
|
||||
bool isValidTextureSource();
|
||||
bool isFolder() const;
|
||||
|
||||
private:
|
||||
void resolveType();
|
||||
|
Reference in New Issue
Block a user