Krita Source Code Documentation
Loading...
Searching...
No Matches
SelectionDecorator Class Reference

#include <SelectionDecorator.h>

Public Member Functions

void paint (QPainter &painter, const KoViewConverter &converter)
 
 SelectionDecorator (KoCanvasResourceProvider *resourceManager, KoColorDisplayRendererInterface *displayInterface)
 
void setCurrentMeshGradientHandles (const KoShapeMeshGradientHandles::Handle &selectedHandle, const KoShapeMeshGradientHandles::Handle &hoveredHandle)
 
void setDecorationThickness (int thickness)
 
void setForceShapeOutlines (bool value)
 
void setHandleRadius (int radius)
 
void setSelection (KoSelection *selection)
 
void setShowFillGradientHandles (bool value)
 
void setShowFillMeshGradientHandles (bool value)
 
void setShowStrokeFillGradientHandles (bool value)
 
 ~SelectionDecorator ()
 

Private Member Functions

void paintGradientHandles (KoShape *shape, KoFlake::FillVariant fillVariant, QPainter &painter, const KoViewConverter &converter)
 
void paintMeshGradientHandles (KoShape *shape, KoFlake::FillVariant fillVariant, QPainter &painter, const KoViewConverter &converter)
 

Private Attributes

KoShapeMeshGradientHandles::Handle m_currentHoveredMeshHandle
 
int m_decorationThickness {1}
 
bool m_forceShapeOutlines {false}
 
int m_handleRadius {7}
 
KoFlake::AnchorPosition m_hotPosition
 
KoColorDisplayRendererInterfacem_rendererInterface {nullptr}
 
KoShapeMeshGradientHandles::Handle m_selectedMeshHandle
 
KoSelectionm_selection {nullptr}
 
bool m_showFillGradientHandles {false}
 
bool m_showFillMeshGradientHandles {false}
 
bool m_showStrokeFillGradientHandles {false}
 

Detailed Description

The SelectionDecorator is used to paint extra user-interface items on top of a selection.

Definition at line 30 of file SelectionDecorator.h.

Constructor & Destructor Documentation

◆ SelectionDecorator()

SelectionDecorator::SelectionDecorator ( KoCanvasResourceProvider * resourceManager,
KoColorDisplayRendererInterface * displayInterface )

Constructor.

Parameters
arrowsthe direction that needs highlighting. (currently unused)
rotationHandlesif true; the rotation handles will be drawn
shearHandlesif true; the shearhandles will be drawn

Definition at line 35 of file SelectionDecorator.cpp.

37 , m_rendererInterface(displayInterface)
43{
46 resourceManager->resource(KoFlake::HotPosition).toInt());
47}
KoColorDisplayRendererInterface * m_rendererInterface
KoFlake::AnchorPosition m_hotPosition
AnchorPosition
Definition KoFlake.h:85
@ Center
Definition KoFlake.h:90
@ HotPosition
Definition KoFlake.h:102

References KoFlake::HotPosition, m_hotPosition, and KoCanvasResourceProvider::resource().

◆ ~SelectionDecorator()

SelectionDecorator::~SelectionDecorator ( )
inline

Definition at line 40 of file SelectionDecorator.h.

40{}

Member Function Documentation

◆ paint()

void SelectionDecorator::paint ( QPainter & painter,
const KoViewConverter & converter )

paint the decorations.

Parameters
painterthe painter to paint to.
converterto convert between internal and view coordinates.

Definition at line 86 of file SelectionDecorator.cpp.

87{
89 if (selectedShapes.isEmpty()) return;
90
92
93 const bool haveOnlyOneEditableShape =
94 m_selection->selectedEditableShapes().size() == 1 &&
95 selectedShapes.size() == 1;
96
97 bool editable = false;
98 bool forceBoundingRubberLine = false;
99
100 Q_FOREACH (KoShape *shape, KoShape::linearizeSubtree(selectedShapes)) {
101 if (!haveOnlyOneEditableShape || !m_showStrokeFillGradientHandles) {
104
106
108 helper.drawRubberLine(shape->outlineRect());
109 } else {
110 QList<QPolygonF> polys = shape->outline().toSubpathPolygons();
111
112 if (polys.size() == 1) {
113 const QPolygonF poly1 = polys[0];
114 const QPolygonF poly2 = QPolygonF(polys[0].boundingRect());
115 const QPolygonF nonoverlap = poly2.subtracted(poly1);
116
117 forceBoundingRubberLine |= !nonoverlap.isEmpty();
118 }
119
120 Q_FOREACH (const QPolygonF &poly, polys) {
121 helper.drawRubberLine(poly);
122 }
123 }
124 }
125
126 if (shape->isShapeEditable()) {
127 editable = true;
128 }
129 }
130
131 const QRectF handleArea = m_selection->outlineRect();
132
133 // draw extra rubber line around all the shapes
134 if (selectedShapes.size() > 1 || forceBoundingRubberLine) {
137
139 helper.drawRubberLine(handleArea);
140 }
141
142 // if we have no editable shape selected there
143 // is no need drawing the selection handles
144 if (editable) {
148
149 QPolygonF outline = handleArea;
150
151 {
152 helper.drawHandleRect(outline.value(0));
153 helper.drawHandleRect(outline.value(1));
154 helper.drawHandleRect(outline.value(2));
155 helper.drawHandleRect(outline.value(3));
156 helper.drawHandleRect(0.5 * (outline.value(0) + outline.value(1)));
157 helper.drawHandleRect(0.5 * (outline.value(1) + outline.value(2)));
158 helper.drawHandleRect(0.5 * (outline.value(2) + outline.value(3)));
159 helper.drawHandleRect(0.5 * (outline.value(3) + outline.value(0)));
160
161 QPointF hotPos = KoFlake::anchorToPoint(m_hotPosition, handleArea);
163 helper.drawHandleRect(hotPos);
164 }
165 }
166
167 if (haveOnlyOneEditableShape) {
168 KoShape *shape = selectedShapes.first();
169
171 paintGradientHandles(shape, KoFlake::Fill, painter, converter);
173 paintGradientHandles(shape, KoFlake::StrokeFill, painter, converter);
174 }
175
176 // paint meshgradient handles
178 paintMeshGradientHandles(shape, KoFlake::Fill, painter, converter);
179 }
180 }
181
182}
The KisHandlePainterHelper class is a special helper for painting handles around objects....
void drawHandleRect(const QPointF &center, qreal radius)
void setHandleStyle(const KisHandleStyle &style)
void drawRubberLine(const QPolygonF &poly)
static KisHandleStyle & secondarySelection(KisHandlePalette palette=KisHandlePalette())
static KisHandleStyle & primarySelection(KisHandlePalette palette=KisHandlePalette())
static KisHandleStyle & highlightedPrimaryHandles(KisHandlePalette palette=KisHandlePalette())
virtual KisHandlePalette handlePaletteForDisplayColorSpace() const =0
handlePaletteForDisplayColorSpace
const QList< KoShape * > selectedVisibleShapes() const
QRectF outlineRect() const override
const QList< KoShape * > selectedEditableShapes() const
virtual QRectF outlineRect() const
Definition KoShape.cpp:561
virtual QPainterPath outline() const
Definition KoShape.cpp:554
virtual bool isShapeEditable(bool recursive=true) const
checks recursively if the shape or one of its parents is not visible or locked
Definition KoShape.cpp:965
static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
Definition KoShape.cpp:977
static QList< KoShape * > linearizeSubtree(const QList< KoShape * > &shapes)
Definition KoShape.cpp:1173
void paintGradientHandles(KoShape *shape, KoFlake::FillVariant fillVariant, QPainter &painter, const KoViewConverter &converter)
void paintMeshGradientHandles(KoShape *shape, KoFlake::FillVariant fillVariant, QPainter &painter, const KoViewConverter &converter)
KoSelection * m_selection
KRITAFLAKE_EXPORT QPointF anchorToPoint(AnchorPosition anchor, const QRectF rect, bool *valid=0)
Definition KoFlake.cpp:329
@ StrokeFill
Definition KoFlake.h:30
@ Fill
Definition KoFlake.h:29
rgba palette[MAX_PALETTE]
Definition palette.c:35

References KoFlake::anchorToPoint(), KoShape::createHandlePainterHelperView(), KisHandlePainterHelper::drawHandleRect(), KisHandlePainterHelper::drawRubberLine(), KoFlake::Fill, KoColorDisplayRendererInterface::handlePaletteForDisplayColorSpace(), KisHandleStyle::highlightedPrimaryHandles(), KoShape::isShapeEditable(), KoShape::linearizeSubtree(), m_decorationThickness, m_forceShapeOutlines, m_handleRadius, m_hotPosition, m_rendererInterface, m_selection, m_showFillGradientHandles, m_showFillMeshGradientHandles, m_showStrokeFillGradientHandles, KoShape::outline(), KoShape::outlineRect(), KoSelection::outlineRect(), paintGradientHandles(), paintMeshGradientHandles(), palette, KisHandleStyle::primarySelection(), KisHandleStyle::secondarySelection(), KoSelection::selectedEditableShapes(), KoSelection::selectedVisibleShapes(), KisHandlePainterHelper::setHandleStyle(), and KoFlake::StrokeFill.

◆ paintGradientHandles()

void SelectionDecorator::paintGradientHandles ( KoShape * shape,
KoFlake::FillVariant fillVariant,
QPainter & painter,
const KoViewConverter & converter )
private

Definition at line 184 of file SelectionDecorator.cpp.

185{
186 KoShapeGradientHandles gradientHandles(fillVariant, shape);
187 QVector<KoShapeGradientHandles::Handle> handles = gradientHandles.handles();
189
192
193 const QTransform t = shape->absoluteTransformation().inverted();
194
195 if (gradientHandles.type() == QGradient::LinearGradient) {
196 KIS_SAFE_ASSERT_RECOVER_NOOP(handles.size() == 2);
197
198 if (handles.size() == 2) {
200 helper.drawGradientArrow(t.map(handles[0].pos), t.map(handles[1].pos), 1.5 * m_handleRadius);
201 }
202 }
203
205
206 Q_FOREACH (const KoShapeGradientHandles::Handle &h, handles) {
208 helper.drawGradientCrossHandle(t.map(h.pos), 1.2 * m_handleRadius);
209 } else {
210 helper.drawGradientHandle(t.map(h.pos), 1.2 * m_handleRadius);
211 }
212 }
213}
void drawGradientCrossHandle(const QPointF &center, qreal radius)
void drawGradientHandle(const QPointF &center, qreal radius)
void drawGradientArrow(const QPointF &start, const QPointF &end, qreal radius)
static KisHandleStyle & gradientArrows(KisHandlePalette palette=KisHandlePalette())
static KisHandleStyle & gradientHandles(KisHandlePalette palette=KisHandlePalette())
QTransform absoluteTransformation() const
Definition KoShape.cpp:330
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KoShape::absoluteTransformation(), KoShape::createHandlePainterHelperView(), KisHandlePainterHelper::drawGradientArrow(), KisHandlePainterHelper::drawGradientCrossHandle(), KisHandlePainterHelper::drawGradientHandle(), KisHandleStyle::gradientArrows(), KisHandleStyle::gradientHandles(), KoColorDisplayRendererInterface::handlePaletteForDisplayColorSpace(), KoShapeGradientHandles::handles(), KIS_SAFE_ASSERT_RECOVER_NOOP, m_decorationThickness, m_handleRadius, m_rendererInterface, palette, KoShapeGradientHandles::Handle::RadialCenter, KisHandlePainterHelper::setHandleStyle(), and KoShapeGradientHandles::type().

◆ paintMeshGradientHandles()

void SelectionDecorator::paintMeshGradientHandles ( KoShape * shape,
KoFlake::FillVariant fillVariant,
QPainter & painter,
const KoViewConverter & converter )
private

Definition at line 215 of file SelectionDecorator.cpp.

219{
220 KoShapeMeshGradientHandles gradientHandles(fillVariant, shape);
222
226
227 helper.drawPath(gradientHandles.path());
228
229 // invert them, because we draw in logical coordinates.
230 const QTransform t = shape->absoluteTransformation().inverted();
231 const QVector<KoShapeMeshGradientHandles::Handle> cornerHandles = gradientHandles.handles();
232 for (const auto& corner: cornerHandles) {
233 const QPointF point = t.map(corner.pos);
235 helper.drawConnectionLine(gradientHandles.getAttachedCorner(corner), point);
236 helper.drawHandleSmallCircle(point);
237 } else if (corner.type == KoShapeMeshGradientHandles::Handle::Corner) {
238 helper.drawHandleCircle(point);
239 }
240 }
241
243
244 // highlight the selected handle (only corner)
246 helper.drawHandleRect(t.map(gradientHandles.getHandle(m_selectedMeshHandle.getPosition()).pos));
247 }
248
249 // highlight the path which is being hovered/moved
251 QVector<QPainterPath> paths = gradientHandles.getConnectedPath(m_currentHoveredMeshHandle);
252 for (const auto &path: paths) {
253 helper.drawPath(path);
254 }
255 }
256}
void drawHandleSmallCircle(const QPointF &center)
void drawPath(const QPainterPath &path)
void drawConnectionLine(const QLineF &line)
void drawHandleCircle(const QPointF &center, qreal radius)
static KisHandleStyle & highlightedPrimaryHandlesWithSolidOutline(KisHandlePalette palette=KisHandlePalette())
KoShapeMeshGradientHandles::Handle m_selectedMeshHandle
KoShapeMeshGradientHandles::Handle m_currentHoveredMeshHandle

References KoShape::absoluteTransformation(), KoShapeMeshGradientHandles::Handle::BezierHandle, KoShapeMeshGradientHandles::Handle::Corner, KoShape::createHandlePainterHelperView(), KisHandlePainterHelper::drawConnectionLine(), KisHandlePainterHelper::drawHandleCircle(), KisHandlePainterHelper::drawHandleRect(), KisHandlePainterHelper::drawHandleSmallCircle(), KisHandlePainterHelper::drawPath(), KoShapeMeshGradientHandles::getAttachedCorner(), KoShapeMeshGradientHandles::getConnectedPath(), KoShapeMeshGradientHandles::getHandle(), KoShapeMeshGradientHandles::Handle::getPosition(), KoColorDisplayRendererInterface::handlePaletteForDisplayColorSpace(), KoShapeMeshGradientHandles::handles(), KisHandleStyle::highlightedPrimaryHandlesWithSolidOutline(), m_currentHoveredMeshHandle, m_decorationThickness, m_handleRadius, m_rendererInterface, m_selectedMeshHandle, KoShapeMeshGradientHandles::Handle::None, palette, KoShapeMeshGradientHandles::path(), KoShapeMeshGradientHandles::Handle::pos, KisHandleStyle::secondarySelection(), KisHandlePainterHelper::setHandleStyle(), and KoShapeMeshGradientHandles::Handle::type.

◆ setCurrentMeshGradientHandles()

void SelectionDecorator::setCurrentMeshGradientHandles ( const KoShapeMeshGradientHandles::Handle & selectedHandle,
const KoShapeMeshGradientHandles::Handle & hoveredHandle )

Definition at line 79 of file SelectionDecorator.cpp.

81{
82 m_selectedMeshHandle = selectedHandle;
83 m_currentHoveredMeshHandle = hoveredHandle;
84}

References m_currentHoveredMeshHandle, and m_selectedMeshHandle.

◆ setDecorationThickness()

void SelectionDecorator::setDecorationThickness ( int thickness)

set the thickness of decoration lines, used for HiDPI support.

Parameters
thickness– the new thickness

Definition at line 59 of file SelectionDecorator.cpp.

60{
61 m_decorationThickness = thickness;
62}

References m_decorationThickness.

◆ setForceShapeOutlines()

void SelectionDecorator::setForceShapeOutlines ( bool value)

Definition at line 258 of file SelectionDecorator.cpp.

259{
261}
float value(const T *src, size_t ch)

References m_forceShapeOutlines, and value().

◆ setHandleRadius()

void SelectionDecorator::setHandleRadius ( int radius)

set the radius of the selection handles

Parameters
radiusthe new handle radius

Definition at line 54 of file SelectionDecorator.cpp.

55{
56 m_handleRadius = radius;
57}

References m_handleRadius.

◆ setSelection()

void SelectionDecorator::setSelection ( KoSelection * selection)

set the selection that is to be painted.

Parameters
selectionthe current selection.

Definition at line 49 of file SelectionDecorator.cpp.

50{
51 m_selection = selection;
52}

References m_selection.

◆ setShowFillGradientHandles()

void SelectionDecorator::setShowFillGradientHandles ( bool value)

Set true if you want to render gradient handles on the canvas. Default value: false

Definition at line 64 of file SelectionDecorator.cpp.

References m_showFillGradientHandles, and value().

◆ setShowFillMeshGradientHandles()

void SelectionDecorator::setShowFillMeshGradientHandles ( bool value)

Definition at line 74 of file SelectionDecorator.cpp.

References m_showFillMeshGradientHandles, and value().

◆ setShowStrokeFillGradientHandles()

void SelectionDecorator::setShowStrokeFillGradientHandles ( bool value)

Set true if you want to render gradient handles on the canvas. Default value: false

Definition at line 69 of file SelectionDecorator.cpp.

References m_showStrokeFillGradientHandles, and value().

Member Data Documentation

◆ m_currentHoveredMeshHandle

KoShapeMeshGradientHandles::Handle SelectionDecorator::m_currentHoveredMeshHandle
private

Definition at line 94 of file SelectionDecorator.h.

◆ m_decorationThickness

int SelectionDecorator::m_decorationThickness {1}
private

Definition at line 97 of file SelectionDecorator.h.

97{1};

◆ m_forceShapeOutlines

bool SelectionDecorator::m_forceShapeOutlines {false}
private

Definition at line 101 of file SelectionDecorator.h.

101{false};

◆ m_handleRadius

int SelectionDecorator::m_handleRadius {7}
private

Definition at line 96 of file SelectionDecorator.h.

96{7};

◆ m_hotPosition

KoFlake::AnchorPosition SelectionDecorator::m_hotPosition
private

Definition at line 91 of file SelectionDecorator.h.

◆ m_rendererInterface

KoColorDisplayRendererInterface* SelectionDecorator::m_rendererInterface {nullptr}
private

Definition at line 93 of file SelectionDecorator.h.

93{nullptr};

◆ m_selectedMeshHandle

KoShapeMeshGradientHandles::Handle SelectionDecorator::m_selectedMeshHandle
private

Definition at line 95 of file SelectionDecorator.h.

◆ m_selection

KoSelection* SelectionDecorator::m_selection {nullptr}
private

Definition at line 92 of file SelectionDecorator.h.

92{nullptr};

◆ m_showFillGradientHandles

bool SelectionDecorator::m_showFillGradientHandles {false}
private

Definition at line 98 of file SelectionDecorator.h.

98{false};

◆ m_showFillMeshGradientHandles

bool SelectionDecorator::m_showFillMeshGradientHandles {false}
private

Definition at line 100 of file SelectionDecorator.h.

100{false};

◆ m_showStrokeFillGradientHandles

bool SelectionDecorator::m_showStrokeFillGradientHandles {false}
private

Definition at line 99 of file SelectionDecorator.h.

99{false};

The documentation for this class was generated from the following files: