void KnobGuiColor::onDialogCurrentColorChanged(const QColor & color) { KnobColorPtr knob = _knob.lock(); if (!knob) { return; } int nDims = knob->getNDimensions(); std::vector<double> values(nDims); values[0] = color.redF(); convertFromUIToInternalColorspace(&values[0]); if (nDims > 1) { values[1] = color.greenF(); convertFromUIToInternalColorspace(&values[1]); } if (nDims > 2) { values[2] = color.blueF(); convertFromUIToInternalColorspace(&values[2]); } if (nDims > 3) { values[3] = color.alphaF(); } KnobGuiPtr knobUI = getKnobGui(); knob->setValueAcrossDimensions(values, DimIdx(0), getView(), eValueChangedReasonUserEdited); if ( knobUI->getGui() ) { knobUI->getGui()->setDraftRenderEnabled(true); } }
void KnobGuiColor::onDimensionsMadeVisible(bool visible) { KnobColorPtr knob = _knob.lock(); if (!knob) { return; } int nDims = knob->getNDimensions(); QColor colors[4]; colors[0].setRgbF(0.851643, 0.196936, 0.196936); colors[1].setRgbF(0, 0.654707, 0); colors[2].setRgbF(0.345293, 0.345293, 1); colors[3].setRgbF(0.398979, 0.398979, 0.398979); for (int i = 0; i < nDims; ++i) { SpinBox* sb = 0; getSpinBox(DimIdx(i), &sb); assert(sb); if (!visible) { sb->setAdditionalDecorationTypeEnabled(LineEdit::eAdditionalDecorationColoredUnderlinedText, false); } else { sb->setAdditionalDecorationTypeEnabled(LineEdit::eAdditionalDecorationColoredUnderlinedText, true, colors[i]); } } }
void KnobGuiColor::onDialogCurrentColorChanged(const QColor & color) { KnobColorPtr knob = _knob.lock(); bool isSimple = _useSimplifiedUI; int nDims = knob->getNDimensions(); std::vector<double> values(nDims); values[0] = isSimple ? color.redF() : Color::from_func_srgb( color.redF() ); if (nDims >= 3) { values[1] = isSimple ? color.greenF() : Color::from_func_srgb( color.greenF() ); values[2] = isSimple ? color.blueF() : Color::from_func_srgb( color.blueF() ); if (nDims == 4) { values[3] = color.alphaF(); } } KnobGuiPtr knobUI = getKnobGui(); knob->setValueAcrossDimensions(values, DimIdx(0), getView(), eValueChangedReasonUserEdited); if ( knobUI->getGui() ) { knobUI->getGui()->setDraftRenderEnabled(true); } }
void KnobGuiColor::getDecimals(std::vector<int>* decimals) const { KnobColorPtr knob = _knob.lock(); if (!knob) { return; } int nDims = knob->getNDimensions(); decimals->resize(nDims); for (int i = 0; i < nDims; ++i) { (*decimals)[i] = 6; } }
void KnobGuiColor::getIncrements(std::vector<double>* increments) const { KnobColorPtr knob = _knob.lock(); if (!knob) { return; } int nDims = knob->getNDimensions(); increments->resize(nDims); for (int i = 0; i < nDims; ++i) { (*increments)[i] = 0.001; } }
void KnobGuiColor::showColorDialog() { QColorDialog dialog( _colorLabel->parentWidget() ); dialog.setOption(QColorDialog::DontUseNativeDialog); KnobColorPtr knob = _knob.lock(); if (!knob) { return; } const int nDims = knob->getNDimensions(); ViewIdx view = getView(); double curR = knob->getValue(DimIdx(0), view, false /*clampToMinmax*/); _lastColor.resize(nDims); _lastColor[0] = curR; double curG = curR; double curB = curR; double curA = 1.; if (nDims > 1) { curG = knob->getValue(DimIdx(1), view, false /*clampToMinmax*/); _lastColor[1] = curG; curB = knob->getValue(DimIdx(2), view, false /*clampToMinmax*/); _lastColor[2] = curB; } if (nDims > 3) { dialog.setOption(QColorDialog::ShowAlphaChannel); curA = knob->getValue(DimIdx(3), view, false /*clampToMinmax*/); _lastColor[3] = curA; } convertFromInternalToUIColorspace(&curR, &curG, &curB); QColor curColor; curColor.setRgbF( Image::clamp<qreal>(curR, 0., 1.), Image::clamp<qreal>(curG, 0., 1.), Image::clamp<qreal>(curB, 0., 1.), Image::clamp<qreal>(curA, 0., 1.) ); dialog.setCurrentColor(curColor); QObject::connect( &dialog, SIGNAL(currentColorChanged(QColor)), this, SLOT(onDialogCurrentColorChanged(QColor)) ); if ( !dialog.exec() ) { knob->setValueAcrossDimensions(_lastColor, DimIdx(0), view, eValueChangedReasonUserEdited); } else { QColor userColor = dialog.currentColor(); std::vector<double> color(nDims); color[0] = userColor.redF(); convertFromUIToInternalColorspace(&color[0]); if (nDims > 1) { color[1] = userColor.greenF(); convertFromUIToInternalColorspace(&color[1]); } if (nDims > 2) { color[2] = userColor.blueF(); convertFromUIToInternalColorspace(&color[2]); } if (nDims > 3) { color[3] = userColor.alphaF(); } for (int i = 0; i < 3; ++i) { SpinBox* sb = 0; getSpinBox(DimIdx(i), &sb); if (sb) { sb->setValue(color[i]); } } std::vector<double> oldColor(nDims); for (int i = 0; i < nDims; ++i) { oldColor[i] = _lastColor[i]; } KnobGuiPtr knobUI = getKnobGui(); knobUI->pushUndoCommand( new KnobUndoCommand<double>(knob, oldColor, color, getView()) ); } KnobGuiPtr knobUI = getKnobGui(); if ( knobUI->getGui() ) { knobUI->getGui()->setDraftRenderEnabled(false); } } // showColorDialog