VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMouseHandler.h@ 98503

Last change on this file since 98503 was 98503, checked in by vboxsync, 2 years ago

FE/Qt: bugref:10322: Runtime UI: Rework CMouse wrapper usage the way it's fully encapsulated inside UISession.

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

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