2022-08-19 15:59:36 +02:00
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
2020-02-11 11:33:25 +02:00
2022-04-28 10:23:02 +03:00
# include "edit3dactions.h"
# include "edit3dcanvas.h"
2020-02-11 11:33:25 +02:00
# include "edit3dview.h"
# include "edit3dwidget.h"
2022-06-08 18:00:09 +03:00
# include "edit3dviewconfig.h"
# include "backgroundcolorselection.h"
2022-08-25 12:27:41 +03:00
# include "metainfo.h"
2022-08-26 15:59:40 +03:00
# include "seekerslider.h"
# include "view3dactioncommand.h"
2022-08-26 17:45:11 +03:00
# include "nodehints.h"
2020-02-11 11:33:25 +02:00
2022-07-25 20:16:58 +02:00
# include <auxiliarydataproperties.h>
2022-04-28 10:23:02 +03:00
# include <coreplugin/icore.h>
# include <coreplugin/messagebox.h>
2020-02-11 11:33:25 +02:00
# include <designeractionmanager.h>
# include <designersettings.h>
2022-04-28 10:23:02 +03:00
# include <designmodecontext.h>
# include <nodeinstanceview.h>
2022-07-25 20:16:58 +02:00
# include <viewmanager.h>
2020-02-11 11:33:25 +02:00
# include <qmldesignerconstants.h>
2022-04-28 10:23:02 +03:00
# include <qmldesignericons.h>
2021-11-02 15:05:11 +02:00
# include <qmldesignerplugin.h>
2022-07-25 20:16:58 +02:00
2022-04-28 10:23:02 +03:00
# include <utils/qtcassert.h>
2020-02-11 11:33:25 +02:00
# include <utils/utilsicons.h>
2022-01-21 17:15:01 +02:00
# include <QToolButton>
2020-02-11 11:33:25 +02:00
namespace QmlDesigner {
Edit3DView : : Edit3DView ( QObject * parent )
: AbstractView ( parent )
{
2022-08-25 12:27:41 +03:00
m_compressionTimer . setInterval ( 1000 ) ;
m_compressionTimer . setSingleShot ( true ) ;
connect ( & m_compressionTimer , & QTimer : : timeout , this , & Edit3DView : : handleEntriesChanged ) ;
2020-02-11 11:33:25 +02:00
}
Edit3DView : : ~ Edit3DView ( )
2022-08-25 12:27:41 +03:00
{ }
2020-02-11 11:33:25 +02:00
void Edit3DView : : createEdit3DWidget ( )
{
createEdit3DActions ( ) ;
m_edit3DWidget = new Edit3DWidget ( this ) ;
2020-03-12 15:55:30 +02:00
auto editor3DContext = new Internal : : Editor3DContext ( m_edit3DWidget . data ( ) ) ;
Core : : ICore : : addContextObject ( editor3DContext ) ;
2020-02-11 11:33:25 +02:00
}
2020-03-19 13:05:36 +02:00
void Edit3DView : : checkImports ( )
{
2022-03-18 17:28:28 +02:00
edit3DWidget ( ) - > showCanvas ( model ( ) - > hasImport ( " QtQuick3D " ) ) ;
2020-03-19 13:05:36 +02:00
}
2020-02-11 11:33:25 +02:00
WidgetInfo Edit3DView : : widgetInfo ( )
{
if ( ! m_edit3DWidget )
createEdit3DWidget ( ) ;
2022-03-16 16:32:36 +01:00
return createWidgetInfo ( m_edit3DWidget . data ( ) , " Editor3D " , WidgetInfo : : CentralPane , 0 , tr ( " 3D " ) , DesignerWidgetFlags : : IgnoreErrors ) ;
2020-02-11 11:33:25 +02:00
}
Edit3DWidget * Edit3DView : : edit3DWidget ( ) const
{
return m_edit3DWidget . data ( ) ;
}
2022-07-07 18:04:18 +02:00
void Edit3DView : : selectedNodesChanged ( [[maybe_unused]] const QList < ModelNode > & selectedNodeList ,
[[maybe_unused]] const QList < ModelNode > & lastSelectedNodeList )
2021-08-12 05:31:36 +03:00
{
SelectionContext selectionContext ( this ) ;
selectionContext . setUpdateMode ( SelectionContext : : UpdateMode : : Fast ) ;
if ( m_alignCamerasAction )
m_alignCamerasAction - > currentContextChanged ( selectionContext ) ;
if ( m_alignViewAction )
m_alignViewAction - > currentContextChanged ( selectionContext ) ;
}
2020-02-11 11:33:25 +02:00
void Edit3DView : : renderImage3DChanged ( const QImage & img )
{
edit3DWidget ( ) - > canvas ( ) - > updateRenderImage ( img ) ;
2020-03-06 16:14:12 +02:00
// Notify puppet to resize if received image wasn't correct size
if ( img . size ( ) ! = canvasSize ( ) )
edit3DViewResized ( canvasSize ( ) ) ;
2022-02-09 18:49:40 +01:00
if ( edit3DWidget ( ) - > canvas ( ) - > busyIndicator ( ) - > isVisible ( ) ) {
edit3DWidget ( ) - > canvas ( ) - > setOpacity ( 1.0 ) ;
edit3DWidget ( ) - > canvas ( ) - > busyIndicator ( ) - > hide ( ) ;
}
2020-02-11 11:33:25 +02:00
}
void Edit3DView : : updateActiveScene3D ( const QVariantMap & sceneState )
{
2022-02-21 11:26:53 +02:00
const QString sceneKey = QStringLiteral ( " sceneInstanceId " ) ;
const QString selectKey = QStringLiteral ( " selectionMode " ) ;
const QString transformKey = QStringLiteral ( " transformMode " ) ;
const QString perspectiveKey = QStringLiteral ( " usePerspective " ) ;
const QString orientationKey = QStringLiteral ( " globalOrientation " ) ;
const QString editLightKey = QStringLiteral ( " showEditLight " ) ;
const QString gridKey = QStringLiteral ( " showGrid " ) ;
const QString selectionBoxKey = QStringLiteral ( " showSelectionBox " ) ;
const QString iconGizmoKey = QStringLiteral ( " showIconGizmo " ) ;
const QString cameraFrustumKey = QStringLiteral ( " showCameraFrustum " ) ;
const QString particleEmitterKey = QStringLiteral ( " showParticleEmitter " ) ;
const QString particlesPlayKey = QStringLiteral ( " particlePlay " ) ;
2020-02-11 11:33:25 +02:00
2020-03-12 15:55:30 +02:00
if ( sceneState . contains ( sceneKey ) ) {
qint32 newActiveScene = sceneState [ sceneKey ] . value < qint32 > ( ) ;
edit3DWidget ( ) - > canvas ( ) - > updateActiveScene ( newActiveScene ) ;
2022-07-25 20:16:58 +02:00
rootModelNode ( ) . setAuxiliaryData ( active3dSceneProperty , newActiveScene ) ;
2020-03-12 15:55:30 +02:00
}
2020-02-11 11:33:25 +02:00
if ( sceneState . contains ( selectKey ) )
2020-03-27 20:16:29 +02:00
m_selectionModeAction - > action ( ) - > setChecked ( sceneState [ selectKey ] . toInt ( ) = = 1 ) ;
2020-02-11 11:33:25 +02:00
else
m_selectionModeAction - > action ( ) - > setChecked ( false ) ;
if ( sceneState . contains ( transformKey ) ) {
const int tool = sceneState [ transformKey ] . toInt ( ) ;
if ( tool = = 0 )
m_moveToolAction - > action ( ) - > setChecked ( true ) ;
else if ( tool = = 1 )
m_rotateToolAction - > action ( ) - > setChecked ( true ) ;
else
m_scaleToolAction - > action ( ) - > setChecked ( true ) ;
} else {
m_moveToolAction - > action ( ) - > setChecked ( true ) ;
}
if ( sceneState . contains ( perspectiveKey ) )
m_cameraModeAction - > action ( ) - > setChecked ( sceneState [ perspectiveKey ] . toBool ( ) ) ;
else
m_cameraModeAction - > action ( ) - > setChecked ( false ) ;
2020-03-27 20:16:29 +02:00
2020-02-11 11:33:25 +02:00
if ( sceneState . contains ( orientationKey ) )
m_orientationModeAction - > action ( ) - > setChecked ( sceneState [ orientationKey ] . toBool ( ) ) ;
else
m_orientationModeAction - > action ( ) - > setChecked ( false ) ;
2020-03-27 20:16:29 +02:00
2020-02-11 11:33:25 +02:00
if ( sceneState . contains ( editLightKey ) )
m_editLightAction - > action ( ) - > setChecked ( sceneState [ editLightKey ] . toBool ( ) ) ;
else
m_editLightAction - > action ( ) - > setChecked ( false ) ;
2020-03-27 20:16:29 +02:00
if ( sceneState . contains ( gridKey ) )
m_showGridAction - > action ( ) - > setChecked ( sceneState [ gridKey ] . toBool ( ) ) ;
else
m_showGridAction - > action ( ) - > setChecked ( false ) ;
2021-11-15 14:23:06 +02:00
2022-01-21 17:15:01 +02:00
if ( sceneState . contains ( selectionBoxKey ) )
m_showSelectionBoxAction - > action ( ) - > setChecked ( sceneState [ selectionBoxKey ] . toBool ( ) ) ;
else
m_showSelectionBoxAction - > action ( ) - > setChecked ( false ) ;
if ( sceneState . contains ( iconGizmoKey ) )
m_showIconGizmoAction - > action ( ) - > setChecked ( sceneState [ iconGizmoKey ] . toBool ( ) ) ;
else
m_showIconGizmoAction - > action ( ) - > setChecked ( false ) ;
if ( sceneState . contains ( cameraFrustumKey ) )
m_showCameraFrustumAction - > action ( ) - > setChecked ( sceneState [ cameraFrustumKey ] . toBool ( ) ) ;
else
m_showCameraFrustumAction - > action ( ) - > setChecked ( false ) ;
2022-02-21 11:26:53 +02:00
if ( sceneState . contains ( particleEmitterKey ) )
m_showParticleEmitterAction - > action ( ) - > setChecked ( sceneState [ particleEmitterKey ] . toBool ( ) ) ;
else
m_showParticleEmitterAction - > action ( ) - > setChecked ( false ) ;
2021-11-15 14:23:06 +02:00
if ( sceneState . contains ( particlesPlayKey ) )
m_particlesPlayAction - > action ( ) - > setChecked ( sceneState [ particlesPlayKey ] . toBool ( ) ) ;
else
m_particlesPlayAction - > action ( ) - > setChecked ( true ) ;
2020-02-11 11:33:25 +02:00
}
2020-03-19 13:05:36 +02:00
void Edit3DView : : modelAttached ( Model * model )
{
AbstractView : : modelAttached ( model ) ;
checkImports ( ) ;
2022-02-09 18:49:40 +01:00
auto cachedImage = m_canvasCache . take ( model ) ;
if ( cachedImage ) {
edit3DWidget ( ) - > canvas ( ) - > updateRenderImage ( * cachedImage ) ;
edit3DWidget ( ) - > canvas ( ) - > setOpacity ( 0.5 ) ;
}
edit3DWidget ( ) - > canvas ( ) - > busyIndicator ( ) - > show ( ) ;
2022-08-25 12:27:41 +03:00
connect ( model - > metaInfo ( ) . itemLibraryInfo ( ) , & ItemLibraryInfo : : entriesChanged , this ,
& Edit3DView : : onEntriesChanged , Qt : : UniqueConnection ) ;
}
void Edit3DView : : onEntriesChanged ( )
{
m_compressionTimer . start ( ) ;
}
void Edit3DView : : handleEntriesChanged ( )
{
2022-08-26 17:45:11 +03:00
if ( ! model ( ) )
return ;
const QString cameras = tr ( " Cameras " ) ;
const QString lights = tr ( " Lights " ) ;
const QString primitives = tr ( " Primitives " ) ;
const QString importedModels = tr ( " Imported Models " ) ;
const QStringList keys { cameras , lights , primitives , importedModels } ; // used to maintain order
QHash < QString , QList < ItemLibraryEntry > > entriesMap {
{ cameras , { } } ,
{ lights , { } } ,
{ primitives , { } } ,
{ importedModels , { } }
2022-08-25 12:27:41 +03:00
} ;
const QList < ItemLibraryEntry > itemLibEntries = model ( ) - > metaInfo ( ) . itemLibraryInfo ( ) - > entries ( ) ;
for ( const ItemLibraryEntry & entry : itemLibEntries ) {
2022-09-09 15:30:56 +03:00
if ( entry . typeName ( ) = = " QtQuick3D.Model " & & entry . name ( ) ! = " Empty " ) {
2022-08-26 17:45:11 +03:00
entriesMap [ primitives ] . append ( entry ) ;
} else if ( entry . typeName ( ) = = " QtQuick3D.DirectionalLight "
| | entry . typeName ( ) = = " QtQuick3D.PointLight "
| | entry . typeName ( ) = = " QtQuick3D.SpotLight " ) {
entriesMap [ lights ] . append ( entry ) ;
} else if ( entry . typeName ( ) = = " QtQuick3D.OrthographicCamera "
| | entry . typeName ( ) = = " QtQuick3D.PerspectiveCamera " ) {
entriesMap [ cameras ] . append ( entry ) ;
} else if ( entry . typeName ( ) . startsWith ( " Quick3DAssets. " )
& & NodeHints : : fromItemLibraryEntry ( entry ) . canBeDroppedInView3D ( ) ) {
entriesMap [ importedModels ] . append ( entry ) ;
}
2022-08-25 12:27:41 +03:00
}
2022-08-26 17:45:11 +03:00
m_edit3DWidget - > updateCreateSubMenu ( keys , entriesMap ) ;
2020-03-19 13:05:36 +02:00
}
2020-03-06 16:14:12 +02:00
void Edit3DView : : modelAboutToBeDetached ( Model * model )
{
2020-03-19 13:05:36 +02:00
// Hide the canvas when model is detached (i.e. changing documents)
2022-05-09 16:35:14 +02:00
if ( edit3DWidget ( ) & & edit3DWidget ( ) - > canvas ( ) ) {
m_canvasCache . insert ( model , edit3DWidget ( ) - > canvas ( ) - > renderImage ( ) ) ;
edit3DWidget ( ) - > showCanvas ( false ) ;
}
2020-03-19 13:05:36 +02:00
AbstractView : : modelAboutToBeDetached ( model ) ;
}
2022-07-07 18:04:18 +02:00
void Edit3DView : : importsChanged ( [[maybe_unused]] const QList < Import > & addedImports ,
[[maybe_unused]] const QList < Import > & removedImports )
2020-03-19 13:05:36 +02:00
{
checkImports ( ) ;
2020-03-06 16:14:12 +02:00
}
2022-07-07 18:04:18 +02:00
void Edit3DView : : customNotification ( [[maybe_unused]] const AbstractView * view ,
const QString & identifier ,
[[maybe_unused]] const QList < ModelNode > & nodeList ,
[[maybe_unused]] const QList < QVariant > & data )
2020-04-21 13:30:44 +03:00
{
if ( identifier = = " asset_import_update " )
resetPuppet ( ) ;
}
2022-08-19 13:04:26 +03:00
/**
2022-09-06 15:10:53 +03:00
* @ brief Get node at position from puppet process
2022-08-19 13:04:26 +03:00
*
* Response from puppet process for the model at requested position
*
2022-09-06 15:10:53 +03:00
* @ param modelNode Node picked at the requested position or invalid node if nothing could be picked
2022-08-19 13:04:26 +03:00
*/
2022-09-06 15:10:53 +03:00
void Edit3DView : : nodeAtPosReady ( const ModelNode & modelNode )
2022-07-01 11:35:09 +03:00
{
2022-09-06 15:10:53 +03:00
if ( m_nodeAtPosReqType = = NodeAtPosReqType : : ContextMenu ) {
2022-08-23 15:19:56 +03:00
// Make sure right-clicked item is selected. Due to a bug in puppet side right-clicking an item
// while the context-menu is shown doesn't select the item.
if ( modelNode . isValid ( ) & & ! modelNode . isSelected ( ) )
setSelectedModelNode ( modelNode ) ;
2022-08-19 13:04:26 +03:00
m_edit3DWidget - > showContextMenu ( m_contextMenuPos , modelNode ) ;
2022-09-06 15:10:53 +03:00
} else if ( m_nodeAtPosReqType = = NodeAtPosReqType : : MaterialDrop ) {
2022-09-13 11:15:16 +02:00
// TODO: this is from 8.0 branch that doesn't apply anymore:
// const bool isModel = modelNode.isSubclassOf("QtQuick3D.Model");
const bool isModel = false ;
if ( m_droppedMaterial . isValid ( ) & & modelNode . isValid ( ) & & isModel ) {
2022-08-19 13:04:26 +03:00
executeInTransaction ( __FUNCTION__ , [ & ] {
assignMaterialTo3dModel ( modelNode , m_droppedMaterial ) ;
} ) ;
}
}
2022-09-06 15:10:53 +03:00
m_nodeAtPosReqType = NodeAtPosReqType : : None ;
2022-07-01 11:35:09 +03:00
}
2020-02-11 11:33:25 +02:00
void Edit3DView : : sendInputEvent ( QInputEvent * e ) const
{
2020-03-13 12:09:02 +02:00
if ( nodeInstanceView ( ) )
nodeInstanceView ( ) - > sendInputEvent ( e ) ;
2020-02-11 11:33:25 +02:00
}
void Edit3DView : : edit3DViewResized ( const QSize & size ) const
{
2020-03-13 12:09:02 +02:00
if ( nodeInstanceView ( ) )
nodeInstanceView ( ) - > edit3DViewResized ( size ) ;
2020-02-11 11:33:25 +02:00
}
QSize Edit3DView : : canvasSize ( ) const
{
if ( ! m_edit3DWidget . isNull ( ) & & m_edit3DWidget - > canvas ( ) )
return m_edit3DWidget - > canvas ( ) - > size ( ) ;
return { } ;
}
2021-10-19 10:04:15 +03:00
void Edit3DView : : setSeeker ( SeekerSlider * slider )
{
m_seeker = slider ;
}
2022-06-08 18:00:09 +03:00
Edit3DAction * Edit3DView : : createSelectBackgrounColorAction ( )
{
QString description = QCoreApplication : : translate ( " SelectBackgroundColorAction " ,
" Select Background Color " ) ;
QString tooltip = QCoreApplication : : translate ( " SelectBackgroundColorAction " ,
" Select a color for the background of the 3D Editor. " ) ;
auto operation = [ this ] ( const SelectionContext & ) {
BackgroundColorSelection : : showBackgroundColorSelectionWidget (
edit3DWidget ( ) ,
DesignerSettingsKey : : EDIT3DVIEW_BACKGROUND_COLOR ,
View3DActionCommand : : SelectBackgroundColor ) ;
} ;
return new Edit3DAction (
Constants : : EDIT3D_EDIT_SELECT_BACKGROUND_COLOR , View3DActionCommand : : SelectBackgroundColor ,
description ,
{ } , false , false , { } , { } , operation ,
tooltip ) ;
}
Edit3DAction * Edit3DView : : createGridColorSelectionAction ( )
{
QString description = QCoreApplication : : translate ( " SelectGridColorAction " , " Select Grid Color " ) ;
QString tooltip = QCoreApplication : : translate ( " SelectGridColorAction " ,
" Select a color for the grid lines of the 3D Editor. " ) ;
auto operation = [ this ] ( const SelectionContext & ) {
BackgroundColorSelection : : showBackgroundColorSelectionWidget (
edit3DWidget ( ) ,
DesignerSettingsKey : : EDIT3DVIEW_GRID_COLOR ,
View3DActionCommand : : SelectGridColor ) ;
} ;
return new Edit3DAction (
Constants : : EDIT3D_EDIT_SELECT_GRID_COLOR , View3DActionCommand : : SelectGridColor ,
description , { } , false , false , { } , { } , operation ,
tooltip ) ;
}
Edit3DAction * Edit3DView : : createResetColorAction ( )
{
QString description = QCoreApplication : : translate ( " ResetEdit3DColorsAction " , " Reset Colors " ) ;
QString tooltip = QCoreApplication : : translate ( " ResetEdit3DColorsAction " ,
" Reset the background color and the color of the "
" grid lines of the 3D Editor to the default valus. " ) ;
auto operation = [ ] ( const SelectionContext & ) {
QList < QColor > bgColors = { QRgb ( 0x222222 ) , QRgb ( 0x999999 ) } ;
Edit3DViewConfig : : set ( View3DActionCommand : : SelectBackgroundColor , bgColors ) ;
Edit3DViewConfig : : save ( DesignerSettingsKey : : EDIT3DVIEW_BACKGROUND_COLOR , bgColors ) ;
QColor gridColor { 0xaaaaaa } ;
Edit3DViewConfig : : set ( View3DActionCommand : : SelectGridColor , gridColor ) ;
Edit3DViewConfig : : save ( DesignerSettingsKey : : EDIT3DVIEW_GRID_COLOR , gridColor ) ;
} ;
return new Edit3DAction (
QmlDesigner : : Constants : : EDIT3D_EDIT_RESET_BACKGROUND_COLOR , View3DActionCommand : : ResetBackgroundColor ,
description ,
{ } , false , false , { } , { } , operation ,
tooltip ) ;
}
2022-06-20 16:06:28 +03:00
Edit3DAction * Edit3DView : : createSyncBackgroundColorAction ( )
{
QString description = QCoreApplication : : translate ( " SyncEdit3DColorAction " ,
" Use Scene Environment Color " ) ;
QString tooltip = QCoreApplication : : translate ( " SyncEdit3DColorAction " ,
" Sets the 3D Editor to use the Scene Environment "
" color as background color. " ) ;
return new Edit3DAction (
QmlDesigner : : Constants : : EDIT3D_EDIT_SYNC_BACKGROUND_COLOR , View3DActionCommand : : SyncBackgroundColor ,
description ,
{ } , true , false , { } , { } , { } ,
tooltip ) ;
}
2020-02-11 11:33:25 +02:00
void Edit3DView : : createEdit3DActions ( )
{
m_selectionModeAction
= new Edit3DAction (
2020-03-20 16:27:55 +02:00
QmlDesigner : : Constants : : EDIT3D_SELECTION_MODE , View3DActionCommand : : SelectionModeToggle ,
2020-03-10 16:45:52 +01:00
QCoreApplication : : translate ( " SelectionModeToggleAction " , " Toggle Group/Single Selection Mode " ) ,
2020-02-11 11:33:25 +02:00
QKeySequence ( Qt : : Key_Q ) , true , false , Icons : : EDIT3D_SELECTION_MODE_OFF . icon ( ) ,
Icons : : EDIT3D_SELECTION_MODE_ON . icon ( ) ) ;
m_moveToolAction
= new Edit3DAction (
2020-03-20 16:27:55 +02:00
QmlDesigner : : Constants : : EDIT3D_MOVE_TOOL , View3DActionCommand : : MoveTool ,
2020-02-11 11:33:25 +02:00
QCoreApplication : : translate ( " MoveToolAction " , " Activate Move Tool " ) ,
QKeySequence ( Qt : : Key_W ) , true , true , Icons : : EDIT3D_MOVE_TOOL_OFF . icon ( ) ,
Icons : : EDIT3D_MOVE_TOOL_ON . icon ( ) ) ;
m_rotateToolAction
= new Edit3DAction (
2020-03-20 16:27:55 +02:00
QmlDesigner : : Constants : : EDIT3D_ROTATE_TOOL , View3DActionCommand : : RotateTool ,
2020-02-11 11:33:25 +02:00
QCoreApplication : : translate ( " RotateToolAction " , " Activate Rotate Tool " ) ,
QKeySequence ( Qt : : Key_E ) , true , false , Icons : : EDIT3D_ROTATE_TOOL_OFF . icon ( ) ,
Icons : : EDIT3D_ROTATE_TOOL_ON . icon ( ) ) ;
m_scaleToolAction
= new Edit3DAction (
2020-03-20 16:27:55 +02:00
QmlDesigner : : Constants : : EDIT3D_SCALE_TOOL , View3DActionCommand : : ScaleTool ,
2020-02-11 11:33:25 +02:00
QCoreApplication : : translate ( " ScaleToolAction " , " Activate Scale Tool " ) ,
QKeySequence ( Qt : : Key_R ) , true , false , Icons : : EDIT3D_SCALE_TOOL_OFF . icon ( ) ,
Icons : : EDIT3D_SCALE_TOOL_ON . icon ( ) ) ;
m_fitAction = new Edit3DAction (
2020-03-20 16:27:55 +02:00
QmlDesigner : : Constants : : EDIT3D_FIT_SELECTED , View3DActionCommand : : FitToView ,
2020-03-10 16:45:52 +01:00
QCoreApplication : : translate ( " FitToViewAction " , " Fit Selected Object to View " ) ,
2020-02-11 11:33:25 +02:00
QKeySequence ( Qt : : Key_F ) , false , false , Icons : : EDIT3D_FIT_SELECTED_OFF . icon ( ) , { } ) ;
2021-08-12 05:31:36 +03:00
m_alignCamerasAction = new Edit3DCameraAction (
QmlDesigner : : Constants : : EDIT3D_ALIGN_CAMERAS , View3DActionCommand : : AlignCamerasToView ,
QCoreApplication : : translate ( " AlignCamerasToViewAction " , " Align Selected Cameras to View " ) ,
QKeySequence ( ) , false , false , Icons : : EDIT3D_ALIGN_CAMERA_ON . icon ( ) , { } ) ;
m_alignViewAction = new Edit3DCameraAction (
QmlDesigner : : Constants : : EDIT3D_ALIGN_VIEW , View3DActionCommand : : AlignViewToCamera ,
QCoreApplication : : translate ( " AlignCamerasToViewAction " , " Align View to Selected Camera " ) ,
QKeySequence ( ) , false , false , Icons : : EDIT3D_ALIGN_VIEW_ON . icon ( ) , { } ) ;
2020-02-11 11:33:25 +02:00
m_cameraModeAction
= new Edit3DAction (
2020-03-20 16:27:55 +02:00
QmlDesigner : : Constants : : EDIT3D_EDIT_CAMERA , View3DActionCommand : : CameraToggle ,
2020-03-10 16:45:52 +01:00
QCoreApplication : : translate ( " CameraToggleAction " , " Toggle Perspective/Orthographic Edit Camera " ) ,
2020-02-11 11:33:25 +02:00
QKeySequence ( Qt : : Key_T ) , true , false , Icons : : EDIT3D_EDIT_CAMERA_OFF . icon ( ) ,
Icons : : EDIT3D_EDIT_CAMERA_ON . icon ( ) ) ;
m_orientationModeAction
= new Edit3DAction (
2020-03-20 16:27:55 +02:00
QmlDesigner : : Constants : : EDIT3D_ORIENTATION , View3DActionCommand : : OrientationToggle ,
2020-03-10 16:45:52 +01:00
QCoreApplication : : translate ( " OrientationToggleAction " , " Toggle Global/Local Orientation " ) ,
2020-02-11 11:33:25 +02:00
QKeySequence ( Qt : : Key_Y ) , true , false , Icons : : EDIT3D_ORIENTATION_OFF . icon ( ) ,
Icons : : EDIT3D_ORIENTATION_ON . icon ( ) ) ;
m_editLightAction
= new Edit3DAction (
2020-03-20 16:27:55 +02:00
QmlDesigner : : Constants : : EDIT3D_EDIT_LIGHT , View3DActionCommand : : EditLightToggle ,
2020-03-10 16:45:52 +01:00
QCoreApplication : : translate ( " EditLightToggleAction " , " Toggle Edit Light On/Off " ) ,
2020-02-11 11:33:25 +02:00
QKeySequence ( Qt : : Key_U ) , true , false , Icons : : EDIT3D_LIGHT_OFF . icon ( ) ,
Icons : : EDIT3D_LIGHT_ON . icon ( ) ) ;
2020-03-27 20:16:29 +02:00
m_showGridAction = new Edit3DAction (
QmlDesigner : : Constants : : EDIT3D_EDIT_SHOW_GRID , View3DActionCommand : : ShowGrid ,
2022-01-21 17:15:01 +02:00
QCoreApplication : : translate ( " ShowGridAction " , " Show Grid " ) ,
QKeySequence ( Qt : : Key_G ) , true , true , { } , { } , nullptr ,
QCoreApplication : : translate ( " ShowGridAction " , " Toggle the visibility of the helper grid. " ) ) ;
m_showSelectionBoxAction = new Edit3DAction (
QmlDesigner : : Constants : : EDIT3D_EDIT_SHOW_SELECTION_BOX , View3DActionCommand : : ShowSelectionBox ,
QCoreApplication : : translate ( " ShowSelectionBoxAction " , " Show Selection Boxes " ) ,
QKeySequence ( Qt : : Key_S ) , true , true , { } , { } , nullptr ,
QCoreApplication : : translate ( " ShowSelectionBoxAction " , " Toggle the visibility of selection boxes. " ) ) ;
m_showIconGizmoAction = new Edit3DAction (
QmlDesigner : : Constants : : EDIT3D_EDIT_SHOW_ICON_GIZMO , View3DActionCommand : : ShowIconGizmo ,
QCoreApplication : : translate ( " ShowIconGizmoAction " , " Show Icon Gizmos " ) ,
QKeySequence ( Qt : : Key_I ) , true , true , { } , { } , nullptr ,
QCoreApplication : : translate ( " ShowIconGizmoAction " , " Toggle the visibility of icon gizmos, such as light and camera icons. " ) ) ;
m_showCameraFrustumAction = new Edit3DAction (
QmlDesigner : : Constants : : EDIT3D_EDIT_SHOW_CAMERA_FRUSTUM , View3DActionCommand : : ShowCameraFrustum ,
QCoreApplication : : translate ( " ShowCameraFrustumAction " , " Always Show Camera Frustums " ) ,
QKeySequence ( Qt : : Key_C ) , true , false , { } , { } , nullptr ,
QCoreApplication : : translate ( " ShowCameraFrustumAction " , " Toggle between always showing the camera frustum visualization and only showing it when the camera is selected. " ) ) ;
2020-03-27 20:16:29 +02:00
2022-02-21 11:26:53 +02:00
m_showParticleEmitterAction = new Edit3DAction (
QmlDesigner : : Constants : : EDIT3D_EDIT_SHOW_PARTICLE_EMITTER , View3DActionCommand : : ShowParticleEmitter ,
2022-03-17 15:44:37 +02:00
QCoreApplication : : translate ( " ShowParticleEmitterAction " , " Always Show Particle Emitters And Attractors " ) ,
2022-02-21 11:26:53 +02:00
QKeySequence ( Qt : : Key_M ) , true , false , { } , { } , nullptr ,
2022-03-17 15:44:37 +02:00
QCoreApplication : : translate ( " ShowParticleEmitterAction " , " Toggle between always showing the particle emitter and attractor visualizations and only showing them when the emitter or attractor is selected. " ) ) ;
2022-02-21 11:26:53 +02:00
2020-02-11 11:33:25 +02:00
SelectionContextOperation resetTrigger = [ this ] ( const SelectionContext & ) {
2021-10-19 10:04:15 +03:00
m_particlesPlayAction - > action ( ) - > setEnabled ( particlemode ) ;
m_particlesRestartAction - > action ( ) - > setEnabled ( particlemode ) ;
if ( particlemode )
m_particlesPlayAction - > action ( ) - > setChecked ( true ) ;
if ( m_seeker )
m_seeker - > setEnabled ( false ) ;
setCurrentStateNode ( rootModelNode ( ) ) ;
resetPuppet ( ) ;
} ;
SelectionContextOperation particlesTrigger = [ this ] ( const SelectionContext & ) {
particlemode = ! particlemode ;
m_particlesPlayAction - > action ( ) - > setEnabled ( particlemode ) ;
m_particlesRestartAction - > action ( ) - > setEnabled ( particlemode ) ;
if ( m_seeker )
m_seeker - > setEnabled ( false ) ;
QmlDesigner : : DesignerSettings : : setValue ( " particleMode " , particlemode ) ;
2020-02-11 11:33:25 +02:00
setCurrentStateNode ( rootModelNode ( ) ) ;
resetPuppet ( ) ;
} ;
2021-10-19 10:04:15 +03:00
SelectionContextOperation particlesPlayTrigger = [ this ] ( const SelectionContext & ) {
if ( m_seeker )
m_seeker - > setEnabled ( ! m_particlesPlayAction - > action ( ) - > isChecked ( ) ) ;
} ;
m_particleViewModeAction
= new Edit3DAction (
QmlDesigner : : Constants : : EDIT3D_PARTICLE_MODE , View3DActionCommand : : Edit3DParticleModeToggle ,
QCoreApplication : : translate ( " ParticleViewModeAction " , " Toggle particle animation On/Off " ) ,
QKeySequence ( Qt : : Key_V ) , true , false , Icons : : EDIT3D_PARTICLE_OFF . icon ( ) ,
Icons : : EDIT3D_PARTICLE_ON . icon ( ) , particlesTrigger ) ;
particlemode = false ;
m_particlesPlayAction
= new Edit3DAction (
QmlDesigner : : Constants : : EDIT3D_PARTICLES_PLAY , View3DActionCommand : : ParticlesPlay ,
QCoreApplication : : translate ( " ParticlesPlayAction " , " Play Particles " ) ,
2022-02-28 11:37:04 +02:00
QKeySequence ( Qt : : Key_Comma ) , true , true , Icons : : EDIT3D_PARTICLE_PLAY . icon ( ) ,
2021-10-19 10:04:15 +03:00
Icons : : EDIT3D_PARTICLE_PAUSE . icon ( ) , particlesPlayTrigger ) ;
m_particlesRestartAction
= new Edit3DAction (
QmlDesigner : : Constants : : EDIT3D_PARTICLES_RESTART , View3DActionCommand : : ParticlesRestart ,
QCoreApplication : : translate ( " ParticlesRestartAction " , " Restart Particles " ) ,
2022-02-28 11:37:04 +02:00
QKeySequence ( Qt : : Key_Slash ) , false , false , Icons : : EDIT3D_PARTICLE_RESTART . icon ( ) ,
2021-11-22 13:32:14 +02:00
Icons : : EDIT3D_PARTICLE_RESTART . icon ( ) ) ;
2021-10-19 10:04:15 +03:00
m_particlesPlayAction - > action ( ) - > setEnabled ( particlemode ) ;
m_particlesRestartAction - > action ( ) - > setEnabled ( particlemode ) ;
2020-02-11 11:33:25 +02:00
m_resetAction
= new Edit3DAction (
2020-03-20 16:27:55 +02:00
QmlDesigner : : Constants : : EDIT3D_RESET_VIEW , View3DActionCommand : : Empty ,
2020-02-11 11:33:25 +02:00
QCoreApplication : : translate ( " ResetView " , " Reset View " ) ,
QKeySequence ( Qt : : Key_P ) , false , false , Utils : : Icons : : RESET_TOOLBAR . icon ( ) , { } ,
resetTrigger ) ;
2022-01-21 17:15:01 +02:00
SelectionContextOperation visibilityTogglesTrigger = [ this ] ( const SelectionContext & ) {
if ( ! edit3DWidget ( ) - > visibilityTogglesMenu ( ) )
return ;
QPoint pos ;
const auto & actionWidgets = m_visibilityTogglesAction - > action ( ) - > associatedWidgets ( ) ;
for ( auto actionWidget : actionWidgets ) {
if ( auto button = qobject_cast < QToolButton * > ( actionWidget ) ) {
pos = button - > mapToGlobal ( QPoint ( 0 , 0 ) ) ;
break ;
}
}
edit3DWidget ( ) - > showVisibilityTogglesMenu ( ! edit3DWidget ( ) - > visibilityTogglesMenu ( ) - > isVisible ( ) ,
pos ) ;
} ;
m_visibilityTogglesAction = new Edit3DAction (
QmlDesigner : : Constants : : EDIT3D_VISIBILITY_TOGGLES , View3DActionCommand : : Empty ,
QCoreApplication : : translate ( " VisibilityTogglesAction " , " Visibility Toggles " ) ,
QKeySequence ( ) , false , false , Utils : : Icons : : EYE_OPEN_TOOLBAR . icon ( ) ,
{ } , visibilityTogglesTrigger ) ;
2022-05-31 16:19:29 +03:00
SelectionContextOperation backgroundColorActionsTrigger = [ this ] ( const SelectionContext & ) {
if ( ! edit3DWidget ( ) - > backgroundColorMenu ( ) )
return ;
QPoint pos ;
const auto & actionWidgets = m_backgrondColorMenuAction - > action ( ) - > associatedWidgets ( ) ;
for ( auto actionWidget : actionWidgets ) {
if ( auto button = qobject_cast < QToolButton * > ( actionWidget ) ) {
pos = button - > mapToGlobal ( QPoint ( 0 , 0 ) ) ;
break ;
}
}
edit3DWidget ( ) - > showBackgroundColorMenu ( ! edit3DWidget ( ) - > backgroundColorMenu ( ) - > isVisible ( ) ,
pos ) ;
} ;
m_backgrondColorMenuAction = new Edit3DAction (
QmlDesigner : : Constants : : EDIT3D_BACKGROUND_COLOR_ACTIONS , View3DActionCommand : : Empty ,
QCoreApplication : : translate ( " BackgroundColorMenuActions " , " Background Color Actions " ) ,
QKeySequence ( ) , false , false , Icons : : COLOR_PALETTE . icon ( ) ,
{ } , backgroundColorActionsTrigger ) ;
2020-02-11 11:33:25 +02:00
m_leftActions < < m_selectionModeAction ;
m_leftActions < < nullptr ; // Null indicates separator
m_leftActions < < nullptr ; // Second null after separator indicates an exclusive group
m_leftActions < < m_moveToolAction ;
m_leftActions < < m_rotateToolAction ;
m_leftActions < < m_scaleToolAction ;
m_leftActions < < nullptr ;
m_leftActions < < m_fitAction ;
m_leftActions < < nullptr ;
m_leftActions < < m_cameraModeAction ;
m_leftActions < < m_orientationModeAction ;
m_leftActions < < m_editLightAction ;
2021-08-12 05:31:36 +03:00
m_leftActions < < nullptr ;
m_leftActions < < m_alignCamerasAction ;
m_leftActions < < m_alignViewAction ;
2022-01-21 17:15:01 +02:00
m_leftActions < < nullptr ;
m_leftActions < < m_visibilityTogglesAction ;
2022-05-31 16:19:29 +03:00
m_leftActions < < nullptr ;
m_leftActions < < m_backgrondColorMenuAction ;
2020-02-11 11:33:25 +02:00
2021-10-19 10:04:15 +03:00
m_rightActions < < m_particleViewModeAction ;
m_rightActions < < m_particlesPlayAction ;
m_rightActions < < m_particlesRestartAction ;
m_rightActions < < nullptr ;
2020-02-11 11:33:25 +02:00
m_rightActions < < m_resetAction ;
2022-01-21 17:15:01 +02:00
m_visibilityToggleActions < < m_showGridAction ;
m_visibilityToggleActions < < m_showSelectionBoxAction ;
m_visibilityToggleActions < < m_showIconGizmoAction ;
m_visibilityToggleActions < < m_showCameraFrustumAction ;
2022-02-21 11:26:53 +02:00
m_visibilityToggleActions < < m_showParticleEmitterAction ;
2022-05-31 16:19:29 +03:00
2022-06-08 18:00:09 +03:00
m_backgroundColorActions < < createSelectBackgrounColorAction ( ) ;
m_backgroundColorActions < < createGridColorSelectionAction ( ) ;
2022-06-20 16:06:28 +03:00
m_backgroundColorActions < < createSyncBackgroundColorAction ( ) ;
2022-06-08 18:00:09 +03:00
m_backgroundColorActions < < createResetColorAction ( ) ;
2020-02-11 11:33:25 +02:00
}
QVector < Edit3DAction * > Edit3DView : : leftActions ( ) const
{
return m_leftActions ;
}
QVector < Edit3DAction * > Edit3DView : : rightActions ( ) const
{
return m_rightActions ;
}
2022-01-21 17:15:01 +02:00
QVector < Edit3DAction * > Edit3DView : : visibilityToggleActions ( ) const
{
return m_visibilityToggleActions ;
}
2022-05-31 16:19:29 +03:00
QVector < Edit3DAction * > Edit3DView : : backgroundColorActions ( ) const
{
return m_backgroundColorActions ;
}
2020-03-19 13:05:36 +02:00
void Edit3DView : : addQuick3DImport ( )
{
2021-11-02 15:05:11 +02:00
DesignDocument * document = QmlDesignerPlugin : : instance ( ) - > currentDesignDocument ( ) ;
if ( document & & ! document - > inFileComponentModelActive ( ) & & model ( ) ) {
2020-04-24 12:21:35 +03:00
const QList < Import > imports = model ( ) - > possibleImports ( ) ;
for ( const auto & import : imports ) {
if ( import . url ( ) = = " QtQuick3D " ) {
2021-06-07 17:36:07 +03:00
if ( ! import . version ( ) . isEmpty ( ) & & import . majorVersion ( ) > = 6 ) {
// Prefer empty version number in Qt6 and beyond
model ( ) - > changeImports ( { Import : : createLibraryImport (
import . url ( ) , { } , import . alias ( ) ,
import . importPaths ( ) ) } , { } ) ;
} else {
model ( ) - > changeImports ( { import } , { } ) ;
}
2020-04-24 12:21:35 +03:00
return ;
}
2020-03-19 13:05:36 +02:00
}
}
Core : : AsynchronousMessageBox : : warning ( tr ( " Failed to Add Import " ) ,
tr ( " Could not add QtQuick3D import to project. " ) ) ;
}
2022-08-19 13:04:26 +03:00
// This method is called upon right-clicking the view to prepare for context-menu creation. The actual
2022-09-06 15:10:53 +03:00
// context menu is created when nodeAtPosReady() is received from puppet
2022-08-19 13:04:26 +03:00
void Edit3DView : : startContextMenu ( const QPoint & pos )
{
m_contextMenuPos = pos ;
2022-09-06 15:10:53 +03:00
m_nodeAtPosReqType = NodeAtPosReqType : : ContextMenu ;
2022-08-19 13:04:26 +03:00
}
2022-07-01 11:35:09 +03:00
void Edit3DView : : dropMaterial ( const ModelNode & matNode , const QPointF & pos )
{
2022-09-06 15:10:53 +03:00
m_nodeAtPosReqType = NodeAtPosReqType : : MaterialDrop ;
2022-07-01 11:35:09 +03:00
m_droppedMaterial = matNode ;
2022-09-06 15:10:53 +03:00
QmlDesignerPlugin : : instance ( ) - > viewManager ( ) . nodeInstanceView ( ) - > view3DAction ( { View3DActionCommand : : GetNodeAtPos , pos } ) ;
2020-02-11 11:33:25 +02:00
}
2022-07-01 11:35:09 +03:00
} // namespace QmlDesigner