forked from qt-creator/qt-creator
QmlDesigner: Use StudioQuickWidget in material browser
The event filter has to be installed on the actual QQuickWidget. Using registerPropertyMap instead of global context properties. Task-number: QDS-9124 Change-Id: Ic4d26081bb10b4cb4c8cca7050180feb1c081664 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -67,7 +67,7 @@ Rectangle {
|
||||
|
||||
onClicked: {
|
||||
materialsListView.currentIndex = index
|
||||
rootView.updatePropsModel(id())
|
||||
MaterialBrowserBackend.rootView.updatePropsModel(id())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,7 +134,7 @@ Rectangle {
|
||||
text: qsTr("Cancel")
|
||||
|
||||
onClicked: {
|
||||
rootView.closeChooseMatPropsView()
|
||||
MaterialBrowserBackend.rootView.closeChooseMatPropsView()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ Rectangle {
|
||||
let matId = materialsListView.currentItem.id()
|
||||
let prop = propertiesListView.currentItem.propName()
|
||||
|
||||
rootView.applyTextureToProperty(matId, prop)
|
||||
MaterialBrowserBackend.rootView.applyTextureToProperty(matId, prop)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import QtQuickDesignerTheme 1.0
|
||||
import HelperWidgets 2.0 as HelperWidgets
|
||||
import StudioControls 1.0 as StudioControls
|
||||
import StudioTheme 1.0 as StudioTheme
|
||||
import MaterialBrowserBackend
|
||||
|
||||
Item {
|
||||
id: root
|
||||
@@ -17,6 +18,9 @@ Item {
|
||||
&& materialBrowserModel.hasQuick3DImport
|
||||
|
||||
property var currMaterialItem: null
|
||||
property var rootView: MaterialBrowserBackend.rootView
|
||||
property var materialBrowserModel: MaterialBrowserBackend.materialBrowserModel
|
||||
property var materialBrowserTexturesModel: MaterialBrowserBackend.materialBrowserTexturesModel
|
||||
|
||||
// Called also from C++ to close context menu on focus out
|
||||
function closeContextMenu()
|
||||
|
@@ -5,6 +5,7 @@ import QtQuick
|
||||
import HelperWidgets
|
||||
import StudioControls as StudioControls
|
||||
import StudioTheme as StudioTheme
|
||||
import MaterialBrowserBackend
|
||||
|
||||
StudioControls.Menu {
|
||||
id: root
|
||||
@@ -15,6 +16,8 @@ StudioControls.Menu {
|
||||
property var matSectionsModel: []
|
||||
property bool restoreFocusOnClose: true
|
||||
|
||||
property var materialBrowserModel: MaterialBrowserBackend.materialBrowserModel
|
||||
|
||||
function popupMenu(targetItem = null, targetMaterial = null)
|
||||
{
|
||||
this.targetItem = targetItem
|
||||
|
@@ -6,6 +6,7 @@ import QtQuick.Layouts 1.15
|
||||
import QtQuickDesignerTheme 1.0
|
||||
import HelperWidgets 2.0
|
||||
import StudioTheme 1.0 as StudioTheme
|
||||
import MaterialBrowserBackend
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
@@ -32,12 +33,12 @@ Rectangle {
|
||||
if (matName.readOnly)
|
||||
return;
|
||||
|
||||
materialBrowserModel.renameMaterial(index, matName.text);
|
||||
MaterialBrowserBackend.materialBrowserModel.renameMaterial(index, matName.text);
|
||||
mouseArea.forceActiveFocus()
|
||||
}
|
||||
|
||||
border.width: materialBrowserModel.selectedIndex === index ? rootView.materialSectionFocused ? 3 : 1 : 0
|
||||
border.color: materialBrowserModel.selectedIndex === index
|
||||
border.width: MaterialBrowserBackend.materialBrowserModel.selectedIndex === index ? MaterialBrowserBackend.rootView.materialSectionFocused ? 3 : 1 : 0
|
||||
border.color: MaterialBrowserBackend.materialBrowserModel.selectedIndex === index
|
||||
? StudioTheme.Values.themeControlOutlineInteraction
|
||||
: "transparent"
|
||||
color: "transparent"
|
||||
@@ -57,11 +58,11 @@ Rectangle {
|
||||
drag.accept()
|
||||
|
||||
if (drag.formats[0] === "application/vnd.qtdesignstudio.texture")
|
||||
rootView.acceptTextureDropOnMaterial(index, drag.getDataAsString(drag.keys[0]))
|
||||
MaterialBrowserBackend.rootView.acceptTextureDropOnMaterial(index, drag.getDataAsString(drag.keys[0]))
|
||||
else if (drag.formats[0] === "application/vnd.qtdesignstudio.bundletexture")
|
||||
rootView.acceptBundleTextureDropOnMaterial(index, drag.urls[0])
|
||||
MaterialBrowserBackend.rootView.acceptBundleTextureDropOnMaterial(index, drag.urls[0])
|
||||
else if (drag.formats[0] === "application/vnd.qtdesignstudio.assets")
|
||||
rootView.acceptAssetsDropOnMaterial(index, drag.urls)
|
||||
MaterialBrowserBackend.rootView.acceptAssetsDropOnMaterial(index, drag.urls)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,16 +73,16 @@ Rectangle {
|
||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||
|
||||
onPressed: (mouse) => {
|
||||
materialBrowserModel.selectMaterial(index)
|
||||
rootView.focusMaterialSection(true)
|
||||
MaterialBrowserBackend.materialBrowserModel.selectMaterial(index)
|
||||
MaterialBrowserBackend.rootView.focusMaterialSection(true)
|
||||
|
||||
if (mouse.button === Qt.LeftButton)
|
||||
rootView.startDragMaterial(index, mapToGlobal(mouse.x, mouse.y))
|
||||
MaterialBrowserBackend.rootView.startDragMaterial(index, mapToGlobal(mouse.x, mouse.y))
|
||||
else if (mouse.button === Qt.RightButton)
|
||||
root.showContextMenu()
|
||||
}
|
||||
|
||||
onDoubleClicked: materialBrowserModel.openMaterialEditor();
|
||||
onDoubleClicked: MaterialBrowserBackend.materialBrowserModel.openMaterialEditor();
|
||||
}
|
||||
|
||||
Column {
|
||||
@@ -145,8 +146,8 @@ Rectangle {
|
||||
anchors.fill: parent
|
||||
|
||||
onClicked: {
|
||||
materialBrowserModel.selectMaterial(index)
|
||||
rootView.focusMaterialSection(true)
|
||||
MaterialBrowserBackend.materialBrowserModel.selectMaterial(index)
|
||||
MaterialBrowserBackend.rootView.focusMaterialSection(true)
|
||||
}
|
||||
onDoubleClicked: root.startRename()
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import QtQuick
|
||||
import HelperWidgets
|
||||
import StudioControls as StudioControls
|
||||
import StudioTheme as StudioTheme
|
||||
import MaterialBrowserBackend
|
||||
|
||||
StudioControls.Menu {
|
||||
id: root
|
||||
@@ -12,6 +13,8 @@ StudioControls.Menu {
|
||||
property var targetTexture: null
|
||||
property int copiedTextureInternalId: -1
|
||||
|
||||
property var materialBrowserTexturesModel: MaterialBrowserBackend.materialBrowserTexturesModel
|
||||
|
||||
function popupMenu(targetTexture = null)
|
||||
{
|
||||
this.targetTexture = targetTexture
|
||||
@@ -30,7 +33,7 @@ StudioControls.Menu {
|
||||
|
||||
StudioControls.MenuItem {
|
||||
text: qsTr("Apply to selected material")
|
||||
enabled: root.targetTexture && materialBrowserModel.selectedIndex >= 0
|
||||
enabled: root.targetTexture && MaterialBrowserBackend.materialBrowserModel.selectedIndex >= 0
|
||||
onTriggered: materialBrowserTexturesModel.applyToSelectedMaterial(root.targetTexture.textureInternalId)
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,7 @@ import QtQuick.Layouts
|
||||
import QtQuickDesignerTheme
|
||||
import HelperWidgets
|
||||
import StudioTheme as StudioTheme
|
||||
import MaterialBrowserBackend
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
@@ -14,9 +15,9 @@ Rectangle {
|
||||
visible: textureVisible
|
||||
|
||||
color: "transparent"
|
||||
border.width: materialBrowserTexturesModel.selectedIndex === index
|
||||
? !rootView.materialSectionFocused ? 3 : 1 : 0
|
||||
border.color: materialBrowserTexturesModel.selectedIndex === index
|
||||
border.width: MaterialBrowserBackend.materialBrowserTexturesModel.selectedIndex === index
|
||||
? !MaterialBrowserBackend.rootView.materialSectionFocused ? 3 : 1 : 0
|
||||
border.color: MaterialBrowserBackend.materialBrowserTexturesModel.selectedIndex === index
|
||||
? StudioTheme.Values.themeControlOutlineInteraction
|
||||
: "transparent"
|
||||
|
||||
@@ -30,16 +31,16 @@ Rectangle {
|
||||
hoverEnabled: true
|
||||
|
||||
onPressed: (mouse) => {
|
||||
materialBrowserTexturesModel.selectTexture(index)
|
||||
rootView.focusMaterialSection(false)
|
||||
MaterialBrowserBackend.materialBrowserTexturesModel.selectTexture(index)
|
||||
MaterialBrowserBackend.rootView.focusMaterialSection(false)
|
||||
|
||||
if (mouse.button === Qt.LeftButton)
|
||||
rootView.startDragTexture(index, mapToGlobal(mouse.x, mouse.y))
|
||||
MaterialBrowserBackend.rootView.startDragTexture(index, mapToGlobal(mouse.x, mouse.y))
|
||||
else if (mouse.button === Qt.RightButton)
|
||||
root.showContextMenu()
|
||||
}
|
||||
|
||||
onDoubleClicked: materialBrowserTexturesModel.openTextureEditor();
|
||||
onDoubleClicked: MaterialBrowserBackend.materialBrowserTexturesModel.openTextureEditor();
|
||||
}
|
||||
|
||||
ToolTip {
|
||||
|
@@ -19,6 +19,8 @@
|
||||
#include "theme.h"
|
||||
#include "variantproperty.h"
|
||||
|
||||
#include <studioquickwidget.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -33,7 +35,6 @@
|
||||
#include <QQmlEngine>
|
||||
#include <QQuickImageProvider>
|
||||
#include <QQuickItem>
|
||||
#include <QQuickWidget>
|
||||
#include <QShortcut>
|
||||
#include <QStackedWidget>
|
||||
#include <QTabBar>
|
||||
@@ -152,7 +153,7 @@ MaterialBrowserWidget::MaterialBrowserWidget(AsynchronousImageCache &imageCache,
|
||||
: m_materialBrowserView(view)
|
||||
, m_materialBrowserModel(new MaterialBrowserModel(this))
|
||||
, m_materialBrowserTexturesModel(new MaterialBrowserTexturesModel(this))
|
||||
, m_quickWidget(new QQuickWidget(this))
|
||||
, m_quickWidget(new StudioQuickWidget(this))
|
||||
, m_previewImageProvider(new PreviewImageProvider())
|
||||
{
|
||||
QImage defaultImage;
|
||||
@@ -172,17 +173,11 @@ MaterialBrowserWidget::MaterialBrowserWidget(AsynchronousImageCache &imageCache,
|
||||
m_quickWidget->engine()->addImportPath(propertyEditorResourcesPath() + "/imports");
|
||||
m_quickWidget->setClearColor(Theme::getColor(Theme::Color::DSpanelBackground));
|
||||
|
||||
m_quickWidget->rootContext()->setContextProperties({
|
||||
{"rootView", QVariant::fromValue(this)},
|
||||
{"materialBrowserModel", QVariant::fromValue(m_materialBrowserModel.data())},
|
||||
{"materialBrowserTexturesModel", QVariant::fromValue(m_materialBrowserTexturesModel.data())},
|
||||
});
|
||||
|
||||
m_quickWidget->engine()->addImageProvider("materialBrowser", m_previewImageProvider);
|
||||
m_quickWidget->engine()->addImageProvider("materialBrowserTex", m_textureImageProvider);
|
||||
|
||||
Theme::setupTheme(m_quickWidget->engine());
|
||||
m_quickWidget->installEventFilter(this);
|
||||
m_quickWidget->quickWidget()->installEventFilter(this);
|
||||
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins({});
|
||||
@@ -209,6 +204,14 @@ MaterialBrowserWidget::MaterialBrowserWidget(AsynchronousImageCache &imageCache,
|
||||
|
||||
QmlDesignerPlugin::trackWidgetFocusTime(this, Constants::EVENT_MATERIALBROWSER_TIME);
|
||||
|
||||
auto map = m_quickWidget->registerPropertyMap("MaterialBrowserBackend");
|
||||
|
||||
map->setProperties({
|
||||
{"rootView", QVariant::fromValue(this)},
|
||||
{"materialBrowserModel", QVariant::fromValue(m_materialBrowserModel.data())},
|
||||
{"materialBrowserTexturesModel", QVariant::fromValue(m_materialBrowserTexturesModel.data())},
|
||||
});
|
||||
|
||||
reloadQmlSource();
|
||||
|
||||
setFocusProxy(m_quickWidget.data());
|
||||
@@ -378,7 +381,6 @@ void MaterialBrowserWidget::reloadQmlSource()
|
||||
|
||||
QTC_ASSERT(QFileInfo::exists(materialBrowserQmlPath), return);
|
||||
|
||||
m_quickWidget->engine()->clearComponentCache();
|
||||
m_quickWidget->setSource(QUrl::fromLocalFile(materialBrowserQmlPath));
|
||||
}
|
||||
|
||||
@@ -397,7 +399,7 @@ void MaterialBrowserWidget::setIsDragging(bool val)
|
||||
}
|
||||
}
|
||||
|
||||
QQuickWidget *MaterialBrowserWidget::quickWidget() const
|
||||
StudioQuickWidget *MaterialBrowserWidget::quickWidget() const
|
||||
{
|
||||
return m_quickWidget.data();
|
||||
}
|
||||
|
@@ -16,12 +16,13 @@
|
||||
#include <memory>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QQuickWidget;
|
||||
class QPointF;
|
||||
class QShortcut;
|
||||
class QToolButton;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class StudioQuickWidget;
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
class AssetImageProvider;
|
||||
@@ -66,7 +67,7 @@ public:
|
||||
Q_INVOKABLE void acceptTextureDropOnMaterial(int matIndex, const QString &texId);
|
||||
Q_INVOKABLE void focusMaterialSection(bool focusMatSec);
|
||||
|
||||
QQuickWidget *quickWidget() const;
|
||||
StudioQuickWidget *quickWidget() const;
|
||||
|
||||
void clearPreviewCache();
|
||||
|
||||
@@ -86,7 +87,7 @@ private:
|
||||
QPointer<MaterialBrowserView> m_materialBrowserView;
|
||||
QPointer<MaterialBrowserModel> m_materialBrowserModel;
|
||||
QPointer<MaterialBrowserTexturesModel> m_materialBrowserTexturesModel;
|
||||
QScopedPointer<QQuickWidget> m_quickWidget;
|
||||
QScopedPointer<StudioQuickWidget> m_quickWidget;
|
||||
|
||||
QShortcut *m_qmlSourceUpdateShortcut = nullptr;
|
||||
PreviewImageProvider *m_previewImageProvider = nullptr;
|
||||
|
Reference in New Issue
Block a user