From 0a56c9d676f5ff97468e96bc13b597dd6f3850f6 Mon Sep 17 00:00:00 2001 From: Shrief Gabr Date: Wed, 29 Jan 2025 16:44:48 +0200 Subject: [PATCH] QmlDesigner: Add link to add QtQuick3D from ContentLibrary Fixes: QDS-11766 Change-Id: I092cfc07fda96f73be20383f7601e50f89c7207f Reviewed-by: Miikka Heikkinen --- .../ContentLibraryEffectsView.qml | 8 +++++++- .../ContentLibraryMaterialsView.qml | 9 +++++++-- .../contentLibraryQmlSource/ContentLibraryUserView.qml | 9 +++++++-- .../components/contentlibrary/contentlibraryview.cpp | 9 +++++++++ .../components/contentlibrary/contentlibrarywidget.cpp | 5 +++++ .../components/contentlibrary/contentlibrarywidget.h | 2 ++ 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryEffectsView.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryEffectsView.qml index aa85425617d..ca8650d116a 100644 --- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryEffectsView.qml +++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryEffectsView.qml @@ -107,11 +107,14 @@ HelperWidgets.ScrollView { Text { id: infoText + text: { if (!ContentLibraryBackend.rootView.isQt6Project) qsTr("Content Library effects are not supported in Qt5 projects.") else if (!ContentLibraryBackend.rootView.hasQuick3DImport) - qsTr("To use Content Library, first add the QtQuick3D module in the Components view.") + qsTr('To use Content Library, first + add the QtQuick3D module in the Components view.') + .arg(StudioTheme.Values.themeInteraction) else if (!ContentLibraryBackend.effectsModel.hasRequiredQuick3DImport) qsTr("To use Content Library, version 6.4 or later of the QtQuick3D module is required.") else if (!ContentLibraryBackend.rootView.hasMaterialLibrary) @@ -123,11 +126,14 @@ HelperWidgets.ScrollView { else "" } + textFormat: Text.RichText color: StudioTheme.Values.themeTextColor font.pixelSize: StudioTheme.Values.baseFontSize topPadding: 10 leftPadding: 10 visible: ContentLibraryBackend.effectsModel.isEmpty + + onLinkActivated: ContentLibraryBackend.rootView.addQtQuick3D() } } } diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml index 8cfabf06d22..0ace2e7efd0 100644 --- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml +++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryMaterialsView.qml @@ -112,11 +112,14 @@ HelperWidgets.ScrollView { Text { id: infoText + text: { if (!ContentLibraryBackend.rootView.isQt6Project) qsTr("Content Library materials are not supported in Qt5 projects.") else if (!ContentLibraryBackend.rootView.hasQuick3DImport) - qsTr("To use Content Library, first add the QtQuick3D module in the Components view.") + qsTr('To use Content Library, first + add the QtQuick3D module in the Components view.') + .arg(StudioTheme.Values.themeInteraction) else if (!root.materialsModel.hasRequiredQuick3DImport) qsTr("To use Content Library, version 6.3 or later of the QtQuick3D module is required.") else if (!ContentLibraryBackend.rootView.hasMaterialLibrary) @@ -128,13 +131,15 @@ HelperWidgets.ScrollView { else "" } + textFormat: Text.RichText color: StudioTheme.Values.themeTextColor font.pixelSize: StudioTheme.Values.baseFontSize topPadding: 10 leftPadding: 10 - visible: root.materialsModel.isEmpty wrapMode: Text.WordWrap width: root.width - x + + onLinkActivated: ContentLibraryBackend.rootView.addQtQuick3D() } } } diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml index e1268072fff..287223bf3fb 100644 --- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml +++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryUserView.qml @@ -206,11 +206,13 @@ Item { text: { let categoryName = (categoryTitle === "3D") ? categoryTitle + " assets" : categoryTitle.toLowerCase() - if (!ContentLibraryBackend.rootView.isQt6Project) qsTr("Content Library is not supported in Qt5 projects.") else if (!ContentLibraryBackend.rootView.hasQuick3DImport && categoryTitle !== "Textures") - qsTr("To use " + categoryName + ", first add the QtQuick3D module in the Components view.") + qsTr(`To use %1, first + add the QtQuick3D module in the Components view.`) + .arg(categoryName) + .arg(StudioTheme.Values.themeInteraction) else if (!ContentLibraryBackend.rootView.hasMaterialLibrary && categoryTitle !== "Textures") qsTr("Content Library is disabled inside a non-visual component.") else if (categoryEmpty) @@ -218,11 +220,14 @@ Item { else "" } + textFormat: Text.RichText color: StudioTheme.Values.themeTextColor font.pixelSize: StudioTheme.Values.baseFontSize topPadding: 10 leftPadding: 10 visible: infoText.text !== "" + + onLinkActivated: ContentLibraryBackend.rootView.addQtQuick3D() } } } diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp index e6b8c962fa6..406c5c4c470 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp @@ -74,6 +74,15 @@ WidgetInfo ContentLibraryView::widgetInfo() m_bundleHelper = std::make_unique(this, m_widget); + connect(m_widget, &ContentLibraryWidget::importQtQuick3D, this, [&] { + DesignDocument *document = QmlDesignerPlugin::instance()->currentDesignDocument(); + if (document && !document->inFileComponentModelActive() && model()) { + ModelUtils::addImportWithCheck( + "QtQuick3D", + [](const Import &import) { return !import.hasVersion() || import.majorVersion() >= 6; }, + model()); + } + }); connect(m_widget, &ContentLibraryWidget::bundleMaterialDragStarted, this, [&] (QmlDesigner::ContentLibraryMaterial *mat) { m_draggedBundleMaterial = mat; diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.cpp index ca474711f28..66d6cda0467 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.cpp @@ -679,6 +679,11 @@ bool ContentLibraryWidget::areNodes3D(const QByteArray &data) const return true; } +void ContentLibraryWidget::addQtQuick3D() +{ + emit importQtQuick3D(); +} + QSize ContentLibraryWidget::sizeHint() const { return {420, 420}; diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.h index 92628adee1c..07ddd14c04c 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.h +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarywidget.h @@ -102,6 +102,7 @@ public: Q_INVOKABLE void updateSceneEnvState(); Q_INVOKABLE void markTextureUpdated(const QString &textureKey); Q_INVOKABLE bool areNodes3D(const QByteArray &data) const; + Q_INVOKABLE void addQtQuick3D(); QSize sizeHint() const override; @@ -128,6 +129,7 @@ signals: void acceptTexturesDrop(const QList &urls); void acceptMaterialDrop(const QString &internalId); void accept3DDrop(const QByteArray &internalIds); + void importQtQuick3D(); protected: bool eventFilter(QObject *obj, QEvent *event) override;