File indexing completed on 2024-06-09 04:21:53

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_switch_current_time_command.h"
0008 
0009 #include "kis_image.h"
0010 #include "kis_image_animation_interface.h"
0011 #include "kis_command_ids.h"
0012 
0013 
0014 KisSwitchCurrentTimeCommand::KisSwitchCurrentTimeCommand(KisImageAnimationInterface *animation, int oldTime, int newTime, KUndo2Command *parent)
0015     : KUndo2Command(kundo2_i18n("Switch current time"), parent),
0016       m_animation(animation),
0017       m_oldTime(oldTime),
0018       m_newTime(newTime)
0019 {
0020 }
0021 
0022 KisSwitchCurrentTimeCommand::~KisSwitchCurrentTimeCommand()
0023 {
0024 }
0025 
0026 int KisSwitchCurrentTimeCommand::id() const
0027 {
0028     return KisCommandUtils::ChangeCurrentTimeId;
0029 }
0030 
0031 bool KisSwitchCurrentTimeCommand::mergeWith(const KUndo2Command* command)
0032 {
0033     const KisSwitchCurrentTimeCommand *other =
0034         dynamic_cast<const KisSwitchCurrentTimeCommand*>(command);
0035 
0036     if (!other || other->id() != id()) {
0037         return false;
0038     }
0039 
0040     m_newTime = other->m_newTime;
0041     return true;
0042 }
0043 
0044 void KisSwitchCurrentTimeCommand::redo()
0045 {
0046     m_animation->requestTimeSwitchNonGUI(m_newTime);
0047 }
0048 
0049 void KisSwitchCurrentTimeCommand::undo()
0050 {
0051     m_animation->requestTimeSwitchNonGUI(m_oldTime);
0052 }