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

The Scratchpad class A scratchpad is a type of blank canvas area that can be painted on with the normal painting devices. More...

#include <Scratchpad.h>

+ Inheritance diagram for Scratchpad:

Classes

struct  Private
 

Public Slots

bool canvasZoomLink ()
 return if scratchpad zoom level is linked with current view zoom level
 
void clear ()
 Clears out scratchpad with color specified set during setup.
 
QRect contentBounds () const
 The content of scratchpad can be bigger or smaller than scratchpad dimension. The bounds return the area in which there's some content.
 
QImage copyScratchpadImageData ()
 Take what is on the scratchpad area and grab image.
 
void fillBackground ()
 Fill the entire scratchpad with current background color.
 
void fillDefault ()
 Fill the entire scratchpad with default color.
 
void fillDocument (bool fullContent=true)
 Fill the entire scratchpad with current document projection content.
 
void fillForeground ()
 Fill the entire scratchpad with current foreground color.
 
void fillGradient (const QPoint &gradientVectorStart=QPoint(), const QPoint &gradientVectorEnd=QPoint(), const QString &gradientShape="linear", const QString &gradientRepeat="none", bool reverseGradient=false, bool dither=false)
 Fill the entire scratchpad with current gradient.
 
void fillLayer (bool fullContent=true)
 Fill the entire scratchpad with current layer content.
 
void fillPattern (QTransform transform=QTransform())
 Fill the entire scratchpad with current pattern.
 
void fillTransparent ()
 Fill the entire scratchpad with a transparent color.
 
void linkCanvasZoom (bool value)
 DEPRECATED – USE setCanvasZoomLink() instead Makes a connection between the zoom of the canvas and scratchpad area so they zoom in sync.
 
void loadScratchpadImage (QImage image)
 Load image data to the scratchpad.
 
void panCenter ()
 pan scratchpad content to center content in viewport
 
void panTo (qint32 x, qint32 y)
 pan scratchpad content to top-left position of scratchpad viewport Provided value are absolute
 
qreal scale ()
 return current zoom level applied on scratchpad (whatever the zoom source is: view zoom level or set manually)
 
void scaleReset ()
 reset scale and pan to origin Note: call method is ignored if canvasZoomLink() is True
 
void scaleToFit ()
 calculate scale automatically to fit scratchpad content in scratchpad viewport Note: call method is ignored if canvasZoomLink() is True
 
void setCanvasZoomLink (bool value)
 Makes a connection between the zoom of the canvas and scratchpad area so they zoom in sync.
 
void setFillColor (QColor color)
 Define default fill color for scratchpad.
 
void setMode (QString modeName)
 Manually set what mode scratchpad is in. Ignored if "setModeManually is set to false.
 
void setModeManually (bool value)
 Switches between a GUI controlling the current mode and when mouse clicks control mode.
 
bool setScale (qreal scale) const
 allow to manually set scratchpad zoom level Note: call method is ignored if canvasZoomLink() is True,
 
QRect viewportBounds () const
 The viewport indicates which part of scratchpad content is visible. It takes in account the current translation & scale.
 

Signals

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 viewportChanged (const QRect rect)
 signal is emitted when scratchpad viewport has been modified (pan, zoom)
 

Public Member Functions

 Scratchpad (View *view, const QColor &defaultColor, QWidget *parent=0)
 
 ~Scratchpad ()
 

Private Attributes

const QScopedPointer< Privated
 

Detailed Description

The Scratchpad class A scratchpad is a type of blank canvas area that can be painted on with the normal painting devices.

Definition at line 31 of file Scratchpad.h.

Constructor & Destructor Documentation

◆ Scratchpad()

Scratchpad::Scratchpad ( View * view,
const QColor & defaultColor,
QWidget * parent = 0 )

Definition at line 28 of file Scratchpad.cpp.

29 : QWidget(parent), d(new Private)
30{
31 d->scratchpad = new KisScratchPad();
32 d->scratchpad->setupScratchPad(view->view()->resourceProvider(), defaultColor);
33 d->scratchpad->setMinimumSize(50, 50);
34
35 QVBoxLayout *layout = new QVBoxLayout(this);
36 layout->addWidget(d->scratchpad);
37
38 // Forward KisScratchPad::scaleChanged to Scratchpad::scaleChanged
39 connect(d->scratchpad, SIGNAL(scaleChanged(qreal)), this, SIGNAL(scaleChanged(qreal)));
40
41 // Forward KisScratchPad::contentChanged to Scratchpad::contentChanged
42 connect(d->scratchpad, SIGNAL(contentChanged()), this, SIGNAL(contentChanged()));
43
44 // Forward KisScratchPad::viewportChanged to Scratchpad::viewportChanged
45 connect(d->scratchpad, SIGNAL(viewportChanged(const QRect)), this, SIGNAL(viewportChanged(const QRect)));
46}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisCanvasResourceProvider * resourceProvider() const
Definition KisView.cpp:414
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 viewportChanged(const QRect rect)
signal is emitted when scratchpad viewport has been modified (pan, zoom)
const QScopedPointer< Private > d
Definition Scratchpad.h:257
KisView * view()
Definition View.cpp:103

References connect(), contentChanged(), d, KisView::resourceProvider(), scaleChanged(), View::view(), and viewportChanged().

◆ ~Scratchpad()

Scratchpad::~Scratchpad ( )

Definition at line 48 of file Scratchpad.cpp.

49{
50}

Member Function Documentation

◆ canvasZoomLink

bool Scratchpad::canvasZoomLink ( )
slot

return if scratchpad zoom level is linked with current view zoom level

Returns
return True if connection between the zoom of the canvas and scratchpad (so they zoom in sync) is active

Definition at line 73 of file Scratchpad.cpp.

74{
75 return d->scratchpad->canvasZoomLink();
76}

References d.

◆ clear

void Scratchpad::clear ( )
slot

Clears out scratchpad with color specified set during setup.

Definition at line 131 of file Scratchpad.cpp.

132{
133 // need ability to set color
134 d->scratchpad->fillDefault();
135}

References d.

◆ contentBounds

QRect Scratchpad::contentBounds ( ) const
slot

The content of scratchpad can be bigger or smaller than scratchpad dimension. The bounds return the area in which there's some content.

Returns
scratchpad content bounds as a QRect

Definition at line 222 of file Scratchpad.cpp.

223{
224 return d->scratchpad->contentBounds();
225}

References d.

◆ contentChanged

void Scratchpad::contentChanged ( )
signal

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

◆ copyScratchpadImageData

QImage Scratchpad::copyScratchpadImageData ( )
slot

Take what is on the scratchpad area and grab image.

Returns
the image data from the scratchpad

Definition at line 126 of file Scratchpad.cpp.

127{
128 return d->scratchpad->copyScratchpadImageData();
129}

References d.

◆ fillBackground

void Scratchpad::fillBackground ( )
slot

Fill the entire scratchpad with current background color.

Definition at line 152 of file Scratchpad.cpp.

153{
154 d->scratchpad->fillBackground();
155}

References d.

◆ fillDefault

void Scratchpad::fillDefault ( )
slot

Fill the entire scratchpad with default color.

Definition at line 142 of file Scratchpad.cpp.

143{
144 d->scratchpad->fillDefault();
145}

References d.

◆ fillDocument

void Scratchpad::fillDocument ( bool fullContent = true)
slot

Fill the entire scratchpad with current document projection content.

Parameters
fullContentwhen True, full document projection is loaded in scratchpad, otherwise only content matching scratchpad viewport is loaded

Definition at line 207 of file Scratchpad.cpp.

208{
209 d->scratchpad->fillDocument(fullContent);
210}

References d.

◆ fillForeground

void Scratchpad::fillForeground ( )
slot

Fill the entire scratchpad with current foreground color.

Definition at line 157 of file Scratchpad.cpp.

158{
159 d->scratchpad->fillForeground();
160}

References d.

◆ fillGradient

void Scratchpad::fillGradient ( const QPoint & gradientVectorStart = QPoint(),
const QPoint & gradientVectorEnd = QPoint(),
const QString & gradientShape = "linear",
const QString & gradientRepeat = "none",
bool reverseGradient = false,
bool dither = false )
slot

Fill the entire scratchpad with current gradient.

Parameters
gradientVectorStartis a QPoint to define origin of gradient Set an empty QPoint() to use default scratchpad top-left
gradientVectorEndis a QPoint to define end of gradient set an empty QPoint() to use default scratchpad bottom-right
gradientShapedefine which gradient to apply, can be:
  • "linear"
  • "bilinear"
  • "radial"
  • "square"
  • "conical"
  • "conicalSymmetric"
  • "spiral"
  • "reverseSpiral"
  • "polygonal"
gradientRepeatdefine how to repeat gradient, can be:
  • "none"
  • "alternate"
  • "forwards"
reverseGradienta boolean to define if gradient is reversed or not
dithera boolean to define if gradient is dithered or not

Definition at line 162 of file Scratchpad.cpp.

168{
171
172 if (gradientShape != "linear") {
173 if (gradientShape == "bilinear") {
175 } else if ( gradientShape == "radial") {
176 gradientShapeValue = KisGradientPainter::GradientShapeRadial;
177 } else if ( gradientShape == "square") {
178 gradientShapeValue = KisGradientPainter::GradientShapeSquare;
179 } else if ( gradientShape == "conical") {
180 gradientShapeValue = KisGradientPainter::GradientShapeConical;
181 } else if ( gradientShape == "conicalSymmetric") {
183 } else if ( gradientShape == "spiral") {
184 gradientShapeValue = KisGradientPainter::GradientShapeSpiral;
185 } else if ( gradientShape == "reverseSpiral") {
187 } else if ( gradientShape == "polygonal") {
189 }
190 }
191
192 if (gradientRepeat != "none") {
193 if (gradientRepeat == "alternate") {
195 } else if (gradientRepeat == "forwards") {
196 gradientRepeatValue = KisGradientPainter::GradientRepeatForwards;
197 }
198 }
199 d->scratchpad->fillGradient(gradientVectorStart, gradientVectorEnd, gradientShapeValue, gradientRepeatValue, reverseGradient, dither);
200}

References d, KisGradientPainter::GradientRepeatAlternate, KisGradientPainter::GradientRepeatForwards, KisGradientPainter::GradientRepeatNone, KisGradientPainter::GradientShapeBiLinear, KisGradientPainter::GradientShapeConical, KisGradientPainter::GradientShapeConicalSymetric, KisGradientPainter::GradientShapeLinear, KisGradientPainter::GradientShapePolygonal, KisGradientPainter::GradientShapeRadial, KisGradientPainter::GradientShapeReverseSpiral, KisGradientPainter::GradientShapeSpiral, and KisGradientPainter::GradientShapeSquare.

◆ fillLayer

void Scratchpad::fillLayer ( bool fullContent = true)
slot

Fill the entire scratchpad with current layer content.

Parameters
fullContentwhen True, full layer content is loaded in scratchpad, otherwise only content matching scratchpad viewport is loaded

Definition at line 202 of file Scratchpad.cpp.

203{
204 d->scratchpad->fillLayer(fullContent);
205}

References d.

◆ fillPattern

void Scratchpad::fillPattern ( QTransform transform = QTransform())
slot

Fill the entire scratchpad with current pattern.

Parameters
transformis QTransform that let define pattern scale/rotation property

Definition at line 212 of file Scratchpad.cpp.

213{
214 d->scratchpad->fillPattern(transform);
215}

References d.

◆ fillTransparent

void Scratchpad::fillTransparent ( )
slot

Fill the entire scratchpad with a transparent color.

Definition at line 147 of file Scratchpad.cpp.

148{
149 d->scratchpad->fillTransparent();
150}

References d.

◆ linkCanvasZoom

void Scratchpad::linkCanvasZoom ( bool value)
slot

DEPRECATED – USE setCanvasZoomLink() instead Makes a connection between the zoom of the canvas and scratchpad area so they zoom in sync.

Parameters
valueIf True (default) the scratchpad will share the current view zoom level. If False, then use scratchpad scale methods to define current zoom level

Definition at line 62 of file Scratchpad.cpp.

63{
64 qWarning("[DEPRECATED] Use Scratchpad.setCanvasZoomLink() instead of Scratchpad.linkCanvasZoom()");
65 d->scratchpad->setCanvasZoomLink(value);
66}
float value(const T *src, size_t ch)

References d, and value().

◆ loadScratchpadImage

void Scratchpad::loadScratchpadImage ( QImage image)
slot

Load image data to the scratchpad.

Parameters
imageImage object to load

Definition at line 121 of file Scratchpad.cpp.

122{
123 d->scratchpad->loadScratchpadImage(image);
124}

References d.

◆ panCenter

void Scratchpad::panCenter ( )
slot

pan scratchpad content to center content in viewport

Definition at line 116 of file Scratchpad.cpp.

117{
118 d->scratchpad->panCenter();
119}

References d.

◆ panTo

void Scratchpad::panTo ( qint32 x,
qint32 y )
slot

pan scratchpad content to top-left position of scratchpad viewport Provided value are absolute

Parameters
xabscissa position to pan to
yordinate position to pan to

Definition at line 111 of file Scratchpad.cpp.

112{
113 d->scratchpad->panTo(x, y);
114}

References d.

◆ scale

qreal Scratchpad::scale ( )
slot

return current zoom level applied on scratchpad (whatever the zoom source is: view zoom level or set manually)

Returns
a float value (1.00 = 100%)

Definition at line 78 of file Scratchpad.cpp.

79{
80 // return scale X only, consider zoom X/Y will always be the same
81 return d->scratchpad->scaleX();
82}

References d.

◆ scaleChanged

void Scratchpad::scaleChanged ( qreal scale)
signal

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

Parameters
scaleupdated scale value (1.00 = 100%)

◆ scaleReset

void Scratchpad::scaleReset ( )
slot

reset scale and pan to origin Note: call method is ignored if canvasZoomLink() is True

Definition at line 102 of file Scratchpad.cpp.

103{
104 if (d->scratchpad->canvasZoomLink()) {
105 // if zoom level is linked to canvas zoom level, ignore setScale()
106 return;
107 };
108 d->scratchpad->scaleReset();
109}

References d.

◆ scaleToFit

void Scratchpad::scaleToFit ( )
slot

calculate scale automatically to fit scratchpad content in scratchpad viewport Note: call method is ignored if canvasZoomLink() is True

Definition at line 93 of file Scratchpad.cpp.

94{
95 if (d->scratchpad->canvasZoomLink()) {
96 // if zoom level is linked to canvas zoom level, ignore setScale()
97 return;
98 };
99 d->scratchpad->scaleToFit();
100}

References d.

◆ setCanvasZoomLink

void Scratchpad::setCanvasZoomLink ( bool value)
slot

Makes a connection between the zoom of the canvas and scratchpad area so they zoom in sync.

Parameters
valueIf True (default) the scratchpad will share the current view zoom level. If False, then use scratchpad scale methods to define current zoom level

Definition at line 68 of file Scratchpad.cpp.

69{
70 d->scratchpad->setCanvasZoomLink(value);
71}

References d, and value().

◆ setFillColor

void Scratchpad::setFillColor ( QColor color)
slot

Define default fill color for scratchpad.

Parameters
Colorto fill the canvas with

Definition at line 137 of file Scratchpad.cpp.

138{
139 d->scratchpad->setFillColor(color);
140}

References d.

◆ setMode

void Scratchpad::setMode ( QString modeName)
slot

Manually set what mode scratchpad is in. Ignored if "setModeManually is set to false.

Parameters
modeNameAvailable options are:
  • "painting"
  • "panning"
  • "colorsampling"

Definition at line 57 of file Scratchpad.cpp.

58{
59 d->scratchpad->setModeType(modeType);
60}

References d.

◆ setModeManually

void Scratchpad::setModeManually ( bool value)
slot

Switches between a GUI controlling the current mode and when mouse clicks control mode.

Parameters
valueSet to True allows GUI to control the mode with explicitly setting mode

Definition at line 52 of file Scratchpad.cpp.

53{
54 d->scratchpad->setModeManually(value);
55}

References d, and value().

◆ setScale

bool Scratchpad::setScale ( qreal scale) const
slot

allow to manually set scratchpad zoom level Note: call method is ignored if canvasZoomLink() is True,

Parameters
scalezoom level to apply (1.00 = 100%)
Returns
if scale has been applied return True, otherwise return False

Definition at line 84 of file Scratchpad.cpp.

85{
86 if (d->scratchpad->canvasZoomLink()) {
87 // if zoom level is linked to canvas zoom level, ignore setScale()
88 return false;
89 };
90 return d->scratchpad->setScale(scale, scale);
91}
qreal scale()
return current zoom level applied on scratchpad (whatever the zoom source is: view zoom level or set ...

References d, and scale().

◆ viewportBounds

QRect Scratchpad::viewportBounds ( ) const
slot

The viewport indicates which part of scratchpad content is visible. It takes in account the current translation & scale.

Example 1:

  • Scratchpad size: 500x500
  • Scratchpad content: 2000x2000
  • Scratchpad scale: 1.0
  • Scratchpad pan: 0, 0 Returned viewport is a QRect(0, 0, 500, 500) matching content really visible in scratchpad. If scale is 2.00, returned viewport will be QRect(0, 0, 250, 250) If scale is 0.50, returned viewport will be QRect(0, 0, 1000, 1000)

Example 2:

  • Scratchpad size: 500x500
  • Scratchpad content: 2000x2000
  • Scratchpad scale: 2.0
  • Scratchpad pan: 500, 1500 Returned viewport is a QRect(500, 1500, 250, 250) matching content really visible in scratchpad.
Returns
scratchpad viewport bounds as a QRect

Definition at line 217 of file Scratchpad.cpp.

218{
219 return d->scratchpad->imageBounds();
220}

References d.

◆ viewportChanged

void Scratchpad::viewportChanged ( const QRect rect)
signal

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

Parameters
rectnew viewport bounds

Member Data Documentation

◆ d

const QScopedPointer<Private> Scratchpad::d
private

Definition at line 257 of file Scratchpad.h.


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