25#include <QRadioButton>
27#include <QDialogButtonBox>
28#include <QColorDialog>
41 : QWidget(parent), count(0), showAddButton(showAddButton), editableExpression(0) {
48 QPushButton* button =
new QPushButton(
"Add Widget");
49 button->setFocusPolicy(Qt::NoFocus);
50 QHBoxLayout* buttonLayout =
new QHBoxLayout();
51 buttonLayout->insertStretch(-1, 100);
52 buttonLayout->addWidget(button, 0);
62 QVBoxLayout* verticalLayout;
63 verticalLayout =
new QVBoxLayout();
64 verticalLayout->setSpacing(3);
65 verticalLayout->setMargin(3);
66 setLayout(verticalLayout);
67 QHBoxLayout* horizontalLayout =
new QHBoxLayout();
69 horizontalLayout->addWidget(
new QLabel(
"Variable"));
71 variableName =
new QLineEdit(QString(
"$var%1").arg(count++));
74 verticalLayout->addLayout(horizontalLayout);
80 QWidget* curveTab =
new QWidget();
81 QFormLayout* curveLayout =
new QFormLayout(curveTab);
82 curveLayout->setWidget(0, QFormLayout::LabelRole,
new QLabel(
"Lookup"));
84 curveLayout->setWidget(0, QFormLayout::FieldRole,
curveLookup);
85 tabWidget->addTab(curveTab, QString(
"Curve"));
90 QWidget* colorCurveTab =
new QWidget();
91 QFormLayout* colorCurveLayout =
new QFormLayout(colorCurveTab);
92 colorCurveLayout->setWidget(0, QFormLayout::LabelRole,
new QLabel(
"Lookup"));
95 tabWidget->addTab(colorCurveTab, QString(
"Color Curve"));
100 QWidget* intTab =
new QWidget();
101 QFormLayout* intFormLayout =
new QFormLayout(intTab);
102 intFormLayout->setWidget(0, QFormLayout::LabelRole,
new QLabel(
"Default"));
103 intFormLayout->setWidget(1, QFormLayout::LabelRole,
new QLabel(
"Min"));
104 intFormLayout->setWidget(2, QFormLayout::LabelRole,
new QLabel(
"Max"));
106 intFormLayout->setWidget(0, QFormLayout::FieldRole,
intDefault);
107 intMin =
new QLineEdit(
"0");
108 intFormLayout->setWidget(1, QFormLayout::FieldRole,
intMin);
109 intMax =
new QLineEdit(
"10");
110 intFormLayout->setWidget(2, QFormLayout::FieldRole,
intMax);
111 tabWidget->addTab(intTab, QString(
"Int"));
116 QWidget* floatTab =
new QWidget();
117 QFormLayout* floatFormLayout =
new QFormLayout(floatTab);
118 floatFormLayout->setWidget(0, QFormLayout::LabelRole,
new QLabel(
"Default"));
119 floatFormLayout->setWidget(1, QFormLayout::LabelRole,
new QLabel(
"Min"));
120 floatFormLayout->setWidget(2, QFormLayout::LabelRole,
new QLabel(
"Max"));
122 floatFormLayout->setWidget(0, QFormLayout::FieldRole,
floatDefault);
124 floatFormLayout->setWidget(1, QFormLayout::FieldRole,
floatMin);
126 floatFormLayout->setWidget(2, QFormLayout::FieldRole,
floatMax);
128 tabWidget->addTab(floatTab, QString(
"Float"));
133 QWidget* vectorTab =
new QWidget();
134 QFormLayout* vectorFormLayout =
new QFormLayout(vectorTab);
135 vectorFormLayout->setWidget(0, QFormLayout::LabelRole,
new QLabel(
"Default"));
136 vectorFormLayout->setWidget(1, QFormLayout::LabelRole,
new QLabel(
"Min"));
137 vectorFormLayout->setWidget(2, QFormLayout::LabelRole,
new QLabel(
"Max"));
141 QHBoxLayout* compLayout =
new QHBoxLayout();
145 vectorFormLayout->setLayout(0, QFormLayout::FieldRole, compLayout);
147 vectorFormLayout->setWidget(1, QFormLayout::FieldRole,
vectorMin);
149 vectorFormLayout->setWidget(2, QFormLayout::FieldRole,
vectorMax);
151 tabWidget->addTab(vectorTab, QString(
"Vector"));
156 QWidget* colorTab =
new QWidget();
157 QFormLayout* colorLayout =
new QFormLayout(colorTab);
161 colorLayout->setWidget(0, QFormLayout::LabelRole,
new QLabel(
"Color"));
162 colorLayout->setWidget(0, QFormLayout::FieldRole,
colorWidget);
164 QPixmap colorPix(30, 30);
165 colorPix.fill(
color);
167 tabWidget->addTab(colorTab, QString(
"Color"));
174 QWidget* swatchTab =
new QWidget();
175 QFormLayout* swatchLayout =
new QFormLayout(swatchTab);
177 swatchLayout->setWidget(0, QFormLayout::LabelRole,
new QLabel(
"Lookup"));
178 swatchLayout->setWidget(0, QFormLayout::FieldRole,
swatchLookup);
182 swatchLayout->setWidget(1, QFormLayout::LabelRole,
new QLabel(
"Colors"));
184 swatchLayout->setWidget(2, QFormLayout::LabelRole,
new QLabel(
""));
185 swatchLayout->setWidget(2, QFormLayout::FieldRole,
grayPaletteBtn);
186 tabWidget->addTab(swatchTab, QString(
"Swatch"));
191 QWidget* stringTab =
new QWidget();
192 QFormLayout* stringLayout =
new QFormLayout(stringTab);
200 stringLayout->setWidget(0, QFormLayout::LabelRole,
new QLabel(
"String Name"));
202 stringLayout->setWidget(1, QFormLayout::LabelRole,
new QLabel(
"String Type"));
204 stringLayout->setWidget(2, QFormLayout::LabelRole,
new QLabel(
"String Default"));
207 tabWidget->addTab(stringTab, QString(
"String"));
212 QWidget* curveTab =
new QWidget();
213 QFormLayout* curveLayout =
new QFormLayout(curveTab);
214 curveLayout->setWidget(0, QFormLayout::LabelRole,
new QLabel(
"Lookup"));
215 curveLayout->setWidget(1, QFormLayout::LabelRole,
new QLabel(
"Link"));
219 curveLayout->setWidget(1, QFormLayout::FieldRole,
animCurveLink);
220 tabWidget->addTab(curveTab, QString(
"AnimCurve"));
225 QWidget* deepWaterTab =
new QWidget();
226 QFormLayout* deepWaterLayout =
new QFormLayout(deepWaterTab);
227 deepWaterLayout->setWidget(0, QFormLayout::LabelRole,
new QLabel(
"Lookup"));
229 deepWaterLayout->setWidget(0, QFormLayout::FieldRole,
deepWaterLookup);
230 tabWidget->addTab(deepWaterTab, QString(
"Deep Water"));
235 QDialogButtonBox* buttonBox =
new QDialogButtonBox();
236 buttonBox->setOrientation(Qt::Horizontal);
237 buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
239 verticalLayout->addWidget(buttonBox);
241 QObject::connect(buttonBox, SIGNAL(accepted()),
this, SLOT(accept()));
242 QObject::connect(buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
249 if (
color.isValid()) {
250 QPixmap colorPix(30, 30);
251 colorPix.fill(
color);
252 ((QPushButton*)sender())->setIcon(QIcon(colorPix));
258 return (
"[1,0,0],[1,.6,0],[1,1,0],[0,1,0],[0,1,1],[0,0,1],[.6,.1,.6],[1,0,1],[1,1,1],[0,0,0]");
261 "[1,1,1],[.9,.9,.9],[.8,.8,.8],[.7,.7,.7],[.6,.6,.6],[.5,.5,.5],[.4,.4,.4],[.3,.3,.3],[.2,.2,.2],[0,0,0]");
263 return (
"[1,1,1],[.5,.5,.5],[0,0,0]");
268 if (dialog->exec()) {
270 switch (dialog->
tabWidget->currentIndex()) {
272 s = QString(
"%1 = curve(%2,0,0,4,1,1,4);\n").arg(dialog->
variableName->text()).arg(
276 s = QString(
"%1 = ccurve(%2,0,[0,0,0],4,1,[1,1,1],4);\n").arg(dialog->
variableName->text()).arg(
281 dialog->
intMin->text() +
"," + dialog->
intMax->text() +
"\n";
284 s = QString(
"%1 = %2; # %3, %4\n")
287 .arg(atof(dialog->
floatMin->text().toStdString().c_str()), 0,
'f', 3)
288 .arg(atof(dialog->
floatMax->text().toStdString().c_str()), 0,
'f', 3);
291 s = QString(
"%1 = [%2,%3,%4]; # %5, %6\n")
296 .arg(atof(dialog->
vectorMin->text().toStdString().c_str()), 0,
'f', 3)
297 .arg(atof(dialog->
vectorMax->text().toStdString().c_str()), 0,
'f', 3);
300 s = QString(
"%1 = [%2,%3,%4];\n")
302 .arg(dialog->
color.redF())
303 .arg(dialog->
color.greenF())
304 .arg(dialog->
color.blueF());
307 s = QString(
"%1 = swatch(%2,%3);\n")
313 s = QString(
"\"%1\" #%2 %3\n")
319 s = QString(
"%1 = animCurve(%2,\"constant\",\"constant\",0,\"%3\");")
325 s = QString(
"%1 = deepWater(%2,9,30,0,1,0,5,0,0,[0,0,0],0,0,0);\n")
337 newEditable->
setExpr(expressionText.toStdString());
341 bool newVariables =
true;
344 const std::vector<std::string>& vars = newEditable->
getVariables();
346 for (
size_t k = 0; k < vars.size(); k++) {
347 variables.push_back((
"$" + vars[k]).c_str());
361 for (
unsigned int i = 0; i <
_controls.size(); i++) {
374 Editable* editable = (*editableExpression)[i];
394 std::cerr <<
"SeExpr editor logic error, cannot find a widget for the given editable" << std::endl;
406 std::cerr <<
"Expr Editor Logic ERROR did not make widget" << std::endl;
414 if (idx < 0 || idx >= (
int)
_controls.size())
return;
419 if (!control)
return;
426 for (
unsigned int i = 0; i <
_controls.size(); i++) {
437 if (_linkedId < 0 || _linkedId >= (
int)
_controls.size())
return;
Control for editing a color ramp curve.
A control for editing color swatches.
Control for editing a normal curve ramp.
Control for displaying a deep water spectrum.
Factors a SeExpr into an editable expression with controls (i.e. value boxes, curve boxes)
size_t size() const
Return the count of editable parameters.
void setExpr(const std::string &expr)
Set's expressions and parses it into "control editable form".
std::string getEditedExpr() const
Return a reconstructed expression using all the editable's current values.
bool controlsMatch(const EditableExpression &other) const
Check if the other editable expression has editables that all match i.e. the controls are same.
void updateString(const EditableExpression &other)
Update the string refered to into the controls (this is only valid if controlsmatch)
const std::vector< std::string > & getVariables() const
Get list of commentsø
This class is the UI for adding widgets.
QLineEdit * animCurveLookup
QLineEdit * vectorDefault0
QLineEdit * animCurveLink
QRadioButton * grayPaletteBtn
void colorChooseClicked()
QLineEdit * vectorDefault1
QRadioButton * rainbowPaletteBtn
QLineEdit * stringDefaultWidget
ExprAddDialog(int &count, QWidget *parent=0)
QLineEdit * stringNameWidget
QLineEdit * deepWaterLookup
QComboBox * stringTypeWidget
QLineEdit * colorCurveLookup
QLineEdit * vectorDefault2
QPushButton * colorWidget
const char * initSwatch()
void controlChanged(int id)
Notification that a specific control was changed.
bool rebuildControls(const QString &expressionText, std::vector< QString > &variables)
Rebuild the controls given the new expressionText. Return any local variables found.
ExprControlCollection(QWidget *parent=0, bool showAddButton=true)
void insertString(const std::string &controlString)
void singleControlChanged(int id)
Notification when by a control whenever it is edited.
void linkColorOutput(QColor color)
Gives information about when a link color was changed.
QVBoxLayout * controlLayout
void addControlDialog()
When a user clicks "Add Widget" button.
std::vector< ExprControl * > _controls
void linkColorLink(int id)
Notification by a control that a new color link is desired.
void linkColorEdited(int id, QColor color)
Notification by a control that a color is edited (when it is linked)
EditableExpression * editableExpression
void updateText(const int id, QString &text)
Request new text, given taking into account control id's new values.
void linkColorInput(QColor color)
Base class for all controls for Expressions.
Number slider for either float or int data.
A control for editing strings, filenames, and directories.
A vector or color control (named vector because it edits a SeExpr2::Vec3d literal)
</pre > Once we have this we need an instance to store our variable and provide a reference to that We make it because it may be useful to use the same ExprVarRef from multiple expressions !For if you have expressions that all have access to the same variables
</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