コード例 #1
0
ファイル: scgconfig.cpp プロジェクト: Lebedinsky/kbe
SCgConfig::SCgConfig(QObject *parent) :
    QObject(parent)
{
    configTabEl = new QWidget();
    defaultTypeNodeList = new QComboBox();

    SCgAlphabet::SCgObjectTypesMap types;
    SCgAlphabet::SCgObjectTypesMap::const_iterator iter;

    SCgAlphabet::getInstance().getObjectTypes("node", SCgAlphabet::Const, types);
    for (iter = types.begin(); iter != types.end(); ++iter)
        defaultTypeNodeList->addItem(iter.value(), iter.key());
    SCgAlphabet::getInstance().getObjectTypes("node", SCgAlphabet::Var, types);
    for (iter = types.begin(); iter != types.end(); ++iter)
        defaultTypeNodeList->addItem(iter.value(), iter.key());

    defaultTypePairList = new QComboBox();

    SCgAlphabet::getInstance().getObjectTypes("pair", SCgAlphabet::Const, types);
    for (iter = types.begin(); iter != types.end(); ++iter)
    {
        if (isWritting) break;
        QString first4symbols = iter.key();
        first4symbols.resize(4);
        if (first4symbols == "pair")
            defaultTypePairList->addItem(iter.value(), iter.key());
    }

    isWritting = true;
    SCgAlphabet::getInstance().getObjectTypes("pair", SCgAlphabet::Var, types);
    for (iter = types.begin(); iter != types.end(); ++iter)
    {
        QString first4symbols = iter.key();
        first4symbols.resize(4);
        if (first4symbols == "pair")
            defaultTypePairList->addItem(iter.value(), iter.key());
    }

    QVBoxLayout *vertical = new QVBoxLayout();
    QLabel *labelNodeList = new QLabel(tr("Default type of nodes: "));
    QLabel *labelPairList = new QLabel(tr("Default type of pairs: "));
    vertical->addWidget(labelNodeList);
    defaultTypeNodeList->setFixedWidth(250);
    vertical->addWidget(defaultTypeNodeList);
    vertical->addSpacing(20);
    vertical->addWidget(labelPairList);
    defaultTypePairList->setFixedWidth(250);
    vertical->addWidget(defaultTypePairList);
    vertical->addSpacing(150);

    configTabEl->setLayout(vertical);

    connect(defaultTypeNodeList, SIGNAL(activated(int)), this, SLOT(setNodeDefaultType()));
    connect(defaultTypePairList, SIGNAL(activated(int)), this, SLOT(setPairDefaultType()));
}
コード例 #2
0
ファイル: scgview.cpp プロジェクト: pkkazantsev/kbe
void SCgView::contextMenuEvent(QContextMenuEvent *event)
{
    if (event->reason() == QContextMenuEvent::Keyboard || event->reason() == QContextMenuEvent::Other)
        return;
    // get scg-object under mouse
    QPointF mousePos = mapToScene(event->pos());/* +
                                QPointF(horizontalScrollBar()->value(), verticalScrollBar()->value()) -
                                scene()->sceneRect().topLeft();*/

    SCgObject *object = static_cast<SCgScene*>(scene())->objectAt(mousePos);

    // create context menu
    if (mContextMenu)
    {
        delete mContextMenu;
        mContextMenu = 0;
    }

    // selection by right mouse click
    if(object && !object->isSelected())
    {
        scene()->clearSelection();
        object->setSelected(true);
    }

    // create new context menu
    mContextMenu = new QMenu;

    if (mContextObject)
    {
        // creating menu actions depending on object type
        if (mContextObject->type() == SCgNode::Type || mContextObject->type() == SCgPair::Type)
        {
            // type changing
            QMenu *menu = mContextMenu->addMenu(tr("Change type"));

            connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(changeType(QAction*)));

            QMenu* constSub = menu->addMenu(tr("Const"));
            QMenu* varSub = menu->addMenu(tr("Var"));

            QString stype;
            SCgAlphabet::SCgObjectTypesMap types;
            SCgAlphabet::SCgObjectTypesMap::const_iterator iter;

            if (mContextObject->type() == SCgNode::Type)
                stype = "node";
            else if (mContextObject->type() == SCgPair::Type)
                stype = "pair";

            SCgAlphabet::getInstance().getObjectTypes(stype, SCgAlphabet::Const, types);
            for (iter = types.begin(); iter != types.end(); ++iter)
                constSub->addAction(iter.value(), iter.key())->setData(QVariant(iter.key()));
            types.clear();
            SCgAlphabet::getInstance().getObjectTypes(stype, SCgAlphabet::Var, types);
            for (iter = types.begin(); iter != types.end(); ++iter)
                varSub->addAction(iter.value(), iter.key())->setData(QVariant(iter.key()));
            types.clear();

            SCgAlphabet::getInstance().getObjectTypes(stype, SCgAlphabet::ConstUnknown, types);
            for (iter = types.begin(); iter != types.end(); ++iter)
                menu->addAction(iter.value(), iter.key())->setData(QVariant(iter.key()));
            types.clear();
        }
    }