Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPasteActionFactory Struct Reference

#include <KisPasteActionFactories.h>

+ Inheritance diagram for KisPasteActionFactory:

Public Types

enum  Flag { None = 0x0 , PasteAtCursor = 0x1 , ForceNewLayer = 0x2 }
 

Public Member Functions

 KisPasteActionFactory ()
 
void run (Flags flags, KisViewManager *view)
 
void runFromXML (KisViewManager *view, const KisOperationConfiguration &config) override
 
- Public Member Functions inherited from KisOperation
QString id () const
 
 KisOperation (const QString &id)
 
virtual ~KisOperation ()
 

Additional Inherited Members

- Protected Member Functions inherited from KisOperation
KisProcessingApplicatorbeginAction (KisViewManager *view, const KUndo2MagicString &actionName)
 
void endAction (KisProcessingApplicator *applicator, const QString &xmlData)
 

Detailed Description

Definition at line 14 of file KisPasteActionFactories.h.

Member Enumeration Documentation

◆ Flag

Enumerator
None 
PasteAtCursor 
ForceNewLayer 

Definition at line 15 of file KisPasteActionFactories.h.

Constructor & Destructor Documentation

◆ KisPasteActionFactory()

KisPasteActionFactory::KisPasteActionFactory ( )
inline

Definition at line 22 of file KisPasteActionFactories.h.

22: KisOperation("paste-ui-action") {}
KisOperation(const QString &id)

Member Function Documentation

◆ run()

void KisPasteActionFactory::run ( Flags flags,
KisViewManager * view )

TODO: we are relying on a sticky translated string from KisImageLayerAddCommand change the string after Krita 5.2.5

Definition at line 209 of file KisPasteActionFactories.cpp.

210{
211 bool pasteAtCursorPosition = flags.testFlag(PasteAtCursor);
212
213 KisImageSP image = view->image();
214 if (!image) return;
215
216 const QPointF docPos = view->canvasBase()->canvasController()->currentCursorPosition();
217
218 // Activate the current tool's paste functionality
219 if (view->canvasBase()->toolProxy()->paste()) {
220 // XXX: "Add saving of XML data for Paste of shapes"
221 return;
222 }
223
224 // Paste shapes
225 if (tryPasteShapes(flags, view)) {
226 return;
227 }
228
229 const QRect fittingBounds =
230 pasteAtCursorPosition ? QRect() : image->bounds();
231
232 // If no shapes, check for layers
233 if (KisClipboard::instance()->hasLayers()) {
234 const QPointF offsetTopLeft = [&]() -> QPointF {
235 KisPaintDeviceSP clip =
237 image->colorSpace());
238
239 if (!clip) {
240 pasteAtCursorPosition = false;
241 return {};
242 }
243
244
245 QPointF imagePos;
246 if (pasteAtCursorPosition) {
247 imagePos =
249 docPos);
250
251 } else if (!clip->exactBounds().intersects(image->bounds())) {
252 // BUG:459111
253 pasteAtCursorPosition = true;
254 imagePos = QPointF(image->bounds().center());
255 } else {
256 return {};
257 }
258 const QPointF offset =
259 (imagePos - QRectF(clip->exactBounds()).center()).toPoint();
260 return offset;
261 }();
262
263
264 if (view->selection()) {
267 KisProcessingApplicator *ap = beginAction(view, kundo2_i18n("Add Layer"));
268 KUndo2Command *deselectCmd = new KisDeselectActiveSelectionCommand(view->selection(), image);
269 ap->applyCommand(deselectCmd);
270 view->nodeManager()->pasteLayersFromClipboard(pasteAtCursorPosition,
271 offsetTopLeft,
272 ap);
273 endAction(ap, KisOperationConfiguration(id()).toXML());
274 } else {
275 view->nodeManager()->pasteLayersFromClipboard(pasteAtCursorPosition,
276 offsetTopLeft);
277 }
278
279 return;
280 }
281
282 KisTimeSpan range;
283 KisPaintDeviceSP clip = KisClipboard::instance()->clip(fittingBounds, true, -1, &range);
284
285 if (clip) {
286 if (pasteAtCursorPosition) {
287 const QPointF imagePos = view->canvasBase()->coordinatesConverter()->documentToImage(docPos);
288
289 const QPoint offset =
290 (imagePos - QRectF(clip->exactBounds()).center()).toPoint();
291
292 clip->setX(clip->x() + offset.x());
293 clip->setY(clip->y() + offset.y());
294 }
295
297 bool renamePastedLayers = KisConfig(true).renamePastedLayers();
298 QString pastedLayerName = renamePastedLayers ? image->nextLayerName() + " " + i18n("(pasted)") :
299 image->nextLayerName();
300 KisPaintLayerSP newLayer = new KisPaintLayer(image.data(),
301 pastedLayerName,
303 KisNodeSP aboveNode = view->activeLayer();
304 KisNodeSP parentNode = aboveNode ? aboveNode->parent() : image->root();
305
306 if (range.isValid()) {
307 newLayer->enableAnimation();
309 KisRasterKeyframeChannel *rasterChannel = dynamic_cast<KisRasterKeyframeChannel*>(channel);
310 KIS_SAFE_ASSERT_RECOVER_RETURN(rasterChannel);
311 rasterChannel->importFrame(range.start(), clip, nullptr);
312
313 if (!range.isInfinite()) {
314 rasterChannel->addKeyframe(range.end() + 1, 0);
315 }
316 } else {
317 const QRect rc = clip->extent();
318 KisPainter::copyAreaOptimized(rc.topLeft(), clip, newLayer->paintDevice(), rc);
319 }
320
321 KUndo2Command *cmd = new KisImageLayerAddCommand(image, newLayer, parentNode, aboveNode);
322 KisProcessingApplicator *ap = beginAction(view, cmd->text());
324
325 if (view->selection()) {
326 KUndo2Command *deselectCmd = new KisDeselectActiveSelectionCommand(view->selection(), image);
328 }
329
330 if (KisConfig(true).activateTransformToolAfterPaste()) {
331 KUndo2Command *transformToolCmd = new KisTransformToolActivationCommand(view);
333 }
334
335 endAction(ap, KisOperationConfiguration(id()).toXML());
336 }
337}
const quint8 OPACITY_OPAQUE_U8
KUndo2MagicString text() const
KisCoordinatesConverter * coordinatesConverter
KisToolProxy toolProxy
static KisClipboard * instance()
KisPaintDeviceSP clipFromKritaLayers(const KoColorSpace *cs) const
bool renamePastedLayers(bool defaultValue=false) const
_Private::Traits< T >::Result documentToImage(const T &obj) const
The command for adding a layer.
const KoColorSpace * colorSpace() const
QString nextLayerName(const QString &baseName="") const
Definition kis_image.cc:715
QRect bounds() const override
static void adaptClipToImageColorSpace(KisPaintDeviceSP dev, KisImageSP image)
KisKeyframeChannel stores and manages KisKeyframes. Maps units of time to virtual keyframe values....
static const KoID Raster
void addKeyframe(int time, KUndo2Command *parentUndoCmd=nullptr)
Add a new keyframe to the channel at the specified time.
void pasteLayersFromClipboard(bool changeOffset=false, QPointF offset=QPointF(), KisProcessingApplicator *applicator=nullptr)
KisProcessingApplicator * beginAction(KisViewManager *view, const KUndo2MagicString &actionName)
void endAction(KisProcessingApplicator *applicator, const QString &xmlData)
void setX(qint32 x)
QRect exactBounds() const
QRect extent() const
void setY(qint32 y)
static void copyAreaOptimized(const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect)
void applyCommand(KUndo2Command *command, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
The KisRasterKeyframeChannel is a concrete KisKeyframeChannel subclass that stores and manages KisRas...
void importFrame(int time, KisPaintDeviceSP sourceDevice, KUndo2Command *parentCommand)
int start() const
bool isInfinite() const
int end() const
bool isValid() const
KisCanvas2 * canvasBase() const
Return the canvas base class.
KisSelectionSP selection()
KisLayerSP activeLayer()
Convenience method to get at the active layer.
KisNodeManager * nodeManager() const
The node manager handles everything about nodes.
KisImageWSP image() const
Return the image this view is displaying.
KoCanvasController * canvasController() const
virtual QPointF currentCursorPosition() const =0
bool paste()
Forwarded to the current KoToolBase.
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define bounds(x, a, b)
KUndo2MagicString kundo2_i18n(const char *text)
KisKeyframeChannel * getKeyframeChannel(const QString &id, bool create)
void enableAnimation()
KisNodeWSP parent
Definition kis_node.cpp:86
KisPaintDeviceSP paintDevice

References KisViewManager::activeLayer(), KisImportCatcher::adaptClipToImageColorSpace(), KisKeyframeChannel::addKeyframe(), KisProcessingApplicator::applyCommand(), KisStrokeJobData::BARRIER, KisOperation::beginAction(), KisImage::bounds(), KisViewManager::canvasBase(), KoCanvasBase::canvasController(), KisClipboard::clip, KisClipboard::clipFromKritaLayers(), KisImage::colorSpace(), KisCanvas2::coordinatesConverter, KisPainter::copyAreaOptimized(), KoCanvasController::currentCursorPosition(), KisSharedPtr< T >::data(), KisCoordinatesConverter::documentToImage(), KisBaseNode::enableAnimation(), KisTimeSpan::end(), KisOperation::endAction(), KisPaintDevice::exactBounds(), KisPaintDevice::extent(), KisBaseNode::getKeyframeChannel(), KisViewManager::image(), KisRasterKeyframeChannel::importFrame(), KisClipboard::instance(), KisTimeSpan::isInfinite(), KisTimeSpan::isValid(), KIS_SAFE_ASSERT_RECOVER_RETURN, kundo2_i18n(), KisImage::nextLayerName(), KisViewManager::nodeManager(), KisStrokeJobData::NORMAL, OPACITY_OPAQUE_U8, KisPaintLayer::paintDevice, KisNode::parent, KoToolProxy::paste(), PasteAtCursor, KisNodeManager::pasteLayersFromClipboard(), KisKeyframeChannel::Raster, KisConfig::renamePastedLayers(), KisNodeFacade::root, KisViewManager::selection(), KisStrokeJobData::SEQUENTIAL, KisPaintDevice::setX(), KisPaintDevice::setY(), KisTimeSpan::start(), KUndo2Command::text(), KisCanvas2::toolProxy, KisPaintDevice::x(), and KisPaintDevice::y().

◆ runFromXML()

void KisPasteActionFactory::runFromXML ( KisViewManager * view,
const KisOperationConfiguration & config )
inlineoverridevirtual

Reimplemented from KisOperation.

Definition at line 24 of file KisPasteActionFactories.h.

24 {
25 Flags flags;
26 flags.setFlag(PasteAtCursor, config.getBool("paste-at-cursor-position", false));
27 flags.setFlag(ForceNewLayer, config.getBool("force-new-layer", false));
28 run(flags, view);
29 }
void run(Flags flags, KisViewManager *view)
bool getBool(const QString &name, bool def=false) const

References KisPropertiesConfiguration::getBool().


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