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: {
|
onClicked: {
|
||||||
materialsListView.currentIndex = index
|
materialsListView.currentIndex = index
|
||||||
rootView.updatePropsModel(id())
|
MaterialBrowserBackend.rootView.updatePropsModel(id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ Rectangle {
|
|||||||
text: qsTr("Cancel")
|
text: qsTr("Cancel")
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
rootView.closeChooseMatPropsView()
|
MaterialBrowserBackend.rootView.closeChooseMatPropsView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ Rectangle {
|
|||||||
let matId = materialsListView.currentItem.id()
|
let matId = materialsListView.currentItem.id()
|
||||||
let prop = propertiesListView.currentItem.propName()
|
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 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 MaterialBrowserBackend
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
@@ -17,6 +18,9 @@ Item {
|
|||||||
&& materialBrowserModel.hasQuick3DImport
|
&& materialBrowserModel.hasQuick3DImport
|
||||||
|
|
||||||
property var currMaterialItem: null
|
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
|
// Called also from C++ to close context menu on focus out
|
||||||
function closeContextMenu()
|
function closeContextMenu()
|
||||||
|
@@ -5,6 +5,7 @@ import QtQuick
|
|||||||
import HelperWidgets
|
import HelperWidgets
|
||||||
import StudioControls as StudioControls
|
import StudioControls as StudioControls
|
||||||
import StudioTheme as StudioTheme
|
import StudioTheme as StudioTheme
|
||||||
|
import MaterialBrowserBackend
|
||||||
|
|
||||||
StudioControls.Menu {
|
StudioControls.Menu {
|
||||||
id: root
|
id: root
|
||||||
@@ -15,6 +16,8 @@ StudioControls.Menu {
|
|||||||
property var matSectionsModel: []
|
property var matSectionsModel: []
|
||||||
property bool restoreFocusOnClose: true
|
property bool restoreFocusOnClose: true
|
||||||
|
|
||||||
|
property var materialBrowserModel: MaterialBrowserBackend.materialBrowserModel
|
||||||
|
|
||||||
function popupMenu(targetItem = null, targetMaterial = null)
|
function popupMenu(targetItem = null, targetMaterial = null)
|
||||||
{
|
{
|
||||||
this.targetItem = targetItem
|
this.targetItem = targetItem
|
||||||
|
@@ -6,6 +6,7 @@ import QtQuick.Layouts 1.15
|
|||||||
import QtQuickDesignerTheme 1.0
|
import QtQuickDesignerTheme 1.0
|
||||||
import HelperWidgets 2.0
|
import HelperWidgets 2.0
|
||||||
import StudioTheme 1.0 as StudioTheme
|
import StudioTheme 1.0 as StudioTheme
|
||||||
|
import MaterialBrowserBackend
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: root
|
id: root
|
||||||
@@ -32,12 +33,12 @@ Rectangle {
|
|||||||
if (matName.readOnly)
|
if (matName.readOnly)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
materialBrowserModel.renameMaterial(index, matName.text);
|
MaterialBrowserBackend.materialBrowserModel.renameMaterial(index, matName.text);
|
||||||
mouseArea.forceActiveFocus()
|
mouseArea.forceActiveFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
border.width: materialBrowserModel.selectedIndex === index ? rootView.materialSectionFocused ? 3 : 1 : 0
|
border.width: MaterialBrowserBackend.materialBrowserModel.selectedIndex === index ? MaterialBrowserBackend.rootView.materialSectionFocused ? 3 : 1 : 0
|
||||||
border.color: materialBrowserModel.selectedIndex === index
|
border.color: MaterialBrowserBackend.materialBrowserModel.selectedIndex === index
|
||||||
? StudioTheme.Values.themeControlOutlineInteraction
|
? StudioTheme.Values.themeControlOutlineInteraction
|
||||||
: "transparent"
|
: "transparent"
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
@@ -57,11 +58,11 @@ Rectangle {
|
|||||||
drag.accept()
|
drag.accept()
|
||||||
|
|
||||||
if (drag.formats[0] === "application/vnd.qtdesignstudio.texture")
|
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")
|
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")
|
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
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||||
|
|
||||||
onPressed: (mouse) => {
|
onPressed: (mouse) => {
|
||||||
materialBrowserModel.selectMaterial(index)
|
MaterialBrowserBackend.materialBrowserModel.selectMaterial(index)
|
||||||
rootView.focusMaterialSection(true)
|
MaterialBrowserBackend.rootView.focusMaterialSection(true)
|
||||||
|
|
||||||
if (mouse.button === Qt.LeftButton)
|
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)
|
else if (mouse.button === Qt.RightButton)
|
||||||
root.showContextMenu()
|
root.showContextMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
onDoubleClicked: materialBrowserModel.openMaterialEditor();
|
onDoubleClicked: MaterialBrowserBackend.materialBrowserModel.openMaterialEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
@@ -145,8 +146,8 @@ Rectangle {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
materialBrowserModel.selectMaterial(index)
|
MaterialBrowserBackend.materialBrowserModel.selectMaterial(index)
|
||||||
rootView.focusMaterialSection(true)
|
MaterialBrowserBackend.rootView.focusMaterialSection(true)
|
||||||
}
|
}
|
||||||
onDoubleClicked: root.startRename()
|
onDoubleClicked: root.startRename()
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ import QtQuick
|
|||||||
import HelperWidgets
|
import HelperWidgets
|
||||||
import StudioControls as StudioControls
|
import StudioControls as StudioControls
|
||||||
import StudioTheme as StudioTheme
|
import StudioTheme as StudioTheme
|
||||||
|
import MaterialBrowserBackend
|
||||||
|
|
||||||
StudioControls.Menu {
|
StudioControls.Menu {
|
||||||
id: root
|
id: root
|
||||||
@@ -12,6 +13,8 @@ StudioControls.Menu {
|
|||||||
property var targetTexture: null
|
property var targetTexture: null
|
||||||
property int copiedTextureInternalId: -1
|
property int copiedTextureInternalId: -1
|
||||||
|
|
||||||
|
property var materialBrowserTexturesModel: MaterialBrowserBackend.materialBrowserTexturesModel
|
||||||
|
|
||||||
function popupMenu(targetTexture = null)
|
function popupMenu(targetTexture = null)
|
||||||
{
|
{
|
||||||
this.targetTexture = targetTexture
|
this.targetTexture = targetTexture
|
||||||
@@ -30,7 +33,7 @@ StudioControls.Menu {
|
|||||||
|
|
||||||
StudioControls.MenuItem {
|
StudioControls.MenuItem {
|
||||||
text: qsTr("Apply to selected material")
|
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)
|
onTriggered: materialBrowserTexturesModel.applyToSelectedMaterial(root.targetTexture.textureInternalId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@ import QtQuick.Layouts
|
|||||||
import QtQuickDesignerTheme
|
import QtQuickDesignerTheme
|
||||||
import HelperWidgets
|
import HelperWidgets
|
||||||
import StudioTheme as StudioTheme
|
import StudioTheme as StudioTheme
|
||||||
|
import MaterialBrowserBackend
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: root
|
id: root
|
||||||
@@ -14,9 +15,9 @@ Rectangle {
|
|||||||
visible: textureVisible
|
visible: textureVisible
|
||||||
|
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
border.width: materialBrowserTexturesModel.selectedIndex === index
|
border.width: MaterialBrowserBackend.materialBrowserTexturesModel.selectedIndex === index
|
||||||
? !rootView.materialSectionFocused ? 3 : 1 : 0
|
? !MaterialBrowserBackend.rootView.materialSectionFocused ? 3 : 1 : 0
|
||||||
border.color: materialBrowserTexturesModel.selectedIndex === index
|
border.color: MaterialBrowserBackend.materialBrowserTexturesModel.selectedIndex === index
|
||||||
? StudioTheme.Values.themeControlOutlineInteraction
|
? StudioTheme.Values.themeControlOutlineInteraction
|
||||||
: "transparent"
|
: "transparent"
|
||||||
|
|
||||||
@@ -30,16 +31,16 @@ Rectangle {
|
|||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
|
|
||||||
onPressed: (mouse) => {
|
onPressed: (mouse) => {
|
||||||
materialBrowserTexturesModel.selectTexture(index)
|
MaterialBrowserBackend.materialBrowserTexturesModel.selectTexture(index)
|
||||||
rootView.focusMaterialSection(false)
|
MaterialBrowserBackend.rootView.focusMaterialSection(false)
|
||||||
|
|
||||||
if (mouse.button === Qt.LeftButton)
|
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)
|
else if (mouse.button === Qt.RightButton)
|
||||||
root.showContextMenu()
|
root.showContextMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
onDoubleClicked: materialBrowserTexturesModel.openTextureEditor();
|
onDoubleClicked: MaterialBrowserBackend.materialBrowserTexturesModel.openTextureEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolTip {
|
ToolTip {
|
||||||
|
@@ -19,6 +19,8 @@
|
|||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "variantproperty.h"
|
#include "variantproperty.h"
|
||||||
|
|
||||||
|
#include <studioquickwidget.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -33,7 +35,6 @@
|
|||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include <QQuickImageProvider>
|
#include <QQuickImageProvider>
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
#include <QQuickWidget>
|
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
#include <QTabBar>
|
#include <QTabBar>
|
||||||
@@ -152,7 +153,7 @@ MaterialBrowserWidget::MaterialBrowserWidget(AsynchronousImageCache &imageCache,
|
|||||||
: m_materialBrowserView(view)
|
: m_materialBrowserView(view)
|
||||||
, m_materialBrowserModel(new MaterialBrowserModel(this))
|
, m_materialBrowserModel(new MaterialBrowserModel(this))
|
||||||
, m_materialBrowserTexturesModel(new MaterialBrowserTexturesModel(this))
|
, m_materialBrowserTexturesModel(new MaterialBrowserTexturesModel(this))
|
||||||
, m_quickWidget(new QQuickWidget(this))
|
, m_quickWidget(new StudioQuickWidget(this))
|
||||||
, m_previewImageProvider(new PreviewImageProvider())
|
, m_previewImageProvider(new PreviewImageProvider())
|
||||||
{
|
{
|
||||||
QImage defaultImage;
|
QImage defaultImage;
|
||||||
@@ -172,17 +173,11 @@ MaterialBrowserWidget::MaterialBrowserWidget(AsynchronousImageCache &imageCache,
|
|||||||
m_quickWidget->engine()->addImportPath(propertyEditorResourcesPath() + "/imports");
|
m_quickWidget->engine()->addImportPath(propertyEditorResourcesPath() + "/imports");
|
||||||
m_quickWidget->setClearColor(Theme::getColor(Theme::Color::DSpanelBackground));
|
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("materialBrowser", m_previewImageProvider);
|
||||||
m_quickWidget->engine()->addImageProvider("materialBrowserTex", m_textureImageProvider);
|
m_quickWidget->engine()->addImageProvider("materialBrowserTex", m_textureImageProvider);
|
||||||
|
|
||||||
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({});
|
||||||
@@ -209,6 +204,14 @@ MaterialBrowserWidget::MaterialBrowserWidget(AsynchronousImageCache &imageCache,
|
|||||||
|
|
||||||
QmlDesignerPlugin::trackWidgetFocusTime(this, Constants::EVENT_MATERIALBROWSER_TIME);
|
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();
|
reloadQmlSource();
|
||||||
|
|
||||||
setFocusProxy(m_quickWidget.data());
|
setFocusProxy(m_quickWidget.data());
|
||||||
@@ -378,7 +381,6 @@ void MaterialBrowserWidget::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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,7 +399,7 @@ void MaterialBrowserWidget::setIsDragging(bool val)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QQuickWidget *MaterialBrowserWidget::quickWidget() const
|
StudioQuickWidget *MaterialBrowserWidget::quickWidget() const
|
||||||
{
|
{
|
||||||
return m_quickWidget.data();
|
return m_quickWidget.data();
|
||||||
}
|
}
|
||||||
|
@@ -16,12 +16,13 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QQuickWidget;
|
|
||||||
class QPointF;
|
class QPointF;
|
||||||
class QShortcut;
|
class QShortcut;
|
||||||
class QToolButton;
|
class QToolButton;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class StudioQuickWidget;
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
class AssetImageProvider;
|
class AssetImageProvider;
|
||||||
@@ -66,7 +67,7 @@ public:
|
|||||||
Q_INVOKABLE void acceptTextureDropOnMaterial(int matIndex, const QString &texId);
|
Q_INVOKABLE void acceptTextureDropOnMaterial(int matIndex, const QString &texId);
|
||||||
Q_INVOKABLE void focusMaterialSection(bool focusMatSec);
|
Q_INVOKABLE void focusMaterialSection(bool focusMatSec);
|
||||||
|
|
||||||
QQuickWidget *quickWidget() const;
|
StudioQuickWidget *quickWidget() const;
|
||||||
|
|
||||||
void clearPreviewCache();
|
void clearPreviewCache();
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ private:
|
|||||||
QPointer<MaterialBrowserView> m_materialBrowserView;
|
QPointer<MaterialBrowserView> m_materialBrowserView;
|
||||||
QPointer<MaterialBrowserModel> m_materialBrowserModel;
|
QPointer<MaterialBrowserModel> m_materialBrowserModel;
|
||||||
QPointer<MaterialBrowserTexturesModel> m_materialBrowserTexturesModel;
|
QPointer<MaterialBrowserTexturesModel> m_materialBrowserTexturesModel;
|
||||||
QScopedPointer<QQuickWidget> m_quickWidget;
|
QScopedPointer<StudioQuickWidget> m_quickWidget;
|
||||||
|
|
||||||
QShortcut *m_qmlSourceUpdateShortcut = nullptr;
|
QShortcut *m_qmlSourceUpdateShortcut = nullptr;
|
||||||
PreviewImageProvider *m_previewImageProvider = nullptr;
|
PreviewImageProvider *m_previewImageProvider = nullptr;
|
||||||
|
Reference in New Issue
Block a user