KSeExpr 6.0.0.0
ExprControl.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2011-2019 Disney Enterprises, Inc.
2// SPDX-License-Identifier: LicenseRef-Apache-2.0
3// SPDX-FileCopyrightText: 2020 L. E. Segovia <amy@amyspark.me>
4// SPDX-License-Identifier: GPL-3.0-or-later
5
6#pragma once
7
8#include <array>
9#include <atomic>
10#include <cstddef>
11#include <memory>
12
13#include <QCheckBox>
14#include <QHBoxLayout>
15#include <QLabel>
16
17#include "Editable.h"
18#include "ExprColorCurve.h"
19#include "ExprColorSwatch.h"
20#include "ExprCurve.h"
21
22
24class ExprControl : public QWidget
25{
26 Q_OBJECT
27
28protected:
29 int _id;
30 std::atomic<bool> _updating {}; // whether to send events (i.e. masked when self editing)
31 QHBoxLayout *hbox {nullptr};
32 QCheckBox *_colorLinkCB {nullptr};
33 QLabel *_label {nullptr};
34
35 Editable *_editable {nullptr};
36
37public:
38 ExprControl(int id, Editable *editable, bool showColorLink);
39 ~ExprControl() override = default;
40
42 virtual QColor getColor()
43 {
44 return {};
45 }
47 virtual void setColor(QColor) {};
48
49Q_SIGNALS:
50 // sends that the control has been changed to the control collection
51 void controlChanged(int id);
52 // sends the new color to the control collection
53 void linkColorEdited(int id, QColor color);
54 // sends that a color link is desired to the control collection
55 void linkColorLink(int id);
56public Q_SLOTS:
57 // receives that the link should be changed to the given state (0=off,1=on)
58 void linkStateChange(int state);
59
60public:
61 // notifies this that the link should be disconnected
62 void linkDisconnect(int newId);
63
64protected:
65 // Allows to adapt the widget contents - amyspark
66 void resizeEvent(QResizeEvent *event) override;
67};
68
70template<class T, class T2, class T3> T clamp(const T val, const T2 minval, const T3 maxval)
71{
72 assert(!(maxval < minval));
73 if (val < minval)
74 return minval;
75 else if (val > maxval)
76 return maxval;
77 return val;
78}
79
81// TODO: can this now be removed?
82class ExprLineEdit : public QLineEdit
83{
84 Q_OBJECT
85public:
86 ExprLineEdit(int id, QWidget *parent);
87 virtual void setText(const QString &t)
88 {
89 if (_signaling)
90 return;
91 QLineEdit::setText(t);
92 }
93
94Q_SIGNALS:
95 void textChanged(int id, const QString &text);
96
97private Q_SLOTS:
98 void textChangedCB(const QString &text);
99
100private:
101 int _id;
102 std::atomic<bool> _signaling{false};
103};
104
106class ExprSlider : public QSlider
107{
108 Q_OBJECT
109public:
110 ExprSlider(QWidget *parent = nullptr)
111 : QSlider(parent)
112 {
113 }
114 ExprSlider(Qt::Orientation orientation, QWidget *parent = nullptr)
115 : QSlider(orientation, parent)
116 {
117 }
118 void mousePressEvent(QMouseEvent *e) override;
119 void mouseMoveEvent(QMouseEvent *e) override;
120 void paintEvent(QPaintEvent *e) override;
121 void leaveEvent(QEvent *) override
122 {
123 update();
124 }
125 void enterEvent(QEnterEvent *) override
126 {
127 update();
128 }
129 void wheelEvent(QWheelEvent *e) override
130 {
131 e->ignore();
132 }
133};
134
136class ExprChannelSlider : public QWidget
137{
138 Q_OBJECT
139public:
140 ExprChannelSlider(int id, QWidget *parent);
141 void paintEvent(QPaintEvent *e) override;
142 void mousePressEvent(QMouseEvent *e) override;
143 void mouseMoveEvent(QMouseEvent *e) override;
144 void wheelEvent(QWheelEvent *e) override
145 {
146 e->ignore();
147 }
148 double value() const
149 {
150 return _value;
151 }
152 void setDisplayColor(QColor c)
153 {
154 _col = c;
155 }
156
157public Q_SLOTS:
158 void setValue(double value);
159
160Q_SIGNALS:
161 void valueChanged(int id, double value);
162
163private:
164 int _id;
165 double _value;
166 QColor _col;
167};
168
171{
172 Q_OBJECT
173
177 ExprSlider *_slider {nullptr};
179 ExprLineEdit *_edit {nullptr};
180
181public:
182 NumberControl(int id, NumberEditable *editable);
183
184private:
186 void setValue(double value);
188 void updateControl();
189private Q_SLOTS:
190 void sliderChanged(int val);
191 void editChanged(int id, const QString &text);
192};
193
196{
197 Q_OBJECT
198
202 std::array<ExprLineEdit *, 3> _edits{};
204
206 std::array<ExprChannelSlider *, 3> _sliders{};
207
208public:
209 VectorControl(int id, VectorEditable *editable);
210
211 QColor getColor() override;
212 void setColor(QColor color) override;
213
214private:
216 void setValue(int n, double value);
218 void updateControl();
219private Q_SLOTS:
220 void sliderChanged(int id, double val);
221 void editChanged(int id, const QString &text);
222 void swatchChanged(QColor color);
223};
224
227{
228 Q_OBJECT
229
233 QLineEdit *_edit {nullptr};
234
235public:
236 StringControl(int id, StringEditable *stringEditable);
237
238private:
239 void updateControl();
240private Q_SLOTS:
241 void textChanged(const QString &newText);
242 void fileBrowse();
243 void directoryBrowse();
244};
245
248{
249 Q_OBJECT
250
254 ExprCurve *_curve {nullptr};
255
256public:
257 CurveControl(int id, CurveEditable *stringEditable);
258private Q_SLOTS:
259 void curveChanged();
260};
261
264{
265 Q_OBJECT
266
271
272public:
273 CCurveControl(int id, ColorCurveEditable *stringEditable);
274 QColor getColor() override;
275 void setColor(QColor color) override;
276private Q_SLOTS:
277 void curveChanged();
278};
279
282{
283 Q_OBJECT
284
289
290public:
291 ColorSwatchControl(int id, ColorSwatchEditable *swatchEditable);
292private Q_SLOTS:
293 void buildSwatchWidget();
294 void colorChanged(int index, KSeExpr::Vec3d value);
295 void colorAdded(int index, KSeExpr::Vec3d value);
296 void colorRemoved(int index);
297
298private:
300};
T clamp(const T val, const T2 minval, const T3 maxval)
clamp val to the specified range [minval,maxval]
Definition ExprControl.h:70
Control for editing a color ramp curve.
QColor getColor() override
Interface for getting the color (used for linked color picking)
void setColor(QColor color) override
Interface for setting the color (used for linked color picking)
ColorCurveEditable * _curveEditable
color curve model
ExprColorCurve * _curve
color curve widget
A control for editing color swatches.
void colorChanged(int index, KSeExpr::Vec3d value)
void colorAdded(int index, KSeExpr::Vec3d value)
void colorRemoved(int index)
ColorSwatchEditable * _swatchEditable
model for the color swatches control
ExprColorSwatchWidget * _swatch
Edit box for the color swatches.
Control for editing a normal curve ramp.
void curveChanged()
ExprCurve * _curve
curve edit widget
CurveEditable * _curveEditable
curve model
Channel Slider (i.e. for colors)
void mouseMoveEvent(QMouseEvent *e) override
void setValue(double value)
void wheelEvent(QWheelEvent *e) override
double value() const
void valueChanged(int id, double value)
void paintEvent(QPaintEvent *e) override
void setDisplayColor(QColor c)
void mousePressEvent(QMouseEvent *e) override
Base class for all controls for Expressions.
Definition ExprControl.h:25
QCheckBox * _colorLinkCB
Definition ExprControl.h:32
std::atomic< bool > _updating
Definition ExprControl.h:30
Editable * _editable
Definition ExprControl.h:35
QHBoxLayout * hbox
Definition ExprControl.h:31
virtual QColor getColor()
Interface for getting the color (used for linked color picking)
Definition ExprControl.h:42
void resizeEvent(QResizeEvent *event) override
void linkStateChange(int state)
void linkDisconnect(int newId)
QLabel * _label
Definition ExprControl.h:33
void controlChanged(int id)
void linkColorLink(int id)
void linkColorEdited(int id, QColor color)
~ExprControl() override=default
virtual void setColor(QColor)
Interface for setting the color (used for linked color picking)
Definition ExprControl.h:47
Line Editor Widget(used for numbers)
Definition ExprControl.h:83
virtual void setText(const QString &t)
Definition ExprControl.h:87
std::atomic< bool > _signaling
void textChanged(int id, const QString &text)
void textChangedCB(const QString &text)
Generic Slider (used for int and float sliders)
ExprSlider(QWidget *parent=nullptr)
ExprSlider(Qt::Orientation orientation, QWidget *parent=nullptr)
void wheelEvent(QWheelEvent *e) override
void paintEvent(QPaintEvent *e) override
void mouseMoveEvent(QMouseEvent *e) override
void leaveEvent(QEvent *) override
void enterEvent(QEnterEvent *) override
void mousePressEvent(QMouseEvent *e) override
Number slider for either float or int data.
NumberEditable * _numberEditable
Pointer to the number control model.
void editChanged(int id, const QString &text)
void updateControl()
Update values in slider and textbox given what the model contains.
ExprLineEdit * _edit
Text box for the number.
void sliderChanged(int val)
ExprSlider * _slider
Slider for the number.
void setValue(double value)
Update the model with the value and notify the collection.
A control for editing strings, filenames, and directories.
void directoryBrowse()
StringEditable * _stringEditable
model for the string control
void textChanged(const QString &newText)
QLineEdit * _edit
Edit box for the string.
A vector or color control (named vector because it edits a KSeExpr::Vec3d literal)
void setValue(int n, double value)
set the value in the model (in response to editing from controls)
void updateControl()
update the individual slider and eidt box controls
std::array< ExprLineEdit *, 3 > _edits
All three line edit widgets (for each component)
void editChanged(int id, const QString &text)
std::array< ExprChannelSlider *, 3 > _sliders
All three channel sliders (for each component)
void swatchChanged(QColor color)
VectorEditable * _numberEditable
Number model.
void sliderChanged(int id, double val)
QColor getColor() override
Interface for getting the color (used for linked color picking)
void setColor(QColor color) override
Interface for setting the color (used for linked color picking)
ExprCSwatchFrame * _swatch