aboutsummaryrefslogtreecommitdiffstats
path: root/share/qtcreator
diff options
context:
space:
mode:
authorMahmoud Badri <mahmoud.badri@qt.io>2024-03-21 12:47:09 +0200
committerMahmoud Badri <mahmoud.badri@qt.io>2024-04-08 12:13:16 +0000
commitbc5628afca0c0716642cd69679d6b51acfa60316 (patch)
treeff0ceee4cea89c86f2ef60ad352b68da8e822a74 /share/qtcreator
parentda21fa4c3396e867537909b68f4a053114d195c0 (diff)
QmlDesigner: Add content library user materials bundle
Fixes: QDS-12389 Change-Id: Icec1b06c57e0eaa4ff444e3143d3cba0803c8dd1 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'share/qtcreator')
-rw-r--r--share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibrary.qml46
-rw-r--r--share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterial.qml13
-rw-r--r--share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialContextMenu.qml13
-rw-r--r--share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml25
-rw-r--r--share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexturesView.qml3
-rw-r--r--share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml151
-rw-r--r--share/qtcreator/qmldesigner/contentLibraryQmlSource/UnimportBundleMaterialDialog.qml23
7 files changed, 230 insertions, 44 deletions
diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibrary.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibrary.qml
index c6db8425ff..2c98b58adc 100644
--- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibrary.qml
+++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibrary.qml
@@ -23,6 +23,7 @@ Item {
texturesView.closeContextMenu()
environmentsView.closeContextMenu()
effectsView.closeContextMenu()
+ userView.closeContextMenu()
HelperWidgets.Controller.closeContextMenu()
}
@@ -113,10 +114,18 @@ Item {
id: tabBar
width: parent.width
height: StudioTheme.Values.toolbarHeight
- tabsModel: [{name: qsTr("Materials"), icon: StudioTheme.Constants.material_medium},
- {name: qsTr("Textures"), icon: StudioTheme.Constants.textures_medium},
- {name: qsTr("Environments"), icon: StudioTheme.Constants.languageList_medium},
- {name: qsTr("Effects"), icon: StudioTheme.Constants.effects}]
+
+ Component.onCompleted: {
+ var tabs = [
+ { name: qsTr("Materials"), icon: StudioTheme.Constants.material_medium },
+ { name: qsTr("Textures"), icon: StudioTheme.Constants.textures_medium },
+ { name: qsTr("Environments"), icon: StudioTheme.Constants.languageList_medium },
+ { name: qsTr("Effects"), icon: StudioTheme.Constants.effects }
+ ];
+ if (ContentLibraryBackend.rootView.userBundleEnabled())
+ tabs.push({ name: qsTr("User Assets"), icon: StudioTheme.Constants.effects });
+ tabBar.tabsModel = tabs;
+ }
}
}
}
@@ -148,7 +157,8 @@ Item {
onUnimport: (bundleMat) => {
confirmUnimportDialog.targetBundleItem = bundleMat
- confirmUnimportDialog.targetBundleType = "material"
+ confirmUnimportDialog.targetBundleLabel = "material"
+ confirmUnimportDialog.targetBundleModel = ContentLibraryBackend.materialsModel
confirmUnimportDialog.open()
}
@@ -208,7 +218,31 @@ Item {
onUnimport: (bundleItem) => {
confirmUnimportDialog.targetBundleItem = bundleItem
- confirmUnimportDialog.targetBundleType = "effect"
+ confirmUnimportDialog.targetBundleLabel = "effect"
+ confirmUnimportDialog.targetBundleModel = ContentLibraryBackend.effectsModel
+ confirmUnimportDialog.open()
+ }
+
+ onCountChanged: root.responsiveResize(stackLayout.width, stackLayout.height)
+ }
+
+ ContentLibraryUserView {
+ id: userView
+
+ adsFocus: root.adsFocus
+ width: root.width
+
+ cellWidth: root.thumbnailSize
+ cellHeight: root.thumbnailSize + 20
+ numColumns: root.numColumns
+ hideHorizontalScrollBar: true
+
+ searchBox: searchBox
+
+ onUnimport: (bundleItem) => {
+ confirmUnimportDialog.targetBundleItem = bundleItem
+ confirmUnimportDialog.targetBundleLabel = "material"
+ confirmUnimportDialog.targetBundleModel = ContentLibraryBackend.userModel
confirmUnimportDialog.open()
}
diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterial.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterial.qml
index 93b226d6ca..0e9fc4903e 100644
--- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterial.qml
+++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterial.qml
@@ -12,12 +12,15 @@ import WebFetcher
Item {
id: root
- signal showContextMenu()
-
// Download states: "" (ie default, not downloaded), "unavailable", "downloading", "downloaded",
// "failed"
property string downloadState: modelData.isDownloaded() ? "downloaded" : ""
+ property bool importerRunning: false
+
+ signal showContextMenu()
+ signal addToProject()
+
visible: modelData.bundleMaterialVisible
MouseArea {
@@ -29,7 +32,7 @@ Item {
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: (mouse) => {
- if (mouse.button === Qt.LeftButton && !materialsModel.importerRunning) {
+ if (mouse.button === Qt.LeftButton && !root.importerRunning) {
if (root.downloadState === "downloaded")
ContentLibraryBackend.rootView.startDragMaterial(modelData, mapToGlobal(mouse.x, mouse.y))
} else if (mouse.button === Qt.RightButton && root.downloadState === "downloaded") {
@@ -96,12 +99,12 @@ Item {
pressColor: Qt.hsla(c.hslHue, c.hslSaturation, c.hslLightness, .4)
anchors.right: img.right
anchors.bottom: img.bottom
- enabled: !ContentLibraryBackend.materialsModel.importerRunning
+ enabled: !root.importerRunning
visible: root.downloadState === "downloaded"
&& (containsMouse || mouseArea.containsMouse)
onClicked: {
- ContentLibraryBackend.materialsModel.addToProject(modelData)
+ root.addToProject()
}
}
diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialContextMenu.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialContextMenu.qml
index ca3a05bdd1..b67ec311ef 100644
--- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialContextMenu.qml
+++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialContextMenu.qml
@@ -15,8 +15,9 @@ StudioControls.Menu {
readonly property bool targetAvailable: targetMaterial && !importerRunning
- signal unimport(var bundleMat);
- signal addToProject(var bundleMat)
+ signal unimport();
+ signal addToProject()
+ signal applyToSelected(bool add)
function popupMenu(targetMaterial = null)
{
@@ -29,13 +30,13 @@ StudioControls.Menu {
StudioControls.MenuItem {
text: qsTr("Apply to selected (replace)")
enabled: root.targetAvailable && root.hasModelSelection
- onTriggered: materialsModel.applyToSelected(root.targetMaterial, false)
+ onTriggered: root.applyToSelected(false)
}
StudioControls.MenuItem {
text: qsTr("Apply to selected (add)")
enabled: root.targetAvailable && root.hasModelSelection
- onTriggered: materialsModel.applyToSelected(root.targetMaterial, true)
+ onTriggered: root.applyToSelected(true)
}
StudioControls.MenuSeparator {}
@@ -45,7 +46,7 @@ StudioControls.Menu {
text: qsTr("Add an instance to project")
onTriggered: {
- root.addToProject(root.targetMaterial)
+ root.addToProject()
}
}
@@ -53,6 +54,6 @@ StudioControls.Menu {
enabled: root.targetAvailable && root.targetMaterial.bundleMaterialImported
text: qsTr("Remove from project")
- onTriggered: root.unimport(root.targetMaterial)
+ onTriggered: root.unimport()
}
}
diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml
index c21baf4c58..9a0e33b8e5 100644
--- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml
+++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml
@@ -27,8 +27,6 @@ HelperWidgets.ScrollView {
root.count = c
}
- property var currMaterialItem: null
- property var rootItem: null
property var materialsModel: ContentLibraryBackend.materialsModel
required property var searchBox
@@ -51,17 +49,19 @@ HelperWidgets.ScrollView {
ContentLibraryMaterialContextMenu {
id: ctxMenu
- hasModelSelection: materialsModel.hasModelSelection
- importerRunning: materialsModel.importerRunning
+ hasModelSelection: root.materialsModel.hasModelSelection
+ importerRunning: root.materialsModel.importerRunning
- onUnimport: (bundleMat) => root.unimport(bundleMat)
- onAddToProject: (bundleMat) => materialsModel.addToProject(bundleMat)
+ onApplyToSelected: (add) => root.materialsModel.applyToSelected(ctxMenu.targetMaterial, add)
+
+ onUnimport: root.unimport(ctxMenu.targetMaterial)
+ onAddToProject: root.materialsModel.addToProject(ctxMenu.targetMaterial)
}
Repeater {
id: categoryRepeater
- model: materialsModel
+ model: root.materialsModel
delegate: HelperWidgets.Section {
id: section
@@ -73,7 +73,7 @@ HelperWidgets.ScrollView {
bottomPadding: StudioTheme.Values.sectionPadding
caption: bundleCategoryName
- visible: bundleCategoryVisible && !materialsModel.isEmpty
+ visible: bundleCategoryVisible && !root.materialsModel.isEmpty
expanded: bundleCategoryExpanded
expandOnClick: false
category: "ContentLib_Mat"
@@ -103,7 +103,10 @@ HelperWidgets.ScrollView {
width: root.cellWidth
height: root.cellHeight
+ importerRunning: root.materialsModel.importerRunning
+
onShowContextMenu: ctxMenu.popupMenu(modelData)
+ onAddToProject: root.materialsModel.addToProject(modelData)
}
onCountChanged: root.assignMaxCount()
@@ -115,13 +118,13 @@ HelperWidgets.ScrollView {
Text {
id: infoText
text: {
- if (!materialsModel.matBundleExists)
+ if (!root.materialsModel.matBundleExists)
qsTr("No materials available. Make sure you have internet connection.")
else if (!ContentLibraryBackend.rootView.isQt6Project)
qsTr("<b>Content Library</b> materials are not supported in Qt5 projects.")
else if (!ContentLibraryBackend.rootView.hasQuick3DImport)
qsTr("To use <b>Content Library</b>, first add the QtQuick3D module in the <b>Components</b> view.")
- else if (!materialsModel.hasRequiredQuick3DImport)
+ else if (!root.materialsModel.hasRequiredQuick3DImport)
qsTr("To use <b>Content Library</b>, version 6.3 or later of the QtQuick3D module is required.")
else if (!ContentLibraryBackend.rootView.hasMaterialLibrary)
qsTr("<b>Content Library</b> is disabled inside a non-visual component.")
@@ -134,7 +137,7 @@ HelperWidgets.ScrollView {
font.pixelSize: StudioTheme.Values.baseFontSize
topPadding: 10
leftPadding: 10
- visible: materialsModel.isEmpty
+ visible: root.materialsModel.isEmpty
}
}
}
diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexturesView.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexturesView.qml
index 1fac9f2234..617b724e66 100644
--- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexturesView.qml
+++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexturesView.qml
@@ -27,9 +27,6 @@ HelperWidgets.ScrollView {
root.count = c
}
- property var currMaterialItem: null
- property var rootItem: null
-
required property var searchBox
required property var model
required property string sectionCategory
diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml
new file mode 100644
index 0000000000..d3d1dbad92
--- /dev/null
+++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml
@@ -0,0 +1,151 @@
+// 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
+import HelperWidgets as HelperWidgets
+import StudioControls as StudioControls
+import StudioTheme as StudioTheme
+import ContentLibraryBackend
+
+HelperWidgets.ScrollView {
+ id: root
+
+ clip: true
+ interactive: !ctxMenu.opened && !ContentLibraryBackend.rootView.isDragging
+ && !HelperWidgets.Controller.contextMenuOpened
+
+ 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);
+
+ function closeContextMenu() {
+ ctxMenu.close()
+ }
+
+ function expandVisibleSections() {
+ for (let i = 0; i < categoryRepeater.count; ++i) {
+ let cat = categoryRepeater.itemAt(i)
+ if (cat.visible && !cat.expanded)
+ cat.expandSection()
+ }
+ }
+
+ Column {
+ ContentLibraryMaterialContextMenu {
+ id: ctxMenu
+
+ hasModelSelection: ContentLibraryBackend.userModel.hasModelSelection
+ importerRunning: ContentLibraryBackend.userModel.importerRunning
+
+ onApplyToSelected: (add) => ContentLibraryBackend.userModel.applyToSelected(ctxMenu.targetMaterial, add)
+
+ onUnimport: root.unimport(ctxMenu.targetMaterial)
+ onAddToProject: ContentLibraryBackend.userModel.addToProject(ctxMenu.targetMaterial)
+ }
+
+ Repeater {
+ id: categoryRepeater
+
+ model: ContentLibraryBackend.userModel
+
+ delegate: HelperWidgets.Section {
+ id: section
+
+ width: root.width
+ leftPadding: StudioTheme.Values.sectionPadding
+ rightPadding: StudioTheme.Values.sectionPadding
+ topPadding: StudioTheme.Values.sectionPadding
+ bottomPadding: StudioTheme.Values.sectionPadding
+
+ caption: categoryName
+ visible: categoryVisible
+ expanded: categoryExpanded
+ expandOnClick: false
+ category: "ContentLib_User"
+
+ onToggleExpand: categoryExpanded = !categoryExpanded
+ onExpand: categoryExpanded = true
+ onCollapse: categoryExpanded = false
+
+ function expandSection() {
+ categoryExpanded = true
+ }
+
+ property alias count: repeater.count
+
+ onCountChanged: root.assignMaxCount()
+
+ property int numVisibleItem: 1 // initially, the tab is invisible so this will be 0
+
+ Grid {
+ width: section.width - section.leftPadding - section.rightPadding
+ spacing: StudioTheme.Values.sectionGridSpacing
+ columns: root.numColumns
+
+ Repeater {
+ id: repeater
+ model: categoryItems
+
+ delegate: ContentLibraryMaterial {
+ width: root.cellWidth
+ height: root.cellHeight
+
+ importerRunning: ContentLibraryBackend.userModel.importerRunning
+
+ onShowContextMenu: ctxMenu.popupMenu(modelData)
+ onAddToProject: ContentLibraryBackend.userModel.addToProject(modelData)
+
+ onVisibleChanged: {
+ section.numVisibleItem += visible ? 1 : -1
+ }
+ }
+
+ onCountChanged: root.assignMaxCount()
+ }
+ }
+
+ Text {
+ text: qsTr("No match found.");
+ color: StudioTheme.Values.themeTextColor
+ font.pixelSize: StudioTheme.Values.baseFontSize
+ leftPadding: 10
+ visible: !searchBox.isEmpty() && section.numVisibleItem === 0
+ }
+ }
+ }
+
+ Text {
+ id: infoText
+ text: {
+ if (!ContentLibraryBackend.effectsModel.bundleExists)
+ qsTr("User bundle couldn't be found.")
+ else if (!ContentLibraryBackend.rootView.isQt6Project)
+ qsTr("<b>Content Library</b> is not supported in Qt5 projects.")
+ else if (!ContentLibraryBackend.rootView.hasQuick3DImport)
+ qsTr("To use <b>Content Library</b>, first add the QtQuick3D module in the <b>Components</b> view.")
+ else if (!ContentLibraryBackend.rootView.hasMaterialLibrary)
+ qsTr("<b>Content Library</b> is disabled inside a non-visual component.")
+ else
+ ""
+ }
+ color: StudioTheme.Values.themeTextColor
+ font.pixelSize: StudioTheme.Values.baseFontSize
+ topPadding: 10
+ leftPadding: 10
+ visible: ContentLibraryBackend.effectsModel.isEmpty
+ }
+ }
+}
diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/UnimportBundleMaterialDialog.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/UnimportBundleMaterialDialog.qml
index 48be045d8b..4385e3bf82 100644
--- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/UnimportBundleMaterialDialog.qml
+++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/UnimportBundleMaterialDialog.qml
@@ -12,24 +12,27 @@ import ContentLibraryBackend
StudioControls.Dialog {
id: root
- title: qsTr("Bundle material might be in use")
+ property var targetBundleItem
+ property var targetBundleLabel // "effect" or "material"
+ property var targetBundleModel
+
+ title: qsTr("Bundle %1 might be in use").arg(root.targetBundleLabel)
anchors.centerIn: parent
closePolicy: Popup.CloseOnEscape
implicitWidth: 300
modal: true
- property var targetBundleType // "effect" or "material"
- property var targetBundleItem
+ onOpened: warningText.forceActiveFocus()
contentItem: Column {
spacing: 20
width: parent.width
Text {
- id: folderNotEmpty
+ id: warningText
- text: qsTr("If the %1 you are removing is in use, it might cause the project to malfunction.\n\nAre you sure you want to remove the %1?")
- .arg(root.targetBundleType)
+ text: qsTr("If the %1 you are removing is in use, it might cause the project to malfunction.\n\nAre you sure you want to remove it?")
+ .arg(root.targetBundleLabel)
color: StudioTheme.Values.themeTextColor
wrapMode: Text.WordWrap
anchors.right: parent.right
@@ -49,11 +52,7 @@ StudioControls.Dialog {
text: qsTr("Remove")
onClicked: {
- if (root.targetBundleType === "material")
- ContentLibraryBackend.materialsModel.removeFromProject(root.targetBundleItem)
- else if (root.targetBundleType === "effect")
- ContentLibraryBackend.effectsModel.removeFromProject(root.targetBundleItem)
-
+ root.targetBundleModel.removeFromProject(root.targetBundleItem)
root.accept()
}
}
@@ -64,6 +63,4 @@ StudioControls.Dialog {
}
}
}
-
- onOpened: folderNotEmpty.forceActiveFocus()
}