forked from qt-creator/qt-creator
QmlDesigner: Use StudioQuickWidget in content library
The event filter has to be installed on the actual QQuickWidget. Using registerPropertyMap instead of global context properties. Task-number: QDS-9124 Change-Id: I148ecc6b489f6d72d80a345aa195f74676a92d51 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -8,6 +8,7 @@ import QtQuickDesignerTheme
|
|||||||
import HelperWidgets 2.0 as HelperWidgets
|
import HelperWidgets 2.0 as HelperWidgets
|
||||||
import StudioControls 1.0 as StudioControls
|
import StudioControls 1.0 as StudioControls
|
||||||
import StudioTheme 1.0 as StudioTheme
|
import StudioTheme 1.0 as StudioTheme
|
||||||
|
import ContentLibraryBackend
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
@@ -50,16 +51,16 @@ Item {
|
|||||||
style: StudioTheme.Values.searchControlStyle
|
style: StudioTheme.Values.searchControlStyle
|
||||||
enabled: {
|
enabled: {
|
||||||
if (tabBar.currIndex === 0) { // Materials tab
|
if (tabBar.currIndex === 0) { // Materials tab
|
||||||
materialsModel.matBundleExists
|
ContentLibraryBackend.materialsModel.matBundleExists
|
||||||
&& rootView.hasMaterialLibrary
|
&& ContentLibraryBackend.rootView.hasMaterialLibrary
|
||||||
&& materialsModel.hasRequiredQuick3DImport
|
&& ContentLibraryBackend.materialsModel.hasRequiredQuick3DImport
|
||||||
} else { // Textures / Environments tabs
|
} else { // Textures / Environments tabs
|
||||||
texturesModel.texBundleExists
|
texturesModel.texBundleExists
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearchChanged: (searchText) => {
|
onSearchChanged: (searchText) => {
|
||||||
rootView.handleSearchFilterChanged(searchText)
|
ContentLibraryBackend.rootView.handleSearchFilterChanged(searchText)
|
||||||
|
|
||||||
// make sure categories with matches are expanded
|
// make sure categories with matches are expanded
|
||||||
materialsView.expandVisibleSections()
|
materialsView.expandVisibleSections()
|
||||||
|
@@ -8,6 +8,7 @@ import HelperWidgets 2.0
|
|||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
|
|
||||||
import StudioTheme 1.0 as StudioTheme
|
import StudioTheme 1.0 as StudioTheme
|
||||||
|
import ContentLibraryBackend
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
@@ -25,7 +26,7 @@ Item {
|
|||||||
|
|
||||||
onPressed: (mouse) => {
|
onPressed: (mouse) => {
|
||||||
if (mouse.button === Qt.LeftButton && !materialsModel.importerRunning)
|
if (mouse.button === Qt.LeftButton && !materialsModel.importerRunning)
|
||||||
rootView.startDragMaterial(modelData, mapToGlobal(mouse.x, mouse.y))
|
ContentLibraryBackend.rootView.startDragMaterial(modelData, mapToGlobal(mouse.x, mouse.y))
|
||||||
else if (mouse.button === Qt.RightButton)
|
else if (mouse.button === Qt.RightButton)
|
||||||
root.showContextMenu()
|
root.showContextMenu()
|
||||||
}
|
}
|
||||||
@@ -81,11 +82,11 @@ Item {
|
|||||||
pressColor: Qt.hsla(c.hslHue, c.hslSaturation, c.hslLightness, .4)
|
pressColor: Qt.hsla(c.hslHue, c.hslSaturation, c.hslLightness, .4)
|
||||||
anchors.right: img.right
|
anchors.right: img.right
|
||||||
anchors.bottom: img.bottom
|
anchors.bottom: img.bottom
|
||||||
enabled: !materialsModel.importerRunning
|
enabled: !ContentLibraryBackend.materialsModel.importerRunning
|
||||||
visible: containsMouse || mouseArea.containsMouse
|
visible: containsMouse || mouseArea.containsMouse
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
materialsModel.addToProject(modelData)
|
ContentLibraryBackend.materialsModel.addToProject(modelData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,18 +5,20 @@ import QtQuick
|
|||||||
import HelperWidgets as HelperWidgets
|
import HelperWidgets as HelperWidgets
|
||||||
import StudioControls as StudioControls
|
import StudioControls as StudioControls
|
||||||
import StudioTheme as StudioTheme
|
import StudioTheme as StudioTheme
|
||||||
|
import ContentLibraryBackend
|
||||||
|
|
||||||
HelperWidgets.ScrollView {
|
HelperWidgets.ScrollView {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
clip: true
|
clip: true
|
||||||
interactive: !ctxMenu.opened && !rootView.isDragging
|
interactive: !ctxMenu.opened && !ContentLibraryBackend.rootView.isDragging
|
||||||
|
|
||||||
readonly property int cellWidth: 100
|
readonly property int cellWidth: 100
|
||||||
readonly property int cellHeight: 120
|
readonly property int cellHeight: 120
|
||||||
|
|
||||||
property var currMaterialItem: null
|
property var currMaterialItem: null
|
||||||
property var rootItem: null
|
property var rootItem: null
|
||||||
|
property var materialsModel: ContentLibraryBackend.materialsModel
|
||||||
|
|
||||||
required property var searchBox
|
required property var searchBox
|
||||||
|
|
||||||
@@ -94,11 +96,11 @@ HelperWidgets.ScrollView {
|
|||||||
text: {
|
text: {
|
||||||
if (!materialsModel.matBundleExists)
|
if (!materialsModel.matBundleExists)
|
||||||
qsTr("<b>Content Library</b> materials are not installed.")
|
qsTr("<b>Content Library</b> materials are not installed.")
|
||||||
else if (!rootView.hasQuick3DImport)
|
else if (!ContentLibraryBackend.rootView.hasQuick3DImport)
|
||||||
qsTr("To use <b>Content Library</b>, first add the QtQuick3D module in the <b>Components</b> view.")
|
qsTr("To use <b>Content Library</b>, first add the QtQuick3D module in the <b>Components</b> view.")
|
||||||
else if (!materialsModel.hasRequiredQuick3DImport)
|
else if (!materialsModel.hasRequiredQuick3DImport)
|
||||||
qsTr("To use <b>Content Library</b>, version 6.3 or later of the QtQuick3D module is required.")
|
qsTr("To use <b>Content Library</b>, version 6.3 or later of the QtQuick3D module is required.")
|
||||||
else if (!rootView.hasMaterialLibrary)
|
else if (!ContentLibraryBackend.rootView.hasMaterialLibrary)
|
||||||
qsTr("<b>Content Library</b> is disabled inside a non-visual component.")
|
qsTr("<b>Content Library</b> is disabled inside a non-visual component.")
|
||||||
else if (!searchBox.isEmpty())
|
else if (!searchBox.isEmpty())
|
||||||
qsTr("No match found.")
|
qsTr("No match found.")
|
||||||
|
@@ -10,6 +10,7 @@ import QtQuick.Controls
|
|||||||
import StudioTheme 1.0 as StudioTheme
|
import StudioTheme 1.0 as StudioTheme
|
||||||
|
|
||||||
import WebFetcher 1.0
|
import WebFetcher 1.0
|
||||||
|
import ContentLibraryBackend
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
@@ -161,7 +162,7 @@ Item {
|
|||||||
onPressed: (mouse) => {
|
onPressed: (mouse) => {
|
||||||
if (mouse.button === Qt.LeftButton) {
|
if (mouse.button === Qt.LeftButton) {
|
||||||
if (root.downloadState === "downloaded")
|
if (root.downloadState === "downloaded")
|
||||||
rootView.startDragTexture(modelData, mapToGlobal(mouse.x, mouse.y))
|
ContentLibraryBackend.rootView.startDragTexture(modelData, mapToGlobal(mouse.x, mouse.y))
|
||||||
} else if (mouse.button === Qt.RightButton && root.downloadState === "downloaded") {
|
} else if (mouse.button === Qt.RightButton && root.downloadState === "downloaded") {
|
||||||
root.showContextMenu()
|
root.showContextMenu()
|
||||||
}
|
}
|
||||||
@@ -174,7 +175,7 @@ Item {
|
|||||||
if (root.downloadState !== "" && root.downloadState !== "failed")
|
if (root.downloadState !== "" && root.downloadState !== "failed")
|
||||||
return
|
return
|
||||||
|
|
||||||
if (!rootView.markTextureDownloading())
|
if (!ContentLibraryBackend.rootView.markTextureDownloading())
|
||||||
return
|
return
|
||||||
|
|
||||||
progressBar.visible = true
|
progressBar.visible = true
|
||||||
@@ -216,7 +217,7 @@ Item {
|
|||||||
root.downloadStateChanged()
|
root.downloadStateChanged()
|
||||||
mouseArea.enabled = true
|
mouseArea.enabled = true
|
||||||
|
|
||||||
rootView.markNoTextureDownloading()
|
ContentLibraryBackend.rootView.markNoTextureDownloading()
|
||||||
}
|
}
|
||||||
|
|
||||||
onDownloadFailed: {
|
onDownloadFailed: {
|
||||||
@@ -224,7 +225,7 @@ Item {
|
|||||||
root.downloadStateChanged()
|
root.downloadStateChanged()
|
||||||
mouseArea.enabled = true
|
mouseArea.enabled = true
|
||||||
|
|
||||||
rootView.markNoTextureDownloading()
|
ContentLibraryBackend.rootView.markNoTextureDownloading()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,7 +242,7 @@ Item {
|
|||||||
root.downloadState = modelData.isDownloaded() ? "downloaded" : "failed"
|
root.downloadState = modelData.isDownloaded() ? "downloaded" : "failed"
|
||||||
root.downloadStateChanged()
|
root.downloadStateChanged()
|
||||||
|
|
||||||
rootView.markNoTextureDownloading()
|
ContentLibraryBackend.rootView.markNoTextureDownloading()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ import QtQuick 2.15
|
|||||||
import HelperWidgets 2.0
|
import HelperWidgets 2.0
|
||||||
import StudioControls 1.0 as StudioControls
|
import StudioControls 1.0 as StudioControls
|
||||||
import StudioTheme 1.0 as StudioTheme
|
import StudioTheme 1.0 as StudioTheme
|
||||||
|
import ContentLibraryBackend
|
||||||
|
|
||||||
StudioControls.Menu {
|
StudioControls.Menu {
|
||||||
id: root
|
id: root
|
||||||
@@ -12,12 +13,12 @@ StudioControls.Menu {
|
|||||||
property var targetTexture: null
|
property var targetTexture: null
|
||||||
property bool hasSceneEnv: false
|
property bool hasSceneEnv: false
|
||||||
|
|
||||||
property bool canUse3D: targetTexture && rootView.hasQuick3DImport && rootView.hasMaterialLibrary
|
property bool canUse3D: targetTexture && ContentLibraryBackend.rootView.hasQuick3DImport && ContentLibraryBackend.rootView.hasMaterialLibrary
|
||||||
|
|
||||||
function popupMenu(targetTexture = null)
|
function popupMenu(targetTexture = null)
|
||||||
{
|
{
|
||||||
this.targetTexture = targetTexture
|
this.targetTexture = targetTexture
|
||||||
rootView.updateSceneEnvState();
|
ContentLibraryBackend.rootView.updateSceneEnvState();
|
||||||
popup()
|
popup()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,18 +27,18 @@ StudioControls.Menu {
|
|||||||
StudioControls.MenuItem {
|
StudioControls.MenuItem {
|
||||||
text: qsTr("Add image")
|
text: qsTr("Add image")
|
||||||
enabled: root.targetTexture
|
enabled: root.targetTexture
|
||||||
onTriggered: rootView.addImage(root.targetTexture)
|
onTriggered: ContentLibraryBackend.rootView.addImage(root.targetTexture)
|
||||||
}
|
}
|
||||||
|
|
||||||
StudioControls.MenuItem {
|
StudioControls.MenuItem {
|
||||||
text: qsTr("Add texture")
|
text: qsTr("Add texture")
|
||||||
enabled: canUse3D
|
enabled: canUse3D
|
||||||
onTriggered: rootView.addTexture(root.targetTexture)
|
onTriggered: ContentLibraryBackend.rootView.addTexture(root.targetTexture)
|
||||||
}
|
}
|
||||||
|
|
||||||
StudioControls.MenuItem {
|
StudioControls.MenuItem {
|
||||||
text: qsTr("Add light probe")
|
text: qsTr("Add light probe")
|
||||||
enabled: root.hasSceneEnv && canUse3D
|
enabled: root.hasSceneEnv && canUse3D
|
||||||
onTriggered: rootView.addLightProbe(root.targetTexture)
|
onTriggered: ContentLibraryBackend.rootView.addLightProbe(root.targetTexture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,12 +5,13 @@ import QtQuick
|
|||||||
import HelperWidgets as HelperWidgets
|
import HelperWidgets as HelperWidgets
|
||||||
import StudioControls as StudioControls
|
import StudioControls as StudioControls
|
||||||
import StudioTheme as StudioTheme
|
import StudioTheme as StudioTheme
|
||||||
|
import ContentLibraryBackend
|
||||||
|
|
||||||
HelperWidgets.ScrollView {
|
HelperWidgets.ScrollView {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
clip: true
|
clip: true
|
||||||
interactive: !ctxMenu.opened && !rootView.isDragging
|
interactive: !ctxMenu.opened && !ContentLibraryBackend.rootView.isDragging
|
||||||
|
|
||||||
readonly property int cellWidth: 100
|
readonly property int cellWidth: 100
|
||||||
readonly property int cellHeight: 100
|
readonly property int cellHeight: 100
|
||||||
|
@@ -8,6 +8,7 @@ import QtQuickDesignerTheme
|
|||||||
import HelperWidgets
|
import HelperWidgets
|
||||||
import StudioControls as StudioControls
|
import StudioControls as StudioControls
|
||||||
import StudioTheme as StudioTheme
|
import StudioTheme as StudioTheme
|
||||||
|
import ContentLibraryBackend
|
||||||
|
|
||||||
Dialog {
|
Dialog {
|
||||||
id: root
|
id: root
|
||||||
@@ -47,7 +48,7 @@ Dialog {
|
|||||||
text: qsTr("Remove")
|
text: qsTr("Remove")
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
materialsModel.removeFromProject(root.targetBundleMaterial)
|
ContentLibraryBackend.materialsModel.removeFromProject(root.targetBundleMaterial)
|
||||||
root.accept()
|
root.accept()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
#include <qmldesignerconstants.h>
|
#include <qmldesignerconstants.h>
|
||||||
#include <qmldesignerplugin.h>
|
#include <qmldesignerplugin.h>
|
||||||
|
|
||||||
|
#include <studioquickwidget.h>
|
||||||
#include <theme.h>
|
#include <theme.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
@@ -91,7 +92,7 @@ bool ContentLibraryWidget::eventFilter(QObject *obj, QEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ContentLibraryWidget::ContentLibraryWidget()
|
ContentLibraryWidget::ContentLibraryWidget()
|
||||||
: m_quickWidget(new QQuickWidget(this))
|
: m_quickWidget(new StudioQuickWidget(this))
|
||||||
, m_materialsModel(new ContentLibraryMaterialsModel(this))
|
, m_materialsModel(new ContentLibraryMaterialsModel(this))
|
||||||
, m_texturesModel(new ContentLibraryTexturesModel("Textures", this))
|
, m_texturesModel(new ContentLibraryTexturesModel("Textures", this))
|
||||||
, m_environmentsModel(new ContentLibraryTexturesModel("Environments", this))
|
, m_environmentsModel(new ContentLibraryTexturesModel("Environments", this))
|
||||||
@@ -119,15 +120,8 @@ ContentLibraryWidget::ContentLibraryWidget()
|
|||||||
m_environmentsModel->loadTextureBundle(textureBundlePath + "/Environments",
|
m_environmentsModel->loadTextureBundle(textureBundlePath + "/Environments",
|
||||||
baseUrl + "/Environments", metaData);
|
baseUrl + "/Environments", metaData);
|
||||||
|
|
||||||
m_quickWidget->rootContext()->setContextProperties({
|
|
||||||
{"rootView", QVariant::fromValue(this)},
|
|
||||||
{"materialsModel", QVariant::fromValue(m_materialsModel.data())},
|
|
||||||
{"texturesModel", QVariant::fromValue(m_texturesModel.data())},
|
|
||||||
{"environmentsModel", QVariant::fromValue(m_environmentsModel.data())},
|
|
||||||
});
|
|
||||||
|
|
||||||
Theme::setupTheme(m_quickWidget->engine());
|
Theme::setupTheme(m_quickWidget->engine());
|
||||||
m_quickWidget->installEventFilter(this);
|
m_quickWidget->quickWidget()->installEventFilter(this);
|
||||||
|
|
||||||
auto layout = new QVBoxLayout(this);
|
auto layout = new QVBoxLayout(this);
|
||||||
layout->setContentsMargins({});
|
layout->setContentsMargins({});
|
||||||
@@ -144,6 +138,13 @@ ContentLibraryWidget::ContentLibraryWidget()
|
|||||||
|
|
||||||
QmlDesignerPlugin::trackWidgetFocusTime(this, Constants::EVENT_CONTENTLIBRARY_TIME);
|
QmlDesignerPlugin::trackWidgetFocusTime(this, Constants::EVENT_CONTENTLIBRARY_TIME);
|
||||||
|
|
||||||
|
auto map = m_quickWidget->registerPropertyMap("ContentLibraryBackend");
|
||||||
|
|
||||||
|
map->setProperties({{"rootView", QVariant::fromValue(this)},
|
||||||
|
{"materialsModel", QVariant::fromValue(m_materialsModel.data())},
|
||||||
|
{"texturesModel", QVariant::fromValue(m_texturesModel.data())},
|
||||||
|
{"environmentsModel", QVariant::fromValue(m_environmentsModel.data())}});
|
||||||
|
|
||||||
reloadQmlSource();
|
reloadQmlSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +219,6 @@ void ContentLibraryWidget::reloadQmlSource()
|
|||||||
|
|
||||||
QTC_ASSERT(QFileInfo::exists(materialBrowserQmlPath), return);
|
QTC_ASSERT(QFileInfo::exists(materialBrowserQmlPath), return);
|
||||||
|
|
||||||
m_quickWidget->engine()->clearComponentCache();
|
|
||||||
m_quickWidget->setSource(QUrl::fromLocalFile(materialBrowserQmlPath));
|
m_quickWidget->setSource(QUrl::fromLocalFile(materialBrowserQmlPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,9 +11,10 @@
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QShortcut;
|
class QShortcut;
|
||||||
class QToolButton;
|
class QToolButton;
|
||||||
class QQuickWidget;
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class StudioQuickWidget;
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
class ContentLibraryTexture;
|
class ContentLibraryTexture;
|
||||||
@@ -80,7 +81,7 @@ private:
|
|||||||
void setIsDragging(bool val);
|
void setIsDragging(bool val);
|
||||||
QString findTextureBundlePath();
|
QString findTextureBundlePath();
|
||||||
|
|
||||||
QScopedPointer<QQuickWidget> m_quickWidget;
|
QScopedPointer<StudioQuickWidget> m_quickWidget;
|
||||||
QPointer<ContentLibraryMaterialsModel> m_materialsModel;
|
QPointer<ContentLibraryMaterialsModel> m_materialsModel;
|
||||||
QPointer<ContentLibraryTexturesModel> m_texturesModel;
|
QPointer<ContentLibraryTexturesModel> m_texturesModel;
|
||||||
QPointer<ContentLibraryTexturesModel> m_environmentsModel;
|
QPointer<ContentLibraryTexturesModel> m_environmentsModel;
|
||||||
|
Reference in New Issue
Block a user