Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_gamma_exposure_action.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2014 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QApplication>
10
11#include <klocalizedstring.h>
12#include <kis_canvas2.h>
13#include "kis_cursor.h"
14#include "KisViewManager.h"
15#include "kis_input_manager.h"
16#include "krita_utils.h"
18
19
21{
22public:
24
25 // Coverity requires sane defaults for all variables (CID 248819)
27
29
30 qreal baseExposure {0.0};
31 qreal baseGamma {0.0};
32
33 void addExposure(qreal diff);
34 void addGamma(qreal diff);
35};
36
37
39{
41 q->inputManager()->canvas()->exposureGammaCorrectionInterface();
42
43 if (!interface->canChangeExposureAndGamma()) return;
44
45 interface->setCurrentExposure(interface->currentExposure() + diff);
46}
47
49{
51 q->inputManager()->canvas()->exposureGammaCorrectionInterface();
52
53 if (!interface->canChangeExposureAndGamma()) return;
54
55 interface->setCurrentGamma(interface->currentGamma() + diff);
56}
57
59 : KisAbstractInputAction("Exposure or Gamma")
60 , d(new Private(this))
61{
62 setName(i18n("Exposure and Gamma"));
63 setDescription(i18n("The <i>Exposure and Gamma</i> action changes the display mode of the canvas."));
64
65 QHash< QString, int > shortcuts;
66 shortcuts.insert(i18n("Exposure Mode"), ExposureShortcut);
67 shortcuts.insert(i18n("Gamma Mode"), GammaShortcut);
68
69 shortcuts.insert(i18n("Exposure +0.5"), AddExposure05Shortcut);
70 shortcuts.insert(i18n("Exposure -0.5"), RemoveExposure05Shortcut);
71 shortcuts.insert(i18n("Gamma +0.5"), AddGamma05Shortcut);
72 shortcuts.insert(i18n("Gamma -0.5"), RemoveGamma05Shortcut);
73
74 shortcuts.insert(i18n("Exposure +0.2"), AddExposure02Shortcut);
75 shortcuts.insert(i18n("Exposure -0.2"), RemoveExposure02Shortcut);
76 shortcuts.insert(i18n("Gamma +0.2"), AddGamma02Shortcut);
77 shortcuts.insert(i18n("Gamma -0.2"), RemoveGamma02Shortcut);
78
79 shortcuts.insert(i18n("Reset Exposure and Gamma"), ResetExposureAndGammaShortcut);
80 setShortcutIndexes(shortcuts);
81}
82
87
89{
90 return 5;
91}
92
94{
95 if (shortcut == ExposureShortcut) {
96 QApplication::setOverrideCursor(KisCursor::changeExposureCursor());
97 } else /* if (shortcut == GammaShortcut) */ {
98 QApplication::setOverrideCursor(KisCursor::changeGammaCursor());
99 }
100}
101
103{
104 Q_UNUSED(shortcut);
105 QApplication::restoreOverrideCursor();
106}
107
108void KisGammaExposureAction::begin(int shortcut, QEvent *event)
109{
110 KisAbstractInputAction::begin(shortcut, event);
111
113 inputManager()->canvas()->exposureGammaCorrectionInterface();
114
115 switch(shortcut) {
116 case ExposureShortcut:
117 d->baseExposure = interface->currentExposure();
118 d->mode = (Shortcuts)shortcut;
119 break;
120 case GammaShortcut:
121 d->baseGamma = interface->currentGamma();
122 d->mode = (Shortcuts)shortcut;
123 break;
124
126 d->addExposure(0.5);
127 break;
129 d->addExposure(-0.5);
130 break;
132 d->addGamma(0.5);
133 break;
135 d->addGamma(-0.5);
136 break;
137
139 d->addExposure(0.2);
140 break;
142 d->addExposure(-0.2);
143 break;
145 d->addGamma(0.2);
146 break;
148 d->addGamma(-0.2);
149 break;
150
153 inputManager()->canvas()->exposureGammaCorrectionInterface();
154 if (!interface->canChangeExposureAndGamma()) break;
155
156 interface->setCurrentGamma(1.0);
157 interface->setCurrentExposure(0.0);
158 break;
159 }
160 }
161}
162
163void KisGammaExposureAction::cursorMovedAbsolute(const QPointF &startPos, const QPointF &pos)
164{
165 QPointF diff = -(pos - startPos);
166
167 const int step = 200;
168
170 inputManager()->canvas()->exposureGammaCorrectionInterface();
171
172 if (!interface->canChangeExposureAndGamma()) return;
173
174
175 if (d->mode == ExposureShortcut) {
176 const qreal currentExposure = d->baseExposure + qreal(diff.y()) / step;
177 interface->setCurrentExposure(currentExposure);
178 } else if (d->mode == GammaShortcut) {
179 const qreal currentGamma = d->baseExposure + qreal(diff.y()) / step;
180 interface->setCurrentGamma(currentGamma);
181 }
182}
183
185{
186 Q_UNUSED(shortcut);
187 return false;
188}
Abstract base class for input actions.
static KisInputManager * inputManager
void setShortcutIndexes(const QHash< QString, int > &indexes)
void setName(const QString &name)
void setDescription(const QString &description)
virtual void begin(int shortcut, QEvent *event)
static QCursor changeGammaCursor()
static QCursor changeExposureCursor()
bool isShortcutRequired(int shortcut) const override
void begin(int shortcut, QEvent *event=nullptr) override
void cursorMovedAbsolute(const QPointF &lastPos, const QPointF &pos) override
void deactivate(int shortcut) override
void activate(int shortcut) override
KisCanvas2 * canvas