1 | /* $Id: UIMachineWindow.h 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIMachineWindow class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef FEQT_INCLUDED_SRC_runtime_UIMachineWindow_h
|
---|
19 | #define FEQT_INCLUDED_SRC_runtime_UIMachineWindow_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* Qt includes: */
|
---|
25 | #include <QMainWindow>
|
---|
26 |
|
---|
27 | /* GUI includes: */
|
---|
28 | #include "QIWithRetranslateUI.h"
|
---|
29 | #include "UIExtraDataDefs.h"
|
---|
30 | #ifdef VBOX_WS_MAC
|
---|
31 | # include "VBoxUtils-darwin.h"
|
---|
32 | #endif /* VBOX_WS_MAC */
|
---|
33 |
|
---|
34 | /* COM includes: */
|
---|
35 | #include "COMEnums.h"
|
---|
36 | #include "CMachine.h"
|
---|
37 |
|
---|
38 | /* Forward declarations: */
|
---|
39 | class QCloseEvent;
|
---|
40 | class QEvent;
|
---|
41 | class QHideEvent;
|
---|
42 | class QGridLayout;
|
---|
43 | class QShowEvent;
|
---|
44 | class QSpacerItem;
|
---|
45 | class UIActionPool;
|
---|
46 | class UISession;
|
---|
47 | class UIMachineLogic;
|
---|
48 | class UIMachineView;
|
---|
49 | class CSession;
|
---|
50 |
|
---|
51 |
|
---|
52 | /* Machine-window interface: */
|
---|
53 | class UIMachineWindow : public QIWithRetranslateUI2<QMainWindow>
|
---|
54 | {
|
---|
55 | Q_OBJECT;
|
---|
56 |
|
---|
57 | signals:
|
---|
58 |
|
---|
59 | /** Notifies about frame-buffer resize. */
|
---|
60 | void sigFrameBufferResize();
|
---|
61 |
|
---|
62 | public:
|
---|
63 |
|
---|
64 | /* Factory functions to create/destroy machine-window: */
|
---|
65 | static UIMachineWindow* create(UIMachineLogic *pMachineLogic, ulong uScreenId = 0);
|
---|
66 | static void destroy(UIMachineWindow *pWhichWindow);
|
---|
67 |
|
---|
68 | /* Prepare/cleanup machine-window: */
|
---|
69 | void prepare();
|
---|
70 | void cleanup();
|
---|
71 |
|
---|
72 | /* Public getters: */
|
---|
73 | ulong screenId() const { return m_uScreenId; }
|
---|
74 | UIMachineView* machineView() const { return m_pMachineView; }
|
---|
75 | UIMachineLogic* machineLogic() const { return m_pMachineLogic; }
|
---|
76 | UIActionPool* actionPool() const;
|
---|
77 | UISession* uisession() const;
|
---|
78 |
|
---|
79 | /** Returns the session reference. */
|
---|
80 | CSession& session() const;
|
---|
81 | /** Returns the session's machine reference. */
|
---|
82 | CMachine& machine() const;
|
---|
83 | /** Returns the session's console reference. */
|
---|
84 | CConsole& console() const;
|
---|
85 |
|
---|
86 | /** Returns the machine name. */
|
---|
87 | const QString& machineName() const;
|
---|
88 |
|
---|
89 | /** Returns whether the machine-window should resize to fit to the guest display.
|
---|
90 | * @note Relevant only to normal (windowed) case. */
|
---|
91 | bool shouldResizeToGuestDisplay() const;
|
---|
92 |
|
---|
93 | /** Restores cached window geometry.
|
---|
94 | * @note Reimplemented in sub-classes. Base implementation does nothing. */
|
---|
95 | virtual void restoreCachedGeometry() {}
|
---|
96 |
|
---|
97 | /** Adjusts machine-window size to correspond current machine-view size.
|
---|
98 | * @param fAdjustPosition determines whether is it necessary to adjust position too.
|
---|
99 | * @param fResizeToGuestDisplay determines if is it necessary to resize the window to fit to guest display size.
|
---|
100 | * @note Reimplemented in sub-classes. Base implementation does nothing. */
|
---|
101 | virtual void normalizeGeometry(bool fAdjustPosition, bool fResizeToGuestDisplay) { Q_UNUSED(fAdjustPosition); Q_UNUSED(fResizeToGuestDisplay); }
|
---|
102 |
|
---|
103 | /** Adjusts machine-view size to correspond current machine-window size. */
|
---|
104 | virtual void adjustMachineViewSize();
|
---|
105 |
|
---|
106 | /** Sends machine-view size-hint to the guest. */
|
---|
107 | virtual void sendMachineViewSizeHint();
|
---|
108 |
|
---|
109 | #ifdef VBOX_WITH_MASKED_SEAMLESS
|
---|
110 | /* Virtual caller for base class setMask: */
|
---|
111 | virtual void setMask(const QRegion ®ion);
|
---|
112 | #endif /* VBOX_WITH_MASKED_SEAMLESS */
|
---|
113 |
|
---|
114 | protected slots:
|
---|
115 |
|
---|
116 | #ifdef VBOX_WS_X11
|
---|
117 | /** X11: Performs machine-window geometry normalization. */
|
---|
118 | void sltNormalizeGeometry() { normalizeGeometry(true /* adjust position */, shouldResizeToGuestDisplay()); }
|
---|
119 | #endif /* VBOX_WS_X11 */
|
---|
120 |
|
---|
121 | /** Performs machine-window activation. */
|
---|
122 | void sltActivateWindow() { activateWindow(); }
|
---|
123 |
|
---|
124 | /* Session event-handlers: */
|
---|
125 | virtual void sltMachineStateChanged();
|
---|
126 |
|
---|
127 | protected:
|
---|
128 |
|
---|
129 | /* Constructor: */
|
---|
130 | UIMachineWindow(UIMachineLogic *pMachineLogic, ulong uScreenId);
|
---|
131 |
|
---|
132 | /* Show stuff: */
|
---|
133 | virtual void showInNecessaryMode() = 0;
|
---|
134 |
|
---|
135 | /* Translate stuff: */
|
---|
136 | void retranslateUi();
|
---|
137 |
|
---|
138 | /** Handles any Qt @a pEvent. */
|
---|
139 | virtual bool event(QEvent *pEvent) /* override */;
|
---|
140 |
|
---|
141 | /** Handles show @a pEvent. */
|
---|
142 | virtual void showEvent(QShowEvent *pEvent) /* override */;
|
---|
143 | /** Handles hide @a pEvent. */
|
---|
144 | virtual void hideEvent(QHideEvent *pEvent) /* override */;
|
---|
145 |
|
---|
146 | /** Close event handler. */
|
---|
147 | void closeEvent(QCloseEvent *pCloseEvent);
|
---|
148 |
|
---|
149 | #ifdef VBOX_WS_MAC
|
---|
150 | /** Mac OS X: Handles native notifications.
|
---|
151 | * @param strNativeNotificationName Native notification name. */
|
---|
152 | virtual void handleNativeNotification(const QString & /* strNativeNotificationName */) {}
|
---|
153 |
|
---|
154 | /** Mac OS X: Handles standard window button callbacks.
|
---|
155 | * @param enmButtonType Brings standard window button type.
|
---|
156 | * @param fWithOptionKey Brings whether the Option key was held. */
|
---|
157 | virtual void handleStandardWindowButtonCallback(StandardWindowButtonType enmButtonType, bool fWithOptionKey);
|
---|
158 | #endif /* VBOX_WS_MAC */
|
---|
159 |
|
---|
160 | /* Prepare helpers: */
|
---|
161 | virtual void prepareSessionConnections();
|
---|
162 | virtual void prepareMainLayout();
|
---|
163 | virtual void prepareMenu() {}
|
---|
164 | virtual void prepareStatusBar() {}
|
---|
165 | virtual void prepareMachineView();
|
---|
166 | virtual void prepareNotificationCenter();
|
---|
167 | virtual void prepareVisualState() {}
|
---|
168 | virtual void prepareHandlers();
|
---|
169 | virtual void loadSettings() {}
|
---|
170 |
|
---|
171 | /* Cleanup helpers: */
|
---|
172 | virtual void saveSettings() {}
|
---|
173 | virtual void cleanupHandlers();
|
---|
174 | virtual void cleanupVisualState() {}
|
---|
175 | virtual void cleanupNotificationCenter();
|
---|
176 | virtual void cleanupMachineView();
|
---|
177 | virtual void cleanupStatusBar() {}
|
---|
178 | virtual void cleanupMenu() {}
|
---|
179 | virtual void cleanupMainLayout() {}
|
---|
180 | virtual void cleanupSessionConnections();
|
---|
181 |
|
---|
182 | /* Update stuff: */
|
---|
183 | virtual void updateAppearanceOf(int iElement);
|
---|
184 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
185 | void updateDbgWindows();
|
---|
186 | #endif /* VBOX_WITH_DEBUGGER_GUI */
|
---|
187 |
|
---|
188 | /* Helpers: */
|
---|
189 | const QString& defaultWindowTitle() const { return m_strWindowTitlePrefix; }
|
---|
190 | static Qt::Alignment viewAlignment(UIVisualStateType visualStateType);
|
---|
191 |
|
---|
192 | #ifdef VBOX_WS_MAC
|
---|
193 | /** Mac OS X: Handles native notifications.
|
---|
194 | * @param strNativeNotificationName Native notification name.
|
---|
195 | * @param pWidget Widget, notification related to. */
|
---|
196 | static void handleNativeNotification(const QString &strNativeNotificationName, QWidget *pWidget);
|
---|
197 |
|
---|
198 | /** Mac OS X: Handles standard window button callbacks.
|
---|
199 | * @param enmButtonType Brings standard window button type.
|
---|
200 | * @param fWithOptionKey Brings whether the Option key was held.
|
---|
201 | * @param pWidget Brings widget, callback related to. */
|
---|
202 | static void handleStandardWindowButtonCallback(StandardWindowButtonType enmButtonType, bool fWithOptionKey, QWidget *pWidget);
|
---|
203 | #endif /* VBOX_WS_MAC */
|
---|
204 |
|
---|
205 | /* Variables: */
|
---|
206 | UIMachineLogic *m_pMachineLogic;
|
---|
207 | UIMachineView *m_pMachineView;
|
---|
208 | QString m_strWindowTitlePrefix;
|
---|
209 | ulong m_uScreenId;
|
---|
210 | QGridLayout *m_pMainLayout;
|
---|
211 | QSpacerItem *m_pTopSpacer;
|
---|
212 | QSpacerItem *m_pBottomSpacer;
|
---|
213 | QSpacerItem *m_pLeftSpacer;
|
---|
214 | QSpacerItem *m_pRightSpacer;
|
---|
215 |
|
---|
216 | /* Friend classes: */
|
---|
217 | friend class UIMachineLogic;
|
---|
218 | friend class UIMachineLogicFullscreen;
|
---|
219 | friend class UIMachineLogicSeamless;
|
---|
220 | };
|
---|
221 |
|
---|
222 | #endif /* !FEQT_INCLUDED_SRC_runtime_UIMachineWindow_h */
|
---|
223 |
|
---|