forked from qt-creator/qt-creator
QmlDesigner: Update assets context menu based on scene env state
Also remove signals emitted from the assets widget to the view since the widget now has a reference to the view. Fixes: QDS-9467 Change-Id: I80a2aef4c35aeeb344cc71c890664e1645d4334a Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -31,7 +31,7 @@ StudioControls.Menu {
|
||||
{
|
||||
root.__showInGraphicalShellEnabled = true
|
||||
|
||||
rootView.updateHasMaterialLibrary()
|
||||
rootView.updateContextMenuActionsEnableState()
|
||||
|
||||
root.__onFolderCreated = onFolderCreated
|
||||
root.__fileIndex = ""
|
||||
@@ -46,7 +46,7 @@ StudioControls.Menu {
|
||||
{
|
||||
root.__showInGraphicalShellEnabled = true
|
||||
|
||||
rootView.updateHasMaterialLibrary()
|
||||
rootView.updateContextMenuActionsEnableState()
|
||||
|
||||
root.__onFolderCreated = onFolderCreated
|
||||
root.__dirPath = dirPath
|
||||
@@ -77,7 +77,7 @@ StudioControls.Menu {
|
||||
addTexturesItem.text = qsTr("Add Texture")
|
||||
}
|
||||
|
||||
rootView.updateHasMaterialLibrary()
|
||||
rootView.updateContextMenuActionsEnableState()
|
||||
|
||||
root.__onFolderCreated = onFolderCreated
|
||||
root.__selectedAssetPathsList = selectedAssetPathsList
|
||||
@@ -132,7 +132,7 @@ StudioControls.Menu {
|
||||
StudioControls.MenuItem {
|
||||
id: addLightProbes
|
||||
text: qsTr("Add Light Probe")
|
||||
enabled: rootView.hasMaterialLibrary
|
||||
enabled: rootView.hasMaterialLibrary && rootView.hasSceneEnv
|
||||
visible: root.__fileIndex && root.__selectedAssetPathsList.length === 1
|
||||
&& AssetsLibraryBackend.assetsModel.allFilePathsAreTextures(root.__selectedAssetPathsList)
|
||||
height: addLightProbes.visible ? addLightProbes.implicitHeight : 0
|
||||
|
@@ -4,7 +4,6 @@
|
||||
#include "assetslibraryview.h"
|
||||
|
||||
#include "assetslibrarywidget.h"
|
||||
#include "createtexture.h"
|
||||
#include "designmodecontext.h"
|
||||
#include "qmldesignerplugin.h"
|
||||
|
||||
@@ -47,7 +46,6 @@ public:
|
||||
|
||||
AssetsLibraryView::AssetsLibraryView(ExternalDependenciesInterface &externalDependencies)
|
||||
: AbstractView{externalDependencies}
|
||||
, m_createTextures{this}
|
||||
{}
|
||||
|
||||
AssetsLibraryView::~AssetsLibraryView()
|
||||
@@ -67,23 +65,6 @@ WidgetInfo AssetsLibraryView::widgetInfo()
|
||||
|
||||
auto context = new Internal::AssetsLibraryContext(m_widget.data());
|
||||
Core::ICore::addContextObject(context);
|
||||
|
||||
connect(m_widget, &AssetsLibraryWidget::addTexturesRequested, this,
|
||||
[&] (const QStringList &filePaths, AddTextureMode mode) {
|
||||
executeInTransaction("AssetsLibraryView::widgetInfo", [&]() {
|
||||
m_createTextures.execute(filePaths, mode, m_sceneId);
|
||||
});
|
||||
});
|
||||
|
||||
connect(m_widget, &AssetsLibraryWidget::hasMaterialLibraryUpdateRequested, this, [&]() {
|
||||
m_widget->setHasMaterialLibrary(model() && materialLibraryNode().isValid()
|
||||
&& model()->hasImport("QtQuick3D"));
|
||||
});
|
||||
|
||||
connect(m_widget, &AssetsLibraryWidget::endDrag, this, [&]() {
|
||||
if (model())
|
||||
model()->endDrag();
|
||||
});
|
||||
}
|
||||
|
||||
return createWidgetInfo(m_widget.data(), "Assets", WidgetInfo::LeftPane, 0, tr("Assets"));
|
||||
@@ -103,18 +84,13 @@ void AssetsLibraryView::modelAttached(Model *model)
|
||||
AbstractView::modelAttached(model);
|
||||
|
||||
m_widget->clearSearchFilter();
|
||||
m_widget->setModel(model);
|
||||
|
||||
setResourcePath(DocumentManager::currentResourcePath().toFileInfo().absoluteFilePath());
|
||||
|
||||
m_sceneId = model->active3DSceneId();
|
||||
}
|
||||
|
||||
void AssetsLibraryView::modelAboutToBeDetached(Model *model)
|
||||
{
|
||||
AbstractView::modelAboutToBeDetached(model);
|
||||
|
||||
m_widget->setModel(nullptr);
|
||||
}
|
||||
|
||||
void AssetsLibraryView::setResourcePath(const QString &resourcePath)
|
||||
@@ -141,9 +117,4 @@ AssetsLibraryView::ImageCacheData *AssetsLibraryView::imageCacheData()
|
||||
return m_imageCacheData.get();
|
||||
}
|
||||
|
||||
void AssetsLibraryView::active3DSceneChanged(qint32 sceneId)
|
||||
{
|
||||
m_sceneId = sceneId;
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
@@ -4,7 +4,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "abstractview.h"
|
||||
#include "createtexture.h"
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
@@ -31,7 +30,6 @@ public:
|
||||
void modelAboutToBeDetached(Model *model) override;
|
||||
|
||||
void setResourcePath(const QString &resourcePath);
|
||||
void active3DSceneChanged(qint32 sceneId) override;
|
||||
|
||||
private:
|
||||
class ImageCacheData;
|
||||
@@ -44,8 +42,6 @@ private:
|
||||
std::unique_ptr<ImageCacheData> m_imageCacheData;
|
||||
QPointer<AssetsLibraryWidget> m_widget;
|
||||
QString m_lastResourcePath;
|
||||
CreateTextures m_createTextures;
|
||||
qint32 m_sceneId = -1;
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -6,9 +6,8 @@
|
||||
#include "asset.h"
|
||||
#include "assetslibraryiconprovider.h"
|
||||
#include "assetslibrarymodel.h"
|
||||
#include "designeractionmanager.h"
|
||||
#include "assetslibraryview.h"
|
||||
|
||||
#include "designeractionmanager.h"
|
||||
#include "modelnodeoperations.h"
|
||||
#include "qmldesignerconstants.h"
|
||||
#include "qmldesignerplugin.h"
|
||||
@@ -58,7 +57,7 @@ bool AssetsLibraryWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
if (obj == m_assetsWidget->quickWidget())
|
||||
QMetaObject::invokeMethod(m_assetsWidget->rootObject(), "handleViewFocusOut");
|
||||
} else if (event->type() == QMouseEvent::MouseMove) {
|
||||
if (!m_assetsToDrag.isEmpty() && !m_model.isNull()) {
|
||||
if (!m_assetsToDrag.isEmpty() && m_assetsView->model()) {
|
||||
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
||||
if ((me->globalPos() - m_dragStartPoint).manhattanLength() > 10) {
|
||||
QMimeData *mimeData = new QMimeData;
|
||||
@@ -70,8 +69,8 @@ bool AssetsLibraryWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
|
||||
mimeData->setUrls(urlsToDrag);
|
||||
|
||||
m_model->startDrag(mimeData, m_assetsIconProvider->requestPixmap(m_assetsToDrag[0],
|
||||
nullptr, {128, 128}));
|
||||
m_assetsView->model()->startDrag(mimeData, m_assetsIconProvider->requestPixmap(
|
||||
m_assetsToDrag[0], nullptr, {128, 128}));
|
||||
|
||||
m_assetsToDrag.clear();
|
||||
}
|
||||
@@ -92,6 +91,7 @@ AssetsLibraryWidget::AssetsLibraryWidget(AsynchronousImageCache &asynchronousFon
|
||||
, m_assetsIconProvider{new AssetsLibraryIconProvider(synchronousFontImageCache)}
|
||||
, m_assetsModel{new AssetsLibraryModel(this)}
|
||||
, m_assetsView{view}
|
||||
, m_createTextures{view}
|
||||
, m_assetsWidget{new StudioQuickWidget(this)}
|
||||
{
|
||||
setWindowTitle(tr("Assets Library", "Title of assets library widget"));
|
||||
@@ -225,22 +225,27 @@ int AssetsLibraryWidget::qtVersion() const
|
||||
|
||||
void AssetsLibraryWidget::addTextures(const QStringList &filePaths)
|
||||
{
|
||||
emit addTexturesRequested(filePaths, AddTextureMode::Texture);
|
||||
m_assetsView->executeInTransaction(__FUNCTION__, [&] {
|
||||
m_createTextures.execute(filePaths, AddTextureMode::Texture,
|
||||
m_assetsView->model()->active3DSceneId());
|
||||
});
|
||||
}
|
||||
|
||||
void AssetsLibraryWidget::addLightProbe(const QString &filePath)
|
||||
{
|
||||
emit addTexturesRequested({filePath}, AddTextureMode::LightProbe);
|
||||
m_assetsView->executeInTransaction(__FUNCTION__, [&] {
|
||||
m_createTextures.execute({filePath}, AddTextureMode::LightProbe,
|
||||
m_assetsView->model()->active3DSceneId());
|
||||
});
|
||||
}
|
||||
|
||||
void AssetsLibraryWidget::updateHasMaterialLibrary()
|
||||
void AssetsLibraryWidget::updateContextMenuActionsEnableState()
|
||||
{
|
||||
emit hasMaterialLibraryUpdateRequested();
|
||||
}
|
||||
setHasMaterialLibrary(m_assetsView->materialLibraryNode().isValid()
|
||||
&& m_assetsView->model()->hasImport("QtQuick3D"));
|
||||
|
||||
bool AssetsLibraryWidget::hasMaterialLibrary() const
|
||||
{
|
||||
return m_hasMaterialLibrary;
|
||||
ModelNode activeSceneEnv = m_createTextures.resolveSceneEnv(m_assetsView->model()->active3DSceneId());
|
||||
setHasSceneEnv(activeSceneEnv.isValid());
|
||||
}
|
||||
|
||||
void AssetsLibraryWidget::setHasMaterialLibrary(bool enable)
|
||||
@@ -252,6 +257,15 @@ void AssetsLibraryWidget::setHasMaterialLibrary(bool enable)
|
||||
emit hasMaterialLibraryChanged();
|
||||
}
|
||||
|
||||
void AssetsLibraryWidget::setHasSceneEnv(bool b)
|
||||
{
|
||||
if (b == m_hasSceneEnv)
|
||||
return;
|
||||
|
||||
m_hasSceneEnv = b;
|
||||
emit hasSceneEnvChanged();
|
||||
}
|
||||
|
||||
void AssetsLibraryWidget::invalidateThumbnail(const QString &id)
|
||||
{
|
||||
m_assetsIconProvider->invalidateThumbnail(id);
|
||||
@@ -331,7 +345,7 @@ void AssetsLibraryWidget::handleExtFilesDrop(const QList<QUrl> &simpleFilePaths,
|
||||
if (!complexFilePathStrings.empty())
|
||||
addResources(complexFilePathStrings);
|
||||
|
||||
emit endDrag();
|
||||
m_assetsView->model()->endDrag();
|
||||
}
|
||||
|
||||
QSet<QString> AssetsLibraryWidget::supportedAssetSuffixes(bool complex)
|
||||
@@ -353,11 +367,6 @@ void AssetsLibraryWidget::openEffectMaker(const QString &filePath)
|
||||
ModelNodeOperations::openEffectMaker(filePath);
|
||||
}
|
||||
|
||||
void AssetsLibraryWidget::setModel(Model *model)
|
||||
{
|
||||
m_model = model;
|
||||
}
|
||||
|
||||
QString AssetsLibraryWidget::qmlSourcesPath()
|
||||
{
|
||||
#ifdef SHARE_QML_PATH
|
||||
|
@@ -3,10 +3,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <previewtooltip/previewtooltipbackend.h>
|
||||
|
||||
#include "createtexture.h"
|
||||
#include "previewtooltipbackend.h"
|
||||
|
||||
#include <coreplugin/icontext.h>
|
||||
|
||||
#include <QFrame>
|
||||
#include <QQmlPropertyMap>
|
||||
@@ -42,7 +42,8 @@ class AssetsLibraryWidget : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(bool hasMaterialLibrary READ hasMaterialLibrary NOTIFY hasMaterialLibraryChanged)
|
||||
Q_PROPERTY(bool hasMaterialLibrary MEMBER m_hasMaterialLibrary NOTIFY hasMaterialLibraryChanged)
|
||||
Q_PROPERTY(bool hasSceneEnv MEMBER m_hasSceneEnv NOTIFY hasSceneEnvChanged)
|
||||
|
||||
// Needed for a workaround for a bug where after drag-n-dropping an item, the ScrollView scrolls to a random position
|
||||
Q_PROPERTY(bool isDragging MEMBER m_isDragging NOTIFY isDraggingChanged)
|
||||
@@ -62,12 +63,8 @@ public:
|
||||
void updateModel();
|
||||
|
||||
void setResourcePath(const QString &resourcePath);
|
||||
void setModel(Model *model);
|
||||
static QPair<QString, QByteArray> getAssetTypeAndData(const QString &assetPath);
|
||||
|
||||
bool hasMaterialLibrary() const;
|
||||
void setHasMaterialLibrary(bool enable);
|
||||
|
||||
void deleteSelectedAssets();
|
||||
|
||||
Q_INVOKABLE void startDragAsset(const QStringList &assetPaths, const QPointF &mousePos);
|
||||
@@ -92,7 +89,7 @@ public:
|
||||
|
||||
Q_INVOKABLE void addTextures(const QStringList &filePaths);
|
||||
Q_INVOKABLE void addLightProbe(const QString &filePaths);
|
||||
Q_INVOKABLE void updateHasMaterialLibrary();
|
||||
Q_INVOKABLE void updateContextMenuActionsEnableState();
|
||||
|
||||
Q_INVOKABLE QString getUniqueEffectPath(const QString &parentFolder, const QString &effectName);
|
||||
Q_INVOKABLE bool createNewEffect(const QString &effectPath, bool openEffectMaker = true);
|
||||
@@ -108,9 +105,8 @@ signals:
|
||||
const QList<QUrl> &complexFilePaths,
|
||||
const QString &targetDirPath);
|
||||
void directoryCreated(const QString &path);
|
||||
void addTexturesRequested(const QStringList &filePaths, QmlDesigner::AddTextureMode mode);
|
||||
void hasMaterialLibraryUpdateRequested();
|
||||
void hasMaterialLibraryChanged();
|
||||
void hasSceneEnvChanged();
|
||||
void isDraggingChanged();
|
||||
void endDrag();
|
||||
void deleteSelectedAssetsRequested();
|
||||
@@ -125,6 +121,9 @@ private:
|
||||
void updateSearch();
|
||||
void setIsDragging(bool val);
|
||||
|
||||
void setHasMaterialLibrary(bool enable);
|
||||
void setHasSceneEnv(bool b);
|
||||
|
||||
QSize m_itemIconSize;
|
||||
|
||||
SynchronousImageCache &m_fontImageCache;
|
||||
@@ -132,17 +131,18 @@ private:
|
||||
AssetsLibraryIconProvider *m_assetsIconProvider = nullptr;
|
||||
AssetsLibraryModel *m_assetsModel = nullptr;
|
||||
AssetsLibraryView *m_assetsView = nullptr;
|
||||
CreateTextures m_createTextures = nullptr;
|
||||
|
||||
QScopedPointer<StudioQuickWidget> m_assetsWidget;
|
||||
std::unique_ptr<PreviewTooltipBackend> m_fontPreviewTooltipBackend;
|
||||
|
||||
QShortcut *m_qmlSourceUpdateShortcut = nullptr;
|
||||
QPointer<Model> m_model;
|
||||
QStringList m_assetsToDrag;
|
||||
bool m_updateRetry = false;
|
||||
QString m_filterText;
|
||||
QPoint m_dragStartPoint;
|
||||
bool m_hasMaterialLibrary = false;
|
||||
bool m_hasSceneEnv = false;
|
||||
bool m_isDragging = false;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user