Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
RestoreDefaultsCommand::RestoreDefaultsCommand(const std::list<KnobIPtr > & knobs,
                                               DimSpec targetDim,
                                               ViewSetSpec targetView,
                                               QUndoCommand *parent)
: QUndoCommand(parent)
, _targetDim(targetDim)
, _targetView(targetView)
, _knobs()
{
    setText( tr("Restore Default Value(s)") );


    for (std::list<KnobIPtr >::const_iterator it = knobs.begin(); it != knobs.end(); ++it) {
        KnobButtonPtr isButton = toKnobButton(*it);
        KnobPagePtr isPage = toKnobPage(*it);
        KnobSeparatorPtr isSep = toKnobSeparator(*it);
        if (isSep || isPage || (isButton && !isButton->getIsCheckable())) {
            continue;
        }

        SERIALIZATION_NAMESPACE::KnobSerializationPtr s(new SERIALIZATION_NAMESPACE::KnobSerialization());
        (*it)->toSerialization(s.get());
        _serializations.push_back(s);
        _knobs.push_back(*it);

    }
}
Ejemplo n.º 3
0
void
ViewerNode::setRefreshButtonDown(bool down)
{
    KnobButtonPtr knob = _imp->refreshButtonKnob.lock();
    // Ignore evaluation

    ScopedChanges_RAII changes(this, true);
    knob->setValue(down, ViewIdx(0), DimIdx(0), eValueChangedReasonTimeChanged);

}
Ejemplo n.º 4
0
void
DiskCacheNode::initializeKnobs()
{
    KnobPagePtr page = createKnob<KnobPage>("controlsPage");
    page->setLabel(tr("Controls") );
    KnobChoicePtr frameRange = createKnob<KnobChoice>(kDiskCacheNodeFrameRange);
    frameRange->setLabel(tr(kDiskCacheNodeFrameRangeLabel) );
    frameRange->setHintToolTip(tr(kDiskCacheNodeFrameRangeHint));
    frameRange->setAnimationEnabled(false);
    {
        std::vector<ChoiceOption> choices;
        choices.push_back(ChoiceOption("Input frame range", "", ""));
        choices.push_back(ChoiceOption("Project frame range", "", ""));
        choices.push_back(ChoiceOption("Manual","", ""));
        frameRange->populateChoices(choices);
    }
    frameRange->setEvaluateOnChange(false);
    frameRange->setDefaultValue(0);
    page->addKnob(frameRange);
    _imp->frameRange = frameRange;

    KnobIntPtr firstFrame = createKnob<KnobInt>(kDiskCacheNodeFirstFrame);
    firstFrame->setLabel(tr(kDiskCacheNodeFirstFrameLabel) );
    firstFrame->setHintToolTip(tr(kDiskCacheNodeFirstFrameHint));
    firstFrame->setAnimationEnabled(false);
    firstFrame->disableSlider();
    firstFrame->setEvaluateOnChange(false);
    firstFrame->setAddNewLine(false);
    firstFrame->setDefaultValue(1);
    firstFrame->setSecret(true);
    page->addKnob(firstFrame);
    _imp->firstFrame = firstFrame;

    KnobIntPtr lastFrame = createKnob<KnobInt>(kDiskCacheNodeLastFrame);
    lastFrame->setAnimationEnabled(false);
    lastFrame->setLabel(tr(kDiskCacheNodeLastFrameLabel));
    lastFrame->setHintToolTip(tr(kDiskCacheNodeLastFrameHint));
    lastFrame->disableSlider();
    lastFrame->setEvaluateOnChange(false);
    lastFrame->setDefaultValue(100);
    lastFrame->setSecret(true);
    page->addKnob(lastFrame);
    _imp->lastFrame = lastFrame;

    KnobButtonPtr preRender = createKnob<KnobButton>("preRender");
    preRender->setLabel(tr("Pre-cache"));
    preRender->setEvaluateOnChange(false);
    preRender->setHintToolTip( tr("Cache the frame range specified by rendering images at zoom-level 100% only.") );
    page->addKnob(preRender);
    _imp->preRender = preRender;
}
Ejemplo n.º 5
0
void
KnobGuiButton::updateGUI()
{
    KnobButtonPtr k = _knob.lock();

    if ( k && k->getIsCheckable() ) {
        bool checked = k->getValue();
        if (_button->isChecked() == checked) {
            return;
        }
        _button->setDown(checked);
        _button->setChecked(checked);
    }
}
Ejemplo n.º 6
0
void
KnobGuiButton::emitValueChanged(bool clicked)
{
    KnobButtonPtr k = _knob.lock();

    assert(k);

    if ( k->getIsCheckable() ) {
        _button->setDown(clicked);
        _button->setChecked(clicked);

        KnobButtonPtr knob = _knob.lock();
        getKnobGui()->pushUndoCommand( new KnobUndoCommand<bool>(knob, knob->getValue(DimIdx(0), getView()), clicked, DimIdx(0), getView()) );
    } else {
        k->trigger();
    }
}
Ejemplo n.º 7
0
void
DiskCacheNode::initializeKnobs()
{
    KnobPagePtr page = AppManager::createKnob<KnobPage>( shared_from_this(), tr("Controls") );
    KnobChoicePtr frameRange = AppManager::createKnob<KnobChoice>( shared_from_this(), tr("Frame range") );

    frameRange->setName("frameRange");
    frameRange->setAnimationEnabled(false);
    std::vector<std::string> choices;
    choices.push_back("Input frame range");
    choices.push_back("Project frame range");
    choices.push_back("Manual");
    frameRange->populateChoices(choices);
    frameRange->setEvaluateOnChange(false);
    frameRange->setDefaultValue(0);
    page->addKnob(frameRange);
    _imp->frameRange = frameRange;

    KnobIntPtr firstFrame = AppManager::createKnob<KnobInt>( shared_from_this(), tr("First Frame") );
    firstFrame->setAnimationEnabled(false);
    firstFrame->setName("firstFrame");
    firstFrame->disableSlider();
    firstFrame->setEvaluateOnChange(false);
    firstFrame->setAddNewLine(false);
    firstFrame->setDefaultValue(1);
    firstFrame->setSecret(true);
    page->addKnob(firstFrame);
    _imp->firstFrame = firstFrame;

    KnobIntPtr lastFrame = AppManager::createKnob<KnobInt>( shared_from_this(), tr("Last Frame") );
    lastFrame->setAnimationEnabled(false);
    lastFrame->setName("LastFrame");
    lastFrame->disableSlider();
    lastFrame->setEvaluateOnChange(false);
    lastFrame->setDefaultValue(100);
    lastFrame->setSecret(true);
    page->addKnob(lastFrame);
    _imp->lastFrame = lastFrame;

    KnobButtonPtr preRender = AppManager::createKnob<KnobButton>( shared_from_this(), tr("Pre-cache") );
    preRender->setName("preRender");
    preRender->setEvaluateOnChange(false);
    preRender->setHintToolTip( tr("Cache the frame range specified by rendering images at zoom-level 100% only.") );
    page->addKnob(preRender);
    _imp->preRender = preRender;
}
Ejemplo n.º 8
0
void
KnobGuiButton::loadPixmaps(bool applyColorOverlay, const QColor& overlayColor)
{
    QPixmap uncheckedPix = loadPixmapInternal(false, applyColorOverlay, overlayColor);
    QPixmap checkedPix = loadPixmapInternal(true, applyColorOverlay, overlayColor);
    QIcon icon;
    if (!uncheckedPix.isNull()) {
        icon.addPixmap(uncheckedPix, QIcon::Normal, QIcon::Off);
    }
    if (!checkedPix.isNull()) {
        icon.addPixmap(checkedPix, QIcon::Normal, QIcon::On);
    }
    if (!icon.isNull()) {
        _button->setIcon(icon);
    } else {
        KnobButtonPtr knob = _knob.lock();
        QString label = QString::fromUtf8( knob->getLabel().c_str() );
        _button->setText(label);
    }
} // loadPixmap
Ejemplo n.º 9
0
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