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

#include <kis_selection_filters.h>

+ Inheritance diagram for KisInvertSelectionFilter:

Public Member Functions

QRect changeRect (const QRect &rect, KisDefaultBoundsBaseSP defaultBounds) override
 
KUndo2MagicString name () override
 
void process (KisPixelSelectionSP pixelSelection, const QRect &rect) override
 
- Public Member Functions inherited from KisSelectionFilter
virtual ~KisSelectionFilter ()
 

Additional Inherited Members

- Protected Member Functions inherited from KisSelectionFilter
void computeBorder (qint32 *circ, qint32 xradius, qint32 yradius)
 
void computeTransition (quint8 *transition, quint8 **buf, qint32 width)
 
void rotatePointers (quint8 **p, quint32 n)
 

Detailed Description

Definition at line 134 of file kis_selection_filters.h.

Member Function Documentation

◆ changeRect()

QRect KisInvertSelectionFilter::changeRect ( const QRect & rect,
KisDefaultBoundsBaseSP defaultBounds )
overridevirtual

Reimplemented from KisSelectionFilter.

Definition at line 888 of file kis_selection_filters.cpp.

889{
890 Q_UNUSED(rect);
891 return defaultBounds->bounds();
892}
virtual QRect bounds() const =0

References KisDefaultBoundsBase::bounds().

◆ name()

KUndo2MagicString KisInvertSelectionFilter::name ( )
overridevirtual

Reimplemented from KisSelectionFilter.

Definition at line 883 of file kis_selection_filters.cpp.

884{
885 return kundo2_i18n("Invert Selection");
886}
KUndo2MagicString kundo2_i18n(const char *text)

References kundo2_i18n().

◆ process()

void KisInvertSelectionFilter::process ( KisPixelSelectionSP pixelSelection,
const QRect & rect )
overridevirtual

The default bounds of a selection may also include the extent of the parent device, which is not what we want here. Hence we should request imageBorderRect() directly.

A special treatment for the user-visible selection inversion:

If the selection is fully contained inside the image, then just invert it pixel-by-pixel without changing the default pixel. It makes it selectedExactRect() work a little bit more expected for the user (see bug 457820).

If the selection spreads outside the image bounds, then just invert it in a mathematical way adjusting the default pixel.

Implements KisSelectionFilter.

Definition at line 894 of file kis_selection_filters.cpp.

895{
896 Q_UNUSED(rect);
897
903 const QRect imageRect = pixelSelection->defaultBounds()->imageBorderRect();
904 const QRect selectionRect = pixelSelection->selectedExactRect();
905
919 if (!imageRect.contains(selectionRect)) {
920 pixelSelection->invert();
921 } else {
922 KisSequentialIterator it(pixelSelection, imageRect);
923 while(it.nextPixel()) {
924 *(it.rawData()) = MAX_SELECTED - *(it.rawData());
925 }
926 pixelSelection->crop(imageRect);
927 pixelSelection->invalidateOutlineCache();
928 }
929}
virtual QRect imageBorderRect() const
void crop(qint32 x, qint32 y, qint32 w, qint32 h)
KisDefaultBoundsBaseSP defaultBounds() const
const quint8 MAX_SELECTED
Definition kis_global.h:32
QRect selectedExactRect() const

References KisPaintDevice::crop(), KisPaintDevice::defaultBounds(), KisDefaultBoundsBase::imageBorderRect(), KisPixelSelection::invalidateOutlineCache(), KisPixelSelection::invert(), MAX_SELECTED, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), and KisPixelSelection::selectedExactRect().


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