You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.3 KiB
C++
96 lines
2.3 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
#include "UiCanvasEditor_precompiled.h"
|
|
|
|
#include "EditorCommon.h"
|
|
|
|
CommandViewportInteractionMode::CommandViewportInteractionMode(UndoStack* stack,
|
|
ViewportInteraction* viewportInteraction,
|
|
QAction* from,
|
|
QAction* to)
|
|
: QUndoCommand()
|
|
, m_stack(stack)
|
|
, m_viewportInteraction(viewportInteraction)
|
|
, m_from(from)
|
|
, m_to(to)
|
|
{
|
|
UpdateText();
|
|
}
|
|
|
|
void CommandViewportInteractionMode::undo()
|
|
{
|
|
UndoStackExecutionScope s(m_stack);
|
|
|
|
SetMode(m_from);
|
|
}
|
|
|
|
void CommandViewportInteractionMode::redo()
|
|
{
|
|
UndoStackExecutionScope s(m_stack);
|
|
|
|
SetMode(m_to);
|
|
}
|
|
|
|
int CommandViewportInteractionMode::id() const
|
|
{
|
|
return (int)FusibleCommand::kViewportInteractionMode;
|
|
}
|
|
|
|
bool CommandViewportInteractionMode::mergeWith(const QUndoCommand* other)
|
|
{
|
|
if (other->id() != id())
|
|
{
|
|
// NOT the same command type.
|
|
return false;
|
|
}
|
|
|
|
const CommandViewportInteractionMode* subsequent = static_cast<const CommandViewportInteractionMode*>(other);
|
|
AZ_Assert(subsequent, "No command to merge with");
|
|
|
|
if (!((subsequent->m_stack == m_stack) &&
|
|
(subsequent->m_viewportInteraction == m_viewportInteraction)))
|
|
{
|
|
// NOT the same context.
|
|
return false;
|
|
}
|
|
|
|
m_to = subsequent->m_to;
|
|
|
|
UpdateText();
|
|
|
|
return true;
|
|
}
|
|
|
|
void CommandViewportInteractionMode::UpdateText()
|
|
{
|
|
setText(QString("mode change to %1").arg(ViewportHelpers::InteractionModeToString(m_to->data().toInt())));
|
|
}
|
|
|
|
void CommandViewportInteractionMode::SetMode(QAction* action) const
|
|
{
|
|
action->trigger();
|
|
|
|
// IMPORTANT: It's NOT necessary to prevent this from executing on the
|
|
// first run. We WON'T get a redundant Qt notification by this point.
|
|
m_viewportInteraction->SetMode((ViewportInteraction::InteractionMode)action->data().toInt());
|
|
}
|
|
|
|
void CommandViewportInteractionMode::Push(UndoStack* stack,
|
|
ViewportInteraction* viewportInteraction,
|
|
QAction* from,
|
|
QAction* to)
|
|
{
|
|
if (stack->GetIsExecuting())
|
|
{
|
|
// This is a redundant Qt notification.
|
|
// Nothing else to do.
|
|
return;
|
|
}
|
|
|
|
stack->push(new CommandViewportInteractionMode(stack, viewportInteraction, from, to));
|
|
}
|