forked from qt-creator/qt-creator
QmlDesigner: Choose target property when dragging image to material
When dragging an image to a Quick3D default or principled material, pop up a dialog to choose the target texture property. Change-Id: I8d97ef5bf7c5192c2651fcd8cf64a7f4a87c9847 Fixes: QDS-2326 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -0,0 +1,91 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2020 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "choosetexturepropertydialog.h"
|
||||||
|
#include "nodemetainfo.h"
|
||||||
|
#include "ui_choosetexturepropertydialog.h"
|
||||||
|
|
||||||
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
// This dialog displays all texture properties of an object and allows the user to choose one
|
||||||
|
ChooseTexturePropertyDialog::ChooseTexturePropertyDialog(const ModelNode &node, QWidget *parent)
|
||||||
|
: QDialog(parent)
|
||||||
|
, m_ui(new Ui::ChooseTexturePropertyDialog)
|
||||||
|
{
|
||||||
|
m_ui->setupUi(this);
|
||||||
|
setWindowTitle(tr("Select Texture Property"));
|
||||||
|
m_ui->label->setText(tr("Set texture to property:"));
|
||||||
|
setFixedSize(size());
|
||||||
|
|
||||||
|
connect(m_ui->listProps, &QListWidget::itemClicked, this, [this](QListWidgetItem *item) {
|
||||||
|
m_selectedProperty = item->isSelected() ? item->data(Qt::DisplayRole).toByteArray() : QByteArray();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(m_ui->listProps, &QListWidget::itemDoubleClicked, this, [this](QListWidgetItem *item) {
|
||||||
|
Q_UNUSED(item)
|
||||||
|
QDialog::accept();
|
||||||
|
});
|
||||||
|
|
||||||
|
fillList(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChooseTexturePropertyDialog::~ChooseTexturePropertyDialog()
|
||||||
|
{
|
||||||
|
delete m_ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
TypeName ChooseTexturePropertyDialog::selectedProperty() const
|
||||||
|
{
|
||||||
|
return m_selectedProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChooseTexturePropertyDialog::fillList(const ModelNode &node)
|
||||||
|
{
|
||||||
|
// Fill the list with all properties of type Texture
|
||||||
|
const auto metaInfo = node.metaInfo();
|
||||||
|
const auto propNames = metaInfo.propertyNames();
|
||||||
|
const TypeName textureProp("QtQuick3D.Texture");
|
||||||
|
QStringList nameList;
|
||||||
|
for (const auto &propName : propNames) {
|
||||||
|
if (metaInfo.propertyTypeName(propName) == textureProp)
|
||||||
|
nameList.append(QString::fromLatin1(propName));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nameList.isEmpty()) {
|
||||||
|
QString defaultProp = nameList.first();
|
||||||
|
|
||||||
|
nameList.sort();
|
||||||
|
for (const auto &propName : qAsConst(nameList)) {
|
||||||
|
QListWidgetItem *newItem = new QListWidgetItem(propName);
|
||||||
|
m_ui->listProps->addItem(newItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select the default prop
|
||||||
|
m_ui->listProps->setCurrentRow(nameList.indexOf(defaultProp));
|
||||||
|
m_selectedProperty = defaultProp.toLatin1();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,54 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2020 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <modelnode.h>
|
||||||
|
#include <nodeinstanceglobal.h>
|
||||||
|
|
||||||
|
#include <QtWidgets/qdialog.h>
|
||||||
|
|
||||||
|
namespace QmlDesigner {
|
||||||
|
namespace Ui {
|
||||||
|
class ChooseTexturePropertyDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ChooseTexturePropertyDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ChooseTexturePropertyDialog(const ModelNode &node, QWidget *parent = 0);
|
||||||
|
~ChooseTexturePropertyDialog();
|
||||||
|
|
||||||
|
TypeName selectedProperty() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void fillList(const ModelNode &node);
|
||||||
|
|
||||||
|
Ui::ChooseTexturePropertyDialog *m_ui;
|
||||||
|
TypeName m_selectedProperty;
|
||||||
|
};
|
||||||
|
}
|
@@ -0,0 +1,110 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>QmlDesigner::ChooseTexturePropertyDialog</class>
|
||||||
|
<widget class="QDialog" name="QmlDesigner::ChooseTexturePropertyDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>250</width>
|
||||||
|
<height>250</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>200</width>
|
||||||
|
<height>150</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>1000</width>
|
||||||
|
<height>1000</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="autoFillBackground">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="sizeGripEnabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget" native="true">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="listProps"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>QmlDesigner::ChooseTexturePropertyDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>240</x>
|
||||||
|
<y>240</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>QmlDesigner::ChooseTexturePropertyDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>240</x>
|
||||||
|
<y>240</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
@@ -5,7 +5,8 @@ SOURCES += navigatorview.cpp \
|
|||||||
navigatorwidget.cpp \
|
navigatorwidget.cpp \
|
||||||
nameitemdelegate.cpp \
|
nameitemdelegate.cpp \
|
||||||
iconcheckboxitemdelegate.cpp \
|
iconcheckboxitemdelegate.cpp \
|
||||||
navigatortreeview.cpp
|
navigatortreeview.cpp \
|
||||||
|
choosetexturepropertydialog.cpp
|
||||||
|
|
||||||
HEADERS += navigatorview.h \
|
HEADERS += navigatorview.h \
|
||||||
navigatortreemodel.h \
|
navigatortreemodel.h \
|
||||||
@@ -13,6 +14,9 @@ HEADERS += navigatorview.h \
|
|||||||
nameitemdelegate.h \
|
nameitemdelegate.h \
|
||||||
iconcheckboxitemdelegate.h \
|
iconcheckboxitemdelegate.h \
|
||||||
navigatortreeview.h \
|
navigatortreeview.h \
|
||||||
navigatormodelinterface.h
|
navigatormodelinterface.h \
|
||||||
|
choosetexturepropertydialog.h
|
||||||
|
|
||||||
RESOURCES += navigator.qrc
|
RESOURCES += navigator.qrc
|
||||||
|
|
||||||
|
FORMS += choosetexturepropertydialog.ui
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "navigatortreemodel.h"
|
#include "navigatortreemodel.h"
|
||||||
#include "navigatorview.h"
|
#include "navigatorview.h"
|
||||||
|
#include "choosetexturepropertydialog.h"
|
||||||
#include "qmldesignerplugin.h"
|
#include "qmldesignerplugin.h"
|
||||||
|
|
||||||
#include <bindingproperty.h>
|
#include <bindingproperty.h>
|
||||||
@@ -661,16 +662,21 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
|
|||||||
|
|
||||||
if (targetNode.isSubclassOf("QtQuick3D.Material")) {
|
if (targetNode.isSubclassOf("QtQuick3D.Material")) {
|
||||||
// if dropping an image on a default material, create a texture instead of image
|
// if dropping an image on a default material, create a texture instead of image
|
||||||
|
ChooseTexturePropertyDialog *dialog = nullptr;
|
||||||
|
if (targetNode.isSubclassOf("QtQuick3D.DefaultMaterial") || targetNode.isSubclassOf("QtQuick3D.PrincipledMaterial")) {
|
||||||
|
// Show texture property selection dialog
|
||||||
|
dialog = new ChooseTexturePropertyDialog(targetNode, Core::ICore::dialogParent());
|
||||||
|
dialog->exec();
|
||||||
|
}
|
||||||
|
if (!dialog || dialog->result() == QDialog::Accepted) {
|
||||||
m_view->executeInTransaction("NavigatorTreeModel::handleItemLibraryImageDrop", [&] {
|
m_view->executeInTransaction("NavigatorTreeModel::handleItemLibraryImageDrop", [&] {
|
||||||
if (createTextureNode(targetProperty)) {
|
if (createTextureNode(targetProperty) && dialog) {
|
||||||
// Automatically set the texture to default property
|
// Automatically set the texture to selected property
|
||||||
// TODO: allow the user to choose which map property to set the texture for (QDS-2326)
|
targetNode.bindingProperty(dialog->selectedProperty()).setExpression(newModelNode.validId());
|
||||||
if (targetNode.isSubclassOf("QtQuick3D.DefaultMaterial"))
|
|
||||||
targetNode.bindingProperty("diffuseMap").setExpression(newModelNode.validId());
|
|
||||||
else if (targetNode.isSubclassOf("QtQuick3D.PrincipledMaterial"))
|
|
||||||
targetNode.bindingProperty("baseColorMap").setExpression(newModelNode.validId());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
delete dialog;
|
||||||
} else if (targetNode.isSubclassOf("QtQuick3D.TextureInput")) {
|
} else if (targetNode.isSubclassOf("QtQuick3D.TextureInput")) {
|
||||||
// If dropping an image on a TextureInput, create a texture on the same level as
|
// If dropping an image on a TextureInput, create a texture on the same level as
|
||||||
// TextureInput, as the TextureInput doesn't support Texture children (QTBUG-86219)
|
// TextureInput, as the TextureInput doesn't support Texture children (QTBUG-86219)
|
||||||
|
Reference in New Issue
Block a user