bool UIActionPool::processHotKey(const QKeySequence &key) { /* Get the list of keys: */ QList<int> keys = m_pool.keys(); /* Iterate through the whole list of keys: */ for (int i = 0; i < keys.size(); ++i) { /* Get current action: */ UIAction *pAction = m_pool[keys[i]]; /* Skip menus/separators: */ if (pAction->type() == UIActionType_Menu) continue; /* Get the hot key of the current action: */ QString strHotKey = VBoxGlobal::extractKeyFromActionText(pAction->text()); if (pAction->isEnabled() && pAction->isVisible() && !strHotKey.isEmpty()) { if (key.matches(QKeySequence(strHotKey)) == QKeySequence::ExactMatch) { /* We asynchronously post a special event instead of calling * pAction->trigger() directly, to let key presses and * releases be processed correctly by Qt first. * Note: we assume that nobody will delete the menu item * corresponding to the key sequence, so that the pointer to * menu data posted along with the event will remain valid in * the event handler, at least until the main window is closed. */ QApplication::postEvent(this, new ActivateActionEvent(pAction)); return true; } } } return false; }
void UIMachineWindowNormal::sltHandleIndicatorContextMenuRequest(IndicatorType enmIndicatorType, const QPoint &indicatorPosition) { /* Determine action depending on indicator-type: */ UIAction *pAction = 0; switch (enmIndicatorType) { case IndicatorType_HardDisks: pAction = actionPool()->action(UIActionIndexRT_M_Devices_M_HardDrives); break; case IndicatorType_OpticalDisks: pAction = actionPool()->action(UIActionIndexRT_M_Devices_M_OpticalDevices); break; case IndicatorType_FloppyDisks: pAction = actionPool()->action(UIActionIndexRT_M_Devices_M_FloppyDevices); break; case IndicatorType_Audio: pAction = actionPool()->action(UIActionIndexRT_M_Devices_M_Audio); break; case IndicatorType_Network: pAction = actionPool()->action(UIActionIndexRT_M_Devices_M_Network); break; case IndicatorType_USB: pAction = actionPool()->action(UIActionIndexRT_M_Devices_M_USBDevices); break; case IndicatorType_SharedFolders: pAction = actionPool()->action(UIActionIndexRT_M_Devices_M_SharedFolders); break; case IndicatorType_Display: pAction = actionPool()->action(UIActionIndexRT_M_ViewPopup); break; case IndicatorType_Recording: pAction = actionPool()->action(UIActionIndexRT_M_View_M_Recording); break; case IndicatorType_Mouse: pAction = actionPool()->action(UIActionIndexRT_M_Input_M_Mouse); break; case IndicatorType_Keyboard: pAction = actionPool()->action(UIActionIndexRT_M_Input_M_Keyboard); break; default: break; } /* Raise action's context-menu: */ if (pAction && pAction->isEnabled()) pAction->menu()->exec(m_pIndicatorsPool->mapIndicatorPositionToGlobal(enmIndicatorType, indicatorPosition)); }