Exemple #1
0
void StateActions::setupContextMenu(Process::LayerContextMenuManager& ctxm)
{
  using namespace Process;
  Process::LayerContextMenu cm
      = MetaContextMenu<ContextMenus::StateContextMenu>::make();

  cm.functions.push_back(
      [this](QMenu& menu, QPoint, QPointF, const Process::LayerContext& ctx) {
        using namespace score;
        auto sel = ctx.context.selectionStack.currentSelection();
        if (sel.empty())
          return;

        if (ossia::any_of(
                sel,
                matches<Scenario::StateModel>{})) // TODO : event or timesync ?
        {
          auto stateSubmenu = menu.addMenu(tr("State"));
          stateSubmenu->setObjectName("State");
          stateSubmenu->addAction(m_snapshot);
          stateSubmenu->addAction(m_refreshStates);
        }
      });

  ctxm.insert(std::move(cm));
}
void ObjectMenuActions::setupContextMenu(Process::LayerContextMenuManager &ctxm)
{
    using namespace Process;
    LayerContextMenu scenario_model = MetaContextMenu<ContextMenus::ScenarioModelContextMenu>::make();
    LayerContextMenu scenario_object = MetaContextMenu<ContextMenus::ScenarioObjectContextMenu>::make();

    // Used for scenario model
    scenario_model.functions.push_back(
                [this] (QMenu& menu, QPoint, QPointF scenePoint, const LayerContext& ctx)
    {
        auto& scenario = *safe_cast<const TemporalScenarioPresenter*>(&ctx.layerPresenter);
        auto sel = ctx.context.selectionStack.currentSelection();
        if(!sel.empty())
        {
            auto objectMenu = menu.addMenu(tr("Object"));

            objectMenu->addAction(m_elementsToJson);
            objectMenu->addAction(m_removeElements);
            objectMenu->addAction(m_clearElements);
            objectMenu->addSeparator();

            objectMenu->addAction(m_copyContent);
            objectMenu->addAction(m_cutContent);
            objectMenu->addAction(m_pasteContent);
        }

        auto pasteElements = new QAction{tr("Paste element(s)"), this};
        pasteElements->setShortcut(QKeySequence::Paste);
        pasteElements->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        connect(pasteElements, &QAction::triggered,
                [&,scenePoint]()
        {
            this->pasteElements(QJsonDocument::fromJson(QApplication::clipboard()->text().toUtf8()).object(),
                          Scenario::ConvertToScenarioPoint(
                                    scenePoint,
                                    scenario.zoomRatio(),
                                    scenario.view().boundingRect().height()));
        });
        menu.addAction(pasteElements);
    });

    // Used for base scenario, loops, etc.
    scenario_object.functions.push_back(
                [this] (QMenu& menu, QPoint, QPointF, const LayerContext& ctx)
    {
        auto sel = ctx.context.selectionStack.currentSelection();
        if(!sel.empty())
        {
            auto objectMenu = menu.addMenu(tr("Object"));

            objectMenu->addAction(m_elementsToJson);
            objectMenu->addAction(m_clearElements);
            objectMenu->addSeparator();

            objectMenu->addAction(m_copyContent);
            objectMenu->addAction(m_pasteContent);
        }
    });
    m_eventActions.setupContextMenu(ctxm);
    m_cstrActions.setupContextMenu(ctxm);
    m_stateActions.setupContextMenu(ctxm);

    ctxm.insert(std::move(scenario_model));
    ctxm.insert(std::move(scenario_object));
}