Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_tool_select_elliptical.cc
Go to the documentation of this file.
1/*
2 * kis_tool_select_elliptical.cc -- part of Krita
3 *
4 * SPDX-FileCopyrightText: 2004 Boudewijn Rempt (boud@valdyas.org)
5 * SPDX-FileCopyrightText: 2007 Sven Langkamp <sven.langkamp@gmail.com>
6 * SPDX-FileCopyrightText: 2015 Michael Abrahams <miabraha@gmail.com>
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
12
13#include <QVBoxLayout>
14
15#include "KisViewManager.h"
16#include "kis_canvas2.h"
17#include "kis_painter.h"
18#include "kis_pixel_selection.h"
24#include <kis_command_utils.h>
26#include <kis_default_bounds.h>
27
29 : KisToolEllipseBase(canvas, KisToolEllipseBase::SELECT,
30 KisCursor::load("tool_elliptical_selection_cursor.png", 6, 6))
31{
32 setObjectName("tool_select_elliptical");
33}
34
35
39
40void KisToolSelectElliptical::finishRect(const QRectF &rect, qreal roundCornersX, qreal roundCornersY)
41{
42 Q_UNUSED(roundCornersX);
43 Q_UNUSED(roundCornersY);
44
45 KisCanvas2 * kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
46 Q_ASSERT(kisCanvas);
47
48 KisSelectionToolHelper helper(kisCanvas, kundo2_i18n("Select Ellipse"));
49
51 return;
52 }
53
54 if (rect.isEmpty()) {
55 return;
56 }
57
58 const SelectionMode mode =
59 helper.tryOverrideSelectionMode(kisCanvas->viewManager()->selection(),
62
63 if (mode == PIXEL_SELECTION) {
68 kundo2_i18n("Select Ellipse"));
69
70 KisPixelSelectionSP tmpSel =
72
73 const bool antiAlias = antiAliasSelection();
74 const int grow = growSelection();
75 const int feather = featherSelection();
76
77 QPainterPath path;
78 path.addEllipse(rect);
79 getRotatedPath(path, rect.center(), getRotationAngle());
80
82 [tmpSel, antiAlias, grow, feather, path]() mutable
83 -> KUndo2Command * {
84 KisPainter painter(tmpSel);
85 painter.setPaintColor(KoColor(Qt::black, tmpSel->colorSpace()));
86 // Since the feathering already smooths the selection, the
87 // antiAlias is not applied if we must feather
88 painter.setAntiAliasPolygonFill(antiAlias && feather == 0);
91
92 painter.paintPainterPath(path);
93
94 if (grow > 0) {
95 KisGrowSelectionFilter biggy(grow, grow);
96 biggy.process(tmpSel,
97 tmpSel->selectedRect().adjusted(-grow,
98 -grow,
99 grow,
100 grow));
101 } else if (grow < 0) {
102 KisShrinkSelectionFilter tiny(-grow, -grow, false);
103 tiny.process(tmpSel, tmpSel->selectedRect());
104 }
105 if (feather > 0) {
106 KisFeatherSelectionFilter feathery(feather);
107 feathery.process(tmpSel,
108 tmpSel->selectedRect().adjusted(-feather,
109 -feather,
110 feather,
111 feather));
112 }
113
114 if (grow == 0 && feather == 0) {
115 tmpSel->setOutlineCache(path);
116 } else {
117 tmpSel->invalidateOutlineCache();
118 }
119
120 return 0;
121 });
122
124 helper.selectPixelSelection(applicator, tmpSel, selectionAction());
125 applicator.end();
126
127 } else {
128 QRectF ptRect = convertToPt(rect);
130 shape->rotate(qRadiansToDegrees(getRotationAngle()));
131
132 helper.addSelectionShape(shape, selectionAction());
133 }
134}
135
140
145
147{
149 useCursor(KisCursor::load("tool_elliptical_selection_cursor_add.png", 6, 6));
150 } else if (selectionAction() == SELECTION_SUBTRACT) {
151 useCursor(KisCursor::load("tool_elliptical_selection_cursor_sub.png", 6, 6));
152 } else if (selectionAction() == SELECTION_INTERSECT) {
153 useCursor(KisCursor::load("tool_elliptical_selection_cursor_inter.png", 6, 6));
155 useCursor(KisCursor::load("tool_elliptical_selection_cursor_symdiff.png", 6, 6));
156 } else {
158 }
159}
160
QVector< KisImageSignalType > KisImageSignalVector
SelectionMode
@ PIXEL_SELECTION
@ SELECTION_INTERSECT
@ SELECTION_SYMMETRICDIFFERENCE
@ SELECTION_SUBTRACT
@ SELECTION_ADD
KisViewManager * viewManager() const
static QCursor load(const QString &cursorName, int hotspotX=-1, int hotspotY=-1)
void process(KisPixelSelectionSP pixelSelection, const QRect &rect) override
void process(KisPixelSelectionSP pixelSelection, const QRect &rect) override
const KoColorSpace * colorSpace() const
@ FillStyleForegroundColor
void paintPainterPath(const QPainterPath &path)
void setStrokeStyle(StrokeStyle strokeStyle)
Set the current brush stroke style.
void setFillStyle(FillStyle fillStyle)
Set the current style with which to fill.
void setPaintColor(const KoColor &color)
void setAntiAliasPolygonFill(bool antiAliasPolygonFill)
Set whether a polygon's filled area should be anti-aliased or not. The default is true.
void applyCommand(KUndo2Command *command, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
void addSelectionShape(KoShape *shape, SelectionAction action=SELECTION_DEFAULT)
void selectPixelSelection(KisProcessingApplicator &applicator, KisPixelSelectionSP selection, SelectionAction action)
SelectionMode tryOverrideSelectionMode(KisSelectionSP activeSelection, SelectionMode currentMode, SelectionAction currentAction) const
bool tryDeselectCurrentSelection(const QRectF selectionViewRect, SelectionAction action)
static KoShape * createEllipseShape(const QRectF &rect)
void process(KisPixelSelectionSP pixelSelection, const QRect &rect) override
void getRotatedPath(QPainterPath &path, const QPointF &center, const qreal &angle)
void finishRect(const QRectF &rect, qreal roundCornersX, qreal roundCornersY) override
KisToolSelectElliptical(KoCanvasBase *canvas)
KisSelectionSP selection()
void rotate(qreal angle)
Rotate the shape (relative)
Definition KoShape.cpp:250
void useCursor(const QCursor &cursor)
__KisToolSelectEllipticalLocal(KoCanvasBase *canvas)
KUndo2MagicString kundo2_i18n(const char *text)
The LambdaCommand struct is a shorthand for creation of AggregateCommand commands using C++ lambda fe...
void setOutlineCache(const QPainterPath &cache)
virtual ToolMode mode() const
Definition kis_tool.cc:407
KisImageWSP currentImage()
Definition kis_tool.cc:393
QPointF pixelToView(const QPoint &pixelCoord) const
Definition kis_tool.cc:269
KisNodeSP currentNode() const
Definition kis_tool.cc:370
QRectF convertToPt(const QRectF &rect)
Definition kis_tool.cc:252
KisCanvas2 * canvas