25 #include <QtGui/QColorDialog>
26 #include <QtGui/QDoubleValidator>
27 #include <QtGui/QGraphicsSceneMouseEvent>
28 #include <QtGui/QHBoxLayout>
29 #include <QtGui/QLabel>
30 #include <QtGui/QVBoxLayout>
31 #include <QtGui/QResizeEvent>
32 #include <QtGui/QPushButton>
33 #include <QtGui/QDialogButtonBox>
34 #include <QtGui/QMenu>
36 #include <SeExpr2/ExprBuiltins.h>
37 #ifdef SEEXPR_USE_QDGUI
38 #include <qdgui/QdColorPickerDialog.h>
44 _selectedItem(-1), _pixmapDirty(true), _baseRectW(0), _baseRect(0), _lmb(false)
61 setSceneRect(-9, -2, width, height);
72 for(
unsigned int i=0;i<
_cvs.size();i++)
82 int newIndex=
_cvs.size()-1;
115 if (((event->key() == Qt::Key_Backspace) ||
125 QPointF pos = mouseEvent->scenePos();
127 QList<QGraphicsItem *> itemList = items(pos);
128 if (itemList.empty()) {
132 }
else if (itemList[0]->zValue() == 2) {
135 for (
int i = 0; i < numCircle; i++ ) {
137 if (obj == itemList[0]) {
146 if(mouseEvent->buttons() == Qt::LeftButton){
148 double myx=pos.x()/
_width;
164 QPointF
point = mouseEvent->scenePos();
181 QMenu *menu =
new QMenu(event->widget());
182 QAction *deleteAction = menu->addAction(
"Delete Point");
183 QAction *action = menu->exec(event->screenPos());
190 Q_UNUSED(mouseEvent);
246 buf.append(QString(
"P6\n%1 %2\n255\n").arg(
_width).arg(
_height));
248 _pixmap.loadFromData(buf,
"PPM");
259 QByteArray pixmap(len, 127);
261 double paramInc = 1.0 / (
_width - 2);
262 double param = 0.5 * paramInc;
264 char* ptr = pixmap.data();
268 for (
int i = 1; i <
_width - 1; i++) {
280 for (
int i = 1; i < _height-1; i++) {
281 memcpy(pixmap.data()+(i * _width * 3), pixmap.data()+((i - 1) * _width * 3), _width * 3);
285 memset(pixmap.data(), 0, _width * 3);
286 memset(pixmap.data()+((_height - 1) * _width * 3), 0, _width * 3);
314 const int numCV =
_cvs.size();
315 for (
int i = 0; i < numCV; i++) {
319 pen = QPen(QColor(255,170,0),1.0);
321 pen = QPen(Qt::black,1.0);
325 circle->setFlag(QGraphicsItem::ItemIsMovable,
true);
326 circle->setZValue(2);
342 p.fillRect(contentsRect(),
_color);
354 _color = QColor(
int(255 * value[0] + 0.5),
int(255 * value[1] + 0.5),
int(255 * value[2] + 0.5));
369 #ifdef SEEXPR_USE_QDGUI
370 QColor color = QdColorPickerDialog::chooseColorFromDialog(
_color,
this);
372 QColor color = QColorDialog::getColor(
_color);
374 if (color.isValid()) {
375 _value[0] = color.red() / 255.0;
376 _value[1] = color.green() / 255.0;
377 _value[2] = color.blue() / 255.0;
378 setPalette(QPalette(color));
388 QWidget(parent), _scene(0), _selPosEdit(0), _selValEdit(0), _interpComboBox(0)
391 QHBoxLayout *mainLayout =
new QHBoxLayout();
392 mainLayout->setSpacing(2);
393 mainLayout->setMargin(5);
395 QWidget *edits =
new QWidget;
396 QVBoxLayout *editsLayout =
new QVBoxLayout;
397 editsLayout->setAlignment(Qt::AlignTop);
398 editsLayout->setSpacing(0);
399 editsLayout->setMargin(0);
400 edits->setLayout(editsLayout);
402 QWidget *selPos =
new QWidget;
403 QHBoxLayout *selPosLayout =
new QHBoxLayout;
404 selPosLayout->setSpacing(1);
405 selPosLayout->setMargin(1);
406 selPos->setLayout(selPosLayout);
408 QDoubleValidator *posValidator =
new QDoubleValidator(0.0,1.0,6,
_selPosEdit);
412 selPosLayout->addStretch(50);
414 if (pLabel.isEmpty()) {
415 posLabel =
new QLabel(
"Selected Position: ");
417 posLabel =
new QLabel(pLabel);
419 selPosLayout->addWidget(posLabel);
422 QWidget *selVal =
new QWidget;
423 QBoxLayout *selValLayout =
new QHBoxLayout;
424 selValLayout->setSpacing(1);
425 selValLayout->setMargin(1);
426 selVal->setLayout(selValLayout);
430 selValLayout->addStretch(50);
432 if (vLabel.isEmpty()) {
433 valLabel =
new QLabel(
"Selected Color: ");
435 valLabel =
new QLabel(vLabel);
437 selValLayout->addWidget(valLabel);
450 editsLayout->addWidget(selPos);
451 editsLayout->addWidget(selVal);
454 QFrame *curveFrame =
new QFrame;
455 curveFrame->setFrameShape(QFrame::Panel);
456 curveFrame->setFrameShadow(QFrame::Sunken);
457 curveFrame->setLineWidth(1);
458 QHBoxLayout *curveFrameLayout =
new QHBoxLayout;
459 curveFrameLayout->setMargin(0);
461 curveView->setFrameShape(QFrame::Panel);
462 curveView->setFrameShadow(QFrame::Sunken);
463 curveView->setLineWidth(1);
464 curveView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
465 curveView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
467 curveView->setScene(
_scene);
468 curveView->setTransform(QTransform().scale(1, -1));
469 curveView->setRenderHints(QPainter::Antialiasing);
470 curveFrameLayout->addWidget(curveView);
471 curveFrame->setLayout(curveFrameLayout);
473 mainLayout->addWidget(edits);
474 mainLayout->addWidget(curveFrame);
476 QPushButton* expandButton=
new QPushButton(
">");
477 expandButton->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding);
478 expandButton->setFixedWidth(15);
479 mainLayout->addWidget(expandButton);
481 connect(expandButton, SIGNAL(clicked()),
this, SLOT(
openDetail()));
483 mainLayout->setStretchFactor(curveFrame,100);
484 setLayout(mainLayout);
499 connect(curveView, SIGNAL(resizeSignal(
int,
int)),
_scene, SLOT(resize(
int,
int)));
508 posStr.setNum(pos,
'f', 3);
511 emit
swatchChanged(QColor::fromRgbF(val[0],val[1],val[2],1));
520 _selPosEdit->setText(QString(
"%1").arg(pos, 0,
'f', 3));
531 SeExpr2::Vec3d newColor(color.redF(),color.greenF(),color.blueF());
539 return QColor::fromRgbF(val[0],val[1],val[2],1);
549 QDialog* dialog=
new QDialog();
550 dialog->setMinimumWidth(1024);
551 dialog->setMinimumHeight(400);
555 const std::vector<T_CURVE::CV >& data=
_scene->
_cvs;
556 typedef std::vector<T_CURVE::CV >::const_iterator ITERATOR;
557 for(ITERATOR i=data.begin();i!=data.end();++i)
558 curve->
addPoint(i->_pos,i->_val,i->_interp);
560 QVBoxLayout* layout=
new QVBoxLayout();
561 dialog->setLayout(layout);
562 layout->addWidget(curve);
564 dialog->setLayout(layout);
565 layout->addWidget(curve);
566 QDialogButtonBox* buttonbar=
new QDialogButtonBox();
567 buttonbar->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
568 connect(buttonbar,SIGNAL(accepted()),dialog,SLOT(accept()));
569 connect(buttonbar,SIGNAL(rejected()),dialog,SLOT(reject()));
570 layout->addWidget(buttonbar);
572 if(dialog->exec()==QDialog::Accepted){
575 const std::vector<T_CURVE::CV >& dataNew=curve->
_scene->
_cvs;
576 typedef std::vector<T_CURVE::CV >::const_iterator ITERATOR;
577 for(ITERATOR i=dataNew.begin();i!=dataNew.end();++i)
578 addPoint(i->_pos,i->_val,i->_interp);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
SeExpr2::CurveFuncX curve
void preparePoints()
Prepares points for evaluation (sorts and computes boundaries, clamps extrema)
ExprCSwatchFrame * _selValEdit
virtual void keyPressEvent(QKeyEvent *event)
void selValChanged(const SeExpr2::Vec3d &val)
Interpolation curve class for double->double and double->Vec3D.
T_CURVE::InterpType T_INTERP
void resize(const int width, const int height)
QComboBox * _interpComboBox
std::vector< T_CURVE::CV > _cvs
void selValChangedSignal(SeExpr2::Vec3d value)
T getValue(const double param) const
Evaluates curve and returns full value.
QGraphicsProxyWidget * _baseRect
virtual void mousePressEvent(QMouseEvent *event)
void internalSwatchChanged(QColor color)
CV getLowerBoundCV(const double param) const
std::vector< QGraphicsEllipseItem * > _circleObjects
void addPoint(double x, const SeExpr2::Vec3d y, const T_INTERP interp, const bool select=true)
void selPosChangedSignal(double pos)
SeExpr2::Vec3d getValue() const
For any rgb or hsl value(except for negative s values)
void setValue(const SeExpr2::Vec3d &value)
double max(double x, double y)
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). 
ExprColorCurve(QWidget *parent=0, QString pLabel="", QString vLabel="", QString iLabel="", bool expandable=true)
Vec< double, 3, false > Vec3d
void removePoint(const int index)
SeExpr2::Curve< SeExpr2::Vec3d > T_CURVE
double min(double x, double y)
void selPosChanged(double pos)
void interpChanged(const int interp)
void cvSelectedSlot(const double pos, const SeExpr2::Vec3d val, const T_INTERP interp)
</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
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
virtual void paintEvent(QPaintEvent *event)
void addPoint(const double x, const SeExpr2::Vec3d y, const T_INTERP interp, bool select=false)
void selValChangedSignal(SeExpr2::Vec3d val)
double clamp(double x, double lo, double hi)
ExprCSwatchFrame(SeExpr2::Vec3d value, QWidget *parent=0)
void swatchChanged(QColor color)
void addPoint(double position, const T &val, InterpType type)
Adds a point to the curve.
InterpType
Supported interpolation types.
void cvSelected(double x, const SeExpr2::Vec3d y, const T_INTERP interp)
void swatchChanged(QColor color)
This is the same as the prman cellnoise function< br ></div >< br > float< b > float y< br > float< b > float y
void setSwatchColor(QColor color)