2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
2023-01-04 08:52:22 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2022-03-18 17:28:28 +02:00
|
|
|
|
2024-01-16 12:30:29 +01:00
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Layouts
|
|
|
|
|
import HelperWidgets
|
|
|
|
|
import StudioTheme as StudioTheme
|
2023-03-09 10:46:32 +01:00
|
|
|
import MaterialBrowserBackend
|
2022-03-18 17:28:28 +02:00
|
|
|
|
2023-10-10 15:25:50 +02:00
|
|
|
Item {
|
2022-03-18 17:28:28 +02:00
|
|
|
id: root
|
|
|
|
|
|
|
|
|
|
signal showContextMenu()
|
|
|
|
|
|
2023-10-10 15:25:50 +02:00
|
|
|
function refreshPreview() {
|
2022-03-18 17:28:28 +02:00
|
|
|
img.source = ""
|
|
|
|
|
img.source = "image://materialBrowser/" + materialInternalId
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-10 15:25:50 +02:00
|
|
|
function forceFinishEditing() {
|
2023-05-04 19:31:02 +03:00
|
|
|
matName.commitRename()
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-10 15:25:50 +02:00
|
|
|
function startRename() {
|
2023-06-27 14:15:00 +03:00
|
|
|
matName.startRename()
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-18 17:28:28 +02:00
|
|
|
visible: materialVisible
|
|
|
|
|
|
2022-12-13 16:29:25 +02:00
|
|
|
DropArea {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
|
|
onEntered: (drag) => {
|
|
|
|
|
drag.accepted = drag.formats[0] === "application/vnd.qtdesignstudio.texture"
|
2023-03-07 18:48:12 +02:00
|
|
|
|| drag.formats[0] === "application/vnd.qtdesignstudio.bundletexture"
|
2023-03-07 11:43:46 +02:00
|
|
|
|| (drag.formats[0] === "application/vnd.qtdesignstudio.assets"
|
|
|
|
|
&& rootView.hasAcceptableAssets(drag.urls))
|
2022-12-13 16:29:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDropped: (drag) => {
|
2023-02-17 15:22:55 +02:00
|
|
|
drag.accept()
|
2023-03-07 11:43:46 +02:00
|
|
|
|
|
|
|
|
if (drag.formats[0] === "application/vnd.qtdesignstudio.texture")
|
2023-03-09 10:46:32 +01:00
|
|
|
MaterialBrowserBackend.rootView.acceptTextureDropOnMaterial(index, drag.getDataAsString(drag.keys[0]))
|
2023-03-07 18:48:12 +02:00
|
|
|
else if (drag.formats[0] === "application/vnd.qtdesignstudio.bundletexture")
|
2023-03-09 10:46:32 +01:00
|
|
|
MaterialBrowserBackend.rootView.acceptBundleTextureDropOnMaterial(index, drag.urls[0])
|
2023-03-07 11:43:46 +02:00
|
|
|
else if (drag.formats[0] === "application/vnd.qtdesignstudio.assets")
|
2023-03-09 10:46:32 +01:00
|
|
|
MaterialBrowserBackend.rootView.acceptAssetsDropOnMaterial(index, drag.urls)
|
2022-12-13 16:29:25 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-18 17:28:28 +02:00
|
|
|
MouseArea {
|
|
|
|
|
id: mouseArea
|
|
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
|
|
2022-06-27 14:31:59 +03:00
|
|
|
onPressed: (mouse) => {
|
2023-03-09 10:46:32 +01:00
|
|
|
MaterialBrowserBackend.materialBrowserModel.selectMaterial(index)
|
|
|
|
|
MaterialBrowserBackend.rootView.focusMaterialSection(true)
|
2022-06-27 14:31:59 +03:00
|
|
|
|
|
|
|
|
if (mouse.button === Qt.LeftButton)
|
2023-03-09 10:46:32 +01:00
|
|
|
MaterialBrowserBackend.rootView.startDragMaterial(index, mapToGlobal(mouse.x, mouse.y))
|
2022-06-27 14:31:59 +03:00
|
|
|
else if (mouse.button === Qt.RightButton)
|
2022-03-18 17:28:28 +02:00
|
|
|
root.showContextMenu()
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-09 10:46:32 +01:00
|
|
|
onDoubleClicked: MaterialBrowserBackend.materialBrowserModel.openMaterialEditor();
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
spacing: 1
|
|
|
|
|
|
|
|
|
|
Image {
|
|
|
|
|
id: img
|
|
|
|
|
|
2023-10-10 15:25:50 +02:00
|
|
|
width: root.width
|
2022-03-18 17:28:28 +02:00
|
|
|
height: img.width
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
source: "image://materialBrowser/" + materialInternalId
|
|
|
|
|
cache: false
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 15:39:42 +02:00
|
|
|
// Eat keys so they are not passed to parent while editing name
|
2023-10-10 15:25:50 +02:00
|
|
|
Keys.onPressed: (event) => {
|
|
|
|
|
event.accepted = true
|
2023-02-20 15:39:42 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-04 19:31:02 +03:00
|
|
|
MaterialBrowserItemName {
|
2022-03-18 17:28:28 +02:00
|
|
|
id: matName
|
|
|
|
|
|
|
|
|
|
text: materialName
|
|
|
|
|
width: img.width
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
|
2023-05-04 19:31:02 +03:00
|
|
|
onRenamed: (newName) => {
|
|
|
|
|
MaterialBrowserBackend.materialBrowserModel.renameMaterial(index, newName);
|
|
|
|
|
mouseArea.forceActiveFocus()
|
2022-11-08 13:02:06 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-04 19:31:02 +03:00
|
|
|
onClicked: {
|
|
|
|
|
MaterialBrowserBackend.materialBrowserModel.selectMaterial(index)
|
|
|
|
|
MaterialBrowserBackend.rootView.focusMaterialSection(true)
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-10 15:25:50 +02:00
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: marker
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
border.width: MaterialBrowserBackend.materialBrowserModel.selectedIndex === index ? MaterialBrowserBackend.rootView.materialSectionFocused ? 3 : 1 : 0
|
|
|
|
|
border.color: MaterialBrowserBackend.materialBrowserModel.selectedIndex === index
|
|
|
|
|
? StudioTheme.Values.themeControlOutlineInteraction
|
|
|
|
|
: "transparent"
|
|
|
|
|
color: "transparent"
|
|
|
|
|
}
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|