21 #include <QtGui/QLineEdit>
22 #include <QtGui/QPushButton>
23 #include <QtGui/QToolButton>
24 #include <QtCore/QRegExp>
25 #include <QtGui/QSplitter>
26 #include <QtGui/QLabel>
27 #include <QtGui/QMouseEvent>
28 #include <QtGui/QKeyEvent>
29 #include <QtGui/QHBoxLayout>
30 #include <QtGui/QVBoxLayout>
31 #include <QtGui/QPaintEvent>
32 #include <QtGui/QPainter>
33 #include <QtGui/QScrollArea>
34 #include <QtGui/QSpacerItem>
35 #include <QtGui/QSizePolicy>
36 #include <QtGui/QTextCharFormat>
37 #include <QtGui/QCompleter>
38 #include <QtGui/QAbstractItemView>
39 #include <QtGui/QStandardItemModel>
40 #include <QtGui/QStringListModel>
41 #include <QtGui/QFileDialog>
42 #include <QtGui/QDialogButtonBox>
43 #include <QtGui/QScrollBar>
44 #include <QtGui/QToolTip>
45 #include <QtGui/QListWidget>
46 #include <QtGui/QTreeView>
61 "....................",
62 "....................",
63 "....................",
64 ".......#aaaa#.......",
65 ".....#########......",
66 "....###bbbbb###.....",
67 "....##b.....b##.....",
68 "...bb#b.....b##.....",
69 "...bbbb....aaaaaa...",
70 "...........aaaaaa...",
71 "....##......####....",
72 "...####......##.....",
73 "..######............",
74 "..aaa#aa............",
75 "....##......bbb.....",
76 "....##b...bbbab.....",
77 "....a#abbbb##ab.....",
78 ".....#a####aa#b.....",
79 ".....aaaaaaa#.b.....",
80 "...................."};
90 "..........#a.a......",
91 "..........#a.a.....b",
92 "..........#.a.....bb",
93 "..........#aa....bb.",
94 "..........#.....bb..",
95 "..........#....bb...",
96 "..........#....bb...",
97 "....bbb...#...bb....",
98 "...bbbbb..#..bbb....",
99 "...b...bbb#.bbb.....",
100 "..bb....bb#bbb......",
101 "##bb####bbbbb#######",
102 ".bb......bbb....c.c.",
103 ".bb.......#......c..",
104 ".b........#.....c.c.",
105 "bb........#.........",
106 "b.........#.........",
107 "..........#.........",
108 "..........#.........",
109 "..........#........."};
118 "....................",
119 "....................",
120 "....................",
121 "....................",
122 "...........#######..",
123 "...........#aaaaa#..",
124 "..##########aaaaa#..",
125 "..#aaaaaaaaaaaaaa#..",
126 "..#aaaaaaaaaaaaaa#..",
127 "..#aaaaaaaaaaaaaa#..",
128 "..#aaaaaaaaaaaaaa#..",
129 "..#aaaaaaaaaaaaaa#..",
130 "..#aaaaa##a##a##a#..",
131 "..#aaaaa##a##a##a#..",
132 "..#aaaaaaaaaaaaaa#..",
133 "..################..",
134 "....................",
135 "....................",
136 "....................",
137 "...................."};
147 "....................",
148 "....................",
149 "....#########.......",
150 "....#aaaaaaa##......",
151 "....#aaaaaaa#b#.....",
152 "....#aaaaaaa#bb#....",
153 "....#aaaaaaa####....",
154 "....#aaaaaaaaaa#....",
155 "....#aaaaaaaaaa#....",
156 "....#aaaaaaaaaa#....",
157 "....#aaaaaaaaaa#....",
158 "....#aaaaaaaaaa#....",
159 "....#aaaaaaaaaa#....",
160 "....#aaaaaaaaaa#....",
161 "....#aaaaaaaaaa#....",
162 "....#accaccacca#....",
163 "....#accaccacca#....",
164 "....#aaaaaaaaaa#....",
165 "....############....",
166 "...................."};
177 float r = maximum()-minimum();
178 float v = ((float)(e->x()-2)*r/(width()-5))+minimum()+.5f;
189 float r = maximum()-minimum();
190 int linepos = (int)((v-minimum())/r*(width()-5)+2);
192 QColor qcol = palette().color(QPalette::Dark);
193 QColor bcol = palette().color(QPalette::Midlight);
194 QColor dcol = bcol.lighter(140);
195 QColor bgcol = palette().color(QPalette::Base);
199 bcol = bcol.lighter(110);
200 bgcol = bgcol.lighter(110);
201 int mx = mapFromGlobal(QCursor::pos()).x();
202 if (abs(linepos-mx)<4) dcol = dcol.lighter(200);
205 p.fillRect(1,1,width()-1,height()-2,bgcol);
206 p.fillRect(1,1,linepos-1,height()-2,bcol);
214 p.drawLine(linepos,2,linepos,height()-2);
218 p.drawLine(linepos-2,1,linepos-2,height()-1);
219 p.drawLine(linepos+2,1,linepos+2,height()-1);
224 p.drawRect(0,0,width()-1,height()-1);
228 : QWidget(parent), _id(id), _value(0)
235 if (_value < 0 || _value > 1)
return;
236 int x = int(
_value * (width()-3) + 0.5);
238 p.fillRect(contentsRect(),
_col);
239 p.fillRect(x, 0, 3, height(), QColor(64,64,64));
256 if (value ==
_value)
return;
264 :_id(id),_updating(false),_editable(editable)
266 hbox=
new QHBoxLayout(
this);
276 _label =
new QLabel(QString(
"<b>")+editable->
name.c_str()+
"</b>");
277 _label->setFixedWidth(72);
278 _label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
280 _label->setAutoFillBackground(
true);
285 _label->setFixedWidth(84);
297 if(state==Qt::Checked){
318 :
ExprControl(id,editable,false),_numberEditable(editable)
322 float smin = editable->
min, smax = editable->
max;
324 float srange = smax-smin;
326 _slider->setRange(
int(smin),
int(smax));
332 _slider->setFocusPolicy(Qt::ClickFocus);
336 _edit->setMinimumWidth(0);
337 _edit->setFixedHeight(16);
339 connect(
_edit,SIGNAL(textChanged(
int,
const QString&)),SLOT(
editChanged(
int,
const QString&)));
357 float val = text.toFloat(&ok);
382 :
ExprControl(id,editable,true),_numberEditable(editable)
392 for(
int i=0;i<3;i++){
393 QVBoxLayout* vbl=
new QVBoxLayout();
394 hbox->addLayout(vbl);
399 vbl->addWidget(edit);
401 edit->setMinimumWidth(0);
402 edit->setFixedHeight(16);
405 vbl->addWidget(slider);
407 slider->setFixedHeight(6);
409 static const QColor rgb[3] = { QColor(128,64,64), QColor(64,128,64), QColor(64,64,128) };
412 connect(edit,SIGNAL(textChanged(
int,
const QString&)),SLOT(
editChanged(
int,
const QString&)));
413 connect(slider, SIGNAL(valueChanged(
int,
float)), SLOT(
sliderChanged(
int,
float)));
454 float val = text.toFloat(&ok);
463 for (
unsigned int i = 0; i < 3; i++)
464 _edits[i]->setText(QString(
"%1")
467 for (
unsigned int i = 0; i < 3; i++){
473 float r =
clamp(val[0],0,1);
474 float g =
clamp(val[1],0,1);
475 float b =
clamp(val[2],0,1);
476 float lum = r*.2+g*.7+b*.1;
478 QPalette pal = palette();
479 pal.setColor(QPalette::Window,QColor(
int(r*255),
int(g*255),
int(b*255)));
480 pal.setColor(QPalette::WindowText,(lum<0.5) ? QColor(255,255,255) : QColor(0,0,0));
489 if (n < 0 || n >= 3)
return;
498 :
ExprControl(id,editable,false),_stringEditable(editable)
501 _edit=
new QLineEdit();
502 _edit->setFixedHeight(20);
506 QPushButton* button=
new QPushButton();
507 button->setFixedSize(20,20);
510 hbox->addWidget(button,1);
515 connect(button,SIGNAL(clicked()),SLOT(
fileBrowse()));
516 button->setIcon(QIcon(QPixmap(
fileXPM)));
530 QString newFilename=dialog.
getOpenFileName(
"Please choose a file",
_edit->text(),tr(
"Images (*.tif *.tx *.jpg *.ptx *.png)"));
531 if(newFilename!=
"")
_edit->setText(newFilename);
539 if(newFilename!=
"")
_edit->setText(newFilename);
555 :
ExprControl(id,editable,false),_curveEditable(editable)
558 _curve->setFixedHeight(80);
561 for (
int i = 0; i < numVal; i++) {
579 :
ExprControl(id,editable,true),_curveEditable(editable)
582 _curve->setFixedHeight(80);
585 for (
int i = 0; i < numVal; i++) {
616 std::vector<float>
x,
y;
635 QWidget::paintEvent(event);
636 QPainter painter(
this);
637 painter.setRenderHint(QPainter::Antialiasing,
true);
638 painter.setPen(QColor(255,255,255));
649 int x_pad_in_pixels=25,y_pad_in_pixels=15;
661 QBrush darkbrush(QColor(100,100,100),Qt::SolidPattern);
663 QBrush brush(QColor(150,150,150),Qt::SolidPattern);
668 painter.fillRect(area,brush);
671 for(
int i=1;i<(int)
x.size();i++)
678 painter.setPen(QColor(75,50,50));
679 painter.drawPath(path);
681 painter.setPen(QPen());
682 painter.drawText(right,Qt::AlignTop|Qt::AlignLeft,QString(
"%1").arg(
ymax,0,
'f',1));
683 painter.drawText(right,Qt::AlignBottom|Qt::AlignLeft,QString(
"%1").arg(
ymin,0,
'f',1));
684 painter.drawText(bottom,Qt::AlignTop|Qt::AlignLeft,QString(
"%1").arg(
xmin,0,
'f',1));
685 painter.drawText(bottom,Qt::AlignTop|Qt::AlignRight,QString(
"%1").arg(
xmax,0,
'f',1));
687 painter.setBrush(QBrush(QColor(0,0,0),Qt::SolidPattern));
688 for(
size_t i=0;i<
cpx.size();i++){
693 #ifdef SEEXPR_USE_ANIMLIB
694 void sample(
const animlib::AnimCurve&
curve){
695 int numKeys=curve.getNumKeys();
699 const animlib::AnimKeyframe* key=&*curve.getFirstKey();
700 xmin=key[0].getTime();
701 xmax=key[numKeys-1].getTime();
705 for(
int i=0;i<numKeys;i++){
706 cpx.push_back(key[i].getTime());
707 cpy.push_back(key[i].getValue());
713 for(
int i=0;i<nsamples;i++){
715 float yeval=curve.getValue(xeval);
735 :
ExprControl(id,editable,false),_editable(editable)
745 QPushButton* refreshButton=
new QPushButton();
746 refreshButton->setMaximumWidth(30);
747 refreshButton->setIcon(QIcon(QPixmap(
refreshXPM)));
748 QPushButton* expandButton=
new QPushButton(
">");
749 expandButton->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding);
750 expandButton->setFixedWidth(15);
751 hbox->addWidget(expandButton);
754 hbox->addWidget(refreshButton);
756 #ifdef SEEXPR_USE_ANIMLIB
761 connect(refreshButton,SIGNAL(clicked()),
this,SLOT(
refreshClicked()));
764 #ifdef SEEXPR_USE_ANIMLIB
765 #include <CE/CETool.h>
771 #ifdef SEEXPR_USE_ANIMLIB
781 #ifdef SEEXPR_USE_ANIMLIB
782 QDialog* dialog=
new QDialog(
this);
783 CETool* tool=
new CETool;
784 animlib::AnimAttrID attr1(
"",
"");
785 animlib::AnimCurve& anim=*
new animlib::AnimCurve(attr1);
790 QVBoxLayout* layout=
new QVBoxLayout();
791 dialog->resize(QSize(1024,640));
792 dialog->setLayout(layout);
793 layout->addWidget(widg);
794 tool->addCurve(&anim);
796 QDialogButtonBox* buttonbar=
new QDialogButtonBox();
797 buttonbar->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
798 connect(buttonbar,SIGNAL(accepted()),dialog,SLOT(accept()));
799 connect(buttonbar,SIGNAL(rejected()),dialog,SLOT(reject()));
800 layout->addWidget(buttonbar);
802 if(dialog->exec()==QDialog::Accepted){
822 _swatchEditable(editable), _indexLabel(false)
875 :
ExprControl(id,editable,false),_deepWaterEditable(editable)
void editChanged(int id, const QString &text)
void linkColorEdited(int id, QColor color)
void colorChanged(int index, SeExpr2::Vec3d value)
virtual void mouseMoveEvent(QMouseEvent *e)
void linkColorLink(int id)
SeExpr2::CurveFuncX curve
DeepWaterControl(int id, DeepWaterEditable *stringEditable)
void colorAdded(int index, SeExpr2::Vec3d value)
Generic Slider (used for int and float sliders)
virtual void paintEvent(QPaintEvent *e)
void editChanged(int id, const QString &text)
StringControl(int id, StringEditable *stringEditable)
void linkStateChange(int state)
ExprGraphPreview(QWidget *parent=0)
ExprLineEdit * _edits[3]
All three line edit widgets (for each component)
void swatchChanged(QColor color)
DeepWaterEditable * _deepWaterEditable
curve model
void change(int index, const SeExpr2::Vec3d &value)
virtual QColor getColor()
Interface for getting the color (used for linked color picking)
ExprCurve * _curve
curve edit widget
QLineEdit * _edit
Edit box for the string.
ExprChannelSlider(int id, QWidget *parent)
std::vector< T_CURVE::CV > _cvs
void updateControl()
Update values in slider and textbox given what the model contains.
void add(const SeExpr2::Vec3d &value)
ExprCSwatchFrame * _swatch
void paintEvent(QPaintEvent *event)
void updateControl()
update the individual slider and eidt box controls
virtual void paintEvent(QPaintEvent *e)
void colorRemoved(int index)
void(* AnimCurveCallback)(const std::string &, animlib::AnimCurve &curve)
ExprColorSwatchWidget * _swatch
Edit box for the color swatches.
QPointF toScreen(float x, float y)
SeExpr2::Vec3d getValue() const
void setValue(int id, float value)
set the value in the model (in response to editing from controls)
QString getExistingDirectory(const QString &caption=QString::null, const QString &startWith=QString::null, const QString &filter=QString::null)
void valueChanged(int id, float value)
void controlChanged(int id)
For any rgb or hsl value(except for negative s values)
void setValue(const SeExpr2::Vec3d &value)
ColorSwatchEditable * _swatchEditable
model for the color swatches control
ExprSlider * _slider
Slider for the number.
void setValue(float value)
double max(double x, double y)
ColorSwatchControl(int id, ColorSwatchEditable *swatchEditable)
ColorCurveEditable * _curveEditable
color curve model
void sliderChanged(int id, float val)
The result is computed int int< br >< divstyle="margin-left:40px;"> Picks values randomly between loRange and hiRange based on supplied index(which is automatically hashed). 
static void setAnimCurveCallback(AnimCurveCallback callback)
void addPoint(const double x, const double y, const T_INTERP interp, bool select=false)
void linkDisconnect(int newId)
CurveControl(int id, CurveEditable *stringEditable)
double min(double x, double y)
QColor getColor()
Interface for getting the color (used for linked color picking)
virtual void mouseMoveEvent(QMouseEvent *e)
void setColor(QColor color)
Interface for setting the color (used for linked color picking)
Line Editor Widget(used for numbers)
static const char * fileXPM[]
</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
ExprControl(int id, Editable *editable, bool showColorLink)
void setDisplayColor(QColor c)
CurveEditable * _curveEditable
curve model
NumberEditable * _numberEditable
Pointer to the number control model.
void setValue(float value)
Update the model with the value and notify the collection.
ExprDeepWater * _deepWater
deep water widget
ExprLineEdit * _edit
Text box for the number.
virtual void mousePressEvent(QMouseEvent *e)
ExprGraphPreview * _preview
void setParams(const SeDeepWaterParams ¶ms)
void addPoint(const double x, const SeExpr2::Vec3d y, const T_INTERP interp, bool select=false)
Base class for all controls for Expressions.
StringEditable * _stringEditable
model for the string control
NumberControl(int id, NumberEditable *number)
QColor getColor()
Interface for getting the color (used for linked color picking)
double clamp(double x, double lo, double hi)
CCurveControl(int id, ColorCurveEditable *stringEditable)
ExprColorCurve * _curve
color curve widget
void textChanged(const QString &newText)
static const char * directoryXPM[]
AnimCurveControl(int id, AnimCurveEditable *curveEditable)
Channel Slider (i.e. for colors)
static AnimCurveCallback callback
static const char * refreshXPM[]
QString getOpenFileName(const QString &caption=QString::null, const QString &startWith=QString::null, const QString &filter=QString::null)
std::vector< SeExpr2::Vec3d > colors
VectorControl(int id, VectorEditable *number)
static const char * graphXPM[]
virtual void mousePressEvent(QMouseEvent *e)
virtual void setText(const QString &t)
VectorEditable * _numberEditable
Number model.
void sliderChanged(int val)
ExprChannelSlider * _sliders[3]
All three channel sliders (for each component)
std::vector< T_CURVE::CV > _cvs
void setColor(QColor color)
Interface for setting the color (used for linked color picking)
AnimCurveEditable * _editable
void setSwatchColor(QColor color)