2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2022-03-18 17:28:28 +02:00
|
|
|
|
|
|
|
|
import QtQuick 2.15
|
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
|
import QtQuickDesignerTheme 1.0
|
|
|
|
|
import HelperWidgets 2.0
|
|
|
|
|
import StudioTheme 1.0 as StudioTheme
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: root
|
|
|
|
|
|
|
|
|
|
signal showContextMenu()
|
|
|
|
|
|
|
|
|
|
function refreshPreview()
|
|
|
|
|
{
|
|
|
|
|
img.source = ""
|
|
|
|
|
img.source = "image://materialBrowser/" + materialInternalId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startRename()
|
|
|
|
|
{
|
|
|
|
|
matName.readOnly = false
|
|
|
|
|
matName.selectAll()
|
|
|
|
|
matName.forceActiveFocus()
|
2022-11-08 13:02:06 +02:00
|
|
|
matName.ensureVisible(matName.text.length)
|
2022-03-18 17:28:28 +02:00
|
|
|
nameMouseArea.enabled = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function commitRename()
|
|
|
|
|
{
|
|
|
|
|
if (matName.readOnly)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
materialBrowserModel.renameMaterial(index, matName.text);
|
2022-11-08 13:02:06 +02:00
|
|
|
mouseArea.forceActiveFocus()
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-25 17:30:05 +02:00
|
|
|
border.width: materialBrowserModel.selectedIndex === index ? rootView.materialSectionFocused ? 3 : 1 : 0
|
2022-03-18 17:28:28 +02:00
|
|
|
border.color: materialBrowserModel.selectedIndex === index
|
|
|
|
|
? StudioTheme.Values.themeControlOutlineInteraction
|
|
|
|
|
: "transparent"
|
|
|
|
|
color: "transparent"
|
|
|
|
|
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"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDropped: (drag) => {
|
2023-02-17 15:22:55 +02:00
|
|
|
drag.accept()
|
2022-12-13 16:29:25 +02:00
|
|
|
rootView.acceptTextureDropOnMaterial(index, drag.getDataAsString(drag.keys[0]))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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) => {
|
2022-03-18 17:28:28 +02:00
|
|
|
materialBrowserModel.selectMaterial(index)
|
2023-02-13 17:39:33 +02:00
|
|
|
rootView.focusMaterialSection(true)
|
2022-06-27 14:31:59 +03:00
|
|
|
|
|
|
|
|
if (mouse.button === Qt.LeftButton)
|
|
|
|
|
rootView.startDragMaterial(index, mapToGlobal(mouse.x, mouse.y))
|
|
|
|
|
else if (mouse.button === Qt.RightButton)
|
2022-03-18 17:28:28 +02:00
|
|
|
root.showContextMenu()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDoubleClicked: materialBrowserModel.openMaterialEditor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
spacing: 1
|
|
|
|
|
|
|
|
|
|
Item { width: 1; height: 5 } // spacer
|
|
|
|
|
|
|
|
|
|
Image {
|
|
|
|
|
id: img
|
|
|
|
|
|
|
|
|
|
width: root.width - 10
|
|
|
|
|
height: img.width
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
source: "image://materialBrowser/" + materialInternalId
|
|
|
|
|
cache: false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextInput {
|
|
|
|
|
id: matName
|
|
|
|
|
|
|
|
|
|
text: materialName
|
|
|
|
|
|
|
|
|
|
width: img.width
|
|
|
|
|
clip: true
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
horizontalAlignment: TextInput.AlignHCenter
|
|
|
|
|
|
|
|
|
|
font.pixelSize: StudioTheme.Values.myFontSize
|
|
|
|
|
|
|
|
|
|
readOnly: true
|
|
|
|
|
selectByMouse: !matName.readOnly
|
|
|
|
|
|
|
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
|
selectionColor: StudioTheme.Values.themeTextSelectionColor
|
|
|
|
|
selectedTextColor: StudioTheme.Values.themeTextSelectedTextColor
|
|
|
|
|
|
|
|
|
|
// allow only alphanumeric characters, underscores, no space at start, and 1 space between words
|
|
|
|
|
validator: RegExpValidator { regExp: /^(\w+\s)*\w+$/ }
|
|
|
|
|
|
|
|
|
|
onEditingFinished: root.commitRename()
|
|
|
|
|
|
2022-11-08 13:02:06 +02:00
|
|
|
onActiveFocusChanged: {
|
|
|
|
|
if (!activeFocus) {
|
|
|
|
|
matName.readOnly = true
|
|
|
|
|
nameMouseArea.enabled = true
|
|
|
|
|
ensureVisible(0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Component.onCompleted: ensureVisible(0)
|
|
|
|
|
|
2022-03-18 17:28:28 +02:00
|
|
|
MouseArea {
|
|
|
|
|
id: nameMouseArea
|
|
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
2022-11-25 17:30:05 +02:00
|
|
|
onClicked: {
|
|
|
|
|
materialBrowserModel.selectMaterial(index)
|
2023-02-13 17:39:33 +02:00
|
|
|
rootView.focusMaterialSection(true)
|
2022-11-25 17:30:05 +02:00
|
|
|
}
|
2022-03-18 17:28:28 +02:00
|
|
|
onDoubleClicked: root.startRename()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|