bool ToolBarEventFilter::handleContextMenuEvent(QContextMenuEvent * event )
{
    event->accept();

    const QPoint globalPos = event->globalPos();
    const int index = actionIndexAt(m_toolBar, m_toolBar->mapFromGlobal(globalPos), m_toolBar->orientation());
    const ActionList actions = m_toolBar->actions();
    QAction *action = index != -1 ?actions.at(index) : 0;
    QVariant itemData;
    QMenu menu(0);

    // Insert before
    if (action && index != 0 && !action->isSeparator()) {
        QAction *newSeperatorAct = menu.addAction(tr("Insert Separator before '%1'").arg(action->objectName()));
        qVariantSetValue(itemData, action);
        newSeperatorAct->setData(itemData);
        connect(newSeperatorAct, SIGNAL(triggered()), this, SLOT(slotInsertSeparator()));
    }

    // Append separator
    if (actions.empty() || !actions.back()->isSeparator()) {
        QAction *newSeperatorAct = menu.addAction(tr("Append Separator"));
        qVariantSetValue(itemData, static_cast<QAction*>(0));
        newSeperatorAct->setData(itemData);
        connect(newSeperatorAct, SIGNAL(triggered()), this, SLOT(slotInsertSeparator()));
    }
    // Remove
    if (!menu.actions().empty())
        menu.addSeparator();

    // Remove
    if (action) {
        QAction *a = menu.addAction(tr("Remove action '%1'").arg(action->objectName()));
        qVariantSetValue(itemData, action);
        a->setData(itemData);
        connect(a, SIGNAL(triggered()), this, SLOT(slotRemoveSelectedAction()));
    }

    QAction *remove_toolbar = menu.addAction(tr("Remove Toolbar '%1'").arg(m_toolBar->objectName()));
    connect(remove_toolbar, SIGNAL(triggered()), this, SLOT(slotRemoveToolBar()));

    menu.exec(globalPos);
    return true;
}
Ejemplo n.º 2
0
ActionList ToolBarEventFilter::contextMenuActions(const QPoint &globalPos)
{
    ActionList rc;
    const int index = actionIndexAt(m_toolBar, m_toolBar->mapFromGlobal(globalPos), m_toolBar->orientation());
    const ActionList actions = m_toolBar->actions();
    QAction *action = index != -1 ?actions.at(index) : 0;
    QVariant itemData;

    // Insert before
    if (action && index != 0 && !action->isSeparator()) {
        QAction *newSeperatorAct = new QAction(tr("Insert Separator before '%1'").arg(action->objectName()), 0);
        itemData.setValue(action);
        newSeperatorAct->setData(itemData);
        connect(newSeperatorAct, SIGNAL(triggered()), this, SLOT(slotInsertSeparator()));
        rc.push_back(newSeperatorAct);
    }

    // Append separator
    if (actions.empty() || !actions.back()->isSeparator()) {
        QAction *newSeperatorAct = new QAction(tr("Append Separator"), 0);
        itemData.setValue(static_cast<QAction*>(0));
        newSeperatorAct->setData(itemData);
        connect(newSeperatorAct, SIGNAL(triggered()), this, SLOT(slotInsertSeparator()));
        rc.push_back(newSeperatorAct);
    }
    // Promotion
    if (!m_promotionTaskMenu)
        m_promotionTaskMenu = new PromotionTaskMenu(m_toolBar, PromotionTaskMenu::ModeSingleWidget, this);
    m_promotionTaskMenu->addActions(formWindow(), PromotionTaskMenu::LeadingSeparator|PromotionTaskMenu::TrailingSeparator, rc);
    // Remove
    if (action) {
        QAction *a = new QAction(tr("Remove action '%1'").arg(action->objectName()), 0);
        itemData.setValue(action);
        a->setData(itemData);
        connect(a, SIGNAL(triggered()), this, SLOT(slotRemoveSelectedAction()));
        rc.push_back(a);
    }

    QAction *remove_toolbar = new QAction(tr("Remove Toolbar '%1'").arg(m_toolBar->objectName()), 0);
    connect(remove_toolbar, SIGNAL(triggered()), this, SLOT(slotRemoveToolBar()));
    rc.push_back(remove_toolbar);
    return rc;
}
Ejemplo n.º 3
0
void Resource::readAction(Common::File *file, ActionList &list) {
	list.clear();

	while (file->readByte() == 1) {
		list.push_back(Action());
		Action &action = list.back();

		action._actionType = (ActionType)file->readSint16LE();
		action._param1 = file->readSint16LE();
		action._param2 = file->readSint16LE();
		action._param3 = file->readSint16LE();

		if (action._actionType == kActionShowMessages) {
			action._messages.reserve(action._param1);
			for (int i = 0; i < action._param1; i++)
				action._messages.push_back(readString(file));
		} else {
			action._messages.push_back(readString(file));
		}
	}
}
Ejemplo n.º 4
0
// Determine the free area behind the last action.
QRect ToolBarEventFilter::freeArea(const QToolBar *tb)
{
    QRect rc = QRect(QPoint(0, 0), tb->size());
    const ActionList actionList = tb->actions();
    QRect exclusionRectangle = actionList.empty() ? handleArea(tb) : tb->actionGeometry(actionList.back());
    switch (tb->orientation()) {
    case Qt::Horizontal:
        switch (tb->layoutDirection()) {
        case Qt::LayoutDirectionAuto: // Should never happen
        case Qt::LeftToRight:
            rc.setX(exclusionRectangle.right() + 1);
            break;
        case Qt::RightToLeft:
            rc.setRight(exclusionRectangle.x());
            break;
        }
        break;
    case Qt::Vertical:
        rc.setY(exclusionRectangle.bottom() + 1);
        break;
    }
    return rc;
}