void KnobGuiColor::addExtraWidgets(QHBoxLayout* containerLayout) { containerLayout->addSpacing( TO_DPIX(10) ); KnobColorPtr knob = _knob.lock(); if (!knob) { return; } KnobGuiPtr knobUI = getKnobGui(); if (!knobUI) { return; } _colorLabel = new ColorPickerLabel( _useSimplifiedUI, knobUI->getLayoutType(), this, containerLayout->widget() ); if (!_useSimplifiedUI && knobUI->getLayoutType() != KnobGui::eKnobLayoutTypeTableItemWidget) { _colorLabel->setToolTip( NATRON_NAMESPACE::convertFromPlainText(tr("To pick a color on a viewer, click this and then press control + left click on any viewer.\n" "You can also pick the average color of a given rectangle by holding control + shift + left click\n. " "To deselect the picker left click anywhere." "Note that by default %1 converts to linear the color picked\n" "because all the processing pipeline is linear, but you can turn this off in the\n" "preferences panel.").arg( QString::fromUtf8(NATRON_APPLICATION_NAME) ), NATRON_NAMESPACE::WhiteSpaceNormal) ); } QSize medSize( TO_DPIX(NATRON_MEDIUM_BUTTON_SIZE), TO_DPIY(NATRON_MEDIUM_BUTTON_SIZE) ); QSize medIconSize( TO_DPIX(NATRON_MEDIUM_BUTTON_ICON_SIZE), TO_DPIY(NATRON_MEDIUM_BUTTON_ICON_SIZE) ); _colorLabel->setFixedSize(medSize); QObject::connect( _colorLabel, SIGNAL(pickingEnabled(bool)), this, SLOT(onColorLabelPickingEnabled(bool)) ); containerLayout->addWidget(_colorLabel); if (_useSimplifiedUI) { containerLayout->addSpacing( TO_DPIX(5) ); } if (knobUI->getLayoutType() != KnobGui::eKnobLayoutTypeTableItemWidget) { QPixmap buttonPix; appPTR->getIcon(NATRON_PIXMAP_COLORWHEEL, NATRON_MEDIUM_BUTTON_ICON_SIZE, &buttonPix); _colorDialogButton = new Button( QIcon(buttonPix), QString(), containerLayout->widget() ); _colorDialogButton->setFixedSize(medSize); _colorDialogButton->setIconSize(medIconSize); _colorDialogButton->setToolTip( NATRON_NAMESPACE::convertFromPlainText(tr("Open the color dialog."), NATRON_NAMESPACE::WhiteSpaceNormal) ); _colorDialogButton->setFocusPolicy(Qt::NoFocus); QObject::connect( _colorDialogButton, SIGNAL(clicked()), this, SLOT(showColorDialog()) ); containerLayout->addWidget(_colorDialogButton); } if (_useSimplifiedUI) { setWidgetsVisibleInternal(false); KnobGuiWidgets::enableRightClickMenu(getKnobGui(), _colorLabel, DimSpec::all(), getView()); } }
void KnobGuiButton::createWidget(QHBoxLayout* layout) { KnobGuiPtr knobUI = getKnobGui(); KnobButtonPtr knob = _knob.lock(); _button = new Button( layout->parentWidget() ); if (knobUI->getLayoutType() == KnobGui::eKnobLayoutTypeTableItemWidget) { _button->setIconSize( QSize(TO_DPIX(NATRON_SMALL_BUTTON_ICON_SIZE), TO_DPIY(NATRON_SMALL_BUTTON_ICON_SIZE)) ); } else { _button->setIconSize( QSize(TO_DPIX(NATRON_MEDIUM_BUTTON_ICON_SIZE), TO_DPIY(NATRON_MEDIUM_BUTTON_ICON_SIZE)) ); } loadPixmaps(false, QColor()); if (!_button->icon().isNull()) { _button->setFixedSize(TO_DPIX(NATRON_MEDIUM_BUTTON_SIZE), TO_DPIY(NATRON_MEDIUM_BUTTON_SIZE)); } bool checkable = knob->getIsCheckable(); if (checkable) { _button->setCheckable(true); bool checked = knob->getValue(); _button->setChecked(checked); _button->setDown(checked); } QObject::connect( _button, SIGNAL(clicked(bool)), this, SLOT(emitValueChanged(bool)) ); if ( knobUI->hasToolTip() ) { knobUI->toolTip(_button, getView()); } layout->addWidget(_button); } // KnobGuiButton::createWidget
KnobGuiColor::KnobGuiColor(const KnobGuiPtr& knobUI, ViewIdx view) : KnobGuiValue(knobUI, view) , _knob( toKnobColor(knobUI->getKnob()) ) , _colorLabel(0) , _colorDialogButton(0) , _useSimplifiedUI(false) , _uiColorspaceLut(0) , _internalColorspaceLut(0) { KnobColorPtr knob = _knob.lock(); if (!knob) { return; } _useSimplifiedUI = knob && knob->isSimplified(); if (!_useSimplifiedUI) { DimIdx singleDim; bool singleDimEnabled = knobUI->isSingleDimensionalEnabled(&singleDim); if (knobUI->getLayoutType() == KnobGui::eKnobLayoutTypeViewerUI && !singleDimEnabled) { _useSimplifiedUI = true; } } const std::string& uiName = knob->getUIColorspaceName(); const std::string& internalName = knob->getInternalColorspaceName(); _uiColorspaceLut = Color::LutManager::findLut(uiName); _internalColorspaceLut = Color::LutManager::findLut(internalName); }
KnobGuiColor::KnobGuiColor(const KnobGuiPtr& knobUI, ViewIdx view) : KnobGuiValue(knobUI, view) , _knob( toKnobColor(knobUI->getKnob()) ) , _colorLabel(0) , _colorDialogButton(0) , _useSimplifiedUI( _knob.lock()->isSimplified() ) { if (!_useSimplifiedUI) { DimIdx singleDim; bool singleDimEnabled = knobUI->isSingleDimensionalEnabled(&singleDim); if (knobUI->getLayoutType() == KnobGui::eKnobLayoutTypeViewerUI && !singleDimEnabled) { _useSimplifiedUI = true; } } }
QPixmap KnobGuiButton::loadPixmapInternal(bool checked, bool applyColorOverlay, const QColor& overlayColor) { KnobGuiPtr knobUI = getKnobGui(); KnobButtonPtr knob = _knob.lock(); EffectInstancePtr isEffect = toEffectInstance( knob->getHolder() ); KnobTableItemPtr isTableItem = toKnobTableItem(knob->getHolder()); if (isTableItem) { isEffect = isTableItem->getModel()->getNode()->getEffectInstance(); } QString filePath; if (knobUI->getLayoutType() == KnobGui::eKnobLayoutTypeViewerUI) { filePath = QString::fromUtf8( knob->getInViewerContextIconFilePath(checked).c_str() ); } else { filePath = QString::fromUtf8( knob->getIconLabel(checked).c_str() ); } if ( !filePath.isEmpty() && !QFile::exists(filePath) ) { if (isEffect) { //Prepend the resources path QString resourcesPath = QString::fromUtf8( isEffect->getNode()->getPluginResourcesPath().c_str() ); if ( !resourcesPath.endsWith( QLatin1Char('/') ) ) { resourcesPath += QLatin1Char('/'); } filePath.prepend(resourcesPath); } } if ( !filePath.isEmpty() ) { #if 0 QPixmap pix; if (pix.load(filePath)) { return pix; } #else QImage img; if ( img.load(filePath) ) { if (applyColorOverlay) { int depth = img.depth(); if (depth != 32) { img = img.convertToFormat(QImage::Format_ARGB32); } depth = img.depth(); assert(depth == 32); for (int y = 0; y < img.height(); ++y) { QRgb* pix = (QRgb*)img.scanLine(y); for (int x = 0; x < img.width(); ++x) { QRgb srcPix = pix[x]; double a = qAlpha(srcPix) / 255.f; double r = qRed(srcPix) / 255.f * a; double g = qGreen(srcPix) / 255.f * a; double b = qBlue(srcPix) / 255.f * a; r = Image::clamp(overFunctor(overlayColor.redF(), r, overlayColor.alphaF()), 0., 1.); g = Image::clamp(overFunctor(overlayColor.greenF(), g, overlayColor.alphaF()), 0., 1.); b = Image::clamp(overFunctor(overlayColor.blueF(), b, overlayColor.alphaF()), 0., 1.); a = Image::clamp(overFunctor(overlayColor.alphaF(), a, overlayColor.alphaF()) * a, 0., 1.); QRgb p = qRgba(r * 255, g * 255, b * 255, a * 255); img.setPixel(x, y, p); } } } QPixmap pix = QPixmap::fromImage(img); return pix; } #endif } return QPixmap(); } // loadPixmapInternal