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#include "kis_scratch_pad.h"
17
18#include <QColor>
19#include <QVBoxLayout>
20
21
22struct Scratchpad::Private
23{
24 KisScratchPad *scratchpad = 0;
25};
26
27
28Scratchpad::Scratchpad(View *view, const QColor & defaultColor, QWidget *parent)
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}
47
48Scratchpad::~Scratchpad()
49{
50}
51
53{
54 d->scratchpad->setModeManually(value);
55}
56
58{
59 d->scratchpad->setModeType(modeType);
60}
61
63{
64 qWarning("[DEPRECATED] Use Scratchpad.setCanvasZoomLink() instead of Scratchpad.linkCanvasZoom()");
65 d->scratchpad->setCanvasZoomLink(value);
66}
67
69{
70 d->scratchpad->setCanvasZoomLink(value);
71}
72
74{
75 return d->scratchpad->canvasZoomLink();
76}
77
79{
80 // return scale X only, consider zoom X/Y will alway be the same
81 return d->scratchpad->scaleX();
82}
83
84bool Scratchpad::setScale(qreal scale) const
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}
92
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}
101
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}
110
111void Scratchpad::panTo(qint32 x, qint32 y)
112{
113 d->scratchpad->panTo(x, y);
114}
115
117{
118 d->scratchpad->panCenter();
119}
120
122{
123 d->scratchpad->loadScratchpadImage(image);
124}
125
127{
128 return d->scratchpad->copyScratchpadImageData();
129}
130
132{
133 // need ability to set color
134 d->scratchpad->fillDefault();
135}
136
138{
139 d->scratchpad->setFillColor(color);
140}
141
143{
144 d->scratchpad->fillDefault();
145}
146
148{
149 d->scratchpad->fillTransparent();
150}
151
153{
154 d->scratchpad->fillBackground();
155}
156
158{
159 d->scratchpad->fillForeground();
160}
161
162void Scratchpad::fillGradient(const QPoint &gradientVectorStart,
163 const QPoint &gradientVectorEnd,
164 const QString &gradientShape,
165 const QString &gradientRepeat,
166 bool reverseGradient,
167 bool dither)
168{
169 KisGradientPainter::enumGradientShape gradientShapeValue = KisGradientPainter::GradientShapeLinear;
170 KisGradientPainter::enumGradientRepeat gradientRepeatValue = KisGradientPainter::GradientRepeatNone;
171
172 if (gradientShape != "linear") {
173 if (gradientShape == "bilinear") {
174 gradientShapeValue = KisGradientPainter::GradientShapeBiLinear;
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") {
182 gradientShapeValue = KisGradientPainter::GradientShapeConicalSymetric;
183 } else if ( gradientShape == "spiral") {
184 gradientShapeValue = KisGradientPainter::GradientShapeSpiral;
185 } else if ( gradientShape == "reverseSpiral") {
186 gradientShapeValue = KisGradientPainter::GradientShapeReverseSpiral;
187 } else if ( gradientShape == "polygonal") {
188 gradientShapeValue = KisGradientPainter::GradientShapePolygonal;
189 }
190 }
191
192 if (gradientRepeat != "none") {
193 if (gradientRepeat == "alternate") {
194 gradientRepeatValue = KisGradientPainter::GradientRepeatAlternate;
195 } else if (gradientRepeat == "forwards") {
196 gradientRepeatValue = KisGradientPainter::GradientRepeatForwards;
197 }
198 }
199 d->scratchpad->fillGradient(gradientVectorStart, gradientVectorEnd, gradientShapeValue, gradientRepeatValue, reverseGradient, dither);
200}
201
202void Scratchpad::fillLayer(bool fullContent)
203{
204 d->scratchpad->fillLayer(fullContent);
205}
206
207void Scratchpad::fillDocument(bool fullContent)
208{
209 d->scratchpad->fillDocument(fullContent);
210}
211
213{
214 d->scratchpad->fillPattern(transform);
215}
216
218{
219 return d->scratchpad->imageBounds();
220}
221
223{
224 return d->scratchpad->contentBounds();
225}
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 Nov 22 2024 12:06:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.