QString KnobGuiChoice::getPixmapPathFromFilePath(const QString &filePath) const { KnobChoicePtr knob = _knob.lock(); if (!knob) { return QString(); } return getPixmapPathFromFilePath(knob->getHolder(),filePath); }
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