2024-05-11 00:04:11 +03:00
|
|
|
// Copyright (C) 2024 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2022-10-26 19:57:41 +03:00
|
|
|
|
2024-05-11 00:04:11 +03:00
|
|
|
import QtQuick
|
|
|
|
|
import StudioControls as StudioControls
|
|
|
|
|
import StudioTheme as StudioTheme
|
|
|
|
|
import ContentLibraryBackend
|
2022-10-26 19:57:41 +03:00
|
|
|
|
|
|
|
|
StudioControls.Menu {
|
|
|
|
|
id: root
|
|
|
|
|
|
2024-05-11 00:04:11 +03:00
|
|
|
property var targetItem: null
|
2024-06-26 20:56:05 +03:00
|
|
|
property bool showRemoveAction: false // true: adds an option to remove targetItem
|
|
|
|
|
property bool showImportAction: false // true: adds an option to import a bundle from file
|
2022-11-29 16:56:08 +02:00
|
|
|
|
2024-05-11 00:04:11 +03:00
|
|
|
readonly property bool targetAvailable: targetItem && !ContentLibraryBackend.rootView.importerRunning
|
2022-11-29 16:56:08 +02:00
|
|
|
|
2024-03-21 12:47:09 +02:00
|
|
|
signal unimport();
|
|
|
|
|
signal addToProject()
|
|
|
|
|
signal applyToSelected(bool add)
|
2024-04-25 11:59:01 +03:00
|
|
|
signal removeFromContentLib()
|
2024-06-26 20:56:05 +03:00
|
|
|
signal importBundle()
|
2022-10-26 19:57:41 +03:00
|
|
|
|
2024-05-11 00:04:11 +03:00
|
|
|
function popupMenu(item = null)
|
2022-10-26 19:57:41 +03:00
|
|
|
{
|
2024-05-11 00:04:11 +03:00
|
|
|
root.targetItem = item
|
|
|
|
|
|
2024-06-28 13:02:02 +03:00
|
|
|
let isMaterial = item && (root.targetItem.bundleId === "UserMaterials"
|
|
|
|
|
|| root.targetItem.bundleId === "MaterialBundle"
|
|
|
|
|
|| root.targetItem.bundleId === "Materials")
|
2024-05-11 00:04:11 +03:00
|
|
|
applyToSelectedReplace.visible = isMaterial
|
|
|
|
|
applyToSelectedAdd.visible = isMaterial
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
popup()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closePolicy: StudioControls.Menu.CloseOnEscape | StudioControls.Menu.CloseOnPressOutside
|
|
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
2024-05-11 00:04:11 +03:00
|
|
|
id: applyToSelectedReplace
|
2022-10-26 19:57:41 +03:00
|
|
|
text: qsTr("Apply to selected (replace)")
|
2024-05-11 00:04:11 +03:00
|
|
|
height: visible ? implicitHeight : 0
|
|
|
|
|
enabled: root.targetAvailable && ContentLibraryBackend.rootView.hasModelSelection
|
2024-03-21 12:47:09 +02:00
|
|
|
onTriggered: root.applyToSelected(false)
|
2022-10-26 19:57:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
2024-05-11 00:04:11 +03:00
|
|
|
id: applyToSelectedAdd
|
2022-10-26 19:57:41 +03:00
|
|
|
text: qsTr("Apply to selected (add)")
|
2024-05-11 00:04:11 +03:00
|
|
|
height: visible ? implicitHeight : 0
|
|
|
|
|
enabled: root.targetAvailable && ContentLibraryBackend.rootView.hasModelSelection
|
2024-03-21 12:47:09 +02:00
|
|
|
onTriggered: root.applyToSelected(true)
|
2022-10-26 19:57:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StudioControls.MenuSeparator {}
|
|
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
2022-11-29 16:56:08 +02:00
|
|
|
enabled: root.targetAvailable
|
2022-10-26 19:57:41 +03:00
|
|
|
text: qsTr("Add an instance to project")
|
2024-05-11 00:04:11 +03:00
|
|
|
onTriggered: root.addToProject()
|
2022-10-26 19:57:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
2024-05-11 00:04:11 +03:00
|
|
|
enabled: root.targetAvailable && root.targetItem.bundleItemImported
|
2022-10-26 19:57:41 +03:00
|
|
|
text: qsTr("Remove from project")
|
2024-03-21 12:47:09 +02:00
|
|
|
onTriggered: root.unimport()
|
2022-10-26 19:57:41 +03:00
|
|
|
}
|
2024-04-25 11:59:01 +03:00
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
text: qsTr("Remove from Content Library")
|
2024-06-26 20:56:05 +03:00
|
|
|
visible: root.showRemoveAction && root.targetAvailable
|
2024-04-25 11:59:01 +03:00
|
|
|
height: visible ? implicitHeight : 0
|
|
|
|
|
onTriggered: root.removeFromContentLib()
|
|
|
|
|
}
|
2024-06-26 20:56:05 +03:00
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
text: qsTr("Import bundle")
|
|
|
|
|
visible: root.showImportAction
|
|
|
|
|
height: visible ? implicitHeight : 0
|
|
|
|
|
onTriggered: root.importBundle()
|
|
|
|
|
}
|
2022-10-26 19:57:41 +03:00
|
|
|
}
|