[krita] krita/ui: FEATURE: Allow switching frames using arrow keys

Dmitry Kazakov dimula73 at gmail.com
Fri Dec 18 16:23:00 UTC 2015


Git commit e187c960fb874d3e9f494cdce63fca19466d03ef by Dmitry Kazakov.
Committed on 18/12/2015 at 16:22.
Pushed by dkazakov into branch 'master'.

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/krita/e187c960fb874d3e9f494cdce63fca19466d03ef

diff --git a/krita/ui/CMakeLists.txt b/krita/ui/CMakeLists.txt
index 76b79a6..efc7910 100644
--- a/krita/ui/CMakeLists.txt
+++ b/krita/ui/CMakeLists.txt
@@ -243,6 +243,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 363d016..fb8efb7 100644
--- a/krita/ui/input/kis_abstract_input_action.cpp
+++ b/krita/ui/input/kis_abstract_input_action.cpp
@@ -204,3 +204,8 @@ QPointF KisAbstractInputAction::eventPosF(const QEvent *event) {
         return QPoint();
     }
 }
+
+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 93b2b17..b887ffd 100644
--- a/krita/ui/input/kis_abstract_input_action.h
+++ b/krita/ui/input/kis_abstract_input_action.h
@@ -159,6 +159,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 6973a98..819fe27 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 Q_DECL_HIDDEN KisAbstractShortcut::Private
 {
 public:
@@ -62,3 +65,8 @@ bool KisAbstractShortcut::compareKeys(const QSet<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 7767c03..13467f2 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 QSet<Qt::Key> &keys1,
                      const QSet<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 e6f183f..1e51547 100644
--- a/krita/ui/input/kis_input_profile_manager.cpp
+++ b/krita/ui/input/kis_input_profile_manager.cpp
@@ -40,6 +40,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 fa525d4..3e19153 100644
--- a/krita/ui/input/kis_shortcut_matcher.cpp
+++ b/krita/ui/input/kis_shortcut_matcher.cpp
@@ -356,7 +356,8 @@ bool KisShortcutMatcher::tryRunSingleActionShortcutImpl(T param, U *event, const
     KisSingleActionShortcut *goodCandidate = 0;
 
     Q_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;
@@ -391,7 +392,8 @@ bool KisShortcutMatcher::tryRunReadyShortcut( Qt::MouseButton button, QEvent* ev
     KisStrokeShortcut *goodCandidate = 0;
 
     Q_FOREACH (KisStrokeShortcut *s, m_d->candidateShortcuts) {
-        if (s->matchBegin(button) &&
+        if (s->isAvailable() &&
+            s->matchBegin(button) &&
             (!goodCandidate || s->priority() > goodCandidate->priority())) {
 
             goodCandidate = s;



More information about the kimageshop mailing list