Exemplo n.º 1
0
void Menu::mouseReleaseEvent(QMouseEvent* e)
{
    QAction* qact = actionAt(e->pos());
    Action* act = qobject_cast<Action*> (qact);

    if (qact && qact->menu()) {
        Menu* m = qobject_cast<Menu*> (qact->menu());
        if (!m) {
            QMenu::mouseReleaseEvent(e);
            return;
        }

        if (e->button() == Qt::MiddleButton || (e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier)) {
            closeAllMenus();
            emit menuMiddleClicked(m);
        }
    }

    if (!act) {
        QMenu::mouseReleaseEvent(e);
        return;
    }

    if (e->button() == Qt::LeftButton && e->modifiers() == Qt::NoModifier) {
        closeAllMenus();
        act->trigger();
        e->accept();
    }
    else if (e->button() == Qt::MiddleButton || (e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier)) {
        closeAllMenus();
        act->triggerMiddleClick();
        e->accept();
    }
}
Exemplo n.º 2
0
void Menu::keyPressEvent(QKeyEvent* e)
{
    if (e->key() != Qt::Key_Enter && e->key() != Qt::Key_Return) {
        QMenu::keyPressEvent(e);
        return;
    }

    QAction* qact = activeAction();
    Action* act = qobject_cast<Action*> (qact);

    if (!act) {
        QMenu::keyPressEvent(e);
        return;
    }

    if (e->modifiers() == Qt::NoModifier) {
        closeAllMenus();
        act->trigger();
        e->accept();
    }
    else if (e->modifiers() == Qt::ControlModifier) {
        closeAllMenus();
        act->emitCtrlTriggered();
        e->accept();
    }
    else if (e->modifiers() == Qt::ShiftModifier) {
        closeAllMenus();
        act->emitShiftTriggered();
        e->accept();
    }
}
Exemplo n.º 3
0
void MenuBar::onMouseDown(APoint m_pos, MouseButton b, bool direct)
{
	if(direct)
	{
		closeAllMenus();
	}
	else if(pointInside(m_pos))
	{
		for(auto mb : menuButtons)
			if(mb->pointInside(m_pos))
				return;
		
		//If not over any of the buttons, close menus
		closeAllMenus();
	}
}
Exemplo n.º 4
0
void Menu::mouseReleaseEvent(QMouseEvent* e)
{
    QAction* qact = activeAction();
    Action* act = qobject_cast<Action*> (qact);

    if (qact && qact->menu()) {
        Menu* m = qobject_cast<Menu*> (qact->menu());
        if (!m) {
            QMenu::mouseReleaseEvent(e);
            return;
        }

        if (e->button() == Qt::MiddleButton || (e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier)) {
            closeAllMenus();
            emit menuMiddleClicked(m);
        }
    }

    if (!act) {
        QMenu::mouseReleaseEvent(e);
        return;
    }

    if ((e->button() == Qt::LeftButton || e->button() == Qt::RightButton) && e->modifiers() == Qt::NoModifier) {
        closeAllMenus();
        act->trigger();
        e->accept();
    }
    else if (e->button() == Qt::MiddleButton || (e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier)) {
        if ((e->button() == Qt::MiddleButton && m_closeOnMiddleClick) || e->button() != Qt::MiddleButton) {
            closeAllMenus();
        }
        act->emitCtrlTriggered();
        e->accept();
    }
    else if (e->button() == Qt::LeftButton && e->modifiers() == Qt::ShiftModifier) {
        closeAllMenus();
        act->emitShiftTriggered();
        e->accept();
    }
}
Exemplo n.º 5
0
 void MenuEscape::handleInput(int in) {
     const int maxUiSelection = 3;
     
     move(selection + 2, 0);
     clrtoeol();
     
     if(in == KEY_ESCAPE){
         closeThisMenu();
     } else if(in == Key::interact || in == '\n'){
         switch (selection) {
             case 0:
                 closeThisMenu();
                 break;
                 
             case 1:
                 openMenu(new MenuControls());
                 break;
                 
             case 2:
                 openMenu(new MenuSettings());
                 break;
                 
             case 3:
                 if(Settings::autoSave && menuTime > Settings::autoSaveDelay){
                     closeAllMenus();
                 } else {
                     openMenu(new MenuYesNo("Do you want to save '" + menuGame->currentWorld->name + "' ?", menuGame->saveAnswer, true));
                 }
                 break;
                 
             default:
                 break;
         }
     }else if(in == Key::uiUp){
         selection--;
         if (selection < 0) {
             selection = maxUiSelection;
         }
         
     }else if(in == Key::uiDown){
         selection++;
         if (selection > maxUiSelection) {
             selection = 0;
         }
     }
     
 }
Exemplo n.º 6
0
void MenuBar::onLostFocus()
{
	closeAllMenus();
}