Krita

Scratchpad.cpp
1/*
2 * SPDX-FileCopyrightText: 2020 Scott Petrovic <scottpetrovic@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#include "Scratchpad.h"
7#include <KoResource.h>
8#include <kis_config.h>
9#include <kis_gradient_painter.h>
10#include "kis_scratch_pad.h"
11#include "Resource.h"
12#include "View.h"
13#include "Canvas.h"
14#include <KoCanvasBase.h>
15#include <kis_canvas2.h>
16
17#include <QColor>
18#include <QVBoxLayout>
19
20
21struct Scratchpad::Private
22{
23 KisScratchPad *scratchpad = 0;
24};
25
26
27Scratchpad::Scratchpad(View *view, const QColor & defaultColor, QWidget *parent)
28 : QWidget(parent), d(new Private)
29{
30 d->scratchpad = new KisScratchPad();
31 d->scratchpad->setupScratchPad(view->view()->resourceProvider(), defaultColor);
32 d->scratchpad->setMinimumSize(50, 50);
33
34 QVBoxLayout *layout = new QVBoxLayout(this);
35 layout->addWidget(d->scratchpad);
36
37 // Forward KisScratchPad::scaleChanged to Scratchpad::scaleChanged
38 connect(d->scratchpad, SIGNAL(scaleChanged(qreal)), this, SIGNAL(scaleChanged(qreal)));
39
40 // Forward KisScratchPad::contentChanged to Scratchpad::contentChanged
41 connect(d->scratchpad, SIGNAL(contentChanged()), this, SIGNAL(contentChanged()));
42
43 // Forward KisScratchPad::viewportChanged to Scratchpad::viewportChanged
44 connect(d->scratchpad, SIGNAL(viewportChanged(const QRect)), this, SIGNAL(viewportChanged(const QRect)));
45}
46
47Scratchpad::~Scratchpad()
48{
49}
50
52{
53 d->scratchpad->setModeManually(value);
54}
55
57{
58 d->scratchpad->setModeType(modeType);
59}
60
62{
63 qWarning("[DEPRECATED] Use Scratchpad.setCanvasZoomLink() instead of Scratchpad.linkCanvasZoom()");
64 d->scratchpad->setCanvasZoomLink(value);
65}
66
68{
69 d->scratchpad->setCanvasZoomLink(value);
70}
71
73{
74 return d->scratchpad->canvasZoomLink();
75}
76
78{
79 // return scale X only, consider zoom X/Y will alway be the same
80 return d->scratchpad->scaleX();
81}
82
83bool Scratchpad::setScale(qreal scale) const
84{
85 if (d->scratchpad->canvasZoomLink()) {
86 // if zoom level is linked to canvas zoom level, ignore setScale()
87 return false;
88 };
89 return d->scratchpad->setScale(scale, scale);
90}
91
93{
94 if (d->scratchpad->canvasZoomLink()) {
95 // if zoom level is linked to canvas zoom level, ignore setScale()
96 return;
97 };
98 d->scratchpad->scaleToFit();
99}
100
102{
103 if (d->scratchpad->canvasZoomLink()) {
104 // if zoom level is linked to canvas zoom level, ignore setScale()
105 return;
106 };
107 d->scratchpad->scaleReset();
108}
109
110void Scratchpad::panTo(qint32 x, qint32 y)
111{
112 d->scratchpad->panTo(x, y);
113}
114
116{
117 d->scratchpad->panCenter();
118}
119
121{
122 d->scratchpad->loadScratchpadImage(image);
123}
124
126{
127 return d->scratchpad->copyScratchpadImageData();
128}
129
131{
132 // need ability to set color
133 d->scratchpad->fillDefault();
134}
135
137{
138 d->scratchpad->setFillColor(color);
139}
140
142{
143 d->scratchpad->fillDefault();
144}
145
147{
148 d->scratchpad->fillTransparent();
149}
150
152{
153 d->scratchpad->fillBackground();
154}
155
157{
158 d->scratchpad->fillForeground();
159}
160
161void Scratchpad::fillGradient(const QPoint &gradientVectorStart,
162 const QPoint &gradientVectorEnd,
163 const QString &gradientShape,
164 const QString &gradientRepeat,
165 bool reverseGradient,
166 bool dither)
167{
168 KisGradientPainter::enumGradientShape gradientShapeValue = KisGradientPainter::GradientShapeLinear;
169 KisGradientPainter::enumGradientRepeat gradientRepeatValue = KisGradientPainter::GradientRepeatNone;
170
171 if (gradientShape != "linear") {
172 if (gradientShape == "bilinear") {
173 gradientShapeValue = KisGradientPainter::GradientShapeBiLinear;
174 } else if ( gradientShape == "radial") {
175 gradientShapeValue = KisGradientPainter::GradientShapeRadial;
176 } else if ( gradientShape == "square") {
177 gradientShapeValue = KisGradientPainter::GradientShapeSquare;
178 } else if ( gradientShape == "conical") {
179 gradientShapeValue = KisGradientPainter::GradientShapeConical;
180 } else if ( gradientShape == "conicalSymmetric") {
181 gradientShapeValue = KisGradientPainter::GradientShapeConicalSymetric;
182 } else if ( gradientShape == "spiral") {
183 gradientShapeValue = KisGradientPainter::GradientShapeSpiral;
184 } else if ( gradientShape == "reverseSpiral") {
185 gradientShapeValue = KisGradientPainter::GradientShapeReverseSpiral;
186 } else if ( gradientShape == "polygonal") {
187 gradientShapeValue = KisGradientPainter::GradientShapePolygonal;
188 }
189 }
190
191 if (gradientRepeat != "none") {
192 if (gradientRepeat == "alternate") {
193 gradientRepeatValue = KisGradientPainter::GradientRepeatAlternate;
194 } else if (gradientRepeat == "forwards") {
195 gradientRepeatValue = KisGradientPainter::GradientRepeatForwards;
196 }
197 }
198 d->scratchpad->fillGradient(gradientVectorStart, gradientVectorEnd, gradientShapeValue, gradientRepeatValue, reverseGradient, dither);
199}
200
201void Scratchpad::fillLayer(bool fullContent)
202{
203 d->scratchpad->fillLayer(fullContent);
204}
205
206void Scratchpad::fillDocument(bool fullContent)
207{
208 d->scratchpad->fillDocument(fullContent);
209}
210
212{
213 d->scratchpad->fillPattern(transform);
214}
215
217{
218 return d->scratchpad->imageBounds();
219}
220
222{
223 return d->scratchpad->contentBounds();
224}
void fillBackground()
Fill the entire scratchpad with current background color.
void fillLayer(bool fullContent=true)
Fill the entire scratchpad with current layer content.
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
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:55:54 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.