forked from qt-creator/qt-creator
QmlDesigner: Add "Group/Single selection" to the 3D context menu
- "Toggle Group/Single selection mode" option is added to the 3D Editor's context menu. - All 3D actions are pushed into a map and are accessible by View3DActionType as the key. Task-number: QDS-8200 Change-Id: Ia5071ef8901b926ee4e4889fd840fc49c859bccd Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "edit3dactions.h"
|
#include "edit3dactions.h"
|
||||||
#include "edit3dview.h"
|
#include "edit3dview.h"
|
||||||
#include "edit3dwidget.h"
|
|
||||||
|
|
||||||
#include <viewmanager.h>
|
#include <viewmanager.h>
|
||||||
#include <nodeinstanceview.h>
|
#include <nodeinstanceview.h>
|
||||||
@@ -18,7 +17,7 @@ namespace QmlDesigner {
|
|||||||
|
|
||||||
Edit3DActionTemplate::Edit3DActionTemplate(const QString &description,
|
Edit3DActionTemplate::Edit3DActionTemplate(const QString &description,
|
||||||
SelectionContextOperation action,
|
SelectionContextOperation action,
|
||||||
AbstractView *view,
|
Edit3DView *view,
|
||||||
View3DActionType type)
|
View3DActionType type)
|
||||||
: DefaultAction(description)
|
: DefaultAction(description)
|
||||||
, m_action(action)
|
, m_action(action)
|
||||||
@@ -45,12 +44,14 @@ Edit3DAction::Edit3DAction(const QByteArray &menuId,
|
|||||||
bool checked,
|
bool checked,
|
||||||
const QIcon &iconOff,
|
const QIcon &iconOff,
|
||||||
const QIcon &iconOn,
|
const QIcon &iconOn,
|
||||||
AbstractView *view,
|
Edit3DView *view,
|
||||||
SelectionContextOperation selectionAction,
|
SelectionContextOperation selectionAction,
|
||||||
const QString &toolTip)
|
const QString &toolTip)
|
||||||
: AbstractAction(new Edit3DActionTemplate(description, selectionAction, view, type))
|
: AbstractAction(new Edit3DActionTemplate(description, selectionAction, view, type))
|
||||||
, m_menuId(menuId)
|
, m_menuId(menuId)
|
||||||
|
, m_actionTemplate(qobject_cast<Edit3DActionTemplate *>(defaultAction()))
|
||||||
{
|
{
|
||||||
|
view->registerEdit3DAction(this);
|
||||||
action()->setShortcut(key);
|
action()->setShortcut(key);
|
||||||
action()->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
action()->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
||||||
action()->setCheckable(checkable);
|
action()->setCheckable(checkable);
|
||||||
@@ -73,11 +74,21 @@ Edit3DAction::Edit3DAction(const QByteArray &menuId,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Edit3DAction::~Edit3DAction()
|
||||||
|
{
|
||||||
|
m_actionTemplate->m_view->unregisterEdit3DAction(this);
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray Edit3DAction::category() const
|
QByteArray Edit3DAction::category() const
|
||||||
{
|
{
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
View3DActionType Edit3DAction::actionType() const
|
||||||
|
{
|
||||||
|
return m_actionTemplate->m_type;
|
||||||
|
}
|
||||||
|
|
||||||
bool Edit3DAction::isVisible([[maybe_unused]] const SelectionContext &selectionContext) const
|
bool Edit3DAction::isVisible([[maybe_unused]] const SelectionContext &selectionContext) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@@ -96,7 +107,7 @@ Edit3DCameraAction::Edit3DCameraAction(const QByteArray &menuId,
|
|||||||
bool checked,
|
bool checked,
|
||||||
const QIcon &iconOff,
|
const QIcon &iconOff,
|
||||||
const QIcon &iconOn,
|
const QIcon &iconOn,
|
||||||
AbstractView *view,
|
Edit3DView *view,
|
||||||
SelectionContextOperation selectionAction)
|
SelectionContextOperation selectionAction)
|
||||||
: Edit3DAction(menuId, type, description, key, checkable, checked, iconOff, iconOn, view, selectionAction)
|
: Edit3DAction(menuId, type, description, key, checkable, checked, iconOff, iconOn, view, selectionAction)
|
||||||
{
|
{
|
||||||
|
@@ -10,19 +10,22 @@
|
|||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
using SelectionContextOperation = std::function<void(const SelectionContext &)>;
|
using SelectionContextOperation = std::function<void(const SelectionContext &)>;
|
||||||
|
class Edit3DView;
|
||||||
|
|
||||||
class Edit3DActionTemplate : public DefaultAction
|
class Edit3DActionTemplate : public DefaultAction
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Edit3DActionTemplate(const QString &description,
|
Edit3DActionTemplate(const QString &description,
|
||||||
SelectionContextOperation action,
|
SelectionContextOperation action,
|
||||||
AbstractView *view,
|
Edit3DView *view,
|
||||||
View3DActionType type);
|
View3DActionType type);
|
||||||
|
|
||||||
void actionTriggered(bool b) override;
|
void actionTriggered(bool b) override;
|
||||||
|
|
||||||
SelectionContextOperation m_action;
|
SelectionContextOperation m_action;
|
||||||
AbstractView *m_view;
|
Edit3DView *m_view = nullptr;
|
||||||
View3DActionType m_type;
|
View3DActionType m_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -37,10 +40,12 @@ public:
|
|||||||
bool checked,
|
bool checked,
|
||||||
const QIcon &iconOff,
|
const QIcon &iconOff,
|
||||||
const QIcon &iconOn,
|
const QIcon &iconOn,
|
||||||
AbstractView *view,
|
Edit3DView *view,
|
||||||
SelectionContextOperation selectionAction = nullptr,
|
SelectionContextOperation selectionAction = nullptr,
|
||||||
const QString &toolTip = {});
|
const QString &toolTip = {});
|
||||||
|
|
||||||
|
virtual ~Edit3DAction();
|
||||||
|
|
||||||
QByteArray category() const override;
|
QByteArray category() const override;
|
||||||
|
|
||||||
int priority() const override
|
int priority() const override
|
||||||
@@ -58,12 +63,15 @@ public:
|
|||||||
return m_menuId;
|
return m_menuId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
View3DActionType actionType() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool isVisible(const SelectionContext &selectionContext) const override;
|
bool isVisible(const SelectionContext &selectionContext) const override;
|
||||||
bool isEnabled(const SelectionContext &selectionContext) const override;
|
bool isEnabled(const SelectionContext &selectionContext) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QByteArray m_menuId;
|
QByteArray m_menuId;
|
||||||
|
Edit3DActionTemplate *m_actionTemplate = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Edit3DCameraAction : public Edit3DAction
|
class Edit3DCameraAction : public Edit3DAction
|
||||||
@@ -77,7 +85,7 @@ public:
|
|||||||
bool checked,
|
bool checked,
|
||||||
const QIcon &iconOff,
|
const QIcon &iconOff,
|
||||||
const QIcon &iconOn,
|
const QIcon &iconOn,
|
||||||
AbstractView *view,
|
Edit3DView *view,
|
||||||
SelectionContextOperation selectionAction = nullptr);
|
SelectionContextOperation selectionAction = nullptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@@ -38,7 +38,9 @@ Edit3DView::Edit3DView(ExternalDependenciesInterface &externalDependencies)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Edit3DView::~Edit3DView()
|
Edit3DView::~Edit3DView()
|
||||||
{}
|
{
|
||||||
|
qDeleteAll(m_edit3DActions);
|
||||||
|
}
|
||||||
|
|
||||||
void Edit3DView::createEdit3DWidget()
|
void Edit3DView::createEdit3DWidget()
|
||||||
{
|
{
|
||||||
@@ -197,6 +199,31 @@ void Edit3DView::onEntriesChanged()
|
|||||||
m_compressionTimer.start();
|
m_compressionTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Edit3DView::registerEdit3DAction(Edit3DAction *action)
|
||||||
|
{
|
||||||
|
View3DActionType actionType = action->actionType();
|
||||||
|
if (actionType == View3DActionType::Empty)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_edit3DActions.contains(actionType)) {
|
||||||
|
Edit3DAction *formerAction = m_edit3DActions.value(actionType);
|
||||||
|
if (formerAction == action)
|
||||||
|
return;
|
||||||
|
|
||||||
|
qWarning() << Q_FUNC_INFO << __LINE__ << "Reregistering action for" << int(actionType);
|
||||||
|
delete formerAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_edit3DActions.insert(actionType, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Edit3DView::unregisterEdit3DAction(Edit3DAction *action)
|
||||||
|
{
|
||||||
|
View3DActionType actionType = action->actionType();
|
||||||
|
if (m_edit3DActions.value(actionType, nullptr) == action)
|
||||||
|
m_edit3DActions.remove(actionType);
|
||||||
|
}
|
||||||
|
|
||||||
void Edit3DView::handleEntriesChanged()
|
void Edit3DView::handleEntriesChanged()
|
||||||
{
|
{
|
||||||
if (!model())
|
if (!model())
|
||||||
@@ -812,6 +839,11 @@ QVector<Edit3DAction *> Edit3DView::backgroundColorActions() const
|
|||||||
return m_backgroundColorActions;
|
return m_backgroundColorActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Edit3DAction *Edit3DView::edit3DAction(View3DActionType type) const
|
||||||
|
{
|
||||||
|
return m_edit3DActions.value(type, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
void Edit3DView::addQuick3DImport()
|
void Edit3DView::addQuick3DImport()
|
||||||
{
|
{
|
||||||
DesignDocument *document = QmlDesignerPlugin::instance()->currentDesignDocument();
|
DesignDocument *document = QmlDesignerPlugin::instance()->currentDesignDocument();
|
||||||
|
@@ -57,6 +57,7 @@ public:
|
|||||||
QVector<Edit3DAction *> rightActions() const;
|
QVector<Edit3DAction *> rightActions() const;
|
||||||
QVector<Edit3DAction *> visibilityToggleActions() const;
|
QVector<Edit3DAction *> visibilityToggleActions() const;
|
||||||
QVector<Edit3DAction *> backgroundColorActions() const;
|
QVector<Edit3DAction *> backgroundColorActions() const;
|
||||||
|
Edit3DAction *edit3DAction(View3DActionType type) const;
|
||||||
void setSeeker(SeekerSlider *slider);
|
void setSeeker(SeekerSlider *slider);
|
||||||
|
|
||||||
void addQuick3DImport();
|
void addQuick3DImport();
|
||||||
@@ -77,6 +78,9 @@ private:
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void registerEdit3DAction(Edit3DAction *action);
|
||||||
|
void unregisterEdit3DAction(Edit3DAction *action);
|
||||||
|
|
||||||
void createEdit3DWidget();
|
void createEdit3DWidget();
|
||||||
void checkImports();
|
void checkImports();
|
||||||
void handleEntriesChanged();
|
void handleEntriesChanged();
|
||||||
@@ -92,6 +96,7 @@ private:
|
|||||||
QVector<Edit3DAction *> m_rightActions;
|
QVector<Edit3DAction *> m_rightActions;
|
||||||
QVector<Edit3DAction *> m_visibilityToggleActions;
|
QVector<Edit3DAction *> m_visibilityToggleActions;
|
||||||
QVector<Edit3DAction *> m_backgroundColorActions;
|
QVector<Edit3DAction *> m_backgroundColorActions;
|
||||||
|
QMap<View3DActionType, Edit3DAction *> m_edit3DActions;
|
||||||
Edit3DAction *m_selectionModeAction = nullptr;
|
Edit3DAction *m_selectionModeAction = nullptr;
|
||||||
Edit3DAction *m_moveToolAction = nullptr;
|
Edit3DAction *m_moveToolAction = nullptr;
|
||||||
Edit3DAction *m_rotateToolAction = nullptr;
|
Edit3DAction *m_rotateToolAction = nullptr;
|
||||||
@@ -120,6 +125,8 @@ private:
|
|||||||
NodeAtPosReqType m_nodeAtPosReqType;
|
NodeAtPosReqType m_nodeAtPosReqType;
|
||||||
QPoint m_contextMenuPos;
|
QPoint m_contextMenuPos;
|
||||||
QTimer m_compressionTimer;
|
QTimer m_compressionTimer;
|
||||||
|
|
||||||
|
friend class Edit3DAction;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -232,6 +232,14 @@ void Edit3DWidget::createContextMenu()
|
|||||||
view()->setSelectedModelNode(parentNode);
|
view()->setSelectedModelNode(parentNode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QAction *defaultToggleGroupAction = view()->edit3DAction(View3DActionType::SelectionModeToggle)->action();
|
||||||
|
m_toggleGroupAction = m_contextMenu->addAction(tr("Group Selection Mode"), [&](const bool &mode) {
|
||||||
|
view()->edit3DAction(View3DActionType::SelectionModeToggle)->action()->trigger();
|
||||||
|
});
|
||||||
|
connect(defaultToggleGroupAction, &QAction::toggled, m_toggleGroupAction, &QAction::setChecked);
|
||||||
|
m_toggleGroupAction->setCheckable(true);
|
||||||
|
m_toggleGroupAction->setChecked(defaultToggleGroupAction->isChecked());
|
||||||
|
|
||||||
m_contextMenu->addSeparator();
|
m_contextMenu->addSeparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,6 +384,7 @@ void Edit3DWidget::showContextMenu(const QPoint &pos, const ModelNode &modelNode
|
|||||||
m_alignCameraAction->setEnabled(isCamera);
|
m_alignCameraAction->setEnabled(isCamera);
|
||||||
m_alignViewAction->setEnabled(isCamera);
|
m_alignViewAction->setEnabled(isCamera);
|
||||||
m_selectParentAction->setEnabled(selectionExcludingRoot);
|
m_selectParentAction->setEnabled(selectionExcludingRoot);
|
||||||
|
m_toggleGroupAction->setEnabled(true);
|
||||||
|
|
||||||
m_contextMenu->popup(mapToGlobal(pos));
|
m_contextMenu->popup(mapToGlobal(pos));
|
||||||
}
|
}
|
||||||
|
@@ -72,6 +72,7 @@ private:
|
|||||||
QPointer<QAction> m_alignCameraAction;
|
QPointer<QAction> m_alignCameraAction;
|
||||||
QPointer<QAction> m_alignViewAction;
|
QPointer<QAction> m_alignViewAction;
|
||||||
QPointer<QAction> m_selectParentAction;
|
QPointer<QAction> m_selectParentAction;
|
||||||
|
QPointer<QAction> m_toggleGroupAction;
|
||||||
QPointer<QMenu> m_createSubMenu;
|
QPointer<QMenu> m_createSubMenu;
|
||||||
ModelNode m_contextMenuTarget;
|
ModelNode m_contextMenuTarget;
|
||||||
QVector3D m_contextMenuPos3d;
|
QVector3D m_contextMenuPos3d;
|
||||||
|
Reference in New Issue
Block a user