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 QtQuickDesignerTheme 1.0
|
|
|
|
|
import HelperWidgets 2.0
|
|
|
|
|
import StudioControls 1.0 as StudioControls
|
|
|
|
|
import StudioTheme 1.0 as StudioTheme
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: root
|
|
|
|
|
|
|
|
|
|
readonly property int cellWidth: 100
|
|
|
|
|
readonly property int cellHeight: 120
|
|
|
|
|
|
2022-10-18 16:26:16 +03:00
|
|
|
property var currMaterialItem: null
|
2022-08-12 11:47:36 +03:00
|
|
|
|
2022-03-18 17:28:28 +02:00
|
|
|
// Called also from C++ to close context menu on focus out
|
|
|
|
|
function closeContextMenu()
|
|
|
|
|
{
|
2022-10-12 20:46:17 +03:00
|
|
|
ctxMenu.close()
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called from C++ to refresh a preview material after it changes
|
|
|
|
|
function refreshPreview(idx)
|
|
|
|
|
{
|
2022-10-26 19:57:41 +03:00
|
|
|
var item = materialRepeater.itemAt(idx);
|
2022-03-18 17:28:28 +02:00
|
|
|
if (item)
|
|
|
|
|
item.refreshPreview();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called from C++
|
|
|
|
|
function clearSearchFilter()
|
|
|
|
|
{
|
2022-05-23 20:32:43 +03:00
|
|
|
searchBox.clear();
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
id: rootMouseArea
|
|
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
|
|
acceptedButtons: Qt.RightButton
|
|
|
|
|
|
2022-09-01 15:03:01 +03:00
|
|
|
onClicked: (mouse) => {
|
2022-10-26 19:57:41 +03:00
|
|
|
if (materialBrowserModel.hasMaterialRoot || !materialBrowserModel.hasQuick3DImport)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var matsSecBottom = mapFromItem(materialsSection, 0, materialsSection.y).y
|
|
|
|
|
+ materialsSection.height;
|
2022-09-01 15:03:01 +03:00
|
|
|
|
2022-10-18 12:23:27 +03:00
|
|
|
if (!materialBrowserModel.hasMaterialRoot && materialBrowserModel.hasQuick3DImport
|
2022-10-26 19:57:41 +03:00
|
|
|
&& mouse.y < matsSecBottom) {
|
2022-10-18 16:26:16 +03:00
|
|
|
ctxMenu.popupMenu()
|
2022-08-11 12:45:05 +03:00
|
|
|
}
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
|
target: materialBrowserModel
|
|
|
|
|
|
|
|
|
|
function onSelectedIndexChanged() {
|
|
|
|
|
// commit rename upon changing selection
|
2022-10-18 16:26:16 +03:00
|
|
|
if (root.currMaterialItem)
|
|
|
|
|
root.currMaterialItem.commitRename();
|
2022-03-18 17:28:28 +02:00
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
root.currMaterialItem = materialRepeater.itemAt(materialBrowserModel.selectedIndex);
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 16:26:16 +03:00
|
|
|
MaterialBrowserContextMenu {
|
2022-10-12 20:46:17 +03:00
|
|
|
id: ctxMenu
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
id: col
|
|
|
|
|
y: 5
|
|
|
|
|
spacing: 5
|
|
|
|
|
|
|
|
|
|
Row {
|
|
|
|
|
width: root.width
|
2022-08-11 12:45:05 +03:00
|
|
|
enabled: !materialBrowserModel.hasMaterialRoot && materialBrowserModel.hasQuick3DImport
|
2022-03-18 17:28:28 +02:00
|
|
|
|
2022-09-26 15:59:22 +03:00
|
|
|
StudioControls.SearchBox {
|
2022-03-18 17:28:28 +02:00
|
|
|
id: searchBox
|
|
|
|
|
|
|
|
|
|
width: root.width - addMaterialButton.width
|
2022-09-26 15:21:33 +03:00
|
|
|
|
2022-10-03 15:07:43 +03:00
|
|
|
onSearchChanged: (searchText) => {
|
|
|
|
|
rootView.handleSearchFilterChanged(searchText)
|
|
|
|
|
}
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IconButton {
|
|
|
|
|
id: addMaterialButton
|
|
|
|
|
|
|
|
|
|
tooltip: qsTr("Add a material.")
|
|
|
|
|
|
|
|
|
|
icon: StudioTheme.Constants.plus
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
buttonSize: searchBox.height
|
|
|
|
|
onClicked: materialBrowserModel.addNewMaterial()
|
2022-10-18 12:23:27 +03:00
|
|
|
enabled: materialBrowserModel.hasQuick3DImport
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text {
|
2022-08-11 12:45:05 +03:00
|
|
|
text: {
|
|
|
|
|
if (materialBrowserModel.hasMaterialRoot)
|
|
|
|
|
qsTr("<b>Material Browser</b> is disabled inside a material component.")
|
|
|
|
|
else if (!materialBrowserModel.hasQuick3DImport)
|
|
|
|
|
qsTr("To use <b>Material Browser</b>, first add the QtQuick3D module in the <b>Components</b> view.")
|
|
|
|
|
else
|
|
|
|
|
""
|
|
|
|
|
}
|
2022-03-18 17:28:28 +02:00
|
|
|
|
2022-06-22 12:48:25 +03:00
|
|
|
textFormat: Text.RichText
|
2022-03-18 17:28:28 +02:00
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
|
font.pixelSize: StudioTheme.Values.mediumFontSize
|
|
|
|
|
topPadding: 30
|
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
|
width: root.width
|
2022-08-11 12:45:05 +03:00
|
|
|
visible: text !== ""
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScrollView {
|
|
|
|
|
id: scrollView
|
|
|
|
|
|
|
|
|
|
width: root.width
|
|
|
|
|
height: root.height - searchBox.height
|
|
|
|
|
clip: true
|
2022-09-01 15:03:01 +03:00
|
|
|
visible: materialBrowserModel.hasQuick3DImport && !materialBrowserModel.hasMaterialRoot
|
2022-10-26 19:57:41 +03:00
|
|
|
interactive: !ctxMenu.opened
|
2022-09-01 15:03:01 +03:00
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
Section {
|
2022-10-26 19:57:41 +03:00
|
|
|
id: materialsSection
|
2022-09-01 15:03:01 +03:00
|
|
|
|
|
|
|
|
width: root.width
|
2022-10-12 20:46:17 +03:00
|
|
|
caption: qsTr("Materials")
|
2022-10-20 17:42:46 +03:00
|
|
|
dropEnabled: true
|
|
|
|
|
|
|
|
|
|
onDropEnter: (drag) => {
|
2022-10-26 19:57:41 +03:00
|
|
|
drag.accepted = drag.formats[0] === "application/vnd.qtdesignstudio.bundlematerial"
|
|
|
|
|
materialsSection.highlight = drag.accepted
|
2022-10-20 17:42:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDropExit: {
|
2022-10-26 19:57:41 +03:00
|
|
|
materialsSection.highlight = false
|
2022-10-20 17:42:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDrop: {
|
2022-10-26 19:57:41 +03:00
|
|
|
materialsSection.highlight = false
|
|
|
|
|
rootView.acceptBundleMaterialDrop()
|
2022-10-20 17:42:46 +03:00
|
|
|
}
|
2022-09-01 15:03:01 +03:00
|
|
|
|
|
|
|
|
Grid {
|
|
|
|
|
id: grid
|
|
|
|
|
|
|
|
|
|
width: scrollView.width
|
|
|
|
|
leftPadding: 5
|
|
|
|
|
rightPadding: 5
|
|
|
|
|
bottomPadding: 5
|
|
|
|
|
columns: root.width / root.cellWidth
|
|
|
|
|
|
|
|
|
|
Repeater {
|
2022-10-26 19:57:41 +03:00
|
|
|
id: materialRepeater
|
2022-09-01 15:03:01 +03:00
|
|
|
|
|
|
|
|
model: materialBrowserModel
|
|
|
|
|
delegate: MaterialItem {
|
|
|
|
|
width: root.cellWidth
|
|
|
|
|
height: root.cellHeight
|
|
|
|
|
|
|
|
|
|
onShowContextMenu: {
|
2022-10-18 16:26:16 +03:00
|
|
|
ctxMenu.popupMenu(this, model)
|
2022-09-01 15:03:01 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-18 17:28:28 +02:00
|
|
|
|
2022-09-01 15:03:01 +03:00
|
|
|
Text {
|
|
|
|
|
text: qsTr("No match found.");
|
|
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
|
font.pixelSize: StudioTheme.Values.baseFontSize
|
|
|
|
|
leftPadding: 10
|
|
|
|
|
visible: materialBrowserModel.isEmpty && !searchBox.isEmpty() && !materialBrowserModel.hasMaterialRoot
|
|
|
|
|
}
|
2022-03-18 17:28:28 +02:00
|
|
|
|
2022-09-01 15:03:01 +03:00
|
|
|
Text {
|
|
|
|
|
text:qsTr("There are no materials in this project.<br>Select '<b>+</b>' to create one.")
|
|
|
|
|
visible: materialBrowserModel.isEmpty && searchBox.isEmpty()
|
|
|
|
|
textFormat: Text.RichText
|
|
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
|
font.pixelSize: StudioTheme.Values.mediumFontSize
|
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
|
width: root.width
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-18 17:28:28 +02:00
|
|
|
|
2022-09-01 15:03:01 +03:00
|
|
|
Section {
|
2022-10-26 19:57:41 +03:00
|
|
|
id: texturesSection
|
2022-10-03 15:07:43 +03:00
|
|
|
|
2022-09-01 15:03:01 +03:00
|
|
|
width: root.width
|
2022-10-26 19:57:41 +03:00
|
|
|
caption: qsTr("Textures")
|
|
|
|
|
|
|
|
|
|
Grid {
|
|
|
|
|
width: scrollView.width
|
|
|
|
|
leftPadding: 5
|
|
|
|
|
rightPadding: 5
|
|
|
|
|
bottomPadding: 5
|
|
|
|
|
spacing: 5
|
|
|
|
|
columns: root.width / root.cellWidth
|
2022-09-01 15:03:01 +03:00
|
|
|
|
|
|
|
|
Repeater {
|
2022-10-26 19:57:41 +03:00
|
|
|
id: texturesRepeater
|
|
|
|
|
|
|
|
|
|
model: materialBrowserTexturesModel
|
|
|
|
|
delegate: TextureItem {
|
|
|
|
|
width: root.cellWidth
|
|
|
|
|
height: root.cellWidth
|
|
|
|
|
|
|
|
|
|
onShowContextMenu: {
|
|
|
|
|
// ctxMenuTexture.popupMenu(this, model) // TODO: implement textures context menu
|
2022-09-01 15:03:01 +03:00
|
|
|
}
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-10-26 19:57:41 +03:00
|
|
|
}
|
2022-09-01 15:03:01 +03:00
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
Text {
|
|
|
|
|
text: qsTr("No match found.");
|
|
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
|
font.pixelSize: StudioTheme.Values.baseFontSize
|
|
|
|
|
leftPadding: 10
|
|
|
|
|
visible: materialBrowserModel.isEmpty && !searchBox.isEmpty() && !materialBrowserModel.hasMaterialRoot
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text {
|
|
|
|
|
text:qsTr("There are no texture in this project.")
|
|
|
|
|
visible: materialBrowserTexturesModel.isEmpty && searchBox.isEmpty()
|
|
|
|
|
textFormat: Text.RichText
|
|
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
|
font.pixelSize: StudioTheme.Values.mediumFontSize
|
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
|
width: root.width
|
2022-03-18 17:28:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|