Commit 79a6e438 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Implemented the Select Layer by Mouse Click feature

Now you can select a layer by pressing 'R' key and clicking
with mouse cursor. Krita will select the topmost editable layer.

BUG:324590
parent 75f6e58e
[Alternate Invocation]
0={1;2;[1000021,1000023];1;0;0}
1={0;2;[1000021];1;0;0}
0={0;2;[1000021];1;0;0}
1={1;2;[1000021,1000023];1;0;0}
[Change Primary Setting]
0={0;2;[1000020];1;0;0}
......@@ -9,38 +9,41 @@
name=Krita Default
[Pan Canvas]
0={4;1;[1000015];0;0;0}
1={3;1;[1000013];0;0;0}
2={2;1;[1000014];0;0;0}
3={1;1;[1000012];0;0;0}
4={0;2;[];4;0;0}
5={0;2;[20];1;0;0}
0={0;2;[20];1;0;0}
1={0;2;[];4;0;0}
2={1;1;[1000012];0;0;0}
3={2;1;[1000014];0;0;0}
4={3;1;[1000013];0;0;0}
5={4;1;[1000015];0;0;0}
[Rotate Canvas]
0={3;1;[36];0;0;0}
1={4;1;[35];0;0;0}
2={2;1;[34];0;0;0}
3={0;2;[1000020];4;0;0}
4={0;2;[1000020,1000023,20];1;0;0}
5={0;2;[1000020,20];1;0;0}
0={0;2;[1000020,20];1;0;0}
1={0;2;[1000020,1000023,20];1;0;0}
2={0;2;[1000020];4;0;0}
3={2;1;[34];0;0;0}
4={4;1;[35];0;0;0}
5={3;1;[36];0;0;0}
[Select Layer]
0={0;2;[52];1;0;0}
[Show Popup Palette]
0={0;2;[];2;0;0}
[Tool Invocation]
0={0;2;[];1;0;0}
0={2;1;[1000000];0;0;0}
1={1;1;[1000004];0;0;0}
2={2;1;[1000000];0;0;0}
2={0;2;[];1;0;0}
[Zoom Canvas]
0={6;1;[33];0;0;0}
1={5;1;[32];0;0;0}
2={4;1;[31];0;0;0}
3={3;1;[2d];0;0;0}
4={2;1;[3d];0;0;0}
5={3;3;[];0;2;0}
6={2;3;[];0;1;0}
7={0;2;[1000021];4;0;0}
8={1;2;[1000021,1000023,20];1;0;0}
9={0;2;[1000021,20];1;0;0}
10={2;1;[2b];0;0;0}
0={0;2;[1000021,20];1;0;0}
1={1;2;[1000021,1000023,20];1;0;0}
10={6;1;[33];0;0;0}
2={0;2;[1000021];4;0;0}
3={2;3;[];0;1;0}
4={3;3;[];0;2;0}
5={2;1;[3d];0;0;0}
6={3;1;[2d];0;0;0}
7={4;1;[31];0;0;0}
8={2;1;[2b];0;0;0}
9={5;1;[32];0;0;0}
......@@ -30,6 +30,7 @@
#include "kis_canvas2.h"
#include "kis_image.h"
#include "kis_tool_utils.h"
#include "kis_paint_layer.h"
#include "strokes/move_stroke_strategy.h"
#include "strokes/move_selection_stroke_strategy.h"
......@@ -75,42 +76,6 @@ void KisToolMove::requestStrokeCancellation()
cancelStroke();
}
// recursively search a node with a non-transparent pixel
KisNodeSP findNode(KisNodeSP node, const QPoint &point, bool wholeGroup)
{
KisNodeSP foundNode = 0;
while (node) {
KisLayerSP layer = dynamic_cast<KisLayer*>(node.data());
if (!layer || !layer->isEditable()) {
node = node->prevSibling();
continue;
}
KoColor color(layer->projection()->colorSpace());
layer->projection()->pixel(point.x(), point.y(), &color);
if(color.opacityU8() != OPACITY_TRANSPARENT_U8) {
if (layer->inherits("KisGroupLayer")) {
// if this is a group and the pixel is transparent,
// don't even enter it
foundNode = findNode(node->lastChild(), point, wholeGroup);
}
else {
foundNode = !wholeGroup ? node : node->parent();
}
}
if (foundNode) break;
node = node->prevSibling();
}
return foundNode;
}
void KisToolMove::mousePressEvent(KoPointerEvent *event)
{
if(PRESS_CONDITION_OM(event, KisTool::HOVER_MODE,
......@@ -135,7 +100,7 @@ void KisToolMove::mousePressEvent(KoPointerEvent *event)
(m_optionsWidget->radioGroup->isChecked() ||
event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier));
node = findNode(image->root(), pos, wholeGroup);
node = KisToolUtils::findNode(image->root(), pos, wholeGroup);
}
if((!node && !(node = currentNode())) || !node->isEditable()) return;
......
......@@ -159,7 +159,7 @@ set(kritaui_LIB_SRCS
tool/kis_tool_ellipse_base.cpp
tool/kis_tool_rectangle_base.cpp
tool/kis_tool_polyline_base.cpp
tool/kis_color_picker_utils.cpp
tool/kis_tool_utils.cpp
tool/kis_resources_snapshot.cpp
tool/kis_smoothing_options.cpp
tool/strokes/freehand_stroke.cpp
......@@ -218,6 +218,7 @@ set(kritaui_LIB_SRCS
input/kis_single_action_shortcut.cpp
input/kis_stroke_shortcut.cpp
input/kis_shortcut_matcher.cpp
input/kis_select_layer_action.cpp
operations/kis_operation.cpp
operations/kis_operation_configuration.cpp
operations/kis_operation_registry.cpp
......
......@@ -39,6 +39,8 @@
#include "kis_tool_invocation_action.h"
#include "kis_zoom_action.h"
#include "kis_shortcut_configuration.h"
#include "kis_select_layer_action.h"
class KisInputProfileManager::Private
{
......@@ -282,6 +284,7 @@ void KisInputProfileManager::Private::createActions()
actions.append(new KisRotateCanvasAction());
actions.append(new KisZoomAction());
actions.append(new KisShowPaletteAction());
actions.append(new KisSelectLayerAction());
}
QString KisInputProfileManager::Private::profileFileName(const QString &profileName)
......
/* This file is part of the KDE project
* Copyright (C) 2012 Arjen Hiemstra <ahiemstra@heimr.nl>
*
* 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_select_layer_action.h"
#include <QDebug>
#include <QMouseEvent>
#include <QApplication>
#include <klocalizedstring.h>
#include <kis_canvas2.h>
#include <kis_image.h>
#include <kis_view2.h>
#include <kis_node_manager.h>
#include "kis_input_manager.h"
#include "kis_tool_utils.h"
class KisSelectLayerAction::Private
{
public:
};
KisSelectLayerAction::KisSelectLayerAction()
: d(new Private)
{
setName(i18n("Select Layer"));
setDescription(i18n("Selects a layer under cursor position"));
QHash<QString, int> shortcuts;
shortcuts.insert(i18n("Toggle Select Layer Mode"), SelectLayerToggleShortcut);
setShortcutIndexes(shortcuts);
}
KisSelectLayerAction::~KisSelectLayerAction()
{
delete d;
}
int KisSelectLayerAction::priority() const
{
return 5;
}
void KisSelectLayerAction::activate()
{
QApplication::setOverrideCursor(Qt::PointingHandCursor);
}
void KisSelectLayerAction::deactivate()
{
QApplication::restoreOverrideCursor();
}
void KisSelectLayerAction::begin(int shortcut, QEvent *event)
{
KisAbstractInputAction::begin(shortcut, event);
switch (shortcut) {
case SelectLayerToggleShortcut:
inputEvent(event);
break;
}
}
void KisSelectLayerAction::inputEvent(QEvent *event)
{
QMouseEvent *mouseEvent;
if (event && (mouseEvent = dynamic_cast<QMouseEvent*>(event))) {
QPoint pos =
inputManager()->canvas()->
coordinatesConverter()->widgetToImage(mouseEvent->posF()).toPoint();
KisNodeSP node = KisToolUtils::findNode(inputManager()->canvas()->image()->root(), pos, false);
if (node) {
inputManager()->canvas()->view()->nodeManager()->slotNonUiActivatedNode(node);
}
}
}
/*
* Copyright (c) 2009 Boudewijn Rempt <boud@valdyas.org>
/* This file is part of the KDE project
* Copyright (C) 2012 Arjen Hiemstra <ahiemstra@heimr.nl>
*
* 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
......@@ -15,18 +15,38 @@
* 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_color_picker_utils.h>
namespace KisToolUtils {
#ifndef KIS_SELECT_LAYER_ACTION_H
#define KIS_SELECT_LAYER_ACTION_H
#include "kis_abstract_input_action.h"
/**
* return the color at the given position on the given paint device.
* \brief Select Layer implementation of KisAbstractInputAction.
*
* The Select Layer action selects a layer under a cursor.
*/
KoColor pick(KisPaintDeviceSP dev, const QPoint& pos)
class KisSelectLayerAction : public KisAbstractInputAction
{
public:
enum Shortcut {
SelectLayerToggleShortcut, ///< Toggle the layer select mode.
};
explicit KisSelectLayerAction();
virtual ~KisSelectLayerAction();
virtual int priority() const;
void activate();
void deactivate();
void begin(int shortcut, QEvent *event);
void inputEvent(QEvent *event);
KoColor pickedColor;
dev->pixel(pos.x(), pos.y(), &pickedColor);
return pickedColor;
}
private:
class Private;
Private * const d;
};
}
#endif // KIS_SELECT_LAYER_ACTION_H
......@@ -67,7 +67,7 @@
#include "widgets/kis_slider_spin_box.h"
#include "kis_canvas_resource_provider.h"
#include <recorder/kis_recorded_paint_action.h>
#include "kis_color_picker_utils.h"
#include "kis_tool_utils.h"
#include <kis_paintop.h>
const int STEP = 25;
......
/*
* Copyright (c) 2009 Boudewijn Rempt <boud@valdyas.org>
*
* 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_tool_utils.h>
#include <KoColorSpace.h>
#include <kis_paint_device.h>
#include <kis_layer.h>
namespace KisToolUtils {
KoColor pick(KisPaintDeviceSP dev, const QPoint& pos)
{
KoColor pickedColor;
dev->pixel(pos.x(), pos.y(), &pickedColor);
return pickedColor;
}
KisNodeSP findNode(KisNodeSP node, const QPoint &point, bool wholeGroup, bool editableOnly)
{
KisNodeSP foundNode = 0;
while (node) {
KisLayerSP layer = dynamic_cast<KisLayer*>(node.data());
if (!layer || !layer->isEditable()) {
node = node->prevSibling();
continue;
}
KoColor color(layer->projection()->colorSpace());
layer->projection()->pixel(point.x(), point.y(), &color);
if(color.opacityU8() != OPACITY_TRANSPARENT_U8) {
if (layer->inherits("KisGroupLayer") && (!editableOnly || layer->isEditable())) {
// if this is a group and the pixel is transparent,
// don't even enter it
foundNode = findNode(node->lastChild(), point, wholeGroup, editableOnly);
}
else {
foundNode = !wholeGroup ? node : node->parent();
}
}
if (foundNode) break;
node = node->prevSibling();
}
return foundNode;
}
}
......@@ -15,21 +15,27 @@
* 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_COLOR_PICKER_UTILS_H
#define KIS_COLOR_PICKER_UTILS_H
#ifndef KIS_TOOL_UTILS_H
#define KIS_TOOL_UTILS_H
#include <QPoint>
#include <KoColor.h>
#include <kis_types.h>
#include <krita_export.h>
#include <kis_paint_device.h>
namespace KisToolUtils {
/**
* return the color at the given position on the given paint device.
*/
KoColor pick(KisPaintDeviceSP dev, const QPoint& pos);
KoColor KRITAUI_EXPORT pick(KisPaintDeviceSP dev, const QPoint& pos);
/**
* Recursively search a node with a non-transparent pixel
*/
KisNodeSP KRITAUI_EXPORT findNode(KisNodeSP node, const QPoint &point, bool wholeGroup, bool editableOnly = true);
}
#endif // KIS_COLOR_PICKER_UTILS_H
#endif // KIS_TOOL_UTILS_H
......@@ -30,7 +30,7 @@
#include <KoAbstractGradient.h>
#include <kis_cursor.h>
#include <kis_color_picker_utils.h>
#include <kis_tool_utils.h>
#include <kis_paint_layer.h>
#include <kis_paint_device.h>
#include <kis_gradient_painter.h>
......
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