25#include <QColorDialog>
26#include <QDoubleValidator>
27#include <QGraphicsSceneMouseEvent>
31#include <QResizeEvent>
33#include <QDialogButtonBox>
37#ifdef SEEXPR_USE_QDGUI
38#include <qdgui/QdColorPickerDialog.h>
44 : _curve(new
T_CURVE), _width(320), _height(170), _color(
SeExpr2::Vec3d(.5)), _interp(
T_CURVE::kMonotoneSpline),
45 _selectedItem(-1), _pixmapDirty(true), _baseRectW(0), _baseRect(0), _lmb(false) {
56 setSceneRect(-9, -2, width, height);
74 int newIndex =
_cvs.size() - 1;
101 if (((event->key() == Qt::Key_Backspace) || (event->key() == Qt::Key_Delete)) && (
_selectedItem >= 0)) {
109 QPointF pos = mouseEvent->scenePos();
111 QList<QGraphicsItem *> itemList = items(pos);
112 if (itemList.empty()) {
116 }
else if (itemList[0]->zValue() == 2) {
119 for (
int i = 0; i < numCircle; i++) {
121 if (obj == itemList[0]) {
130 if (mouseEvent->buttons() == Qt::LeftButton) {
132 double myx = pos.x() /
_width;
146 QPointF
point = mouseEvent->scenePos();
163 QMenu *menu =
new QMenu(event->widget());
164 QAction *deleteAction = menu->addAction(
"Delete Point");
165 QAction *action = menu->exec(event->screenPos());
171 Q_UNUSED(mouseEvent);
219 buf.append(QString(
"P6\n%1 %2\n255\n").arg(
_width).arg(
_height));
221 _pixmap.loadFromData(buf,
"PPM");
230 QByteArray pixmap(len, 127);
232 double paramInc = 1.0 / (
_width - 2);
233 double param = 0.5 * paramInc;
235 char *ptr = pixmap.data();
239 for (
int i = 1; i <
_width - 1; i++) {
241 *ptr++ = char(std::min(std::max(0.0, 255 * color[0]), 255.0) + 0.5);
242 *ptr++ = char(std::min(std::max(0.0, 255 * color[1]), 255.0) + 0.5);
243 *ptr++ = char(std::min(std::max(0.0, 255 * color[2]), 255.0) + 0.5);
251 for (
int i = 1; i <
_height - 1; i++) {
252 memcpy(pixmap.data() + (i *
_width * 3), pixmap.data() + ((i - 1) *
_width * 3),
_width * 3);
256 memset(pixmap.data(), 0,
_width * 3);
281 const int numCV =
_cvs.size();
282 for (
int i = 0; i < numCV; i++) {
286 pen = QPen(QColor(255, 170, 0), 1.0);
288 pen = QPen(Qt::black, 1.0);
296 QBrush(QColor(
int(255 * pt.
_val[0] + 0.5),
int(255 * pt.
_val[1] + 0.5),
int(255 * pt.
_val[2] + 0.5)))));
298 circle->setFlag(QGraphicsItem::ItemIsMovable,
true);
299 circle->setZValue(2);
312 p.fillRect(contentsRect(),
_color);
330#ifdef SEEXPR_USE_QDGUI
331 QColor color = QdColorPickerDialog::chooseColorFromDialog(
_color,
this);
333 QColor color = QColorDialog::getColor(
_color);
335 if (color.isValid()) {
336 _value[0] = color.red() / 255.0;
337 _value[1] = color.green() / 255.0;
338 _value[2] = color.blue() / 255.0;
339 setPalette(QPalette(color));
347 : QWidget(parent), _scene(0), _selPosEdit(0), _selValEdit(0), _interpComboBox(0) {
349 QHBoxLayout *mainLayout =
new QHBoxLayout();
350 mainLayout->setSpacing(2);
351 mainLayout->setMargin(5);
353 QWidget *edits =
new QWidget;
354 QVBoxLayout *editsLayout =
new QVBoxLayout;
355 editsLayout->setAlignment(Qt::AlignTop);
356 editsLayout->setSpacing(0);
357 editsLayout->setMargin(0);
358 edits->setLayout(editsLayout);
360 QWidget *selPos =
new QWidget;
361 QHBoxLayout *selPosLayout =
new QHBoxLayout;
362 selPosLayout->setSpacing(1);
363 selPosLayout->setMargin(1);
364 selPos->setLayout(selPosLayout);
366 QDoubleValidator *posValidator =
new QDoubleValidator(0.0, 1.0, 6,
_selPosEdit);
370 selPosLayout->addStretch(50);
372 if (pLabel.isEmpty()) {
373 posLabel =
new QLabel(
"Selected Position: ");
375 posLabel =
new QLabel(pLabel);
377 selPosLayout->addWidget(posLabel);
380 QWidget *selVal =
new QWidget;
381 QBoxLayout *selValLayout =
new QHBoxLayout;
382 selValLayout->setSpacing(1);
383 selValLayout->setMargin(1);
384 selVal->setLayout(selValLayout);
388 selValLayout->addStretch(50);
390 if (vLabel.isEmpty()) {
391 valLabel =
new QLabel(
"Selected Color: ");
393 valLabel =
new QLabel(vLabel);
395 selValLayout->addWidget(valLabel);
408 editsLayout->addWidget(selPos);
409 editsLayout->addWidget(selVal);
412 QFrame *curveFrame =
new QFrame;
413 curveFrame->setFrameShape(QFrame::Panel);
414 curveFrame->setFrameShadow(QFrame::Sunken);
415 curveFrame->setLineWidth(1);
416 QHBoxLayout *curveFrameLayout =
new QHBoxLayout;
417 curveFrameLayout->setMargin(0);
419 curveView->setFrameShape(QFrame::Panel);
420 curveView->setFrameShadow(QFrame::Sunken);
421 curveView->setLineWidth(1);
422 curveView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
423 curveView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
425 curveView->setScene(
_scene);
426 curveView->setTransform(QTransform().scale(1, -1));
427 curveView->setRenderHints(QPainter::Antialiasing);
428 curveFrameLayout->addWidget(curveView);
429 curveFrame->setLayout(curveFrameLayout);
431 mainLayout->addWidget(edits);
432 mainLayout->addWidget(curveFrame);
434 QPushButton *expandButton =
new QPushButton(
">");
435 expandButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
436 expandButton->setFixedWidth(15);
437 mainLayout->addWidget(expandButton);
439 connect(expandButton, SIGNAL(clicked()),
this, SLOT(
openDetail()));
441 mainLayout->setStretchFactor(curveFrame, 100);
442 setLayout(mainLayout);
463 connect(curveView, SIGNAL(resizeSignal(
int,
int)),
_scene, SLOT(resize(
int,
int)));
470 posStr.setNum(pos,
'f', 3);
473 emit
swatchChanged(QColor::fromRgbF(val[0], val[1], val[2], 1));
481 _selPosEdit->setText(QString(
"%1").arg(pos, 0,
'f', 3));
490 SeExpr2::Vec3d newColor(color.redF(), color.greenF(), color.blueF());
497 return QColor::fromRgbF(val[0], val[1], val[2], 1);
503 QDialog *dialog =
new QDialog();
504 dialog->setMinimumWidth(1024);
505 dialog->setMinimumHeight(400);
509 const std::vector<T_CURVE::CV> &data =
_scene->
_cvs;
510 typedef std::vector<T_CURVE::CV>::const_iterator ITERATOR;
511 for (ITERATOR i = data.begin(); i != data.end(); ++i) curve->addPoint(i->_pos, i->_val, i->_interp);
513 QVBoxLayout *layout =
new QVBoxLayout();
514 dialog->setLayout(layout);
515 layout->addWidget(curve);
517 dialog->setLayout(layout);
518 layout->addWidget(curve);
519 QDialogButtonBox *buttonbar =
new QDialogButtonBox();
520 buttonbar->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
521 connect(buttonbar, SIGNAL(accepted()), dialog, SLOT(accept()));
522 connect(buttonbar, SIGNAL(rejected()), dialog, SLOT(reject()));
523 layout->addWidget(buttonbar);
525 if (dialog->exec() == QDialog::Accepted) {
528 const std::vector<T_CURVE::CV> &dataNew = curve->_scene->_cvs;
529 typedef std::vector<T_CURVE::CV>::const_iterator ITERATOR;
530 for (ITERATOR i = dataNew.begin(); i != dataNew.end(); ++i)
addPoint(i->_pos, i->_val, i->_interp);
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QGraphicsProxyWidget * _baseRect
void removePoint(const int index)
std::vector< QGraphicsEllipseItem * > _circleObjects
void selPosChanged(double pos)
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
SeExpr2::Curve< SeExpr2::Vec3d > T_CURVE
std::vector< T_CURVE::CV > _cvs
void cvSelected(double x, const SeExpr2::Vec3d y, const T_INTERP interp)
void addPoint(double x, const SeExpr2::Vec3d y, const T_INTERP interp, const bool select=true)
void selValChanged(const SeExpr2::Vec3d &val)
virtual void keyPressEvent(QKeyEvent *event)
T_CURVE::InterpType T_INTERP
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
void interpChanged(const int interp)
void resize(const int width, const int height)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
void selValChangedSignal(SeExpr2::Vec3d value)
void swatchChanged(QColor color)
virtual void paintEvent(QPaintEvent *event)
ExprCSwatchFrame(SeExpr2::Vec3d value, QWidget *parent=0)
SeExpr2::Vec3d getValue() const
void setValue(const SeExpr2::Vec3d &value)
virtual void mousePressEvent(QMouseEvent *event)
void internalSwatchChanged(QColor color)
void addPoint(const double x, const SeExpr2::Vec3d y, const T_INTERP interp, bool select=false)
void swatchChanged(QColor color)
void setSwatchColor(QColor color)
ExprColorCurve(QWidget *parent=0, QString pLabel="", QString vLabel="", QString iLabel="", bool expandable=true)
void selValChangedSignal(SeExpr2::Vec3d val)
void cvSelectedSlot(const double pos, const SeExpr2::Vec3d val, const T_INTERP interp)
QComboBox * _interpComboBox
ExprCSwatchFrame * _selValEdit
void selPosChangedSignal(double pos)
Interpolation curve class for double->double and double->Vec3D.
CV getLowerBoundCV(const double param) const
InterpType
Supported interpolation types.
T getValue(const double param) const
Evaluates curve and returns full value.
void addPoint(double position, const T &val, InterpType type)
Adds a point to the curve.
void preparePoints()
Prepares points for evaluation (sorts and computes boundaries, clamps extrema)
double clamp(double x, double lo, double hi)
</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
This is the same as the prman cellnoise function< br ></div >< br > float< b > float y< br > float< b > float y
The result is computed int int< br >< div style="margin-left: 40px;"> Picks values randomly between loRange and hiRange based on supplied index(which is automatically hashed).  
For any rgb or hsl value(except for negative s values)