File indexing completed on 2024-12-22 04:12:39

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_change_frame_action.h"
0008 
0009 #include <klocalizedstring.h>
0010 #include "kis_action.h"
0011 #include "kis_input_manager.h"
0012 #include "kis_canvas2.h"
0013 #include "KisViewManager.h"
0014 #include "kis_action_manager.h"
0015 #include "kis_node.h"
0016 
0017 
0018 struct KisChangeFrameAction::Private
0019 {
0020 };
0021 
0022 KisChangeFrameAction::KisChangeFrameAction()
0023     : KisAbstractInputAction("Switch Time"),
0024       m_d(new Private)
0025 {
0026     setName(i18n("Switch Time"));
0027     setDescription(i18n("The <i>Switch Time</i> action changes the current time of the animation."));
0028 
0029     QHash< QString, int > shortcuts;
0030     shortcuts.insert(i18n("Next Frame"), NextFrameShortcut);
0031     shortcuts.insert(i18n("Previous Frame"), PreviousFrameShortcut);
0032     setShortcutIndexes(shortcuts);
0033 }
0034 
0035 KisChangeFrameAction::~KisChangeFrameAction()
0036 {
0037 }
0038 
0039 bool KisChangeFrameAction::isAvailable() const
0040 {
0041     KisNodeSP node = inputManager()->canvas()->viewManager()->activeNode();
0042 
0043     return node ? node->isAnimated() : false;
0044 }
0045 
0046 void KisChangeFrameAction::begin(int shortcut, QEvent *event)
0047 {
0048     KisAbstractInputAction::begin(shortcut, event);
0049 
0050     switch(shortcut) {
0051     case NextFrameShortcut: {
0052         KisAction *action = inputManager()->canvas()->viewManager()->actionManager()->actionByName("next_frame");
0053         if (action) {
0054             action->trigger();
0055         }
0056         break;
0057     }
0058     case PreviousFrameShortcut: {
0059         KisAction *action = inputManager()->canvas()->viewManager()->actionManager()->actionByName("previous_frame");
0060         if (action) {
0061             action->trigger();
0062         }
0063         break;
0064     }
0065     }
0066 }