Krita Source Code Documentation
Loading...
Searching...
No Matches
KisToolUtils Namespace Reference

Classes

struct  ColorSamplerConfig
 
class  StandardBrushSizes
 

Enumerations

enum  ColorSamplerSource { SampleSourceImage = 0 , SampleSourceGroup , SampleSourceNode }
 

Functions

void bakeDefaultPixel (KisPaintDeviceSP clip, const QRect &rc)
 
KisImageSP buildImageForClipboard (KisImageSP srcImage, KisNodeList nodes)
 
bool clearImage (KisImageSP image, KisNodeList nodes, KisSelectionSP selection)
 
void ensureClipVisible (const QRect &imageBounds, KisPaintDeviceSP clip)
 
KisNodeSP findNode (KisNodeSP node, const QPoint &point, bool wholeGroup, bool editableOnly)
 
KisNodeList findNodes (KisNodeSP node, const QPoint &point, bool wholeGroup, bool includeGroups, bool editableOnly)
 
QList< KisShapeLayerSP > findShapeLayers (KisNodeSP root, const QPointF &point, bool editableOnly)
 
QString nodeEditableMessage (KisNodeSP node, bool blockedNoIndirectPainting=false)
 nodeEditableMessage
 
bool KRITAUI_EXPORT platformSupportsSetCursorPos ()
 
void recenterClip (KisPaintDeviceSP clip, const QPoint &newCenter)
 
bool sampleColor (KoColor &out_color, KisPaintDeviceSP dev, const QPoint &pos, KoColor const *const blendColor, int radius, int blend, bool pure)
 
bool selectShapeCrossLayer (KoCanvasBase *canvas, const QPointF &point, const QString &shapeType=QString(), bool skipCurrentShapes=true)
 selectShapeCrossLayer Tries to select a shape under the cursor regardless of which layer it is on, to do so, it will always select the layer first and then the shape.
 
void KRITAUI_EXPORT setCursorPos (const QPoint &point)
 
QPainterPath shapeHoverInfoCrossLayer (KoCanvasBase *canvas, const QPointF &point, QString &shapeType, bool *isHorizontal=nullptr, bool skipCurrentShapes=true)
 shapeHoverInfoCrossLayer get hover info of shapes on all layers.
 
void KRITAUI_EXPORT showBrushSizeFloatingMessage (KoCanvasBase *canvas, qreal size)
 
void trimDeviceForClipboard (KisImageSP image, KisPaintDeviceSP device, KisSelectionSP selection, bool makeSharpClip)
 

Enumeration Type Documentation

◆ ColorSamplerSource

Enumerator
SampleSourceImage 
SampleSourceGroup 
SampleSourceNode 

Definition at line 21 of file kis_tool_utils.h.

Function Documentation

◆ bakeDefaultPixel()

void KRITAUI_EXPORT KisToolUtils::bakeDefaultPixel ( KisPaintDeviceSP clip,
const QRect & rc )

If clip has non-transparent default pixel, it will be written into pixels explicitly in the area rc. After that, the default pixel will be reset to "transparent".

Definition at line 545 of file kis_tool_utils.cpp.

546 {
548 KisPaintDeviceSP copy = new KisPaintDevice(clip->colorSpace());
549 copy->makeCloneFromRough(clip, rc);
550 KisPainter::copyAreaOptimized(rc.topLeft(), copy, clip, rc);
552 }
553 }
const quint8 OPACITY_TRANSPARENT_U8
void setDefaultPixel(const KoColor &defPixel)
const KoColorSpace * colorSpace() const
KoColor defaultPixel() const
static void copyAreaOptimized(const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect)
static KoColor createTransparent(const KoColorSpace *cs)
Definition KoColor.cpp:682
quint8 opacityU8() const
Definition KoColor.cpp:341

References KisPaintDevice::colorSpace(), KisPainter::copyAreaOptimized(), KoColor::createTransparent(), KisPaintDevice::defaultPixel(), OPACITY_TRANSPARENT_U8, KoColor::opacityU8(), and KisPaintDevice::setDefaultPixel().

◆ buildImageForClipboard()

KisImageSP KRITAUI_EXPORT KisToolUtils::buildImageForClipboard ( KisImageSP srcImage,
KisNodeList nodes )

Creates an image that has the same resolution and size as srcImage, which can be used as a container image for uploading nodes into clipboard.

Definition at line 515 of file kis_tool_utils.cpp.

516 {
517 KisImageSP clipImage = new KisImage(0, srcImage->width(), srcImage->height(), srcImage->colorSpace(), "ClipImage");
518 clipImage->setResolution(srcImage->xRes(), srcImage->yRes());
519 Q_FOREACH (KisNodeSP node, nodes) {
520 clipImage->addNode(node, clipImage->root());
521 }
522
523 clipImage->refreshGraphAsync();
524 clipImage->waitForDone();
525
526 return clipImage;
527 }
void waitForDone()
void refreshGraphAsync(KisNodeSP root, const QVector< QRect > &rects, const QRect &cropRect, KisProjectionUpdateFlags flags=KisProjectionUpdateFlag::None) override
const KoColorSpace * colorSpace() const
qint32 width() const
double xRes() const
double yRes() const
qint32 height() const
void setResolution(double xres, double yres)
bool addNode(KisNodeSP node, KisNodeSP parent=KisNodeSP(), KisNodeAdditionFlags flags=KisNodeAdditionFlag::None)

References KisNodeFacade::addNode(), KisImage::colorSpace(), KisImage::height(), KisImage::refreshGraphAsync(), KisNodeFacade::root, KisImage::setResolution(), KisImage::waitForDone(), KisImage::width(), KisImage::xRes(), and KisImage::yRes().

◆ clearImage()

bool KRITAUI_EXPORT KisToolUtils::clearImage ( KisImageSP image,
KisNodeList nodes,
KisSelectionSP selection )

return true if success Clears the image. Selection is optional, use 0 to clear everything.

Definition at line 198 of file kis_tool_utils.cpp.

199 {
200 KisNodeList masks;
201
202 Q_FOREACH (KisNodeSP node, nodes) {
203 if (node->inherits("KisMask")) {
204 masks.append(node);
205 }
206 }
207
208 // To prevent deleting same layer multiple times
210 nodes.append(masks);
211
212 if (nodes.isEmpty()) {
213 return false;
214 }
215
218
219 Q_FOREACH (KisNodeSP node, nodes) {
220 KisLayerUtils::recursiveApplyNodes(node, [&applicator, selection, masks] (KisNodeSP node) {
221
222 // applied on masks if selected explicitly
223 if (node->inherits("KisMask") && !masks.contains(node)) {
224 return;
225 }
226
227 if(node->hasEditablePaintDevice()) {
228 KUndo2Command *cmd =
229 new KisCommandUtils::LambdaCommand(kundo2_i18n("Clear"),
230 [node, selection] () {
231 KisPaintDeviceSP device = node->paintDevice();
232
233 std::unique_ptr<KisCommandUtils::CompositeCommand> parentCommand(
234 new KisCommandUtils::CompositeCommand());
235
236 KUndo2Command *autoKeyframeCommand = KisAutoKey::tryAutoCreateDuplicatedFrame(device);
237 if (autoKeyframeCommand) {
238 parentCommand->addCommand(autoKeyframeCommand);
239 }
240
241 KisTransaction transaction(kundo2_noi18n("internal-clear-command"), device);
242
243 QRect dirtyRect;
244 if (selection) {
245 dirtyRect = selection->selectedRect();
246 device->clearSelection(selection);
247 } else {
248 dirtyRect = device->extent();
249 device->clear();
250 }
251
252 device->setDirty(dirtyRect);
253 parentCommand->addCommand(transaction.endAndTake());
254
255 return parentCommand.release();
256 });
257 applicator.applyCommand(cmd, KisStrokeJobData::CONCURRENT);
258 }
259 });
260 }
261
262 applicator.end();
263
264 return true;
265 }
QVector< KisImageSignalType > KisImageSignalVector
KUndo2MagicString kundo2_i18n(const char *text)
void recursiveApplyNodes(NodePointer node, Functor func)
void filterMergeableNodes(KisNodeList &nodes, bool allowMasks)
bool hasEditablePaintDevice() const

References KisProcessingApplicator::applyCommand(), KisStrokeJobData::CONCURRENT, KisLayerUtils::filterMergeableNodes(), KisBaseNode::hasEditablePaintDevice(), kundo2_i18n(), KisProcessingApplicator::NONE, and KisLayerUtils::recursiveApplyNodes().

◆ ensureClipVisible()

void KRITAUI_EXPORT KisToolUtils::ensureClipVisible ( const QRect & imageBounds,
KisPaintDeviceSP clip )

Make sure non-default area of the clip device is visible within image bounds

The function uses nonDefaultPixelArea() instead of exactBounds(), because the clip may have non-transparent default pixel.

Definition at line 536 of file kis_tool_utils.cpp.

537 {
538 const QRect clipBounds = clip->nonDefaultPixelArea();
539 if (!imageBounds.intersects(clipBounds)) {
540 const QPoint diff = imageBounds.center() - clipBounds.center();
541 clip->moveTo(clip->offset() + diff);
542 }
543 }
QRect nonDefaultPixelArea() const
void moveTo(qint32 x, qint32 y)
QPoint offset() const

References KisPaintDevice::moveTo(), KisPaintDevice::nonDefaultPixelArea(), and KisPaintDevice::offset().

◆ findNode()

KisNodeSP KRITAUI_EXPORT KisToolUtils::findNode ( KisNodeSP node,
const QPoint & point,
bool wholeGroup,
bool editableOnly = true )

Recursively search a node with a non-transparent pixel

Definition at line 121 of file kis_tool_utils.cpp.

122 {
123 KisNodeSP foundNode = 0;
124 while (node) {
125 KisLayerSP layer = qobject_cast<KisLayer*>(node.data());
126
127 if (!layer || !layer->isEditable()) {
128 node = node->prevSibling();
129 continue;
130 }
131
132 KoColor color(layer->projection()->colorSpace());
133 layer->projection()->pixel(point.x(), point.y(), &color);
134
135 KisGroupLayerSP group = dynamic_cast<KisGroupLayer*>(layer.data());
136
137 if ((group && group->passThroughMode()) || color.opacityU8() != OPACITY_TRANSPARENT_U8) {
138 if (layer->inherits("KisGroupLayer") && (!editableOnly || layer->isEditable())) {
139 // if this is a group and the pixel is transparent, don't even enter it
140 foundNode = findNode(node->lastChild(), point, wholeGroup, editableOnly);
141 }
142 else {
143 foundNode = !wholeGroup ? node : node->parent();
144 }
145
146 }
147
148 if (foundNode) break;
149
150 node = node->prevSibling();
151 }
152
153 return foundNode;
154 }
bool pixel(qint32 x, qint32 y, QColor *c) const
bool isEditable(bool checkVisibility=true) const
KisPaintDeviceSP projection() const override
Definition kis_layer.cc:826
KisNodeSP prevSibling() const
Definition kis_node.cpp:402
KisNodeWSP parent
Definition kis_node.cpp:86
KisNodeSP lastChild() const
Definition kis_node.cpp:367

References KisPaintDevice::colorSpace(), KisSharedPtr< T >::data(), findNode(), KisBaseNode::isEditable(), KisNode::lastChild(), OPACITY_TRANSPARENT_U8, KoColor::opacityU8(), KisNode::parent, KisGroupLayer::passThroughMode, KisPaintDevice::pixel(), KisNode::prevSibling(), and KisLayer::projection().

◆ findNodes()

KisNodeList KRITAUI_EXPORT KisToolUtils::findNodes ( KisNodeSP node,
const QPoint & point,
bool wholeGroup,
bool includeGroups,
bool editableOnly )

Definition at line 156 of file kis_tool_utils.cpp.

157 {
158 KisNodeList foundNodes;
159 while (node) {
160 KisLayerSP layer = qobject_cast<KisLayer*>(node.data());
161
162 if (!layer || !layer->isEditable()) {
163 node = node->nextSibling();
164 continue;
165 }
166
167 KoColor color(layer->projection()->colorSpace());
168 layer->projection()->pixel(point.x(), point.y(), &color);
169 const bool isTransparent = color.opacityU8() == OPACITY_TRANSPARENT_U8;
170
171 KisGroupLayerSP group = dynamic_cast<KisGroupLayer*>(layer.data());
172
173 if (group) {
174 if (!isTransparent || group->passThroughMode()) {
175 foundNodes << findNodes(node->firstChild(), point, wholeGroup, includeGroups, editableOnly);
176 if (includeGroups) {
177 foundNodes << node;
178 }
179 }
180 } else {
181 if (!isTransparent) {
182 if (wholeGroup) {
183 if (!foundNodes.contains(node->parent())) {
184 foundNodes << node->parent();
185 }
186 } else {
187 foundNodes << node;
188 }
189 }
190 }
191
192 node = node->nextSibling();
193 }
194
195 return foundNodes;
196 }
KisNodeSP firstChild() const
Definition kis_node.cpp:361
KisNodeSP nextSibling() const
Definition kis_node.cpp:408

References KisPaintDevice::colorSpace(), KisSharedPtr< T >::data(), findNodes(), KisNode::firstChild(), KisBaseNode::isEditable(), KisNode::nextSibling(), OPACITY_TRANSPARENT_U8, KoColor::opacityU8(), KisNode::parent, KisGroupLayer::passThroughMode, KisPaintDevice::pixel(), and KisLayer::projection().

◆ findShapeLayers()

QList< KisShapeLayerSP > KisToolUtils::findShapeLayers ( KisNodeSP root,
const QPointF & point,
bool editableOnly )

Definition at line 340 of file kis_tool_utils.cpp.

340 {
341 QList<KisShapeLayerSP> foundNodes;
343 if ((node->isEditable(true) && editableOnly) || !editableOnly) {
344
345 KisShapeLayerSP shapeLayer = dynamic_cast<KisShapeLayer*>(node.data());
346 if (shapeLayer && shapeLayer->isEditable() && shapeLayer->shapeManager()->shapeAt(point)) {
347 foundNodes.append(shapeLayer);
348 }
349 }
350 });
351 return foundNodes;
352 }

References KisBaseNode::isEditable(), and KisLayerUtils::recursiveApplyNodes().

◆ nodeEditableMessage()

QString KRITAUI_EXPORT KisToolUtils::nodeEditableMessage ( KisNodeSP node,
bool blockedNoIndirectPainting = false )

nodeEditableMessage

Parameters
node– active node.
blockedNoIndirectPainting– whether editing is blocked due no-indirect painting being possible.
Returns
the message for why the node is not editable. Will return empty if it is editable after all.

Definition at line 423 of file kis_tool_utils.cpp.

424 {
425 QString message;
426 if (!node->isEditable(true) || blockedNoIndirectPainting) {
427 if (!node->visible() && node->userLocked()) {
428 message = i18n("Layer is locked and invisible.");
429 } else if (node->userLocked()) {
430 message = i18n("Layer is locked.");
431 } else if(!node->visible()) {
432 message = i18n("Layer is invisible.");
433 } else if (blockedNoIndirectPainting) {
434 message = i18n("Layer can't be painted in Build Up mode.");
435 } else {
436 message = i18n("Group not editable.");
437 }
438 }
439 return message;
440 }
bool userLocked() const
virtual bool visible(bool recursive=false) const

References KisBaseNode::isEditable(), KisBaseNode::userLocked(), and KisBaseNode::visible().

◆ platformSupportsSetCursorPos()

bool KRITAUI_EXPORT KisToolUtils::platformSupportsSetCursorPos ( )

Return true if platform supports QCursor::setPos() call

All platforms except Wayland support that

Definition at line 312 of file kis_tool_utils.cpp.

313 {
314 return qApp->platformName() != "wayland";
315 }

◆ recenterClip()

void KRITAUI_EXPORT KisToolUtils::recenterClip ( KisPaintDeviceSP clip,
const QPoint & newCenter )

Moves the center of non-default area to the requested position

Definition at line 529 of file kis_tool_utils.cpp.

530 {
531 const QRect clipBounds = clip->nonDefaultPixelArea();
532 const QPoint diff = newCenter - clipBounds.center();
533 clip->moveTo(clip->offset() + diff);
534 }

References KisPaintDevice::moveTo(), KisPaintDevice::nonDefaultPixelArea(), and KisPaintDevice::offset().

◆ sampleColor()

bool KRITAUI_EXPORT KisToolUtils::sampleColor ( KoColor & out_color,
KisPaintDeviceSP dev,
const QPoint & pos,
KoColor const *const blendColor = nullptr,
int radius = 1,
int blend = 100,
bool pure = false )

Sample a color based on the given position on the given paint device.

out_color - Output parameter returning newly sampled color. dev - Paint device to sample from. pos - Position to sample from. blendColor - Optional color to be blended with. radius - Sampling area radius in pixels. blend - Blend percentage. 100% all sampled, 0% all blendColor. pure - Whether to bypass radius, blending, and active layer settings for pure sampling.

RETURN - Returns TRUE whenever a valid color is sampled.

Definition at line 42 of file kis_tool_utils.cpp.

44 {
45 KIS_ASSERT(dev);
46
47 // Bugfix hack forcing pure on first sample to avoid wrong
48 // format blendColor on newly initialized Krita.
49 static bool firstTime = true;
50 if (firstTime == true) {
51 pure = true;
52 firstTime = false;
53 }
54
55 const KoColorSpace *cs = dev->colorSpace();
56 KoColor sampledColor = KoColor::createTransparent(cs);
57
58 // Wrap around color sampling is supported on any paint device
59 bool oldSupportsWraparound = dev->supportsWraproundMode();
61
62 // Sampling radius.
63 if (!pure && radius > 1) {
64 QScopedPointer<KoMixColorsOp::Mixer> mixer(cs->mixColorsOp()->createMixer());
65
67 const int effectiveRadius = radius - 1;
68
69 const QRect sampleRect(pos.x() - effectiveRadius, pos.y() - effectiveRadius,
70 2 * effectiveRadius + 1, 2 * effectiveRadius + 1);
71 KisSequentialConstIterator it(dev, sampleRect);
72
73 const int radiusSq = pow2(effectiveRadius);
74
75 int nConseqPixels = it.nConseqPixels();
76 while (it.nextPixels(nConseqPixels)) {
77 const QPoint realPos(it.x(), it.y());
78 if (kisSquareDistance(realPos, pos) < radiusSq) {
79 mixer->accumulateAverage(it.oldRawData(), nConseqPixels);
80 }
81 }
82
83 mixer->computeMixedColor(sampledColor.data());
84
85 } else {
86 dev->pixel(pos.x(), pos.y(), &sampledColor);
87 }
88
89 dev->setSupportsWraparoundMode(oldSupportsWraparound);
90
91 // Color blending.
92 if (!pure && blendColor && blend < 100) {
93 KoColor effectiveBlendColor = *blendColor;
94 effectiveBlendColor.convertTo(dev->colorSpace());
95
96 //Scale from 0..100% to 0..255 range for mixOp weights.
97 quint8 blendScaled = static_cast<quint8>(blend * 2.55f);
98
99 const quint8 *colors[2];
100 colors[0] = effectiveBlendColor.data();
101 colors[1] = sampledColor.data();
102 qint16 weights[2];
103 weights[0] = 255 - blendScaled;
104 weights[1] = blendScaled;
105
106 const KoMixColorsOp *mixOp = dev->colorSpace()->mixColorsOp();
107 mixOp->mixColors(colors, weights, 2, sampledColor.data());
108 }
109
110 sampledColor.convertTo(dev->compositionSourceColorSpace());
111
112 bool validColorSampled = sampledColor.opacityU8() != OPACITY_TRANSPARENT_U8;
113
114 if (validColorSampled) {
115 out_color = sampledColor;
116 }
117
118 return validColorSampled;
119 }
bool supportsWraproundMode() const
virtual const KoColorSpace * compositionSourceColorSpace() const
void setSupportsWraparoundMode(bool value)
KoMixColorsOp * mixColorsOp
void convertTo(const KoColorSpace *cs, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)
Definition KoColor.cpp:136
quint8 * data()
Definition KoColor.h:144
virtual Mixer * createMixer() const =0
virtual void mixColors(const quint8 *const *colors, const qint16 *weights, int nColors, quint8 *dst, int weightSum=255) const =0
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
T pow2(const T &x)
Definition kis_global.h:166
qreal kisSquareDistance(const QPointF &pt1, const QPointF &pt2)
Definition kis_global.h:194
T blend(T src, T srcAlpha, T dst, T dstAlpha, T cfValue)

References KisPaintDevice::colorSpace(), KisPaintDevice::compositionSourceColorSpace(), KoColor::convertTo(), KoMixColorsOp::createMixer(), KoColor::createTransparent(), KoColor::data(), KIS_ASSERT, kisSquareDistance(), KoMixColorsOp::mixColors(), KoColorSpace::mixColorsOp, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nConseqPixels(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixels(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::oldRawData(), OPACITY_TRANSPARENT_U8, KoColor::opacityU8(), KisPaintDevice::pixel(), pow2(), KisPaintDevice::setSupportsWraparoundMode(), KisPaintDevice::supportsWraproundMode(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::x(), and KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::y().

◆ selectShapeCrossLayer()

bool KRITAUI_EXPORT KisToolUtils::selectShapeCrossLayer ( KoCanvasBase * canvas,
const QPointF & point,
const QString & shapeType = QString(),
bool skipCurrentShapes = true )

selectShapeCrossLayer Tries to select a shape under the cursor regardless of which layer it is on, to do so, it will always select the layer first and then the shape.

Parameters
canvas– the current canvas.
point– the point in document coordinates.
shapeType– the required shapeId, if empty, selects any koshape.
Returns
whether a shape was successfully selected.

Definition at line 395 of file kis_tool_utils.cpp.

396 {
397 KisCanvas2 *canvas2 = dynamic_cast<KisCanvas2*>(canvas);
398 if (!canvas2) return false;
399
400 QList<KoShape*> currentShapes = canvas->shapeManager()->selection()->selectedShapes();
401 QList<KisShapeLayerSP> candidates = findShapeLayers(canvas2->image()->root(), point, true);
402 KisShapeLayerSP shapeLayer = candidates.isEmpty()? nullptr: candidates.last();
403
404 if (shapeLayer) {
405 KoShape *shape = shapeLayer->shapeManager()->shapeAt(point);
406 if (shape
407 && !(currentShapes.contains(shape) && skipCurrentShapes)
408 && (shapeType.isEmpty() || shapeType == shape->shapeId())) {
409 canvas2->viewManager()->nodeManager()->slotNonUiActivatedNode(shapeLayer);
410 canvas2->shapeManager()->selection()->deselectAll();
411 canvas2->shapeManager()->selection()->select(shape);
412 } else {
413 return false;
414 }
415 } else {
416 return false;
417 }
418
419 return true;
420 }
KisImageWSP image() const
KoShapeManager shapeManager
KisViewManager * viewManager() const
void slotNonUiActivatedNode(KisNodeSP node)
KoShapeManager * shapeManager() const
KisNodeManager * nodeManager() const
The node manager handles everything about nodes.
virtual KoShapeManager * shapeManager() const =0
void deselectAll()
clear the selections list
void select(KoShape *shape)
const QList< KoShape * > selectedShapes() const
KoShape * shapeAt(const QPointF &position, KoFlake::ShapeSelection selection=KoFlake::ShapeOnTop, bool omitHiddenShapes=true)
KoSelection * selection
QString shapeId() const
Definition KoShape.cpp:878
QList< KisShapeLayerSP > findShapeLayers(KisNodeSP root, const QPointF &point, bool editableOnly)

References KoSelection::deselectAll(), findShapeLayers(), KisCanvas2::image(), KisViewManager::nodeManager(), KisNodeFacade::root, KoSelection::select(), KoSelection::selectedShapes(), KoShapeManager::selection, KoShapeManager::shapeAt(), KoShape::shapeId(), KisShapeLayer::shapeManager(), KoCanvasBase::shapeManager(), KisCanvas2::shapeManager, KisNodeManager::slotNonUiActivatedNode(), and KisCanvas2::viewManager().

◆ setCursorPos()

void KRITAUI_EXPORT KisToolUtils::setCursorPos ( const QPoint & point)

Moves the cursor (hot spot) of the primary screen to the global screen position (x, y).

This function is provided as a replacement to QCursor::setPos which does not properly handle multiple monitors with different scale factors.

Definition at line 317 of file kis_tool_utils.cpp.

318 {
319 // https://bugreports.qt.io/browse/QTBUG-99009
320 QScreen *screen = qApp->screenAt(point);
321 if (!screen) {
322 screen = qApp->primaryScreen();
323 }
324 QCursor::setPos(screen, point);
325 }

◆ shapeHoverInfoCrossLayer()

QPainterPath KRITAUI_EXPORT KisToolUtils::shapeHoverInfoCrossLayer ( KoCanvasBase * canvas,
const QPointF & point,
QString & shapeType,
bool * isHorizontal = nullptr,
bool skipCurrentShapes = true )

shapeHoverInfoCrossLayer get hover info of shapes on all layers.

Parameters
canvas– current canvas.
point– the point in document coordinates.
shapeType– the shapeID of the found shape.
isHorizontal– when this is a textShape, sets whether the writing mode is horizontal.
Returns

Definition at line 354 of file kis_tool_utils.cpp.

355 {
356 QPainterPath p;
357 KisCanvas2 *canvas2 = dynamic_cast<KisCanvas2*>(canvas);
358 if (!canvas2) return p;
359
360 QList<KoShape*> currentShapes = canvas->shapeManager()->selection()->selectedShapes();
361 QList<KisShapeLayerSP> candidates = findShapeLayers(canvas2->image()->root(), point, true);
362 KisShapeLayerSP shapeLayer = candidates.isEmpty()? nullptr: candidates.last();
363
364 if (shapeLayer) {
365 KoShape *shape = shapeLayer->shapeManager()->shapeAt(point);
366 if (shape && !(currentShapes.contains(shape) && skipCurrentShapes)) {
367 shapeType = shape->shapeId();
368 KoSvgTextShape *t = dynamic_cast<KoSvgTextShape *>(shape);
369 if (t) {
370 p.addRect(t->boundingRect());
371 if (isHorizontal) {
372 *isHorizontal = t->writingMode() == KoSvgText::HorizontalTB;
373 }
374 if (!t->shapesInside().isEmpty()) {
375 QPainterPath paths;
376 Q_FOREACH(KoShape *s, t->shapesInside()) {
377 KoPathShape *path = dynamic_cast<KoPathShape *>(s);
378 if (path) {
379 paths.addPath(path->absoluteTransformation().map(path->outline()));
380 }
381 }
382 if (!paths.isEmpty()) {
383 p = paths;
384 }
385 }
386 } else {
387 p = shape->absoluteTransformation().map(shape->outline());
388 }
389 }
390 }
391
392 return p;
393 }
const Params2D p
The position of a path point within a path shape.
Definition KoPathShape.h:63
virtual QPainterPath outline() const
Definition KoShape.cpp:554
QTransform absoluteTransformation() const
Definition KoShape.cpp:330
QRectF boundingRect() const override
Get the bounding box of the shape.
QList< KoShape * > shapesInside
KoSvgText::WritingMode writingMode() const
writingMode There's a number of places we need to check the writing mode to provide proper controls.
@ HorizontalTB
Definition KoSvgText.h:38

References KoShape::absoluteTransformation(), KoSvgTextShape::boundingRect(), findShapeLayers(), KoSvgText::HorizontalTB, KisCanvas2::image(), KoShape::outline(), p, KisNodeFacade::root, KoSelection::selectedShapes(), KoShapeManager::selection, KoShapeManager::shapeAt(), KoShape::shapeId(), KisShapeLayer::shapeManager(), KoCanvasBase::shapeManager(), KoSvgTextShape::shapesInside, and KoSvgTextShape::writingMode().

◆ showBrushSizeFloatingMessage()

void KRITAUI_EXPORT KisToolUtils::showBrushSizeFloatingMessage ( KoCanvasBase * canvas,
qreal size )

Definition at line 327 of file kis_tool_utils.cpp.

328 {
329 KisCanvas2 *kisCanvas = dynamic_cast<KisCanvas2 *>(canvas);
331 kisCanvas->viewManager()->showFloatingMessage(i18n("Brush Size: %1 px", size),
332 QIcon(),
333 1000,
335 Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter);
336 }
void showFloatingMessage(const QString &message, const QIcon &icon, int timeout=4500, KisFloatingMessage::Priority priority=KisFloatingMessage::Medium, int alignment=Qt::AlignCenter|Qt::TextWordWrap)
shows a floating message in the top right corner of the canvas
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References KisFloatingMessage::High, KIS_SAFE_ASSERT_RECOVER_RETURN, KisViewManager::showFloatingMessage(), and KisCanvas2::viewManager().

◆ trimDeviceForClipboard()

void KRITAUI_EXPORT KisToolUtils::trimDeviceForClipboard ( KisImageSP image,
KisPaintDeviceSP device,
KisSelectionSP selection,
bool makeSharpClip = false )

Trims the device for uploading to the clipboard

  • if selection is present, then selection is baked into the device, the whole device is cropped by the selection and the default pixel is reset to "transparent
  • if selection is null, then device is just cropped by the image bounds

Sharp method is an exact reverse of COMPOSITE_OVER so if you cover the cut/copied piece over its source you get an exactly the same image without any seams

Definition at line 468 of file kis_tool_utils.cpp.

472 {
474
475 QRect rc = selection ? selection->selectedExactRect() : image->bounds();
476
477 const KoColorSpace *cs = device->colorSpace();
478
479 if (selection) {
480 // Apply selection mask.
481 KisPaintDeviceSP selectionProjection = selection->projection();
482 const KoColorSpace *selCs = selection->projection()->colorSpace();
483
484 KisSequentialIterator layerIt(device, rc);
485 KisSequentialConstIterator selectionIt(selectionProjection, rc);
486
487 while (layerIt.nextPixel() && selectionIt.nextPixel()) {
488
494 if (makeSharpClip) {
495 qreal dstAlpha = cs->opacityF(layerIt.rawData());
496 qreal sel = selCs->opacityF(selectionIt.oldRawData());
497 qreal newAlpha = sel * dstAlpha / (1.0 - dstAlpha + sel * dstAlpha);
498 float mask = newAlpha / dstAlpha;
499
500 cs->applyAlphaNormedFloatMask(layerIt.rawData(), &mask, 1);
501 } else {
502 cs->applyAlphaU8Mask(layerIt.rawData(), selectionIt.oldRawData(), 1);
503 }
504 }
505
506 // if we have a selection, then we should remove the rest of the image
507 // and make it fully transparent
509 device->purgeDefaultPixels();
510 }
511
512 device->crop(rc);
513 }
QRect bounds() const override
void crop(qint32 x, qint32 y, qint32 w, qint32 h)
virtual void applyAlphaU8Mask(quint8 *pixels, const quint8 *alpha, qint32 nPixels) const =0
virtual qreal opacityF(const quint8 *pixel) const =0
virtual void applyAlphaNormedFloatMask(quint8 *pixels, const float *alpha, qint32 nPixels) const =0
KisPixelSelectionSP projection() const
QRect selectedExactRect() const
Slow, but exact way of determining the rectangle that encloses the selection.

References KoColorSpace::applyAlphaNormedFloatMask(), KoColorSpace::applyAlphaU8Mask(), KisImage::bounds(), KisPaintDevice::colorSpace(), KoColor::createTransparent(), KisPaintDevice::crop(), KIS_SAFE_ASSERT_RECOVER_RETURN, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::oldRawData(), KoColorSpace::opacityF(), KisSelection::projection(), KisPaintDevice::purgeDefaultPixels(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), KisSelection::selectedExactRect(), and KisPaintDevice::setDefaultPixel().