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

KDE's Doxygen guidelines are available online.