Example #1
0
void Presenter::fillContextMenu(
        QMenu& menu,
        const QPoint& pos,
        const QPointF& scenepos)
{
    menu.addSeparator();

    auto removeAct = new QAction{tr("Remove"), this};
    connect(removeAct, &QAction::triggered,
            [&] () {
        removeSelection();
    });

    auto typeMenu = menu.addMenu(tr("Type"));
    for(const auto& seg : m_curveSegments)
    {
        auto act = typeMenu->addAction(seg.prettyName());
        connect(act, &QAction::triggered,
                this, [this,key=seg.concreteFactoryKey()] () {
            updateSegmentsType(key);
        });
    }

    auto lockAction = new QAction{tr("Lock between points"), this};
    connect(lockAction, &QAction::toggled,
            this, [&] (bool b) { m_editionSettings.setLockBetweenPoints(b); });
    lockAction->setCheckable(true);
    lockAction->setChecked(m_editionSettings.lockBetweenPoints());

    auto suppressAction = new QAction{tr("Suppress on overlap"), this};
    connect(suppressAction, &QAction::toggled,
            this, [&] (bool b) { m_editionSettings.setSuppressOnOverlap(b); });

    suppressAction->setCheckable(true);
    suppressAction->setChecked(m_editionSettings.suppressOnOverlap());

    menu.addAction(removeAct);
    menu.addAction(lockAction);
    menu.addAction(suppressAction);
}
Example #2
0
void CurvePresenter::setupContextMenu()
{
    m_contextMenu = new QMenu;

    auto selectAct = new QAction{tr("Select"), this};

    selectAct->setCheckable(true);
    selectAct->setChecked(false);
    connect(selectAct, &QAction::toggled, this,
            [&] (bool b) {
        if(b)
            m_sm->changeTool(int(Curve::Tool::Selection));
        else
            m_sm->changeTool(int(Curve::Tool::Move));
    });

    auto removeAct = new QAction{tr("Remove"), this};
    removeAct->setData(2); // Small identifier for segments actions...

    auto typeMenu = m_contextMenu->addMenu(tr("Type"));
    for(const auto& seg : SingletonCurveSegmentList::instance().nameList())
    {
        auto act = typeMenu->addAction(seg);
        act->setData(1);
    }

    auto lockAction = new QAction{tr("Lock between points"), this};
    connect(lockAction, &QAction::toggled,
            this, [&] (bool b) { setLockBetweenPoints(b); });
    lockAction->setCheckable(true);
    lockAction->setChecked(true);

    auto suppressAction = new QAction{tr("Suppress on overlap"), this};
    connect(suppressAction, &QAction::toggled,
            this, [&] (bool b) { setSuppressOnOverlap(b); });

    suppressAction->setCheckable(true);
    suppressAction->setChecked(false);

    m_contextMenu->addAction(selectAct);
    m_contextMenu->addAction(removeAct);
    m_contextMenu->addAction(lockAction);
    m_contextMenu->addAction(suppressAction);

    connect(m_view, &CurveView::contextMenuRequested,
            this, [&] (const QPoint& pt)
    {
        auto act = m_contextMenu->exec(pt, nullptr);
        m_contextMenu->close();

        if(!act)
        {
            return;
        }
        else if(act->data().value<int>() == 1)
        {
            updateSegmentsType(act->text());
        }
        else if(act->data().value<int>() == 2)
        {
            removeSelection();
        }
    });
}