Example #1
0
void
KnobGuiChoice::onItemNewSelected()
{
    KnobChoicePtr knob = _knob.lock();
    if (!knob) {
        return;
    }
    ChoiceKnobDimView::KnobChoiceNewItemCallback callback = knob->getNewOptionCallback();
    if (!callback) {
        return;
    }
    callback(knob);
}
Example #2
0
void
KnobGuiChoice::onEntryAppended()
{
    KnobChoicePtr knob = _knob.lock();
    if (!knob) {
        return;
    }


    std::vector<ChoiceOption> options = knob->getEntries();

    for (int i = _comboBox->count(); i < (int)options.size(); ++i) {
        if ( knob->getNewOptionCallback()) {
            _comboBox->insertItem(_comboBox->count() - 1, QString::fromUtf8(options[i].label.c_str()), QIcon(), QKeySequence(), QString::fromUtf8(options[i].tooltip.c_str()));
        } else {
            _comboBox->addItem(QString::fromUtf8(options[i].label.c_str()), QIcon(), QKeySequence(), QString::fromUtf8(options[i].tooltip.c_str()));
        }

    }

    updateGUI();

}
Example #3
0
void
KnobGuiChoice::onEntriesPopulated()
{
    KnobChoicePtr knob = _knob.lock();
    if (!knob) {
        return;
    }

    _comboBox->clear();
    std::vector<ChoiceOption> entries = knob->getEntries();

    std::string pluginShortcutGroup;
    EffectInstancePtr isEffect = toEffectInstance(knob->getHolder());
    if (isEffect) {
        PluginPtr plugin = isEffect->getNode()->getOriginalPlugin();
        if (plugin) {
            pluginShortcutGroup = plugin->getPluginShortcutGroup();
        }
    }


    const std::map<int, std::string>& shortcutsMap = knob->getShortcuts();
    const std::map<int, std::string>& iconsMap = knob->getIcons();

    for (U32 i = 0; i < entries.size(); ++i) {

        std::string shortcutID;
        std::string iconFilePath;
        if (!pluginShortcutGroup.empty()) {
            std::map<int, std::string>::const_iterator foundShortcut = shortcutsMap.find(i);
            if (foundShortcut != shortcutsMap.end()) {
                shortcutID = foundShortcut->second;
            }
        }

        std::map<int, std::string>::const_iterator foundIcon = iconsMap.find(i);
        if (foundIcon != iconsMap.end()) {
            iconFilePath = foundIcon->second;
        }

        
        QIcon icon;
        if (!iconFilePath.empty()) {
            QPixmap pix( getPixmapPathFromFilePath( QString::fromUtf8( iconFilePath.c_str() ) ) );
            if (!pix.isNull()) {
                pix = pix.scaled(TO_DPIX(NATRON_MEDIUM_BUTTON_ICON_SIZE), TO_DPIY(NATRON_MEDIUM_BUTTON_ICON_SIZE));
                icon.addPixmap(pix);
            }
        }

        if (!shortcutID.empty() && !pluginShortcutGroup.empty() && !_comboBox->isCascading()) {
            QAction* action = new ActionWithShortcut(pluginShortcutGroup,
                                                     shortcutID,
                                                     entries[i].label,
                                                     _comboBox);
            if (!icon.isNull()) {
                action->setIcon(icon);
            }
            _comboBox->addAction(action);

        } else {
            _comboBox->addItem( QString::fromUtf8( entries[i].label.c_str() ), icon, QKeySequence(), QString::fromUtf8( entries[i].tooltip.c_str() ) );
            
        }
    } // for all entries

    const std::vector<int>& separators = knob->getSeparators();
    for (std::size_t i = 0; i < separators.size(); ++i) {
        _comboBox->insertSeparator(separators[i]);
    }

    // the "New" menu is only added to known parameters (e.g. the choice of output channels)
    if (knob->getNewOptionCallback()) {
        _comboBox->addItemNew();
    }

    updateGUI();

} // onEntriesPopulated