2024-03-21 12:47:09 +02:00
|
|
|
// Copyright (C) 2024 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
|
|
|
|
import QtQuick
|
2024-04-09 17:50:11 +03:00
|
|
|
import Qt.labs.qmlmodels
|
2024-03-21 12:47:09 +02:00
|
|
|
import HelperWidgets as HelperWidgets
|
|
|
|
import StudioControls as StudioControls
|
|
|
|
import StudioTheme as StudioTheme
|
|
|
|
import ContentLibraryBackend
|
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
Item {
|
2024-03-21 12:47:09 +02:00
|
|
|
id: root
|
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
property alias adsFocus: scrollView.adsFocus
|
2024-03-21 12:47:09 +02:00
|
|
|
|
|
|
|
property real cellWidth: 100
|
|
|
|
property real cellHeight: 120
|
|
|
|
property int numColumns: 4
|
|
|
|
|
|
|
|
property int count: 0
|
|
|
|
function assignMaxCount() {
|
|
|
|
let c = 0
|
|
|
|
for (let i = 0; i < categoryRepeater.count; ++i)
|
|
|
|
c = Math.max(c, categoryRepeater.itemAt(i)?.count ?? 0)
|
|
|
|
|
|
|
|
root.count = c
|
|
|
|
}
|
|
|
|
|
|
|
|
required property var searchBox
|
|
|
|
|
|
|
|
signal unimport(var bundleItem);
|
2024-04-25 11:59:01 +03:00
|
|
|
signal removeFromContentLib(var bundleItem);
|
2024-03-21 12:47:09 +02:00
|
|
|
|
|
|
|
function closeContextMenu() {
|
2024-05-11 00:04:11 +03:00
|
|
|
ctxMenuItem.close()
|
2024-04-23 15:17:41 +03:00
|
|
|
ctxMenuTexture.close()
|
2024-03-21 12:47:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function expandVisibleSections() {
|
|
|
|
for (let i = 0; i < categoryRepeater.count; ++i) {
|
|
|
|
let cat = categoryRepeater.itemAt(i)
|
|
|
|
if (cat.visible && !cat.expanded)
|
|
|
|
cat.expandSection()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
ContentLibraryItemContextMenu {
|
|
|
|
id: ctxMenuItem
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
showRemoveAction: true
|
|
|
|
showImportAction: true
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
onApplyToSelected: (add) => ContentLibraryBackend.userModel.applyToSelected(ctxMenuItem.targetItem, add)
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
onUnimport: root.unimport(ctxMenuItem.targetItem)
|
|
|
|
onAddToProject: ContentLibraryBackend.userModel.addToProject(ctxMenuItem.targetItem)
|
|
|
|
onRemoveFromContentLib: root.removeFromContentLib(ctxMenuItem.targetItem)
|
|
|
|
onImportBundle: ContentLibraryBackend.rootView.importBundle();
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentLibraryTextureContextMenu {
|
|
|
|
id: ctxMenuTexture
|
|
|
|
|
|
|
|
showRemoveAction: true
|
|
|
|
hasSceneEnv: ContentLibraryBackend.texturesModel.hasSceneEnv
|
|
|
|
}
|
2024-04-23 15:17:41 +03:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
MouseArea {
|
|
|
|
id: rootMouseArea
|
2024-04-23 15:17:41 +03:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
anchors.fill: parent
|
|
|
|
acceptedButtons: Qt.RightButton
|
2024-08-05 16:12:52 +03:00
|
|
|
enabled: ContentLibraryBackend.rootView.isQt6Project
|
|
|
|
&& ContentLibraryBackend.rootView.hasQuick3DImport
|
|
|
|
&& ContentLibraryBackend.rootView.hasMaterialLibrary
|
2024-06-26 20:56:05 +03:00
|
|
|
|
|
|
|
onClicked: (mouse) => {
|
|
|
|
ctxMenuItem.popupMenu()
|
2024-03-21 12:47:09 +02:00
|
|
|
}
|
2024-06-26 20:56:05 +03:00
|
|
|
}
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
HelperWidgets.ScrollView {
|
|
|
|
id: scrollView
|
|
|
|
anchors.fill: parent
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
clip: true
|
|
|
|
interactive: !ctxMenuItem.opened && !ctxMenuTexture.opened
|
|
|
|
&& !ContentLibraryBackend.rootView.isDragging && !HelperWidgets.Controller.contextMenuOpened
|
|
|
|
hideHorizontalScrollBar: true
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
Column {
|
|
|
|
Repeater {
|
|
|
|
id: categoryRepeater
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
model: ContentLibraryBackend.userModel
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
delegate: HelperWidgets.Section {
|
|
|
|
id: section
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
width: root.width
|
|
|
|
leftPadding: StudioTheme.Values.sectionPadding
|
|
|
|
rightPadding: StudioTheme.Values.sectionPadding
|
|
|
|
topPadding: StudioTheme.Values.sectionPadding
|
|
|
|
bottomPadding: StudioTheme.Values.sectionPadding
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
caption: categoryTitle
|
2025-01-01 22:38:16 +02:00
|
|
|
dropEnabled: true
|
2024-06-26 20:56:05 +03:00
|
|
|
category: "ContentLib_User"
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
function expandSection() {
|
|
|
|
section.expanded = true
|
|
|
|
}
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
property alias count: repeater.count
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
onCountChanged: root.assignMaxCount()
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2025-01-01 22:38:16 +02:00
|
|
|
onDropEnter: (drag) => {
|
2025-01-16 15:57:11 +02:00
|
|
|
let has3DNode = ContentLibraryBackend.rootView
|
|
|
|
.has3DNode(drag.getDataAsArrayBuffer(drag.formats[0]))
|
2025-01-07 13:22:39 +02:00
|
|
|
|
2025-01-16 15:57:11 +02:00
|
|
|
let hasTexture = ContentLibraryBackend.rootView
|
|
|
|
.hasTexture(drag.formats[0], drag.urls)
|
|
|
|
|
|
|
|
drag.accepted = (categoryTitle === "Textures" && hasTexture)
|
2025-01-02 12:55:05 +02:00
|
|
|
|| (categoryTitle === "Materials" && drag.formats[0] === "application/vnd.qtdesignstudio.material")
|
2025-01-16 15:57:11 +02:00
|
|
|
|| (categoryTitle === "3D" && has3DNode)
|
2025-01-01 22:38:16 +02:00
|
|
|
|
|
|
|
section.highlight = drag.accepted
|
|
|
|
}
|
|
|
|
|
|
|
|
onDropExit: {
|
|
|
|
section.highlight = false
|
|
|
|
}
|
|
|
|
|
|
|
|
onDrop: (drag) => {
|
|
|
|
section.highlight = false
|
|
|
|
drag.accept()
|
|
|
|
section.expandSection()
|
2025-01-02 12:55:05 +02:00
|
|
|
|
2025-01-16 15:57:11 +02:00
|
|
|
if (categoryTitle === "Textures") {
|
|
|
|
if (drag.formats[0] === "application/vnd.qtdesignstudio.assets")
|
|
|
|
ContentLibraryBackend.rootView.acceptTexturesDrop(drag.urls)
|
|
|
|
else if (drag.formats[0] === "application/vnd.qtdesignstudio.texture")
|
|
|
|
ContentLibraryBackend.rootView.acceptTextureDrop(drag.getDataAsString(drag.formats[0]))
|
|
|
|
} else if (categoryTitle === "Materials") {
|
2025-01-02 12:55:05 +02:00
|
|
|
ContentLibraryBackend.rootView.acceptMaterialDrop(drag.getDataAsString(drag.formats[0]))
|
2025-01-16 15:57:11 +02:00
|
|
|
} else if (categoryTitle === "3D") {
|
2025-01-07 13:22:39 +02:00
|
|
|
ContentLibraryBackend.rootView.accept3DDrop(drag.getDataAsArrayBuffer(drag.formats[0]))
|
2025-01-16 15:57:11 +02:00
|
|
|
}
|
2025-01-01 22:38:16 +02:00
|
|
|
}
|
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
Grid {
|
|
|
|
width: section.width - section.leftPadding - section.rightPadding
|
|
|
|
spacing: StudioTheme.Values.sectionGridSpacing
|
|
|
|
columns: root.numColumns
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
Repeater {
|
|
|
|
id: repeater
|
|
|
|
model: categoryItems
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
delegate: DelegateChooser {
|
|
|
|
role: "bundleId"
|
|
|
|
|
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "UserMaterials"
|
|
|
|
ContentLibraryItem {
|
|
|
|
width: root.cellWidth
|
|
|
|
height: root.cellHeight
|
2025-01-13 11:43:28 +02:00
|
|
|
visible: modelData.bundleItemVisible && !infoText.visible
|
2024-04-09 17:50:11 +03:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
onShowContextMenu: ctxMenuItem.popupMenu(modelData)
|
|
|
|
onAddToProject: ContentLibraryBackend.userModel.addToProject(modelData)
|
|
|
|
}
|
2024-04-09 17:50:11 +03:00
|
|
|
}
|
2024-06-26 20:56:05 +03:00
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "UserTextures"
|
|
|
|
delegate: ContentLibraryTexture {
|
|
|
|
width: root.cellWidth
|
|
|
|
height: root.cellWidth // for textures use a square size since there is no name row
|
|
|
|
|
|
|
|
onShowContextMenu: ctxMenuTexture.popupMenu(modelData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "User3D"
|
|
|
|
delegate: ContentLibraryItem {
|
|
|
|
width: root.cellWidth
|
|
|
|
height: root.cellHeight
|
2025-01-13 11:43:28 +02:00
|
|
|
visible: modelData.bundleItemVisible && !infoText.visible
|
2024-06-26 20:56:05 +03:00
|
|
|
|
|
|
|
onShowContextMenu: ctxMenuItem.popupMenu(modelData)
|
|
|
|
onAddToProject: ContentLibraryBackend.userModel.addToProject(modelData)
|
|
|
|
}
|
2024-04-26 16:41:29 +03:00
|
|
|
}
|
|
|
|
}
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
onCountChanged: root.assignMaxCount()
|
|
|
|
}
|
2024-03-21 12:47:09 +02:00
|
|
|
}
|
|
|
|
|
2024-06-26 20:56:05 +03:00
|
|
|
Text {
|
|
|
|
text: qsTr("No match found.");
|
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
font.pixelSize: StudioTheme.Values.baseFontSize
|
|
|
|
leftPadding: 10
|
|
|
|
visible: infoText.text === "" && !searchBox.isEmpty() && categoryNoMatch
|
|
|
|
}
|
2024-03-21 12:47:09 +02:00
|
|
|
|
2024-12-27 00:13:22 +02:00
|
|
|
Text {
|
|
|
|
id: infoText
|
|
|
|
|
|
|
|
text: {
|
|
|
|
let categoryName = (categoryTitle === "3D") ? categoryTitle + " assets"
|
|
|
|
: categoryTitle.toLowerCase()
|
2025-03-06 13:35:33 +02:00
|
|
|
if (!ContentLibraryBackend.rootView.isQt6Project) {
|
2024-12-27 00:13:22 +02:00
|
|
|
qsTr("<b>Content Library</b> is not supported in Qt5 projects.")
|
2025-03-06 13:35:33 +02:00
|
|
|
} else if (!ContentLibraryBackend.rootView.hasQuick3DImport && categoryTitle !== "Textures") {
|
|
|
|
qsTr('To use %1, add the <b>QtQuick3D</b> module and the <b>View3D</b>
|
|
|
|
component in the <b>Components</b> view, or click
|
|
|
|
<a href=\"#add_import\"><span style=\"text-decoration:none;color:%2\">
|
|
|
|
here</span></a>.')
|
|
|
|
.arg(categoryName)
|
|
|
|
.arg(StudioTheme.Values.themeInteraction)
|
|
|
|
} else if (!ContentLibraryBackend.rootView.hasMaterialLibrary && categoryTitle !== "Textures") {
|
2024-12-27 00:13:22 +02:00
|
|
|
qsTr("<b>Content Library</b> is disabled inside a non-visual component.")
|
2025-03-06 13:35:33 +02:00
|
|
|
} else if (categoryEmpty) {
|
2024-12-27 00:13:22 +02:00
|
|
|
qsTr("There are no "+ categoryName + " in the <b>User Assets</b>.")
|
2025-03-06 13:35:33 +02:00
|
|
|
} else {
|
2024-12-27 00:13:22 +02:00
|
|
|
""
|
2025-03-06 13:35:33 +02:00
|
|
|
}
|
2024-12-27 00:13:22 +02:00
|
|
|
}
|
2025-01-29 16:44:48 +02:00
|
|
|
textFormat: Text.RichText
|
2024-12-27 00:13:22 +02:00
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
font.pixelSize: StudioTheme.Values.baseFontSize
|
|
|
|
topPadding: 10
|
|
|
|
leftPadding: 10
|
2025-03-06 13:35:33 +02:00
|
|
|
rightPadding: 10
|
2024-12-27 00:13:22 +02:00
|
|
|
visible: infoText.text !== ""
|
2025-03-06 13:35:33 +02:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
width: root.width
|
2025-01-29 16:44:48 +02:00
|
|
|
|
|
|
|
onLinkActivated: ContentLibraryBackend.rootView.addQtQuick3D()
|
2024-12-27 00:13:22 +02:00
|
|
|
}
|
2024-06-26 20:56:05 +03:00
|
|
|
}
|
2024-03-21 12:47:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|