From e2e18ff625cf28f5f456bb172b7aacbf3e5b1674 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 15 Oct 2019 18:14:13 +0200 Subject: [PATCH] QmlDesigner: Implement combobox to disable 3d editor The combobox is in the toolbar of the form editor. For pure 2D scenes the combobox is disabled. Since auxiliaryData is persistent, this setting is also persistent. Change-Id: I1bf1d9acba7320b8503311ca785410df27d650db Reviewed-by: Miikka Heikkinen Reviewed-by: Alessandro Portale --- src/plugins/qmldesigner/CMakeLists.txt | 1 + .../components/formeditor/formeditor.pri | 6 +- .../components/formeditor/formeditorview.cpp | 31 +++++++++ .../components/formeditor/formeditorview.h | 3 + .../formeditor/formeditorwidget.cpp | 27 ++++++-- .../components/formeditor/formeditorwidget.h | 3 + .../components/formeditor/option3daction.cpp | 66 +++++++++++++++++++ .../components/formeditor/option3daction.h | 52 +++++++++++++++ .../designercore/instances/puppetcreator.cpp | 16 ++++- src/plugins/qmldesigner/qmldesignerplugin.qbs | 2 + 10 files changed, 196 insertions(+), 11 deletions(-) create mode 100644 src/plugins/qmldesigner/components/formeditor/option3daction.cpp create mode 100644 src/plugins/qmldesigner/components/formeditor/option3daction.h diff --git a/src/plugins/qmldesigner/CMakeLists.txt b/src/plugins/qmldesigner/CMakeLists.txt index 6233990e183..9bf5fab1135 100644 --- a/src/plugins/qmldesigner/CMakeLists.txt +++ b/src/plugins/qmldesigner/CMakeLists.txt @@ -231,6 +231,7 @@ extend_qtc_plugin(QmlDesigner snapper.cpp snapper.h snappinglinecreator.cpp snappinglinecreator.h toolbox.cpp toolbox.h + option3daction.cpp option3daction.h ) extend_qtc_plugin(QmlDesigner diff --git a/src/plugins/qmldesigner/components/formeditor/formeditor.pri b/src/plugins/qmldesigner/components/formeditor/formeditor.pri index aef4f587c65..5bff19e664c 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditor.pri +++ b/src/plugins/qmldesigner/components/formeditor/formeditor.pri @@ -36,7 +36,8 @@ SOURCES += formeditoritem.cpp \ bindingindicatorgraphicsitem.cpp \ contentnoteditableindicator.cpp \ backgroundaction.cpp \ - formeditortoolbutton.cpp + formeditortoolbutton.cpp \ + option3daction.cpp HEADERS += formeditorscene.h \ formeditorwidget.h \ @@ -75,6 +76,7 @@ HEADERS += formeditorscene.h \ bindingindicatorgraphicsitem.h \ contentnoteditableindicator.h \ backgroundaction.h \ - formeditortoolbutton.h + formeditortoolbutton.h \ + option3daction.h RESOURCES += formeditor.qrc diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp index f964b804589..10fcbdc1b75 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp @@ -26,6 +26,7 @@ #include "formeditorview.h" #include "selectiontool.h" #include "movetool.h" +#include "option3daction.h" #include "resizetool.h" #include "dragtool.h" #include "formeditorwidget.h" @@ -45,6 +46,7 @@ #include #include +#include #include #include @@ -83,6 +85,7 @@ void FormEditorView::modelAttached(Model *model) setupFormEditorItemTree(rootModelNode()); m_formEditorWidget->updateActions(); + setupOption3DAction(); if (!rewriterView()->errors().isEmpty()) formEditorWidget()->showErrorMessageBox(rewriterView()->errors()); @@ -178,6 +181,22 @@ void FormEditorView::temporaryBlockView() }); } +void FormEditorView::setupOption3DAction() +{ + auto import = Import::createLibraryImport("QtQuick3D", "1.0"); + auto action = m_formEditorWidget->option3DAction(); + if (model() && model()->hasImport(import, true, true)) { + bool enabled = true; + if (rootModelNode().hasAuxiliaryData("3d-view")) + enabled = rootModelNode().auxiliaryData("3d-view").toBool(); + action->set3DEnabled(enabled); + action->setEnabled(true); + } else { + action->set3DEnabled(false); + action->setEnabled(false); + } +} + void FormEditorView::nodeCreated(const ModelNode &node) { //If the node has source for components/custom parsers we ignore it. @@ -567,6 +586,16 @@ void FormEditorView::exportAsImage() m_formEditorWidget->exportAsImage(m_scene->rootFormEditorItem()->boundingRect()); } +void FormEditorView::toggle3DViewEnabled(bool enabled) +{ + QTC_ASSERT(model(), return); + QTC_ASSERT(rootModelNode().isValid(), return); + if (enabled) + rootModelNode().removeAuxiliaryData("3d-view"); + else + rootModelNode().setAuxiliaryData("3d-view", false); +} + QmlItemNode findRecursiveQmlItemNode(const QmlObjectNode &firstQmlObjectNode) { QmlObjectNode qmlObjectNode = firstQmlObjectNode; @@ -629,6 +658,8 @@ void FormEditorView::delayedReset() m_scene->clearFormEditorItems(); if (isAttached() && QmlItemNode::isValidQmlItemNode(rootModelNode())) setupFormEditorItemTree(rootModelNode()); + + setupOption3DAction(); } } diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorview.h b/src/plugins/qmldesigner/components/formeditor/formeditorview.h index 186730a0e24..c607aa0b69e 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorview.h +++ b/src/plugins/qmldesigner/components/formeditor/formeditorview.h @@ -118,6 +118,8 @@ public: void exportAsImage(); + void toggle3DViewEnabled(bool enabled); + protected: void reset(); void delayedReset(); @@ -129,6 +131,7 @@ private: //functions void hideNodeFromScene(const QmlItemNode &qmlItemNode); void createFormEditorWidget(); void temporaryBlockView(); + void setupOption3DAction(); private: //variables QPointer m_formEditorWidget; diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp index 2a9eea5ea60..045fe964398 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.cpp @@ -34,24 +34,25 @@ #include #include -#include -#include -#include -#include -#include +#include #include #include #include #include -#include +#include +#include +#include #include #include #include +#include #include #include +#include +#include namespace QmlDesigner { @@ -143,6 +144,15 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view) : upperActions.append(m_backgroundAction.data()); m_toolBox->addRightSideAction(m_backgroundAction.data()); + m_option3DAction = new Option3DAction(m_toolActionGroup.data()); + addAction(m_option3DAction.data()); + upperActions.append(m_option3DAction.data()); + m_toolBox->addRightSideAction(m_option3DAction.data()); + connect(m_option3DAction.data(), &Option3DAction::enabledChanged, + m_formEditorView.data(), &FormEditorView::toggle3DViewEnabled); + connect(m_option3DAction.data(), &Option3DAction::activated, + this, &FormEditorWidget::resetNodeInstanceView); + m_zoomAction = new ZoomAction(m_toolActionGroup.data()); connect(m_zoomAction.data(), &ZoomAction::zoomLevelChanged, this, &FormEditorWidget::setZoomLevel); @@ -285,6 +295,11 @@ ZoomAction *FormEditorWidget::zoomAction() const return m_zoomAction.data(); } +Option3DAction *FormEditorWidget::option3DAction() const +{ + return m_option3DAction.data(); +} + QAction *FormEditorWidget::showBoundingRectAction() const { return m_showBoundingRectAction.data(); diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.h b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.h index 1d85138ebc5..ef0ae3615e4 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorwidget.h +++ b/src/plugins/qmldesigner/components/formeditor/formeditorwidget.h @@ -40,6 +40,7 @@ namespace QmlDesigner { class ZoomAction; class LineEditAction; class BackgroundAction; +class Option3DAction; class FormEditorView; class FormEditorScene; class FormEditorGraphicsView; @@ -54,6 +55,7 @@ public: FormEditorWidget(FormEditorView *view); ZoomAction *zoomAction() const; + Option3DAction *option3DAction() const; QAction *showBoundingRectAction() const; QAction *snappingAction() const; QAction *snappingAndAnchoringAction() const; @@ -112,6 +114,7 @@ private: QPointer m_rootWidthAction; QPointer m_rootHeightAction; QPointer m_backgroundAction; + QPointer m_option3DAction; QPointer m_resetAction; QPointer m_documentErrorWidget; }; diff --git a/src/plugins/qmldesigner/components/formeditor/option3daction.cpp b/src/plugins/qmldesigner/components/formeditor/option3daction.cpp new file mode 100644 index 00000000000..6a8befe6b5a --- /dev/null +++ b/src/plugins/qmldesigner/components/formeditor/option3daction.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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 "option3daction.h" + +#include +#include + +namespace QmlDesigner { + +Option3DAction::Option3DAction(QObject *parent) : + QWidgetAction(parent) +{ +} + +void Option3DAction::set3DEnabled(bool enabled) +{ + m_comboBox->setCurrentIndex(enabled ? 1 : 0); +} + +QWidget *Option3DAction::createWidget(QWidget *parent) +{ + m_comboBox = new QComboBox(parent); + m_comboBox->setFixedWidth(82); + + m_comboBox->addItem(tr("2D")); + m_comboBox->addItem(tr("2D/3D")); + + m_comboBox->setCurrentIndex(0); + connect(m_comboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, [this](){ + emit enabledChanged(m_comboBox->currentIndex() != 0); + }); + connect(m_comboBox, QOverload::of(&QComboBox::activated), + this, [this](){ + emit activated(); + }); + + m_comboBox->setProperty("hideborder", true); + m_comboBox->setToolTip(tr("Enable/Disable 3D edit mode.")); + return m_comboBox; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/formeditor/option3daction.h b/src/plugins/qmldesigner/components/formeditor/option3daction.h new file mode 100644 index 00000000000..113442c7ae9 --- /dev/null +++ b/src/plugins/qmldesigner/components/formeditor/option3daction.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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 + +QT_FORWARD_DECLARE_CLASS(QComboBox) + +namespace QmlDesigner { + +class Option3DAction : public QWidgetAction +{ + Q_OBJECT + +public: + explicit Option3DAction(QObject *parent); + void set3DEnabled(bool enabled); + +signals: + void enabledChanged(bool enabled); + void activated(); + +protected: + QWidget *createWidget(QWidget *parent) override; + +private: + QComboBox *m_comboBox = nullptr; +}; + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/puppetcreator.cpp b/src/plugins/qmldesigner/designercore/instances/puppetcreator.cpp index 6cb7a888384..12a55c25fe1 100644 --- a/src/plugins/qmldesigner/designercore/instances/puppetcreator.cpp +++ b/src/plugins/qmldesigner/designercore/instances/puppetcreator.cpp @@ -459,18 +459,28 @@ QProcessEnvironment PuppetCreator::processEnvironment() const if (!m_qrcMapping.isEmpty()) { environment.set("QMLDESIGNER_RC_PATHS", m_qrcMapping); } + + AbstractView *view = nullptr; #ifndef QMLDESIGNER_TEST - QmlDesignerPlugin::instance()->viewManager().nodeInstanceView()->emitCustomNotification("PuppetStatus", {}, {QVariant(m_qrcMapping)}); + view = QmlDesignerPlugin::instance()->viewManager().nodeInstanceView(); + view->emitCustomNotification("PuppetStatus", {}, {QVariant(m_qrcMapping)}); #endif QStringList importPaths = m_model->importPaths(); QmlDesigner::Import import = QmlDesigner::Import::createLibraryImport("QtQuick3D", "1.0"); + bool view3DEnabled = false; - if (m_model->hasImport(import, true, true)) + if (view && m_model->hasImport(import, true, true)) { + if (view->rootModelNode().hasAuxiliaryData("3d-view")) + view3DEnabled = view->rootModelNode().auxiliaryData("3d-view").toBool(); + else + view3DEnabled = true; + } + + if (view3DEnabled) environment.set("QMLDESIGNER_QUICK3D_MODE", "true"); - /* For the fallback puppet we have to remove the path to the original qtbase plugins to avoid conflics */ if (m_availablePuppetType == FallbackPuppet) filterOutQtBaseImportPath(&importPaths); diff --git a/src/plugins/qmldesigner/qmldesignerplugin.qbs b/src/plugins/qmldesigner/qmldesignerplugin.qbs index 8409f4751b4..c62c75be984 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.qbs +++ b/src/plugins/qmldesigner/qmldesignerplugin.qbs @@ -505,6 +505,8 @@ Project { "formeditor/toolbox.h", "formeditor/formeditortoolbutton.cpp", "formeditor/formeditortoolbutton.h", + "formeditor/option3daction.cpp", + "formeditor/option3daction.h", "importmanager/importlabel.cpp", "importmanager/importlabel.h", "importmanager/importmanagercombobox.cpp",