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

KDE's Doxygen guidelines are available online.