2022-10-26 19:57:41 +03:00
|
|
|
// Copyright (C) 2022 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-09-01 15:03:01 +03:00
|
|
|
|
|
|
|
|
import QtQuick 2.15
|
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
|
import QtQuickDesignerTheme 1.0
|
|
|
|
|
import HelperWidgets 2.0
|
2022-10-12 20:46:17 +03:00
|
|
|
import QtQuick.Controls
|
|
|
|
|
|
2022-09-01 15:03:01 +03:00
|
|
|
import StudioTheme 1.0 as StudioTheme
|
2023-03-02 13:21:40 +01:00
|
|
|
import ContentLibraryBackend
|
2022-09-01 15:03:01 +03:00
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
import WebFetcher 1.0
|
|
|
|
|
|
2022-09-01 15:03:01 +03:00
|
|
|
Item {
|
|
|
|
|
id: root
|
|
|
|
|
|
|
|
|
|
signal showContextMenu()
|
|
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
// Download states: "" (ie default, not downloaded), "unavailable", "downloading", "downloaded",
|
|
|
|
|
// "failed"
|
|
|
|
|
property string downloadState: modelData.isDownloaded() ? "downloaded" : ""
|
|
|
|
|
|
2022-09-01 15:03:01 +03:00
|
|
|
visible: modelData.bundleMaterialVisible
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
id: mouseArea
|
|
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
enabled: root.downloadState !== "downloading"
|
2022-12-05 13:51:50 +02:00
|
|
|
hoverEnabled: true
|
2022-09-01 15:03:01 +03:00
|
|
|
anchors.fill: parent
|
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
|
|
|
|
|
|
onPressed: (mouse) => {
|
2023-03-02 14:50:06 +02:00
|
|
|
if (mouse.button === Qt.LeftButton && !materialsModel.importerRunning) {
|
|
|
|
|
if (root.downloadState === "downloaded")
|
|
|
|
|
ContentLibraryBackend.rootView.startDragMaterial(modelData, mapToGlobal(mouse.x, mouse.y))
|
|
|
|
|
} else if (mouse.button === Qt.RightButton && root.downloadState === "downloaded") {
|
2022-09-01 15:03:01 +03:00
|
|
|
root.showContextMenu()
|
2023-03-02 14:50:06 +02:00
|
|
|
}
|
2022-09-01 15:03:01 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
spacing: 1
|
|
|
|
|
|
|
|
|
|
Item { width: 1; height: 5 } // spacer
|
|
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
DownloadPane {
|
|
|
|
|
id: downloadPane
|
|
|
|
|
width: root.width - 10
|
|
|
|
|
height: img.width
|
|
|
|
|
visible: root.downloadState === "downloading"
|
|
|
|
|
|
|
|
|
|
onRequestCancel: downloader.cancel()
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 15:03:01 +03:00
|
|
|
Image {
|
|
|
|
|
id: img
|
|
|
|
|
|
|
|
|
|
width: root.width - 10
|
|
|
|
|
height: img.width
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
source: modelData.bundleMaterialIcon
|
|
|
|
|
cache: false
|
2023-03-02 14:50:06 +02:00
|
|
|
visible: root.downloadState != "downloading"
|
2022-10-12 20:46:17 +03:00
|
|
|
|
|
|
|
|
Rectangle { // circular indicator for imported bundle materials
|
|
|
|
|
width: 10
|
|
|
|
|
height: 10
|
|
|
|
|
radius: 5
|
|
|
|
|
anchors.right: img.right
|
|
|
|
|
anchors.top: img.top
|
|
|
|
|
anchors.margins: 5
|
|
|
|
|
color: "#00ff00"
|
|
|
|
|
border.color: "#555555"
|
|
|
|
|
border.width: 1
|
|
|
|
|
visible: modelData.bundleMaterialImported
|
|
|
|
|
|
|
|
|
|
ToolTip {
|
|
|
|
|
visible: indicatorMouseArea.containsMouse
|
|
|
|
|
text: qsTr("Material is imported to project")
|
|
|
|
|
delay: 1000
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
id: indicatorMouseArea
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
hoverEnabled: true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IconButton {
|
|
|
|
|
icon: StudioTheme.Constants.plus
|
|
|
|
|
tooltip: qsTr("Add an instance to project")
|
|
|
|
|
buttonSize: 22
|
|
|
|
|
property color c: StudioTheme.Values.themeIconColor
|
|
|
|
|
normalColor: Qt.hsla(c.hslHue, c.hslSaturation, c.hslLightness, .2)
|
|
|
|
|
hoverColor: Qt.hsla(c.hslHue, c.hslSaturation, c.hslLightness, .3)
|
|
|
|
|
pressColor: Qt.hsla(c.hslHue, c.hslSaturation, c.hslLightness, .4)
|
|
|
|
|
anchors.right: img.right
|
|
|
|
|
anchors.bottom: img.bottom
|
2023-03-02 13:21:40 +01:00
|
|
|
enabled: !ContentLibraryBackend.materialsModel.importerRunning
|
2023-03-02 14:50:06 +02:00
|
|
|
visible: root.downloadState === "downloaded"
|
|
|
|
|
&& (containsMouse || mouseArea.containsMouse)
|
2022-10-12 20:46:17 +03:00
|
|
|
|
|
|
|
|
onClicked: {
|
2023-03-02 13:21:40 +01:00
|
|
|
ContentLibraryBackend.materialsModel.addToProject(modelData)
|
2022-10-12 20:46:17 +03:00
|
|
|
}
|
2023-03-02 14:50:06 +02:00
|
|
|
} // IconButton
|
|
|
|
|
|
|
|
|
|
Text { // download icon
|
|
|
|
|
color: root.downloadState === "unavailable" || root.downloadState === "failed"
|
|
|
|
|
? StudioTheme.Values.themeRedLight
|
|
|
|
|
: StudioTheme.Values.themeTextColor
|
|
|
|
|
|
|
|
|
|
font.family: StudioTheme.Constants.iconFont.family
|
|
|
|
|
text: root.downloadState === "unavailable"
|
|
|
|
|
? StudioTheme.Constants.downloadUnavailable
|
|
|
|
|
: StudioTheme.Constants.download
|
|
|
|
|
|
|
|
|
|
font.pixelSize: 22
|
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
|
anchors.bottomMargin: 0
|
|
|
|
|
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
style: Text.Outline
|
|
|
|
|
styleColor: "black"
|
|
|
|
|
|
|
|
|
|
visible: root.downloadState !== "downloaded"
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
acceptedButtons: Qt.LeftButton
|
|
|
|
|
|
|
|
|
|
onClicked: (mouse) => {
|
|
|
|
|
if (root.downloadState !== "" && root.downloadState !== "failed")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
downloadPane.beginDownload(Qt.binding(function() { return downloader.progress }))
|
|
|
|
|
|
|
|
|
|
root.downloadState = ""
|
|
|
|
|
downloader.start()
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-12 20:46:17 +03:00
|
|
|
}
|
2023-03-02 14:50:06 +02:00
|
|
|
} // Image
|
2022-09-01 15:03:01 +03:00
|
|
|
|
|
|
|
|
TextInput {
|
|
|
|
|
id: matName
|
|
|
|
|
|
|
|
|
|
text: modelData.bundleMaterialName
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
2023-03-02 14:50:06 +02:00
|
|
|
} // Column
|
|
|
|
|
|
|
|
|
|
MultiFileDownloader {
|
|
|
|
|
id: downloader
|
|
|
|
|
|
|
|
|
|
baseUrl: modelData.bundleMaterialBaseWebUrl
|
|
|
|
|
files: modelData.bundleMaterialFiles
|
|
|
|
|
|
|
|
|
|
targetDirPath: modelData.bundleMaterialParentPath
|
|
|
|
|
|
|
|
|
|
onDownloadStarting: {
|
|
|
|
|
root.downloadState = "downloading"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onFinishedChanged: {
|
|
|
|
|
downloadPane.endDownload()
|
|
|
|
|
|
|
|
|
|
root.downloadState = "downloaded"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDownloadCanceled: {
|
|
|
|
|
downloadPane.endDownload()
|
|
|
|
|
|
|
|
|
|
root.downloadState = ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDownloadFailed: {
|
|
|
|
|
downloadPane.endDownload()
|
|
|
|
|
|
|
|
|
|
root.downloadState = "failed"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
downloader: FileDownloader {
|
|
|
|
|
id: fileDownloader
|
|
|
|
|
url: downloader.nextUrl
|
|
|
|
|
probeUrl: false
|
|
|
|
|
downloadEnabled: true
|
|
|
|
|
targetFilePath: downloader.nextTargetPath
|
|
|
|
|
} // FileDownloader
|
|
|
|
|
} // MultiFileDownloader
|
2022-09-01 15:03:01 +03:00
|
|
|
}
|