20static constexpr std::array<const char *, 24>
directoryXPM = {
"20 20 3 1",
24 "....................",
25 "....................",
26 "....................",
27 "....................",
28 "...........#######..",
29 "...........#aaaaa#..",
30 "..##########aaaaa#..",
31 "..#aaaaaaaaaaaaaa#..",
32 "..#aaaaaaaaaaaaaa#..",
33 "..#aaaaaaaaaaaaaa#..",
34 "..#aaaaaaaaaaaaaa#..",
35 "..#aaaaaaaaaaaaaa#..",
36 "..#aaaaa##a##a##a#..",
37 "..#aaaaa##a##a##a#..",
38 "..#aaaaaaaaaaaaaa#..",
39 "..################..",
40 "....................",
41 "....................",
42 "....................",
43 "...................."};
46static constexpr std::array<const char *, 26>
fileXPM = {
"20 20 5 1",
52 "....................",
53 "....................",
54 "....#########.......",
55 "....#aaaaaaa##......",
56 "....#aaaaaaa#b#.....",
57 "....#aaaaaaa#bb#....",
58 "....#aaaaaaa####....",
59 "....#aaaaaaaaaa#....",
60 "....#aaaaaaaaaa#....",
61 "....#aaaaaaaaaa#....",
62 "....#aaaaaaaaaa#....",
63 "....#aaaaaaaaaa#....",
64 "....#aaaaaaaaaa#....",
65 "....#aaaaaaaaaa#....",
66 "....#aaaaaaaaaa#....",
67 "....#accaccacca#....",
68 "....#accaccacca#....",
69 "....#aaaaaaaaaa#....",
70 "....############....",
71 "...................."};
80 auto r = maximum() - minimum();
81 auto v = ((double)(e->x() - 2) * r / (width() - 5)) + minimum() + .5F;
82 int iv = std::min(std::max((
int)v, minimum()), maximum());
91 double r = maximum() - minimum();
92 int linepos = (int)((v - minimum()) / r * (width() - 5) + 2);
94 QColor qcol = palette().color(QPalette::Dark);
95 QColor bcol = palette().color(QPalette::Midlight);
96 QColor dcol = bcol.lighter(140);
97 QColor bgcol = palette().color(QPalette::Base);
100 bcol = bcol.lighter(110);
101 bgcol = bgcol.lighter(110);
102 int mx = mapFromGlobal(QCursor::pos()).x();
103 if (abs(linepos - mx) < 4)
104 dcol = dcol.lighter(200);
107 p.fillRect(1, 1, width() - 1, height() - 2, bgcol);
108 p.fillRect(1, 1, linepos - 1, height() - 2, bcol);
116 p.drawLine(linepos, 2, linepos, height() - 2);
120 p.drawLine(linepos - 2, 1, linepos - 2, height() - 1);
121 p.drawLine(linepos + 2, 1, linepos + 2, height() - 1);
126 p.drawRect(0, 0, width() - 1, height() - 1);
138 if (_value < 0 || _value > 1)
140 int x = int(
_value * (width() - 3) + 0.5);
142 p.fillRect(contentsRect(),
_col);
143 p.fillRect(x, 0, 3, height(), QColor(64, 64, 64));
168 , _editable(editable)
170 hbox =
new QHBoxLayout(
this);
179 QString editableLabel = QString::fromStdString(
_editable->
name);
181 QFontMetrics _labelSize(
_label->font());
184 _label->setMinimumWidth(60);
185 _label->setText(tr(
"<b>%1</b>").arg(_labelSize.elidedText(editableLabel, Qt::TextElideMode::ElideRight, qMax(0,
_label->width() - 15))));
186 _label->setAutoFillBackground(
true);
189 if (!showColorLink) {
198 QString editableLabel = QString::fromStdString(
_editable->
name);
199 QFontMetrics _labelSize(
_label->font());
200 _label->setText(tr(
"<b>%1</b>").arg(_labelSize.elidedText(editableLabel, Qt::TextElideMode::ElideRight, qMax(0,
_label->width() - 15))));
208 if (state == Qt::Checked) {
227 , _numberEditable(editable)
229 auto *slider =
new QHBoxLayout();
231 auto smin = editable->
min;
232 auto smax = editable->
max;
237 auto srange = smax - smin;
239 _slider->setRange(
int(smin),
int(smax));
240 _slider->setTickInterval(std::max(1,
int(srange / 10)));
241 _slider->setSingleStep(std::max(1,
int(srange / 50)));
242 _slider->setPageStep(std::max(1,
int(srange / 10)));
243 _slider->setFocusPolicy(Qt::ClickFocus);
247 slider->addWidget(
_edit);
248 hbox->addLayout(slider, 4);
249 connect(
_edit, SIGNAL(textChanged(
int,
const QString &)), SLOT(
editChanged(
int,
const QString &)));
267 float val = text.toFloat(&ok);
277 if (sliderval !=
_slider->value())
295 , _numberEditable(editable)
297 auto *control =
new QHBoxLayout();
304 for (
int i = 0; i < 3; i++) {
305 auto *vbl =
new QVBoxLayout();
306 control->addLayout(vbl);
307 vbl->setContentsMargins({});
311 vbl->addWidget(edit);
316 auto width(edit->minimumSizeHint().width());
317 auto height(edit->minimumSizeHint().height() + 6);
318 _swatch->setMinimumWidth(width);
319 _swatch->setMinimumHeight(height);
320 _swatch->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
324 vbl->addWidget(slider);
327 slider->setFixedHeight(6);
329 static const std::array<QColor, 3> rgb = {QColor(128, 64, 64), QColor(64, 128, 64), QColor(64, 64, 128)};
331 slider->setDisplayColor(rgb[i]);
333 connect(edit, SIGNAL(textChanged(
int,
const QString &)), SLOT(
editChanged(
int,
const QString &)));
334 connect(slider, SIGNAL(valueChanged(
int,
double)), SLOT(
sliderChanged(
int,
double)));
336 hbox->addLayout(control, 4);
375 float val = text.toFloat(&ok);
385 for (
auto i = 0; i < 3; i++) {
390 for (
auto i = 0; i < 3; i++) {
396 auto r =
clamp(val[0], 0, 1);
397 auto g =
clamp(val[1], 0, 1);
398 auto b =
clamp(val[2], 0, 1);
399 auto lum = r * .2 + g * .7 + b * .1;
401 QPalette pal = palette();
402 pal.setColor(QPalette::Window, QColor(
int(r * 255),
int(g * 255),
int(b * 255)));
403 pal.setColor(QPalette::WindowText, (lum < 0.5) ? QColor(255, 255, 255) : QColor(0, 0, 0));
424 , _stringEditable(editable)
427 _edit =
new QLineEdit();
428 _edit->setFixedHeight(20);
432 auto *button =
new QPushButton();
433 button->setFixedSize(20, 20);
436 hbox->addWidget(button, 1);
441 connect(button, SIGNAL(clicked()), SLOT(
fileBrowse()));
442 button->setIcon(QIcon(QPixmap(
fileXPM.data())));
456 QString newFilename = dialog.
getOpenFileName(tr(
"Please choose a file"),
_edit->text(), tr(
"Images (*.tif *.tx *.jpg *.ptx *.png)"));
457 if (!newFilename.isEmpty())
458 _edit->setText(newFilename);
466 if (!newFilename.isEmpty())
467 _edit->setText(newFilename);
473 _edit->setText(newText);
486 , _curveEditable(editable)
491 for (
int i = 0; i < numVal; i++) {
510 , _curveEditable(editable)
515 for (
int i = 0; i < numVal; i++) {
546 std::vector<float>
x,
y;
568 QWidget::paintEvent(event);
569 QPainter painter(
this);
570 painter.setRenderHint(QPainter::Antialiasing,
true);
571 painter.setPen(QColor(255, 255, 255));
584 int x_pad_in_pixels = 25;
585 int y_pad_in_pixels = 15;
586 auto xpad = x_pad_in_pixels * (
win_xmax -
win_xmin) / (width() - x_pad_in_pixels);
587 auto ypad = y_pad_in_pixels * (
win_ymax -
win_ymin) / (height() - y_pad_in_pixels);
597 QBrush darkbrush(QColor(100, 100, 100), Qt::SolidPattern);
599 QBrush brush(QColor(150, 150, 150), Qt::SolidPattern);
604 painter.fillRect(area, brush);
607 for (
int i = 1; i < (int)
x.size(); i++)
613 painter.setPen(QColor(75, 50, 50));
614 painter.drawPath(path);
616 painter.setPen(QPen());
617 painter.drawText(right, Qt::AlignTop | Qt::AlignLeft, QString(tr(
"%1")).arg(
ymax, 0,
'f', 1));
618 painter.drawText(right, Qt::AlignBottom | Qt::AlignLeft, QString(tr(
"%1")).arg(
ymin, 0,
'f', 1));
619 painter.drawText(bottom, Qt::AlignTop | Qt::AlignLeft, QString(tr(
"%1")).arg(
xmin, 0,
'f', 1));
620 painter.drawText(bottom, Qt::AlignTop | Qt::AlignRight, QString(tr(
"%1")).arg(
xmax, 0,
'f', 1));
622 painter.setBrush(QBrush(QColor(0, 0, 0), Qt::SolidPattern));
623 for (
size_t i = 0; i <
cpx.size(); i++) {
632 , _swatchEditable(editable)
static constexpr std::array< const char *, 24 > directoryXPM
static constexpr std::array< const char *, 26 > fileXPM
T clamp(const T val, const T2 minval, const T3 maxval)
clamp val to the specified range [minval,maxval]
static constexpr std::array< int, 514 > p
CCurveControl(int id, ColorCurveEditable *stringEditable)
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
std::vector< T_CURVE::CV > _cvs
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.
ColorSwatchControl(int id, ColorSwatchEditable *swatchEditable)
void change(int index, const KSeExpr::Vec3d &value)
void add(const KSeExpr::Vec3d &value)
std::vector< KSeExpr::Vec3d > colors
CurveControl(int id, CurveEditable *stringEditable)
ExprCurve * _curve
curve edit widget
CurveEditable * _curveEditable
curve model
std::vector< T_CURVE::CV > _cvs
KSeExpr::Vec3d getValue() const
void setValue(const KSeExpr::Vec3d &value)
Channel Slider (i.e. for colors)
void mouseMoveEvent(QMouseEvent *e) override
void setValue(double value)
void valueChanged(int id, double value)
ExprChannelSlider(int id, QWidget *parent)
void paintEvent(QPaintEvent *e) override
void mousePressEvent(QMouseEvent *e) override
void addPoint(double x, KSeExpr::Vec3d y, T_INTERP interp, bool select=false)
void setSwatchColor(QColor color)
Base class for all controls for Expressions.
std::atomic< bool > _updating
virtual QColor getColor()
Interface for getting the color (used for linked color picking)
void resizeEvent(QResizeEvent *event) override
void linkStateChange(int state)
void linkDisconnect(int newId)
void controlChanged(int id)
void linkColorLink(int id)
void linkColorEdited(int id, QColor color)
ExprControl(int id, Editable *editable, bool showColorLink)
void addPoint(double x, double y, T_INTERP interp, bool select=false)
QString getExistingDirectory(const QString &caption=QString(), const QString &startWith=QString(), const QString &filter=QString())
QString getOpenFileName(const QString &caption=QString(), const QString &startWith=QString(), const QString &filter=QString())
ExprGraphPreview(QWidget *parent=nullptr)
void paintEvent(QPaintEvent *event) override
QPointF toScreen(qreal x, qreal y)
Line Editor Widget(used for numbers)
virtual void setText(const QString &t)
Generic Slider (used for int and float sliders)
void paintEvent(QPaintEvent *e) override
void mouseMoveEvent(QMouseEvent *e) override
void mousePressEvent(QMouseEvent *e) override
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.
NumberControl(int id, NumberEditable *editable)
void setValue(double value)
Update the model with the value and notify the collection.
StringEditable * _stringEditable
model for the string control
void textChanged(const QString &newText)
StringControl(int id, StringEditable *stringEditable)
QLineEdit * _edit
Edit box for the string.
void setValue(int n, double value)
set the value in the model (in response to editing from controls)
VectorControl(int id, VectorEditable *editable)
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