Example #1
0
void BookmarksToolbar::showBookmarkContextMenu(const QPoint &pos)
{
    Q_UNUSED(pos)

    ToolButton* button = qobject_cast<ToolButton*>(sender());
    if (!button) {
        return;
    }

    QVariant buttonPointer = QVariant::fromValue((void*) button);

    QMenu menu;
    menu.addAction(tr("Open bookmark"), this, SLOT(loadClickedBookmark()))->setData(buttonPointer);
    menu.addAction(tr("Open bookmark in new tab"), this, SLOT(loadClickedBookmarkInNewTab()))->setData(buttonPointer);
    menu.addSeparator();
    menu.addAction(qIconProvider->fromTheme("go-next"), tr("Move right"), this, SLOT(moveRight()))->setData(buttonPointer);
    menu.addAction(qIconProvider->fromTheme("go-previous"), tr("Move left"), this, SLOT(moveLeft()))->setData(buttonPointer);
    menu.addAction(tr("Edit bookmark"), this, SLOT(editBookmark()))->setData(buttonPointer);
    menu.addSeparator();
    menu.addAction(qIconProvider->fromTheme("list-remove"), tr("Remove bookmark"), this, SLOT(removeButton()))->setData(buttonPointer);

    //Prevent choosing first option with double rightclick
    QPoint position = button->mapToGlobal(pos);
    QPoint p(position.x(), position.y() + 1);
    menu.exec(p);
}
Example #2
0
void NavigationBar::toolActionActivated()
{
    QAction *act = qobject_cast<QAction*>(sender());
    if (!act) {
        return;
    }
    const QString id = act->data().toString();
    if (!m_widgets.contains(id)) {
        return;
    }
    WidgetData data = m_widgets.value(id);
    if (!data.button) {
        return;
    }
    ToolButton *buttonTools = qobject_cast<ToolButton*>(m_widgets.value(QSL("button-tools")).widget);
    if (!buttonTools) {
        return;
    }

    AbstractButtonInterface::ClickController *c = new AbstractButtonInterface::ClickController;
    c->visualParent = buttonTools;
    c->popupPosition = [=](const QSize &size) {
        QPoint pos = buttonTools->mapToGlobal(buttonTools->rect().bottomRight());
        if (QApplication::isRightToLeft()) {
            pos.setX(pos.x() - buttonTools->rect().width());
        } else {
            pos.setX(pos.x() - size.width());
        }
        c->popupOpened = true;
        return pos;
    };
    c->popupClosed = [=]() {
        buttonTools->setDown(false);
        delete c;
    };
    emit data.button->clicked(c);
    if (c->popupOpened) {
        buttonTools->setDown(true);
    } else {
        c->popupClosed();
    }
}