aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2020-08-28 14:00:43 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2020-09-04 11:58:15 +0000
commit913dc6473ddd93dbc6d3d260a4a4445696ba3b09 (patch)
tree7a87e054922a290e127a33810c4b9118a27f895a
parent5cc7dae9659afaf546a609c0d6577a7118d7400b (diff)
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>
-rw-r--r--src/plugins/qmldesigner/components/navigator/choosetexturepropertydialog.cpp91
-rw-r--r--src/plugins/qmldesigner/components/navigator/choosetexturepropertydialog.h54
-rw-r--r--src/plugins/qmldesigner/components/navigator/choosetexturepropertydialog.ui110
-rw-r--r--src/plugins/qmldesigner/components/navigator/navigator.pri8
-rw-r--r--src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp26
5 files changed, 277 insertions, 12 deletions
diff --git a/src/plugins/qmldesigner/components/navigator/choosetexturepropertydialog.cpp b/src/plugins/qmldesigner/components/navigator/choosetexturepropertydialog.cpp
new file mode 100644
index 0000000000..826ed580ca
--- /dev/null
+++ b/src/plugins/qmldesigner/components/navigator/choosetexturepropertydialog.cpp
@@ -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();
+ }
+}
+
+}
diff --git a/src/plugins/qmldesigner/components/navigator/choosetexturepropertydialog.h b/src/plugins/qmldesigner/components/navigator/choosetexturepropertydialog.h
new file mode 100644
index 0000000000..7604e6f942
--- /dev/null
+++ b/src/plugins/qmldesigner/components/navigator/choosetexturepropertydialog.h
@@ -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;
+};
+}
diff --git a/src/plugins/qmldesigner/components/navigator/choosetexturepropertydialog.ui b/src/plugins/qmldesigner/components/navigator/choosetexturepropertydialog.ui
new file mode 100644
index 0000000000..8643e866d5
--- /dev/null
+++ b/src/plugins/qmldesigner/components/navigator/choosetexturepropertydialog.ui
@@ -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>
diff --git a/src/plugins/qmldesigner/components/navigator/navigator.pri b/src/plugins/qmldesigner/components/navigator/navigator.pri
index 08432e7f86..7344f1bc5a 100644
--- a/src/plugins/qmldesigner/components/navigator/navigator.pri
+++ b/src/plugins/qmldesigner/components/navigator/navigator.pri
@@ -5,7 +5,8 @@ SOURCES += navigatorview.cpp \
navigatorwidget.cpp \
nameitemdelegate.cpp \
iconcheckboxitemdelegate.cpp \
- navigatortreeview.cpp
+ navigatortreeview.cpp \
+ choosetexturepropertydialog.cpp
HEADERS += navigatorview.h \
navigatortreemodel.h \
@@ -13,6 +14,9 @@ HEADERS += navigatorview.h \
nameitemdelegate.h \
iconcheckboxitemdelegate.h \
navigatortreeview.h \
- navigatormodelinterface.h
+ navigatormodelinterface.h \
+ choosetexturepropertydialog.h
RESOURCES += navigator.qrc
+
+FORMS += choosetexturepropertydialog.ui
diff --git a/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp b/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp
index e2cc2970b8..c93b3145e9 100644
--- a/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp
+++ b/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp
@@ -25,6 +25,7 @@
#include "navigatortreemodel.h"
#include "navigatorview.h"
+#include "choosetexturepropertydialog.h"
#include "qmldesignerplugin.h"
#include <bindingproperty.h>
@@ -661,16 +662,21 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
if (targetNode.isSubclassOf("QtQuick3D.Material")) {
// if dropping an image on a default material, create a texture instead of image
- m_view->executeInTransaction("NavigatorTreeModel::handleItemLibraryImageDrop", [&] {
- if (createTextureNode(targetProperty)) {
- // Automatically set the texture to default property
- // TODO: allow the user to choose which map property to set the texture for (QDS-2326)
- if (targetNode.isSubclassOf("QtQuick3D.DefaultMaterial"))
- targetNode.bindingProperty("diffuseMap").setExpression(newModelNode.validId());
- else if (targetNode.isSubclassOf("QtQuick3D.PrincipledMaterial"))
- targetNode.bindingProperty("baseColorMap").setExpression(newModelNode.validId());
- }
- });
+ 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", [&] {
+ if (createTextureNode(targetProperty) && dialog) {
+ // Automatically set the texture to selected property
+ targetNode.bindingProperty(dialog->selectedProperty()).setExpression(newModelNode.validId());
+ }
+ });
+ }
+ delete dialog;
} else if (targetNode.isSubclassOf("QtQuick3D.TextureInput")) {
// 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)