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

#include <kis_shape_selection.h>

+ Inheritance diagram for KisShapeSelection:

Signals

void sigMoveShapes (const QPointF &diff)
 

Public Member Functions

KisSelectionComponentclone (KisSelection *selection) override
 
bool isEmpty () const override
 
 KisShapeSelection (const KisShapeSelection &rhs, KisSelection *selection)
 
 KisShapeSelection (KoShapeControllerBase *shapeControllerBase, KisSelectionWSP selection)
 
bool loadSelection (KoStore *store, const QRect &imageRect)
 
void moveX (qint32 x) override
 
void moveY (qint32 y) override
 
QPainterPath outlineCache () const override
 
bool outlineCacheValid () const override
 
void recalculateOutlineCache () override
 
void renderToProjection (KisPaintDeviceSP projection) override
 
void renderToProjection (KisPaintDeviceSP projection, const QRect &r) override
 
KUndo2CommandresetToEmpty () override
 
bool saveSelection (KoStore *store, const QRect &imageRect) const
 
void setResolutionProxy (KisImageResolutionProxySP resolutionProxy) override
 
KoShapeManagershapeManager () const
 
KUndo2Commandtransform (const QTransform &transform) override
 
 ~KisShapeSelection () override
 
- Public Member Functions inherited from KoShapeLayer
QRectF boundingRect () const override
 Get the bounding box of the shape.
 
bool hitTest (const QPointF &position) const override
 Check if the shape is hit on position.
 
 KoShapeLayer ()
 The default constructor.
 
 KoShapeLayer (KoShapeContainerModel *model)
 
void paintComponent (QPainter &painter) const override
 
- Public Member Functions inherited from KoShapeContainer
void addShape (KoShape *shape)
 
bool inheritsTransform (const KoShape *shape) const
 
bool isClipped (const KoShape *child) const
 
 KoShapeContainer (KoShapeContainerModel *model=0)
 
KoShapeContainerModelmodel () const
 
void paint (QPainter &painter) const override
 reimplemented
 
 Private (const Private &rhs, KoShapeContainer *q)
 
 Private (KoShapeContainer *q)
 
void removeShape (KoShape *shape)
 
void setClipped (const KoShape *child, bool clipping)
 
void setInheritsTransform (const KoShape *shape, bool inherit)
 
int shapeCount () const
 
ShapeInterfaceshapeInterface ()
 
QList< KoShape * > shapes () const
 
virtual void update () const
 
void update () const override
 reimplemented
 
 ~KoShapeContainer () override
 
virtual ~Private ()
 
- Public Member Functions inherited from KoShape
QRectF absoluteOutlineRect () const
 
QPointF absolutePosition (KoFlake::AnchorPosition anchor=KoFlake::Center) const
 
QTransform absoluteTransformation () const
 
bool addDependee (KoShape *shape)
 
QString additionalAttribute (const QString &name) const
 
void addShapeChangeListener (ShapeChangeListener *listener)
 
KoShapeAnchoranchor () const
 
void applyAbsoluteTransformation (const QTransform &matrix)
 
void applyTransformation (const QTransform &matrix)
 
virtual QSharedPointer< KoShapeBackgroundbackground () const
 
virtual ChildZOrderPolicy childZOrderPolicy ()
 
KoClipMaskclipMask () const
 Returns the currently set clip mask or 0 if there is no clip mask set.
 
KoClipPathclipPath () const
 Returns the currently set clip path or 0 if there is no clip path set.
 
virtual KoShapecloneShape () const
 creates a deep copy of the shape or shape's subtree
 
KoShapecloneShapeAndBakeAbsoluteTransform () const
 creates a deep copy of the shape/shapes tree and bakes the absolute transform of this into the resulting shape.
 
void copySettings (const KoShape *shape)
 
QList< KoShape * > dependees () const
 Returns list of shapes depending on this shape.
 
QPointF documentToShape (const QPointF &point) const
 Transforms point from document coordinates to shape coordinates.
 
QRectF documentToShape (const QRectF &rect) const
 Transform rect from document coordinates to shape coordinates.
 
KoFilterEffectStackfilterEffectStack () const
 
bool hasAdditionalAttribute (const QString &name) const
 
bool hasCommonParent (const KoShape *shape) const
 
bool hasDependee (KoShape *shape) const
 Returns if the given shape is dependent on this shape.
 
virtual bool hasTransparency () const
 
QString hyperLink () const
 
bool inheritBackground () const
 inheritBackground shows if the shape inherits background from its parent
 
bool inheritPaintOrder () const
 inheritPaintOrder
 
bool inheritsTransformFromAny (const QList< KoShape * > ancestorsInQuestion) const
 inheritsTransformFromAny checks if the shape inherits transformation from any of the shapes listed in ancestorsInQuestion. The inheritance is checked in recursive way.
 
bool inheritStroke () const
 inheritStroke shows if the shape inherits the stroke from its parent
 
bool isContentProtected () const
 
bool isGeometryProtected () const
 
bool isPrintable () const
 
bool isSelectable () const
 
virtual bool isShapeEditable (bool recursive=true) const
 checks recursively if the shape or one of its parents is not visible or locked
 
bool isVisible (bool recursive=true) const
 
bool keepAspectRatio () const
 
 KoShape ()
 Constructor.
 
qreal minimumHeight () const
 
QString name () const
 
void notifyChanged ()
 
virtual QPainterPath outline () const
 
virtual QRectF outlineRect () const
 
virtual void paintMarkers (QPainter &painter) const
 paintStroke paints the shape's markers
 
virtual QVector< PaintOrderpaintOrder () const
 paintOrder
 
virtual void paintStroke (QPainter &painter) const
 paintStroke paints the shape's stroked outline
 
KoShapeContainerparent () const
 
QPointF position () const
 Get the position of the shape in pt.
 
void removeAdditionalAttribute (const QString &name)
 
void removeAdditionalStyleAttribute (const char *name)
 
void removeDependee (KoShape *shape)
 
void removeShapeChangeListener (ShapeChangeListener *listener)
 
void rotate (qreal angle)
 Rotate the shape (relative)
 
qreal rotation () const
 
int runThrough () const
 
void scale (qreal sx, qreal sy)
 Scale the shape using the zero-point which is the top-left corner.
 
void setAbsolutePosition (const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
 
void setAdditionalAttribute (const QString &name, const QString &value)
 
void setAdditionalStyleAttribute (const char *name, const QString &value)
 
void setAnchor (KoShapeAnchor *anchor)
 
virtual void setBackground (QSharedPointer< KoShapeBackground > background)
 
void setClipMask (KoClipMask *clipMask)
 Sets a new clip mask, removing the old one. The mask is owned by the shape.
 
void setClipPath (KoClipPath *clipPath)
 Sets a new clip path, removing the old one.
 
void setContentProtected (bool protect)
 
void setFilterEffectStack (KoFilterEffectStack *filterEffectStack)
 Sets the new filter effect stack, removing the old one.
 
void setGeometryProtected (bool on)
 
void setHyperLink (const QString &hyperLink)
 
void setInheritBackground (bool value)
 setInheritBackground marks a shape as inheriting the background from the parent shape. NOTE: The currently selected background is destroyed.
 
void setInheritPaintOrder (bool value)
 setInheritPaintOrder set inherit paint order.
 
void setInheritStroke (bool value)
 setInheritStroke marks a shape as inheriting the stroke from the parent shape. NOTE: The currently selected stroke is destroyed.
 
void setKeepAspectRatio (bool keepAspect)
 
void setMinimumHeight (qreal height)
 
void setName (const QString &name)
 
virtual void setPaintOrder (PaintOrder first, PaintOrder second)
 setPaintOrder set the paint order. As there's only three entries in any given paintorder, you only need to have the first and second entry to set it.
 
void setParent (KoShapeContainer *parent)
 
virtual void setPosition (const QPointF &position)
 Set the position of the shape in pt.
 
void setPrintable (bool on)
 
virtual void setResolution (qreal xRes, qreal yRes)
 
virtual void setRunThrough (short int runThrough)
 
void setSelectable (bool selectable)
 
void setShadow (KoShapeShadow *shadow)
 Sets the new shadow, removing the old one.
 
void setShapeId (const QString &id)
 
virtual void setSize (const QSizeF &size)
 Resize the shape.
 
virtual void setStroke (KoShapeStrokeModelSP stroke)
 
void setTextRunAroundContour (TextRunAroundContour contour)
 
void setTextRunAroundDistanceBottom (qreal distance)
 
void setTextRunAroundDistanceLeft (qreal distance)
 
void setTextRunAroundDistanceRight (qreal distance)
 
void setTextRunAroundDistanceTop (qreal distance)
 
void setTextRunAroundSide (TextRunAroundSide side, RunThroughLevel runThrough=Background)
 
void setTextRunAroundThreshold (qreal threshold)
 
void setToolDelegates (const QSet< KoShape * > &delegates)
 
void setTransformation (const QTransform &matrix)
 
void setTransparency (qreal transparency)
 
void setUserData (KoShapeUserData *userData)
 
void setVisible (bool on)
 
void setZIndex (qint16 zIndex)
 
KoShapeShadowshadow () const
 Returns the currently set shadow or 0 if there is no shadow set.
 
virtual QPainterPath shadowOutline () const
 
QString shapeId () const
 
QPointF shapeToDocument (const QPointF &point) const
 Transforms point from shape coordinates to document coordinates.
 
QRectF shapeToDocument (const QRectF &rect) const
 Transforms rect from shape coordinates to document coordinates.
 
void shear (qreal sx, qreal sy)
 Shear the shape The shape will be sheared using the zero-point which is the top-left corner.
 
virtual QSizeF size () const
 Get the size of the shape in pt.
 
virtual KoSnapData snapData () const
 Returns additional snap data the shape wants to have snapping to.
 
virtual KoShapeStrokeModelSP stroke () const
 
KoInsets strokeInsets () const
 
TextRunAroundContour textRunAroundContour () const
 
qreal textRunAroundDistanceBottom () const
 
qreal textRunAroundDistanceLeft () const
 
qreal textRunAroundDistanceRight () const
 
qreal textRunAroundDistanceTop () const
 
TextRunAroundSide textRunAroundSide () const
 
qreal textRunAroundThreshold () const
 
QSet< KoShape * > toolDelegates () const
 
QTransform transformation () const
 Returns the shapes local transformation matrix.
 
qreal transparency (bool recursive=false) const
 
virtual void updateAbsolute (const QRectF &rect) const
 
KoShapeUserDatauserData () const
 
virtual void waitUntilReady (bool asynchronous=true) const
 
qint16 zIndex () const
 
virtual ~KoShape ()
 Destructor.
 
- Public Member Functions inherited from KisSelectionComponent
 KisSelectionComponent ()
 
virtual ~KisSelectionComponent ()
 

Protected Member Functions

void paintComponent (QPainter &painter) const override
 Paint the component Implement this method to allow the shape to paint itself, just like the KoShape::paint() method does.
 
- Protected Member Functions inherited from KoShapeContainer
 KoShapeContainer (const KoShapeContainer &rhs)
 
void setModel (KoShapeContainerModel *model)
 
void setModelInit (KoShapeContainerModel *model)
 
void shapeChanged (ChangeType type, KoShape *shape=0) override
 
virtual void shapeCountChanged ()
 
- Protected Member Functions inherited from KoShape
 KoShape (const KoShape &rhs)
 
QList< ShapeChangeListener * > listeners () const
 
void setSizeImpl (const QSizeF &size) const
 
void shapeChangedPriv (KoShape::ChangeType type)
 
QTransform transform () const
 return the current matrix that contains the rotation/scale/position of this shape
 

Private Slots

void slotMoveShapes (const QPointF &diff)
 

Private Member Functions

void init (KisImageResolutionProxySP resolutionProxy, KoShapeControllerBase *shapeControllerBase)
 
KisShapeSelectionModelinitModel (KisImageWSP image, KisSelectionWSP selection)
 
 KisShapeSelection (const KisShapeSelection &rhs)
 
void renderSelection (KisPaintDeviceSP projection, const QRect &requestedRect)
 
void setUpdatesEnabled (bool enabled)
 
bool updatesEnabled () const
 

Private Attributes

KisShapeSelectionCanvasm_canvas {nullptr}
 
KisImageViewConverterm_converter {nullptr}
 
KisShapeSelectionModelm_model
 
QPainterPath m_outline
 
KisImageResolutionProxySP m_resolutionProxy
 
KoShapeControllerBasem_shapeControllerBase {nullptr}
 

Friends

class KisShapeSelectionModel
 
class KisTakeAllShapesCommand
 

Additional Inherited Members

- Public Types inherited from KoShape
enum  ChangeType {
  PositionChanged , RotationChanged , ScaleChanged , ShearChanged ,
  SizeChanged , GenericMatrixChange , KeepAspectRatioChange , ParentChanged ,
  Deleted , StrokeChanged , BackgroundChanged , ShadowChanged ,
  BorderChanged , ParameterChanged , ContentChanged , TextRunAroundChanged ,
  ChildChanged , ConnectionPointChanged , ClipPathChanged , ClipMaskChanged ,
  TransparencyChanged
}
 Used by shapeChanged() to select which change was made. More...
 
enum  ChildZOrderPolicy { ChildZDefault , ChildZParentChild = ChildZDefault , ChildZPassThrough }
 Used by compareShapeZIndex() to order shapes. More...
 
enum  PaintOrder { Fill , Stroke , Markers }
 
enum  RunThroughLevel { Background , Foreground }
 
enum  TextRunAroundContour { ContourBox , ContourFull , ContourOutside }
 The behavior text should do when intersecting this shape. More...
 
enum  TextRunAroundSide {
  BiggestRunAroundSide , LeftRunAroundSide , RightRunAroundSide , EnoughRunAroundSide ,
  BothRunAroundSide , NoRunAround , RunThrough
}
 The behavior text should do when intersecting this shape. More...
 
- Static Public Member Functions inherited from KoShape
static QRectF absoluteOutlineRect (const QList< KoShape * > &shapes)
 
static QRectF boundingRect (const QList< KoShape * > &shapes)
 
static bool compareShapeZIndex (KoShape *s1, KoShape *s2)
 
static KisHandlePainterHelper createHandlePainterHelperDocument (QPainter *painter, KoShape *shape, qreal handleRadius, int decorationThickness)
 
static KisHandlePainterHelper createHandlePainterHelperView (QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
 
static QVector< PaintOrderdefaultPaintOrder ()
 default paint order as per SVG specification
 
static QList< KoShape * > linearizeSubtree (const QList< KoShape * > &shapes)
 
static QList< KoShape * > linearizeSubtreeSorted (const QList< KoShape * > &shapes)
 
- Public Attributes inherited from KoShapeContainer
KoShapeContainerModelmodel
 
KoShapeContainer::ShapeInterface shapeInterface
 
- Static Public Attributes inherited from KoShape
static const qint16 maxZIndex = std::numeric_limits<qint16>::max()
 
static const qint16 minZIndex = std::numeric_limits<qint16>::min()
 

Detailed Description

Definition at line 42 of file kis_shape_selection.h.

Constructor & Destructor Documentation

◆ KisShapeSelection() [1/3]

KisShapeSelection::KisShapeSelection ( const KisShapeSelection & rhs)
private

◆ KisShapeSelection() [2/3]

KisShapeSelection::KisShapeSelection ( KoShapeControllerBase * shapeControllerBase,
KisSelectionWSP selection )

Definition at line 50 of file kis_shape_selection.cpp.

51 : KoShapeLayer(new KisShapeSelectionModel(selection->resolutionProxy(), selection, this)),
52 m_model(static_cast<KisShapeSelectionModel*>(this->model())),
54{
55 init(m_resolutionProxy, shapeControllerBase);
56}
KisImageResolutionProxySP resolutionProxy() const
void init(KisImageResolutionProxySP resolutionProxy, KoShapeControllerBase *shapeControllerBase)
KisShapeSelectionModel * m_model
friend class KisShapeSelectionModel
KisImageResolutionProxySP m_resolutionProxy
KoShapeContainerModel * model
KoShapeLayer()
The default constructor.
KisImageResolutionProxySP resolutionProxy

References init(), and m_resolutionProxy.

◆ ~KisShapeSelection()

KisShapeSelection::~KisShapeSelection ( )
override

Definition at line 81 of file kis_shape_selection.cpp.

82{
84 delete m_canvas;
85 delete m_converter;
86}
void setShapeSelection(KisShapeSelection *selection)
KisImageViewConverter * m_converter
KisShapeSelectionCanvas * m_canvas

References m_canvas, m_converter, m_model, and KisShapeSelectionModel::setShapeSelection().

◆ KisShapeSelection() [3/3]

KisShapeSelection::KisShapeSelection ( const KisShapeSelection & rhs,
KisSelection * selection )

Definition at line 58 of file kis_shape_selection.cpp.

59 : KoShapeLayer(new KisShapeSelectionModel(selection->resolutionProxy(), selection, this)),
60 m_model(static_cast<KisShapeSelectionModel*>(this->model())),
62{
64
65 // TODO: refactor shape selection to pass signals
66 // via KoShapeManager, not via the model
69
71 Q_FOREACH (KoShape *shape, rhs.shapes()) {
72 KoShape *clonedShape = shape->cloneShape();
73 KIS_SAFE_ASSERT_RECOVER(clonedShape) { continue; }
74 this->addShape(clonedShape);
75 }
76
79}
KoShapeManager * shapeManager() const override
KoShapeControllerBase * m_shapeControllerBase
QList< KoShape * > shapes() const
void addShape(KoShape *shape)
void setUpdatesBlocked(bool value)
void addShape(KoShape *shape, KoShapeManager::Repaint repaint=PaintShapeOnAdd)
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
Definition KoShape.cpp:200
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126

References KoShapeContainer::addShape(), KoShapeManager::addShape(), KoShape::cloneShape(), init(), KIS_SAFE_ASSERT_RECOVER, m_canvas, m_model, m_resolutionProxy, m_shapeControllerBase, KoShapeManager::setUpdatesBlocked(), KisShapeSelectionModel::setUpdatesEnabled(), KisShapeSelectionCanvas::shapeManager(), and KoShapeContainer::shapes().

Member Function Documentation

◆ clone()

KisSelectionComponent * KisShapeSelection::clone ( KisSelection * selection)
overridevirtual

Implements KisSelectionComponent.

Definition at line 109 of file kis_shape_selection.cpp.

110{
111 return new KisShapeSelection(*this, selection);
112}
KisShapeSelection(const KisShapeSelection &rhs)

References KisShapeSelection().

◆ init()

void KisShapeSelection::init ( KisImageResolutionProxySP resolutionProxy,
KoShapeControllerBase * shapeControllerBase )
private

Definition at line 88 of file kis_shape_selection.cpp.

89{
90 KIS_SAFE_ASSERT_RECOVER_RETURN(resolutionProxy);
91 KIS_SAFE_ASSERT_RECOVER_RETURN(shapeControllerBase);
92
93 m_shapeControllerBase = shapeControllerBase;
94
95 setShapeId("KisShapeSelection");
96 setSelectable(false);
97 m_converter = new KisImageViewConverter(resolutionProxy);
98 m_canvas = new KisShapeSelectionCanvas(shapeControllerBase);
100
101 m_model->setObjectName("KisShapeSelectionModel");
102 m_model->moveToThread(qApp->thread());
103 m_canvas->setObjectName("KisShapeSelectionCanvas");
104 m_canvas->moveToThread(qApp->thread());
105
106 connect(this, SIGNAL(sigMoveShapes(QPointF)), SLOT(slotMoveShapes(QPointF)));
107}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void slotMoveShapes(const QPointF &diff)
void sigMoveShapes(const QPointF &diff)
void setSelectable(bool selectable)
Definition KoShape.cpp:1009
void setShapeId(const QString &id)
Definition KoShape.cpp:1062
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References KoShapeManager::addShape(), connect(), KIS_SAFE_ASSERT_RECOVER_RETURN, m_canvas, m_converter, m_model, m_shapeControllerBase, KoShape::setSelectable(), KoShape::setShapeId(), KisShapeSelectionCanvas::shapeManager(), sigMoveShapes(), and slotMoveShapes().

◆ initModel()

KisShapeSelectionModel * KisShapeSelection::initModel ( KisImageWSP image,
KisSelectionWSP selection )
private

◆ isEmpty()

bool KisShapeSelection::isEmpty ( ) const
overridevirtual

Implements KisSelectionComponent.

Definition at line 169 of file kis_shape_selection.cpp.

170{
171 return !m_model->count();
172}

References KisShapeSelectionModel::count(), and m_model.

◆ loadSelection()

bool KisShapeSelection::loadSelection ( KoStore * store,
const QRect & imageRect )

Definition at line 122 of file kis_shape_selection.cpp.

123{
124 QSizeF fragmentSize; // unused!
125
126 // FIXME: we handle xRes() only!
128 const qreal resolutionPPI = 72.0 * m_resolutionProxy->xRes();
129
131
132 if (store->open("content.svg")) {
133 KoStoreDevice storeDev(store);
134 storeDev.open(QIODevice::ReadOnly);
135
137 "", imageRect,
138 resolutionPPI, m_canvas->shapeController()->resourceManager(),
139 true,
140 &fragmentSize);
141
142 store->close();
143
144 Q_FOREACH (KoShape *shape, shapes) {
145 addShape(shape);
146 }
147
148 return true;
149 }
150
151 return false;
152}
static QList< KoShape * > createShapesFromSvg(QIODevice *device, const QString &baseXmlDir, const QRectF &rectInPixels, qreal resolutionPPI, KoDocumentResourceManager *resourceManager, bool loadingFromKra, QSizeF *fragmentSize, QStringList *warnings=0, QStringList *errors=0)
QPointer< KoShapeController > shapeController
bool close()
Definition KoStore.cpp:156
bool open(const QString &name)
Definition KoStore.cpp:109
static bool qFuzzyCompare(half p1, half p2)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KoShapeContainer::addShape(), KoStore::close(), KisShapeLayer::createShapesFromSvg(), KIS_SAFE_ASSERT_RECOVER_NOOP, m_canvas, m_resolutionProxy, KoStore::open(), KoStoreDevice::open(), qFuzzyCompare(), KoCanvasBase::shapeController, and KoShapeContainer::shapes().

◆ moveX()

void KisShapeSelection::moveX ( qint32 x)
overridevirtual

Reimplemented from KisSelectionComponent.

Definition at line 284 of file kis_shape_selection.cpp.

285{
286 const QPointF diff(x / m_resolutionProxy->xRes(), 0);
287 Q_EMIT sigMoveShapes(diff);
288}

References m_resolutionProxy, and sigMoveShapes().

◆ moveY()

void KisShapeSelection::moveY ( qint32 y)
overridevirtual

Reimplemented from KisSelectionComponent.

Definition at line 290 of file kis_shape_selection.cpp.

291{
292 const QPointF diff(0, y / m_resolutionProxy->yRes());
293 Q_EMIT sigMoveShapes(diff);
294}

References m_resolutionProxy, and sigMoveShapes().

◆ outlineCache()

QPainterPath KisShapeSelection::outlineCache ( ) const
overridevirtual

Implements KisSelectionComponent.

Definition at line 174 of file kis_shape_selection.cpp.

175{
176 return m_outline;
177}

References m_outline.

◆ outlineCacheValid()

bool KisShapeSelection::outlineCacheValid ( ) const
overridevirtual

Implements KisSelectionComponent.

Definition at line 179 of file kis_shape_selection.cpp.

180{
181 return true;
182}

◆ paintComponent()

void KisShapeSelection::paintComponent ( QPainter & painter) const
overrideprotectedvirtual

Paint the component Implement this method to allow the shape to paint itself, just like the KoShape::paint() method does.

Parameters
painterused for painting the shape
See also
applyConversion()

Implements KoShapeContainer.

Definition at line 208 of file kis_shape_selection.cpp.

209{
210 Q_UNUSED(painter);
211}

◆ recalculateOutlineCache()

void KisShapeSelection::recalculateOutlineCache ( )
overridevirtual

WARNING: we should unite all the shapes in image coordinates, not in points. Boolean operations inside the QPainterPath linearize the curves into lines and they use absolute values for thresholds.

See KritaUtils::pathShapeBooleanSpaceWorkaround() for more info

Implements KisSelectionComponent.

Definition at line 184 of file kis_shape_selection.cpp.

185{
186 QTransform resolutionMatrix;
187 resolutionMatrix.scale(m_resolutionProxy->xRes(), m_resolutionProxy->yRes());
188
189 QList<KoShape*> shapesList = shapes();
190
191 QPainterPath outline;
192 Q_FOREACH (KoShape * shape, shapesList) {
201 QTransform shapeMatrix = shape->absoluteTransformation();
202 outline = outline.united(resolutionMatrix.map(shapeMatrix.map(shape->outline())));
203 }
204
206}
virtual QPainterPath outline() const
Definition KoShape.cpp:630
QTransform absoluteTransformation() const
Definition KoShape.cpp:382

References KoShape::absoluteTransformation(), m_outline, m_resolutionProxy, KoShape::outline(), and KoShapeContainer::shapes().

◆ renderSelection()

void KisShapeSelection::renderSelection ( KisPaintDeviceSP projection,
const QRect & requestedRect )
private

Definition at line 227 of file kis_shape_selection.cpp.

228{
230
231 const qint32 MASK_IMAGE_WIDTH = 256;
232 const qint32 MASK_IMAGE_HEIGHT = 256;
233
234 QPainterPath selectionOutline = outlineCache();
235
236 if (projection->defaultBounds()->currentLevelOfDetail() > 0) {
237 KisLodTransform t(projection);
238 selectionOutline = t.map(selectionOutline);
239 }
240
241 if (*projection->defaultPixel().data() == OPACITY_TRANSPARENT_U8) {
242 projection->clear(requestedRect);
243 } else {
244 KoColor transparentColor = KoColor::createTransparent(projection->colorSpace());
245 projection->fill(requestedRect, transparentColor);
246 }
247 const QRect r = requestedRect & selectionOutline.boundingRect().toAlignedRect();
248
249 QImage polygonMaskImage(MASK_IMAGE_WIDTH, MASK_IMAGE_HEIGHT, QImage::Format_ARGB32);
250 QPainter maskPainter(&polygonMaskImage);
251 maskPainter.setRenderHint(QPainter::Antialiasing, true);
252
253 // Break the mask up into chunks so we don't have to allocate a potentially very large QImage.
254 for (qint32 x = r.x(); x < r.x() + r.width(); x += MASK_IMAGE_WIDTH) {
255 for (qint32 y = r.y(); y < r.y() + r.height(); y += MASK_IMAGE_HEIGHT) {
256
257 maskPainter.fillRect(polygonMaskImage.rect(), Qt::black);
258 maskPainter.translate(-x, -y);
259 maskPainter.fillPath(selectionOutline, Qt::white);
260 maskPainter.translate(x, y);
261
262 qint32 rectWidth = qMin(r.x() + r.width() - x, MASK_IMAGE_WIDTH);
263 qint32 rectHeight = qMin(r.y() + r.height() - y, MASK_IMAGE_HEIGHT);
264
265 KisSequentialIterator it(projection, QRect(x, y, rectWidth, rectHeight));
266 while (it.nextPixel()) {
267 (*it.rawData()) = qRed(polygonMaskImage.pixel(it.x() - x, it.y() - y));
268 }
269 }
270 }
271}
const quint8 OPACITY_TRANSPARENT_U8
virtual int currentLevelOfDetail() const =0
virtual void clear()
void fill(const QRect &rc, const KoColor &color)
const KoColorSpace * colorSpace() const
KoColor defaultPixel() const
KisDefaultBoundsBaseSP defaultBounds() const
QPainterPath outlineCache() const override
static KoColor createTransparent(const KoColorSpace *cs)
Definition KoColor.cpp:681
quint8 * data()
Definition KoColor.h:144

References KisPaintDevice::clear(), KisPaintDevice::colorSpace(), KoColor::createTransparent(), KisDefaultBoundsBase::currentLevelOfDetail(), KoColor::data(), KisPaintDevice::defaultBounds(), KisPaintDevice::defaultPixel(), KisPaintDevice::fill(), KIS_SAFE_ASSERT_RECOVER_RETURN, KisLodTransform::map(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), OPACITY_TRANSPARENT_U8, outlineCache(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::x(), and KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::y().

◆ renderToProjection() [1/2]

void KisShapeSelection::renderToProjection ( KisPaintDeviceSP projection)
overridevirtual

Renders the shapes to a selection. This method should only be called by KisSelection to update it's projection.

Parameters
projectionthe target selection

Implements KisSelectionComponent.

Definition at line 213 of file kis_shape_selection.cpp.

214{
215 Q_ASSERT(projection);
216
217 QRectF boundingRect = outlineCache().boundingRect();
218 renderSelection(projection, boundingRect.toAlignedRect());
219}
void renderSelection(KisPaintDeviceSP projection, const QRect &requestedRect)
QRectF boundingRect() const override
Get the bounding box of the shape.

References KoShapeLayer::boundingRect(), outlineCache(), and renderSelection().

◆ renderToProjection() [2/2]

void KisShapeSelection::renderToProjection ( KisPaintDeviceSP projection,
const QRect & r )
overridevirtual

Implements KisSelectionComponent.

Definition at line 221 of file kis_shape_selection.cpp.

222{
223 Q_ASSERT(projection);
224 renderSelection(projection, r);
225}

References renderSelection().

◆ resetToEmpty()

KUndo2Command * KisShapeSelection::resetToEmpty ( )
overridevirtual

Reimplemented from KisSelectionComponent.

Definition at line 164 of file kis_shape_selection.cpp.

165{
166 return new KisTakeAllShapesCommand(this, true, false);
167}
friend class KisTakeAllShapesCommand

References KisTakeAllShapesCommand.

◆ saveSelection()

bool KisShapeSelection::saveSelection ( KoStore * store,
const QRect & imageRect ) const

Definition at line 114 of file kis_shape_selection.cpp.

115{
116 const QSizeF sizeInPx = imageRect.size();
117 const QSizeF sizeInPt(sizeInPx.width() / m_resolutionProxy->xRes(), sizeInPx.height() / m_resolutionProxy->yRes());
118
119 return KisShapeLayer::saveShapesToStore(store, this->shapes(), sizeInPt);
120}
static bool saveShapesToStore(KoStore *store, QList< KoShape * > shapes, const QSizeF &sizeInPt)

References m_resolutionProxy, KisShapeLayer::saveShapesToStore(), and KoShapeContainer::shapes().

◆ setResolutionProxy()

void KisShapeSelection::setResolutionProxy ( KisImageResolutionProxySP resolutionProxy)
overridevirtual

Reimplemented from KisSelectionComponent.

Definition at line 336 of file kis_shape_selection.cpp.

337{
338 m_resolutionProxy = resolutionProxy;
339
340 // the model will automatically request update for the
341 // canvas and recalculation of the outline
342 m_model->setResolutionProxy(resolutionProxy);
343}
void setResolutionProxy(KisImageResolutionProxySP newResolutionProxy)

References m_model, m_resolutionProxy, and KisShapeSelectionModel::setResolutionProxy().

◆ setUpdatesEnabled()

void KisShapeSelection::setUpdatesEnabled ( bool enabled)
private

Definition at line 154 of file kis_shape_selection.cpp.

155{
156 m_model->setUpdatesEnabled(enabled);
157}

References m_model, and KisShapeSelectionModel::setUpdatesEnabled().

◆ shapeManager()

KoShapeManager * KisShapeSelection::shapeManager ( ) const

Definition at line 273 of file kis_shape_selection.cpp.

274{
275 return m_canvas->shapeManager();
276}

References m_canvas, and KisShapeSelectionCanvas::shapeManager().

◆ sigMoveShapes

void KisShapeSelection::sigMoveShapes ( const QPointF & diff)
signal

◆ slotMoveShapes

void KisShapeSelection::slotMoveShapes ( const QPointF & diff)
privateslot

Definition at line 296 of file kis_shape_selection.cpp.

297{
298 Q_FOREACH (KoShape* shape, shapeManager()->shapes()) {
299 if (shape != this) {
300 QPointF pos = shape->position();
301 shape->setPosition(pos + diff);
302 }
303 }
304}
KoShapeManager * shapeManager() const
virtual void setPosition(const QPointF &position)
Set the position of the shape in pt.
Definition KoShape.cpp:295
QPointF position() const
Get the position of the shape in pt.
Definition KoShape.cpp:825

References KoShape::position(), KoShape::setPosition(), shapeManager(), and KoShapeContainer::shapes().

◆ transform()

KUndo2Command * KisShapeSelection::transform ( const QTransform & transform)
overridevirtual

Reimplemented from KisSelectionComponent.

Definition at line 307 of file kis_shape_selection.cpp.

307 {
309 if(shapes.isEmpty()) return 0;
310
311 QTransform realTransform = m_converter->documentToView() *
313
314 QList<QTransform> oldTransformations;
315 QList<QTransform> newTransformations;
316
317 // this code won't work if there are shapes, that inherit the transformation from the parent container.
318 // the chart and tree shapes are examples for that, but they aren't used in krita and there are no other shapes like that.
319 Q_FOREACH (const KoShape* shape, shapes) {
320 QTransform oldTransform = shape->transformation();
321 oldTransformations.append(oldTransform);
322
323 // don't transform the container
324 if (dynamic_cast<const KoShapeGroup *>(shape) || !shape->parent()) {
325 newTransformations.append(oldTransform);
326 } else {
327 QTransform globalTransform = shape->absoluteTransformation();
328 QTransform localTransform = globalTransform * realTransform * globalTransform.inverted();
329 newTransformations.append(localTransform*oldTransform);
330 }
331 }
332
333 return new KoShapeTransformCommand(shapes, oldTransformations, newTransformations);
334}
QList< KoShape * > shapes
KoShapeContainer * parent() const
Definition KoShape.cpp:1039
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:424
QTransform transform() const
return the current matrix that contains the rotation/scale/position of this shape
Definition KoShape.cpp:1145
virtual QPointF viewToDocument(const QPointF &viewPoint) const
virtual QPointF documentToView(const QPointF &documentPoint) const

References KoShape::absoluteTransformation(), KoViewConverter::documentToView(), m_canvas, m_converter, KoShape::parent(), KisShapeSelectionCanvas::shapeManager(), KoShapeContainer::shapes(), KoShapeManager::shapes, KoShape::transform(), KoShape::transformation(), and KoViewConverter::viewToDocument().

◆ updatesEnabled()

bool KisShapeSelection::updatesEnabled ( ) const
private

Definition at line 159 of file kis_shape_selection.cpp.

160{
161 return m_model->updatesEnabled();
162}

References m_model, and KisShapeSelectionModel::updatesEnabled().

Friends And Related Symbol Documentation

◆ KisShapeSelectionModel

friend class KisShapeSelectionModel
friend

Definition at line 111 of file kis_shape_selection.h.

◆ KisTakeAllShapesCommand

friend class KisTakeAllShapesCommand
friend

Definition at line 96 of file kis_shape_selection.h.

Member Data Documentation

◆ m_canvas

KisShapeSelectionCanvas* KisShapeSelection::m_canvas {nullptr}
private

Definition at line 107 of file kis_shape_selection.h.

107{nullptr};

◆ m_converter

KisImageViewConverter* KisShapeSelection::m_converter {nullptr}
private

Definition at line 106 of file kis_shape_selection.h.

106{nullptr};

◆ m_model

KisShapeSelectionModel* KisShapeSelection::m_model
private

Definition at line 108 of file kis_shape_selection.h.

◆ m_outline

QPainterPath KisShapeSelection::m_outline
private

Definition at line 105 of file kis_shape_selection.h.

◆ m_resolutionProxy

KisImageResolutionProxySP KisShapeSelection::m_resolutionProxy
private

Definition at line 109 of file kis_shape_selection.h.

◆ m_shapeControllerBase

KoShapeControllerBase* KisShapeSelection::m_shapeControllerBase {nullptr}
private

Definition at line 110 of file kis_shape_selection.h.

110{nullptr};

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