diff --git a/plugins/tools/selectiontools/kis_tool_select_magnetic.cc b/plugins/tools/selectiontools/kis_tool_select_magnetic.cc index 0c609a6fcf..d16d6ccb13 100644 --- a/plugins/tools/selectiontools/kis_tool_select_magnetic.cc +++ b/plugins/tools/selectiontools/kis_tool_select_magnetic.cc @@ -1,208 +1,182 @@ /* * Copyright (c) 2007 Sven Langkamp * * 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_magnetic.h" #include #include "kis_cursor.h" #include "kis_image.h" #include "kis_painter.h" #include "kis_selection_options.h" #include "kis_canvas_resource_provider.h" #include "kis_canvas2.h" #include "kis_pixel_selection.h" #include "kis_selection_tool_helper.h" #include KisToolSelectMagnetic::KisToolSelectMagnetic(KoCanvasBase * canvas) : KisToolSelectBase(canvas, - KisCursor::load("tool_polygonal_selection_cursor.png", 6, 6), + KisCursor::load("tool_magnetic_selection_cursor.svg", 0, 0), i18n("Select path"), (KisTool*) (new __KisToolSelectMagneticLocalTool(canvas, this))) { } void KisToolSelectMagnetic::requestStrokeEnd() { localTool()->endPathWithoutLastPoint(); } void KisToolSelectMagnetic::requestStrokeCancellation() { localTool()->cancelPath(); } void KisToolSelectMagnetic::mousePressEvent(KoPointerEvent* event) { if (!selectionEditable()) return; DelegatedSelectMagneticTool::mousePressEvent(event); } // Install an event filter to catch right-click events. // This code is duplicated in kis_tool_path.cc bool KisToolSelectMagnetic::eventFilter(QObject *obj, QEvent *event) { Q_UNUSED(obj); if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) { QMouseEvent *mouseEvent = static_cast(event); if (mouseEvent->button() == Qt::RightButton) { localTool()->removeLastPoint(); return true; } } else if (event->type() == QEvent::TabletPress) { QTabletEvent *tabletEvent = static_cast(event); if (tabletEvent->button() == Qt::RightButton) { localTool()->removeLastPoint(); return true; } } return false; } QList > KisToolSelectMagnetic::createOptionWidgets() { QList > widgetsList = DelegatedSelectMagneticTool::createOptionWidgets(); QList > filteredWidgets; Q_FOREACH (QWidget* widget, widgetsList) { if (widget->objectName() != "Stroke widget") { filteredWidgets.push_back(widget); } } return filteredWidgets; } -void KisDelegatedSelectMagneticWrapper::beginPrimaryAction(KoPointerEvent *event) { - mousePressEvent(event); -} - -void KisDelegatedSelectMagneticWrapper::continuePrimaryAction(KoPointerEvent *event){ - mouseMoveEvent(event); -} - -void KisDelegatedSelectMagneticWrapper::endPrimaryAction(KoPointerEvent *event) { - mouseReleaseEvent(event); -} - bool KisDelegatedSelectMagneticWrapper::hasUserInteractionRunning() const { /** * KoCreatePathTool doesn't support moving interventions from KisToolselectBase, * because it doesn't use begin/continue/endPrimaryAction and uses direct event * handling instead. * * TODO: refactor KoCreatePathTool and port it to action infrastructure */ return true; } __KisToolSelectMagneticLocalTool::__KisToolSelectMagneticLocalTool(KoCanvasBase * canvas, KisToolSelectMagnetic* parentTool) : KoCreatePathTool(canvas), m_selectionTool(parentTool) { setEnableClosePathShortcut(false); } void __KisToolSelectMagneticLocalTool::paintPath(KoPathShape &pathShape, QPainter &painter, const KoViewConverter &converter) { Q_UNUSED(converter); KisCanvas2 * kisCanvas = dynamic_cast(canvas()); if (!kisCanvas) return; QTransform matrix; matrix.scale(kisCanvas->image()->xRes(), kisCanvas->image()->yRes()); matrix.translate(pathShape.position().x(), pathShape.position().y()); qreal zoomX, zoomY; kisCanvas->viewConverter()->zoom(&zoomX, &zoomY); Q_ASSERT(qFuzzyCompare(zoomX, zoomY)); - - qreal width = 25*2; - width *= zoomX/(kisCanvas->image()->xRes()); - - paintOutline(&painter, m_selectionTool->pixelToView(matrix.map(pathShape.outline())), width); + m_selectionTool->paintToolOutline(&painter, m_selectionTool->pixelToView(matrix.map(pathShape.outline()))); } void __KisToolSelectMagneticLocalTool::addPathShape(KoPathShape* pathShape) { pathShape->normalize(); pathShape->close(); KisCanvas2 * kisCanvas = dynamic_cast(canvas()); if (!kisCanvas) return; KisImageWSP image = kisCanvas->image(); KisSelectionToolHelper helper(kisCanvas, kundo2_i18n("Select by Bezier Curve")); const SelectionMode mode = helper.tryOverrideSelectionMode(kisCanvas->viewManager()->selection(), m_selectionTool->selectionMode(), m_selectionTool->selectionAction()); if (mode == PIXEL_SELECTION) { KisPixelSelectionSP tmpSel = KisPixelSelectionSP(new KisPixelSelection()); KisPainter painter(tmpSel); painter.setPaintColor(KoColor(Qt::black, tmpSel->colorSpace())); painter.setFillStyle(KisPainter::FillStyleForegroundColor); painter.setAntiAliasPolygonFill(m_selectionTool->antiAliasSelection()); painter.setStrokeStyle(KisPainter::StrokeStyleNone); QTransform matrix; matrix.scale(image->xRes(), image->yRes()); matrix.translate(pathShape->position().x(), pathShape->position().y()); QPainterPath path = matrix.map(pathShape->outline()); painter.fillPainterPath(path); tmpSel->setOutlineCache(path); helper.selectPixelSelection(tmpSel, m_selectionTool->selectionAction()); delete pathShape; } else { helper.addSelectionShape(pathShape, m_selectionTool->selectionAction()); } } -void __KisToolSelectMagneticLocalTool::paintOutline(QPainter *painter, const QPainterPath &path, qreal width) -{ - painter->save(); - painter->setOpacity(.3); - painter->setPen(QPen(QColor(128, 128, 128), width)); - painter->drawPath(path); - m_selectionTool->updateCanvasViewRect(path.controlPointRect().adjusted(-width, -width, width, width)); - painter->restore(); -} - void KisToolSelectMagnetic::resetCursorStyle() { if (selectionAction() == SELECTION_ADD) { useCursor(KisCursor::load("tool_polygonal_selection_cursor_add.png", 6, 6)); } else if (selectionAction() == SELECTION_SUBTRACT) { useCursor(KisCursor::load("tool_polygonal_selection_cursor_sub.png", 6, 6)); } else { KisToolSelectBase::resetCursorStyle(); } } diff --git a/plugins/tools/selectiontools/kis_tool_select_magnetic.h b/plugins/tools/selectiontools/kis_tool_select_magnetic.h index 604b4766ed..38dbc2999b 100644 --- a/plugins/tools/selectiontools/kis_tool_select_magnetic.h +++ b/plugins/tools/selectiontools/kis_tool_select_magnetic.h @@ -1,115 +1,114 @@ /* * Copyright (c) 2007 Sven Langkamp * Copyright (c) 2015 Michael Abrahams * * 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_MAGNETIC_H_ #define KIS_TOOL_SELECT_MAGNETIC_H_ #include #include #include "kis_tool_select_base.h" #include "kis_delegated_tool.h" #include class KoCanvasBase; class KisToolSelectMagnetic; class __KisToolSelectMagneticLocalTool : public KoCreatePathTool { public: __KisToolSelectMagneticLocalTool(KoCanvasBase * canvas, KisToolSelectMagnetic* parentTool); void paintPath(KoPathShape &path, QPainter &painter, const KoViewConverter &converter) override; void addPathShape(KoPathShape* pathShape) override; friend class KisToolSelectMagnetic; using KoCreatePathTool::createOptionWidgets; using KoCreatePathTool::endPathWithoutLastPoint; using KoCreatePathTool::endPath; using KoCreatePathTool::cancelPath; using KoCreatePathTool::removeLastPoint; -protected: - void paintOutline(QPainter *painter, const QPainterPath &path, qreal width); - private: KisToolSelectMagnetic* const m_selectionTool; }; typedef KisDelegatedTool DelegatedSelectMagneticTool; struct KisDelegatedSelectMagneticWrapper : public DelegatedSelectMagneticTool { KisDelegatedSelectMagneticWrapper(KoCanvasBase *canvas, const QCursor &cursor, KisTool* delegateTool) : DelegatedSelectMagneticTool(canvas, cursor, (__KisToolSelectMagneticLocalTool*)delegateTool) { } // If an event is explicitly forwarded only as an action (e.g. shift-click is captured by "change size") // we will receive a primary action but no mousePressEvent. Thus these events must be explicitly forwarded. - void beginPrimaryAction(KoPointerEvent *event) override; - void continuePrimaryAction(KoPointerEvent *event) override; - void endPrimaryAction(KoPointerEvent *event) override; + void beginPrimaryAction(KoPointerEvent *event) override { mousePressEvent(event); } + + void continuePrimaryAction(KoPointerEvent *event) override { mouseMoveEvent(event); } + + void endPrimaryAction(KoPointerEvent *event) override { mouseReleaseEvent(event); } bool hasUserInteractionRunning() const; }; class KisToolSelectMagnetic : public KisToolSelectBase { Q_OBJECT public: KisToolSelectMagnetic(KoCanvasBase * canvas); void mousePressEvent(KoPointerEvent* event) override; bool eventFilter(QObject *obj, QEvent *event) override; void resetCursorStyle() override; protected: void requestStrokeCancellation() override; void requestStrokeEnd() override; friend class __KisToolSelectMagneticLocalTool; QList > createOptionWidgets() override; }; class KisToolSelectMagneticFactory : public KisSelectionToolFactoryBase { public: KisToolSelectMagneticFactory() : KisSelectionToolFactoryBase("KisToolSelectMagnetic") { setToolTip(i18n("Magnetic Selection Tool")); setSection(TOOL_TYPE_SELECTION); setActivationShapeId(KRITA_TOOL_ACTIVATION_ID); setIconName(koIconNameCStr("tool_magnetic_selection")); setPriority(6); } ~KisToolSelectMagneticFactory() override {} KoToolBase * createTool(KoCanvasBase *canvas) override { return new KisToolSelectMagnetic(canvas); } }; #endif // KIS_TOOL_SELECT_MAGNETIC_H_ diff --git a/plugins/tools/selectiontools/kis_tool_select_polygonal.h b/plugins/tools/selectiontools/kis_tool_select_polygonal.h index c114511ff3..2bdbba466b 100644 --- a/plugins/tools/selectiontools/kis_tool_select_polygonal.h +++ b/plugins/tools/selectiontools/kis_tool_select_polygonal.h @@ -1,91 +1,89 @@ /* * kis_tool_select_polygonal.h - part of Krayon^WKrita * * Copyright (c) 2000 John Califf * Copyright (c) 2002 Patrick Julien * Copyright (c) 2004 Boudewijn Rempt * Copyright (c) 2015 Michael Abrahams * * 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_POLYGONAL_H_ #define KIS_TOOL_SELECT_POLYGONAL_H_ #include "KisSelectionToolFactoryBase.h" #include "kis_tool_polyline_base.h" #include #include "kis_selection_tool_config_widget_helper.h" #include class __KisToolSelectPolygonalLocal : public KisToolPolylineBase { Q_OBJECT public: __KisToolSelectPolygonalLocal(KoCanvasBase *canvas); protected: virtual SelectionMode selectionMode() const = 0; virtual SelectionAction selectionAction() const = 0; virtual bool antiAliasSelection() const = 0; private: void finishPolyline(const QVector &points) override; private: }; class KisToolSelectPolygonal : public KisToolSelectBase<__KisToolSelectPolygonalLocal> { Q_OBJECT public: KisToolSelectPolygonal(KoCanvasBase* canvas); void resetCursorStyle(); }; - - class KisToolSelectPolygonalFactory : public KisSelectionToolFactoryBase { public: KisToolSelectPolygonalFactory() : KisSelectionToolFactoryBase("KisToolSelectPolygonal") { setToolTip(i18n("Polygonal Selection Tool")); setSection(TOOL_TYPE_SELECTION); setIconName(koIconNameCStr("tool_polygonal_selection")); setPriority(2); setActivationShapeId(KRITA_TOOL_ACTIVATION_ID); } ~KisToolSelectPolygonalFactory() override {} KoToolBase * createTool(KoCanvasBase *canvas) override { return new KisToolSelectPolygonal(canvas); } QList createActionsImpl() { KisActionRegistry *actionRegistry = KisActionRegistry::instance(); QList actions = KisSelectionToolFactoryBase::createActionsImpl(); actions << actionRegistry->makeQAction("undo_polygon_selection"); actions << actionRegistry->makeQAction("selection_tool_mode_add"); return actions; } }; #endif //__selecttoolpolygonal_h__ diff --git a/plugins/tools/selectiontools/selectiontools.qrc b/plugins/tools/selectiontools/selectiontools.qrc index cd3646a389..a55dbb45f3 100644 --- a/plugins/tools/selectiontools/selectiontools.qrc +++ b/plugins/tools/selectiontools/selectiontools.qrc @@ -1,24 +1,25 @@ - - - + + tool_contiguous_selection_cursor_add.png tool_contiguous_selection_cursor.png tool_contiguous_selection_cursor_sub.png tool_elliptical_selection_cursor_add.png tool_elliptical_selection_cursor.png tool_elliptical_selection_cursor_sub.png tool_eraser_selection_cursor.png tool_outline_selection_cursor_add.png tool_outline_selection_cursor.png tool_outline_selection_cursor_sub.png tool_polygonal_selection_cursor_add.png tool_polygonal_selection_cursor.png tool_polygonal_selection_cursor_sub.png tool_rectangular_selection_cursor_add.png tool_rectangular_selection_cursor.png tool_rectangular_selection_cursor_sub.png tool_similar_selection_cursor_add.png tool_similar_selection_cursor.png tool_similar_selection_cursor_sub.png + tool_magnetic_selection_cursor.png + tool_magnetic_selection_cursor.svg diff --git a/plugins/tools/selectiontools/tool_magnetic_selection_cursor.png b/plugins/tools/selectiontools/tool_magnetic_selection_cursor.png new file mode 100644 index 0000000000..4e4c7c4e41 Binary files /dev/null and b/plugins/tools/selectiontools/tool_magnetic_selection_cursor.png differ diff --git a/plugins/tools/selectiontools/tool_magnetic_selection_cursor.svg b/plugins/tools/selectiontools/tool_magnetic_selection_cursor.svg new file mode 100644 index 0000000000..81f8f0f014 --- /dev/null +++ b/plugins/tools/selectiontools/tool_magnetic_selection_cursor.svg @@ -0,0 +1,79 @@ + + + + + + + + + + image/svg+xml + + + + + + + + U + +