2022-11-23 11:49:45 +02:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
2022-08-19 15:59:36 +02:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2021-05-04 22:35:50 +03:00
|
|
|
|
2022-11-23 11:49:45 +02:00
|
|
|
import QtQuick
|
|
|
|
|
import HelperWidgets as HelperWidgets
|
|
|
|
|
import StudioControls as StudioControls
|
|
|
|
|
import StudioTheme as StudioTheme
|
2021-05-04 22:35:50 +03:00
|
|
|
|
|
|
|
|
Item {
|
2022-03-03 12:40:40 +02:00
|
|
|
id: root
|
2021-11-05 00:45:34 +02:00
|
|
|
|
2022-03-15 13:02:15 +02:00
|
|
|
// Array of supported externally dropped files that are imported as-is
|
|
|
|
|
property var dropSimpleExtFiles: []
|
|
|
|
|
|
|
|
|
|
// Array of supported externally dropped files that trigger custom import process
|
|
|
|
|
property var dropComplexExtFiles: []
|
2021-06-15 17:24:24 +03:00
|
|
|
|
2022-11-23 11:49:45 +02:00
|
|
|
readonly property int qtVersionAtLeast6_4: rootView.qtVersionIsAtLeast6_4()
|
2022-11-23 15:47:34 +02:00
|
|
|
property bool __searchBoxEmpty: true
|
2022-11-23 11:49:45 +02:00
|
|
|
|
2022-10-07 19:49:52 +03:00
|
|
|
AssetsContextMenu {
|
|
|
|
|
id: contextMenu
|
2022-11-23 11:49:45 +02:00
|
|
|
assetsView: assetsView
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
2022-02-03 19:49:27 +02:00
|
|
|
function clearSearchFilter()
|
|
|
|
|
{
|
2022-05-23 20:32:43 +03:00
|
|
|
searchBox.clear();
|
2022-02-03 19:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
2022-03-03 12:40:40 +02:00
|
|
|
function updateDropExtFiles(drag)
|
|
|
|
|
{
|
2022-03-15 13:02:15 +02:00
|
|
|
root.dropSimpleExtFiles = []
|
|
|
|
|
root.dropComplexExtFiles = []
|
|
|
|
|
var simpleSuffixes = rootView.supportedAssetSuffixes(false);
|
|
|
|
|
var complexSuffixes = rootView.supportedAssetSuffixes(true);
|
2022-03-03 12:40:40 +02:00
|
|
|
for (const u of drag.urls) {
|
|
|
|
|
var url = u.toString();
|
2022-03-15 13:02:15 +02:00
|
|
|
var ext = '*.' + url.slice(url.lastIndexOf('.') + 1).toLowerCase()
|
|
|
|
|
if (simpleSuffixes.includes(ext))
|
|
|
|
|
root.dropSimpleExtFiles.push(url)
|
|
|
|
|
else if (complexSuffixes.includes(ext))
|
|
|
|
|
root.dropComplexExtFiles.push(url)
|
2022-03-03 12:40:40 +02:00
|
|
|
}
|
2021-05-04 22:35:50 +03:00
|
|
|
|
2022-03-15 13:02:15 +02:00
|
|
|
drag.accepted = root.dropSimpleExtFiles.length > 0 || root.dropComplexExtFiles.length > 0
|
2022-03-03 12:40:40 +02:00
|
|
|
}
|
2021-05-04 22:35:50 +03:00
|
|
|
|
2022-03-03 12:40:40 +02:00
|
|
|
DropArea { // handles external drop on empty area of the view (goes to root folder)
|
|
|
|
|
id: dropArea
|
|
|
|
|
y: assetsView.y + assetsView.contentHeight + 5
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: parent.height - y
|
2021-05-04 22:35:50 +03:00
|
|
|
|
2021-06-17 18:22:11 +03:00
|
|
|
onEntered: (drag)=> {
|
2022-03-03 12:40:40 +02:00
|
|
|
root.updateDropExtFiles(drag)
|
2021-05-04 22:35:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDropped: {
|
2022-03-15 13:02:15 +02:00
|
|
|
rootView.handleExtFilesDrop(root.dropSimpleExtFiles, root.dropComplexExtFiles,
|
2022-11-23 11:49:45 +02:00
|
|
|
assetsModel.rootPath())
|
2022-03-03 12:40:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Canvas { // marker for the drop area
|
|
|
|
|
id: dropCanvas
|
|
|
|
|
anchors.fill: parent
|
2022-03-15 13:02:15 +02:00
|
|
|
visible: dropArea.containsDrag && root.dropSimpleExtFiles.length > 0
|
2022-03-03 12:40:40 +02:00
|
|
|
|
|
|
|
|
onWidthChanged: dropCanvas.requestPaint()
|
|
|
|
|
onHeightChanged: dropCanvas.requestPaint()
|
|
|
|
|
|
|
|
|
|
onPaint: {
|
|
|
|
|
var ctx = getContext("2d")
|
|
|
|
|
ctx.reset()
|
|
|
|
|
ctx.strokeStyle = StudioTheme.Values.themeInteraction
|
|
|
|
|
ctx.lineWidth = 2
|
|
|
|
|
ctx.setLineDash([4, 4])
|
|
|
|
|
ctx.rect(5, 5, dropCanvas.width - 10, dropCanvas.height - 10)
|
|
|
|
|
ctx.stroke()
|
|
|
|
|
}
|
2021-05-04 22:35:50 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 16:12:23 +02:00
|
|
|
MouseArea { // right clicking the empty area of the view
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
acceptedButtons: Qt.RightButton
|
|
|
|
|
onClicked: {
|
2022-11-23 11:49:45 +02:00
|
|
|
if (assetsModel.haveFiles) {
|
|
|
|
|
function onFolderCreated(path) {
|
|
|
|
|
assetsView.addCreatedFolder(path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var rootIndex = assetsModel.rootIndex()
|
|
|
|
|
var dirPath = assetsModel.filePath(rootIndex)
|
|
|
|
|
var dirName = assetsModel.fileName(rootIndex)
|
|
|
|
|
contextMenu.openContextMenuForRoot(rootIndex, dirPath, dirName, onFolderCreated)
|
2022-01-28 16:12:23 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 20:14:14 +03:00
|
|
|
// called from C++ to close context menu on focus out
|
2021-06-23 17:39:08 +03:00
|
|
|
function handleViewFocusOut()
|
2021-06-08 20:14:14 +03:00
|
|
|
{
|
|
|
|
|
contextMenu.close()
|
2022-11-23 11:49:45 +02:00
|
|
|
assetsView.selectedAssets = {}
|
|
|
|
|
assetsView.selectedAssetsChanged()
|
2022-01-31 19:50:38 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-03 19:49:27 +02:00
|
|
|
Column {
|
2021-05-04 22:35:50 +03:00
|
|
|
anchors.fill: parent
|
2022-02-03 19:49:27 +02:00
|
|
|
anchors.topMargin: 5
|
|
|
|
|
spacing: 5
|
2021-07-02 15:10:40 +03:00
|
|
|
|
2022-02-03 19:49:27 +02:00
|
|
|
Row {
|
2022-02-28 15:24:33 +02:00
|
|
|
id: searchRow
|
|
|
|
|
|
2022-02-03 19:49:27 +02:00
|
|
|
width: parent.width
|
2022-01-28 16:12:23 +02:00
|
|
|
|
2022-09-26 15:59:22 +03:00
|
|
|
StudioControls.SearchBox {
|
2022-02-03 19:49:27 +02:00
|
|
|
id: searchBox
|
2022-01-28 16:12:23 +02:00
|
|
|
|
2022-02-03 19:49:27 +02:00
|
|
|
width: parent.width - addAssetButton.width - 5
|
2022-09-26 15:21:33 +03:00
|
|
|
|
2022-11-23 11:49:45 +02:00
|
|
|
onSearchChanged: (searchText) => {
|
|
|
|
|
updateSearchFilterTimer.restart()
|
|
|
|
|
}
|
2022-02-03 19:49:27 +02:00
|
|
|
}
|
2022-01-31 19:50:38 +02:00
|
|
|
|
2022-11-23 11:49:45 +02:00
|
|
|
Timer {
|
|
|
|
|
id: updateSearchFilterTimer
|
|
|
|
|
interval: 200
|
|
|
|
|
repeat: false
|
|
|
|
|
|
|
|
|
|
onTriggered: {
|
|
|
|
|
assetsView.resetVerticalScrollPosition()
|
|
|
|
|
rootView.handleSearchFilterChanged(searchBox.text)
|
|
|
|
|
assetsView.expandAll()
|
|
|
|
|
|
2022-11-23 15:47:34 +02:00
|
|
|
if (root.__searchBoxEmpty && searchBox.text)
|
|
|
|
|
root.__searchBoxEmpty = false
|
|
|
|
|
else if (!root.__searchBoxEmpty && !searchBox.text)
|
|
|
|
|
root.__searchBoxEmpty = true
|
2022-11-23 11:49:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HelperWidgets.IconButton {
|
2022-02-03 19:49:27 +02:00
|
|
|
id: addAssetButton
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
tooltip: qsTr("Add a new asset to the project.")
|
2022-03-18 17:28:28 +02:00
|
|
|
icon: StudioTheme.Constants.plus
|
|
|
|
|
buttonSize: parent.height
|
2022-01-28 16:12:23 +02:00
|
|
|
|
2022-02-03 19:49:27 +02:00
|
|
|
onClicked: rootView.handleAddAsset()
|
2021-06-08 20:14:14 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-03 19:49:27 +02:00
|
|
|
Text {
|
|
|
|
|
text: qsTr("No match found.")
|
|
|
|
|
leftPadding: 10
|
|
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
|
font.pixelSize: 12
|
2022-11-23 15:47:34 +02:00
|
|
|
visible: !assetsModel.haveFiles && !root.__searchBoxEmpty
|
2022-02-03 19:49:27 +02:00
|
|
|
}
|
2021-05-04 22:35:50 +03:00
|
|
|
|
2022-02-28 15:24:33 +02:00
|
|
|
Item { // placeholder when the assets library is empty
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: parent.height - searchRow.height
|
2022-11-23 15:47:34 +02:00
|
|
|
visible: !assetsModel.haveFiles && root.__searchBoxEmpty
|
2022-02-28 15:24:33 +02:00
|
|
|
clip: true
|
|
|
|
|
|
2023-01-10 11:51:20 +02:00
|
|
|
MouseArea { // right clicking the empty area of the view
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
acceptedButtons: Qt.RightButton
|
|
|
|
|
onClicked: {
|
|
|
|
|
contextMenu.openContextMenuForEmpty(assetsModel.rootPath())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 15:29:27 +02:00
|
|
|
DropArea { // handles external drop (goes into default folder based on suffix)
|
|
|
|
|
anchors.fill: parent
|
2022-02-28 15:24:33 +02:00
|
|
|
|
2022-03-15 15:29:27 +02:00
|
|
|
onEntered: (drag)=> {
|
|
|
|
|
root.updateDropExtFiles(drag)
|
|
|
|
|
}
|
2022-02-28 15:24:33 +02:00
|
|
|
|
2022-03-15 15:29:27 +02:00
|
|
|
onDropped: {
|
2022-11-23 11:49:45 +02:00
|
|
|
rootView.emitExtFilesDrop(root.dropSimpleExtFiles, root.dropComplexExtFiles)
|
2022-02-28 15:24:33 +02:00
|
|
|
}
|
|
|
|
|
|
2022-03-15 15:29:27 +02:00
|
|
|
Column {
|
|
|
|
|
id: colNoAssets
|
|
|
|
|
|
|
|
|
|
spacing: 20
|
|
|
|
|
x: 20
|
|
|
|
|
width: root.width - 2 * x
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
|
|
|
|
Text {
|
|
|
|
|
text: qsTr("Looks like you don't have any assets yet.")
|
|
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
|
font.pixelSize: 18
|
|
|
|
|
width: colNoAssets.width
|
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
wrapMode: Text.WordWrap
|
2022-02-28 15:24:33 +02:00
|
|
|
}
|
|
|
|
|
|
2022-03-15 15:29:27 +02:00
|
|
|
Image {
|
|
|
|
|
source: "image://qmldesigner_assets/browse"
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
scale: maBrowse.containsMouse ? 1.2 : 1
|
|
|
|
|
Behavior on scale {
|
|
|
|
|
NumberAnimation {
|
|
|
|
|
duration: 300
|
|
|
|
|
easing.type: Easing.OutQuad
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
id: maBrowse
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
hoverEnabled: true
|
|
|
|
|
onClicked: rootView.handleAddAsset();
|
|
|
|
|
}
|
2022-02-28 15:24:33 +02:00
|
|
|
}
|
|
|
|
|
|
2022-03-15 15:29:27 +02:00
|
|
|
Text {
|
|
|
|
|
text: qsTr("Drag-and-drop your assets here or click the '+' button to browse assets from the file system.")
|
|
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
|
font.pixelSize: 18
|
|
|
|
|
width: colNoAssets.width
|
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
|
}
|
2022-02-28 15:24:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-07 19:49:52 +03:00
|
|
|
AssetsView {
|
2022-02-03 19:49:27 +02:00
|
|
|
id: assetsView
|
2022-11-23 11:49:45 +02:00
|
|
|
assetsRoot: root
|
|
|
|
|
contextMenu: contextMenu
|
|
|
|
|
|
2022-02-03 19:49:27 +02:00
|
|
|
width: parent.width
|
|
|
|
|
height: parent.height - y
|
2021-05-04 22:35:50 +03:00
|
|
|
}
|
2022-11-23 11:49:45 +02:00
|
|
|
} // Column
|
2021-05-04 22:35:50 +03:00
|
|
|
}
|