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 <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>
47 
48 #include "ExprControl.h"
49 #include "ExprColorCurve.h"
50 #include "ExprColorSwatch.h"
51 #include "ExprFileDialog.h"
52 #include "Editable.h"
53 
54 /* XPM */
55 static const char *refreshXPM[]={
56 "20 20 4 1",
57 "# c #303030",
58 "a c #585858",
59 "b c #c3c3c3",
60 ". c #dcdcdc",
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 "...................."};
81 
82 /* XPM */
83 static const char *graphXPM[]={
84 "20 20 5 1",
85 "c c #000040",
86 "a c #303030",
87 "# c #58a8ff",
88 ". c #dcdcdc",
89 "b c #ff0000",
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 "..........#........."};
110 
111 
112 /* XPM */
113 static const char *directoryXPM[]={
114 "20 20 3 1",
115 ". c None",
116 "# c #000000",
117 "a c #d8c59e",
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 "...................."};
138 
139 /* XPM */
140 static const char *fileXPM[]={
141 "20 20 5 1",
142 ". c None",
143 "# c #000000",
144 "c c #303030",
145 "b c #a79b80",
146 "a c #ddcdaa",
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 "...................."};
167 
168 
169 
170 void ExprSlider::mousePressEvent(QMouseEvent* e)
171 {
172  mouseMoveEvent(e);
173 }
174 
175 void ExprSlider::mouseMoveEvent(QMouseEvent* e)
176 {
177  float r = maximum()-minimum();
178  float v = ((float)(e->x()-2)*r/(width()-5))+minimum()+.5f;
179  int iv = std::min(std::max((int)v,minimum()),maximum());
180  setValue(iv);
181 }
182 
183 void ExprSlider::paintEvent(QPaintEvent* e)
184 {
185  Q_UNUSED(e);
186  QPainter p(this);
187 
188  float v = value();
189  float r = maximum()-minimum();
190  int linepos = (int)((v-minimum())/r*(width()-5)+2);
191 
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);
196 
197  if (underMouse())
198  {
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);
203  }
204 
205  p.fillRect(1,1,width()-1,height()-2,bgcol);
206  p.fillRect(1,1,linepos-1,height()-2,bcol);
207 
208  QPen pen = p.pen();
209 
210  pen.setColor(dcol);
211  p.setPen(pen);
212  pen.setWidth(3);
213  p.setPen(pen);
214  p.drawLine(linepos,2,linepos,height()-2);
215  pen.setWidth(1);
216  pen.setColor(qcol);
217  p.setPen(pen);
218  p.drawLine(linepos-2,1,linepos-2,height()-1);
219  p.drawLine(linepos+2,1,linepos+2,height()-1);
220 
221  pen.setWidth(1);
222  pen.setColor(qcol);
223  p.setPen(pen);
224  p.drawRect(0,0,width()-1,height()-1);
225 }
226 
227 ExprChannelSlider::ExprChannelSlider(int id, QWidget* parent)
228  : QWidget(parent), _id(id), _value(0)
229 {
230 }
231 
232 void ExprChannelSlider::paintEvent(QPaintEvent* e)
233 {
234  Q_UNUSED(e);
235  if (_value < 0 || _value > 1) return;
236  int x = int(_value * (width()-3) + 0.5);
237  QPainter p(this);
238  p.fillRect(contentsRect(), _col);
239  p.fillRect(x, 0, 3, height(), QColor(64,64,64));
240 }
241 
243 {
244  mouseMoveEvent(e);
245 }
246 
247 
249 {
250  setValue(clamp(float(e->x()-1) / (width()-3), 0, 1));
251 }
252 
253 
255 {
256  if (value == _value) return;
257  _value = value;
258  emit valueChanged(_id, value);
259  update();
260 }
261 
262 
263 ExprControl::ExprControl(int id,Editable* editable,bool showColorLink)
264  :_id(id),_updating(false),_editable(editable)
265 {
266  hbox=new QHBoxLayout(this);
267  hbox->setSpacing(2);
268  hbox->setMargin(0);
269 
270  _colorLinkCB=new QCheckBox(this);
271  _colorLinkCB->setFixedWidth(14);
272  _colorLinkCB->setFocusPolicy(Qt::NoFocus);
273  connect(_colorLinkCB,SIGNAL(stateChanged(int)),this,SLOT(linkStateChange(int)));
274  hbox->addWidget(_colorLinkCB);
275 
276  _label = new QLabel(QString("<b>")+editable->name.c_str()+"</b>");
277  _label->setFixedWidth(72);
278  _label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
279  _label->setIndent(2);
280  _label->setAutoFillBackground(true);
281  hbox->addWidget(_label);
282 
283  if(!showColorLink){
284  _colorLinkCB->setHidden(true);
285  _label->setFixedWidth(84);
286  }else{
287  _colorLinkCB->setHidden(false);
288  _label->setFixedWidth(84-_colorLinkCB->width()+2);
289  }
290 
291 }
292 
294 {
295  if(_updating) return;
296 
297  if(state==Qt::Checked){
298  emit linkColorLink(_id);
299  emit linkColorEdited(_id,getColor());
300  }else{
301  emit linkColorLink(-1);
302  }
303 }
304 
306 {
307  if(newId!=_id){
308  _updating = 1;
309  _colorLinkCB->setChecked(false);
310  _updating = 0;
311  }
312 }
313 
314 
315 
316 
318  :ExprControl(id,editable,false),_numberEditable(editable)
319 {
320 
321  // slider
322  float smin = editable->min, smax = editable->max;
323  if(!_numberEditable->isInt) { smin *= 1e5; smax *= 1e5; }
324  float srange = smax-smin;
325  _slider = new ExprSlider(Qt::Horizontal,this);
326  _slider->setRange(int(smin),int(smax));
327  _slider->setTickInterval(std::max(1,int(srange/10)));
328  _slider->setSingleStep(std::max(1,int(srange/50)));
329  _slider->setPageStep(std::max(1,int(srange/10)));
330  _slider->setMinimumWidth(0);
331  _slider->setFixedHeight(16);
332  _slider->setFocusPolicy(Qt::ClickFocus);
333  hbox->addWidget(_slider, 3);
334  // edit box
335  _edit = new ExprLineEdit(0,this);
336  _edit->setMinimumWidth(0);
337  _edit->setFixedHeight(16);
338  hbox->addWidget(_edit);
339  connect(_edit,SIGNAL(textChanged(int,const QString&)),SLOT(editChanged(int,const QString&)));
340  connect(_slider, SIGNAL(valueChanged(int)), SLOT(sliderChanged(int)));
341  // show current values
342  updateControl();
343 }
344 
346 {
347  if (_updating) return;
348  setValue(_numberEditable->isInt ? value : value*1e-5);
349 
350 }
351 
352 void NumberControl::editChanged(int id,const QString& text)
353 {
354  Q_UNUSED(id);
355  if (_updating) return;
356  bool ok = 0;
357  float val = text.toFloat(&ok);
358  if (!ok) return;
359  setValue(val);
360 }
361 
363 {
364  _updating = 1;
365  int sliderval = int(_numberEditable->isInt ? _numberEditable->v : _numberEditable->v*1e5);
366  if (sliderval != _slider->value()) _slider->setValue(sliderval);
367  _edit->setText(QString("%1")
368  .arg(_numberEditable->v, 0, 'f', _numberEditable->isInt ? 0 : 3));
369  _updating=0;
370 }
371 
373 {
374  //std::cerr<<"In setValue "<<_id<<value<<std::endl;
375  if (fabs(_numberEditable->v-value) < 1e-5) return;
377  updateControl();
378  emit controlChanged(_id);
379 }
380 
382  :ExprControl(id,editable,true),_numberEditable(editable)
383 {
384 
386  _swatch=new ExprCSwatchFrame(editable->v);
387  _swatch->setFixedWidth(38);
388  _swatch->setFixedHeight(20);
389  connect(_swatch,SIGNAL(swatchChanged(QColor)),this,SLOT(swatchChanged(QColor)));
390  hbox->addWidget(_swatch);
391  }
392  for(int i=0;i<3;i++){
393  QVBoxLayout* vbl=new QVBoxLayout();
394  hbox->addLayout(vbl);
395  vbl->setMargin(0);
396  vbl->setSpacing(0);
397 
398  ExprLineEdit* edit = new ExprLineEdit(i, this);
399  vbl->addWidget(edit);
400  _edits[i]=edit;
401  edit->setMinimumWidth(0);
402  edit->setFixedHeight(16);
403 
404  ExprChannelSlider* slider = new ExprChannelSlider(i, this);
405  vbl->addWidget(slider);
406  _sliders[i]=slider;
407  slider->setFixedHeight(6);
408  // set color
409  static const QColor rgb[3] = { QColor(128,64,64), QColor(64,128,64), QColor(64,64,128) };
410  if(_numberEditable->isColor) slider->setDisplayColor(rgb[i]);
411 
412  connect(edit,SIGNAL(textChanged(int,const QString&)),SLOT(editChanged(int,const QString&)));
413  connect(slider, SIGNAL(valueChanged(int,float)), SLOT(sliderChanged(int,float)));
414 
415  }
416  // update controls
417  updateControl();
418 }
419 
421 {
422  Q_UNUSED(gah);
424  setValue(0,color[0]);
425  setValue(1,color[1]);
426  setValue(2,color[2]);
427 }
428 
430 {
431  return QColor::fromRgbF(clamp(_numberEditable->v[0],0,1),
432  clamp(_numberEditable->v[1],0,1),
433  clamp(_numberEditable->v[2],0,1));
434 }
435 
436 void VectorControl::setColor(QColor color)
437 {
438  setValue(0,color.redF());
439  setValue(1,color.greenF());
440  setValue(2,color.blueF());
441 }
442 
444 {
445  if (_updating) return;
448 }
449 
450 void VectorControl::editChanged(int id,const QString& text)
451 {
452  if (_updating) return;
453  bool ok = 0;
454  float val = text.toFloat(&ok);
455  if (!ok) return;
456  setValue(id,val);
457 }
458 
460 {
461 // //std::cerr<<"In update control "<<_id<<std::endl;
462  _updating = 1;
463  for (unsigned int i = 0; i < 3; i++)
464  _edits[i]->setText(QString("%1")
465  .arg(_numberEditable->v[i], 0, 'f', 3));
467  for (unsigned int i = 0; i < 3; i++){
468  _sliders[i]->setValue((_numberEditable->v[i]-min)/(max-min));
469  }
471  //std::cerr<<"trying to set color"<<std::endl;
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;
477  //std::cerr<<" rgb "<<r<<" "<<g<<" "<<b<<std::endl;
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));
481  _label->setPalette(pal);
482 
483  }
484  _updating = 0;
485 }
486 
488 {
489  if (n < 0 || n >= 3) return;
490  if (fabs(_numberEditable->v[n]-value) < 1e-5) return;
491  _numberEditable->v[n] = value;
493  updateControl();
494  emit controlChanged(_id);
495 }
496 
498  :ExprControl(id,editable,false),_stringEditable(editable)
499 {
500  // make line edit
501  _edit=new QLineEdit();
502  _edit->setFixedHeight(20);
503  connect(_edit,SIGNAL(textChanged(const QString&)),SLOT(textChanged(const QString&)));
504  // make a button if we are a file or directory
505  if(_stringEditable->type=="file" || _stringEditable->type=="directory"){
506  QPushButton* button=new QPushButton();
507  button->setFixedSize(20,20);
508 
509  hbox->addWidget(_edit,3);
510  hbox->addWidget(button,1);
511  if(_stringEditable->type=="directory"){
512  connect(button,SIGNAL(clicked()),SLOT(directoryBrowse()));
513  button->setIcon(QIcon(QPixmap(directoryXPM)));
514  } else if(_stringEditable->type=="file"){
515  connect(button,SIGNAL(clicked()),SLOT(fileBrowse()));
516  button->setIcon(QIcon(QPixmap(fileXPM)));
517  }
518 
519  }else{
520  hbox->addWidget(_edit,3);
521  }
522  // update controls
523  updateControl();
524 }
525 
527 {
528  ExprFileDialog dialog(this);
529  dialog.setPreview();
530  QString newFilename=dialog.getOpenFileName("Please choose a file",_edit->text(),tr("Images (*.tif *.tx *.jpg *.ptx *.png)"));
531  if(newFilename!="") _edit->setText(newFilename);
532 }
533 
535 {
536  ExprFileDialog dialog(this);
537  dialog.setPreview();
538  QString newFilename=dialog.getExistingDirectory("Please choose a file",_edit->text());
539  if(newFilename!="") _edit->setText(newFilename);
540 }
541 
543 {
544  _edit->setText(_stringEditable->v.c_str());
545 }
546 
547 void StringControl::textChanged(const QString& newText)
548 {
549  if(_updating) return;
550  _stringEditable->v=newText.toStdString();
551  emit controlChanged(_id);
552 }
553 
555  :ExprControl(id,editable,false),_curveEditable(editable)
556 {
557  _curve = new ExprCurve(this, "Pos:", "Val:", "Interp:");
558  _curve->setFixedHeight(80);
559 
560  const int numVal = _curveEditable->cvs.size();
561  for (int i = 0; i < numVal; i++) {
563  _curve->addPoint(cv._pos,cv._val,cv._interp);
564  }
565  hbox->addWidget(_curve, 3);
566  connect(_curve->_scene, SIGNAL(curveChanged()), SLOT(curveChanged()));
567  // unneded? updateControl();
568 }
569 
571 {
572  if(_curve && _curveEditable){
574  emit controlChanged(_id);
575  }
576 }
577 
579  :ExprControl(id,editable,true),_curveEditable(editable)
580 {
581  _curve = new ExprColorCurve(this, "Pos:", "Val:", "Interp:");
582  _curve->setFixedHeight(80);
583 
584  const int numVal = _curveEditable->cvs.size();
585  for (int i = 0; i < numVal; i++) {
587  _curve->addPoint(cv._pos,cv._val,cv._interp);
588  }
589  hbox->addWidget(_curve, 3);
590  connect(_curve->_scene, SIGNAL(curveChanged()), SLOT(curveChanged()));
591  // unneeded? updateControl();
592 }
593 
595 {
596  if(_curve && _curveEditable){
598  emit controlChanged(_id);
599 
600  }
601 }
602 
603 
605 {
606  return _curve->getSwatchColor();
607 }
608 
609 void CCurveControl::setColor(QColor color)
610 {
611  _curve->setSwatchColor(color);
612 }
613 
614 struct ExprGraphPreview:public QWidget
615 {
616  std::vector<float> x,y;
617  std::vector<float> cpx,cpy;
618  float xmin,xmax,ymin,ymax,dx,dy;;
620  ExprGraphPreview(QWidget* parent=0)
621  :QWidget(parent)
622  {
623  win_xmin=-1.;
624  win_xmax=2.;
625  win_ymin=-1;
626  win_ymax=2.;
627  }
628 
629  QPointF toScreen(float x,float y){
630  return QPointF((x-win_xmin)*win_dx,height()-(y-win_ymin)*win_dy);
631  }
632 
633 
634  void paintEvent(QPaintEvent* event){
635  QWidget::paintEvent(event);
636  QPainter painter(this);
637  painter.setRenderHint(QPainter::Antialiasing,true);
638  painter.setPen(QColor(255,255,255));
641  float percentXpad=.1*(win_xmax-win_xmin);
642  float percentYpad=.1*(win_ymax-win_ymin);
643  win_xmin-=percentXpad;
644  win_xmax+=percentXpad;
645  win_ymin-=percentYpad;
646  win_ymax+=percentYpad;
647 
648  // make space for text
649  int x_pad_in_pixels=25,y_pad_in_pixels=15;
650  float xpad=x_pad_in_pixels*(win_xmax-win_xmin)/(width()-x_pad_in_pixels);
651  float ypad=y_pad_in_pixels*(win_ymax-win_ymin)/(height()-y_pad_in_pixels);
652  win_ymin-=ypad;
653  win_xmax+=xpad;
654 
655  win_dx=width()/(win_xmax-win_xmin);
656  win_dy=height()/(win_ymax-win_ymin);
657 
658  //int h=height();
659  QPainterPath path;
660  QRectF fullarea(toScreen(win_xmin,win_ymax),toScreen(win_xmax,win_ymin));
661  QBrush darkbrush(QColor(100,100,100),Qt::SolidPattern);
662  QRectF area(toScreen(xmin,ymax),toScreen(xmax,ymin));
663  QBrush brush(QColor(150,150,150),Qt::SolidPattern);
664  //painter.fillRect(fullarea,darkbrush);
665  //painter.setBrush(darkbrush);
666  //painter.drawRoundedRect(fullarea,3,3);
667  //painter.setBrush(QBrush());
668  painter.fillRect(area,brush);
669  if(x.size()>0){
670  path.moveTo(toScreen(x[0],y[0]));
671  for(int i=1;i<(int)x.size();i++)
672  path.lineTo(toScreen(x[i],y[i]));
673 
674  }
675  QRectF right(toScreen(xmax,ymax),toScreen(win_xmax,ymin));
676  QRectF bottom(toScreen(xmin,ymin),toScreen(xmax,win_ymin));
677 
678  painter.setPen(QColor(75,50,50));
679  painter.drawPath(path);
680 
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));
686 
687  painter.setBrush(QBrush(QColor(0,0,0),Qt::SolidPattern));
688  for(size_t i=0;i<cpx.size();i++){
689  painter.drawEllipse(toScreen(cpx[i],cpy[i]),2,2);
690  }
691  }
692 
693 #ifdef SEEXPR_USE_ANIMLIB
694  void sample(const animlib::AnimCurve& curve){
695  int numKeys=curve.getNumKeys();
696  x.clear();y.clear();
697  cpx.clear();cpy.clear();
698  if(numKeys>0){
699  const animlib::AnimKeyframe* key=&*curve.getFirstKey();
700  xmin=key[0].getTime();
701  xmax=key[numKeys-1].getTime();
702  ymin=FLT_MAX;
703  ymax=-FLT_MAX;
704 
705  for(int i=0;i<numKeys;i++){
706  cpx.push_back(key[i].getTime());
707  cpy.push_back(key[i].getValue());
708  }
709 
710  int nsamples=100;
711  float dx=(xmax-xmin)/nsamples;
712  float xeval=xmin;
713  for(int i=0;i<nsamples;i++){
714  x.push_back(xeval);
715  float yeval=curve.getValue(xeval);
716  ymin=std::min(ymin,yeval);
717  ymax=std::max(ymax,yeval);
718  y.push_back(yeval);
719  xeval+=dx;
720  }
721  // pad window AFTER sampling
722  //std::cerr<<"we have xmin xmax ymin ymax "<<xmin<<" "<<xmax<<" "<<ymin<<" "<<ymax<<std::endl;
723  }else{
724  xmin=-1;
725  xmax=1;
726  ymin=-1;
727  ymax=1;
728  }
729  //std::cerr<<"we have xmin xmax ymin ymax "<<xmin<<" "<<xmax<<" "<<ymin<<" "<<ymax<<std::endl;
730  }
731 #endif
732 };
733 
735 :ExprControl(id,editable,false),_editable(editable)
736 {
737 
739  _preview->setMinimumWidth(200);
740  _preview->setMinimumHeight(60);
741  hbox->addWidget(_preview);
742  //QPushButton* button=new QPushButton();
743  //button->setIcon(QIcon(QPixmap(graphXPM)));
744  Q_UNUSED(graphXPM)
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);
752  //hbox->addWidget(button);
753  refreshButton->setVisible(_editable->link!="");
754  hbox->addWidget(refreshButton);
755 
756 #ifdef SEEXPR_USE_ANIMLIB
757  _preview->sample(editable->curve);
758 #endif
759  connect(expandButton,SIGNAL(clicked()),this,SLOT(editGraphClicked()));
760  //connect(_preview,SIGNAL(clicked()),this,SLOT(editGraphClicked()));
761  connect(refreshButton,SIGNAL(clicked()),this,SLOT(refreshClicked()));
762 }
763 
764 #ifdef SEEXPR_USE_ANIMLIB
765 #include <CE/CETool.h>
766 #endif
767 
769 {
770  if(callback){
771 #ifdef SEEXPR_USE_ANIMLIB
772  callback(_editable->link,_editable->curve);
773  _preview->sample(_editable->curve);
774  _preview->repaint();
775  emit controlChanged(_id);
776 #endif
777  }
778 }
779 
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);
786  anim=_editable->curve;
787 
788  QWidget *widg;
789  tool->map(widg,0);
790  QVBoxLayout* layout=new QVBoxLayout();
791  dialog->resize(QSize(1024,640));
792  dialog->setLayout(layout);
793  layout->addWidget(widg);
794  tool->addCurve(&anim);
795 
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);
801 
802  if(dialog->exec()==QDialog::Accepted){
803  // copy points back from child
804  _editable->curve=anim;
805  _preview->sample(_editable->curve);
806  _preview->repaint();
807  emit controlChanged(_id);
808  }
809 #endif
810 }
811 
812 void AnimCurveControl::setAnimCurveCallback(AnimCurveCallback newCallback)
813 {
814  callback=newCallback;
815 }
816 
818 
819 // Editing widget for color swatch
821  :ExprControl(id,editable,false),
822  _swatchEditable(editable), _indexLabel(false)
823 {
824  // include index labels if user specifies 'indices' as labelType
825  if(_swatchEditable->labelType=="indices")
826  _indexLabel = true;
828 }
829 
831 {
832  if(_updating) return;
833  if(index >= 0 && index < int(_swatchEditable->colors.size()))
834  _swatchEditable->change(index, value);
835  emit controlChanged(_id);
836 }
837 
839 {
840  if(_updating) return;
841  if(index >= 0 && index <= int(_swatchEditable->colors.size()))
842  _swatchEditable->add(value); // add to end; TODO insert
843  emit controlChanged(_id);
844 }
845 
847 {
848  if(_updating) return;
849  if(index >= 0 && index < int(_swatchEditable->colors.size())){
850  _swatchEditable->remove(index);
851  _swatch->deleteLater();
852  _swatch = 0;
854  }
855  emit controlChanged(_id);
856 }
857 
859 {
861  connect(_swatch,SIGNAL(swatchChanged(int,SeExpr2::Vec3d)),this, SLOT(colorChanged(int,SeExpr2::Vec3d)));
862  connect(_swatch,SIGNAL(swatchAdded(int,SeExpr2::Vec3d)),this, SLOT(colorAdded(int,SeExpr2::Vec3d)));
863  connect(_swatch,SIGNAL(swatchRemoved(int)),this, SLOT(colorRemoved(int)));
864 
865  _updating = true;
866  for (unsigned int i=0; i<_swatchEditable->colors.size(); i++) {
868  _swatch->addSwatch(val,i);
869  }
870  _updating = false;
871  hbox->addWidget(_swatch);
872 }
873 
875  :ExprControl(id,editable,false),_deepWaterEditable(editable)
876 {
877  _deepWater = new ExprDeepWater(this);
878  _deepWater->setParams(editable->params);
879 
880  hbox->addWidget(_deepWater, 3);
881  connect(_deepWater->_scene, SIGNAL(deepWaterChanged()), SLOT(deepWaterChanged()));
882 }
883 
885 {
888  emit controlChanged(_id);
889  }
890 }
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)
Definition: ExprControl.h:124
virtual void paintEvent(QPaintEvent *e)
void editChanged(int id, const QString &text)
StringControl(int id, StringEditable *stringEditable)
void curveChanged()
void linkStateChange(int state)
ExprGraphPreview(QWidget *parent=0)
ExprLineEdit * _edits[3]
All three line edit widgets (for each component)
Definition: ExprControl.h:194
void swatchChanged(QColor color)
DeepWaterEditable * _deepWaterEditable
curve model
Definition: ExprControl.h:314
void change(int index, const SeExpr2::Vec3d &value)
Definition: Editable.h:349
virtual QColor getColor()
Interface for getting the color (used for linked color picking)
Definition: ExprControl.h:71
ExprCurve * _curve
curve edit widget
Definition: ExprControl.h:241
void curveChanged()
QLineEdit * _edit
Edit box for the string.
Definition: ExprControl.h:222
SeDeepWaterParams params
Definition: Editable.h:369
QCheckBox * _colorLinkCB
Definition: ExprControl.h:61
ExprChannelSlider(int id, QWidget *parent)
std::vector< T_CURVE::CV > _cvs
InterpType _interp
Definition: Curve.h:55
SeDeepWaterParams params
std::vector< float > y
void updateControl()
Update values in slider and textbox given what the model contains.
void add(const SeExpr2::Vec3d &value)
Definition: Editable.h:345
ExprCSwatchFrame * _swatch
Definition: ExprControl.h:195
std::vector< CV > cvs
Definition: Editable.h:196
std::string v
Definition: Editable.h:152
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)
Definition: ExprControl.h:275
ExprColorSwatchWidget * _swatch
Edit box for the color swatches.
Definition: ExprControl.h:296
float value() const
Definition: ExprControl.h:149
QPointF toScreen(float x, float y)
QHBoxLayout * hbox
Definition: ExprControl.h:60
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)
double max
Definition: Editable.h:117
For any rgb or hsl value(except for negative s values)
std::vector< float > cpy
void setValue(const SeExpr2::Vec3d &value)
ColorSwatchEditable * _swatchEditable
model for the color swatches control
Definition: ExprControl.h:294
double _pos
Definition: Curve.h:53
ExprSlider * _slider
Slider for the number.
Definition: ExprControl.h:171
void setValue(float value)
double max(double x, double y)
Definition: ExprBuiltins.h:42
ColorSwatchControl(int id, ColorSwatchEditable *swatchEditable)
ColorCurveEditable * _curveEditable
color curve model
Definition: ExprControl.h:254
void sliderChanged(int id, float val)
std::string link
Definition: Editable.h:245
std::string type
Definition: Editable.h:153
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).&nbsp
std::vector< float > cpx
static void setAnimCurveCallback(AnimCurveCallback callback)
double min
Definition: Editable.h:117
void addPoint(const double x, const double y, const T_INTERP interp, bool select=false)
Definition: ExprCurve.cpp:491
double v
Definition: Editable.h:68
void linkDisconnect(int newId)
CurveControl(int id, CurveEditable *stringEditable)
double min(double x, double y)
Definition: ExprBuiltins.h:43
Between a and b
Definition: userdoc.txt:180
QColor getColor()
Interface for getting the color (used for linked color picking)
static const int p[514]
Definition: NoiseTables.h:20
virtual void mouseMoveEvent(QMouseEvent *e)
double max
Definition: Editable.h:69
std::string name
Definition: Editable.h:40
CCurveScene * _scene
QColor getSwatchColor()
void setColor(QColor color)
Interface for setting the color (used for linked color picking)
Line Editor Widget(used for numbers)
Definition: ExprControl.h:101
void remove(int index)
Definition: Editable.h:353
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
Definition: tutorial.txt:108
ExprControl(int id, Editable *editable, bool showColorLink)
void setDisplayColor(QColor c)
Definition: ExprControl.h:150
CurveScene * _scene
Definition: ExprCurve.h:133
CurveEditable * _curveEditable
curve model
Definition: ExprControl.h:239
NumberEditable * _numberEditable
Pointer to the number control model.
Definition: ExprControl.h:169
void setValue(float value)
Update the model with the value and notify the collection.
ExprDeepWater * _deepWater
deep water widget
Definition: ExprControl.h:316
ExprLineEdit * _edit
Text box for the number.
Definition: ExprControl.h:173
double min
Definition: Editable.h:69
virtual void mousePressEvent(QMouseEvent *e)
ExprGraphPreview * _preview
Definition: ExprControl.h:272
void setParams(const SeDeepWaterParams &params)
void addPoint(const double x, const SeExpr2::Vec3d y, const T_INTERP interp, bool select=false)
QLabel * _label
Definition: ExprControl.h:62
Base class for all controls for Expressions.
Definition: ExprControl.h:53
StringEditable * _stringEditable
model for the string control
Definition: ExprControl.h:220
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)
Definition: ExprBuiltins.h:40
SeExpr2::Vec3d v
Definition: Editable.h:116
CCurveControl(int id, ColorCurveEditable *stringEditable)
ExprColorCurve * _curve
color curve widget
Definition: ExprControl.h:256
void textChanged(const QString &newText)
static const char * directoryXPM[]
DeepWaterScene * _scene
AnimCurveControl(int id, AnimCurveEditable *curveEditable)
void directoryBrowse()
std::vector< float > x
Channel Slider (i.e. for colors)
Definition: ExprControl.h:140
static AnimCurveCallback callback
Definition: ExprControl.h:285
static const char * refreshXPM[]
Definition: ExprControl.cpp:55
std::string labelType
Definition: Editable.h:304
QString getOpenFileName(const QString &caption=QString::null, const QString &startWith=QString::null, const QString &filter=QString::null)
std::vector< SeExpr2::Vec3d > colors
Definition: Editable.h:303
VectorControl(int id, VectorEditable *number)
static const char * graphXPM[]
Definition: ExprControl.cpp:83
virtual void mousePressEvent(QMouseEvent *e)
virtual void setText(const QString &t)
Definition: ExprControl.h:106
VectorEditable * _numberEditable
Number model.
Definition: ExprControl.h:192
void sliderChanged(int val)
ExprChannelSlider * _sliders[3]
All three channel sliders (for each component)
Definition: ExprControl.h:195
bool _updating
Definition: ExprControl.h:59
std::vector< T_CURVE::CV > _cvs
Definition: ExprCurve.h:90
void setColor(QColor color)
Interface for setting the color (used for linked color picking)
AnimCurveEditable * _editable
Definition: ExprControl.h:269
void updateControl()
void setSwatchColor(QColor color)
void addSwatch(SeExpr2::Vec3d &val, int index=-1)