VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIKeyboardHandlerNormal.cpp

Last change on this file was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/* $Id: UIKeyboardHandlerNormal.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIKeyboardHandlerNormal class implementation.
4 */
5
6/*
7 * Copyright (C) 2010-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#ifndef VBOX_WS_MAC
30# include <QMainWindow>
31# include <QMenuBar>
32# include <QKeyEvent>
33# include <QTimer>
34#endif /* !VBOX_WS_MAC */
35
36/* GUI includes: */
37#include "UIKeyboardHandlerNormal.h"
38#ifndef VBOX_WS_MAC
39# include "UIMachineLogic.h"
40# include "UIMachineWindow.h"
41# include "UIShortcutPool.h"
42#endif /* !VBOX_WS_MAC */
43
44
45/* Namespaces: */
46#ifndef VBOX_WS_MAC
47using namespace UIExtraDataDefs;
48#endif /* !VBOX_WS_MAC */
49
50UIKeyboardHandlerNormal::UIKeyboardHandlerNormal(UIMachineLogic* pMachineLogic)
51 : UIKeyboardHandler(pMachineLogic)
52{
53}
54
55UIKeyboardHandlerNormal::~UIKeyboardHandlerNormal()
56{
57}
58
59#ifndef VBOX_WS_MAC
60bool UIKeyboardHandlerNormal::eventFilter(QObject *pWatchedObject, QEvent *pEvent)
61{
62 /* Check if pWatchedObject object is view: */
63 if (UIMachineView *pWatchedView = isItListenedView(pWatchedObject))
64 {
65 /* Get corresponding screen index: */
66 ulong uScreenId = m_views.key(pWatchedView);
67 NOREF(uScreenId);
68 /* Handle view events: */
69 switch (pEvent->type())
70 {
71 /* We don't want this on the Mac, cause there the menu-bar isn't within the
72 * window and popping up a menu there looks really ugly. */
73 case QEvent::KeyPress:
74 {
75 /* Get key-event: */
76 QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(pEvent);
77 /* Process Host+Home as menu-bar activator: */
78 if ( isHostKeyPressed()
79 && gShortcutPool->shortcut(GUI_Input_MachineShortcuts, QString("PopupMenu")).sequences().contains(QKeySequence(pKeyEvent->key())))
80 {
81 /* Trying to get menu-bar: */
82 QMenuBar *pMenuBar = qobject_cast<QMainWindow*>(m_windows[uScreenId])->menuBar();
83 /* If menu-bar is present and have actions: */
84 if (pMenuBar && !pMenuBar->actions().isEmpty())
85 {
86 /* Is menu-bar visible? */
87 if (pMenuBar->isVisible())
88 {
89 /* If 'active' action is NOT chosen: */
90 if (!pMenuBar->activeAction())
91 /* Set first menu-bar action as 'active': */
92 pMenuBar->setActiveAction(pMenuBar->actions()[0]);
93 /* If 'active' action is chosen: */
94 if (pMenuBar->activeAction())
95 {
96 /* Activate 'active' menu-bar action: */
97 pMenuBar->activeAction()->activate(QAction::Trigger);
98#ifdef VBOX_WS_WIN
99 /* Windows host needs separate 'focus set'
100 * to let menubar operate while popped up: */
101 pMenuBar->setFocus();
102#endif /* VBOX_WS_WIN */
103 }
104 }
105 else
106 {
107 /* Post request to show popup-menu: */
108 QTimer::singleShot(0, m_pMachineLogic, SLOT(sltInvokePopupMenu()));
109 }
110 /* Filter-out this event: */
111 return true;
112 }
113 }
114 break;
115 }
116 default:
117 break;
118 }
119 }
120
121 /* Else just propagate to base-class: */
122 return UIKeyboardHandler::eventFilter(pWatchedObject, pEvent);
123}
124#endif /* !VBOX_WS_MAC */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette