Krita Source Code Documentation
Loading...
Searching...
No Matches
KisLevelsSlider.h
Go to the documentation of this file.
1/*
2 * KDE. Krita Project.
3 *
4 * SPDX-FileCopyrightText: 2021 Deif Lou <ginoba@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#ifndef KIS_LEVELS_SLIDER_H
10#define KIS_LEVELS_SLIDER_H
11
12#include <QWidget>
13#include <QVector>
14
15#include "kritawidgets_export.h"
16
21class KRITAWIDGETS_EXPORT KisLevelsSlider : public QWidget
22{
23 Q_OBJECT
24
25public:
26 KisLevelsSlider(QWidget *parent);
28
29 QSize sizeHint() const override;
30 QSize minimumSizeHint() const override;
31
35 qreal handlePosition(int handleIndex) const;
39 QColor handleColor(int handleIndex) const;
43 virtual QRect gradientRect() const;
44
45public Q_SLOTS:
49 virtual void setHandlePosition(int handleIndex, qreal newPosition);
53 virtual void setHandleColor(int handleIndex, const QColor &newColor);
54
55Q_SIGNALS:
59 void handlePositionChanged(int handleIndex, qreal position);
63 void handleColorChanged(int handleIndex, const QColor &color);
64
65protected:
66 struct Handle
67 {
68 int index;
69 qreal position;
70 QColor color;
71 };
72
73 static constexpr int handleWidth{11};
74 static constexpr int handleHeight{11};
75 static constexpr qreal minimumSpaceBetweenHandles{0.001};
76 static constexpr qreal normalPositionIncrement{0.01};
77 static constexpr qreal slowPositionIncrement{0.001};
78
90
93
100 QVector<Handle> sortedHandles() const;
105 int closestHandleToPosition(qreal position) const;
110 qreal positionFromX(int x) const;
115 int closestHandleToX(int x) const;
120 int xFromPosition(qreal position) const;
125 virtual void paintGradient(QPainter &painter, const QRect &rect) = 0;
129 virtual void paintHandle(QPainter &painter, const QRect &rect, const Handle &handle);
130
131 void handleIncrementInput(int direction, Qt::KeyboardModifiers modifiers);
132
133 void paintEvent(QPaintEvent *e) override;
134 void mousePressEvent(QMouseEvent *e) override;
135 void mouseMoveEvent(QMouseEvent *e) override;
136 void leaveEvent(QEvent *e) override;
137 void keyPressEvent(QKeyEvent *e) override;
138 void wheelEvent(QWheelEvent *e) override;
139};
140
147class KRITAWIDGETS_EXPORT KisInputLevelsSlider : public KisLevelsSlider
148{
149 Q_OBJECT
150
151public:
152 KisInputLevelsSlider(QWidget *parent = nullptr);
154
158 qreal blackPoint() const;
162 qreal whitePoint() const;
163
164public Q_SLOTS:
168 virtual void setBlackPoint(qreal newBlackPoint);
172 virtual void setWhitePoint(qreal newWhitePoint);
181 virtual void reset(qreal newBlackPoint, qreal newWhitePoint);
182
183Q_SIGNALS:
187 void blackPointChanged(qreal newBlackPoint);
191 void whitePointChanged(qreal newWhitePoint);
192
193protected:
204 void paintGradient(QPainter &painter, const QRect &rect) override;
212 virtual void paintBottomGradientMiddleSection(QImage &gradientImage, const QVector<Handle> &sortedHandles_);
213};
214
220class KRITAWIDGETS_EXPORT KisInputLevelsSliderWithGamma : public KisInputLevelsSlider
221{
222 Q_OBJECT
223
224public:
225 KisInputLevelsSliderWithGamma(QWidget *parent = nullptr);
227
231 qreal gamma() const;
232
233public Q_SLOTS:
234 void setHandlePosition(int handleIndex, qreal newPosition) override;
238 void setGamma(qreal newGamma);
242 void reset(qreal newBlackPoint, qreal newWhitePoint) override;
246 void reset(qreal newBlackPoint, qreal newWhitePoint, qreal newGamma);
247
248Q_SIGNALS:
252 void gammaChanged(qreal newGamma);
253
254protected:
255 void paintBottomGradientMiddleSection(QImage &gradientImage, const QVector<Handle> &sortedHandles_) override;
256
257private:
258 qreal m_gamma;
259
260 qreal gammaToPosition() const;
261 qreal positionToGamma() const;
262};
263
268class KRITAWIDGETS_EXPORT KisOutputLevelsSlider : public KisInputLevelsSlider
269{
270 Q_OBJECT
271
272public:
273 KisOutputLevelsSlider(QWidget *parent = nullptr);
275};
276
280class KRITAWIDGETS_EXPORT KisThresholdSlider : public KisInputLevelsSlider
281{
282 Q_OBJECT
283
284public:
285 KisThresholdSlider(QWidget *parent = nullptr);
287
291 qreal threshold() const;
292
293public Q_SLOTS:
299 void setHandlePosition(int handleIndex, qreal newPosition) override;
305 void setBlackPoint(qreal newBlackPoint) override;
311 void setWhitePoint(qreal newWhitePoint) override;
312 void reset(qreal newBlackPoint, qreal newWhitePoint) override;
316 void setThreshold(qreal newGamma);
317
318Q_SIGNALS:
322 void thresholdChanged(qreal newThreshold);
323
324protected:
325 void paintBottomGradientMiddleSection(QImage &gradientImage, const QVector<Handle> &sortedHandles_) override;
326 void paintHandle(QPainter &painter, const QRect &rect, const Handle &handle) override;
327};
328
329#endif
This is a input levels slider that has a gamma handle. The handles are constrained so that the black ...
void gammaChanged(qreal newGamma)
Signal emitted when the gamma value changes.
This is a simple input levels slider that has no gamma handle. Use it if you want to show a simple ma...
void blackPointChanged(qreal newBlackPoint)
Signal emitted when the black point changes.
void whitePointChanged(qreal newWhitePoint)
Signal emitted when the white point changes.
A base class for levels slider like widgets: a slider with a gradient and multiple handles.
int m_constrainPositions
This variable indicates if the handles can have unordered positions. If it is set to true then the us...
void handlePositionChanged(int handleIndex, qreal position)
Signal emitted when the position of a handle changes.
void handleColorChanged(int handleIndex, const QColor &color)
Signal emitted when the color associated with a handle changes.
virtual void paintGradient(QPainter &painter, const QRect &rect)=0
Derived classes must override this function to draw the gradient inside the given rect....
QVector< Handle > m_handles
The collection of handles.
This is a simple output levels slider. It is basically the same as KisInputLevelsSlider but the handl...
This is a threshold slider that only has one handle.
void thresholdChanged(qreal newThreshold)
Signal emitted when the threshold value changes.