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

#include <kis_scratch_pad.h>

+ Inheritance diagram for KisScratchPad:

Public Slots

QImage copyScratchpadImageData ()
 
void fillBackground ()
 
void fillDefault ()
 
void fillDocument ()
 
void fillDocument (bool fullContent)
 
void fillForeground ()
 
void fillGradient ()
 
void fillGradient (const QPoint &gradientVectorStart, const QPoint &gradientVectorEnd, KisGradientPainter::enumGradientShape gradientShape, KisGradientPainter::enumGradientRepeat gradientRepeat, bool reverseGradient, bool dither)
 
void fillLayer (bool fullContent)
 Fill the area with what is on your current canvas.
 
void fillPattern (QTransform transform)
 
void fillTransparent ()
 
void loadScratchpadImage (QImage image)
 
void paintCustomImage (const QImage &loadedImage)
 
void paintPresetImage ()
 
void setFillColor (QColor newColor)
 
void setPresetImage (const QImage &image)
 

Signals

void colorSelected (const KoColor &color)
 
void contentChanged ()
 signal is emitted when scratchpad content is changed (stroke or fill)
 
void scaleChanged (qreal scale)
 signal is emitted when scratchpad scale is changed (from zoom canvas or manually)
 
void sigUpdateCanvas (const QRect &rect)
 
void viewportChanged (const QRect rect)
 signal is emitted when scratchpad viewport has been modified (pan, zoom)
 

Public Member Functions

bool canvasZoomLink ()
 return True if the scratchpad zoom level stay in sync with canvas
 
QRect contentBounds () const
 
QImage cutoutOverlay () const
 return the contents of the area under the cutoutOverlay rect
 
QRect imageBounds () const
 
void imageUpdated (const QRect &rect)
 
 KisScratchPad (QWidget *parent=0)
 
void panCenter ()
 pan scratchpad content to center content in viewport
 
void panTo (qint32 x, qint32 y)
 pan scratchpad content to given position
 
void pointerMove (KoPointerEvent *event)
 
void pointerPress (KoPointerEvent *event)
 
void pointerRelease (KoPointerEvent *event)
 
void resetState ()
 
void scaleReset ()
 reset scale value (to 1.0) and reinit position
 
void scaleToFit ()
 calculate and apply scale to fit content in viewport
 
qreal scaleX ()
 return current scale X applied on scratchpad (whatever the zoom source is - canvas zoom or set manually)
 
qreal scaleY ()
 return current scale Y applied on scratchpad (whatever the zoom source is - canvas zoom or set manually)
 
void setCanvasZoomLink (bool value)
 should the scratchpad zoom level stay in sync with canvas
 
void setCutoutOverlayRect (const QRect &rc)
 set the specified rect as the area taken for
 
void setModeManually (bool value)
 
void setModeType (QString modeName)
 change the mode explicitly to paint, mix, or pan
 
bool setScale (qreal scaleX, qreal scaleY)
 allow to manually set scratchpad scale when NOT linked to canvas zoom
 
void setupScratchPad (KisCanvasResourceProvider *resourceProvider, const QColor &defaultColor)
 
QRect viewportBounds () const
 
void wheelDelta (QWheelEvent *event)
 
 ~KisScratchPad () override
 

Protected Member Functions

void paintEvent (QPaintEvent *event) override
 
void resizeEvent (QResizeEvent *event) override
 

Private Types

enum  Mode { PAINTING , HOVERING , PANNING , SAMPLING }
 

Private Slots

void setOnScreenResolution (qreal scaleX, qreal scaleY)
 
void slotConfigChanged ()
 
void slotScreenChanged (QScreen *screen)
 
void slotUpdateCanvas (const QRect &rect)
 

Private Member Functions

void assignNewSurfaceState (const KisMultiSurfaceStateManager::State &newState)
 
void beginPan (KoPointerEvent *event)
 
void beginStroke (KoPointerEvent *event)
 
QTransform documentToWidget () const
 
void doPan (KoPointerEvent *event)
 
void doStroke (KoPointerEvent *event)
 
void endPan (KoPointerEvent *event)
 
void endStroke (KoPointerEvent *event)
 
Mode modeFromButton (Qt::MouseButton button) const
 
void resetWheelDelta ()
 
void sample (KoPointerEvent *event)
 
bool setScaleImpl (qreal scaleX, qreal scaleY)
 
void updateTransformations ()
 
void updateViewport ()
 
bool updateViewportImpl ()
 
QTransform widgetToDocument () const
 

Private Attributes

bool isModeManuallySet
 
bool isMouseDown
 
friend KisScratchPadEventFilter
 
int m_accumulatedMouseDelta
 
qreal m_canvasScaleX
 
qreal m_canvasScaleY
 
QBrush m_checkBrush
 
QCursor m_colorSamplerCursor
 
QCursor m_cursor
 
QRect m_cutoutOverlay
 
KoColor m_defaultColor
 
KisDisplayConfig m_displayConfig
 
const KoColorProfilem_displayProfile
 
KisScratchPadEventFilterm_eventFilter
 
QScopedPointer< KisToolFreehandHelperm_helper
 
KisPaintingInformationBuilderm_infoBuilder
 
bool m_linkCanvasZoomLevel
 
KisMultiSurfaceStateManager::State m_multiSurfaceState
 
KisMultiSurfaceStateManager m_multiSurfaceStateManager
 
KisNodeGraphListenerm_nodeListener
 
KisPaintLayerSP m_paintLayer
 
QPointF m_panDocPoint
 
QImage m_presetImage
 
KisCanvasResourceProviderm_resourceProvider
 
int m_scaleBorderWidth
 
QTransform m_scaleTransform
 
qreal m_scratchpadScaleX
 
qreal m_scratchpadScaleY
 
QScopedPointer< KisScreenMigrationTrackerm_screenMigrationTracker
 
Mode m_toolMode
 
QTransform m_translateTransform
 
KisPostExecutionUndoAdapterm_undoAdapter
 
KisUndoStorem_undoStore
 
KisUpdateSchedulerm_updateScheduler
 
QRect m_viewport
 

Friends

class KisScratchPadPaintingInformationBuilder
 

Detailed Description

A scratchpad is a painting canvas with only one zoomlevel and based on a paint layer, not on a KisImage. It can have a blank, tiled background or a gradient background.

Definition at line 44 of file kis_scratch_pad.h.

Member Enumeration Documentation

◆ Mode

enum KisScratchPad::Mode
private
Enumerator
PAINTING 
HOVERING 
PANNING 
SAMPLING 

Definition at line 250 of file kis_scratch_pad.h.

Constructor & Destructor Documentation

◆ KisScratchPad()

KisScratchPad::KisScratchPad ( QWidget * parent = 0)

Definition at line 160 of file kis_scratch_pad.cpp.

161 : QWidget(parent)
163 , isModeManuallySet(false)
164 , isMouseDown(false)
166 , m_canvasScaleX(1.0)
167 , m_canvasScaleY(1.0)
168 , m_scratchpadScaleX(1.0)
169 , m_scratchpadScaleY(1.0)
171 , m_paintLayer(0)
173{
174
175 setAutoFillBackground(false);
176 setMouseTracking(true);
177
178 m_cursor = KisCursor::load("tool_freehand_cursor.xpm", 2, 2);
179 m_colorSamplerCursor = KisCursor::load("tool_color_sampler_cursor.xpm", 2, 2);
180 setCursor(m_cursor);
181
182
183 KisConfig cfg(true);
184 QImage checkImage = KisCanvasWidgetBase::createCheckersImage(cfg.checkSize());
185 m_checkBrush = QBrush(checkImage);
186
187
188 // We are not supposed to use updates here,
189 // so just set the listener to null
194
195 connect(this, SIGNAL(sigUpdateCanvas(QRect)), SLOT(slotUpdateCanvas(QRect)), Qt::QueuedConnection);
196
197 // filter will be deleted by the QObject hierarchy
199
201
203
205
208
211
212 QScreen *screen = m_screenMigrationTracker->currentScreenSafe();
213 const int canvasScreenNumber = qApp->screens().indexOf(screen);
214
215#if KRITA_USE_SURFACE_COLOR_MANAGEMENT_API
216 if (KisPlatformPluginInterfaceFactory::instance()->surfaceColorManagedByOS()) {
217 // proxy's lifetime is managed by QObject hierarchy
218 KisRootSurfaceInfoProxy *rootSurfaceInfoProxy = new KisRootSurfaceInfoProxy(this, this);
219 m_multiSurfaceStateManager.setRootSurfaceInfoProxy(rootSurfaceInfoProxy);
220 connect(rootSurfaceInfoProxy,
222 parent,
223 [this] (const KoColorProfile *profile) {
225 assignNewSurfaceState(newState);
226 });
227 }
228#endif
229
230 m_multiSurfaceState = m_multiSurfaceStateManager.createInitializingConfig(false, canvasScreenNumber, nullptr);
231}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static QImage createCheckersImage(qint32 checkSize=-1)
static KisConfigNotifier * instance()
void configChanged(void)
static QCursor load(const QString &cursorName, int hotspotX=-1, int hotspotY=-1)
State createInitializingConfig(bool isCanvasOpenGL, int screenId, KisProofingConfigurationSP proofingConfig) const
State onGuiSurfaceFormatChanged(const State &oldState, const KoColorProfile *uiProfile) const
static KisPlatformPluginInterfaceFactory * instance()
void sigRootSurfaceProfileChanged(const KoColorProfile *profile) const
KisScratchPadEventFilter * m_eventFilter
void sigUpdateCanvas(const QRect &rect)
KisCanvasResourceProvider * m_resourceProvider
KisUndoStore * m_undoStore
KisPaintingInformationBuilder * m_infoBuilder
KisUpdateScheduler * m_updateScheduler
QCursor m_colorSamplerCursor
KisNodeGraphListener * m_nodeListener
void slotUpdateCanvas(const QRect &rect)
KisPaintLayerSP m_paintLayer
KisPostExecutionUndoAdapter * m_undoAdapter
friend class KisScratchPadPaintingInformationBuilder
void slotScreenChanged(QScreen *screen)
void assignNewSurfaceState(const KisMultiSurfaceStateManager::State &newState)
KisMultiSurfaceStateManager m_multiSurfaceStateManager
friend KisScratchPadEventFilter
QScopedPointer< KisScreenMigrationTracker > m_screenMigrationTracker
KisMultiSurfaceStateManager::State m_multiSurfaceState
void sigScreenChanged(QScreen *screen)

References assignNewSurfaceState(), KisConfig::checkSize(), KisConfigNotifier::configChanged(), connect(), KisCanvasWidgetBase::createCheckersImage(), KisMultiSurfaceStateManager::createInitializingConfig(), KisConfigNotifier::instance(), KisPlatformPluginInterfaceFactory::instance(), KisScratchPadEventFilter, KisScratchPadPaintingInformationBuilder, KisCursor::load(), m_checkBrush, m_colorSamplerCursor, m_cursor, m_eventFilter, m_infoBuilder, m_multiSurfaceState, m_multiSurfaceStateManager, m_nodeListener, m_scaleBorderWidth, m_screenMigrationTracker, m_undoAdapter, m_undoStore, m_updateScheduler, KisMultiSurfaceStateManager::onGuiSurfaceFormatChanged(), KisRootSurfaceInfoProxy::sigRootSurfaceProfileChanged(), KisScreenMigrationTracker::sigScreenChanged(), sigUpdateCanvas(), slotConfigChanged(), slotScreenChanged(), and slotUpdateCanvas().

◆ ~KisScratchPad()

KisScratchPad::~KisScratchPad ( )
override

Definition at line 233 of file kis_scratch_pad.cpp.

234{
235 delete m_infoBuilder;
236
237 delete m_undoAdapter;
238 delete m_undoStore;
239 delete m_updateScheduler;
240 delete m_nodeListener;
241}

References m_infoBuilder, m_nodeListener, m_undoAdapter, m_undoStore, and m_updateScheduler.

Member Function Documentation

◆ assignNewSurfaceState()

void KisScratchPad::assignNewSurfaceState ( const KisMultiSurfaceStateManager::State & newState)
private

◆ beginPan()

void KisScratchPad::beginPan ( KoPointerEvent * event)
private

Definition at line 445 of file kis_scratch_pad.cpp.

446{
447 setCursor(QCursor(Qt::ClosedHandCursor));
448 m_panDocPoint = event->point;
449}

References m_panDocPoint.

◆ beginStroke()

void KisScratchPad::beginStroke ( KoPointerEvent * event)
private

Definition at line 419 of file kis_scratch_pad.cpp.

420{
421
422 m_helper->initPaint(event,
423 documentToWidget().map(event->point),
424 0,
425 0,
429
430
431}
KisDefaultBoundsBaseSP defaultBounds() const
QTransform documentToWidget() const
QScopedPointer< KisToolFreehandHelper > m_helper
QPointF point
The point in document coordinates.
KisPaintDeviceSP paintDevice

References KisPaintDevice::defaultBounds(), documentToWidget(), m_helper, m_paintLayer, m_updateScheduler, KisPaintLayer::paintDevice, and KoPointerEvent::point.

◆ canvasZoomLink()

bool KisScratchPad::canvasZoomLink ( )

return True if the scratchpad zoom level stay in sync with canvas

Definition at line 862 of file kis_scratch_pad.cpp.

863{
865}

References m_linkCanvasZoomLevel.

◆ colorSelected

void KisScratchPad::colorSelected ( const KoColor & color)
signal

◆ contentBounds()

QRect KisScratchPad::contentBounds ( ) const

Definition at line 665 of file kis_scratch_pad.cpp.

666{
668
669 // -- DIRTY CODE HERE --
670 // Call of nonDefaultPixelArea() should return expected result but no, not in all case
671 //
672 // Doing
673 // - fillLayer()
674 // - contentBounds() --> return expected QRect() bounds
675 //
676 // Doing
677 // - fillDefault()
678 // - do a stroke
679 // - contentBounds() --> return empty QRect()
680 // - do another stroke
681 // - call contentBounds() --> return expected QRect() bounds of 1st stroke, ignoring 2nd stroke
682 // - do another stroke
683 // - call contentBounds() --> return expected QRect() bounds of 2nd stroke, ignoring 3rd stroke...
684 //
685 // Not sure what happen here and what's the best and cleanest solution to apply
686 // Calling calculateExactBounds/nonDefaultPixelArea multiple times fix the problem, except for 1st stroke
687 // for which an empty QRect() is still returned :-/
688 paintDevice->calculateExactBounds(true);
689 paintDevice->nonDefaultPixelArea();
690 paintDevice->calculateExactBounds(true);
691 paintDevice->nonDefaultPixelArea();
692 paintDevice->calculateExactBounds(true);
693
694 return paintDevice->nonDefaultPixelArea();
695}
QRect nonDefaultPixelArea() const
QRect calculateExactBounds(bool nonDefaultOnly) const

References KisPaintDevice::calculateExactBounds(), m_paintLayer, KisPaintDevice::nonDefaultPixelArea(), and KisPaintLayer::paintDevice.

◆ contentChanged

void KisScratchPad::contentChanged ( )
signal

signal is emitted when scratchpad content is changed (stroke or fill)

◆ copyScratchpadImageData

QImage KisScratchPad::copyScratchpadImageData ( )
slot

Definition at line 945 of file kis_scratch_pad.cpp.

946{
947 const QRect paintingBounds = m_paintLayer.data()->exactBounds();
948 QImage imageData = m_paintLayer->paintDevice()->convertToQImage(0, paintingBounds.x(), paintingBounds.y(), paintingBounds.width(), paintingBounds.height(),
951 return imageData;
952}
QImage convertToQImage(const KoColorProfile *dstProfile, qint32 x, qint32 y, qint32 w, qint32 h, KoColorConversionTransformation::Intent renderingIntent=KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::ConversionFlags conversionFlags=KoColorConversionTransformation::internalConversionFlags()) const
QRect exactBounds() const override

References KisPaintDevice::convertToQImage(), KisSharedPtr< T >::data(), KisPaintLayer::exactBounds(), KoColorConversionTransformation::internalConversionFlags(), KoColorConversionTransformation::internalRenderingIntent(), m_paintLayer, and KisPaintLayer::paintDevice.

◆ cutoutOverlay()

QImage KisScratchPad::cutoutOverlay ( ) const

return the contents of the area under the cutoutOverlay rect

Definition at line 867 of file kis_scratch_pad.cpp.

868{
869 if (!m_paintLayer) return QImage();
871
872
873 QRect rc = widgetToDocument().mapRect(m_cutoutOverlay);
874 QImage rawImage = paintDevice->convertToQImage(0, rc.x(), rc.y(), rc.width(), rc.height(), KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags());
875
876 QImage scaledImage = rawImage.scaled(m_cutoutOverlay.size(),
877 Qt::IgnoreAspectRatio,
878 Qt::SmoothTransformation);
879
880 return scaledImage;
881}
QTransform widgetToDocument() const

References KisPaintDevice::convertToQImage(), KoColorConversionTransformation::internalConversionFlags(), KoColorConversionTransformation::internalRenderingIntent(), m_cutoutOverlay, m_paintLayer, KisPaintLayer::paintDevice, and widgetToDocument().

◆ documentToWidget()

QTransform KisScratchPad::documentToWidget ( ) const
private

Definition at line 621 of file kis_scratch_pad.cpp.

622{
623 return m_translateTransform.inverted() * m_scaleTransform;
624}
QTransform m_scaleTransform
QTransform m_translateTransform

References m_scaleTransform, and m_translateTransform.

◆ doPan()

void KisScratchPad::doPan ( KoPointerEvent * event)
private

Definition at line 451 of file kis_scratch_pad.cpp.

452{
453 QPointF docOffset = event->point - m_panDocPoint;
454
455 m_translateTransform.translate(-docOffset.x(), -docOffset.y());
457 update();
458}

References m_panDocPoint, m_translateTransform, and updateTransformations().

◆ doStroke()

void KisScratchPad::doStroke ( KoPointerEvent * event)
private

Definition at line 433 of file kis_scratch_pad.cpp.

434{
435 m_helper->paintEvent(event);
436}

References m_helper.

◆ endPan()

void KisScratchPad::endPan ( KoPointerEvent * event)
private

Definition at line 460 of file kis_scratch_pad.cpp.

461{
462 Q_UNUSED(event);
463
464 // the normal brush editor scratchpad reverts back to paint mode when done
465 if (isModeManuallySet) {
466 setCursor(QCursor(Qt::OpenHandCursor));
467 } else {
468 setCursor(m_cursor);
469 }
471}

References isModeManuallySet, m_cursor, and updateViewport().

◆ endStroke()

void KisScratchPad::endStroke ( KoPointerEvent * event)
private

Definition at line 438 of file kis_scratch_pad.cpp.

439{
440 Q_UNUSED(event);
441 m_helper->endPaint();
442 Q_EMIT contentChanged();
443}
void contentChanged()
signal is emitted when scratchpad content is changed (stroke or fill)

References contentChanged(), and m_helper.

◆ fillBackground

void KisScratchPad::fillBackground ( )
slot

Definition at line 1126 of file kis_scratch_pad.cpp.

1127{
1128 if (!m_paintLayer) return;
1129 KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice();
1130
1131 {
1132 KisUpdateSchedulerLockWithFeedback l(m_updateScheduler);
1133 KisTransaction t(paintDevice);
1135 paintDevice->clear();
1136 t.end();
1137 }
1138
1139 update();
1140 Q_EMIT contentChanged();
1141}
virtual void clear()
void setDefaultPixel(const KoColor &defPixel)

References KisCanvasResourceProvider::bgColor(), KisPaintDevice::clear(), contentChanged(), KisTransaction::end(), m_paintLayer, m_resourceProvider, m_updateScheduler, KisPaintLayer::paintDevice, and KisPaintDevice::setDefaultPixel().

◆ fillDefault

void KisScratchPad::fillDefault ( )
slot

Definition at line 989 of file kis_scratch_pad.cpp.

990{
991 if (!m_paintLayer) return;
993
994 {
995 KisUpdateSchedulerLockWithFeedback l(m_updateScheduler);
996
997 KisTransaction t(paintDevice);
998 paintDevice->setDefaultPixel(m_defaultColor);
999 paintDevice->clear();
1000 t.end();
1001 }
1002
1003 update();
1004 Q_EMIT contentChanged();
1005}

References KisPaintDevice::clear(), contentChanged(), KisTransaction::end(), m_defaultColor, m_paintLayer, m_updateScheduler, KisPaintLayer::paintDevice, and KisPaintDevice::setDefaultPixel().

◆ fillDocument [1/2]

void KisScratchPad::fillDocument ( )
slot

Definition at line 1186 of file kis_scratch_pad.cpp.

1187{
1188 if (!m_paintLayer) return;
1189 fillDocument(false);
1190}

References fillDocument(), and m_paintLayer.

◆ fillDocument [2/2]

void KisScratchPad::fillDocument ( bool fullContent)
slot

Definition at line 1160 of file kis_scratch_pad.cpp.

1161{
1162 QRect sourceRect;
1163
1164 if (!m_paintLayer) return;
1165
1166 KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice();
1167
1168 if (fullContent) {
1169 sourceRect = QRect(0, 0, m_resourceProvider->currentImage()->width(), m_resourceProvider->currentImage()->height());
1170 } else {
1171 sourceRect = QRect(0, 0, paintDevice->exactBounds().width(), paintDevice->exactBounds().height());
1172 }
1173
1174 {
1175 KisUpdateSchedulerLockWithFeedback l(m_updateScheduler);
1176 KisPainter painter(paintDevice);
1177 painter.beginTransaction();
1178 painter.bitBlt(QPoint(0, 0), m_resourceProvider->currentImage()->projection(), sourceRect);
1179 painter.deleteTransaction();
1180 }
1181
1182 update();
1183 Q_EMIT contentChanged();
1184}
KisPaintDeviceSP projection() const
qint32 width() const
qint32 height() const
QRect exactBounds() const

References KisPainter::beginTransaction(), KisPainter::bitBlt(), contentChanged(), KisCanvasResourceProvider::currentImage(), KisPainter::deleteTransaction(), KisPaintDevice::exactBounds(), KisImage::height(), m_paintLayer, m_resourceProvider, m_updateScheduler, KisPaintLayer::paintDevice, KisImage::projection(), and KisImage::width().

◆ fillForeground

void KisScratchPad::fillForeground ( )
slot

Definition at line 1143 of file kis_scratch_pad.cpp.

1144{
1145 if (!m_paintLayer) return;
1146 KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice();
1147
1148 {
1149 KisUpdateSchedulerLockWithFeedback l(m_updateScheduler);
1150 KisTransaction t(paintDevice);
1152 paintDevice->clear();
1153 t.end();
1154 }
1155
1156 update();
1157 Q_EMIT contentChanged();
1158}

References KisPaintDevice::clear(), contentChanged(), KisTransaction::end(), KisCanvasResourceProvider::fgColor(), m_paintLayer, m_resourceProvider, m_updateScheduler, KisPaintLayer::paintDevice, and KisPaintDevice::setDefaultPixel().

◆ fillGradient [1/2]

void KisScratchPad::fillGradient ( )
slot

Definition at line 1084 of file kis_scratch_pad.cpp.

1085{
1086 // default legacy method
1087 if (!m_paintLayer) return;
1088 QRect gradientRect = widgetToDocument().mapRect(rect());
1089 fillGradient(gradientRect.topLeft(),
1090 gradientRect.bottomRight(),
1093 false,
1094 false
1095 );
1096}

References fillGradient(), KisGradientPainter::GradientRepeatNone, KisGradientPainter::GradientShapeLinear, m_paintLayer, and widgetToDocument().

◆ fillGradient [2/2]

void KisScratchPad::fillGradient ( const QPoint & gradientVectorStart,
const QPoint & gradientVectorEnd,
KisGradientPainter::enumGradientShape gradientShape,
KisGradientPainter::enumGradientRepeat gradientRepeat,
bool reverseGradient,
bool dither )
slot

Definition at line 1034 of file kis_scratch_pad.cpp.

1040{
1041 if (!m_paintLayer) return;
1042 KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice();
1043
1045 QRect gradientRect = widgetToDocument().mapRect(rect());
1046
1047
1048 {
1049 KisUpdateSchedulerLockWithFeedback l(m_updateScheduler);
1050 KisTransaction t(paintDevice);
1051
1052 paintDevice->clear();
1053
1054 KisGradientPainter painter(paintDevice);
1055 painter.setGradient(gradient);
1056 painter.setGradientShape(gradientShape);
1057 if (gradientVectorStart == gradientVectorEnd && gradientVectorStart == QPoint()) {
1058 // start & end are the same and are at origin: use default rect
1059 painter.paintGradient(gradientRect.topLeft(),
1060 gradientRect.bottomRight(),
1061 gradientRepeat,
1062 0.2,
1063 reverseGradient,
1064 gradientRect.left(), gradientRect.top(),
1065 gradientRect.width(), gradientRect.height(),
1066 dither);
1067 } else {
1068 painter.paintGradient(gradientVectorStart,
1069 gradientVectorEnd,
1070 gradientRepeat,
1071 0.2,
1072 reverseGradient,
1073 gradientRect.left(), gradientRect.top(),
1074 gradientRect.width(), gradientRect.height(),
1075 dither);
1076 }
1077 t.end();
1078 }
1079
1080 update();
1081 Q_EMIT contentChanged();
1082}
KoAbstractGradientSP currentGradient() const

References KisPaintDevice::clear(), contentChanged(), KisCanvasResourceProvider::currentGradient(), KisTransaction::end(), m_paintLayer, m_resourceProvider, m_updateScheduler, KisPaintLayer::paintDevice, KisGradientPainter::paintGradient(), KisPainter::setGradient(), KisGradientPainter::setGradientShape(), and widgetToDocument().

◆ fillLayer

void KisScratchPad::fillLayer ( bool fullContent)
slot

Fill the area with what is on your current canvas.

Definition at line 1192 of file kis_scratch_pad.cpp.

1193{
1194 QRect sourceRect;
1195
1196 if (!m_paintLayer) return;
1197
1198 KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice();
1199
1200 if (fullContent) {
1201 sourceRect = m_resourceProvider->currentNode()->exactBounds();
1202 } else {
1203 sourceRect = QRect(0, 0, paintDevice->exactBounds().width(), paintDevice->exactBounds().height());
1204 }
1205
1206 {
1207 KisUpdateSchedulerLockWithFeedback l(m_updateScheduler);
1208 KisPainter painter(paintDevice);
1209 painter.beginTransaction();
1210 painter.bitBlt(QPoint(0, 0), m_resourceProvider->currentNode()->projection(), sourceRect);
1211 painter.deleteTransaction();
1212 }
1213
1214 update();
1215 Q_EMIT contentChanged();
1216}
virtual KisPaintDeviceSP projection() const =0
virtual QRect exactBounds() const

References KisPainter::beginTransaction(), KisPainter::bitBlt(), contentChanged(), KisCanvasResourceProvider::currentNode(), KisPainter::deleteTransaction(), KisBaseNode::exactBounds(), KisPaintDevice::exactBounds(), m_paintLayer, m_resourceProvider, m_updateScheduler, KisPaintLayer::paintDevice, and KisBaseNode::projection().

◆ fillPattern

void KisScratchPad::fillPattern ( QTransform transform)
slot

Definition at line 1098 of file kis_scratch_pad.cpp.

1099{
1100 if (!m_paintLayer) return;
1101 KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice();
1102
1104
1105 QRect patternRect = widgetToDocument().mapRect(rect());
1106 {
1107 KisUpdateSchedulerLockWithFeedback l(m_updateScheduler);
1108
1109 KisTransaction t(paintDevice);
1110
1111 paintDevice->clear();
1112
1113 KisFillPainter painter(paintDevice);
1114 painter.setPattern(pattern);
1115 painter.setWidth(patternRect.width());
1116 painter.setHeight(patternRect.height());
1117 painter.fillPattern(0, 0, paintDevice, transform);
1118
1119 t.end();
1120 }
1121
1122 update();
1123 Q_EMIT contentChanged();
1124}

References KisPaintDevice::clear(), contentChanged(), KisCanvasResourceProvider::currentPattern(), KisTransaction::end(), KisFillPainter::fillPattern(), m_paintLayer, m_resourceProvider, m_updateScheduler, KisPaintLayer::paintDevice, KisFillPainter::setHeight(), KisPainter::setPattern(), KisFillPainter::setWidth(), and widgetToDocument().

◆ fillTransparent

void KisScratchPad::fillTransparent ( )
slot

Definition at line 1007 of file kis_scratch_pad.cpp.

1008{
1009 if (!m_paintLayer) return;
1010 KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice();
1011
1012 QColor transQColor(0,0,0,0);
1013 KoColor transparentColor(transQColor, KoColorSpaceRegistry::instance()->rgb8());
1014 transparentColor.setOpacity(0.0);
1015
1016 {
1017 KisUpdateSchedulerLockWithFeedback l(m_updateScheduler);
1018
1019 KisTransaction t(paintDevice);
1020 paintDevice->setDefaultPixel(transparentColor);
1021 paintDevice->clear();
1022 t.end();
1023 }
1024
1025 update();
1026 Q_EMIT contentChanged();
1027}
static KoColorSpaceRegistry * instance()

References KisPaintDevice::clear(), contentChanged(), KisTransaction::end(), KoColorSpaceRegistry::instance(), m_paintLayer, m_updateScheduler, KisPaintLayer::paintDevice, KisPaintDevice::setDefaultPixel(), and KoColor::setOpacity().

◆ imageBounds()

QRect KisScratchPad::imageBounds ( ) const

Definition at line 636 of file kis_scratch_pad.cpp.

637{
638 return rect();
639}

◆ imageUpdated()

void KisScratchPad::imageUpdated ( const QRect & rect)

Definition at line 697 of file kis_scratch_pad.cpp.

698{
699 Q_EMIT sigUpdateCanvas(documentToWidget().mapRect(QRectF(rect)).toAlignedRect());
700}

References documentToWidget(), and sigUpdateCanvas().

◆ loadScratchpadImage

void KisScratchPad::loadScratchpadImage ( QImage image)
slot

Definition at line 919 of file kis_scratch_pad.cpp.

920{
921 if (!m_paintLayer) return;
922
923 m_translateTransform.reset(); // image will be loaded at 0,0, so reset panning location
925
926 fillDefault(); // wipes out whatever was there before
927
928 QRect imageSize = image.rect();
930
931 KisPaintDeviceSP device = new KisPaintDevice(paintDevice->colorSpace());
932 device->convertFromQImage(image, 0);
933
934 {
935 KisUpdateSchedulerLockWithFeedback l(m_updateScheduler);
936 KisPainter painter(paintDevice);
937 painter.beginTransaction();
938 painter.bitBlt(imageSize.topLeft(), device, imageSize);
939 painter.deleteTransaction();
940 }
941
942 update();
943}
const KoColorSpace * colorSpace() const
void convertFromQImage(const QImage &image, const KoColorProfile *profile, qint32 offsetX=0, qint32 offsetY=0)

References KisPainter::beginTransaction(), KisPainter::bitBlt(), KisPaintDevice::colorSpace(), KisPaintDevice::convertFromQImage(), KisPainter::deleteTransaction(), fillDefault(), m_paintLayer, m_translateTransform, m_updateScheduler, KisPaintLayer::paintDevice, and updateTransformations().

◆ modeFromButton()

KisScratchPad::Mode KisScratchPad::modeFromButton ( Qt::MouseButton button) const
private

Definition at line 243 of file kis_scratch_pad.cpp.

244{
245 return
246 button == Qt::NoButton ? HOVERING :
247 button == Qt::MiddleButton ? PANNING :
248 button == Qt::RightButton ? SAMPLING :
249 PAINTING;
250}
QString button(const QWheelEvent &ev)

References button(), HOVERING, PAINTING, PANNING, and SAMPLING.

◆ paintCustomImage

void KisScratchPad::paintCustomImage ( const QImage & loadedImage)
slot

Paint the icon of a custom image that is being loaded

Definition at line 888 of file kis_scratch_pad.cpp.

889{
890 // this is 99% copied from the normal paintPresetImage()
891 // we don't want to save over the preset image, so we don't
892 // want to store it in the m_presetImage
893 if (!m_paintLayer) return;
895
896
897 QRect overlayRect = widgetToDocument().mapRect(m_cutoutOverlay);
898 QRect imageRect(QPoint(), overlayRect.size());
899
900 QImage scaledImage = loadedImage.scaled(overlayRect.size(),
901 Qt::IgnoreAspectRatio,
902 Qt::SmoothTransformation);
903 KisPaintDeviceSP device = new KisPaintDevice(paintDevice->colorSpace());
904 device->convertFromQImage(scaledImage, 0);
905
906 {
907 KisUpdateSchedulerLockWithFeedback l(m_updateScheduler);
908 KisPainter painter(paintDevice);
909 painter.beginTransaction();
910 painter.bitBlt(overlayRect.topLeft(), device, imageRect);
911 painter.deleteTransaction();
912 }
913
914
915 update();
916 Q_EMIT contentChanged();
917}

References KisPainter::beginTransaction(), KisPainter::bitBlt(), KisPaintDevice::colorSpace(), contentChanged(), KisPaintDevice::convertFromQImage(), KisPainter::deleteTransaction(), m_cutoutOverlay, m_paintLayer, m_updateScheduler, KisPaintLayer::paintDevice, and widgetToDocument().

◆ paintEvent()

void KisScratchPad::paintEvent ( QPaintEvent * event)
overrideprotected

Definition at line 733 of file kis_scratch_pad.cpp.

733 {
734 if (!m_paintLayer) return;
735
736 QRectF imageRect = widgetToDocument().mapRect(QRectF(event->rect()));
737
738 QRect alignedImageRect =
739 imageRect.adjusted(-m_scaleBorderWidth, -m_scaleBorderWidth,
740 m_scaleBorderWidth, m_scaleBorderWidth).toAlignedRect();
741
742 QPointF offset = alignedImageRect.topLeft();
743
744 m_paintLayer->projectionPlane()->recalculate(alignedImageRect, m_paintLayer, KisRenderPassFlag::None);
746
747 QImage image = projection->convertToQImage(m_displayConfig.profile,
748 alignedImageRect.x(),
749 alignedImageRect.y(),
750 alignedImageRect.width(),
751 alignedImageRect.height(),
754
755
756 QPainter gc(this);
757 gc.fillRect(event->rect(), m_checkBrush);
758
759 // if we scale down, it should use Smooth
760 // if we scale up, it should use Fast (nearest Neighbour) to show pixels
761 if (event->rect().width() < image.rect().width()) {
762 gc.setRenderHints(QPainter::SmoothPixmapTransform, true);
763 } else {
764 gc.setRenderHints(QPainter::SmoothPixmapTransform, false); // that will use NN
765 }
766
767 gc.drawImage(QRectF(event->rect()), image, imageRect.translated(-offset));
768
769 QBrush brush(Qt::lightGray);
770 QPen pen(brush, 1, Qt::DotLine);
771 gc.setPen(pen);
772 if (m_cutoutOverlay.isValid()) {
773 gc.drawRect(m_cutoutOverlay);
774 }
775
776 if (!isEnabled()) {
777 QColor color(Qt::lightGray);
778 color.setAlphaF(0.5);
779 QBrush disabledBrush(color);
780 gc.fillRect(event->rect(), disabledBrush);
781 }
782 gc.end();
783}
KoColorConversionTransformation::ConversionFlags conversionFlags
const KoColorProfile * profile
KoColorConversionTransformation::Intent intent
KisPaintDeviceSP projection() const override
Definition kis_layer.cc:820
KisLayerProjectionPlaneSP projectionPlane
Definition kis_layer.cc:174

References KisDisplayConfig::conversionFlags, KisPaintDevice::convertToQImage(), KisDisplayConfig::intent, m_checkBrush, m_cutoutOverlay, m_displayConfig, m_paintLayer, m_scaleBorderWidth, None, KisDisplayConfig::profile, KisLayer::projection(), KisLayer::projectionPlane, and widgetToDocument().

◆ paintPresetImage

void KisScratchPad::paintPresetImage ( )
slot

Paint the icon of the current preset inside the cutout overlay

See also
setPresetImage

Definition at line 954 of file kis_scratch_pad.cpp.

955{
956 if (!m_paintLayer) return;
958
959
960 QRect overlayRect = widgetToDocument().mapRect(m_cutoutOverlay);
961 QRect imageRect(QPoint(), overlayRect.size());
962
963 QImage scaledImage = m_presetImage.scaled(overlayRect.size(),
964 Qt::IgnoreAspectRatio,
965 Qt::SmoothTransformation);
966 KisPaintDeviceSP device = new KisPaintDevice(paintDevice->colorSpace());
967 device->convertFromQImage(scaledImage, 0);
968
969 {
970 KisUpdateSchedulerLockWithFeedback l(m_updateScheduler);
971 KisPainter painter(paintDevice);
972 painter.beginTransaction();
973 painter.bitBlt(overlayRect.topLeft(), device, imageRect);
974 painter.deleteTransaction();
975 }
976
977 update();
978 Q_EMIT contentChanged();
979}

References KisPainter::beginTransaction(), KisPainter::bitBlt(), KisPaintDevice::colorSpace(), contentChanged(), KisPaintDevice::convertFromQImage(), KisPainter::deleteTransaction(), m_cutoutOverlay, m_paintLayer, m_presetImage, m_updateScheduler, KisPaintLayer::paintDevice, and widgetToDocument().

◆ panCenter()

void KisScratchPad::panCenter ( )

pan scratchpad content to center content in viewport

Definition at line 610 of file kis_scratch_pad.cpp.

610 {
612
613 QPointF viewportF = QPointF(viewportBounds().width(), viewportBounds().height());
614 QRectF contentsF = QRectF(contentBounds());
615
616 QPoint panPosition = QPointF( contentsF.center() - viewportF/2 ).toPoint() ;
617
618 panTo(panPosition.x(), panPosition.y());
619}
void panTo(qint32 x, qint32 y)
pan scratchpad content to given position
QRect viewportBounds() const
QRect contentBounds() const

References contentBounds(), panTo(), updateViewportImpl(), and viewportBounds().

◆ panTo()

void KisScratchPad::panTo ( qint32 x,
qint32 y )

pan scratchpad content to given position

Parameters
xabsissa position to pan to
yordinate position to pan to

Definition at line 602 of file kis_scratch_pad.cpp.

602 {
603 m_translateTransform.reset();
604 m_translateTransform.translate(x, y);
606 update();
608}

References m_translateTransform, updateTransformations(), and updateViewport().

◆ pointerMove()

void KisScratchPad::pointerMove ( KoPointerEvent * event)

Definition at line 396 of file kis_scratch_pad.cpp.

397{
398 if (!isEnabled()) return;
400
401 if (event->point.isNull() == false) {
402 m_helper->cursorMoved(documentToWidget().map(event->point));
403 }
404
405 if (isMouseDown) {
406 if (m_toolMode == PAINTING) {
407 doStroke(event);
408 event->accept();
409 } else if (m_toolMode == PANNING) {
410 doPan(event);
411 event->accept();
412 } else if (m_toolMode == SAMPLING) {
413 sample(event);
414 event->accept();
415 }
416 }
417}
void doStroke(KoPointerEvent *event)
void sample(KoPointerEvent *event)
void doPan(KoPointerEvent *event)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References documentToWidget(), doPan(), doStroke(), isMouseDown, KIS_SAFE_ASSERT_RECOVER_RETURN, m_helper, m_toolMode, PAINTING, PANNING, KoPointerEvent::point, sample(), and SAMPLING.

◆ pointerPress()

void KisScratchPad::pointerPress ( KoPointerEvent * event)

Definition at line 332 of file kis_scratch_pad.cpp.

333{
334 if (!isEnabled()) return;
335
336 if (isModeManuallySet == false) {
337 m_toolMode = modeFromButton(event->button());
338 }
339
340 // see if we are pressing down with a button
341 if (event->button() == Qt::LeftButton ||
342 event->button() == Qt::MiddleButton ||
343 event->button() == Qt::RightButton) {
344 isMouseDown = true;
345 } else {
346 isMouseDown = false;
347 }
348
349 // if mouse is down, we are doing one of three things
350 if (isMouseDown) {
351 if (m_toolMode == PAINTING) {
352 beginStroke(event);
353 event->accept();
354 } else if (m_toolMode == PANNING) {
355 beginPan(event);
356 event->accept();
357 } else if (m_toolMode == SAMPLING) {
358 sample(event);
359 event->accept();
360 }
361 }
362}
void beginStroke(KoPointerEvent *event)
Mode modeFromButton(Qt::MouseButton button) const
void beginPan(KoPointerEvent *event)
Qt::MouseButton button() const
return button pressed (see QMouseEvent::button());

References beginPan(), beginStroke(), KoPointerEvent::button(), isModeManuallySet, isMouseDown, m_toolMode, modeFromButton(), PAINTING, PANNING, sample(), and SAMPLING.

◆ pointerRelease()

void KisScratchPad::pointerRelease ( KoPointerEvent * event)

Definition at line 364 of file kis_scratch_pad.cpp.

365{
366 if (!isEnabled()) return;
367 isMouseDown = false;
368
369 if (isModeManuallySet == false) {
370 if (modeFromButton(event->button()) != m_toolMode) return;
371
372 if (m_toolMode == PAINTING) {
373 endStroke(event);
375 event->accept();
376 } else if (m_toolMode == PANNING) {
377 endPan(event);
379 event->accept();
380 } else if (m_toolMode == SAMPLING) {
381 event->accept();
383 }
384
385 } else {
386 if (m_toolMode == PAINTING) {
387 endStroke(event);
388 } else if (m_toolMode == PANNING) {
389 endPan(event);
390 }
391
392 event->accept();
393 }
394}
void endStroke(KoPointerEvent *event)
void endPan(KoPointerEvent *event)

References KoPointerEvent::button(), endPan(), endStroke(), HOVERING, isModeManuallySet, isMouseDown, m_toolMode, modeFromButton(), PAINTING, PANNING, and SAMPLING.

◆ resetState()

void KisScratchPad::resetState ( )

Definition at line 790 of file kis_scratch_pad.cpp.

791{
792 if (m_helper->isRunning()) {
793 m_helper->endPaint();
794 }
795
797 setCursor(m_cursor);
798}

References HOVERING, m_cursor, m_helper, and m_toolMode.

◆ resetWheelDelta()

void KisScratchPad::resetWheelDelta ( )
private

Definition at line 550 of file kis_scratch_pad.cpp.

551{
553}

References m_accumulatedMouseDelta.

◆ resizeEvent()

void KisScratchPad::resizeEvent ( QResizeEvent * event)
overrideprotected

Definition at line 785 of file kis_scratch_pad.cpp.

785 {
787 QWidget::resizeEvent(event);
788}

References updateViewport().

◆ sample()

void KisScratchPad::sample ( KoPointerEvent * event)
private

Definition at line 473 of file kis_scratch_pad.cpp.

474{
475 KoColor color;
476 if (KisToolUtils::sampleColor(color, m_paintLayer->projection(), event->point.toPoint())) {
477 Q_EMIT colorSelected(color);
478 }
479}
void colorSelected(const KoColor &color)
bool sampleColor(KoColor &out_color, KisPaintDeviceSP dev, const QPoint &pos, KoColor const *const blendColor, int radius, int blend, bool pure)

References colorSelected(), m_paintLayer, KoPointerEvent::point, KisLayer::projection(), and KisToolUtils::sampleColor().

◆ scaleChanged

void KisScratchPad::scaleChanged ( qreal scale)
signal

signal is emitted when scratchpad scale is changed (from zoom canvas or manually)

Parameters
scaleupdated scale value

◆ scaleReset()

void KisScratchPad::scaleReset ( )

reset scale value (to 1.0) and reinit position

Definition at line 591 of file kis_scratch_pad.cpp.

591 {
592 // developer must ensure zoom level is not linked with canvas zoom level before
593 // calling this method
595
596 if (setScaleImpl(1.0, 1.0)) {
598 }
599 panTo(0, 0);
600}
bool setScaleImpl(qreal scaleX, qreal scaleY)
void scaleChanged(qreal scale)
signal is emitted when scratchpad scale is changed (from zoom canvas or manually)

References KIS_SAFE_ASSERT_RECOVER_RETURN, m_linkCanvasZoomLevel, m_scratchpadScaleX, panTo(), scaleChanged(), and setScaleImpl().

◆ scaleToFit()

void KisScratchPad::scaleToFit ( )

calculate and apply scale to fit content in viewport

Definition at line 565 of file kis_scratch_pad.cpp.

565 {
566 // developer must ensure zoom level is not linked with canvas zoom level before
567 // calling this method
569
570 QRectF viewportF = QRectF(imageBounds());
571 QRectF contentsF = QRectF(contentBounds());
572 qreal scale;
573
574 if (contentsF.isEmpty() || viewportF.isEmpty()) return;
575
576 qreal contentRatio = contentsF.width() / contentsF.height();
577 qreal viewportRatio = viewportF.width() / viewportF.height();
578
579 if (viewportRatio > contentRatio) {
580 scale = viewportF.height() / contentsF.height();
581 } else {
582 scale = viewportF.width() / contentsF.width();
583 }
584
585 if (setScaleImpl(scale, scale)) {
587 }
588 panCenter();
589}
QRect imageBounds() const
void panCenter()
pan scratchpad content to center content in viewport

References contentBounds(), imageBounds(), KIS_SAFE_ASSERT_RECOVER_RETURN, m_linkCanvasZoomLevel, m_scratchpadScaleX, panCenter(), scaleChanged(), and setScaleImpl().

◆ scaleX()

qreal KisScratchPad::scaleX ( )

return current scale X applied on scratchpad (whatever the zoom source is - canvas zoom or set manually)

Definition at line 555 of file kis_scratch_pad.cpp.

556{
557 return m_scratchpadScaleX;
558}

References m_scratchpadScaleX.

◆ scaleY()

qreal KisScratchPad::scaleY ( )

return current scale Y applied on scratchpad (whatever the zoom source is - canvas zoom or set manually)

Definition at line 560 of file kis_scratch_pad.cpp.

561{
562 return m_scratchpadScaleY;
563}

References m_scratchpadScaleY.

◆ setCanvasZoomLink()

void KisScratchPad::setCanvasZoomLink ( bool value)

should the scratchpad zoom level stay in sync with canvas

Parameters
shouldwe link zoom level

Definition at line 848 of file kis_scratch_pad.cpp.

849{
853
855 // link status updated AND set to True
856 // Then need to update scratchPad zoom to canvas zoom immediately
858 }
859 }
860}
float value(const T *src, size_t ch)
void setOnScreenResolution(qreal scaleX, qreal scaleY)

References m_accumulatedMouseDelta, m_canvasScaleX, m_canvasScaleY, m_linkCanvasZoomLevel, setOnScreenResolution(), and value().

◆ setCutoutOverlayRect()

void KisScratchPad::setCutoutOverlayRect ( const QRect & rc)

set the specified rect as the area taken for

See also
cutoutOverlay

Definition at line 824 of file kis_scratch_pad.cpp.

825{
826 m_cutoutOverlay = rc;
827}

References m_cutoutOverlay.

◆ setFillColor

void KisScratchPad::setFillColor ( QColor newColor)
slot

Definition at line 1029 of file kis_scratch_pad.cpp.

1030{
1032}

References KoColorSpaceRegistry::instance(), and m_defaultColor.

◆ setModeManually()

void KisScratchPad::setModeManually ( bool value)

keep track of if our scratchpad is in paint, pan, or color sample mode Set to true if there is a GUI controlling current mode If this is false, the modes are only changed with various mouse click shortcuts

Definition at line 829 of file kis_scratch_pad.cpp.

830{
832}

References isModeManuallySet, and value().

◆ setModeType()

void KisScratchPad::setModeType ( QString modeName)

change the mode explicitly to paint, mix, or pan

Parameters
whatmode to change it to

Definition at line 834 of file kis_scratch_pad.cpp.

835{
836 if (mode.toLower() == "painting") {
838 setCursor(m_cursor);
839 } else if (mode.toLower() == "panning") {
841 setCursor(Qt::OpenHandCursor);
842 } else if (mode.toLower() == "colorsampling") {
844 setCursor(m_colorSamplerCursor);
845 }
846}

References m_colorSamplerCursor, m_cursor, m_toolMode, PAINTING, PANNING, and SAMPLING.

◆ setOnScreenResolution

void KisScratchPad::setOnScreenResolution ( qreal scaleX,
qreal scaleY )
privateslot

Definition at line 481 of file kis_scratch_pad.cpp.

482{
483 // This method is called only when canvas zoom is changed (sigOnScreenResolutionChanged) AND scratchPad is
484 // linked to it
485 //
486 // Otherwise do nothing
487 // If zoom on scratchPad has to be updated, then it has to be updated manually through setScale() method
488
489 // value not changed? do nothing
491
492 // always keep in memory canvas zoom, even if link is not active
495
496 // the scratchpad will use the canvas zoom level...or not
499
500 // memorize current scratchPad scale
503
504 m_scaleTransform = QTransform::fromScale(scaleX, scaleY);
506 update();
507
510 }
511}
qreal scaleY()
return current scale Y applied on scratchpad (whatever the zoom source is - canvas zoom or set manual...
qreal scaleX()
return current scale X applied on scratchpad (whatever the zoom source is - canvas zoom or set manual...
static bool qFuzzyCompare(half p1, half p2)
#define BORDER_SIZE(scale)

References BORDER_SIZE, m_canvasScaleX, m_canvasScaleY, m_linkCanvasZoomLevel, m_scaleBorderWidth, m_scaleTransform, m_scratchpadScaleX, m_scratchpadScaleY, qFuzzyCompare(), scaleChanged(), scaleX(), scaleY(), updateTransformations(), and updateViewport().

◆ setPresetImage

void KisScratchPad::setPresetImage ( const QImage & image)
slot

Set the icon of the current preset

Definition at line 883 of file kis_scratch_pad.cpp.

884{
885 m_presetImage = image;
886}

References m_presetImage.

◆ setScale()

bool KisScratchPad::setScale ( qreal scaleX,
qreal scaleY )

allow to manually set scratchpad scale when NOT linked to canvas zoom

Parameters
scaleXzoom level for X
scaleYzoom level for Y
Returns
if scale is applied, return true otherwise false

Definition at line 513 of file kis_scratch_pad.cpp.

514{
515 const bool retval = setScaleImpl(scaleX, scaleY);
516
517 if (retval) {
520 }
521
522 return retval;
523}

References m_scratchpadScaleX, scaleChanged(), scaleX(), scaleY(), setScaleImpl(), and updateViewport().

◆ setScaleImpl()

bool KisScratchPad::setScaleImpl ( qreal scaleX,
qreal scaleY )
private

Definition at line 525 of file kis_scratch_pad.cpp.

526{
527 // developer must ensure zoom level is not linked with canvas zoom level before
528 // calling this method
530
531 scaleX = qBound(0.05, scaleX, 16.0);
532 scaleY = qBound(0.05, scaleY, 16.0);
533
534 // value not changed? do nothing and return false
535 if (scaleX == m_scratchpadScaleX && scaleY == m_scratchpadScaleY) return false;
536
538
539 // memorize current scratchPad scale
542
545 update();
546
547 return true;
548}
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References BORDER_SIZE, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, m_linkCanvasZoomLevel, m_scaleBorderWidth, m_scaleTransform, m_scratchpadScaleX, m_scratchpadScaleY, scaleX(), scaleY(), and updateTransformations().

◆ setupScratchPad()

void KisScratchPad::setupScratchPad ( KisCanvasResourceProvider * resourceProvider,
const QColor & defaultColor )

Definition at line 800 of file kis_scratch_pad.cpp.

802{
803 m_resourceProvider = resourceProvider;
804
805 connect(m_resourceProvider, SIGNAL(sigOnScreenResolutionChanged(qreal,qreal)),
806 SLOT(setOnScreenResolution(qreal,qreal)));
807 connect(this, SIGNAL(colorSelected(KoColor)),
808 m_resourceProvider, SLOT(slotSetFGColor(KoColor)));
809
811
812 setFillColor(defaultColor);
813
814 KisPaintDeviceSP paintDevice =
815 new KisPaintDevice(m_defaultColor.colorSpace(), "scratchpad");
816
817 m_paintLayer = new KisPaintLayer(0, "ScratchPad", OPACITY_OPAQUE_U8, paintDevice);
820
821 fillDefault();
822}
const quint8 OPACITY_OPAQUE_U8
KoCanvasResourceProvider * resourceManager()
void setDefaultBounds(KisDefaultBoundsBaseSP bounds)
void setFillColor(QColor newColor)
const KoColorSpace * colorSpace() const
return the current colorSpace
Definition KoColor.h:82
void setGraphListener(KisNodeGraphListener *graphListener)
Definition kis_node.cpp:289

References colorSelected(), KoColor::colorSpace(), connect(), fillDefault(), m_defaultColor, m_helper, m_infoBuilder, m_nodeListener, m_paintLayer, m_resourceProvider, OPACITY_OPAQUE_U8, KisPaintLayer::paintDevice, KisCanvasResourceProvider::resourceManager(), KisPaintDevice::setDefaultBounds(), setFillColor(), KisNode::setGraphListener(), and setOnScreenResolution().

◆ sigUpdateCanvas

void KisScratchPad::sigUpdateCanvas ( const QRect & rect)
signal

◆ slotConfigChanged

void KisScratchPad::slotConfigChanged ( )
privateslot

Definition at line 717 of file kis_scratch_pad.cpp.

718{
720
721 KisConfig cfg(true);
722
723 QScreen *screen = m_screenMigrationTracker->currentScreenSafe();
724 const int screenId = qApp->screens().indexOf(screen);
725
727 screenId,
728 cfg.canvasSurfaceColorSpaceManagementMode(),
730 assignNewSurfaceState(newState);
731}
static Options optionsFromKisConfig(const KisConfig &cfg)
State onConfigChanged(const State &oldState, int screenId, KisConfig::CanvasSurfaceMode surfaceMode, const KisDisplayConfig::Options &options) const

References assignNewSurfaceState(), KisConfig::canvasSurfaceColorSpaceManagementMode(), KIS_SAFE_ASSERT_RECOVER_RETURN, m_multiSurfaceState, m_multiSurfaceStateManager, m_screenMigrationTracker, KisMultiSurfaceStateManager::onConfigChanged(), and KisDisplayConfig::optionsFromKisConfig().

◆ slotScreenChanged

void KisScratchPad::slotScreenChanged ( QScreen * screen)
privateslot

Definition at line 981 of file kis_scratch_pad.cpp.

982{
983 const int screenId = qApp->screens().indexOf(screen);
984
986 assignNewSurfaceState(newState);
987}
State onScreenChanged(const State &oldState, int screenId) const

References assignNewSurfaceState(), m_multiSurfaceState, m_multiSurfaceStateManager, and KisMultiSurfaceStateManager::onScreenChanged().

◆ slotUpdateCanvas

void KisScratchPad::slotUpdateCanvas ( const QRect & rect)
privateslot

Definition at line 702 of file kis_scratch_pad.cpp.

703{
704 update(rect);
705}

◆ updateTransformations()

void KisScratchPad::updateTransformations ( )
private

◆ updateViewport()

void KisScratchPad::updateViewport ( )
private

Definition at line 646 of file kis_scratch_pad.cpp.

647{
648 if (updateViewportImpl()) {
650 }
651}
void viewportChanged(const QRect rect)
signal is emitted when scratchpad viewport has been modified (pan, zoom)

References m_viewport, updateViewportImpl(), and viewportChanged().

◆ updateViewportImpl()

bool KisScratchPad::updateViewportImpl ( )
private

Definition at line 653 of file kis_scratch_pad.cpp.

654{
655 const QRect viewport = widgetToDocument().mapRect(rect());
656
657 if (viewport != m_viewport) {
658 m_viewport = viewport;
659 return true;
660 }
661 return false;
662}

References m_viewport, and widgetToDocument().

◆ viewportBounds()

QRect KisScratchPad::viewportBounds ( ) const

Definition at line 641 of file kis_scratch_pad.cpp.

642{
643 return m_viewport;
644}

References m_viewport.

◆ viewportChanged

void KisScratchPad::viewportChanged ( const QRect rect)
signal

signal is emitted when scratchpad viewport has been modified (pan, zoom)

Parameters
rectnew viewport bounds

◆ wheelDelta()

void KisScratchPad::wheelDelta ( QWheelEvent * event)

Definition at line 252 of file kis_scratch_pad.cpp.

253{
254 // if linked to canvas zoom level, ignore wheel event scale
255 if (!isEnabled() || m_linkCanvasZoomLevel) return;
256
257 const int angleDelta = event->angleDelta().y();
258
259#ifdef Q_OS_MACOS
260 // --> from KisInputManager::eventFilterImpl()
261
262 // Some QT wheel events are actually touch pad pan events. From the QT docs:
263 // "Wheel events are generated for both mouse wheels and trackpad scroll gestures."
264 // We differentiate between touchpad events and real mouse wheels by inspecting the
265 // event source.
266 if (event->source() == Qt::MouseEventSource::MouseEventSynthesizedBySystem) {
267 return;
268 }
269
274 if (angleDelta == 0) {
275 return;
276 }
277#endif
278
279 m_accumulatedMouseDelta += angleDelta;
280
283
284 // cursor position on widget
285 QPointF position = event->position();
286 // matching cursor position in document (taking in account scale + translate)
287 QPointF docPosition = widgetToDocument().map(position);
288
289 // loop manage case where angleDelta is greater than one mouse wheel tick
290 // and allows to refresh zoom smoothly in this case
291 // if angleDelta = 360, 360/120 = 3, then scale will be refreshed 3 times
292 // m_accumulatedMouseDelta allow to manage the case where angleDelta in not equal QWheelEvent::DefaultDeltasPerStep
293 while (qAbs(m_accumulatedMouseDelta) >= QWheelEvent::DefaultDeltasPerStep) {
294 if (m_accumulatedMouseDelta > 0) {
295 qreal scaleFactor = 0.5;
296 if (scaleX < 1) scaleFactor = 0.05;
297 // zoom In
298 scaleX += scaleFactor;
299 scaleY += scaleFactor;
300 } else {
301 qreal scaleFactor = 0.5;
302 if (scaleX <= 1) scaleFactor = 0.05;
303 // zoom out
304 scaleX -= scaleFactor;
305 scaleY -= scaleFactor;
306 }
307
308 // update zoom level
309 if (!setScaleImpl(scaleX, scaleY)) {
310 // if can't apply zoom level, reset accumulated delta and exit, no need to try
311 // to continue
313 break;
314 }
315
317
318 // cursor position after scale
319 QPointF offsetPosition = QPointF(position.x() / m_scratchpadScaleX, position.y() / m_scratchpadScaleY);
320
321 // new position after scale is applied
322 //
323 QPoint panPosition = QPointF( docPosition - offsetPosition).toPoint();
324
325 // pan to ensure zoomed point is always under cursor
326 panTo(panPosition.x(), panPosition.y());
327
328 m_accumulatedMouseDelta -= KisAlgebra2D::signPZ(m_accumulatedMouseDelta) * QWheelEvent::DefaultDeltasPerStep;
329 }
330}

References m_accumulatedMouseDelta, m_linkCanvasZoomLevel, m_scratchpadScaleX, m_scratchpadScaleY, panTo(), scaleChanged(), scaleX(), scaleY(), setScaleImpl(), KisAlgebra2D::signPZ(), and widgetToDocument().

◆ widgetToDocument()

QTransform KisScratchPad::widgetToDocument ( ) const
private

Definition at line 626 of file kis_scratch_pad.cpp.

627{
628 return m_scaleTransform.inverted() * m_translateTransform;
629}

References m_scaleTransform, and m_translateTransform.

Friends And Related Symbol Documentation

◆ KisScratchPadPaintingInformationBuilder

Definition at line 242 of file kis_scratch_pad.h.

Member Data Documentation

◆ isModeManuallySet

bool KisScratchPad::isModeManuallySet
private

Definition at line 263 of file kis_scratch_pad.h.

◆ isMouseDown

bool KisScratchPad::isMouseDown
private

Definition at line 264 of file kis_scratch_pad.h.

◆ KisScratchPadEventFilter

friend KisScratchPad::KisScratchPadEventFilter
private

Definition at line 245 of file kis_scratch_pad.h.

◆ m_accumulatedMouseDelta

int KisScratchPad::m_accumulatedMouseDelta
private

Definition at line 276 of file kis_scratch_pad.h.

◆ m_canvasScaleX

qreal KisScratchPad::m_canvasScaleX
private

Definition at line 268 of file kis_scratch_pad.h.

◆ m_canvasScaleY

qreal KisScratchPad::m_canvasScaleY
private

Definition at line 269 of file kis_scratch_pad.h.

◆ m_checkBrush

QBrush KisScratchPad::m_checkBrush
private

Definition at line 287 of file kis_scratch_pad.h.

◆ m_colorSamplerCursor

QCursor KisScratchPad::m_colorSamplerCursor
private

Definition at line 285 of file kis_scratch_pad.h.

◆ m_cursor

QCursor KisScratchPad::m_cursor
private

Definition at line 284 of file kis_scratch_pad.h.

◆ m_cutoutOverlay

QRect KisScratchPad::m_cutoutOverlay
private

Definition at line 286 of file kis_scratch_pad.h.

◆ m_defaultColor

KoColor KisScratchPad::m_defaultColor
private

Definition at line 261 of file kis_scratch_pad.h.

◆ m_displayConfig

KisDisplayConfig KisScratchPad::m_displayConfig
private

Definition at line 283 of file kis_scratch_pad.h.

◆ m_displayProfile

const KoColorProfile* KisScratchPad::m_displayProfile
private

Definition at line 282 of file kis_scratch_pad.h.

◆ m_eventFilter

KisScratchPadEventFilter* KisScratchPad::m_eventFilter
private

Definition at line 294 of file kis_scratch_pad.h.

◆ m_helper

QScopedPointer<KisToolFreehandHelper> KisScratchPad::m_helper
private

Definition at line 296 of file kis_scratch_pad.h.

◆ m_infoBuilder

KisPaintingInformationBuilder* KisScratchPad::m_infoBuilder
private

Definition at line 297 of file kis_scratch_pad.h.

◆ m_linkCanvasZoomLevel

bool KisScratchPad::m_linkCanvasZoomLevel
private

Definition at line 265 of file kis_scratch_pad.h.

◆ m_multiSurfaceState

KisMultiSurfaceStateManager::State KisScratchPad::m_multiSurfaceState
private

Definition at line 308 of file kis_scratch_pad.h.

◆ m_multiSurfaceStateManager

KisMultiSurfaceStateManager KisScratchPad::m_multiSurfaceStateManager
private

Definition at line 307 of file kis_scratch_pad.h.

◆ m_nodeListener

KisNodeGraphListener* KisScratchPad::m_nodeListener
private

Definition at line 293 of file kis_scratch_pad.h.

◆ m_paintLayer

KisPaintLayerSP KisScratchPad::m_paintLayer
private

Definition at line 281 of file kis_scratch_pad.h.

◆ m_panDocPoint

QPointF KisScratchPad::m_panDocPoint
private

Definition at line 302 of file kis_scratch_pad.h.

◆ m_presetImage

QImage KisScratchPad::m_presetImage
private

Definition at line 305 of file kis_scratch_pad.h.

◆ m_resourceProvider

KisCanvasResourceProvider* KisScratchPad::m_resourceProvider
private

Definition at line 288 of file kis_scratch_pad.h.

◆ m_scaleBorderWidth

int KisScratchPad::m_scaleBorderWidth
private

Definition at line 303 of file kis_scratch_pad.h.

◆ m_scaleTransform

QTransform KisScratchPad::m_scaleTransform
private

Definition at line 299 of file kis_scratch_pad.h.

◆ m_scratchpadScaleX

qreal KisScratchPad::m_scratchpadScaleX
private

Definition at line 272 of file kis_scratch_pad.h.

◆ m_scratchpadScaleY

qreal KisScratchPad::m_scratchpadScaleY
private

Definition at line 273 of file kis_scratch_pad.h.

◆ m_screenMigrationTracker

QScopedPointer<KisScreenMigrationTracker> KisScratchPad::m_screenMigrationTracker
private

Definition at line 306 of file kis_scratch_pad.h.

◆ m_toolMode

Mode KisScratchPad::m_toolMode
private

Definition at line 262 of file kis_scratch_pad.h.

◆ m_translateTransform

QTransform KisScratchPad::m_translateTransform
private

Definition at line 300 of file kis_scratch_pad.h.

◆ m_undoAdapter

KisPostExecutionUndoAdapter* KisScratchPad::m_undoAdapter
private

Definition at line 292 of file kis_scratch_pad.h.

◆ m_undoStore

KisUndoStore* KisScratchPad::m_undoStore
private

Definition at line 291 of file kis_scratch_pad.h.

◆ m_updateScheduler

KisUpdateScheduler* KisScratchPad::m_updateScheduler
private

Definition at line 290 of file kis_scratch_pad.h.

◆ m_viewport

QRect KisScratchPad::m_viewport
private

Definition at line 279 of file kis_scratch_pad.h.


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