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

#include <Selection.h>

+ Inheritance diagram for Selection:

Public Slots

void add (Selection *selection)
 
void border (int xRadius, int yRadius)
 
void clear ()
 
void contract (int value)
 
void copy (Node *node)
 copy copies the area defined by the selection from the node to the clipboard.
 
void cut (Node *node)
 cut erases the area defined by the selection from the node and puts a copy on the clipboard.
 
void dilate ()
 
Selectionduplicate () const
 
void erode ()
 
void feather (int radius)
 
void grow (int xradius, int yradius)
 
int height () const
 
void intersect (Selection *selection)
 
void invert ()
 
void move (int x, int y)
 
void paste (Node *destination, int x, int y)
 paste pastes the content of the clipboard to the given node, limited by the area of the current selection.
 
QByteArray pixelData (int x, int y, int w, int h) const
 pixelData reads the given rectangle from the Selection's mask and returns it as a byte array. The pixel data starts top-left, and is ordered row-first.
 
void replace (Selection *selection)
 
void resize (int w, int h)
 
void select (int x, int y, int w, int h, int value)
 
void selectAll (Node *node, int value)
 
void setPixelData (QByteArray value, int x, int y, int w, int h)
 setPixelData writes the given bytes, of which there must be enough, into the Selection.
 
void shrink (int xRadius, int yRadius, bool edgeLock)
 
void smooth ()
 
void subtract (Selection *selection)
 
void symmetricdifference (Selection *selection)
 
int width () const
 
int x () const
 
int y () const
 

Public Member Functions

bool operator!= (const Selection &other) const
 
bool operator== (const Selection &other) const
 
 Selection (KisSelectionSP selection, QObject *parent=0)
 
 Selection (QObject *parent=0)
 
 ~Selection () override
 

Private Member Functions

KisSelectionSP selection () const
 

Private Attributes

Private *const d
 

Friends

class Document
 
class FillLayer
 
class FilterLayer
 
class FilterMask
 
class SelectionMask
 
class TransparencyMask
 

Detailed Description

Selection represents a selection on Krita. A selection is not necessarily associated with a particular Node or Image.

from krita import *
d = Application.activeDocument()
n = d.activeNode()
r = n.bounds()
s = Selection()
s.select(r.width() / 3, r.height() / 3, r.width() / 3, r.height() / 3, 255)
s.cut(n)

Definition at line 30 of file Selection.h.

Constructor & Destructor Documentation

◆ Selection() [1/2]

Selection::Selection ( KisSelectionSP selection,
QObject * parent = 0 )

For internal use only.

Definition at line 26 of file Selection.cpp.

27 : QObject(parent)
28 , d(new Private)
29{
31}
KisSelectionSP selection() const
Private *const d
Definition Selection.h:241
KisSelectionSP selection
Definition Selection.cpp:23

References d, krita::Selection::Private::selection, and selection().

◆ Selection() [2/2]

Selection::Selection ( QObject * parent = 0)
explicit

Create a new, empty selection object.

Definition at line 34 of file Selection.cpp.

35 : QObject(parent)
36 , d(new Private)
37{
38 d->selection = new KisSelection();
39}

References d, and krita::Selection::Private::selection.

◆ ~Selection()

Selection::~Selection ( )
override

Definition at line 41 of file Selection.cpp.

42{
43 delete d;
44}

References d.

Member Function Documentation

◆ add

void Selection::add ( Selection * selection)
slot

Add the given selection's selected pixels to the current selection.

Definition at line 273 of file Selection.cpp.

274{
275 if (!d->selection) return;
277}
@ SELECTION_ADD
void applySelection(KisPixelSelectionSP selection, SelectionAction action)
KisPixelSelectionSP pixelSelection

References KisPixelSelection::applySelection(), d, KisSelection::pixelSelection, krita::Selection::Private::selection, selection(), and SELECTION_ADD.

◆ border

void Selection::border ( int xRadius,
int yRadius )
slot

Border the selection with the given radius.

Definition at line 199 of file Selection.cpp.

200{
201 if (!d->selection) return;
202 KisBorderSelectionFilter sf(xRadius, yRadius, true);
203 QRect rc = sf.changeRect(d->selection->selectedExactRect(), d->selection->pixelSelection()->defaultBounds());
204 sf.process(d->selection->pixelSelection(), rc);
205}
KisDefaultBoundsBaseSP defaultBounds() const
QRect selectedExactRect() const
Slow, but exact way of determining the rectangle that encloses the selection.

References KisBorderSelectionFilter::changeRect(), d, KisPaintDevice::defaultBounds(), KisSelection::pixelSelection, KisBorderSelectionFilter::process(), KisSelection::selectedExactRect(), and krita::Selection::Private::selection.

◆ clear

void Selection::clear ( )
slot

Make the selection entirely unselected.

Definition at line 101 of file Selection.cpp.

102{
103 if (!d->selection) return;
104 d->selection->clear();
105}

References KisSelection::clear(), d, and krita::Selection::Private::selection.

◆ contract

void Selection::contract ( int value)
slot

Make the selection's width and height smaller by the given value. This will not move the selection's top-left position.

Definition at line 107 of file Selection.cpp.

108{
109 if (!d->selection) return;
110 d->selection->pixelSelection()->select(QRect(x(), y(), width() - value, height() - value));
111}
float value(const T *src, size_t ch)
int y() const
Definition Selection.cpp:84
int width() const
Definition Selection.cpp:62
int x() const
Definition Selection.cpp:74
int height() const
Definition Selection.cpp:68
void select(const QRect &r, quint8 selectedness=MAX_SELECTED)

References d, height(), KisSelection::pixelSelection, KisPixelSelection::select(), krita::Selection::Private::selection, value(), width(), x(), and y().

◆ copy

void Selection::copy ( Node * node)
slot

copy copies the area defined by the selection from the node to the clipboard.

Parameters
nodethe node from where the pixels will be copied.

Definition at line 113 of file Selection.cpp.

114{
115 if (!node) return;
116 if (!d->selection) return;
117 if (node->node()->exactBounds().isEmpty()) return;
118 if (!node->node()->hasEditablePaintDevice()) return;
119
120 KisPaintDeviceSP dev = node->node()->paintDevice();
121 KisPaintDeviceSP clip = new KisPaintDevice(dev->colorSpace());
122 KisPaintDeviceSP selectionProjection = d->selection->projection();
123
124 const KoColorSpace *cs = clip->colorSpace();
125 const KoColorSpace *selCs = d->selection->projection()->colorSpace();
126
127 QRect rc = d->selection->selectedExactRect();
128
129 KisPainter::copyAreaOptimized(QPoint(), dev, clip, rc);
130
131 KisHLineIteratorSP layerIt = clip->createHLineIteratorNG(0, 0, rc.width());
132 KisHLineConstIteratorSP selectionIt = selectionProjection->createHLineIteratorNG(rc.x(), rc.y(), rc.width());
133
134 for (qint32 y = 0; y < rc.height(); y++) {
135 for (qint32 x = 0; x < rc.width(); x++) {
136
137 qreal dstAlpha = cs->opacityF(layerIt->rawData());
138 qreal sel = selCs->opacityF(selectionIt->oldRawData());
139 qreal newAlpha = sel * dstAlpha / (1.0 - dstAlpha + sel * dstAlpha);
140 float mask = newAlpha / dstAlpha;
141
142 cs->applyAlphaNormedFloatMask(layerIt->rawData(), &mask, 1);
143
144 layerIt->nextPixel();
145 selectionIt->nextPixel();
146 }
147 layerIt->nextRow();
148 selectionIt->nextRow();
149 }
150
151 KisClipboard::instance()->setClip(clip, rc.topLeft());
152}
virtual const quint8 * oldRawData() const =0
virtual bool nextPixel()=0
static KisClipboard * instance()
void setClip(KisPaintDeviceSP dev, const QPoint &topLeft)
virtual void nextRow()=0
KisHLineIteratorSP createHLineIteratorNG(qint32 x, qint32 y, qint32 w)
const KoColorSpace * colorSpace() const
static void copyAreaOptimized(const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect)
virtual qreal opacityF(const quint8 *pixel) const =0
virtual void applyAlphaNormedFloatMask(quint8 *pixels, const float *alpha, qint32 nPixels) const =0
KisNodeSP node() const
Definition Node.cpp:827
virtual QRect exactBounds() const
virtual KisPaintDeviceSP paintDevice() const =0
bool hasEditablePaintDevice() const
KisPixelSelectionSP projection() const

References KoColorSpace::applyAlphaNormedFloatMask(), KisPaintDevice::colorSpace(), KisPainter::copyAreaOptimized(), KisPaintDevice::createHLineIteratorNG(), d, KisBaseNode::exactBounds(), KisBaseNode::hasEditablePaintDevice(), KisClipboard::instance(), KisBaseConstIteratorNG::nextPixel(), KisHLineConstIteratorNG::nextRow(), Node::node(), KisBaseConstAccessor::oldRawData(), KoColorSpace::opacityF(), KisBaseNode::paintDevice(), KisSelection::projection(), KisSelection::selectedExactRect(), krita::Selection::Private::selection, KisClipboard::setClip(), x(), and y().

◆ cut

void Selection::cut ( Node * node)
slot

cut erases the area defined by the selection from the node and puts a copy on the clipboard.

Parameters
nodethe node from which the selection will be cut.

Definition at line 154 of file Selection.cpp.

155{
156 if (!node) return;
157 if (!d->selection) return;
158 if (node->node()->exactBounds().isEmpty()) return;
159 if (!node->node()->hasEditablePaintDevice()) return;
160 KisPaintDeviceSP dev = node->node()->paintDevice();
161 copy(node);
164}
void clearSelection(KisSelectionSP selection)
void copy(Node *node)
copy copies the area defined by the selection from the node to the clipboard.
virtual void setDirty()
Definition kis_node.cpp:577

References KisPaintDevice::clearSelection(), copy(), d, KisBaseNode::exactBounds(), KisBaseNode::hasEditablePaintDevice(), Node::node(), KisBaseNode::paintDevice(), KisSelection::selectedExactRect(), krita::Selection::Private::selection, and KisNode::setDirty().

◆ dilate

void Selection::dilate ( )
slot

Dilate the selection with a radius of 1 pixel.

Definition at line 191 of file Selection.cpp.

192{
193 if (!d->selection) return;
196 dsf.process(d->selection->pixelSelection(), rc);
197}
QRect changeRect(const QRect &rect, KisDefaultBoundsBaseSP defaultBounds) override
void process(KisPixelSelectionSP pixelSelection, const QRect &rect) override

References KisDilateSelectionFilter::changeRect(), d, KisPaintDevice::defaultBounds(), KisSelection::pixelSelection, KisDilateSelectionFilter::process(), KisSelection::selectedExactRect(), and krita::Selection::Private::selection.

◆ duplicate

Selection * Selection::duplicate ( ) const
slot
Returns
a duplicate of the selection

Definition at line 56 of file Selection.cpp.

57{
58 return new Selection(d->selection ? new KisSelection(*d->selection)
59 : new KisSelection());
60}
Selection(KisSelectionSP selection, QObject *parent=0)
Definition Selection.cpp:26

References d, krita::Selection::Private::selection, and Selection().

◆ erode

void Selection::erode ( )
slot

Erode the selection with a radius of 1 pixel.

Definition at line 183 of file Selection.cpp.

184{
185 if (!d->selection) return;
188 esf.process(d->selection->pixelSelection(), rc);
189}
void process(KisPixelSelectionSP pixelSelection, const QRect &rect) override
QRect changeRect(const QRect &rect, KisDefaultBoundsBaseSP defaultBounds) override

References KisErodeSelectionFilter::changeRect(), d, KisPaintDevice::defaultBounds(), KisSelection::pixelSelection, KisErodeSelectionFilter::process(), KisSelection::selectedExactRect(), and krita::Selection::Private::selection.

◆ feather

void Selection::feather ( int radius)
slot

◆ grow

void Selection::grow ( int xradius,
int yradius )
slot

◆ height

int Selection::height ( ) const
slot
Returns
the height of the selection

Definition at line 68 of file Selection.cpp.

69{
70 if (!d->selection) return 0;
71 return d->selection->selectedExactRect().height();
72}

References d, KisSelection::selectedExactRect(), and krita::Selection::Private::selection.

◆ intersect

void Selection::intersect ( Selection * selection)
slot

Intersect the given selection with this selection.

Definition at line 285 of file Selection.cpp.

286{
287 if (!d->selection) return;
289}
@ SELECTION_INTERSECT

References KisPixelSelection::applySelection(), d, KisSelection::pixelSelection, krita::Selection::Private::selection, selection(), and SELECTION_INTERSECT.

◆ invert

void Selection::invert ( )
slot

Invert the selection.

Definition at line 241 of file Selection.cpp.

242{
243 if (!d->selection) return;
246 sf.process(d->selection->pixelSelection(), rc);
247}
QRect changeRect(const QRect &rect, KisDefaultBoundsBaseSP defaultBounds) override
void process(KisPixelSelectionSP pixelSelection, const QRect &rect) override

References KisInvertSelectionFilter::changeRect(), d, KisPaintDevice::defaultBounds(), KisSelection::pixelSelection, KisInvertSelectionFilter::process(), KisSelection::selectedExactRect(), and krita::Selection::Private::selection.

◆ move

void Selection::move ( int x,
int y )
slot

Move the selection's top-left corner to the given coordinates.

Definition at line 94 of file Selection.cpp.

95{
96 if (!d->selection) return;
97 d->selection->pixelSelection()->moveTo(QPoint(x, y));
98}
void moveTo(const QPoint &pt) override

References d, KisPixelSelection::moveTo(), KisSelection::pixelSelection, krita::Selection::Private::selection, x(), and y().

◆ operator!=()

bool Selection::operator!= ( const Selection & other) const

Definition at line 51 of file Selection.cpp.

52{
53 return !(operator==(other));
54}
bool operator==(const Selection &other) const
Definition Selection.cpp:46

References operator==().

◆ operator==()

bool Selection::operator== ( const Selection & other) const

Definition at line 46 of file Selection.cpp.

47{
48 return (d->selection == other.d->selection);
49}

References d, and krita::Selection::Private::selection.

◆ paste

void Selection::paste ( Node * destination,
int x,
int y )
slot

paste pastes the content of the clipboard to the given node, limited by the area of the current selection.

Parameters
destinationthe node where the pixels will be written
xthe x position at which the clip will be written
ythe y position at which the clip will be written

Definition at line 166 of file Selection.cpp.

167{
168 if (!destination) return;
169 if (!d->selection) return;
170 if (!KisClipboard::instance()->hasClip()) return;
171
172 KisPaintDeviceSP src = KisClipboard::instance()->clip(QRect(), false);
173 KisPaintDeviceSP dst = destination->node()->paintDevice();
174 if (!dst || !src) return;
176 src,
177 dst,
178 src->exactBounds(),
179 d->selection);
180 destination->node()->setDirty();
181}

References KisClipboard::clip, KisPainter::copyAreaOptimized(), d, KisClipboard::instance(), Node::node(), KisBaseNode::paintDevice(), krita::Selection::Private::selection, KisNode::setDirty(), x(), and y().

◆ pixelData

QByteArray Selection::pixelData ( int x,
int y,
int w,
int h ) const
slot

pixelData reads the given rectangle from the Selection's mask and returns it as a byte array. The pixel data starts top-left, and is ordered row-first.

The byte array will contain one byte for every pixel, representing the selectedness. 0 is totally unselected, 255 is fully selected.

You can read outside the Selection's boundaries; those pixels will be unselected.

The byte array is a copy of the original selection data.

Parameters
xx position from where to start reading
yy position from where to start reading
wrow length to read
hnumber of rows to read
Returns
a QByteArray with the pixel data. The byte array may be empty.

Definition at line 298 of file Selection.cpp.

299{
300 QByteArray ba;
301 if (!d->selection) return ba;
303 quint8 *data = new quint8[w * h];
304 dev->readBytes(data, x, y, w, h);
305 ba = QByteArray((const char*)data, (int)(w * h));
306 delete[] data;
307 return ba;
308}
void readBytes(quint8 *data, qint32 x, qint32 y, qint32 w, qint32 h) const

References d, KisSelection::projection(), KisPaintDevice::readBytes(), krita::Selection::Private::selection, x(), and y().

◆ replace

void Selection::replace ( Selection * selection)
slot

Replace the current selection's selection with the one of the given selection.

Definition at line 267 of file Selection.cpp.

268{
269 if (!d->selection) return;
271}
@ SELECTION_REPLACE

References KisPixelSelection::applySelection(), d, KisSelection::pixelSelection, krita::Selection::Private::selection, selection(), and SELECTION_REPLACE.

◆ resize

void Selection::resize ( int w,
int h )
slot

Resize the selection to the given width and height. The top-left position will not be moved.

Definition at line 249 of file Selection.cpp.

250{
251 if (!d->selection) return;
252 d->selection->pixelSelection()->select(QRect(x(), y(), w, h));
253}

References d, KisSelection::pixelSelection, KisPixelSelection::select(), krita::Selection::Private::selection, x(), and y().

◆ select

void Selection::select ( int x,
int y,
int w,
int h,
int value )
slot

Select the given area. The value can be between 0 and 255; 0 is totally unselected, 255 is totally selected.

Definition at line 255 of file Selection.cpp.

256{
257 if (!d->selection) return;
258 d->selection->pixelSelection()->select(QRect(x, y, w, h), value);
259}

References d, KisSelection::pixelSelection, KisPixelSelection::select(), krita::Selection::Private::selection, value(), x(), and y().

◆ selectAll

void Selection::selectAll ( Node * node,
int value )
slot

Select all pixels in the given node. The value can be between 0 and 255; 0 is totally unselected, 255 is totally selected.

Definition at line 261 of file Selection.cpp.

262{
263 if (!d->selection) return;
265}

References d, KisBaseNode::exactBounds(), Node::node(), KisSelection::pixelSelection, KisPixelSelection::select(), krita::Selection::Private::selection, and value().

◆ selection()

KisSelectionSP Selection::selection ( ) const
private

Definition at line 318 of file Selection.cpp.

319{
320 return d->selection;
321}

References d, and krita::Selection::Private::selection.

◆ setPixelData

void Selection::setPixelData ( QByteArray value,
int x,
int y,
int w,
int h )
slot

setPixelData writes the given bytes, of which there must be enough, into the Selection.

Parameters
valuethe byte array representing the pixels. There must be enough bytes available. Krita will take the raw pointer from the QByteArray and start reading, not stopping before (w * h) bytes are read.
xthe x position to start writing from
ythe y position to start writing from
wthe width of each row
hthe number of rows to write

Definition at line 310 of file Selection.cpp.

311{
312 if (!d->selection) return;
314 if (!dev) return;
315 dev->writeBytes((const quint8*)value.constData(), x, y, w, h);
316}
void writeBytes(const quint8 *data, qint32 x, qint32 y, qint32 w, qint32 h)

References d, KisSelection::pixelSelection, krita::Selection::Private::selection, value(), KisPaintDevice::writeBytes(), x(), and y().

◆ shrink

void Selection::shrink ( int xRadius,
int yRadius,
bool edgeLock )
slot

Shrink the selection with the given radius.

Definition at line 224 of file Selection.cpp.

225{
226 if (!d->selection) return;
227 KisShrinkSelectionFilter sf(xRadius, yRadius, edgeLock);
228 QRect rc = sf.changeRect(d->selection->selectedExactRect(), d->selection->pixelSelection()->defaultBounds());
229 sf.process(d->selection->pixelSelection(), rc);
230}

References KisShrinkSelectionFilter::changeRect(), d, KisPaintDevice::defaultBounds(), KisSelection::pixelSelection, KisShrinkSelectionFilter::process(), KisSelection::selectedExactRect(), and krita::Selection::Private::selection.

◆ smooth

void Selection::smooth ( )
slot

Smooth the selection.

Definition at line 232 of file Selection.cpp.

233{
234 if (!d->selection) return;
237 sf.process(d->selection->pixelSelection(), rc);
238}
QRect changeRect(const QRect &rect, KisDefaultBoundsBaseSP defaultBounds) override
void process(KisPixelSelectionSP pixelSelection, const QRect &rect) override

References KisSmoothSelectionFilter::changeRect(), d, KisPaintDevice::defaultBounds(), KisSelection::pixelSelection, KisSmoothSelectionFilter::process(), KisSelection::selectedExactRect(), and krita::Selection::Private::selection.

◆ subtract

void Selection::subtract ( Selection * selection)
slot

Subtract the given selection's selected pixels from the current selection.

Definition at line 279 of file Selection.cpp.

280{
281 if (!d->selection) return;
283}
@ SELECTION_SUBTRACT

References KisPixelSelection::applySelection(), d, KisSelection::pixelSelection, krita::Selection::Private::selection, selection(), and SELECTION_SUBTRACT.

◆ symmetricdifference

void Selection::symmetricdifference ( Selection * selection)
slot

Intersect with the inverse of the given selection with this selection.

Definition at line 291 of file Selection.cpp.

292{
293 if (!d->selection) return;
295}
@ SELECTION_SYMMETRICDIFFERENCE

References KisPixelSelection::applySelection(), d, KisSelection::pixelSelection, krita::Selection::Private::selection, selection(), and SELECTION_SYMMETRICDIFFERENCE.

◆ width

int Selection::width ( ) const
slot
Returns
the width of the selection

Definition at line 62 of file Selection.cpp.

63{
64 if (!d->selection) return 0;
65 return d->selection->selectedExactRect().width();
66}

References d, KisSelection::selectedExactRect(), and krita::Selection::Private::selection.

◆ x

int Selection::x ( ) const
slot
Returns
the left-hand position of the selection.

Definition at line 74 of file Selection.cpp.

75{
76 if (!d->selection) return 0;
77 int xPos = d->selection->x();
79 xPos = d->selection->selectedExactRect().x();
80 }
81 return xPos;
82}
qint32 x() const
bool hasNonEmptyPixelSelection() const

References d, KisSelection::hasNonEmptyPixelSelection(), KisSelection::selectedExactRect(), krita::Selection::Private::selection, and KisSelection::x().

◆ y

int Selection::y ( ) const
slot
Returns
the top position of the selection.

Definition at line 84 of file Selection.cpp.

85{
86 if (!d->selection) return 0;
87 int yPos = d->selection->y();
89 yPos = d->selection->selectedExactRect().y();
90 }
91 return yPos;
92}
qint32 y() const

References d, KisSelection::hasNonEmptyPixelSelection(), KisSelection::selectedExactRect(), krita::Selection::Private::selection, and KisSelection::y().

Friends And Related Symbol Documentation

◆ Document

friend class Document
friend

Definition at line 231 of file Selection.h.

◆ FillLayer

friend class FillLayer
friend

Definition at line 233 of file Selection.h.

◆ FilterLayer

friend class FilterLayer
friend

Definition at line 232 of file Selection.h.

◆ FilterMask

friend class FilterMask
friend

Definition at line 236 of file Selection.h.

◆ SelectionMask

friend class SelectionMask
friend

Definition at line 234 of file Selection.h.

◆ TransparencyMask

friend class TransparencyMask
friend

Definition at line 235 of file Selection.h.

Member Data Documentation

◆ d

Private* const Selection::d
private

Definition at line 241 of file Selection.h.


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