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 ()
 
Selection * duplicate () 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 28 of file Selection.cpp.

29 : QObject(parent)
30 , d(new Private)
31{
33}
KisSelectionSP selection() const
Private *const d
Definition Selection.h:241
KisSelectionSP selection
Definition Selection.cpp:25

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 36 of file Selection.cpp.

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

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

◆ ~Selection()

Selection::~Selection ( )
override

Definition at line 43 of file Selection.cpp.

44{
45 delete d;
46}

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 255 of file Selection.cpp.

256{
257 if (!d->selection) return;
259}
@ 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 181 of file Selection.cpp.

182{
183 if (!d->selection) return;
184 KisBorderSelectionFilter sf(xRadius, yRadius, true);
185 QRect rc = sf.changeRect(d->selection->selectedExactRect(), d->selection->pixelSelection()->defaultBounds());
186 sf.process(d->selection->pixelSelection(), rc);
187}
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 103 of file Selection.cpp.

104{
105 if (!d->selection) return;
106 d->selection->clear();
107}

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 109 of file Selection.cpp.

110{
111 if (!d->selection) return;
112 d->selection->pixelSelection()->select(QRect(x(), y(), width() - value, height() - value));
113}
float value(const T *src, size_t ch)
int y() const
Definition Selection.cpp:86
int width() const
Definition Selection.cpp:64
int x() const
Definition Selection.cpp:76
int height() const
Definition Selection.cpp:70
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 115 of file Selection.cpp.

116{
117 if (!node) return;
118 if (!d->selection) return;
119 if (node->node()->exactBounds().isEmpty()) return;
120 if (!node->node()->hasEditablePaintDevice()) return;
121
122 KisImageSP image = node->node()->image();
123 if (!image) return;
124
125 KisPaintDeviceSP dev(new KisPaintDevice(*node->node()->paintDevice()));
127
128 KisNodeSP newNode = new KisPaintLayer(image, "selection", OPACITY_OPAQUE_U8, dev);
129 KisNodeList nodes{newNode};
130
131 KisImageSP tempImage = KisToolUtils::buildImageForClipboard(image, nodes);
133}
const quint8 OPACITY_OPAQUE_U8
static KisClipboard * instance()
void setLayers(KisNodeList nodes, KisImageSP image, const QRect referenceRect, bool forceCopy=false)
KisNodeSP node() const
Definition Node.cpp:828
KisImageSP buildImageForClipboard(KisImageSP srcImage, KisNodeList nodes)
void trimDeviceForClipboard(KisImageSP image, KisPaintDeviceSP device, KisSelectionSP selection, bool makeSharpClip)
virtual QRect exactBounds() const
KisImageWSP image
virtual KisPaintDeviceSP paintDevice() const =0
bool hasEditablePaintDevice() const

References KisToolUtils::buildImageForClipboard(), d, KisBaseNode::exactBounds(), KisBaseNode::hasEditablePaintDevice(), KisBaseNode::image, KisClipboard::instance(), Node::node(), OPACITY_OPAQUE_U8, KisBaseNode::paintDevice(), KisSelection::selectedExactRect(), krita::Selection::Private::selection, KisClipboard::setLayers(), and KisToolUtils::trimDeviceForClipboard().

◆ 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 135 of file Selection.cpp.

136{
137 if (!node) return;
138 if (!d->selection) return;
139 if (node->node()->exactBounds().isEmpty()) return;
140 if (!node->node()->hasEditablePaintDevice()) return;
141 KisPaintDeviceSP dev = node->node()->paintDevice();
142 copy(node);
145}
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 173 of file Selection.cpp.

174{
175 if (!d->selection) return;
178 dsf.process(d->selection->pixelSelection(), rc);
179}
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 58 of file Selection.cpp.

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

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 165 of file Selection.cpp.

166{
167 if (!d->selection) return;
170 esf.process(d->selection->pixelSelection(), rc);
171}
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 70 of file Selection.cpp.

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

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 267 of file Selection.cpp.

268{
269 if (!d->selection) return;
271}
@ 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 223 of file Selection.cpp.

224{
225 if (!d->selection) return;
228 sf.process(d->selection->pixelSelection(), rc);
229}
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 96 of file Selection.cpp.

97{
98 if (!d->selection) return;
99 d->selection->pixelSelection()->moveTo(QPoint(x, y));
100}
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 53 of file Selection.cpp.

54{
55 return !(operator==(other));
56}
bool operator==(const Selection &other) const
Definition Selection.cpp:48

References operator==().

◆ operator==()

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

Definition at line 48 of file Selection.cpp.

49{
50 return (d->selection == other.d->selection);
51}

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 147 of file Selection.cpp.

148{
149 if (!destination) return;
150 if (!d->selection) return;
151 if (!KisClipboard::instance()->hasClip()) return;
152
153 KisDefaultBoundsBaseSP defaultBounds = destination->node()->paintDevice()->defaultBounds();
154 KisPaintDeviceSP src = KisClipboard::instance()->clip(defaultBounds, false);
155 KisPaintDeviceSP dst = destination->node()->paintDevice();
156 if (!dst || !src) return;
158 src,
159 dst,
160 src->exactBounds(),
161 d->selection);
162 destination->node()->setDirty();
163}
static void copyAreaOptimized(const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect)

References KisClipboard::clip, KisPainter::copyAreaOptimized(), d, KisPaintDevice::defaultBounds(), 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 280 of file Selection.cpp.

281{
282 QByteArray ba;
283 if (!d->selection) return ba;
285 quint8 *data = new quint8[w * h];
286 dev->readBytes(data, x, y, w, h);
287 ba = QByteArray((const char*)data, (int)(w * h));
288 delete[] data;
289 return ba;
290}
void readBytes(quint8 *data, qint32 x, qint32 y, qint32 w, qint32 h) const
KisPixelSelectionSP projection() 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 249 of file Selection.cpp.

250{
251 if (!d->selection) return;
253}
@ 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 231 of file Selection.cpp.

232{
233 if (!d->selection) return;
234 d->selection->pixelSelection()->select(QRect(x(), y(), w, h));
235}

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 237 of file Selection.cpp.

238{
239 if (!d->selection) return;
240 d->selection->pixelSelection()->select(QRect(x, y, w, h), value);
241}

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 243 of file Selection.cpp.

244{
245 if (!d->selection) return;
247}

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 300 of file Selection.cpp.

301{
302 return d->selection;
303}

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 292 of file Selection.cpp.

293{
294 if (!d->selection) return;
296 if (!dev) return;
297 dev->writeBytes((const quint8*)value.constData(), x, y, w, h);
298}
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 206 of file Selection.cpp.

207{
208 if (!d->selection) return;
209 KisShrinkSelectionFilter sf(xRadius, yRadius, edgeLock);
210 QRect rc = sf.changeRect(d->selection->selectedExactRect(), d->selection->pixelSelection()->defaultBounds());
211 sf.process(d->selection->pixelSelection(), rc);
212}

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 214 of file Selection.cpp.

215{
216 if (!d->selection) return;
219 sf.process(d->selection->pixelSelection(), rc);
220}
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 261 of file Selection.cpp.

262{
263 if (!d->selection) return;
265}
@ 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 273 of file Selection.cpp.

274{
275 if (!d->selection) return;
277}
@ 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 64 of file Selection.cpp.

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

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 76 of file Selection.cpp.

77{
78 if (!d->selection) return 0;
79 int xPos = d->selection->x();
81 xPos = d->selection->selectedExactRect().x();
82 }
83 return xPos;
84}
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 86 of file Selection.cpp.

87{
88 if (!d->selection) return 0;
89 int yPos = d->selection->y();
91 yPos = d->selection->selectedExactRect().y();
92 }
93 return yPos;
94}
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: