Ejemplo n.º 1
0
void VMdEditor::initCopyAsMenu(QAction *p_before, QMenu *p_menu)
{
    QStringList targets = g_webUtils->getCopyTargetsName();
    if (targets.isEmpty()) {
        return;
    }

    QMenu *subMenu = new QMenu(tr("Copy HTML As"), p_menu);
    subMenu->setToolTipsVisible(true);
    for (auto const & target : targets) {
        QAction *act = new QAction(target, subMenu);
        act->setData(target);
        act->setToolTip(tr("Copy selected content as HTML using rules specified by target %1").arg(target));

        subMenu->addAction(act);
    }

    connect(subMenu, &QMenu::triggered,
            this, &VMdEditor::handleCopyAsAction);

    QAction *menuAct = p_menu->insertMenu(p_before, subMenu);
    if (p_before) {
        p_menu->removeAction(p_before);
        p_menu->insertAction(menuAct, p_before);
        p_menu->insertSeparator(menuAct);
    }
}
Ejemplo n.º 2
0
void VMdEditor::contextMenuEvent(QContextMenuEvent *p_event)
{
    QMenu *menu = createStandardContextMenu();
    menu->setToolTipsVisible(true);

    VEditTab *editTab = dynamic_cast<VEditTab *>(parent());
    Q_ASSERT(editTab);
    if (editTab->isEditMode()) {
        const QList<QAction *> actions = menu->actions();

        if (textCursor().hasSelection()) {
            initCopyAsMenu(actions.isEmpty() ? NULL : actions.last(), menu);
        } else {
            QAction *saveExitAct = new QAction(VIconUtils::menuIcon(":/resources/icons/save_exit.svg"),
                                               tr("&Save Changes And Read"),
                                               menu);
            saveExitAct->setToolTip(tr("Save changes and exit edit mode"));
            connect(saveExitAct, &QAction::triggered,
                    this, [this]() {
                        emit m_object->saveAndRead();
                    });

            QAction *discardExitAct = new QAction(VIconUtils::menuIcon(":/resources/icons/discard_exit.svg"),
                                                  tr("&Discard Changes And Read"),
                                                  menu);
            discardExitAct->setToolTip(tr("Discard changes and exit edit mode"));
            connect(discardExitAct, &QAction::triggered,
                    this, [this]() {
                        emit m_object->discardAndRead();
                    });

            menu->insertAction(actions.isEmpty() ? NULL : actions[0], discardExitAct);
            menu->insertAction(discardExitAct, saveExitAct);
        }

        if (!actions.isEmpty()) {
            menu->insertSeparator(actions[0]);
        }
    }

    menu->exec(p_event->globalPos());
    delete menu;
}