21 #include <QtGui/QVBoxLayout>
22 #include <QtGui/QHBoxLayout>
23 #include <QtGui/QToolButton>
24 #include <QtGui/QPushButton>
25 #include <QtGui/QRadioButton>
26 #include <QtGui/QFormLayout>
27 #include <QtGui/QDialogButtonBox>
28 #include <QtGui/QColorDialog>
29 #include <QtGui/QLabel>
42 :QWidget(parent),count(0),showAddButton(showAddButton),editableExpression(0)
50 QPushButton* button=
new QPushButton(
"Add Widget");
51 button->setFocusPolicy(Qt::NoFocus);
52 QHBoxLayout* buttonLayout=
new QHBoxLayout();
53 buttonLayout->insertStretch(-1,100);
54 buttonLayout->addWidget(button,0);
70 QVBoxLayout *verticalLayout;
71 verticalLayout =
new QVBoxLayout();
72 verticalLayout->setSpacing(3);
73 verticalLayout->setMargin(3);
74 setLayout(verticalLayout);
75 QHBoxLayout *horizontalLayout =
new QHBoxLayout();
77 horizontalLayout->addWidget(
new QLabel(
"Variable"));
79 variableName =
new QLineEdit(QString(
"$var%1").arg(count++));
82 verticalLayout->addLayout(horizontalLayout);
88 QWidget* curveTab =
new QWidget();
89 QFormLayout* curveLayout =
new QFormLayout(curveTab);
90 curveLayout->setWidget(0,QFormLayout::LabelRole,
new QLabel(
"Lookup"));
92 curveLayout->setWidget(0,QFormLayout::FieldRole,
curveLookup);
93 tabWidget->addTab(curveTab, QString(
"Curve"));
98 QWidget* colorCurveTab =
new QWidget();
99 QFormLayout* colorCurveLayout =
new QFormLayout(colorCurveTab);
100 colorCurveLayout->setWidget(0,QFormLayout::LabelRole,
new QLabel(
"Lookup"));
103 tabWidget->addTab(colorCurveTab, QString(
"Color Curve"));
108 QWidget* intTab =
new QWidget();
109 QFormLayout* intFormLayout =
new QFormLayout(intTab);
110 intFormLayout->setWidget(0, QFormLayout::LabelRole,
new QLabel(
"Default"));
111 intFormLayout->setWidget(1, QFormLayout::LabelRole,
new QLabel(
"Min"));
112 intFormLayout->setWidget(2, QFormLayout::LabelRole,
new QLabel(
"Max"));
114 intFormLayout->setWidget(0, QFormLayout::FieldRole,
intDefault);
115 intMin =
new QLineEdit(
"0");
116 intFormLayout->setWidget(1, QFormLayout::FieldRole,
intMin);
117 intMax =
new QLineEdit(
"10");
118 intFormLayout->setWidget(2, QFormLayout::FieldRole,
intMax);
119 tabWidget->addTab(intTab, QString(
"Int"));
124 QWidget* floatTab =
new QWidget();
125 QFormLayout* floatFormLayout =
new QFormLayout(floatTab);
126 floatFormLayout->setWidget(0, QFormLayout::LabelRole,
new QLabel(
"Default"));
127 floatFormLayout->setWidget(1, QFormLayout::LabelRole,
new QLabel(
"Min"));
128 floatFormLayout->setWidget(2, QFormLayout::LabelRole,
new QLabel(
"Max"));
130 floatFormLayout->setWidget(0, QFormLayout::FieldRole,
floatDefault);
132 floatFormLayout->setWidget(1, QFormLayout::FieldRole,
floatMin);
134 floatFormLayout->setWidget(2, QFormLayout::FieldRole,
floatMax);
136 tabWidget->addTab(floatTab, QString(
"Float"));
141 QWidget* vectorTab =
new QWidget();
142 QFormLayout* vectorFormLayout =
new QFormLayout(vectorTab);
143 vectorFormLayout->setWidget(0, QFormLayout::LabelRole,
new QLabel(
"Default"));
144 vectorFormLayout->setWidget(1, QFormLayout::LabelRole,
new QLabel(
"Min"));
145 vectorFormLayout->setWidget(2, QFormLayout::LabelRole,
new QLabel(
"Max"));
149 QHBoxLayout* compLayout=
new QHBoxLayout();
153 vectorFormLayout->setLayout(0, QFormLayout::FieldRole, compLayout);
155 vectorFormLayout->setWidget(1, QFormLayout::FieldRole,
vectorMin);
157 vectorFormLayout->setWidget(2, QFormLayout::FieldRole,
vectorMax);
159 tabWidget->addTab(vectorTab, QString(
"Vector"));
164 QWidget* colorTab =
new QWidget();
165 QFormLayout* colorLayout =
new QFormLayout(colorTab);
169 colorLayout->setWidget(0,QFormLayout::LabelRole,
new QLabel(
"Color"));
170 colorLayout->setWidget(0,QFormLayout::FieldRole,
colorWidget);
172 QPixmap colorPix(30,30);
173 colorPix.fill(
color);
175 tabWidget->addTab(colorTab, QString(
"Color"));
182 QWidget* swatchTab =
new QWidget();
183 QFormLayout* swatchLayout =
new QFormLayout(swatchTab);
185 swatchLayout->setWidget(0,QFormLayout::LabelRole,
new QLabel(
"Lookup"));
186 swatchLayout->setWidget(0,QFormLayout::FieldRole,
swatchLookup);
190 swatchLayout->setWidget(1,QFormLayout::LabelRole,
new QLabel(
"Colors"));
192 swatchLayout->setWidget(2,QFormLayout::LabelRole,
new QLabel(
""));
194 tabWidget->addTab(swatchTab, QString(
"Swatch"));
199 QWidget* stringTab =
new QWidget();
200 QFormLayout* stringLayout =
new QFormLayout(stringTab);
208 stringLayout->setWidget(0,QFormLayout::LabelRole,
new QLabel(
"String Name"));
210 stringLayout->setWidget(1,QFormLayout::LabelRole,
new QLabel(
"String Type"));
212 stringLayout->setWidget(2,QFormLayout::LabelRole,
new QLabel(
"String Default"));
215 tabWidget->addTab(stringTab, QString(
"String"));
220 QWidget* curveTab =
new QWidget();
221 QFormLayout* curveLayout =
new QFormLayout(curveTab);
222 curveLayout->setWidget(0,QFormLayout::LabelRole,
new QLabel(
"Lookup"));
223 curveLayout->setWidget(1,QFormLayout::LabelRole,
new QLabel(
"Link"));
227 curveLayout->setWidget(1,QFormLayout::FieldRole,
animCurveLink);
228 tabWidget->addTab(curveTab, QString(
"AnimCurve"));
233 QWidget* deepWaterTab =
new QWidget();
234 QFormLayout* deepWaterLayout =
new QFormLayout(deepWaterTab);
235 deepWaterLayout->setWidget(0,QFormLayout::LabelRole,
new QLabel(
"Lookup"));
238 tabWidget->addTab(deepWaterTab, QString(
"Deep Water"));
244 QDialogButtonBox* buttonBox =
new QDialogButtonBox();
245 buttonBox->setOrientation(Qt::Horizontal);
246 buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
248 verticalLayout->addWidget(buttonBox);
251 QObject::connect(buttonBox, SIGNAL(accepted()),
this, SLOT(accept()));
252 QObject::connect(buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
263 QPixmap colorPix(30,30);
264 colorPix.fill(
color);
265 ((QPushButton *)sender())->setIcon(QIcon(colorPix));
272 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]");
274 return(
"[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]");
276 return(
"[1,1,1],[.5,.5,.5],[0,0,0]");
284 switch(dialog->
tabWidget->currentIndex()){
286 s=QString(
"%1 = curve(%2,0,0,4,1,1,4);\n")
291 s=QString(
"%1 = ccurve(%2,0,[0,0,0],4,1,[1,1,1],4);\n")
297 +
"; # "+dialog->
intMin->text()+
","+dialog->
intMax->text()+
"\n";
300 s=QString(
"%1 = %2; # %3, %4\n").arg(dialog->
variableName->text())
302 .arg(atof(dialog->
floatMin->text().toStdString().c_str()),0,
'f',3)
303 .arg(atof(dialog->
floatMax->text().toStdString().c_str()),0,
'f',3);
306 s=QString(
"%1 = [%2,%3,%4]; # %5, %6\n").arg(dialog->
variableName->text())
310 .arg(atof(dialog->
vectorMin->text().toStdString().c_str()),0,
'f',3)
311 .arg(atof(dialog->
vectorMax->text().toStdString().c_str()),0,
'f',3);
314 s=QString(
"%1 = [%2,%3,%4];\n")
316 .arg(dialog->
color.redF())
317 .arg(dialog->
color.greenF())
318 .arg(dialog->
color.blueF());
321 s=QString(
"%1 = swatch(%2,%3);\n")
327 s=QString(
"\"%1\" #%2 %3\n")
333 s=QString(
"%1 = animCurve(%2,\"constant\",\"constant\",0,\"%3\");")
339 s=QString(
"%1 = deepWater(%2,9,30,0,1,0,5,0,0,[0,0,0],0,0,0);\n")
353 newEditable->
setExpr(expressionText.toStdString());
357 bool newVariables=
true;
360 const std::vector<std::string>& vars=newEditable->
getVariables();
362 for(
size_t k=0;k<vars.size();k++){
363 variables.push_back((
"$"+vars[k]).c_str());
377 for (
unsigned int i = 0; i <
_controls.size(); i++){
390 Editable* editable=(*editableExpression)[i];
406 std::cerr<<
"SeExpr editor logic error, cannot find a widget for the given editable"<<std::endl;
418 std::cerr<<
"Expr Editor Logic ERROR did not make widget"<<std::endl;
427 if (idx < 0 || idx >= (
int)
_controls.size())
443 for(
unsigned int i=0;i<
_controls.size();i++){
460 if(_linkedId<0 || _linkedId>=(
int)
_controls.size())
return;
Control for editing a normal curve ramp.
QLineEdit * deepWaterLookup
void controlChanged(int id)
Notification that a specific control was changed.
A control for editing color swatches.
void singleControlChanged(int id)
Notification when by a control whenever it is edited.
QRadioButton * grayPaletteBtn
void setExpr(const std::string &expr)
Set's expressions and parses it into "control editable form".
QLineEdit * vectorDefault2
size_t size() const
Return the count of editable parameters.
QLineEdit * stringDefaultWidget
ExprAddDialog(int &count, QWidget *parent=0)
Control for displaying a deep water spectrum.
void linkColorInput(QColor color)
A vector or color control (named vector because it edits a SeExpr2::Vec3d literal) ...
const std::vector< std::string > & getVariables() const
Get list of commentsø
void addControlDialog()
When a user clicks "Add Widget" button.
QPushButton * colorWidget
QLineEdit * animCurveLink
std::string getEditedExpr() const
Return a reconstructed expression using all the editable's current values.
const char * initSwatch()
QLineEdit * vectorDefault0
QVBoxLayout * controlLayout
</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
A control for editing strings, filenames, and directories.
void linkColorLink(int id)
Notification by a control that a new color link is desired.
ExprControlCollection(QWidget *parent=0, bool showAddButton=true)
QLineEdit * vectorDefault1
QLineEdit * animCurveLookup
QComboBox * stringTypeWidget
std::vector< ExprControl * > _controls
EditableExpression * editableExpression
Factors a SeExpr into an editable expression with controls (i.e. value boxes, curve boxes) ...
bool rebuildControls(const QString &expressionText, std::vector< QString > &variables)
Rebuild the controls given the new expressionText. Return any local variables found.
void updateString(const EditableExpression &other)
Update the string refered to into the controls (this is only valid if controlsmatch) ...
</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
void updateText(const int id, QString &text)
Request new text, given taking into account control id's new values.
QRadioButton * rainbowPaletteBtn
void insertString(const std::string &controlString)
bool controlsMatch(const EditableExpression &other) const
Check if the other editable expression has editables that all match i.e. the controls are same...
Base class for all controls for Expressions.
This class is the UI for adding widgets.
QLineEdit * stringNameWidget
QLineEdit * colorCurveLookup
Number slider for either float or int data.
void colorChooseClicked()
void linkColorOutput(QColor color)
Gives information about when a link color was changed.
void linkColorEdited(int id, QColor color)
Notification by a control that a color is edited (when it is linked)
Control for editing a color ramp curve.