Commit 19ef3688 authored by Halla Rempt's avatar Halla Rempt

Retire the Select Brush

It was always a poor cousin of the real brush tool, and it has been
obsoleted by the global selection visibility switch, which allows the
user to use any tool on the global selection.

BUG:299564
CCBUG:342695
parent 4497a294
......@@ -9,20 +9,10 @@ set(kritaselectiontools_PART_SRCS
kis_tool_select_outline.cc
kis_tool_select_path.cc
kis_tool_select_similar.cc
kis_tool_select_brush.cc
# kis_tool_select_magnetic.cc
# kis_tool_select_magnetic_option_widget.cpp
)
#kde4_add_ui_files(kritaselectiontools_PART_SRCS
# kis_tool_select_magnetic_option_widget.ui
#)
)
kde4_add_plugin(kritaselectiontools ${kritaselectiontools_PART_SRCS})
target_link_libraries(kritaselectiontools kritaui basicflakes)
install(TARGETS kritaselectiontools DESTINATION ${PLUGIN_INSTALL_DIR})
......@@ -33,14 +23,12 @@ install(TARGETS kritaselectiontools DESTINATION ${PLUGIN_INSTALL_DIR})
install( FILES tool_path_selection.png
tool_rect_selection.png
tool_eraser_selection.png
tool_brush_selection.png
tool_contiguous_selection.png
tool_elliptical_selection.png
tool_outline_selection.png
tool_polygonal_selection.png
tool_rectangular_selection_cursor.png
tool_eraser_selection_cursor.png
tool_brush_selection_cursor.png
tool_contiguous_selection_cursor.png
tool_elliptical_selection_cursor.png
tool_outline_selection_cursor.png
......@@ -55,7 +43,6 @@ install( FILES tool_path_selection.png
dark_tool_path_selection.png
dark_tool_polygonal_selection.png
dark_tool_elliptical_selection.png
dark_tool_brush_selection.png
dark_tool_rect_selection.png
dark_tool_similar_selection.png
......@@ -64,7 +51,6 @@ install( FILES tool_path_selection.png
light_tool_path_selection.png
light_tool_polygonal_selection.png
light_tool_elliptical_selection.png
light_tool_brush_selection.png
light_tool_rect_selection.png
light_tool_similar_selection.png
DESTINATION ${DATA_INSTALL_DIR}/krita/pics)
......@@ -74,7 +60,6 @@ install( FILES kritaselectiontools.desktop DESTINATION ${SERVICES_INSTALL_DIR}
install( FILES
KisToolSelectPolygonal.action
KisToolSelectElliptical.action
KisToolSelectBrush.action
KisToolSelectSimilar.action
KisToolSelectContiguous.action
KisToolSelectRectangular.action
......
<Actions version="1" name="KisToolSelectBrush">
<Action iconText="Reset Foreground and Background Color" shortcut="D" toolTip="Reset Foreground and Background Color" icon="" whatsThis="" statusTip="" name="reset_fg_bg" isCheckable="false" text="Reset Foreground and Background Color" defaultShortcut="D"/>
<Action iconText="Swap Foreground and Background Color" shortcut="X" toolTip="Swap Foreground and Background Color" icon="" whatsThis="" statusTip="" name="toggle_fg_bg" isCheckable="false" text="Swap Foreground and Background Color" defaultShortcut="X"/>
</Actions>
/*
* kis_tool_select_brush.cc -- part of Krita
*
* Copyright (C) 2010 Celarek Adam <kdedev at xibo dot at>
*
* 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_select_brush.h"
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPainter>
#include <QPainterPath>
#include <knuminput.h>
#include <KoCanvasBase.h>
#include <KoViewConverter.h>
#include <KoPointerEvent.h>
#include <KoColorSpace.h>
#include <KoCompositeOp.h>
#include <Eigen/Core>
using namespace Eigen;
#include "kis_cursor.h"
#include "kis_canvas2.h"
#include "kis_painter.h"
#include "kis_pixel_selection.h"
#include "kis_image.h"
#include "kis_selection_options.h"
#include "kis_selection_tool_helper.h"
#include "kis_paintop_preset.h"
KisToolSelectBrush::KisToolSelectBrush(KoCanvasBase * canvas)
: KisToolSelectBase(canvas,
KisCursor::load("tool_brush_selection_cursor.png", 6, 6),
i18n("Brush Selection")),
m_brushRadius(15),
m_lastMousePosition(-1, -1)
{
resetSelection();
}
KisToolSelectBrush::~KisToolSelectBrush()
{
}
QWidget* KisToolSelectBrush::createOptionWidget()
{
KisToolSelectBase::createOptionWidget();
KisSelectionOptions *selectionWidget = selectionOptionWidget();
QHBoxLayout* fl = new QHBoxLayout();
QLabel * lbl = new QLabel(i18n("Brush size:"), selectionWidget);
fl->addWidget(lbl);
KIntNumInput * input = new KIntNumInput(selectionWidget);
input->setRange(0, 500, 5);
input->setValue(m_brushRadius*2);
fl->addWidget(input);
connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotSetBrushSize(int)));
QVBoxLayout* l = dynamic_cast<QVBoxLayout*>(selectionWidget->layout());
Q_ASSERT(l);
l->insertLayout(1, fl);
selectionWidget->disableSelectionModeOption();
return selectionWidget;
}
void KisToolSelectBrush::paint(QPainter& gc, const KoViewConverter &converter)
{
Q_UNUSED(converter);
if(mode() == KisTool::PAINT_MODE) {
paintToolOutline(&gc, pixelToView(m_selection));
}
else if(m_lastMousePosition!=QPoint(-1, -1)) {
QPainterPath brushOutline;
brushOutline.addEllipse(m_lastMousePosition, m_brushRadius, m_brushRadius);
paintToolOutline(&gc, pixelToView(brushOutline));
}
}
void KisToolSelectBrush::beginPrimaryAction(KoPointerEvent *event)
{
if (!selectionEditable()) {
event->ignore();
return;
}
setMode(KisTool::PAINT_MODE);
m_lastPoint = convertToPixelCoord(event->point);
addPoint(m_lastPoint);
}
void KisToolSelectBrush::continuePrimaryAction(KoPointerEvent *event)
{
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
// this gives better performance
if(Vector2f((m_lastPoint-convertToPixelCoord(event->point)).x(), (m_lastPoint-convertToPixelCoord(event->point)).y()).norm()<m_brushRadius/6)
return;
//randomise the point to workaround a bug in QPainterPath::operator|=()
//FIXME: http://bugreports.qt.nokia.com/browse/QTBUG-8035
//will be fixed in version 4.7.0
qreal randomX=rand()%100;
randomX/=1000.;
qreal randomY=rand()%100;
randomY/=1000.;
QPointF smallRandomPoint(randomX, randomY);
addPoint(convertToPixelCoord(event->point)+smallRandomPoint);
}
void KisToolSelectBrush::endPrimaryAction(KoPointerEvent *event)
{
Q_UNUSED(event;)
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
setMode(KisTool::HOVER_MODE);
applyToSelection(m_selection);
}
void KisToolSelectBrush::mouseMoveEvent(KoPointerEvent *event)
{
/**
* Update outline
*/
QRect brushRect(-m_brushRadius, -m_brushRadius, 2*m_brushRadius, 2*m_brushRadius);
brushRect.adjust(-2, -2, 2, 2); //width of tool outline
brushRect.moveCenter(m_lastMousePosition);
updateCanvasPixelRect(brushRect);
m_lastMousePosition = convertToPixelCoord(event).toPoint();
brushRect.moveCenter(m_lastMousePosition);
updateCanvasPixelRect(brushRect);
}
void KisToolSelectBrush::deactivate()
{
resetSelection();
KisToolSelectBase::deactivate();
}
void KisToolSelectBrush::slotSetBrushSize(int size)
{
m_brushRadius = ((qreal) size)/2.0;
}
void KisToolSelectBrush::applyToSelection(QPainterPath selection) {
KisCanvas2 * kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
Q_ASSERT(kisCanvas);
if (!kisCanvas)
return;
KisSelectionToolHelper helper(kisCanvas, kundo2_i18n("Select by Brush"));
if (selectionMode() == PIXEL_SELECTION) {
KisPixelSelectionSP tmpSel = new KisPixelSelection();
KisPainter painter(tmpSel);
painter.setPaintColor(KoColor(Qt::black, tmpSel->colorSpace()));
painter.setPaintOpPreset(currentPaintOpPreset(), currentNode(), currentImage());
painter.setAntiAliasPolygonFill(selectionOptionWidget()->antiAliasSelection());
painter.setFillStyle(KisPainter::FillStyleForegroundColor);
painter.setStrokeStyle(KisPainter::StrokeStyleNone);
selection.closeSubpath();
painter.fillPainterPath(selection);
tmpSel->setOutlineCache(selection);
helper.selectPixelSelection(tmpSel, selectionAction());
resetSelection();
}
}
void KisToolSelectBrush::resetSelection()
{
updateCanvasPixelRect(m_selection.boundingRect());
m_selection = QPainterPath();
}
void KisToolSelectBrush::addPoint(const QPointF& point)
{
QPainterPath ellipse;
ellipse.addEllipse(point, m_brushRadius, m_brushRadius);
m_selection |= (ellipse);
addGap(m_lastPoint, point);
updateCanvasPixelRect(QRectF(m_lastPoint, point).normalized().adjusted(-m_brushRadius, -m_brushRadius, m_brushRadius, m_brushRadius));
m_lastPoint = point;
}
void KisToolSelectBrush::addGap(const QPointF& start, const QPointF& end)
{
Vector2f way((end-start).x(), (end-start).y());
if(way.norm() < m_brushRadius/3.)
return;
Vector2f direction(way.normalized());
//rotate 90 degrees clockwise
Vector2f rotatedPlus(direction.y(), -direction.x());
//rotate 90 degrees counter clockwise
Vector2f rotatedMinus(-direction.y(), direction.x());
Vector2f p1(rotatedPlus * m_brushRadius);
Vector2f p2(way+p1);
Vector2f p4(rotatedMinus * m_brushRadius);
Vector2f p3(way+p4);
//we need to convert floating point vectors to int ones because of a bug in QPainterPath::operator|=()
//FIXME: http://bugreports.qt.nokia.com/browse/QTBUG-8035
//converting int to float should be done with rounding, so don't use eigen casting.
//parameter start contains important decimal places, these shouldn't be lost.
QPointF pp1 = QPointF(p1.x(), p1.y()).toPoint();
QPointF pp2 = QPointF(p2.x(), p2.y()).toPoint();
QPointF pp3 = QPointF(p3.x(), p3.y()).toPoint();
QPointF pp4 = QPointF(p4.x(), p4.y()).toPoint();
pp1+=start;
pp2+=start;
pp3+=start;
pp4+=start;
QPainterPath gap;
gap.moveTo(pp1);
gap.lineTo(pp2);
gap.lineTo(pp3);
gap.lineTo(pp4);
gap.closeSubpath();
m_selection |= (gap);
}
#include "kis_tool_select_brush.moc"
/*
* kis_tool_select_brush.h - part of Krita
*
* Copyright (C) 2010 Celarek Adam <kdedev at xibo dot at>
*
* 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_TOOL_SELECT_BRUSH_H__
#define __KIS_TOOL_SELECT_BRUSH_H__
#include "KoToolFactoryBase.h"
#include "krita/ui/tool/kis_tool_select_base.h"
#include <KoIcon.h>
#include <QPointF>
#include <QPainterPath>
class KisToolSelectBrush : public KisToolSelectBase
{
Q_OBJECT
public:
KisToolSelectBrush(KoCanvasBase * canvas);
virtual ~KisToolSelectBrush();
virtual QWidget * createOptionWidget();
public:
virtual void paint(QPainter& gc, const KoViewConverter &converter);
void beginPrimaryAction(KoPointerEvent *event);
void continuePrimaryAction(KoPointerEvent *event);
void endPrimaryAction(KoPointerEvent *event);
void mouseMoveEvent(KoPointerEvent *event);
public slots:
virtual void deactivate();
void slotSetBrushSize(int size);
protected:
void applyToSelection(QPainterPath selection);
void resetSelection();
void addPoint(const QPointF& point);
void addGap(const QPointF& start, const QPointF& end);
private:
qreal m_brushRadius;
QPainterPath m_selection;
QPointF m_lastPoint;
QPoint m_lastMousePosition;
};
class KisToolSelectBrushFactory : public KoToolFactoryBase
{
public:
KisToolSelectBrushFactory(const QStringList&)
: KoToolFactoryBase("KisToolSelectBrush") {
setToolTip(i18n("Brush Selection Tool"));
setToolType(TOOL_TYPE_SELECTED);
setActivationShapeId(KRITA_TOOL_ACTIVATION_ID);
setIconName(koIconNameCStr("tool_brush_selection"));
//setShortcut(KShortcut(Qt::Key_B));
setPriority(53);
}
virtual ~KisToolSelectBrushFactory() {}
virtual KoToolBase * createTool(KoCanvasBase *canvas) {
return new KisToolSelectBrush(canvas);
}
};
#endif //__KIS_TOOL_SELECT_BRUSH_H__
......@@ -36,8 +36,6 @@
#include "kis_tool_select_elliptical.h"
#include "kis_tool_select_path.h"
#include "kis_tool_select_similar.h"
#include "kis_tool_select_brush.h"
//#include "kis_tool_select_magnetic.h"
K_PLUGIN_FACTORY(SelectionToolsFactory, registerPlugin<SelectionTools>();)
K_EXPORT_PLUGIN(SelectionToolsFactory("krita"))
......@@ -55,8 +53,6 @@ SelectionTools::SelectionTools(QObject *parent, const QVariantList &)
r->add(new KisToolSelectContiguousFactory(QStringList()));
r->add(new KisToolSelectPathFactory(QStringList()));
r->add(new KisToolSelectSimilarFactory(QStringList()));
r->add(new KisToolSelectBrushFactory(QStringList()));
// r->add(new KisToolSelectMagneticFactory(QStringList()));
}
SelectionTools::~SelectionTools()
......
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