5 #include <QtGui/QColorDialog>
6 #include <QtGui/QDoubleValidator>
7 #include <QtGui/QGraphicsSceneMouseEvent>
8 #include <QtGui/QHBoxLayout>
9 #include <QtGui/QVBoxLayout>
10 #include <QtGui/QGridLayout>
11 #include <QtGui/QResizeEvent>
12 #include <QtGui/QPushButton>
13 #include <QtGui/QDialogButtonBox>
14 #include <QtGui/QPainter>
15 #include <QtGui/QMenu>
16 #include <QtGui/QLabel>
18 #include <SeExpr2/ExprBuiltins.h>
19 #ifdef SEEXPR_USE_QDGUI
20 # include <qdgui/QdColorPickerDialog.h>
27 QFrame(parent), _value(value)
30 setFrameStyle(QFrame::Box | QFrame::Plain);
31 QPalette pal = palette();
32 pal.setColor(backgroundRole(), pal.highlight().color());
34 setAutoFillBackground(
true);
39 _color = QColor(
int(255 * value[0] + 0.5),
40 int(255 * value[1] + 0.5),
41 int(255 * value[2] + 0.5));
55 p.fillRect(contentsRect(),
_color);
60 if (event->button() == Qt::RightButton)
64 #ifdef SEEXPR_USE_QDGUI
65 QColor color = QdColorPickerDialog::chooseColorFromDialog(
_color,
this);
67 QColor color = QColorDialog::getColor(
_color);
70 if (color.isValid()) {
71 _value[0] = color.red() / 255.0;
72 _value[1] = color.green() / 255.0;
73 _value[2] = color.blue() / 255.0;
84 QMenu *menu =
new QMenu(
this);
85 QAction *deleteAction = menu->addAction(
"Delete Swatch");
86 menu->addAction(
"Cancel");
87 QAction *action = menu->exec(mapToGlobal(pos));
88 if (action == deleteAction)
94 bool indexLabel, QWidget* parent) :
101 QVBoxLayout *vbox =
new QVBoxLayout();
102 vbox->setContentsMargins(0,0,0,0);
107 std::stringstream indexSS;
109 QLabel *label =
new QLabel(indexSS.str().c_str());
110 vbox->addWidget(label);
124 QWidget(parent), _columns(8), _indexLabel(indexLabel)
126 QHBoxLayout *hboxLayout =
new QHBoxLayout();
127 hboxLayout->setContentsMargins(0,0,0,0);
128 setLayout(hboxLayout);
130 QPushButton *addBtn =
new QPushButton(
"+");
131 addBtn->setFixedWidth(16);
132 addBtn->setFixedHeight(16);
133 QVBoxLayout *swatchControlLayout =
new QVBoxLayout();
134 swatchControlLayout->setContentsMargins(0,0,0,0);
135 QHBoxLayout *addRemoveBtnLayout =
new QHBoxLayout();
136 addRemoveBtnLayout->setContentsMargins(0,0,0,0);
137 addRemoveBtnLayout->setSpacing(0);
138 addRemoveBtnLayout->addWidget(addBtn);
139 swatchControlLayout->addLayout(addRemoveBtnLayout);
140 swatchControlLayout->addStretch();
142 QHBoxLayout *paletteLayout =
new QHBoxLayout();
143 paletteLayout->setContentsMargins(0,0,0,0);
144 QWidget *colorGrid =
new QWidget();
145 colorGrid->setMinimumWidth(256);
150 paletteLayout->addStretch();
151 colorGrid->setLayout(paletteLayout);
153 hboxLayout->addWidget(colorGrid);
154 hboxLayout->addLayout(swatchControlLayout);
155 hboxLayout->addStretch();
158 connect(addBtn, SIGNAL(clicked()),
this, SLOT(
addNewColor()));
193 QWidget * parentWidget = widget->parentWidget();
196 if (
_gridLayout->itemAt(i)->widget() == parentWidget){
198 parentWidget->deleteLater();
207 if(index >=0 && index < _gridLayout->count()){
208 SeExpr2::Vec3d newColor(color.redF(),color.greenF(),color.blueF());
209 QLayoutItem *layoutItem =
_gridLayout->itemAt(index);
210 if (layoutItem && layoutItem->widget()){
211 QWidget *widget = layoutItem->widget();
220 if(index >=0 && index < _gridLayout->count()){
221 QLayoutItem *layoutItem =
_gridLayout->itemAt(index);
222 if (layoutItem && layoutItem->widget()){
223 QWidget *widget = layoutItem->widget();
226 return QColor::fromRgbF(val[0],val[1],val[2],1);
SeExpr2::Vec3d getValue() const
void deleteSwatchMenu(const QPoint &pos)
void swatchChanged(QColor color)
void setValue(const SeExpr2::Vec3d &value)
void selValChangedSignal(SeExpr2::Vec3d value)
For any rgb or hsl value(except for negative s values)
void deleteSwatch(ExprColorFrame *swatch)
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). 
virtual void mouseReleaseEvent(QMouseEvent *event)
virtual void paintEvent(QPaintEvent *event)
ExprColorFrame(SeExpr2::Vec3d value, QWidget *parent=0)