SeExpr
ExprControl.cpp
Go to the documentation of this file.
1/*
2* Copyright Disney Enterprises, Inc. All rights reserved.
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License
6* and the following modification to it: Section 6 Trademarks.
7* deleted and replaced with:
8*
9* 6. Trademarks. This License does not grant permission to use the
10* trade names, trademarks, service marks, or product names of the
11* Licensor and its affiliates, except as required for reproducing
12* the content of the NOTICE file.
13*
14* You may obtain a copy of the License at
15* http://www.apache.org/licenses/LICENSE-2.0
16*
17* @file ExprControl.cpp
18* @brief UI control widgets for expressions.
19* @author aselle
20*/
21#include <QRegExp>
22#include <QLineEdit>
23#include <QPushButton>
24#include <QToolButton>
25#include <QSplitter>
26#include <QLabel>
27#include <QMouseEvent>
28#include <QKeyEvent>
29#include <QHBoxLayout>
30#include <QVBoxLayout>
31#include <QPaintEvent>
32#include <QPainter>
33#include <QScrollArea>
34#include <QSpacerItem>
35#include <QSizePolicy>
36#include <QTextCharFormat>
37#include <QCompleter>
38#include <QAbstractItemView>
39#include <QStandardItemModel>
40#include <QStringListModel>
41#include <QFileDialog>
42#include <QDialogButtonBox>
43#include <QScrollBar>
44#include <QToolTip>
45#include <QListWidget>
46#include <QTreeView>
47
48#include "ExprControl.h"
49#include "ExprColorCurve.h"
50#include "ExprColorSwatch.h"
51#include "ExprFileDialog.h"
52#include "Editable.h"
53
54/* XPM */
55static const char* refreshXPM[] = {
56 "20 20 4 1", "# c #303030", "a c #585858", "b c #c3c3c3",
57 ". c #dcdcdc", "....................", "....................", "....................",
58 ".......#aaaa#.......", ".....#########......", "....###bbbbb###.....", "....##b.....b##.....",
59 "...bb#b.....b##.....", "...bbbb....aaaaaa...", "...........aaaaaa...", "....##......####....",
60 "...####......##.....", "..######............", "..aaa#aa............", "....##......bbb.....",
61 "....##b...bbbab.....", "....a#abbbb##ab.....", ".....#a####aa#b.....", ".....aaaaaaa#.b.....",
62 "...................."};
63
64/* XPM */
65static const char* graphXPM[] = {
66 "20 20 5 1", "c c #000040", "a c #303030", "# c #58a8ff",
67 ". c #dcdcdc", "b c #ff0000", "..........#a.a......", "..........#a.a.....b",
68 "..........#.a.....bb", "..........#aa....bb.", "..........#.....bb..", "..........#....bb...",
69 "..........#....bb...", "....bbb...#...bb....", "...bbbbb..#..bbb....", "...b...bbb#.bbb.....",
70 "..bb....bb#bbb......", "##bb####bbbbb#######", ".bb......bbb....c.c.", ".bb.......#......c..",
71 ".b........#.....c.c.", "bb........#.........", "b.........#.........", "..........#.........",
72 "..........#.........", "..........#........."};
73
74/* XPM */
75static const char* directoryXPM[] = {
76 "20 20 3 1", ". c None", "# c #000000", "a c #d8c59e",
77 "....................", "....................", "....................", "....................",
78 "...........#######..", "...........#aaaaa#..", "..##########aaaaa#..", "..#aaaaaaaaaaaaaa#..",
79 "..#aaaaaaaaaaaaaa#..", "..#aaaaaaaaaaaaaa#..", "..#aaaaaaaaaaaaaa#..", "..#aaaaaaaaaaaaaa#..",
80 "..#aaaaa##a##a##a#..", "..#aaaaa##a##a##a#..", "..#aaaaaaaaaaaaaa#..", "..################..",
81 "....................", "....................", "....................", "...................."};
82
83/* XPM */
84static const char* fileXPM[] = {
85 "20 20 5 1", ". c None", "# c #000000", "c c #303030",
86 "b c #a79b80", "a c #ddcdaa", "....................", "....................",
87 "....#########.......", "....#aaaaaaa##......", "....#aaaaaaa#b#.....", "....#aaaaaaa#bb#....",
88 "....#aaaaaaa####....", "....#aaaaaaaaaa#....", "....#aaaaaaaaaa#....", "....#aaaaaaaaaa#....",
89 "....#aaaaaaaaaa#....", "....#aaaaaaaaaa#....", "....#aaaaaaaaaa#....", "....#aaaaaaaaaa#....",
90 "....#aaaaaaaaaa#....", "....#accaccacca#....", "....#accaccacca#....", "....#aaaaaaaaaa#....",
91 "....############....", "...................."};
92
93void ExprSlider::mousePressEvent(QMouseEvent* e) { mouseMoveEvent(e); }
94
95void ExprSlider::mouseMoveEvent(QMouseEvent* e) {
96 float r = maximum() - minimum();
97 float v = ((float)(e->x() - 2) * r / (width() - 5)) + minimum() + .5f;
98 int iv = std::min(std::max((int)v, minimum()), maximum());
99 setValue(iv);
100}
101
102void ExprSlider::paintEvent(QPaintEvent* e) {
103 Q_UNUSED(e);
104 QPainter p(this);
105
106 float v = value();
107 float r = maximum() - minimum();
108 int linepos = (int)((v - minimum()) / r * (width() - 5) + 2);
109
110 QColor qcol = palette().color(QPalette::Dark);
111 QColor bcol = palette().color(QPalette::Midlight);
112 QColor dcol = bcol.lighter(140);
113 QColor bgcol = palette().color(QPalette::Base);
114
115 if (underMouse()) {
116 bcol = bcol.lighter(110);
117 bgcol = bgcol.lighter(110);
118 int mx = mapFromGlobal(QCursor::pos()).x();
119 if (abs(linepos - mx) < 4) dcol = dcol.lighter(200);
120 }
121
122 p.fillRect(1, 1, width() - 1, height() - 2, bgcol);
123 p.fillRect(1, 1, linepos - 1, height() - 2, bcol);
124
125 QPen pen = p.pen();
126
127 pen.setColor(dcol);
128 p.setPen(pen);
129 pen.setWidth(3);
130 p.setPen(pen);
131 p.drawLine(linepos, 2, linepos, height() - 2);
132 pen.setWidth(1);
133 pen.setColor(qcol);
134 p.setPen(pen);
135 p.drawLine(linepos - 2, 1, linepos - 2, height() - 1);
136 p.drawLine(linepos + 2, 1, linepos + 2, height() - 1);
137
138 pen.setWidth(1);
139 pen.setColor(qcol);
140 p.setPen(pen);
141 p.drawRect(0, 0, width() - 1, height() - 1);
142}
143
144ExprChannelSlider::ExprChannelSlider(int id, QWidget* parent) : QWidget(parent), _id(id), _value(0) {}
145
146void ExprChannelSlider::paintEvent(QPaintEvent* e) {
147 Q_UNUSED(e);
148 if (_value < 0 || _value > 1) return;
149 int x = int(_value * (width() - 3) + 0.5);
150 QPainter p(this);
151 p.fillRect(contentsRect(), _col);
152 p.fillRect(x, 0, 3, height(), QColor(64, 64, 64));
153}
154
156
157void ExprChannelSlider::mouseMoveEvent(QMouseEvent* e) { setValue(clamp(float(e->x() - 1) / (width() - 3), 0, 1)); }
158
160 if (value == _value) return;
161 _value = value;
162 emit valueChanged(_id, value);
163 update();
164}
165
166ExprControl::ExprControl(int id, Editable* editable, bool showColorLink)
167 : _id(id), _updating(false), _editable(editable) {
168 hbox = new QHBoxLayout(this);
169 hbox->setSpacing(2);
170 hbox->setMargin(0);
171
172 _colorLinkCB = new QCheckBox(this);
173 _colorLinkCB->setFixedWidth(14);
174 _colorLinkCB->setFocusPolicy(Qt::NoFocus);
175 connect(_colorLinkCB, SIGNAL(stateChanged(int)), this, SLOT(linkStateChange(int)));
176 hbox->addWidget(_colorLinkCB);
177
178 _label = new QLabel(QString("<b>") + editable->name.c_str() + "</b>");
179 _label->setFixedWidth(72);
180 _label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
181 _label->setIndent(2);
182 _label->setAutoFillBackground(true);
183 hbox->addWidget(_label);
184
185 if (!showColorLink) {
186 _colorLinkCB->setHidden(true);
187 _label->setFixedWidth(84);
188 } else {
189 _colorLinkCB->setHidden(false);
190 _label->setFixedWidth(84 - _colorLinkCB->width() + 2);
191 }
192}
193
195 if (_updating) return;
196
197 if (state == Qt::Checked) {
198 emit linkColorLink(_id);
200 } else {
201 emit linkColorLink(-1);
202 }
203}
204
206 if (newId != _id) {
207 _updating = 1;
208 _colorLinkCB->setChecked(false);
209 _updating = 0;
210 }
211}
212
214 : ExprControl(id, editable, false), _numberEditable(editable) {
215
216 // slider
217 float smin = editable->min, smax = editable->max;
218 if (!_numberEditable->isInt) {
219 smin *= 1e5;
220 smax *= 1e5;
221 }
222 float srange = smax - smin;
223 _slider = new ExprSlider(Qt::Horizontal, this);
224 _slider->setRange(int(smin), int(smax));
225 _slider->setTickInterval(std::max(1, int(srange / 10)));
226 _slider->setSingleStep(std::max(1, int(srange / 50)));
227 _slider->setPageStep(std::max(1, int(srange / 10)));
228 _slider->setMinimumWidth(0);
229 _slider->setFixedHeight(16);
230 _slider->setFocusPolicy(Qt::ClickFocus);
231 hbox->addWidget(_slider, 3);
232 // edit box
233 _edit = new ExprLineEdit(0, this);
234 _edit->setMinimumWidth(0);
235 _edit->setFixedHeight(16);
236 hbox->addWidget(_edit);
237 connect(_edit, SIGNAL(textChanged(int, const QString&)), SLOT(editChanged(int, const QString&)));
238 connect(_slider, SIGNAL(valueChanged(int)), SLOT(sliderChanged(int)));
239 // show current values
241}
242
244 if (_updating) return;
246}
247
248void NumberControl::editChanged(int id, const QString& text) {
249 Q_UNUSED(id);
250 if (_updating) return;
251 bool ok = 0;
252 float val = text.toFloat(&ok);
253 if (!ok) return;
254 setValue(val);
255}
256
258 _updating = 1;
259 int sliderval = int(_numberEditable->isInt ? _numberEditable->v : _numberEditable->v * 1e5);
260 if (sliderval != _slider->value()) _slider->setValue(sliderval);
261 _edit->setText(QString("%1").arg(_numberEditable->v, 0, 'f', _numberEditable->isInt ? 0 : 3));
262 _updating = 0;
263}
264
266 // std::cerr<<"In setValue "<<_id<<value<<std::endl;
267 if (fabs(_numberEditable->v - value) < 1e-5) return;
270 emit controlChanged(_id);
271}
272
274 : ExprControl(id, editable, true), _numberEditable(editable) {
275
277 _swatch = new ExprCSwatchFrame(editable->v);
278 _swatch->setFixedWidth(38);
279 _swatch->setFixedHeight(20);
280 connect(_swatch, SIGNAL(swatchChanged(QColor)), this, SLOT(swatchChanged(QColor)));
281 hbox->addWidget(_swatch);
282 }
283 for (int i = 0; i < 3; i++) {
284 QVBoxLayout* vbl = new QVBoxLayout();
285 hbox->addLayout(vbl);
286 vbl->setMargin(0);
287 vbl->setSpacing(0);
288
289 ExprLineEdit* edit = new ExprLineEdit(i, this);
290 vbl->addWidget(edit);
291 _edits[i] = edit;
292 edit->setMinimumWidth(0);
293 edit->setFixedHeight(16);
294
295 ExprChannelSlider* slider = new ExprChannelSlider(i, this);
296 vbl->addWidget(slider);
297 _sliders[i] = slider;
298 slider->setFixedHeight(6);
299 // set color
300 static const QColor rgb[3] = {QColor(128, 64, 64), QColor(64, 128, 64), QColor(64, 64, 128)};
301 if (_numberEditable->isColor) slider->setDisplayColor(rgb[i]);
302
303 connect(edit, SIGNAL(textChanged(int, const QString&)), SLOT(editChanged(int, const QString&)));
304 connect(slider, SIGNAL(valueChanged(int, float)), SLOT(sliderChanged(int, float)));
305 }
306 // update controls
308}
309
311 Q_UNUSED(gah);
313 setValue(0, color[0]);
314 setValue(1, color[1]);
315 setValue(2, color[2]);
316}
317
319 return QColor::fromRgbF(
320 clamp(_numberEditable->v[0], 0, 1), clamp(_numberEditable->v[1], 0, 1), clamp(_numberEditable->v[2], 0, 1));
321}
322
323void VectorControl::setColor(QColor color) {
324 setValue(0, color.redF());
325 setValue(1, color.greenF());
326 setValue(2, color.blueF());
327}
328
330 if (_updating) return;
333}
334
335void VectorControl::editChanged(int id, const QString& text) {
336 if (_updating) return;
337 bool ok = 0;
338 float val = text.toFloat(&ok);
339 if (!ok) return;
340 setValue(id, val);
341}
342
344 // //std::cerr<<"In update control "<<_id<<std::endl;
345 _updating = 1;
346 for (unsigned int i = 0; i < 3; i++) _edits[i]->setText(QString("%1").arg(_numberEditable->v[i], 0, 'f', 3));
348 for (unsigned int i = 0; i < 3; i++) {
349 _sliders[i]->setValue((_numberEditable->v[i] - min) / (max - min));
350 }
352 // std::cerr<<"trying to set color"<<std::endl;
354 float r = clamp(val[0], 0, 1);
355 float g = clamp(val[1], 0, 1);
356 float b = clamp(val[2], 0, 1);
357 float lum = r * .2 + g * .7 + b * .1;
358 // std::cerr<<" rgb "<<r<<" "<<g<<" "<<b<<std::endl;
359 QPalette pal = palette();
360 pal.setColor(QPalette::Window, QColor(int(r * 255), int(g * 255), int(b * 255)));
361 pal.setColor(QPalette::WindowText, (lum < 0.5) ? QColor(255, 255, 255) : QColor(0, 0, 0));
362 _label->setPalette(pal);
363 }
364 _updating = 0;
365}
366
367void VectorControl::setValue(int n, float value) {
368 if (n < 0 || n >= 3) return;
369 if (fabs(_numberEditable->v[n] - value) < 1e-5) return;
370 _numberEditable->v[n] = value;
373 emit controlChanged(_id);
374}
375
377 : ExprControl(id, editable, false), _stringEditable(editable) {
378 // make line edit
379 _edit = new QLineEdit();
380 _edit->setFixedHeight(20);
381 connect(_edit, SIGNAL(textChanged(const QString&)), SLOT(textChanged(const QString&)));
382 // make a button if we are a file or directory
383 if (_stringEditable->type == "file" || _stringEditable->type == "directory") {
384 QPushButton* button = new QPushButton();
385 button->setFixedSize(20, 20);
386
387 hbox->addWidget(_edit, 3);
388 hbox->addWidget(button, 1);
389 if (_stringEditable->type == "directory") {
390 connect(button, SIGNAL(clicked()), SLOT(directoryBrowse()));
391 button->setIcon(QIcon(QPixmap(directoryXPM)));
392 } else if (_stringEditable->type == "file") {
393 connect(button, SIGNAL(clicked()), SLOT(fileBrowse()));
394 button->setIcon(QIcon(QPixmap(fileXPM)));
395 }
396
397 } else {
398 hbox->addWidget(_edit, 3);
399 }
400 // update controls
402}
403
405 ExprFileDialog dialog(this);
406 dialog.setPreview();
407 QString newFilename =
408 dialog.getOpenFileName("Please choose a file", _edit->text(), tr("Images (*.tif *.tx *.jpg *.ptx *.png)"));
409 if (newFilename != "") _edit->setText(newFilename);
410}
411
413 ExprFileDialog dialog(this);
414 dialog.setPreview();
415 QString newFilename = dialog.getExistingDirectory("Please choose a file", _edit->text());
416 if (newFilename != "") _edit->setText(newFilename);
417}
418
420
421void StringControl::textChanged(const QString& newText) {
422 if (_updating) return;
423 _stringEditable->v = newText.toStdString();
424 emit controlChanged(_id);
425}
426
428 : ExprControl(id, editable, false), _curveEditable(editable) {
429 _curve = new ExprCurve(this, "Pos:", "Val:", "Interp:");
430 _curve->setFixedHeight(80);
431
432 const int numVal = _curveEditable->cvs.size();
433 for (int i = 0; i < numVal; i++) {
435 _curve->addPoint(cv._pos, cv._val, cv._interp);
436 }
437 hbox->addWidget(_curve, 3);
438 connect(_curve->_scene, SIGNAL(curveChanged()), SLOT(curveChanged()));
439 // unneded? updateControl();
440}
441
443 if (_curve && _curveEditable) {
445 emit controlChanged(_id);
446 }
447}
448
450 : ExprControl(id, editable, true), _curveEditable(editable) {
451 _curve = new ExprColorCurve(this, "Pos:", "Val:", "Interp:");
452 _curve->setFixedHeight(80);
453
454 const int numVal = _curveEditable->cvs.size();
455 for (int i = 0; i < numVal; i++) {
457 _curve->addPoint(cv._pos, cv._val, cv._interp);
458 }
459 hbox->addWidget(_curve, 3);
460 connect(_curve->_scene, SIGNAL(curveChanged()), SLOT(curveChanged()));
461 // unneeded? updateControl();
462}
463
465 if (_curve && _curveEditable) {
467 emit controlChanged(_id);
468 }
469}
470
472
473void CCurveControl::setColor(QColor color) { _curve->setSwatchColor(color); }
474
475struct ExprGraphPreview : public QWidget {
476 std::vector<float> x, y;
477 std::vector<float> cpx, cpy;
478 float xmin, xmax, ymin, ymax, dx, dy;
479 ;
481 ;
482 ExprGraphPreview(QWidget* parent = 0) : QWidget(parent) {
483 win_xmin = -1.;
484 win_xmax = 2.;
485 win_ymin = -1;
486 win_ymax = 2.;
487 }
488
489 QPointF toScreen(float x, float y) { return QPointF((x - win_xmin) * win_dx, height() - (y - win_ymin) * win_dy); }
490
491 void paintEvent(QPaintEvent* event) {
492 QWidget::paintEvent(event);
493 QPainter painter(this);
494 painter.setRenderHint(QPainter::Antialiasing, true);
495 painter.setPen(QColor(255, 255, 255));
496 win_xmin = xmin;
497 win_xmax = xmax;
498 win_ymin = ymin;
499 win_ymax = ymax;
500 float percentXpad = .1 * (win_xmax - win_xmin);
501 float percentYpad = .1 * (win_ymax - win_ymin);
502 win_xmin -= percentXpad;
503 win_xmax += percentXpad;
504 win_ymin -= percentYpad;
505 win_ymax += percentYpad;
506
507 // make space for text
508 int x_pad_in_pixels = 25, y_pad_in_pixels = 15;
509 float xpad = x_pad_in_pixels * (win_xmax - win_xmin) / (width() - x_pad_in_pixels);
510 float ypad = y_pad_in_pixels * (win_ymax - win_ymin) / (height() - y_pad_in_pixels);
511 win_ymin -= ypad;
512 win_xmax += xpad;
513
514 win_dx = width() / (win_xmax - win_xmin);
515 win_dy = height() / (win_ymax - win_ymin);
516
517 // int h=height();
518 QPainterPath path;
519 QRectF fullarea(toScreen(win_xmin, win_ymax), toScreen(win_xmax, win_ymin));
520 QBrush darkbrush(QColor(100, 100, 100), Qt::SolidPattern);
521 QRectF area(toScreen(xmin, ymax), toScreen(xmax, ymin));
522 QBrush brush(QColor(150, 150, 150), Qt::SolidPattern);
523 // painter.fillRect(fullarea,darkbrush);
524 // painter.setBrush(darkbrush);
525 // painter.drawRoundedRect(fullarea,3,3);
526 // painter.setBrush(QBrush());
527 painter.fillRect(area, brush);
528 if (x.size() > 0) {
529 path.moveTo(toScreen(x[0], y[0]));
530 for (int i = 1; i < (int)x.size(); i++) path.lineTo(toScreen(x[i], y[i]));
531 }
532 QRectF right(toScreen(xmax, ymax), toScreen(win_xmax, ymin));
533 QRectF bottom(toScreen(xmin, ymin), toScreen(xmax, win_ymin));
534
535 painter.setPen(QColor(75, 50, 50));
536 painter.drawPath(path);
537
538 painter.setPen(QPen());
539 painter.drawText(right, Qt::AlignTop | Qt::AlignLeft, QString("%1").arg(ymax, 0, 'f', 1));
540 painter.drawText(right, Qt::AlignBottom | Qt::AlignLeft, QString("%1").arg(ymin, 0, 'f', 1));
541 painter.drawText(bottom, Qt::AlignTop | Qt::AlignLeft, QString("%1").arg(xmin, 0, 'f', 1));
542 painter.drawText(bottom, Qt::AlignTop | Qt::AlignRight, QString("%1").arg(xmax, 0, 'f', 1));
543
544 painter.setBrush(QBrush(QColor(0, 0, 0), Qt::SolidPattern));
545 for (size_t i = 0; i < cpx.size(); i++) {
546 painter.drawEllipse(toScreen(cpx[i], cpy[i]), 2, 2);
547 }
548 }
549
550#ifdef SEEXPR_USE_ANIMLIB
551 void sample(const animlib::AnimCurve& curve) {
552 int numKeys = curve.getNumKeys();
553 x.clear();
554 y.clear();
555 cpx.clear();
556 cpy.clear();
557 if (numKeys > 0) {
558 const animlib::AnimKeyframe* key = &*curve.getFirstKey();
559 xmin = key[0].getTime();
560 xmax = key[numKeys - 1].getTime();
561 ymin = FLT_MAX;
562 ymax = -FLT_MAX;
563
564 for (int i = 0; i < numKeys; i++) {
565 cpx.push_back(key[i].getTime());
566 cpy.push_back(key[i].getValue());
567 }
568
569 int nsamples = 100;
570 float dx = (xmax - xmin) / nsamples;
571 float xeval = xmin;
572 for (int i = 0; i < nsamples; i++) {
573 x.push_back(xeval);
574 float yeval = curve.getValue(xeval);
575 ymin = std::min(ymin, yeval);
576 ymax = std::max(ymax, yeval);
577 y.push_back(yeval);
578 xeval += dx;
579 }
580 // pad window AFTER sampling
581 // std::cerr<<"we have xmin xmax ymin ymax "<<xmin<<" "<<xmax<<" "<<ymin<<" "<<ymax<<std::endl;
582 } else {
583 xmin = -1;
584 xmax = 1;
585 ymin = -1;
586 ymax = 1;
587 }
588 // std::cerr<<"we have xmin xmax ymin ymax "<<xmin<<" "<<xmax<<" "<<ymin<<" "<<ymax<<std::endl;
589 }
590#endif
591};
592
594 : ExprControl(id, editable, false), _editable(editable) {
595
597 _preview->setMinimumWidth(200);
598 _preview->setMinimumHeight(60);
599 hbox->addWidget(_preview);
600 // QPushButton* button=new QPushButton();
601 // button->setIcon(QIcon(QPixmap(graphXPM)));
602 Q_UNUSED(graphXPM)
603 QPushButton* refreshButton = new QPushButton();
604 refreshButton->setMaximumWidth(30);
605 refreshButton->setIcon(QIcon(QPixmap(refreshXPM)));
606 QPushButton* expandButton = new QPushButton(">");
607 expandButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
608 expandButton->setFixedWidth(15);
609 hbox->addWidget(expandButton);
610 // hbox->addWidget(button);
611 refreshButton->setVisible(_editable->link != "");
612 hbox->addWidget(refreshButton);
613
614#ifdef SEEXPR_USE_ANIMLIB
615 _preview->sample(editable->curve);
616#endif
617 connect(expandButton, SIGNAL(clicked()), this, SLOT(editGraphClicked()));
618 // connect(_preview,SIGNAL(clicked()),this,SLOT(editGraphClicked()));
619 connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshClicked()));
620}
621
622#ifdef SEEXPR_USE_ANIMLIB
623#include <CE/CETool.h>
624#endif
625
627 if (callback) {
628#ifdef SEEXPR_USE_ANIMLIB
630 _preview->sample(_editable->curve);
631 _preview->repaint();
632 emit controlChanged(_id);
633#endif
634 }
635}
636
638#ifdef SEEXPR_USE_ANIMLIB
639 QDialog* dialog = new QDialog(this);
640 CETool* tool = new CETool;
641 animlib::AnimAttrID attr1("", "");
642 animlib::AnimCurve& anim = *new animlib::AnimCurve(attr1);
643 anim = _editable->curve;
644
645 QWidget* widg;
646 tool->map(widg, 0);
647 QVBoxLayout* layout = new QVBoxLayout();
648 dialog->resize(QSize(1024, 640));
649 dialog->setLayout(layout);
650 layout->addWidget(widg);
651 tool->addCurve(&anim);
652
653 QDialogButtonBox* buttonbar = new QDialogButtonBox();
654 buttonbar->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
655 connect(buttonbar, SIGNAL(accepted()), dialog, SLOT(accept()));
656 connect(buttonbar, SIGNAL(rejected()), dialog, SLOT(reject()));
657 layout->addWidget(buttonbar);
658
659 if (dialog->exec() == QDialog::Accepted) {
660 // copy points back from child
661 _editable->curve = anim;
662 _preview->sample(_editable->curve);
663 _preview->repaint();
664 emit controlChanged(_id);
665 }
666#endif
667}
668
669void AnimCurveControl::setAnimCurveCallback(AnimCurveCallback newCallback) { callback = newCallback; }
670
672
673// Editing widget for color swatch
675 : ExprControl(id, editable, false), _swatchEditable(editable), _indexLabel(false) {
676 // include index labels if user specifies 'indices' as labelType
677 if (_swatchEditable->labelType == "indices") _indexLabel = true;
679}
680
682 if (_updating) return;
683 if (index >= 0 && index < int(_swatchEditable->colors.size())) _swatchEditable->change(index, value);
684 emit controlChanged(_id);
685}
686
688 if (_updating) return;
689 if (index >= 0 && index <= int(_swatchEditable->colors.size()))
690 _swatchEditable->add(value); // add to end; TODO insert
691 emit controlChanged(_id);
692}
693
695 if (_updating) return;
696 if (index >= 0 && index < int(_swatchEditable->colors.size())) {
698 _swatch->deleteLater();
699 _swatch = 0;
701 }
702 emit controlChanged(_id);
703}
704
707 connect(_swatch, SIGNAL(swatchChanged(int, SeExpr2::Vec3d)), this, SLOT(colorChanged(int, SeExpr2::Vec3d)));
708 connect(_swatch, SIGNAL(swatchAdded(int, SeExpr2::Vec3d)), this, SLOT(colorAdded(int, SeExpr2::Vec3d)));
709 connect(_swatch, SIGNAL(swatchRemoved(int)), this, SLOT(colorRemoved(int)));
710
711 _updating = true;
712 for (unsigned int i = 0; i < _swatchEditable->colors.size(); i++) {
714 _swatch->addSwatch(val, i);
715 }
716 _updating = false;
717 hbox->addWidget(_swatch);
718}
719
721 : ExprControl(id, editable, false), _deepWaterEditable(editable) {
722 _deepWater = new ExprDeepWater(this);
723 _deepWater->setParams(editable->params);
724
725 hbox->addWidget(_deepWater, 3);
726 connect(_deepWater->_scene, SIGNAL(deepWaterChanged()), SLOT(deepWaterChanged()));
727}
728
732 emit controlChanged(_id);
733 }
734}
static const char * refreshXPM[]
Definition: ExprControl.cpp:55
static const char * directoryXPM[]
Definition: ExprControl.cpp:75
static const char * graphXPM[]
Definition: ExprControl.cpp:65
static const char * fileXPM[]
Definition: ExprControl.cpp:84
static const int p[514]
Definition: NoiseTables.h:20
static AnimCurveCallback callback
Definition: ExprControl.h:303
AnimCurveEditable * _editable
Definition: ExprControl.h:286
static void setAnimCurveCallback(AnimCurveCallback callback)
AnimCurveControl(int id, AnimCurveEditable *curveEditable)
ExprGraphPreview * _preview
Definition: ExprControl.h:287
void(* AnimCurveCallback)(const std::string &, animlib::AnimCurve &curve)
Definition: ExprControl.h:291
CCurveControl(int id, ColorCurveEditable *stringEditable)
void setColor(QColor color)
Interface for setting the color (used for linked color picking)
void curveChanged()
QColor getColor()
Interface for getting the color (used for linked color picking)
ColorCurveEditable * _curveEditable
color curve model
Definition: ExprControl.h:268
ExprColorCurve * _curve
color curve widget
Definition: ExprControl.h:270
std::vector< T_CURVE::CV > _cvs
void colorRemoved(int index)
ColorSwatchEditable * _swatchEditable
model for the color swatches control
Definition: ExprControl.h:311
ExprColorSwatchWidget * _swatch
Edit box for the color swatches.
Definition: ExprControl.h:313
void colorAdded(int index, SeExpr2::Vec3d value)
void colorChanged(int index, SeExpr2::Vec3d value)
ColorSwatchControl(int id, ColorSwatchEditable *swatchEditable)
void curveChanged()
CurveControl(int id, CurveEditable *stringEditable)
ExprCurve * _curve
curve edit widget
Definition: ExprControl.h:254
CurveEditable * _curveEditable
curve model
Definition: ExprControl.h:252
std::vector< T_CURVE::CV > _cvs
Definition: ExprCurve.h:88
DeepWaterControl(int id, DeepWaterEditable *stringEditable)
ExprDeepWater * _deepWater
deep water widget
Definition: ExprControl.h:335
DeepWaterEditable * _deepWaterEditable
curve model
Definition: ExprControl.h:333
SeDeepWaterParams params
SeExpr2::Vec3d getValue() const
void setValue(const SeExpr2::Vec3d &value)
Channel Slider (i.e. for colors)
Definition: ExprControl.h:146
void valueChanged(int id, float value)
void setValue(float value)
float value() const
Definition: ExprControl.h:154
ExprChannelSlider(int id, QWidget *parent)
virtual void mousePressEvent(QMouseEvent *e)
void setDisplayColor(QColor c)
Definition: ExprControl.h:155
virtual void paintEvent(QPaintEvent *e)
virtual void mouseMoveEvent(QMouseEvent *e)
QColor getSwatchColor()
void addPoint(const double x, const SeExpr2::Vec3d y, const T_INTERP interp, bool select=false)
void setSwatchColor(QColor color)
CCurveScene * _scene
void addSwatch(SeExpr2::Vec3d &val, int index=-1)
Base class for all controls for Expressions.
Definition: ExprControl.h:54
QCheckBox * _colorLinkCB
Definition: ExprControl.h:61
QHBoxLayout * hbox
Definition: ExprControl.h:60
virtual QColor getColor()
Interface for getting the color (used for linked color picking)
Definition: ExprControl.h:71
void linkStateChange(int state)
void linkDisconnect(int newId)
QLabel * _label
Definition: ExprControl.h:62
void controlChanged(int id)
void linkColorLink(int id)
void linkColorEdited(int id, QColor color)
ExprControl(int id, Editable *editable, bool showColorLink)
bool _updating
Definition: ExprControl.h:59
void addPoint(const double x, const double y, const T_INTERP interp, bool select=false)
Definition: ExprCurve.cpp:442
CurveScene * _scene
Definition: ExprCurve.h:133
DeepWaterScene * _scene
void setParams(const SeDeepWaterParams &params)
QString getOpenFileName(const QString &caption=QString::null, const QString &startWith=QString::null, const QString &filter=QString::null)
QString getExistingDirectory(const QString &caption=QString::null, const QString &startWith=QString::null, const QString &filter=QString::null)
Line Editor Widget(used for numbers)
Definition: ExprControl.h:104
virtual void setText(const QString &t)
Definition: ExprControl.h:108
Generic Slider (used for int and float sliders)
Definition: ExprControl.h:126
virtual void paintEvent(QPaintEvent *e)
virtual void mouseMoveEvent(QMouseEvent *e)
Definition: ExprControl.cpp:95
virtual void mousePressEvent(QMouseEvent *e)
Definition: ExprControl.cpp:93
NumberEditable * _numberEditable
Pointer to the number control model.
Definition: ExprControl.h:175
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.
Definition: ExprControl.h:179
void sliderChanged(int val)
ExprSlider * _slider
Slider for the number.
Definition: ExprControl.h:177
NumberControl(int id, NumberEditable *number)
void setValue(float value)
Update the model with the value and notify the collection.
void updateControl()
void directoryBrowse()
StringEditable * _stringEditable
model for the string control
Definition: ExprControl.h:231
void textChanged(const QString &newText)
StringControl(int id, StringEditable *stringEditable)
QLineEdit * _edit
Edit box for the string.
Definition: ExprControl.h:233
ExprLineEdit * _edits[3]
All three line edit widgets (for each component)
Definition: ExprControl.h:202
QColor getColor()
Interface for getting the color (used for linked color picking)
void updateControl()
update the individual slider and eidt box controls
void editChanged(int id, const QString &text)
void setColor(QColor color)
Interface for setting the color (used for linked color picking)
void sliderChanged(int id, float val)
void setValue(int id, float value)
set the value in the model (in response to editing from controls)
void swatchChanged(QColor color)
ExprChannelSlider * _sliders[3]
All three channel sliders (for each component)
Definition: ExprControl.h:206
VectorEditable * _numberEditable
Number model.
Definition: ExprControl.h:200
VectorControl(int id, VectorEditable *number)
ExprCSwatchFrame * _swatch
Definition: ExprControl.h:203
double max(double x, double y)
Definition: ExprBuiltins.h:42
double clamp(double x, double lo, double hi)
Definition: ExprBuiltins.h:40
double min(double x, double y)
Definition: ExprBuiltins.h:43
SeExpr2::CurveFuncX curve
std::string link
Definition: Editable.h:217
std::vector< SeExpr2::Vec3d > colors
Definition: Editable.h:275
void remove(int index)
Definition: Editable.h:317
std::string labelType
Definition: Editable.h:276
void add(const SeExpr2::Vec3d &value)
Definition: Editable.h:313
void change(int index, const SeExpr2::Vec3d &value)
Definition: Editable.h:315
SeDeepWaterParams params
Definition: Editable.h:328
std::string name
Definition: Editable.h:41
void paintEvent(QPaintEvent *event)
std::vector< float > cpy
ExprGraphPreview(QWidget *parent=0)
std::vector< float > cpx
QPointF toScreen(float x, float y)
std::vector< float > x
std::vector< float > y
std::vector< CV > cvs
Definition: Editable.h:175
double min
Definition: Editable.h:62
double max
Definition: Editable.h:62
double v
Definition: Editable.h:61
double _pos
Definition: Curve.h:53
InterpType _interp
Definition: Curve.h:55
std::string v
Definition: Editable.h:135
std::string type
Definition: Editable.h:136
double min
Definition: Editable.h:103
SeExpr2::Vec3d v
Definition: Editable.h:102
double max
Definition: Editable.h:103
</pre >< h3 > A simple variable reference</h3 > This is not a very interesting subclass of expression until we add some additional variables Variables on some applications may be very dynamic In this we only need x
Definition: tutorial.txt:108
Between a and b
Definition: userdoc.txt:180
The result is computed int int< br >< div style="margin-left: 40px;"> Picks values randomly between loRange and hiRange based on supplied index(which is automatically hashed). &nbsp
For any rgb or hsl value(except for negative s values)
</pre > To parallelize evaluation per a simple parallel_for can be p blocked_range r
Definition: varblocks.txt:76