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
|
|
|
|
|
|
|
|
#include "edit3dactions.h"
|
|
|
|
|
#include "edit3dview.h"
|
|
|
|
|
#include "edit3dwidget.h"
|
|
|
|
|
|
|
|
|
|
#include <viewmanager.h>
|
|
|
|
|
#include <nodeinstanceview.h>
|
|
|
|
|
#include <qmldesignerplugin.h>
|
2021-08-12 05:31:36 +03:00
|
|
|
#include <nodemetainfo.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
2020-02-11 11:33:25 +02:00
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
|
|
Edit3DActionTemplate::Edit3DActionTemplate(const QString &description,
|
|
|
|
|
SelectionContextOperation action,
|
|
|
|
|
View3DActionCommand::Type type)
|
|
|
|
|
: DefaultAction(description),
|
|
|
|
|
m_action(action),
|
|
|
|
|
m_type(type)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
void Edit3DActionTemplate::actionTriggered(bool b)
|
|
|
|
|
{
|
2022-06-08 18:00:09 +03:00
|
|
|
if (m_type != View3DActionCommand::Empty && m_type != View3DActionCommand::SelectBackgroundColor
|
|
|
|
|
&& m_type != View3DActionCommand::SelectGridColor) {
|
2022-05-31 16:19:29 +03:00
|
|
|
auto view = QmlDesignerPlugin::instance()->viewManager().nodeInstanceView();
|
|
|
|
|
View3DActionCommand cmd(m_type, b);
|
|
|
|
|
view->view3DAction(cmd);
|
2020-02-11 11:33:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_action)
|
|
|
|
|
m_action(m_selectionContext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Edit3DAction::Edit3DAction(const QByteArray &menuId, View3DActionCommand::Type type,
|
|
|
|
|
const QString &description, const QKeySequence &key, bool checkable,
|
|
|
|
|
bool checked, const QIcon &iconOff, const QIcon &iconOn,
|
2022-01-21 17:15:01 +02:00
|
|
|
SelectionContextOperation selectionAction, const QString &toolTip)
|
2020-02-11 11:33:25 +02:00
|
|
|
: AbstractAction(new Edit3DActionTemplate(description, selectionAction, type))
|
|
|
|
|
, m_menuId(menuId)
|
|
|
|
|
{
|
|
|
|
|
action()->setShortcut(key);
|
|
|
|
|
action()->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
|
action()->setCheckable(checkable);
|
|
|
|
|
action()->setChecked(checked);
|
2022-01-21 17:15:01 +02:00
|
|
|
|
|
|
|
|
// Description will be used as tooltip by default if no explicit tooltip is provided
|
|
|
|
|
if (!toolTip.isEmpty())
|
|
|
|
|
action()->setToolTip(toolTip);
|
|
|
|
|
|
2020-02-11 11:33:25 +02:00
|
|
|
if (checkable) {
|
|
|
|
|
QIcon onOffIcon;
|
|
|
|
|
const auto onAvail = iconOn.availableSizes(); // Assume both icons have same sizes available
|
|
|
|
|
for (const auto &size : onAvail) {
|
|
|
|
|
onOffIcon.addPixmap(iconOn.pixmap(size), QIcon::Normal, QIcon::On);
|
|
|
|
|
onOffIcon.addPixmap(iconOff.pixmap(size), QIcon::Normal, QIcon::Off);
|
|
|
|
|
}
|
|
|
|
|
action()->setIcon(onOffIcon);
|
|
|
|
|
} else {
|
|
|
|
|
action()->setIcon(iconOff);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray Edit3DAction::category() const
|
|
|
|
|
{
|
|
|
|
|
return QByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-07 18:04:18 +02:00
|
|
|
bool Edit3DAction::isVisible([[maybe_unused]] const SelectionContext &selectionContext) const
|
2020-02-11 11:33:25 +02:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Edit3DAction::isEnabled(const SelectionContext &selectionContext) const
|
|
|
|
|
{
|
|
|
|
|
return isVisible(selectionContext);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-12 05:31:36 +03:00
|
|
|
Edit3DCameraAction::Edit3DCameraAction(const QByteArray &menuId, View3DActionCommand::Type type,
|
|
|
|
|
const QString &description, const QKeySequence &key,
|
|
|
|
|
bool checkable, bool checked, const QIcon &iconOff,
|
|
|
|
|
const QIcon &iconOn,
|
|
|
|
|
SelectionContextOperation selectionAction)
|
|
|
|
|
: Edit3DAction(menuId, type, description, key, checkable, checked, iconOff, iconOn, selectionAction)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Edit3DCameraAction::isEnabled(const SelectionContext &selectionContext) const
|
|
|
|
|
{
|
|
|
|
|
return Utils::anyOf(selectionContext.selectedModelNodes(), [](const ModelNode &node) {
|
2022-08-24 13:11:33 +02:00
|
|
|
return node.isValid() && node.metaInfo().isQtQuick3DCamera();
|
2021-08-12 05:31:36 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 11:33:25 +02:00
|
|
|
}
|
|
|
|
|
|