[calligra/krita-animation-pentikainen] krita/ui: FEATURE: Allow switching frames using arrow keys

Dmitry Kazakov dimula73 at gmail.com
Fri Dec 18 15:45:14 UTC 2015


Git commit 804635bb7958dcf07bf4cdef26e1ccfd8ad458cc by Dmitry Kazakov.
Committed on 18/12/2015 at 15:45.
Pushed by dkazakov into branch 'krita-animation-pentikainen'.

FEATURE: Allow switching frames using arrow keys

Now *of the active layer is animated* Krita will switch the current
frame to and fro using Arrow keys of the keyboard

CC:kimageshop at kde.org

M  +1    -0    krita/ui/CMakeLists.txt
M  +5    -0    krita/ui/input/kis_abstract_input_action.cpp
M  +8    -0    krita/ui/input/kis_abstract_input_action.h
M  +8    -0    krita/ui/input/kis_abstract_shortcut.cpp
M  +5    -0    krita/ui/input/kis_abstract_shortcut.h
A  +78   -0    krita/ui/input/kis_change_frame_action.cpp     [License: GPL (v2+)]
A  +47   -0    krita/ui/input/kis_change_frame_action.h     [License: GPL (v2+)]
M  +2    -0    krita/ui/input/kis_input_profile_manager.cpp
M  +4    -2    krita/ui/input/kis_shortcut_matcher.cpp

http://commits.kde.org/calligra/804635bb7958dcf07bf4cdef26e1ccfd8ad458cc

diff --git a/krita/ui/CMakeLists.txt b/krita/ui/CMakeLists.txt
index 23b7f6c..62c56ae 100644
--- a/krita/ui/CMakeLists.txt
+++ b/krita/ui/CMakeLists.txt
@@ -244,6 +244,7 @@ set(kritaui_LIB_SRCS
     input/kis_alternate_invocation_action.cpp
     input/kis_rotate_canvas_action.cpp
     input/kis_zoom_action.cpp
+    input/kis_change_frame_action.cpp
     input/kis_gamma_exposure_action.cpp
     input/kis_show_palette_action.cpp
     input/kis_change_primary_setting_action.cpp
diff --git a/krita/ui/input/kis_abstract_input_action.cpp b/krita/ui/input/kis_abstract_input_action.cpp
index ac74c3e..d8d8c6d 100644
--- a/krita/ui/input/kis_abstract_input_action.cpp
+++ b/krita/ui/input/kis_abstract_input_action.cpp
@@ -156,3 +156,8 @@ bool KisAbstractInputAction::isShortcutRequired(int shortcut) const
     Q_UNUSED(shortcut);
     return false;
 }
+
+bool KisAbstractInputAction::isAvailable() const
+{
+    return true;
+}
diff --git a/krita/ui/input/kis_abstract_input_action.h b/krita/ui/input/kis_abstract_input_action.h
index fb30e3d..cd2fbbd 100644
--- a/krita/ui/input/kis_abstract_input_action.h
+++ b/krita/ui/input/kis_abstract_input_action.h
@@ -161,6 +161,14 @@ public:
      */
     virtual bool isShortcutRequired(int shortcut) const;
 
+    /**
+     * Some of the actions are available in particular sutiations
+     * only.  E.g. switch frame action is available iff a animated
+     * layer is selected. If isAvailable() returns true then the
+     * action will *not* be triggered by the shortcut matcher.
+     */
+    virtual bool isAvailable() const;
+
 protected:
     /**
      * The input manager this action belongs to.
diff --git a/krita/ui/input/kis_abstract_shortcut.cpp b/krita/ui/input/kis_abstract_shortcut.cpp
index 3f915d5..7e68535 100644
--- a/krita/ui/input/kis_abstract_shortcut.cpp
+++ b/krita/ui/input/kis_abstract_shortcut.cpp
@@ -18,6 +18,9 @@
 
 #include "kis_abstract_shortcut.h"
 
+#include "kis_abstract_input_action.h"
+
+
 class KisAbstractShortcut::Private
 {
 public:
@@ -62,3 +65,8 @@ bool KisAbstractShortcut::compareKeys(const QList<Qt::Key> &keys1,
     }
     return true;
 }
+
+bool KisAbstractShortcut::isAvailable() const
+{
+    return action()->isAvailable();
+}
diff --git a/krita/ui/input/kis_abstract_shortcut.h b/krita/ui/input/kis_abstract_shortcut.h
index 29085d5..0e72765 100644
--- a/krita/ui/input/kis_abstract_shortcut.h
+++ b/krita/ui/input/kis_abstract_shortcut.h
@@ -55,6 +55,11 @@ public:
      */
     int shortcutIndex() const;
 
+    /**
+     * Returns true if the shortcut is enabled at the moment
+     */
+    bool isAvailable() const;
+
 protected:
     bool compareKeys(const QList<Qt::Key> &keys1,
                      const QList<Qt::Key> &keys2);
diff --git a/krita/ui/input/kis_change_frame_action.cpp b/krita/ui/input/kis_change_frame_action.cpp
new file mode 100644
index 0000000..905f114
--- /dev/null
+++ b/krita/ui/input/kis_change_frame_action.cpp
@@ -0,0 +1,78 @@
+/*
+ *  Copyright (c) 2015 Dmitry Kazakov <dimula73 at gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "kis_change_frame_action.h"
+
+#include <klocale.h>
+#include "kis_action.h"
+#include "kis_input_manager.h"
+#include "kis_canvas2.h"
+#include "KisViewManager.h"
+#include "kis_action_manager.h"
+#include "kis_node.h"
+
+
+struct KisChangeFrameAction::Private
+{
+};
+
+KisChangeFrameAction::KisChangeFrameAction()
+    : KisAbstractInputAction("Switch Time"),
+      m_d(new Private)
+{
+    setName(i18n("Switch Time"));
+    setDescription(i18n("The <i>Switch Time</i> action changes the current time of the image."));
+
+    QHash< QString, int > shortcuts;
+    shortcuts.insert(i18n("Next Frame"), NextFrameShortcut);
+    shortcuts.insert(i18n("Previous Frame"), PreviousFrameShortcut);
+    setShortcutIndexes(shortcuts);
+}
+
+KisChangeFrameAction::~KisChangeFrameAction()
+{
+}
+
+bool KisChangeFrameAction::isAvailable() const
+{
+    KisNodeSP node = inputManager()->canvas()->viewManager()->activeNode();
+
+    return node ? node->isAnimated() : false;
+}
+
+void KisChangeFrameAction::begin(int shortcut, QEvent *event)
+{
+    KisAbstractInputAction::begin(shortcut, event);
+
+    switch(shortcut) {
+    case NextFrameShortcut: {
+        KisAction *action = inputManager()->canvas()->viewManager()->actionManager()->actionByName("next_frame");
+        if (action) {
+            action->trigger();
+        }
+        break;
+    }
+    case PreviousFrameShortcut: {
+        KisAction *action = inputManager()->canvas()->viewManager()->actionManager()->actionByName("previous_frame");
+        if (action) {
+            action->trigger();
+        }
+        break;
+    }
+    }
+}
diff --git a/krita/ui/input/kis_change_frame_action.h b/krita/ui/input/kis_change_frame_action.h
new file mode 100644
index 0000000..014e41e
--- /dev/null
+++ b/krita/ui/input/kis_change_frame_action.h
@@ -0,0 +1,47 @@
+/*
+ *  Copyright (c) 2015 Dmitry Kazakov <dimula73 at gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __KIS_CHANGE_FRAME_ACTION_H
+#define __KIS_CHANGE_FRAME_ACTION_H
+
+#include <QScopedPointer>
+
+#include "kis_abstract_input_action.h"
+
+
+class KisChangeFrameAction : public KisAbstractInputAction
+{
+public:
+    enum Shortcuts {
+        NextFrameShortcut,
+        PreviousFrameShortcut
+    };
+
+
+    KisChangeFrameAction();
+    ~KisChangeFrameAction();
+
+    void begin(int shortcut, QEvent *event);
+    bool isAvailable() const;
+
+private:
+    struct Private;
+    const QScopedPointer<Private> m_d;
+};
+
+#endif /* __KIS_CHANGE_FRAME_ACTION_H */
diff --git a/krita/ui/input/kis_input_profile_manager.cpp b/krita/ui/input/kis_input_profile_manager.cpp
index 3798617..723ba01 100644
--- a/krita/ui/input/kis_input_profile_manager.cpp
+++ b/krita/ui/input/kis_input_profile_manager.cpp
@@ -41,6 +41,7 @@
 #include "kis_shortcut_configuration.h"
 #include "kis_select_layer_action.h"
 #include "kis_gamma_exposure_action.h"
+#include "kis_change_frame_action.h"
 
 #define PROFILE_VERSION 3
 
@@ -356,6 +357,7 @@ void KisInputProfileManager::Private::createActions()
     actions.append(new KisShowPaletteAction());
     actions.append(new KisSelectLayerAction());
     actions.append(new KisGammaExposureAction());
+    actions.append(new KisChangeFrameAction());
 }
 
 QString KisInputProfileManager::Private::profileFileName(const QString &profileName)
diff --git a/krita/ui/input/kis_shortcut_matcher.cpp b/krita/ui/input/kis_shortcut_matcher.cpp
index 4d282b3..f16797c 100644
--- a/krita/ui/input/kis_shortcut_matcher.cpp
+++ b/krita/ui/input/kis_shortcut_matcher.cpp
@@ -344,7 +344,8 @@ bool KisShortcutMatcher::tryRunSingleActionShortcutImpl(T param, U *event, const
     KisSingleActionShortcut *goodCandidate = 0;
 
     foreach(KisSingleActionShortcut *s, m_d->singleActionShortcuts) {
-        if(s->match(keysState, param) &&
+        if(s->isAvailable() &&
+           s->match(keysState, param) &&
            (!goodCandidate || s->priority() > goodCandidate->priority())) {
 
             goodCandidate = s;
@@ -376,7 +377,8 @@ bool KisShortcutMatcher::tryRunReadyShortcut( Qt::MouseButton button, QMouseEven
     KisStrokeShortcut *goodCandidate = 0;
 
     foreach(KisStrokeShortcut *s, m_d->readyShortcuts) {
-        if (s->matchBegin(button) &&
+        if (s->isAvailable() &&
+            s->matchBegin(button) &&
             (!goodCandidate || s->priority() > goodCandidate->priority())) {
 
             goodCandidate = s;


More information about the kimageshop mailing list