1 | /* $Id: UIKeyboardHandlerNormal.cpp 30675 2010-07-06 14:57:01Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * UIKeyboardHandlerNormal class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2010 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | /* Global includes */
|
---|
21 | #include <QMainWindow>
|
---|
22 | #include <QMenuBar>
|
---|
23 | #include <QKeyEvent>
|
---|
24 |
|
---|
25 | /* Local includes */
|
---|
26 | #include "UIKeyboardHandlerNormal.h"
|
---|
27 | #include "UIMachineWindow.h"
|
---|
28 |
|
---|
29 | /* Fullscreen keyboard-handler constructor: */
|
---|
30 | UIKeyboardHandlerNormal::UIKeyboardHandlerNormal(UIMachineLogic* pMachineLogic)
|
---|
31 | : UIKeyboardHandler(pMachineLogic)
|
---|
32 | {
|
---|
33 | }
|
---|
34 |
|
---|
35 | /* Fullscreen keyboard-handler destructor: */
|
---|
36 | UIKeyboardHandlerNormal::~UIKeyboardHandlerNormal()
|
---|
37 | {
|
---|
38 | }
|
---|
39 |
|
---|
40 | /* Event handler for prepared listener(s): */
|
---|
41 | bool UIKeyboardHandlerNormal::eventFilter(QObject *pWatchedObject, QEvent *pEvent)
|
---|
42 | {
|
---|
43 | /* Check if pWatchedObject object is view: */
|
---|
44 | if (UIMachineView *pWatchedView = isItListenedView(pWatchedObject))
|
---|
45 | {
|
---|
46 | /* Get corresponding screen index: */
|
---|
47 | ulong uScreenId = m_views.key(pWatchedView);
|
---|
48 | NOREF(uScreenId);
|
---|
49 | /* Handle view events: */
|
---|
50 | switch (pEvent->type())
|
---|
51 | {
|
---|
52 | #ifndef Q_WS_MAC
|
---|
53 | /* We don't want this on the Mac, cause there the menu-bar isn't within the
|
---|
54 | * window and popping up a menu there looks really ugly. */
|
---|
55 | case QEvent::KeyPress:
|
---|
56 | {
|
---|
57 | /* Get key-event: */
|
---|
58 | QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(pEvent);
|
---|
59 | /* Process Host+Home as menu-bar activator: */
|
---|
60 | if (isHostKeyPressed() && pKeyEvent->key() == Qt::Key_Home)
|
---|
61 | {
|
---|
62 | /* Trying to get menu-bar: */
|
---|
63 | QMenuBar *pMenuBar = qobject_cast<QMainWindow*>(m_windows[uScreenId]->machineWindow())->menuBar();
|
---|
64 | /* If menu-bar is present and have actions: */
|
---|
65 | if (pMenuBar && !pMenuBar->actions().isEmpty())
|
---|
66 | {
|
---|
67 | /* If 'active' action is NOT chosen: */
|
---|
68 | if (!pMenuBar->activeAction())
|
---|
69 | /* Set first menu-bar action as 'active': */
|
---|
70 | pMenuBar->setActiveAction(pMenuBar->actions()[0]);
|
---|
71 | /* If 'active' action is chosen: */
|
---|
72 | if (pMenuBar->activeAction())
|
---|
73 | {
|
---|
74 | /* Activate 'active' menu-bar action: */
|
---|
75 | pMenuBar->activeAction()->activate(QAction::Trigger);
|
---|
76 | #ifdef Q_WS_WIN
|
---|
77 | /* Windows host needs separate 'focus set'
|
---|
78 | * to let menubar operate while popped up: */
|
---|
79 | pMenuBar->setFocus();
|
---|
80 | #endif /* Q_WS_WIN */
|
---|
81 | /* Filter-out this event: */
|
---|
82 | return true;
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|
86 | break;
|
---|
87 | }
|
---|
88 | #endif /* !Q_WS_MAC */
|
---|
89 | default:
|
---|
90 | break;
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | /* Else just propagate to base-class: */
|
---|
95 | return UIKeyboardHandler::eventFilter(pWatchedObject, pEvent);
|
---|
96 | }
|
---|
97 |
|
---|