Commit 32b04db8 authored by Dmitry Kazakov's avatar Dmitry Kazakov

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

CC:kimageshop@kde.org
parent 8fef60f3
......@@ -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>
......
......@@ -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
......
......@@ -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"
......@@ -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
/*
* Copyright (c) 2015 Dmitry Kazakov <dimula73@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...
/*
* Copyright (c) 2015 Dmitry Kazakov <dimula73@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 */
......@@ -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");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment