1 | /* $Id: UIMachineWindow.h 86046 2020-09-07 15:27:58Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIMachineWindow class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2020 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 | /** Restores cached window geometry.
|
---|
90 | * @note Reimplemented in sub-classes. Base implementation does nothing. */
|
---|
91 | virtual void restoreCachedGeometry() {}
|
---|
92 |
|
---|
93 | /** Adjusts machine-window size to correspond current machine-view size.
|
---|
94 | * @param fAdjustPosition determines whether is it necessary to adjust position too.
|
---|
95 | * @param fResizeToGuestDisplay determines if is it necessary to resize the window to fit to guest display size.
|
---|
96 | * @note Reimplemented in sub-classes. Base implementation does nothing. */
|
---|
97 | virtual void normalizeGeometry(bool fAdjustPosition, bool fResizeToGuestDisplay) { Q_UNUSED(fAdjustPosition); Q_UNUSED(fResizeToGuestDisplay);}
|
---|
98 |
|
---|
99 | /** Adjusts machine-view size to correspond current machine-window size. */
|
---|
100 | virtual void adjustMachineViewSize();
|
---|
101 |
|
---|
102 | /** Sends machine-view size-hint to the guest. */
|
---|
103 | virtual void sendMachineViewSizeHint();
|
---|
104 |
|
---|
105 | /** Returns true if the machine window should resize to fit to the guest display. Relevant only in normal (windowed) case. */
|
---|
106 | bool shouldResizeToGuestDisplay() const;
|
---|
107 |
|
---|
108 | #ifdef VBOX_WITH_MASKED_SEAMLESS
|
---|
109 | /* Virtual caller for base class setMask: */
|
---|
110 | virtual void setMask(const QRegion ®ion);
|
---|
111 | #endif /* VBOX_WITH_MASKED_SEAMLESS */
|
---|
112 |
|
---|
113 | protected slots:
|
---|
114 |
|
---|
115 | #ifdef VBOX_WS_X11
|
---|
116 | /** X11: Performs machine-window geometry normalization. */
|
---|
117 | void sltNormalizeGeometry() { normalizeGeometry(true /* adjust position */, shouldResizeToGuestDisplay()); }
|
---|
118 | #endif /* VBOX_WS_X11 */
|
---|
119 |
|
---|
120 | /** Performs machine-window activation. */
|
---|
121 | void sltActivateWindow() { activateWindow(); }
|
---|
122 |
|
---|
123 | /* Session event-handlers: */
|
---|
124 | virtual void sltMachineStateChanged();
|
---|
125 |
|
---|
126 | protected:
|
---|
127 |
|
---|
128 | /* Constructor: */
|
---|
129 | UIMachineWindow(UIMachineLogic *pMachineLogic, ulong uScreenId);
|
---|
130 |
|
---|
131 | /* Show stuff: */
|
---|
132 | virtual void showInNecessaryMode() = 0;
|
---|
133 |
|
---|
134 | /* Translate stuff: */
|
---|
135 | void retranslateUi();
|
---|
136 |
|
---|
137 | /** Handles any Qt @a pEvent. */
|
---|
138 | virtual bool event(QEvent *pEvent) /* override */;
|
---|
139 |
|
---|
140 | /** Handles show @a pEvent. */
|
---|
141 | virtual void showEvent(QShowEvent *pEvent) /* override */;
|
---|
142 | /** Handles hide @a pEvent. */
|
---|
143 | virtual void hideEvent(QHideEvent *pEvent) /* override */;
|
---|
144 |
|
---|
145 | /** Close event handler. */
|
---|
146 | void closeEvent(QCloseEvent *pCloseEvent);
|
---|
147 |
|
---|
148 | #ifdef VBOX_WS_MAC
|
---|
149 | /** Mac OS X: Handles native notifications.
|
---|
150 | * @param strNativeNotificationName Native notification name. */
|
---|
151 | virtual void handleNativeNotification(const QString & /* strNativeNotificationName */) {}
|
---|
152 |
|
---|
153 | /** Mac OS X: Handles standard window button callbacks.
|
---|
154 | * @param enmButtonType Brings standard window button type.
|
---|
155 | * @param fWithOptionKey Brings whether the Option key was held. */
|
---|
156 | virtual void handleStandardWindowButtonCallback(StandardWindowButtonType enmButtonType, bool fWithOptionKey);
|
---|
157 | #endif /* VBOX_WS_MAC */
|
---|
158 |
|
---|
159 | /* Prepare helpers: */
|
---|
160 | virtual void prepareSessionConnections();
|
---|
161 | virtual void prepareMainLayout();
|
---|
162 | virtual void prepareMenu() {}
|
---|
163 | virtual void prepareStatusBar() {}
|
---|
164 | virtual void prepareMachineView();
|
---|
165 | virtual void prepareVisualState() {}
|
---|
166 | virtual void prepareHandlers();
|
---|
167 | virtual void loadSettings() {}
|
---|
168 |
|
---|
169 | /* Cleanup helpers: */
|
---|
170 | virtual void saveSettings() {}
|
---|
171 | virtual void cleanupHandlers();
|
---|
172 | virtual void cleanupVisualState() {}
|
---|
173 | virtual void cleanupMachineView();
|
---|
174 | virtual void cleanupStatusBar() {}
|
---|
175 | virtual void cleanupMenu() {}
|
---|
176 | virtual void cleanupMainLayout() {}
|
---|
177 | virtual void cleanupSessionConnections();
|
---|
178 |
|
---|
179 | /* Update stuff: */
|
---|
180 | virtual void updateAppearanceOf(int iElement);
|
---|
181 | #ifdef VBOX_WITH_DEBUGGER_GUI
|
---|
182 | void updateDbgWindows();
|
---|
183 | #endif /* VBOX_WITH_DEBUGGER_GUI */
|
---|
184 |
|
---|
185 | /* Helpers: */
|
---|
186 | const QString& defaultWindowTitle() const { return m_strWindowTitlePrefix; }
|
---|
187 | static Qt::Alignment viewAlignment(UIVisualStateType visualStateType);
|
---|
188 |
|
---|
189 | #ifdef VBOX_WS_MAC
|
---|
190 | /** Mac OS X: Handles native notifications.
|
---|
191 | * @param strNativeNotificationName Native notification name.
|
---|
192 | * @param pWidget Widget, notification related to. */
|
---|
193 | static void handleNativeNotification(const QString &strNativeNotificationName, QWidget *pWidget);
|
---|
194 |
|
---|
195 | /** Mac OS X: Handles standard window button callbacks.
|
---|
196 | * @param enmButtonType Brings standard window button type.
|
---|
197 | * @param fWithOptionKey Brings whether the Option key was held.
|
---|
198 | * @param pWidget Brings widget, callback related to. */
|
---|
199 | static void handleStandardWindowButtonCallback(StandardWindowButtonType enmButtonType, bool fWithOptionKey, QWidget *pWidget);
|
---|
200 | #endif /* VBOX_WS_MAC */
|
---|
201 |
|
---|
202 | /* Variables: */
|
---|
203 | UIMachineLogic *m_pMachineLogic;
|
---|
204 | UIMachineView *m_pMachineView;
|
---|
205 | QString m_strWindowTitlePrefix;
|
---|
206 | ulong m_uScreenId;
|
---|
207 | QGridLayout *m_pMainLayout;
|
---|
208 | QSpacerItem *m_pTopSpacer;
|
---|
209 | QSpacerItem *m_pBottomSpacer;
|
---|
210 | QSpacerItem *m_pLeftSpacer;
|
---|
211 | QSpacerItem *m_pRightSpacer;
|
---|
212 |
|
---|
213 | /* Friend classes: */
|
---|
214 | friend class UIMachineLogic;
|
---|
215 | friend class UIMachineLogicFullscreen;
|
---|
216 | friend class UIMachineLogicSeamless;
|
---|
217 | };
|
---|
218 |
|
---|
219 | #endif /* !FEQT_INCLUDED_SRC_runtime_UIMachineWindow_h */
|
---|
220 |
|
---|