Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_canvas_controls_manager.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2003-2009 Boudewijn Rempt <boud@valdyas.org>
3 * SPDX-FileCopyrightText: 2014 Sven Langkamp <sven.langkamp@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
9
10#include <kactioncollection.h>
11#include <QAction>
12
14
15#include "kis_action.h"
16#include "kis_action_manager.h"
17#include "KisViewManager.h"
18#include "kis_canvas2.h"
20
24
25#include <klocalizedstring.h>
26#include <kconfiggroup.h>
27#include <ksharedconfig.h>
28
29#include <math.h>
30
31const int STEP = 25;
32
37
42
44{
45 KisAction *forcePaletteColors = actionManager->createAction("force_palette_colors");
46 forcePaletteColors->setCheckable(true);
48 connect(forcePaletteColors, SIGNAL(toggled(bool)), SLOT(forcePaletteColors(bool)));
49
50 KisAction *lighterColor = actionManager->createAction("make_brush_color_lighter");
51 connect(lighterColor, SIGNAL(triggered()), SLOT(makeColorLighter()));
52
53 KisAction *darkerColor = actionManager->createAction("make_brush_color_darker");
54 connect(darkerColor, SIGNAL(triggered()), SLOT(makeColorDarker()));
55 KisAction *saturatedColor = actionManager->createAction("make_brush_color_saturated");
56 connect(saturatedColor, SIGNAL(triggered()), SLOT(makeColorSaturated()));
57
58 KisAction *desaturatedColor = actionManager->createAction("make_brush_color_desaturated");
59 connect(desaturatedColor, SIGNAL(triggered()), SLOT(makeColorDesaturated()));
60
61 KisAction *hueClockwise = actionManager->createAction("shift_brush_color_clockwise");
62 connect(hueClockwise, SIGNAL(triggered()), SLOT(shiftHueClockWise()));
63
64 KisAction *hueCounterClockwise = actionManager->createAction("shift_brush_color_counter_clockwise");
65 connect(hueCounterClockwise, SIGNAL(triggered()), SLOT(shiftHueCounterClockWise()));
66
67 KisAction *moreRed = actionManager->createAction("make_brush_color_redder");
68 connect(moreRed, SIGNAL(triggered()), SLOT(makeColorRed()));
69
70 KisAction *moreGreen = actionManager->createAction("make_brush_color_greener");
71 connect(moreGreen, SIGNAL(triggered()), SLOT(makeColorGreen()));
72
73 KisAction *moreBlue = actionManager->createAction("make_brush_color_bluer");
74 connect(moreBlue, SIGNAL(triggered()), SLOT(makeColorBlue()));
75
76 KisAction *moreYellow = actionManager->createAction("make_brush_color_yellower");
77 connect(moreYellow, SIGNAL(triggered()), SLOT(makeColorYellow()));
78
79 KisAction *increaseOpacity = actionManager->createAction("increase_opacity");
80 connect(increaseOpacity, SIGNAL(triggered()), SLOT(increaseOpacity()));
81
82 KisAction *decreaseOpacity = actionManager->createAction("decrease_opacity");
83 connect(decreaseOpacity, SIGNAL(triggered()), SLOT(decreaseOpacity()));
84
85 KisAction *increaseFlow = actionManager->createAction("increase_flow");
86 connect(increaseFlow, SIGNAL(triggered()), SLOT(increaseFlow()));
87
88 KisAction *decreaseFlow = actionManager->createAction("decrease_flow");
89 connect(decreaseFlow, SIGNAL(triggered()), SLOT(decreaseFlow()));
90
91 KisAction *increaseFade = actionManager->createAction("increase_fade");
92 connect(increaseFade, SIGNAL(triggered()), SLOT(increaseFade()));
93
94 KisAction *decreaseFade = actionManager->createAction("decrease_fade");
95 connect(decreaseFade, SIGNAL(triggered()), SLOT(decreaseFade()));
96
97 KisAction *increaseScatter = actionManager->createAction("increase_scatter");
98 connect(increaseScatter, SIGNAL(triggered()), SLOT(increaseScatter()));
99
100 KisAction *decreaseScatter = actionManager->createAction("decrease_scatter");
101 connect(decreaseScatter, SIGNAL(triggered()), SLOT(decreaseScatter()));
102}
103
105{
106 Q_UNUSED(imageView);
107}
108
110{
111 if (!m_view) return;
112 if (!m_view->canvasBase()) return;
114 KConfigGroup hotkeycfg = KSharedConfig::openConfig()->group("colorhotkeys");
115 int steps = hotkeycfg.readEntry("steps_lightness", 10);
116 if (steps <= 0) {
117 steps = 1;
118 }
119
120
122 if (color.colorSpace()->colorModelId().id()=="CMYKA" || color.colorSpace()->colorModelId().id()=="XYZA"){
123 QColor rgb = color.toQColor();
124 int h = 0, s = 0, v = 0;
125 rgb.getHsv(&h,&s,&v);
126 if ((v < 255) || ((s == 0) || (s == 255))) {
127 v += step;
128 v = qBound(0,v,255);
129 } else {
130 s += -step;
131 s = qBound(0,s,255);
132 }
133 rgb.setHsv(h,s,v);
134 color.fromQColor(rgb);
135 } else if (step<0){
136 color.colorSpace()->decreaseLuminosity(color.data(), 1.0/steps);
137 } else {
138 color.colorSpace()->increaseLuminosity(color.data(), 1.0/steps);
139 }
141}
143{
144 if (!m_view) return;
145 if (!m_view->canvasBase()) return;
147 KConfigGroup hotkeycfg = KSharedConfig::openConfig()->group("colorhotkeys");
148 int steps = hotkeycfg.readEntry("steps_saturation", 10);
149 if (steps <= 0) {
150 steps = 1;
151 }
152
154 if (color.colorSpace()->colorModelId().id()=="CMYKA" || color.colorSpace()->colorModelId().id()=="XYZA"){
155 QColor rgb = color.toQColor();
156 int h = 0, s = 0, v = 0;
157 rgb.getHsl(&h,&s,&v);
158 s += step;
159 s = qBound(0,s,255);
160 rgb.setHsl(h,s,v);
161 color.fromQColor(rgb);
162 } else if (step<0){
163 color.colorSpace()->decreaseSaturation(color.data(), 1.0/steps);
164 } else {
165 color.colorSpace()->increaseSaturation(color.data(), 1.0/steps);
166 }
168}
170{
171 if (!m_view) return;
172 if (!m_view->canvasBase()) return;
174 KConfigGroup hotkeycfg = KSharedConfig::openConfig()->group("colorhotkeys");
175 int steps = hotkeycfg.readEntry("steps_hue", 36);
176 if (steps <= 0) {
177 steps = 1;
178 }
179
181 if (color.colorSpace()->colorModelId().id()=="CMYKA" || color.colorSpace()->colorModelId().id()=="XYZA"){
182 QColor rgb = color.toQColor();
183 int h = 0, s = 0, v = 0;
184 rgb.getHsl(&h,&s,&v);
185 h += step;
186 if (h>360.0 || h<0.0){h=fmod(h, 360.0);}
187 rgb.setHsl(h,s,v);
188 color.fromQColor(rgb);
189 } else if (step<0){
190 color.colorSpace()->increaseHue(color.data(), 1.0/steps);
191 } else {
192 color.colorSpace()->decreaseHue(color.data(), 1.0/steps);
193 }
195}
197{
198 if (!m_view) return;
199 if (!m_view->canvasBase()) return;
201 KConfigGroup hotkeycfg = KSharedConfig::openConfig()->group("colorhotkeys");
202 int steps = hotkeycfg.readEntry("steps_redgreen", 10);
203 if (steps <= 0) {
204 steps = 1;
205 }
206
208 if (step<0){
209 color.colorSpace()->increaseGreen(color.data(), 1.0/steps);
210 } else {
211 color.colorSpace()->increaseRed(color.data(), 1.0/steps);
212 }
214}
216{
217 if (!m_view) return;
218 if (!m_view->canvasBase()) return;
220 KConfigGroup hotkeycfg = KSharedConfig::openConfig()->group("colorhotkeys");
221 int steps = hotkeycfg.readEntry("steps_blueyellow", 10);
222 if (steps <= 0) {
223 steps = 1;
224 }
225
227 if (step<0){
228 color.colorSpace()->increaseYellow(color.data(), 1.0/steps);
229 } else {
230 color.colorSpace()->increaseBlue(color.data(), 1.0/steps);
231 }
233}
234
235
240
245
250
259
280
282{
283 if (!m_view) return;
284 if (!m_view->canvasBase()) return;
286
288 alpha += step;
289 alpha = qBound<qreal>(0.0, alpha, 1.0);
291
292 m_view->showFloatingMessage(i18n("Brush Opacity: %1%", alpha * 100), QIcon(), 1000, KisFloatingMessage::High,
293 Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter);
294
295 // FIXME: DK: should we uncomment it back?
296 //KisLockedPropertiesProxySP p = KisLockedPropertiesServer::instance()->createLockedPropertiesProxy(m_view->resourceProvider()->currentPreset()->settings());
297 //p->setProperty("OpacityValue", alpha);
298}
299
304
309
311{
312 if (!m_view) return;
313 if (!m_view->canvasBase()) return;
315
317 flow += step;
318 flow = qBound<qreal>(0.0, flow, 1.0);
319 m_view->canvasBase()->resourceManager ()->setResource(KoCanvasResource::Flow, flow);
320
321 // verify if the brush does actually support this change
322 flow = m_view->canvasBase()->resourceManager ()->resource(KoCanvasResource::Flow).toReal();
323
324 m_view->showFloatingMessage(i18nc("Brush Option Flow", "Flow: %1%", flow * 100), QIcon(), 1000, KisFloatingMessage::High,
325 Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter);
326}
327
332
337
339{
340 if (!m_view) return;
341 if (!m_view->canvasBase()) return;
343
345 fade += step;
346 fade = qBound<qreal>(0.0, fade, 1.0);
347 m_view->canvasBase()->resourceManager ()->setResource(KoCanvasResource::Fade, fade);
348
349 // verify if the brush does actually support this change
350 fade = m_view->canvasBase()->resourceManager ()->resource(KoCanvasResource::Fade).toReal();
351
352 m_view->showFloatingMessage(i18nc("Edge softness, Brush Option Fade", "Fade: %1", fade),
353 QIcon(), 1000, KisFloatingMessage::High, Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter);
354}
355
360
365
367{
368 if (!m_view) return;
369 if (!m_view->canvasBase()) return;
371
373 scatter += step;
374 scatter = qBound<qreal>(0.0, scatter, 5.0);
375 m_view->canvasBase()->resourceManager ()->setResource(KoCanvasResource::Scatter, scatter);
376
377 // verify if the brush does actually support this change
378 scatter = m_view->canvasBase()->resourceManager ()->resource(KoCanvasResource::Scatter).toReal();
379
380 m_view->showFloatingMessage(i18nc("Brush Option Scatter", "Scatter: %1%", scatter * 100), QIcon(), 1000, KisFloatingMessage::High,
381 Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter);
382}
383
388
393
qreal v
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
A KisActionManager class keeps track of KisActions. These actions are always associated with the GUI....
KisAction * createAction(const QString &name)
KisCanvasControlsManager(KisViewManager *view)
void setup(KisActionManager *actionManager)
void setView(QPointer< KisView >imageView)
KoCanvasResourceProvider * resourceManager()
void setForcePaletteColors(bool forcePaletteColors)
KisCanvas2 * canvasBase() const
Return the canvas base class.
KisCanvasResourceProvider * canvasResourceProvider()
void showFloatingMessage(const QString &message, const QIcon &icon, int timeout=4500, KisFloatingMessage::Priority priority=KisFloatingMessage::Medium, int alignment=Qt::AlignCenter|Qt::TextWordWrap)
shows a floating message in the top right corner of the canvas
QPointer< KoCanvasResourceProvider > resourceManager
void setResource(int key, const QVariant &value)
virtual void increaseHue(quint8 *pixel, qreal step) const
virtual void increaseBlue(quint8 *pixel, qreal step) const
virtual void increaseRed(quint8 *pixel, qreal step) const
virtual void decreaseHue(quint8 *pixel, qreal step) const
virtual void increaseSaturation(quint8 *pixel, qreal step) const
virtual void increaseGreen(quint8 *pixel, qreal step) const
virtual void decreaseLuminosity(quint8 *pixel, qreal step) const
virtual void increaseLuminosity(quint8 *pixel, qreal step) const
virtual KoID colorModelId() const =0
virtual void decreaseSaturation(quint8 *pixel, qreal step) const
virtual void increaseYellow(quint8 *pixel, qreal step) const
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
Definition KoColor.cpp:213
quint8 * data()
Definition KoColor.h:144
const KoColorSpace * colorSpace() const
return the current colorSpace
Definition KoColor.h:82
void toQColor(QColor *c) const
a convenience method for the above.
Definition KoColor.cpp:198
QString id() const
Definition KoID.cpp:63
@ ForegroundColor
The active foreground color selected for this canvas.