[krita] krita: [FEATURE] Implement shortcuts for Properties (F3) and Rename Layer (F2)

Dmitry Kazakov dimula73 at gmail.com
Fri Jan 15 11:45:17 UTC 2016


Git commit 32b04db876eb2234a0ca40248da5a4caad192fc8 by Dmitry Kazakov.
Committed on 15/01/2016 at 11:45.
Pushed by dkazakov into branch 'master'.

[FEATURE] Implement shortcuts for Properties (F3) and Rename Layer (F2)

CC:kimageshop at kde.org

M  +2    -2    krita/krita.action
M  +1    -0    krita/plugins/extensions/dockers/defaultdockers/CMakeLists.txt
M  +27   -59   krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.cpp
M  +1    -2    krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.h
A  +21   -0    krita/plugins/extensions/dockers/defaultdockers/sync_button_and_action.cpp     [License: GPL (v2+)]
A  +52   -0    krita/plugins/extensions/dockers/defaultdockers/sync_button_and_action.h     [License: GPL (v2+)]
M  +1    -4    krita/ui/kis_layer_manager.cc

http://commits.kde.org/krita/32b04db876eb2234a0ca40248da5a4caad192fc8

diff --git a/krita/krita.action b/krita/krita.action
index 707195d..6c520d0e 100644
--- a/krita/krita.action
+++ b/krita/krita.action
@@ -3117,8 +3117,8 @@
       <iconText>Properties</iconText>
       <activationFlags>1000</activationFlags>
       <activationConditions>1</activationConditions>
-      <shortcut></shortcut>
-      <defaultShortcut></defaultShortcut>
+      <shortcut>F3</shortcut>
+      <defaultShortcut>F3</defaultShortcut>
       <isCheckable>false</isCheckable>
       <statusTip></statusTip>
     </Action>
diff --git a/krita/plugins/extensions/dockers/defaultdockers/CMakeLists.txt b/krita/plugins/extensions/dockers/defaultdockers/CMakeLists.txt
index 204fc56..9f0524b 100644
--- a/krita/plugins/extensions/dockers/defaultdockers/CMakeLists.txt
+++ b/krita/plugins/extensions/dockers/defaultdockers/CMakeLists.txt
@@ -3,6 +3,7 @@ add_subdirectory( tests )
 set(kritadefaultdockers_SOURCES 
   kis_layer_box.cpp
   defaultdockers.cpp
+  sync_button_and_action.cpp
 )
 
 set(kritadefaultdockers_PART_HEADERS
diff --git a/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.cpp b/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.cpp
index b3825a5..1fe5291 100644
--- a/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.cpp
+++ b/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.cpp
@@ -76,32 +76,10 @@
 #include "kis_config.h"
 #include "KisView.h"
 #include "krita_utils.h"
+#include "sync_button_and_action.h"
 
 #include "ui_wdglayerbox.h"
 
-class ButtonAction : public KisAction
-{
-public:
-    ButtonAction(QAbstractButton* button, const QIcon& icon, const QString& text, QObject* parent)
-        : KisAction(icon, text, parent)
-        , m_button(button)
-    {
-        connect(m_button, SIGNAL(clicked()), this, SLOT(trigger()));
-    }
-
-    ButtonAction(QAbstractButton* button, QObject* parent) : KisAction(parent) , m_button(button)
-    {
-        connect(m_button, SIGNAL(clicked()), this, SLOT(trigger()));
-    }
-
-    virtual void setActionEnabled(bool enabled) {
-        KisAction::setActionEnabled(enabled);
-        m_button->setEnabled(enabled);
-    }
-private:
-    QAbstractButton* m_button;
-};
-
 inline void KisLayerBox::connectActionToButton(KisViewManager* view, QAbstractButton *button, const QString &id)
 {
     Q_ASSERT(view);
@@ -182,41 +160,6 @@ KisLayerBox::KisLayerBox()
     m_wdgLayerBox->bnDuplicate->setIcon(KisIconUtils::loadIcon("duplicatelayer"));
     m_wdgLayerBox->bnDuplicate->setIconSize(QSize(22, 22));
 
-    m_removeAction  = new ButtonAction(m_wdgLayerBox->bnDelete,
-                                       KisIconUtils::loadIcon("deletelayer"), i18n("&Remove Layer"), this);
-    m_removeAction->setActivationFlags(KisAction::ACTIVE_NODE);
-    m_removeAction->setActivationConditions(KisAction::ACTIVE_NODE_EDITABLE);
-    m_removeAction->setObjectName("remove_layer");
-    m_removeAction->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Delete));
-    connect(m_removeAction, SIGNAL(triggered()), this, SLOT(slotRmClicked()));
-    m_actions.append(m_removeAction);
-
-    KisAction *action  = new ButtonAction(m_wdgLayerBox->bnRaise, this);
-    action->setText(i18n("Move Layer or Mask Up"));
-    action->setActivationFlags(KisAction::ACTIVE_NODE);
-    action->setActivationConditions(KisAction::ACTIVE_NODE_EDITABLE);
-    action->setObjectName("move_layer_up");
-    action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageUp));
-    connect(action, SIGNAL(triggered()), this, SLOT(slotRaiseClicked()));
-    m_actions.append(action);
-
-    action  = new ButtonAction(m_wdgLayerBox->bnLower, this);
-    action->setText(i18n("Move Layer or Mask Down"));
-    action->setActivationFlags(KisAction::ACTIVE_NODE);
-    action->setActivationConditions(KisAction::ACTIVE_NODE_EDITABLE);
-    action->setObjectName("move_layer_down");
-    action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageDown));
-    connect(action, SIGNAL(triggered()), this, SLOT(slotLowerClicked()));
-    m_actions.append(action);
-
-    m_propertiesAction  = new ButtonAction(m_wdgLayerBox->bnProperties,
-                                           KisIconUtils::loadIcon("properties"), i18n("&Properties..."),this);
-    m_propertiesAction->setActivationFlags(KisAction::ACTIVE_NODE);
-    m_propertiesAction->setActivationConditions(KisAction::ACTIVE_NODE_EDITABLE);
-    m_propertiesAction->setObjectName("layer_properties");
-    connect(m_propertiesAction, SIGNAL(triggered()), this, SLOT(slotPropertiesClicked()));
-    m_actions.append(m_propertiesAction);
-
     if (cfg.sliderLabels()) {
         m_wdgLayerBox->opacityLabel->hide();
         m_wdgLayerBox->doubleOpacity->setPrefix(QString("%1:  ").arg(i18n("Opacity")));
@@ -312,6 +255,27 @@ void KisLayerBox::setMainWindow(KisViewManager* kisview)
 
     connectActionToButton(kisview, m_wdgLayerBox->bnAdd, "add_new_paint_layer");
     connectActionToButton(kisview, m_wdgLayerBox->bnDuplicate, "duplicatelayer");
+
+    KisActionManager *actionManager = kisview->actionManager();
+
+    KisAction *action = actionManager->createAction("RenameCurrentLayer");
+    connect(action, SIGNAL(triggered()), this, SLOT(slotRenameCurrentNode()));
+
+    m_propertiesAction = actionManager->createAction("layer_properties");
+    new SyncButtonAndAction(m_propertiesAction, m_wdgLayerBox->bnProperties, this);
+    connect(m_propertiesAction, SIGNAL(triggered()), this, SLOT(slotPropertiesClicked()));
+
+    m_removeAction = actionManager->createAction("remove_layer");
+    new SyncButtonAndAction(m_removeAction, m_wdgLayerBox->bnDelete, this);
+    connect(m_removeAction, SIGNAL(triggered()), this, SLOT(slotRmClicked()));
+
+    action = actionManager->createAction("move_layer_up");
+    new SyncButtonAndAction(action, m_wdgLayerBox->bnRaise, this);
+    connect(action, SIGNAL(triggered()), this, SLOT(slotRaiseClicked()));
+
+    action = actionManager->createAction("move_layer_down");
+    new SyncButtonAndAction(action, m_wdgLayerBox->bnLower, this);
+    connect(action, SIGNAL(triggered()), this, SLOT(slotLowerClicked()));
 }
 
 void KisLayerBox::setCanvas(KoCanvasBase *canvas)
@@ -805,5 +769,9 @@ void KisLayerBox::updateThumbnail()
     m_wdgLayerBox->listLayers->updateNode(m_wdgLayerBox->listLayers->currentIndex());
 }
 
-#include "moc_kis_layer_box.cpp"
+void KisLayerBox::slotRenameCurrentNode()
+{
+    m_wdgLayerBox->listLayers->edit(m_wdgLayerBox->listLayers->currentIndex());
+}
 
+#include "moc_kis_layer_box.cpp"
diff --git a/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.h b/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.h
index bd58a55..8124971 100644
--- a/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.h
+++ b/krita/plugins/extensions/dockers/defaultdockers/kis_layer_box.h
@@ -111,6 +111,7 @@ private Q_SLOTS:
     void slotNodeCollapsedChanged();
 
     void slotEditGlobalSelection(bool showSelections);
+    void slotRenameCurrentNode();
 
     void selectionChanged(const QModelIndexList selection);
     void slotNodeManagerChangedSelection(const QList<KisNodeSP> &nodes);
@@ -164,7 +165,5 @@ public:
     }
 };
 
-
-
 #endif // KIS_LAYERBOX_H
 
diff --git a/krita/plugins/extensions/dockers/defaultdockers/sync_button_and_action.cpp b/krita/plugins/extensions/dockers/defaultdockers/sync_button_and_action.cpp
new file mode 100644
index 0000000..357335f
--- /dev/null
+++ b/krita/plugins/extensions/dockers/defaultdockers/sync_button_and_action.cpp
@@ -0,0 +1,21 @@
+/*
+ *  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 "sync_button_and_action.h"
+
+// just for the moc's sake...
diff --git a/krita/plugins/extensions/dockers/defaultdockers/sync_button_and_action.h b/krita/plugins/extensions/dockers/defaultdockers/sync_button_and_action.h
new file mode 100644
index 0000000..1ee5ca2
--- /dev/null
+++ b/krita/plugins/extensions/dockers/defaultdockers/sync_button_and_action.h
@@ -0,0 +1,52 @@
+/*
+ *  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 __SYNC_BUTTON_AND_ACTION_H
+#define __SYNC_BUTTON_AND_ACTION_H
+
+#include <QPointer>
+#include <QAbstractButton>
+#include "kis_action.h"
+
+class SyncButtonAndAction : public QObject
+{
+    Q_OBJECT
+public:
+    SyncButtonAndAction(KisAction *action, QAbstractButton *button, QObject *parent)
+        : QObject(parent),
+          m_action(action),
+          m_button(button)
+    {
+        connect(m_action, SIGNAL(changed()), SLOT(slotActionChanged()));
+    }
+
+private Q_SLOTS:
+    void slotActionChanged() {
+        if (m_action && m_button &&
+            m_action->isEnabled() != m_button->isEnabled()) {
+
+            m_button->setEnabled(m_action->isEnabled());
+        }
+    }
+
+private:
+    QPointer<KisAction> m_action;
+    QPointer<QAbstractButton> m_button;
+};
+
+#endif /* __SYNC_BUTTON_AND_ACTION_H */
diff --git a/krita/ui/kis_layer_manager.cc b/krita/ui/kis_layer_manager.cc
index 5b90358..0f4dd63 100644
--- a/krita/ui/kis_layer_manager.cc
+++ b/krita/ui/kis_layer_manager.cc
@@ -299,9 +299,6 @@ void KisLayerManager::setup(KisActionManager* actionManager)
     m_flattenLayer = actionManager->createAction("flatten_layer");
     connect(m_flattenLayer, SIGNAL(triggered()), this, SLOT(flattenLayer()));
 
-    KisAction * action = actionManager->createAction("RenameCurrentLayer");
-    connect(action, SIGNAL(triggered()), this, SLOT(layerProperties()));
-
     m_rasterizeLayer = actionManager->createAction("rasterize_layer");
     connect(m_rasterizeLayer, SIGNAL(triggered()), this, SLOT(rasterizeLayer()));
 
@@ -311,7 +308,7 @@ void KisLayerManager::setup(KisActionManager* actionManager)
     m_imageResizeToLayer = actionManager->createAction("resizeimagetolayer");
     connect(m_imageResizeToLayer, SIGNAL(triggered()), this, SLOT(imageResizeToActiveLayer()));
 
-    action = actionManager->createAction("trim_to_image");
+    KisAction *action = actionManager->createAction("trim_to_image");
     connect(action, SIGNAL(triggered()), this, SLOT(trimToImage()));
 
     m_layerStyle  = actionManager->createAction("layer_style");


More information about the kimageshop mailing list