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

#include <KisSelectionBasedProcessingHelper.h>

Public Types

using Functor = std::function<void(KisPaintDeviceSP)>
 

Public Member Functions

KUndo2CommandcreateInitCommand ()
 
KUndo2CommandcreateInitCommand (Functor func)
 
 KisSelectionBasedProcessingHelper (KisSelectionSP selection, Functor func)
 
void setSelection (KisSelectionSP selection)
 
void transformPaintDevice (KisPaintDeviceSP device, KisUndoAdapter *undoAdapter)
 
void transformPaintDevice (KisPaintDeviceSP device, KisUndoAdapter *undoAdapter, Functor func)
 

Private Attributes

KisSelectionSP m_cutSelection
 
Functor m_func
 
KisSelectionSP m_selection
 

Detailed Description

Definition at line 16 of file KisSelectionBasedProcessingHelper.h.

Member Typedef Documentation

◆ Functor

Constructor & Destructor Documentation

◆ KisSelectionBasedProcessingHelper()

KisSelectionBasedProcessingHelper::KisSelectionBasedProcessingHelper ( KisSelectionSP selection,
Functor func )

Member Function Documentation

◆ createInitCommand() [1/2]

KUndo2Command * KisSelectionBasedProcessingHelper::createInitCommand ( )

◆ createInitCommand() [2/2]

KUndo2Command * KisSelectionBasedProcessingHelper::createInitCommand ( Functor func)

Definition at line 25 of file KisSelectionBasedProcessingHelper.cpp.

26{
27 if (!m_selection) return 0;
28
29 struct ProcessSelectionCommand : KisTransactionBasedCommand {
30 ProcessSelectionCommand(KisSelectionSP selection,
31 KisSelectionSP cutSelection,
32 std::function<void(KisPaintDeviceSP)> func)
33 : m_selection(selection),
34 m_cutSelection(cutSelection),
35 m_func(func)
36 {
37 }
38
39 KUndo2Command* paint() override {
40 m_cutSelection->pixelSelection()->makeCloneFromRough(m_selection->pixelSelection(), m_selection->selectedRect());
41
42 KisTransaction t(m_selection->pixelSelection());
43 m_func(m_selection->pixelSelection());
44
45 return t.endAndTake();
46 }
47
48 KisSelectionSP m_selection;
49 KisSelectionSP m_cutSelection;
50 Functor m_func;
51 };
52
54 return new ProcessSelectionCommand(m_selection, m_cutSelection, func);
55}

References KisTransaction::endAndTake(), m_cutSelection, and m_selection.

◆ setSelection()

void KisSelectionBasedProcessingHelper::setSelection ( KisSelectionSP selection)

Definition at line 20 of file KisSelectionBasedProcessingHelper.cpp.

21{
22 m_selection = selection;
23}

References m_selection.

◆ transformPaintDevice() [1/2]

void KisSelectionBasedProcessingHelper::transformPaintDevice ( KisPaintDeviceSP device,
KisUndoAdapter * undoAdapter )

Definition at line 62 of file KisSelectionBasedProcessingHelper.cpp.

63{
64 transformPaintDevice(device, undoAdapter, m_func);
65}
void transformPaintDevice(KisPaintDeviceSP device, KisUndoAdapter *undoAdapter)

References m_func, and transformPaintDevice().

◆ transformPaintDevice() [2/2]

void KisSelectionBasedProcessingHelper::transformPaintDevice ( KisPaintDeviceSP device,
KisUndoAdapter * undoAdapter,
Functor func )

Definition at line 67 of file KisSelectionBasedProcessingHelper.cpp.

68{
70
72 // we have already processed the selection in the init command so try to skip it
73 if (device != static_cast<KisPaintDevice*>(m_selection->pixelSelection().data())) {
74 KisTransaction transaction(device);
75
76 const QRect cutBounds = m_cutSelection->selectedExactRect();
77 const QRect pasteBounds = m_selection->selectedExactRect();
78
79
80 KisPaintDeviceSP tempDev = new KisPaintDevice(device->colorSpace());
81 tempDev->makeCloneFromRough(device, cutBounds);
82
83 func(tempDev);
84
86 KisPainter::copyAreaOptimized(pasteBounds.topLeft(), tempDev, device, pasteBounds, m_selection);
87 transaction.commit(undoAdapter);
88 }
89 } else {
90 KisTransaction transaction(device);
91 func(device);
92 transaction.commit(undoAdapter);
93 }
94}
void makeCloneFromRough(KisPaintDeviceSP src, const QRect &minimalRect)
const KoColorSpace * colorSpace() const
void clearSelection(KisSelectionSP selection)
static void copyAreaOptimized(const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
KisPixelSelectionSP pixelSelection
QRect selectedExactRect() const
Slow, but exact way of determining the rectangle that encloses the selection.

References KisPaintDevice::clearSelection(), KisPaintDevice::colorSpace(), KisTransaction::commit(), KisPainter::copyAreaOptimized(), KisSharedPtr< T >::data(), KIS_SAFE_ASSERT_RECOVER_RETURN, m_cutSelection, m_selection, KisPaintDevice::makeCloneFromRough(), KisSelection::pixelSelection, and KisSelection::selectedExactRect().

Member Data Documentation

◆ m_cutSelection

KisSelectionSP KisSelectionBasedProcessingHelper::m_cutSelection
private

Definition at line 36 of file KisSelectionBasedProcessingHelper.h.

◆ m_func

Functor KisSelectionBasedProcessingHelper::m_func
private

Definition at line 37 of file KisSelectionBasedProcessingHelper.h.

◆ m_selection

KisSelectionSP KisSelectionBasedProcessingHelper::m_selection
private

Definition at line 35 of file KisSelectionBasedProcessingHelper.h.


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