Exemplo n.º 1
0
    CompleterLineEditPrivate(const QStringList & displayWords,
                             const QStringList & internalIds,
                             bool quickExit,
                             QDialog* parent)
        : dialog(parent)
        , listView(NULL)
        , model(NULL)
        , quickExitEnabled(quickExit)
    {
        assert( displayWords.size() == internalIds.size() );

        for (int i = 0; i < displayWords.size(); ++i) {
            names.insert( std::make_pair( 0, std::make_pair(internalIds[i], displayWords[i]) ) );
        }
    }
Exemplo n.º 2
0
    CompleterLineEditPrivate(const QStringList & displayWords,
                             const QStringList & internalIds,
                             bool quickExit,
                             QDialog* parent)
        : dialog(parent)
        , listView(NULL)
        , model(NULL)
        , quickExitEnabled(quickExit)
    {
        assert( displayWords.size() == internalIds.size() );

        for (int i = 0; i < displayWords.size(); ++i) {
            CompleterLineEdit::PluginDesc desc;
            desc.comboLabel = displayWords[i];
            desc.lineEditLabel = internalIds[i];
            names.insert(std::make_pair(0, desc));
        }
    }
Exemplo n.º 3
0
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()) );
}
Exemplo n.º 4
0
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()) );
}