CommandCanvasSize.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "EditorCommon.h"
  9. #include "CommandCanvasSize.h"
  10. CommandCanvasSize::CommandCanvasSize(UndoStack* stack,
  11. CanvasSizeToolbarSection* canvasSizeToolbar,
  12. AZ::Vector2 from,
  13. AZ::Vector2 to,
  14. bool fromPreset)
  15. : QUndoCommand()
  16. , m_stack(stack)
  17. , m_canvasSizeToolbar(canvasSizeToolbar)
  18. , m_from(from)
  19. , m_to(to)
  20. , m_fromPreset(fromPreset)
  21. {
  22. UpdateText();
  23. }
  24. void CommandCanvasSize::undo()
  25. {
  26. UndoStackExecutionScope s(m_stack);
  27. SetSize(m_from, m_fromPreset);
  28. }
  29. void CommandCanvasSize::redo()
  30. {
  31. UndoStackExecutionScope s(m_stack);
  32. SetSize(m_to, false);
  33. }
  34. void CommandCanvasSize::UpdateText()
  35. {
  36. QString description(
  37. QString("%1 x %2 (%3)")
  38. .arg(QString::number(m_to.GetX()))
  39. .arg(QString::number(m_to.GetY()))
  40. .arg("custom"));
  41. setText(QString("canvas size change to %1").arg(description));
  42. }
  43. void CommandCanvasSize::SetSize(AZ::Vector2 size, bool fromPreset) const
  44. {
  45. // IMPORTANT: It's NOT necessary to prevent this from executing on the
  46. // first run. We WON'T get a redundant Qt notification by this point.
  47. m_canvasSizeToolbar->SetCustomCanvasSize(size, fromPreset);
  48. }
  49. void CommandCanvasSize::Push(UndoStack* stack,
  50. CanvasSizeToolbarSection* canvasSizeToolbar,
  51. AZ::Vector2 from,
  52. AZ::Vector2 to,
  53. bool fromPreset)
  54. {
  55. if (stack->GetIsExecuting())
  56. {
  57. // This is a redundant Qt notification.
  58. // Nothing else to do.
  59. return;
  60. }
  61. stack->push(new CommandCanvasSize(stack, canvasSizeToolbar, from, to, fromPreset));
  62. }