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)
 
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
 
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 29 of file SelectionDecorator.h.

Constructor & Destructor Documentation

◆ SelectionDecorator()

SelectionDecorator::SelectionDecorator ( KoCanvasResourceProvider * resourceManager)

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 34 of file SelectionDecorator.cpp.

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

◆ ~SelectionDecorator()

SelectionDecorator::~SelectionDecorator ( )
inline

Definition at line 39 of file SelectionDecorator.h.

39{}

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 84 of file SelectionDecorator.cpp.

85{
87 if (selectedShapes.isEmpty()) return;
88
89 const bool haveOnlyOneEditableShape =
90 m_selection->selectedEditableShapes().size() == 1 &&
91 selectedShapes.size() == 1;
92
93 bool editable = false;
94 bool forceBoundingRubberLine = false;
95
96 Q_FOREACH (KoShape *shape, KoShape::linearizeSubtree(selectedShapes)) {
97 if (!haveOnlyOneEditableShape || !m_showStrokeFillGradientHandles) {
100
102
104 helper.drawRubberLine(shape->outlineRect());
105 } else {
106 QList<QPolygonF> polys = shape->outline().toSubpathPolygons();
107
108 if (polys.size() == 1) {
109 const QPolygonF poly1 = polys[0];
110 const QPolygonF poly2 = QPolygonF(polys[0].boundingRect());
111 const QPolygonF nonoverlap = poly2.subtracted(poly1);
112
113 forceBoundingRubberLine |= !nonoverlap.isEmpty();
114 }
115
116 Q_FOREACH (const QPolygonF &poly, polys) {
117 helper.drawRubberLine(poly);
118 }
119 }
120 }
121
122 if (shape->isShapeEditable()) {
123 editable = true;
124 }
125 }
126
127 const QRectF handleArea = m_selection->outlineRect();
128
129 // draw extra rubber line around all the shapes
130 if (selectedShapes.size() > 1 || forceBoundingRubberLine) {
133
135 helper.drawRubberLine(handleArea);
136 }
137
138 // if we have no editable shape selected there
139 // is no need drawing the selection handles
140 if (editable) {
144
145 QPolygonF outline = handleArea;
146
147 {
148 helper.drawHandleRect(outline.value(0));
149 helper.drawHandleRect(outline.value(1));
150 helper.drawHandleRect(outline.value(2));
151 helper.drawHandleRect(outline.value(3));
152 helper.drawHandleRect(0.5 * (outline.value(0) + outline.value(1)));
153 helper.drawHandleRect(0.5 * (outline.value(1) + outline.value(2)));
154 helper.drawHandleRect(0.5 * (outline.value(2) + outline.value(3)));
155 helper.drawHandleRect(0.5 * (outline.value(3) + outline.value(0)));
156
157 QPointF hotPos = KoFlake::anchorToPoint(m_hotPosition, handleArea);
159 helper.drawHandleRect(hotPos);
160 }
161 }
162
163 if (haveOnlyOneEditableShape) {
164 KoShape *shape = selectedShapes.first();
165
167 paintGradientHandles(shape, KoFlake::Fill, painter, converter);
169 paintGradientHandles(shape, KoFlake::StrokeFill, painter, converter);
170 }
171
172 // paint meshgradient handles
174 paintMeshGradientHandles(shape, KoFlake::Fill, painter, converter);
175 }
176 }
177
178}
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 & highlightedPrimaryHandles()
static KisHandleStyle & secondarySelection()
static KisHandleStyle & primarySelection()
const QList< KoShape * > selectedVisibleShapes() const
QRectF outlineRect() const override
const QList< KoShape * > selectedEditableShapes() const
virtual QRectF outlineRect() const
Definition KoShape.cpp:637
virtual QPainterPath outline() const
Definition KoShape.cpp:630
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:1165
static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
Definition KoShape.cpp:1177
static QList< KoShape * > linearizeSubtree(const QList< KoShape * > &shapes)
Definition KoShape.cpp:1381
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

References KoFlake::anchorToPoint(), KoShape::createHandlePainterHelperView(), KisHandlePainterHelper::drawHandleRect(), KisHandlePainterHelper::drawRubberLine(), KoFlake::Fill, KisHandleStyle::highlightedPrimaryHandles(), KoShape::isShapeEditable(), KoShape::linearizeSubtree(), m_decorationThickness, m_forceShapeOutlines, m_handleRadius, m_hotPosition, m_selection, m_showFillGradientHandles, m_showFillMeshGradientHandles, m_showStrokeFillGradientHandles, KoShape::outline(), KoShape::outlineRect(), KoSelection::outlineRect(), paintGradientHandles(), paintMeshGradientHandles(), 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 180 of file SelectionDecorator.cpp.

181{
182 KoShapeGradientHandles gradientHandles(fillVariant, shape);
183 QVector<KoShapeGradientHandles::Handle> handles = gradientHandles.handles();
184
187
188 const QTransform t = shape->absoluteTransformation().inverted();
189
190 if (gradientHandles.type() == QGradient::LinearGradient) {
191 KIS_SAFE_ASSERT_RECOVER_NOOP(handles.size() == 2);
192
193 if (handles.size() == 2) {
195 helper.drawGradientArrow(t.map(handles[0].pos), t.map(handles[1].pos), 1.5 * m_handleRadius);
196 }
197 }
198
200
201 Q_FOREACH (const KoShapeGradientHandles::Handle &h, handles) {
203 helper.drawGradientCrossHandle(t.map(h.pos), 1.2 * m_handleRadius);
204 } else {
205 helper.drawGradientHandle(t.map(h.pos), 1.2 * m_handleRadius);
206 }
207 }
208}
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 & gradientHandles()
static KisHandleStyle & gradientArrows()
QTransform absoluteTransformation() const
Definition KoShape.cpp:382
#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(), KoShapeGradientHandles::handles(), KIS_SAFE_ASSERT_RECOVER_NOOP, m_decorationThickness, m_handleRadius, 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 210 of file SelectionDecorator.cpp.

214{
215 KoShapeMeshGradientHandles gradientHandles(fillVariant, shape);
216
220
221 helper.drawPath(gradientHandles.path());
222
223 // invert them, because we draw in logical coordinates.
224 const QTransform t = shape->absoluteTransformation().inverted();
225 const QVector<KoShapeMeshGradientHandles::Handle> cornerHandles = gradientHandles.handles();
226 for (const auto& corner: cornerHandles) {
227 const QPointF point = t.map(corner.pos);
229 helper.drawConnectionLine(gradientHandles.getAttachedCorner(corner), point);
230 helper.drawHandleSmallCircle(point);
231 } else if (corner.type == KoShapeMeshGradientHandles::Handle::Corner) {
232 helper.drawHandleCircle(point);
233 }
234 }
235
237
238 // highlight the selected handle (only corner)
240 helper.drawHandleRect(t.map(gradientHandles.getHandle(m_selectedMeshHandle.getPosition()).pos));
241 }
242
243 // highlight the path which is being hovered/moved
245 QVector<QPainterPath> paths = gradientHandles.getConnectedPath(m_currentHoveredMeshHandle);
246 for (const auto &path: paths) {
247 helper.drawPath(path);
248 }
249 }
250}
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()
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(), KoShapeMeshGradientHandles::handles(), KisHandleStyle::highlightedPrimaryHandlesWithSolidOutline(), m_currentHoveredMeshHandle, m_decorationThickness, m_handleRadius, m_selectedMeshHandle, KoShapeMeshGradientHandles::Handle::None, 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 77 of file SelectionDecorator.cpp.

79{
80 m_selectedMeshHandle = selectedHandle;
81 m_currentHoveredMeshHandle = hoveredHandle;
82}

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 57 of file SelectionDecorator.cpp.

58{
59 m_decorationThickness = thickness;
60}

References m_decorationThickness.

◆ setForceShapeOutlines()

void SelectionDecorator::setForceShapeOutlines ( bool value)

Definition at line 252 of file SelectionDecorator.cpp.

253{
255}
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 52 of file SelectionDecorator.cpp.

53{
54 m_handleRadius = radius;
55}

References m_handleRadius.

◆ setSelection()

void SelectionDecorator::setSelection ( KoSelection * selection)

set the selection that is to be painted.

Parameters
selectionthe current selection.

Definition at line 47 of file SelectionDecorator.cpp.

48{
49 m_selection = selection;
50}

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 62 of file SelectionDecorator.cpp.

References m_showFillGradientHandles, and value().

◆ setShowFillMeshGradientHandles()

void SelectionDecorator::setShowFillMeshGradientHandles ( bool value)

Definition at line 72 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 67 of file SelectionDecorator.cpp.

References m_showStrokeFillGradientHandles, and value().

Member Data Documentation

◆ m_currentHoveredMeshHandle

KoShapeMeshGradientHandles::Handle SelectionDecorator::m_currentHoveredMeshHandle
private

Definition at line 92 of file SelectionDecorator.h.

◆ m_decorationThickness

int SelectionDecorator::m_decorationThickness {1}
private

Definition at line 95 of file SelectionDecorator.h.

95{1};

◆ m_forceShapeOutlines

bool SelectionDecorator::m_forceShapeOutlines {false}
private

Definition at line 99 of file SelectionDecorator.h.

99{false};

◆ m_handleRadius

int SelectionDecorator::m_handleRadius {7}
private

Definition at line 94 of file SelectionDecorator.h.

94{7};

◆ m_hotPosition

KoFlake::AnchorPosition SelectionDecorator::m_hotPosition
private

Definition at line 90 of file SelectionDecorator.h.

◆ m_selectedMeshHandle

KoShapeMeshGradientHandles::Handle SelectionDecorator::m_selectedMeshHandle
private

Definition at line 93 of file SelectionDecorator.h.

◆ m_selection

KoSelection* SelectionDecorator::m_selection {nullptr}
private

Definition at line 91 of file SelectionDecorator.h.

91{nullptr};

◆ m_showFillGradientHandles

bool SelectionDecorator::m_showFillGradientHandles {false}
private

Definition at line 96 of file SelectionDecorator.h.

96{false};

◆ m_showFillMeshGradientHandles

bool SelectionDecorator::m_showFillMeshGradientHandles {false}
private

Definition at line 98 of file SelectionDecorator.h.

98{false};

◆ m_showStrokeFillGradientHandles

bool SelectionDecorator::m_showStrokeFillGradientHandles {false}
private

Definition at line 97 of file SelectionDecorator.h.

97{false};

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