NodeCreationDialog::NodeCreationDialog(const QString& initialFilter, QWidget* parent) : QDialog(parent) , _imp( new NodeCreationDialogPrivate() ) { setWindowTitle( tr("Node Creation Tool") ); setWindowFlags(Qt::Window | Qt::CustomizeWindowHint); setObjectName( QString::fromUtf8("nodeCreationDialog") ); setAttribute(Qt::WA_DeleteOnClose, false); _imp->layout = new QVBoxLayout(this); _imp->layout->setContentsMargins(0, 0, 0, 0); CompleterLineEdit::PluginsNamesMap pluginsMap; QString initialFilterName; std::string stdInitialFilter = initialFilter.toStdString(); int i = 0; for (PluginsMap::iterator it = _imp->items.begin(); it != _imp->items.end(); ++it) { if ( it->second.empty() ) { continue; } if (it->second.size() == 1) { std::pair<QString, QString> idNamePair; Plugin* p = ( *it->second.begin() ); if ( !p->getIsUserCreatable() ) { continue; } idNamePair.second = p->generateUserFriendlyPluginID(); int indexOfBracket = idNamePair.second.lastIndexOf( QString::fromUtf8(" [") ); if (indexOfBracket != -1) { idNamePair.first = idNamePair.second.left(indexOfBracket); } int weight = getPluginWeight( p->getPluginID(), p->getMajorVersion() ); pluginsMap.insert( std::make_pair(weight, idNamePair) ); if (it->first == stdInitialFilter) { initialFilterName = idNamePair.first; } ++i; } else { QString bestMajorName; for (PluginMajorsOrdered::reverse_iterator it2 = it->second.rbegin(); it2 != it->second.rend(); ++it2) { if ( !(*it2)->getIsUserCreatable() ) { continue; } std::pair<QString, QString> idNamePair; if ( it2 == it->second.rbegin() ) { idNamePair.second = (*it2)->generateUserFriendlyPluginID(); bestMajorName = idNamePair.second; } else { idNamePair.second = (*it2)->generateUserFriendlyPluginIDMajorEncoded(); } int indexOfBracket = idNamePair.second.lastIndexOf( QString::fromUtf8(" [") ); if (indexOfBracket != -1) { idNamePair.first = idNamePair.second.left(indexOfBracket); } ++i; int weight = getPluginWeight( (*it2)->getPluginID(), (*it2)->getMajorVersion() ); pluginsMap.insert( std::make_pair(weight, idNamePair) ); } if (it->first == stdInitialFilter) { initialFilterName = bestMajorName; } } } _imp->textEdit = new CompleterLineEdit(pluginsMap, true, this); if ( !initialFilterName.isEmpty() ) { _imp->textEdit->setText(initialFilterName); } QPoint global = QCursor::pos(); QSize sizeH = sizeHint(); global.rx() -= sizeH.width() / 2; global.ry() -= sizeH.height() / 2; move( global.x(), global.y() ); _imp->layout->addWidget(_imp->textEdit); _imp->textEdit->setFocus(); _imp->textEdit->selectAll(); QTimer::singleShot( 20, _imp->textEdit, SLOT(showCompleter()) ); }
void ContactListEdit::onCompleterRequest() { setFocus(); showCompleter(QString()); }
void ContactListEdit::onTextChanged() { /** Remember last changed text range in _activeCursor member. Will be used to replace entered text whith contact entry. */ QString text = textUnderCursor(&_activeCursor); if(_skipCompletion == false && _completer != nullptr && isReadOnly() == false && text.isEmpty() == false) { TAutoSkipCompletion asc(this); std::string textKey = text.toStdString(); bts::addressbook::wallet_contact matchedContact; bool contactFound = false; try { auto aBook = bts::get_profile()->get_addressbook(); auto contact = aBook->get_contact_by_display_name(textKey); contactFound = contact; if(contactFound == false) contact = aBook->get_contact_by_dac_id(textKey); if(contact) { contactFound = true; matchedContact = *contact; } } catch(const fc::exception& e) { wlog( "${e}", ("e",e.to_detail_string()) ); } bool semanticallyValidKey = false; if(contactFound) { /// Delete previously entered text - will be replaced with image control holding contact info deleteEnteredText(); /// Update PK-like text with displayed form text = QString::fromStdString(matchedContact.get_display_name()); /// If text already points to some found contact, just add it addContactEntry(text, matchedContact, false); } else if(public_key_address::is_valid(textKey, &semanticallyValidKey) && semanticallyValidKey) { /// Delete previously entered text - will be replaced with image control holding contact info deleteEnteredText(); public_key_address converter(textKey); fc::ecc::public_key parsedKey = converter.key; if(Utils::matchContact(parsedKey, &matchedContact)) { QString displayText = _completerModel->getDisplayText(Contact(matchedContact)); addContactEntry(displayText, matchedContact, false); QString txt = tr("Known public key has been replaced with matching contact..."); /// Don't pass here parent widget to avoid switching active window when tooltip appears QToolTip::showText(QCursor::pos(), txt, nullptr, QRect(), 3000); } else { QString tooltip = tr("Valid, but <b>unknown</b> public key, cannot be matched to any contact " "present in address book..."); addContactEntry(text, matchedContact, true, &tooltip); } } else { QTextCharFormat fmt; fmt.setFontWeight(QFont::Bold); fmt.setForeground(QColor(Qt::red)); fmt.setToolTip(tr("Unknown contact - can be <b>ignored</b> while sending message")); _activeCursor.mergeCharFormat(fmt); showCompleter(text); } } fitHeightToDocument(); }
PickKnobDialog::PickKnobDialog(DockablePanel* panel, QWidget* parent) : QDialog(parent) , _imp( new PickKnobDialogPrivate(panel) ) { NodeSettingsPanel* nodePanel = dynamic_cast<NodeSettingsPanel*>(panel); assert(nodePanel); if (!nodePanel) { throw std::logic_error("PickKnobDialog::PickKnobDialog()"); } NodeGuiPtr nodeGui = nodePanel->getNodeGui(); NodePtr node = nodeGui->getNode(); NodeGroupPtr isGroup = node->isEffectNodeGroup(); NodeCollectionPtr collec = node->getGroup(); NodeGroupPtr isCollecGroup = toNodeGroup(collec); NodesList collectNodes = collec->getNodes(); for (NodesList::iterator it = collectNodes.begin(); it != collectNodes.end(); ++it) { if ((*it)->isActivated() && (*it)->getNodeGui() && ( (*it)->getKnobs().size() > 0 ) ) { _imp->allNodes.push_back(*it); } } if (isCollecGroup) { _imp->allNodes.push_back( isCollecGroup->getNode() ); } if (isGroup) { NodesList groupnodes = isGroup->getNodes(); for (NodesList::iterator it = groupnodes.begin(); it != groupnodes.end(); ++it) { if ( (*it)->getNodeGui() && (*it)->isActivated() && ( (*it)->getKnobs().size() > 0 ) ) { _imp->allNodes.push_back(*it); } } } QStringList nodeNames; for (NodesList::iterator it = _imp->allNodes.begin(); it != _imp->allNodes.end(); ++it) { QString name = QString::fromUtf8( (*it)->getLabel().c_str() ); nodeNames.push_back(name); } nodeNames.sort(); _imp->mainLayout = new QGridLayout(this); _imp->selectNodeLabel = new Label( tr("Node:") ); _imp->nodeSelectionCombo = new CompleterLineEdit(nodeNames, nodeNames, false, this); _imp->nodeSelectionCombo->setToolTip( NATRON_NAMESPACE::convertFromPlainText(tr("Input the name of a node in the current project."), NATRON_NAMESPACE::WhiteSpaceNormal) ); _imp->nodeSelectionCombo->setFocus(Qt::PopupFocusReason); _imp->knobSelectionCombo = new ComboBox(this); QObject::connect( _imp->knobSelectionCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onKnobComboIndexChanged(int)) ); QString useAliasTt = NATRON_NAMESPACE::convertFromPlainText(tr("If checked, an alias of the selected parameter will be created, coyping entirely its state. " "Only the script-name, label and tooltip will be editable.\n" "For choice parameters this will also " "dynamically refresh the menu entries when the original parameter's menu is changed.\n" "When unchecked, a simple expression will be set linking the two parameters, but things such as dynamic menus " "will be disabled."), NATRON_NAMESPACE::WhiteSpaceNormal); _imp->useAliasLabel = new Label(tr("Make Alias:"), this); _imp->useAliasLabel->setToolTip(useAliasTt); _imp->useAliasCheckBox = new QCheckBox(this); _imp->useAliasCheckBox->setToolTip(useAliasTt); _imp->useAliasCheckBox->setChecked(true); QObject::connect( _imp->nodeSelectionCombo, SIGNAL(itemCompletionChosen()), this, SLOT(onNodeComboEditingFinished()) ); _imp->destPageLabel = new Label(tr("Page:"), this); QString pagett = NATRON_NAMESPACE::convertFromPlainText(tr("Select the page into which the parameter will be created."), NATRON_NAMESPACE::WhiteSpaceNormal); _imp->destPageLabel->setToolTip(pagett); _imp->destPageCombo = new ComboBox(this); _imp->destPageCombo->setToolTip(pagett); QObject::connect( _imp->destPageCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onPageComboIndexChanged(int)) ); const KnobsVec& knobs = node->getKnobs(); for (std::size_t i = 0; i < knobs.size(); ++i) { if ( knobs[i]->isUserKnob() ) { KnobPagePtr isPage = toKnobPage(knobs[i]); if (isPage) { _imp->pages.push_back(isPage); _imp->destPageCombo->addItem( QString::fromUtf8( isPage->getName().c_str() ) ); } else { KnobGroupPtr isGrp = toKnobGroup(knobs[i]); if (isGrp) { _imp->groups.push_back(isGrp); } } } } if (_imp->destPageCombo->count() == 0) { _imp->destPageLabel->hide(); _imp->destPageCombo->hide(); } _imp->groupLabel = new Label(tr("Group:"), this); QString grouptt = NATRON_NAMESPACE::convertFromPlainText(tr("Select the group into which the parameter will be created."), NATRON_NAMESPACE::WhiteSpaceNormal); _imp->groupCombo = new ComboBox(this); _imp->groupLabel->setToolTip(grouptt); _imp->groupCombo->setToolTip(grouptt); onPageComboIndexChanged(0); _imp->buttons = new DialogButtonBox(QDialogButtonBox::StandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel), Qt::Horizontal, this); QObject::connect( _imp->buttons, SIGNAL(accepted()), this, SLOT(accept()) ); QObject::connect( _imp->buttons, SIGNAL(rejected()), this, SLOT(reject()) ); _imp->mainLayout->addWidget(_imp->selectNodeLabel, 0, 0, 1, 1); _imp->mainLayout->addWidget(_imp->nodeSelectionCombo, 0, 1, 1, 1); _imp->mainLayout->addWidget(_imp->knobSelectionCombo, 0, 2, 1, 1); _imp->mainLayout->addWidget(_imp->useAliasLabel, 1, 0, 1, 1); _imp->mainLayout->addWidget(_imp->useAliasCheckBox, 1, 1, 1, 1); _imp->mainLayout->addWidget(_imp->destPageLabel, 2, 0, 1, 1); _imp->mainLayout->addWidget(_imp->destPageCombo, 2, 1, 1, 1); _imp->mainLayout->addWidget(_imp->groupLabel, 2, 2, 1, 1); _imp->mainLayout->addWidget(_imp->groupCombo, 2, 3, 1, 1); _imp->mainLayout->addWidget(_imp->buttons, 3, 0, 1, 3); QTimer::singleShot( 25, _imp->nodeSelectionCombo, SLOT(showCompleter()) ); }
NodeCreationDialog::NodeCreationDialog(const QString& _defaultPluginID, QWidget* parent) : QDialog(parent) , _imp( new NodeCreationDialogPrivate() ) { setWindowTitle( tr("Node Creation Tool") ); setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); setObjectName( QString::fromUtf8("nodeCreationDialog") ); setAttribute(Qt::WA_DeleteOnClose, true); _imp->layout = new QVBoxLayout(this); _imp->layout->setContentsMargins(0, 0, 0, 0); CompleterLineEdit::PluginsNamesMap pluginsMap; QString initialFilter; std::string defaultPluginID = _defaultPluginID.toStdString(); const PluginsMap& plugins = appPTR->getPluginsList(); for (PluginsMap::const_iterator it = plugins.begin(); it != plugins.end(); ++it) { for (PluginVersionsOrdered::const_reverse_iterator itver = it->second.rbegin(); itver != it->second.rend(); ++itver) { if ( !(*itver)->getIsUserCreatable() ) { continue; } CompleterLineEdit::PluginDesc desc; QString pluginID = QString::fromUtf8((*itver)->getPluginID().c_str()); { desc.plugin = *itver; // This is the highest major version of the plug-in if ( itver == it->second.rbegin() ) { desc.comboLabel = QString::fromUtf8((*itver)->generateUserFriendlyPluginID().c_str()); desc.lineEditLabel = QString::fromUtf8((*itver)->getLabelWithoutSuffix().c_str()); if (it->first == defaultPluginID) { initialFilter = desc.lineEditLabel; } } else { desc.comboLabel = QString::fromUtf8((*itver)->generateUserFriendlyPluginIDMajorEncoded().c_str()); desc.lineEditLabel = QString::fromUtf8((*itver)->getLabelVersionMajorEncoded().c_str()); } int weight = getPluginWeight(pluginID, QString(), (*itver)->getMajorVersion() ); pluginsMap.insert( std::make_pair(weight, desc) ); } // Add also an entry for each preset const std::vector<PluginPresetDescriptor>& presets = (*itver)->getPresetFiles(); for (std::vector<PluginPresetDescriptor>::const_iterator it3 = presets.begin(); it3 != presets.end(); ++it3) { CompleterLineEdit::PluginDesc presetDesc = desc; presetDesc.presetName = it3->presetLabel; QString presetSuffix = QLatin1String(" (") + presetDesc.presetName + QLatin1String(")"); presetDesc.comboLabel += presetSuffix; presetDesc.lineEditLabel += presetSuffix; int weight = getPluginWeight(pluginID, it3->presetLabel, (*itver)->getMajorVersion() ); pluginsMap.insert( std::make_pair(weight, presetDesc) ); } } } _imp->textEdit = new CompleterLineEdit(pluginsMap, true, this); if ( !initialFilter.isEmpty() ) { _imp->textEdit->setText(initialFilter); } QPoint global = QCursor::pos(); QSize sizeH = sizeHint(); global.rx() -= sizeH.width() / 2; global.ry() -= sizeH.height() / 2; move( global.x(), global.y() ); _imp->layout->addWidget(_imp->textEdit); _imp->textEdit->setFocus(); _imp->textEdit->selectAll(); QTimer::singleShot( 20, _imp->textEdit, SLOT(showCompleter()) ); }