36#include <QTextCharFormat>
38#include <QAbstractItemView>
39#include <QStandardItemModel>
40#include <QStringListModel>
42#include <QDialogButtonBox>
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 "...................."};
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 "..........#.........",
"..........#........."};
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 "....................",
"....................",
"....................",
"...................."};
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 "....############....",
"...................."};
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());
107 float r = maximum() - minimum();
108 int linepos = (int)((v - minimum()) /
r * (width() - 5) + 2);
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);
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);
122 p.fillRect(1, 1, width() - 1, height() - 2, bgcol);
123 p.fillRect(1, 1, linepos - 1, height() - 2, bcol);
131 p.drawLine(linepos, 2, linepos, height() - 2);
135 p.drawLine(linepos - 2, 1, linepos - 2, height() - 1);
136 p.drawLine(linepos + 2, 1, linepos + 2, height() - 1);
141 p.drawRect(0, 0, width() - 1, height() - 1);
148 if (_value < 0 || _value > 1)
return;
149 int x = int(
_value * (width() - 3) + 0.5);
151 p.fillRect(contentsRect(),
_col);
152 p.fillRect(
x, 0, 3, height(), QColor(64, 64, 64));
167 : _id(id), _updating(false), _editable(editable) {
168 hbox =
new QHBoxLayout(
this);
178 _label =
new QLabel(QString(
"<b>") + editable->
name.c_str() +
"</b>");
179 _label->setFixedWidth(72);
180 _label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
182 _label->setAutoFillBackground(
true);
185 if (!showColorLink) {
187 _label->setFixedWidth(84);
197 if (state == Qt::Checked) {
214 :
ExprControl(id, editable, false), _numberEditable(editable) {
217 float smin = editable->
min, smax = editable->
max;
222 float srange = smax - smin;
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)));
230 _slider->setFocusPolicy(Qt::ClickFocus);
234 _edit->setMinimumWidth(0);
235 _edit->setFixedHeight(16);
237 connect(
_edit, SIGNAL(textChanged(
int,
const QString&)), SLOT(
editChanged(
int,
const QString&)));
252 float val = text.toFloat(&ok);
274 :
ExprControl(id, editable, true), _numberEditable(editable) {
283 for (
int i = 0; i < 3; i++) {
284 QVBoxLayout* vbl =
new QVBoxLayout();
285 hbox->addLayout(vbl);
290 vbl->addWidget(edit);
292 edit->setMinimumWidth(0);
293 edit->setFixedHeight(16);
296 vbl->addWidget(slider);
298 slider->setFixedHeight(6);
300 static const QColor rgb[3] = {QColor(128, 64, 64), QColor(64, 128, 64), QColor(64, 64, 128)};
303 connect(edit, SIGNAL(textChanged(
int,
const QString&)), SLOT(
editChanged(
int,
const QString&)));
304 connect(slider, SIGNAL(valueChanged(
int,
float)), SLOT(
sliderChanged(
int,
float)));
319 return QColor::fromRgbF(
338 float val = text.toFloat(&ok);
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++) {
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;
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));
368 if (n < 0 || n >= 3)
return;
377 :
ExprControl(id, editable, false), _stringEditable(editable) {
379 _edit =
new QLineEdit();
380 _edit->setFixedHeight(20);
384 QPushButton* button =
new QPushButton();
385 button->setFixedSize(20, 20);
388 hbox->addWidget(button, 1);
393 connect(button, SIGNAL(clicked()), SLOT(
fileBrowse()));
394 button->setIcon(QIcon(QPixmap(
fileXPM)));
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);
416 if (newFilename !=
"")
_edit->setText(newFilename);
428 :
ExprControl(id, editable, false), _curveEditable(editable) {
430 _curve->setFixedHeight(80);
433 for (
int i = 0; i < numVal; i++) {
450 :
ExprControl(id, editable, true), _curveEditable(editable) {
452 _curve->setFixedHeight(80);
455 for (
int i = 0; i < numVal; i++) {
476 std::vector<float>
x,
y;
492 QWidget::paintEvent(event);
493 QPainter painter(
this);
494 painter.setRenderHint(QPainter::Antialiasing,
true);
495 painter.setPen(QColor(255, 255, 255));
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);
520 QBrush darkbrush(QColor(100, 100, 100), Qt::SolidPattern);
522 QBrush brush(QColor(150, 150, 150), Qt::SolidPattern);
527 painter.fillRect(area, brush);
530 for (
int i = 1; i < (int)
x.size(); i++) path.lineTo(
toScreen(
x[i],
y[i]));
535 painter.setPen(QColor(75, 50, 50));
536 painter.drawPath(path);
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));
544 painter.setBrush(QBrush(QColor(0, 0, 0), Qt::SolidPattern));
545 for (
size_t i = 0; i <
cpx.size(); i++) {
550#ifdef SEEXPR_USE_ANIMLIB
551 void sample(
const animlib::AnimCurve& curve) {
552 int numKeys = curve.getNumKeys();
558 const animlib::AnimKeyframe* key = &*curve.getFirstKey();
559 xmin = key[0].getTime();
560 xmax = key[numKeys - 1].getTime();
564 for (
int i = 0; i < numKeys; i++) {
565 cpx.push_back(key[i].getTime());
566 cpy.push_back(key[i].getValue());
572 for (
int i = 0; i < nsamples; i++) {
574 float yeval =
curve.getValue(xeval);
594 :
ExprControl(id, editable, false), _editable(editable) {
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);
612 hbox->addWidget(refreshButton);
614#ifdef SEEXPR_USE_ANIMLIB
619 connect(refreshButton, SIGNAL(clicked()),
this, SLOT(
refreshClicked()));
622#ifdef SEEXPR_USE_ANIMLIB
623#include <CE/CETool.h>
628#ifdef SEEXPR_USE_ANIMLIB
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);
647 QVBoxLayout* layout =
new QVBoxLayout();
648 dialog->resize(QSize(1024, 640));
649 dialog->setLayout(layout);
650 layout->addWidget(widg);
651 tool->addCurve(&anim);
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);
659 if (dialog->exec() == QDialog::Accepted) {
675 :
ExprControl(id, editable, false), _swatchEditable(editable), _indexLabel(false) {
721 :
ExprControl(id, editable, false), _deepWaterEditable(editable) {
static const char * refreshXPM[]
static const char * directoryXPM[]
static const char * graphXPM[]
static const char * fileXPM[]
GenericCurveEditable< double > CurveEditable
T clamp(const T val, const T2 minval, const T3 maxval)
clamp val to the specified range [minval,maxval]
static AnimCurveCallback callback
AnimCurveEditable * _editable
static void setAnimCurveCallback(AnimCurveCallback callback)
AnimCurveControl(int id, AnimCurveEditable *curveEditable)
ExprGraphPreview * _preview
void(* AnimCurveCallback)(const std::string &, animlib::AnimCurve &curve)
CCurveControl(int id, ColorCurveEditable *stringEditable)
void setColor(QColor color)
Interface for setting the color (used for linked color picking)
QColor getColor()
Interface for getting the color (used for linked color picking)
ColorCurveEditable * _curveEditable
color curve model
ExprColorCurve * _curve
color curve widget
std::vector< T_CURVE::CV > _cvs
void colorRemoved(int index)
ColorSwatchEditable * _swatchEditable
model for the color swatches control
ExprColorSwatchWidget * _swatch
Edit box for the color swatches.
void colorAdded(int index, SeExpr2::Vec3d value)
void colorChanged(int index, SeExpr2::Vec3d value)
ColorSwatchControl(int id, ColorSwatchEditable *swatchEditable)
CurveControl(int id, CurveEditable *stringEditable)
ExprCurve * _curve
curve edit widget
CurveEditable * _curveEditable
curve model
std::vector< T_CURVE::CV > _cvs
DeepWaterControl(int id, DeepWaterEditable *stringEditable)
ExprDeepWater * _deepWater
deep water widget
DeepWaterEditable * _deepWaterEditable
curve model
SeExpr2::Vec3d getValue() const
void setValue(const SeExpr2::Vec3d &value)
Channel Slider (i.e. for colors)
void valueChanged(int id, float value)
void setValue(float value)
ExprChannelSlider(int id, QWidget *parent)
virtual void mousePressEvent(QMouseEvent *e)
void setDisplayColor(QColor c)
virtual void paintEvent(QPaintEvent *e)
virtual void mouseMoveEvent(QMouseEvent *e)
void addPoint(const double x, const SeExpr2::Vec3d y, const T_INTERP interp, bool select=false)
void setSwatchColor(QColor color)
Base class for all controls for Expressions.
virtual QColor getColor()
Interface for getting the color (used for linked color picking)
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(const double x, const double y, const T_INTERP interp, bool select=false)
void setParams(const SeDeepWaterParams ¶ms)
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)
virtual void setText(const QString &t)
Generic Slider (used for int and float sliders)
virtual void paintEvent(QPaintEvent *e)
virtual void mouseMoveEvent(QMouseEvent *e)
virtual void mousePressEvent(QMouseEvent *e)
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 *number)
void setValue(float 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.
ExprLineEdit * _edits[3]
All three line edit widgets (for each component)
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)
VectorEditable * _numberEditable
Number model.
VectorControl(int id, VectorEditable *number)
ExprCSwatchFrame * _swatch
SeExpr2::CurveFuncX curve
std::vector< SeExpr2::Vec3d > colors
void add(const SeExpr2::Vec3d &value)
void change(int index, const SeExpr2::Vec3d &value)
void paintEvent(QPaintEvent *event)
ExprGraphPreview(QWidget *parent=0)
QPointF toScreen(float x, float y)
</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
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).  
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