[55401] | 1 | /* $Id: UIMouseHandler.h 103988 2024-03-21 13:49:47Z vboxsync $ */
|
---|
[382] | 2 | /** @file
|
---|
[52727] | 3 | * VBox Qt GUI - UIMouseHandler class declaration.
|
---|
[382] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2010-2023 Oracle and/or its affiliates.
|
---|
[382] | 8 | *
|
---|
[96407] | 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
|
---|
[382] | 26 | */
|
---|
| 27 |
|
---|
[76581] | 28 | #ifndef FEQT_INCLUDED_SRC_runtime_UIMouseHandler_h
|
---|
| 29 | #define FEQT_INCLUDED_SRC_runtime_UIMouseHandler_h
|
---|
[76532] | 30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 31 | # pragma once
|
---|
| 32 | #endif
|
---|
[382] | 33 |
|
---|
[41587] | 34 | /* Qt includes: */
|
---|
[58943] | 35 | #include <QMap>
|
---|
[30408] | 36 | #include <QObject>
|
---|
| 37 | #include <QPoint>
|
---|
[58943] | 38 | #include <QPointer>
|
---|
[35906] | 39 | #include <QRect>
|
---|
[382] | 40 |
|
---|
[41587] | 41 | /* GUI includes: */
|
---|
[51187] | 42 | #include "UIExtraDataDefs.h"
|
---|
[6467] | 43 |
|
---|
[41587] | 44 | /* Forward declarations: */
|
---|
[58943] | 45 | class QTouchEvent;
|
---|
[30408] | 46 | class QWidget;
|
---|
[98378] | 47 | class UIMachine;
|
---|
[27021] | 48 | class UIMachineLogic;
|
---|
[98378] | 49 | class UIMachineView;
|
---|
[34471] | 50 | class UIMachineWindow;
|
---|
[26699] | 51 |
|
---|
[58943] | 52 |
|
---|
[30408] | 53 | /* Delegate to control VM mouse functionality: */
|
---|
| 54 | class UIMouseHandler : public QObject
|
---|
[382] | 55 | {
|
---|
[26637] | 56 | Q_OBJECT;
|
---|
[382] | 57 |
|
---|
[52014] | 58 | signals:
|
---|
| 59 |
|
---|
| 60 | /** Notifies listeners about state-change. */
|
---|
| 61 | void sigStateChange(int iState);
|
---|
| 62 |
|
---|
[382] | 63 | public:
|
---|
| 64 |
|
---|
[30408] | 65 | /* Factory functions to create/destroy mouse-handler: */
|
---|
| 66 | static UIMouseHandler* create(UIMachineLogic *pMachineLogic, UIVisualStateType visualStateType);
|
---|
| 67 | static void destroy(UIMouseHandler *pMouseHandler);
|
---|
[26889] | 68 |
|
---|
[34471] | 69 | /* Prepare/cleanup listener for particular machine-window: */
|
---|
| 70 | void prepareListener(ulong uIndex, UIMachineWindow *pMachineWindow);
|
---|
| 71 | void cleanupListener(ulong uIndex);
|
---|
[382] | 72 |
|
---|
[30408] | 73 | /* Commands to capture/release mouse: */
|
---|
| 74 | void captureMouse(ulong uScreenId);
|
---|
| 75 | void releaseMouse();
|
---|
[26773] | 76 |
|
---|
[30408] | 77 | /* Setter for mouse-integration feature: */
|
---|
| 78 | void setMouseIntegrationEnabled(bool fEnabled);
|
---|
[382] | 79 |
|
---|
[30408] | 80 | /* Current mouse state: */
|
---|
[52014] | 81 | int state() const;
|
---|
[26815] | 82 |
|
---|
[63579] | 83 | /** Qt5: Performs pre-processing of all the native events. */
|
---|
| 84 | bool nativeEventFilter(void *pMessage, ulong uScreenId);
|
---|
[30637] | 85 |
|
---|
[26773] | 86 | protected slots:
|
---|
| 87 |
|
---|
[30408] | 88 | /* Machine state-change handler: */
|
---|
[26815] | 89 | virtual void sltMachineStateChanged();
|
---|
[30408] | 90 |
|
---|
| 91 | /* Mouse capability-change handler: */
|
---|
[26815] | 92 | virtual void sltMouseCapabilityChanged();
|
---|
[26773] | 93 |
|
---|
[30408] | 94 | /* Mouse pointer-shape-change handler: */
|
---|
| 95 | virtual void sltMousePointerShapeChanged();
|
---|
[26967] | 96 |
|
---|
[50824] | 97 | /** Activate hovered window if any. */
|
---|
| 98 | void sltMaybeActivateHoveredWindow();
|
---|
| 99 |
|
---|
[30408] | 100 | protected:
|
---|
[28239] | 101 |
|
---|
[30408] | 102 | /* Mouse-handler constructor/destructor: */
|
---|
| 103 | UIMouseHandler(UIMachineLogic *pMachineLogic);
|
---|
| 104 | virtual ~UIMouseHandler();
|
---|
[26637] | 105 |
|
---|
[30408] | 106 | /* Getters: */
|
---|
[98378] | 107 | UIMachineLogic *machineLogic() const { return m_pMachineLogic; }
|
---|
| 108 | UIMachine *uimachine() const;
|
---|
[26754] | 109 |
|
---|
[30408] | 110 | /* Event handler for registered machine-view(s): */
|
---|
[103988] | 111 | bool eventFilter(QObject *pWatched, QEvent *pEvent) RT_OVERRIDE RT_FINAL;
|
---|
[382] | 112 |
|
---|
[30408] | 113 | /* Separate function to handle most of existing mouse-events: */
|
---|
| 114 | bool mouseEvent(int iEventType, ulong uScreenId,
|
---|
| 115 | const QPoint &relativePos, const QPoint &globalPos,
|
---|
| 116 | Qt::MouseButtons mouseButtons,
|
---|
| 117 | int wheelDelta, Qt::Orientation wheelDirection);
|
---|
[382] | 118 |
|
---|
[47396] | 119 | /* Separate function to handle incoming multi-touch events: */
|
---|
| 120 | bool multiTouchEvent(QTouchEvent *pTouchEvent, ulong uScreenId);
|
---|
| 121 |
|
---|
[60362] | 122 | #ifdef VBOX_WS_WIN
|
---|
[30408] | 123 | /* This method is actually required only because under win-host
|
---|
| 124 | * we do not really grab the mouse in case of capturing it: */
|
---|
| 125 | void updateMouseCursorClipping();
|
---|
[35906] | 126 | QRect m_mouseCursorClippingRect;
|
---|
[60362] | 127 | #endif /* VBOX_WS_WIN */
|
---|
[382] | 128 |
|
---|
[30408] | 129 | /* Machine logic parent: */
|
---|
| 130 | UIMachineLogic *m_pMachineLogic;
|
---|
[382] | 131 |
|
---|
[34471] | 132 | /* Registered machine-windows(s): */
|
---|
| 133 | QMap<ulong, QWidget*> m_windows;
|
---|
[30408] | 134 | /* Registered machine-view(s): */
|
---|
| 135 | QMap<ulong, UIMachineView*> m_views;
|
---|
| 136 | /* Registered machine-view-viewport(s): */
|
---|
| 137 | QMap<ulong, QWidget*> m_viewports;
|
---|
[27012] | 138 |
|
---|
[50824] | 139 | /** Hovered window to be activated. */
|
---|
| 140 | QPointer<QWidget> m_pHoveredWindow;
|
---|
| 141 |
|
---|
[30408] | 142 | /* Other mouse variables: */
|
---|
[26754] | 143 | QPoint m_lastMousePos;
|
---|
| 144 | QPoint m_capturedMousePos;
|
---|
[97771] | 145 | QRect m_capturedScreenGeo;
|
---|
[25304] | 146 | int m_iLastMouseWheelDelta;
|
---|
[30408] | 147 | int m_iMouseCaptureViewIndex;
|
---|
[75938] | 148 |
|
---|
| 149 | #ifdef VBOX_WS_WIN
|
---|
| 150 | /** Holds whether cursor position was just
|
---|
| 151 | * reseted to simulate infinite mouse moving. */
|
---|
| 152 | bool m_fCursorPositionReseted;
|
---|
| 153 | #endif
|
---|
[382] | 154 | };
|
---|
| 155 |
|
---|
[76581] | 156 | #endif /* !FEQT_INCLUDED_SRC_runtime_UIMouseHandler_h */
|
---|