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

#include <KoShapePainter.h>

+ Inheritance diagram for KoShapePainter:

Public Member Functions

QRectF contentRect () const
 Returns the bounding rect of the shapes to paint.
 
 KoShapePainter ()
 
void paint (QImage &image)
 
void paint (QPainter &painter)
 
void paint (QPainter &painter, const QRect &painterRect, const QRectF &documentRect)
 
 Private ()
 
void setShapes (const QList< KoShape * > &shapes)
 
 ~KoShapePainter ()
 
 ~Private ()
 

Public Attributes

SimpleCanvascanvas
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Additional Inherited Members

- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

A utility class to paint a subset of shapes onto a QPainter. Notice that using setShapes repeatedly is very expensive, as it populates the shapeManager and all its caching every time. If at all possible use a shapeManager directly and avoid losing the cache between usages.

Definition at line 104 of file KoShapePainter.cpp.

Constructor & Destructor Documentation

◆ ~Private()

KoShapePainter::~Private ( )
inline

Definition at line 112 of file KoShapePainter.cpp.

112{ delete canvas; }
SimpleCanvas * canvas

◆ KoShapePainter()

KoShapePainter::KoShapePainter ( )
explicit

Definition at line 116 of file KoShapePainter.cpp.

117 : d(new Private())
118{
119}
Private *const d

◆ ~KoShapePainter()

KoShapePainter::~KoShapePainter ( )

Definition at line 121 of file KoShapePainter.cpp.

122{
123 delete d;
124}

References d.

Member Function Documentation

◆ contentRect()

QRectF KoShapePainter::contentRect ( ) const

Returns the bounding rect of the shapes to paint.

Definition at line 190 of file KoShapePainter.cpp.

191{
192 QRectF bound;
193 foreach (KoShape *shape, d->canvas->shapeManager()->shapes()) {
194 if (!shape->isVisible())
195 continue;
196 if (dynamic_cast<KoShapeGroup*>(shape))
197 continue;
198
199 QRectF shapeRect = shape->boundingRect();
200
201 if (bound.isEmpty())
202 bound = shapeRect;
203 else
204 bound = bound.united(shapeRect);
205 }
206 return bound;
207}
KoShapeManager shapeManager
QList< KoShape * > shapes
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
bool isVisible(bool recursive=true) const
Definition KoShape.cpp:979
KisCanvas2 * canvas

References KoShape::boundingRect(), Private::canvas, d, KoShape::isVisible(), KisCanvas2::shapeManager, and KoShapeManager::shapes.

◆ paint() [1/3]

void KoShapePainter::paint ( QImage & image)

Paints shapes to the given image, so that all shapes fit onto it.

Parameters
imagethe image to paint into
Returns
false if image is empty, else true

Definition at line 180 of file KoShapePainter.cpp.

181{
182 if (image.isNull())
183 return;
184
185 QPainter painter(&image);
186
187 paint(painter, image.rect(), contentRect());
188}
QRectF contentRect() const
Returns the bounding rect of the shapes to paint.
void paint(QPainter &painter)

References contentRect(), and paint().

◆ paint() [2/3]

void KoShapePainter::paint ( QPainter & painter)

Paints the shapes on the given painter and using the zoom handler.

Parameters
painterthe painter to paint on
converterthe view converter defining the zoom to use

Definition at line 131 of file KoShapePainter.cpp.

132{
133 foreach (KoShape *shape, d->canvas->shapeManager()->shapes()) {
134 shape->waitUntilReady(false);
135 }
136
137 d->canvas->shapeManager()->paint(painter);
138}
void paint(QPainter &painter)
virtual void waitUntilReady(bool asynchronous=true) const
Definition KoShape.cpp:1160

References Private::canvas, d, KoShapeManager::paint(), KisCanvas2::shapeManager, KoShapeManager::shapes, and KoShape::waitUntilReady().

◆ paint() [3/3]

void KoShapePainter::paint ( QPainter & painter,
const QRect & painterRect,
const QRectF & documentRect )

Paints the shapes on the given painter. The given document rectangle is painted to fit into the given painter rectangle.

Parameters
painterthe painter to paint on
painterRectthe destination rectangle on the painter
documentRectthe document region to paint

Definition at line 140 of file KoShapePainter.cpp.

141{
142 if (documentRect.width() == 0.0f || documentRect.height() == 0.0f)
143 return;
144
145 KoViewConverter converter;
146 // calculate the painter destination rectangle size in document coordinates
147 QRectF paintBox = converter.viewToDocument(QRectF(QPointF(), painterRect.size()));
148
149 // compute the zoom factor based on the bounding rects in document coordinates
150 // so that the content fits into the image
151 qreal zoomW = paintBox.width() / documentRect.width();
152 qreal zoomH = paintBox.height() / documentRect.height();
153 qreal zoom = qMin(zoomW, zoomH);
154
155 // now set the zoom into the zoom handler used for painting the shape
156 converter.setZoom(zoom);
157
158 painter.save();
159
160 // initialize painter
161 painter.setPen(QPen(Qt::NoPen));
162 painter.setBrush(Qt::NoBrush);
163 painter.setRenderHint(QPainter::Antialiasing);
164 painter.setClipRect(painterRect.adjusted(-1,-1,1,1));
165
166 // convert document rectangle to view coordinates
167 QRectF zoomedBound = converter.documentToView(documentRect);
168 // calculate offset between painter rectangle and converted document rectangle
169 QPointF offset = QRectF(painterRect).center() - zoomedBound.center();
170 // center content in painter rectangle
171 painter.translate(offset.x(), offset.y());
172 painter.setTransform(converter.documentToView(), true);
173
174 // finally paint the shapes
175 paint(painter);
176
177 painter.restore();
178}
virtual void setZoom(qreal zoom)
virtual QPointF viewToDocument(const QPointF &viewPoint) const
virtual QPointF documentToView(const QPointF &documentPoint) const
QAction * zoom(const QObject *recvr, const char *slot, QObject *parent)

References KoViewConverter::documentToView(), paint(), KoViewConverter::setZoom(), and KoViewConverter::viewToDocument().

◆ Private()

KoShapePainter::Private ( )
inline

Definition at line 107 of file KoShapePainter.cpp.

108 : canvas(new SimpleCanvas())
109 {
110 }

◆ setShapes()

void KoShapePainter::setShapes ( const QList< KoShape * > & shapes)

Sets the shapes to be painted.

Parameters
shapesthe shapes to paint

Definition at line 126 of file KoShapePainter.cpp.

127{
129}
@ AddWithoutRepaint
Avoids each shapes 'update()' to be called for faster addition when its possible.
void setShapes(const QList< KoShape * > &shapes, Repaint repaint=PaintShapeOnAdd)

References KoShapeManager::AddWithoutRepaint, Private::canvas, d, KoShapeManager::setShapes(), and KisCanvas2::shapeManager.

Member Data Documentation

◆ canvas

SimpleCanvas* KoShapePainter::canvas

Definition at line 113 of file KoShapePainter.cpp.

◆ d

Private* const KoShapePainter::d
private

Definition at line 66 of file KoShapePainter.h.


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