Krita

Scratchpad.h
1/*
2 * SPDX-FileCopyrightText: 2020 Scott Petrovic <scottpetrovic@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#ifndef LIBKIS_SCRATCHPAD_H
7#define LIBKIS_SCRATCHPAD_H
8
9#include <QObject>
10#include <QColor>
11#include <QWidget>
12
13#include <kis_types.h>
14
15#include "libkis.h"
16#include "View.h"
17
18#include "kritalibkis_export.h"
19
20
21class KoCanvasBase;
22class Canvas; // This comes from Python. This would be maybe better
23class KisView;
24
25/**
26 * @brief The Scratchpad class
27 * A scratchpad is a type of blank canvas area that can be painted on
28 * with the normal painting devices
29 *
30 */
31class KRITALIBKIS_EXPORT Scratchpad: public QWidget
32{
34public:
35 Scratchpad(View *view, const QColor & defaultColor, QWidget *parent = 0);
36 ~Scratchpad();
37
38public Q_SLOTS:
39
40 /**
41 * @brief Clears out scratchpad with color specified set during setup
42 */
43 void clear();
44
45 /**
46 * @brief Fill the entire scratchpad with default color
47 */
48 void fillDefault();
49
50 /**
51 * @brief Fill the entire scratchpad with current gradient
52 * @param gradientVectorStart is a QPoint to define origin of gradient
53 * Set an empty QPoint() to use default scratchpad top-left
54 * @param gradientVectorEnd is a QPoint to define end of gradient
55 * set an empty QPoint() to use default scratchpad bottom-right
56 * @param gradientShape define which gradient to apply, can be:
57 * - "linear"
58 * - "bilinear"
59 * - "radial"
60 * - "square"
61 * - "conical"
62 * - "conicalSymmetric"
63 * - "spiral"
64 * - "reverseSpiral"
65 * - "polygonal"
66 * @param gradientRepeat define how to repeat gradient, can be:
67 * - "none"
68 * - "alternate"
69 * - "forwards"
70 * @param reverseGradient a boolean to define if gradient is reversed or not
71 * @param dither a boolean to define if gradient is dithered or not
72 */
73 void fillGradient(const QPoint &gradientVectorStart = QPoint(),
74 const QPoint &gradientVectorEnd = QPoint(),
75 const QString &gradientShape = "linear",
76 const QString &gradientRepeat = "none",
77 bool reverseGradient = false,
78 bool dither = false);
79
80 /**
81 * @brief Fill the entire scratchpad with current background color
82 */
83 void fillBackground();
84
85 /**
86 * @brief Fill the entire scratchpad with current foreground color
87 */
88 void fillForeground();
89
90 /**
91 * @brief Fill the entire scratchpad with a transparent color
92 */
93 void fillTransparent();
94
95 /**
96 * @brief Fill the entire scratchpad with current document projection content
97 * @param fullContent when True, full document projection is loaded in scratchpad, otherwise only content matching scratchpad viewport is loaded
98 */
99 void fillDocument(bool fullContent = true);
100
101 /**
102 * @brief Fill the entire scratchpad with current layer content
103 * @param fullContent when True, full layer content is loaded in scratchpad, otherwise only content matching scratchpad viewport is loaded
104 */
105 void fillLayer(bool fullContent = true);
106
107 /**
108 * @brief Fill the entire scratchpad with current pattern
109 * @param transform is QTransform that let define pattern scale/rotation property
110 */
111 void fillPattern(QTransform transform = QTransform());
112
113 /**
114 * @brief Define default fill color for scratchpad
115 * @param Color to fill the canvas with
116 */
117 void setFillColor(QColor color);
118
119 /**
120 * @brief Switches between a GUI controlling the current mode and when mouse clicks control mode
121 * @param value Set to True allows GUI to control the mode with explicitly setting mode
122 */
123 void setModeManually(bool value);
124
125 /**
126 * @brief Manually set what mode scratchpad is in. Ignored if "setModeManually is set to false
127 * @param modeName Available options are:
128 * - "painting"
129 * - "panning"
130 * - "colorsampling"
131 */
132 void setMode(QString modeName);
133
134 /**
135 * @brief DEPRECATED -- USE setCanvasZoomLink() instead
136 * Makes a connection between the zoom of the canvas and scratchpad area so they zoom in sync
137 * @param value If True (default) the scratchpad will share the current view zoom level.
138 * If False, then use scratchpad scale methods to define current zoom level
139 */
140 void linkCanvasZoom(bool value);
141
142 /**
143 * @brief return if scratchpad zoom level is linked with current view zoom level
144 * @return return True if connection between the zoom of the canvas and scratchpad (so they zoom in sync) is active
145 */
146 bool canvasZoomLink();
147
148 /**
149 * @brief Makes a connection between the zoom of the canvas and scratchpad area so they zoom in sync
150 * @param value If True (default) the scratchpad will share the current view zoom level.
151 * If False, then use scratchpad scale methods to define current zoom level
152 */
153 void setCanvasZoomLink(bool value);
154
155 /**
156 * @brief return current zoom level applied on scratchpad (whatever the zoom source is: view zoom level or set manually)
157 * @return a float value (1.00 = 100%)
158 */
159 qreal scale();
160
161 /**
162 * @brief allow to manually set scratchpad zoom level
163 * Note: call method is ignored if canvasZoomLink() is True,
164 * @param scale zoom level to apply (1.00 = 100%)
165 * @return if scale has been applied return True, otherwise return False
166 */
167 bool setScale(qreal scale) const;
168
169 /**
170 * @brief calculate scale automatically to fit scratchpad content in scratchpad viewport
171 * Note: call method is ignored if canvasZoomLink() is True
172 */
173 void scaleToFit();
174
175 /**
176 * @brief reset scale and pan to origin
177 * Note: call method is ignored if canvasZoomLink() is True
178 */
179 void scaleReset();
180
181 /**
182 * @brief pan scratchpad content to top-left position of scratchpad viewport
183 * Provided value are absolute
184 * @param x abscissa position to pan to
185 * @param y ordinate position to pan to
186 */
187 void panTo(qint32 x, qint32 y);
188
189 /**
190 * @brief pan scratchpad content to center content in viewport
191 */
192 void panCenter();
193
194 /**
195 * @brief Load image data to the scratchpad
196 * @param image Image object to load
197 */
198 void loadScratchpadImage(QImage image);
199
200 /**
201 * @brief Take what is on the scratchpad area and grab image
202 * @return the image data from the scratchpad
203 */
205
206 /**
207 * @brief The viewport indicates which part of scratchpad content is visible.
208 * It takes in account the current translation & scale
209 *
210 * Example 1:
211 * - Scratchpad size: 500x500
212 * - Scratchpad content: 2000x2000
213 * - Scratchpad scale: 1.0
214 * - Scratchpad pan: 0, 0
215 * Returned viewport is a QRect(0, 0, 500, 500) matching content really visible in scratchpad.
216 * If scale is 2.00, returned viewport will be QRect(0, 0, 250, 250)
217 * If scale is 0.50, returned viewport will be QRect(0, 0, 1000, 1000)
218 *
219 * Example 2:
220 * - Scratchpad size: 500x500
221 * - Scratchpad content: 2000x2000
222 * - Scratchpad scale: 2.0
223 * - Scratchpad pan: 500, 1500
224 * Returned viewport is a QRect(500, 1500, 250, 250) matching content really visible in scratchpad.
225 *
226 * @return scratchpad viewport bounds as a QRect
227 */
228 QRect viewportBounds() const;
229
230 /**
231 * @brief The content of scratchpad can be bigger or smaller than scratchpad dimension.
232 * The bounds return the area in which there's some content
233 * @return scratchpad content bounds as a QRect
234 */
235 QRect contentBounds() const;
236
238 /**
239 * @brief signal is emitted when scratchpad scale is changed (from zoom canvas or manually)
240 * @param scale updated scale value (1.00 = 100%)
241 */
242 void scaleChanged(qreal scale);
243
244 /**
245 * @brief signal is emitted when scratchpad content is changed (stroke or fill)
246 */
248
249 /**
250 * @brief signal is emitted when scratchpad viewport has been modified (pan, zoom)
251 * @param rect new viewport bounds
252 */
254
255private:
256 struct Private;
258
259};
260
261#endif // LIBKIS_SCRATCHPAD_H
262
Canvas wraps the canvas inside a view on an image/document.
Definition Canvas.h:23
void contentChanged()
signal is emitted when scratchpad content is changed (stroke or fill)
void fillBackground()
Fill the entire scratchpad with current background color.
void scaleChanged(qreal scale)
signal is emitted when scratchpad scale is changed (from zoom canvas or manually)
void fillLayer(bool fullContent=true)
Fill the entire scratchpad with current layer content.
void viewportChanged(const QRect rect)
signal is emitted when scratchpad viewport has been modified (pan, zoom)
QRect contentBounds() const
The content of scratchpad can be bigger or smaller than scratchpad dimension.
void fillPattern(QTransform transform=QTransform())
Fill the entire scratchpad with current pattern.
void fillTransparent()
Fill the entire scratchpad with a transparent color.
void panCenter()
pan scratchpad content to center content in viewport
QImage copyScratchpadImageData()
Take what is on the scratchpad area and grab image.
void scaleReset()
reset scale and pan to origin Note: call method is ignored if canvasZoomLink() is True
void setModeManually(bool value)
Switches between a GUI controlling the current mode and when mouse clicks control mode.
qreal scale()
return current zoom level applied on scratchpad (whatever the zoom source is: view zoom level or set ...
void fillDefault()
Fill the entire scratchpad with default color.
void linkCanvasZoom(bool value)
DEPRECATED – USE setCanvasZoomLink() instead Makes a connection between the zoom of the canvas and sc...
void setFillColor(QColor color)
Define default fill color for scratchpad.
void scaleToFit()
calculate scale automatically to fit scratchpad content in scratchpad viewport Note: call method is i...
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 setCanvasZoomLink(bool value)
Makes a connection between the zoom of the canvas and scratchpad area so they zoom in sync.
void panTo(qint32 x, qint32 y)
pan scratchpad content to top-left position of scratchpad viewport Provided value are absolute
QRect viewportBounds() const
The viewport indicates which part of scratchpad content is visible.
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 setMode(QString modeName)
Manually set what mode scratchpad is in.
void clear()
Clears out scratchpad with color specified set during setup.
bool canvasZoomLink()
return if scratchpad zoom level is linked with current view zoom level
bool setScale(qreal scale) const
allow to manually set scratchpad zoom level Note: call method is ignored if canvasZoomLink() is True,
void loadScratchpadImage(QImage image)
Load image data to the scratchpad.
View represents one view on a document.
Definition View.h:25
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
QWidget(QWidget *parent, Qt::WindowFlags f)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 21 2025 11:55:31 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.