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:
Thomas Hartmann
2023-03-02 13:21:40 +01:00
parent 269738d7e5
commit fb685307f9
9 changed files with 43 additions and 34 deletions

View File

@@ -8,6 +8,7 @@ import QtQuickDesignerTheme
import HelperWidgets 2.0 as HelperWidgets
import StudioControls 1.0 as StudioControls
import StudioTheme 1.0 as StudioTheme
import ContentLibraryBackend
Item {
id: root
@@ -50,16 +51,16 @@ Item {
style: StudioTheme.Values.searchControlStyle
enabled: {
if (tabBar.currIndex === 0) { // Materials tab
materialsModel.matBundleExists
&& rootView.hasMaterialLibrary
&& materialsModel.hasRequiredQuick3DImport
ContentLibraryBackend.materialsModel.matBundleExists
&& ContentLibraryBackend.rootView.hasMaterialLibrary
&& ContentLibraryBackend.materialsModel.hasRequiredQuick3DImport
} else { // Textures / Environments tabs
texturesModel.texBundleExists
}
}
onSearchChanged: (searchText) => {
rootView.handleSearchFilterChanged(searchText)
ContentLibraryBackend.rootView.handleSearchFilterChanged(searchText)
// make sure categories with matches are expanded
materialsView.expandVisibleSections()

View File

@@ -8,6 +8,7 @@ import HelperWidgets 2.0
import QtQuick.Controls
import StudioTheme 1.0 as StudioTheme
import ContentLibraryBackend
Item {
id: root
@@ -25,7 +26,7 @@ Item {
onPressed: (mouse) => {
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)
root.showContextMenu()
}
@@ -81,11 +82,11 @@ Item {
pressColor: Qt.hsla(c.hslHue, c.hslSaturation, c.hslLightness, .4)
anchors.right: img.right
anchors.bottom: img.bottom
enabled: !materialsModel.importerRunning
enabled: !ContentLibraryBackend.materialsModel.importerRunning
visible: containsMouse || mouseArea.containsMouse
onClicked: {
materialsModel.addToProject(modelData)
ContentLibraryBackend.materialsModel.addToProject(modelData)
}
}
}

View File

@@ -5,18 +5,20 @@ 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 && !rootView.isDragging
interactive: !ctxMenu.opened && !ContentLibraryBackend.rootView.isDragging
readonly property int cellWidth: 100
readonly property int cellHeight: 120
property var currMaterialItem: null
property var rootItem: null
property var materialsModel: ContentLibraryBackend.materialsModel
required property var searchBox
@@ -94,11 +96,11 @@ HelperWidgets.ScrollView {
text: {
if (!materialsModel.matBundleExists)
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.")
else if (!materialsModel.hasRequiredQuick3DImport)
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.")
else if (!searchBox.isEmpty())
qsTr("No match found.")

View File

@@ -10,6 +10,7 @@ import QtQuick.Controls
import StudioTheme 1.0 as StudioTheme
import WebFetcher 1.0
import ContentLibraryBackend
Item {
id: root
@@ -161,7 +162,7 @@ Item {
onPressed: (mouse) => {
if (mouse.button === Qt.LeftButton) {
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") {
root.showContextMenu()
}
@@ -174,7 +175,7 @@ Item {
if (root.downloadState !== "" && root.downloadState !== "failed")
return
if (!rootView.markTextureDownloading())
if (!ContentLibraryBackend.rootView.markTextureDownloading())
return
progressBar.visible = true
@@ -216,7 +217,7 @@ Item {
root.downloadStateChanged()
mouseArea.enabled = true
rootView.markNoTextureDownloading()
ContentLibraryBackend.rootView.markNoTextureDownloading()
}
onDownloadFailed: {
@@ -224,7 +225,7 @@ Item {
root.downloadStateChanged()
mouseArea.enabled = true
rootView.markNoTextureDownloading()
ContentLibraryBackend.rootView.markNoTextureDownloading()
}
}
@@ -241,7 +242,7 @@ Item {
root.downloadState = modelData.isDownloaded() ? "downloaded" : "failed"
root.downloadStateChanged()
rootView.markNoTextureDownloading()
ContentLibraryBackend.rootView.markNoTextureDownloading()
}
}
}

View File

@@ -5,6 +5,7 @@ import QtQuick 2.15
import HelperWidgets 2.0
import StudioControls 1.0 as StudioControls
import StudioTheme 1.0 as StudioTheme
import ContentLibraryBackend
StudioControls.Menu {
id: root
@@ -12,12 +13,12 @@ StudioControls.Menu {
property var targetTexture: null
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)
{
this.targetTexture = targetTexture
rootView.updateSceneEnvState();
ContentLibraryBackend.rootView.updateSceneEnvState();
popup()
}
@@ -26,18 +27,18 @@ StudioControls.Menu {
StudioControls.MenuItem {
text: qsTr("Add image")
enabled: root.targetTexture
onTriggered: rootView.addImage(root.targetTexture)
onTriggered: ContentLibraryBackend.rootView.addImage(root.targetTexture)
}
StudioControls.MenuItem {
text: qsTr("Add texture")
enabled: canUse3D
onTriggered: rootView.addTexture(root.targetTexture)
onTriggered: ContentLibraryBackend.rootView.addTexture(root.targetTexture)
}
StudioControls.MenuItem {
text: qsTr("Add light probe")
enabled: root.hasSceneEnv && canUse3D
onTriggered: rootView.addLightProbe(root.targetTexture)
onTriggered: ContentLibraryBackend.rootView.addLightProbe(root.targetTexture)
}
}

View File

@@ -5,12 +5,13 @@ 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 && !rootView.isDragging
interactive: !ctxMenu.opened && !ContentLibraryBackend.rootView.isDragging
readonly property int cellWidth: 100
readonly property int cellHeight: 100

View File

@@ -8,6 +8,7 @@ import QtQuickDesignerTheme
import HelperWidgets
import StudioControls as StudioControls
import StudioTheme as StudioTheme
import ContentLibraryBackend
Dialog {
id: root
@@ -47,7 +48,7 @@ Dialog {
text: qsTr("Remove")
onClicked: {
materialsModel.removeFromProject(root.targetBundleMaterial)
ContentLibraryBackend.materialsModel.removeFromProject(root.targetBundleMaterial)
root.accept()
}
}

View File

@@ -12,6 +12,7 @@
#include <qmldesignerconstants.h>
#include <qmldesignerplugin.h>
#include <studioquickwidget.h>
#include <theme.h>
#include <utils/algorithm.h>
@@ -91,7 +92,7 @@ bool ContentLibraryWidget::eventFilter(QObject *obj, QEvent *event)
}
ContentLibraryWidget::ContentLibraryWidget()
: m_quickWidget(new QQuickWidget(this))
: m_quickWidget(new StudioQuickWidget(this))
, m_materialsModel(new ContentLibraryMaterialsModel(this))
, m_texturesModel(new ContentLibraryTexturesModel("Textures", this))
, m_environmentsModel(new ContentLibraryTexturesModel("Environments", this))
@@ -119,15 +120,8 @@ ContentLibraryWidget::ContentLibraryWidget()
m_environmentsModel->loadTextureBundle(textureBundlePath + "/Environments",
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());
m_quickWidget->installEventFilter(this);
m_quickWidget->quickWidget()->installEventFilter(this);
auto layout = new QVBoxLayout(this);
layout->setContentsMargins({});
@@ -144,6 +138,13 @@ ContentLibraryWidget::ContentLibraryWidget()
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();
}
@@ -218,7 +219,6 @@ void ContentLibraryWidget::reloadQmlSource()
QTC_ASSERT(QFileInfo::exists(materialBrowserQmlPath), return);
m_quickWidget->engine()->clearComponentCache();
m_quickWidget->setSource(QUrl::fromLocalFile(materialBrowserQmlPath));
}

View File

@@ -11,9 +11,10 @@
QT_BEGIN_NAMESPACE
class QShortcut;
class QToolButton;
class QQuickWidget;
QT_END_NAMESPACE
class StudioQuickWidget;
namespace QmlDesigner {
class ContentLibraryTexture;
@@ -80,7 +81,7 @@ private:
void setIsDragging(bool val);
QString findTextureBundlePath();
QScopedPointer<QQuickWidget> m_quickWidget;
QScopedPointer<StudioQuickWidget> m_quickWidget;
QPointer<ContentLibraryMaterialsModel> m_materialsModel;
QPointer<ContentLibraryTexturesModel> m_texturesModel;
QPointer<ContentLibraryTexturesModel> m_environmentsModel;