1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * UIMachineView class declaration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2010 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef ___UIMachineView_h___
|
---|
20 | #define ___UIMachineView_h___
|
---|
21 |
|
---|
22 | /* Global includes */
|
---|
23 | #include <QAbstractScrollArea>
|
---|
24 | #include <QEventLoop>
|
---|
25 |
|
---|
26 | /* Local includes */
|
---|
27 | #include "COMDefs.h"
|
---|
28 | #include "UIMachineDefs.h"
|
---|
29 |
|
---|
30 | #ifdef Q_WS_MAC
|
---|
31 | # include <CoreFoundation/CFBase.h>
|
---|
32 | #endif /* Q_WS_MAC */
|
---|
33 |
|
---|
34 | /* Local forwards */
|
---|
35 | class UISession;
|
---|
36 | class UIMachineLogic;
|
---|
37 | class UIMachineWindow;
|
---|
38 | class UIFrameBuffer;
|
---|
39 |
|
---|
40 | class UIMachineView : public QAbstractScrollArea
|
---|
41 | {
|
---|
42 | Q_OBJECT;
|
---|
43 |
|
---|
44 | public:
|
---|
45 |
|
---|
46 | /* Desktop geometry types: */
|
---|
47 | enum DesktopGeo { DesktopGeo_Invalid = 0, DesktopGeo_Fixed, DesktopGeo_Automatic, DesktopGeo_Any };
|
---|
48 |
|
---|
49 | /* Factory function to create machine-view: */
|
---|
50 | static UIMachineView* create( UIMachineWindow *pMachineWindow
|
---|
51 | , ulong uScreenId
|
---|
52 | , UIVisualStateType visualStateType
|
---|
53 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
54 | , bool bAccelerate2DVideo
|
---|
55 | #endif /* VBOX_WITH_VIDEOHWACCEL */
|
---|
56 | );
|
---|
57 | /* Factory function to destroy required machine-view: */
|
---|
58 | static void destroy(UIMachineView *pMachineView);
|
---|
59 |
|
---|
60 | /* Public setters: */
|
---|
61 | virtual void setGuestAutoresizeEnabled(bool /* fEnabled */) {}
|
---|
62 |
|
---|
63 | /* Public members: */
|
---|
64 | virtual void normalizeGeometry(bool /* bAdjustPosition = false */) = 0;
|
---|
65 |
|
---|
66 | /* Framebuffer aspect ratio: */
|
---|
67 | double aspectRatio() const;
|
---|
68 |
|
---|
69 | signals:
|
---|
70 |
|
---|
71 | /* Utility signals: */
|
---|
72 | void resizeHintDone();
|
---|
73 |
|
---|
74 | protected slots:
|
---|
75 |
|
---|
76 | /* Console callback handlers: */
|
---|
77 | virtual void sltMachineStateChanged();
|
---|
78 |
|
---|
79 | protected:
|
---|
80 |
|
---|
81 | /* Machine-view constructor: */
|
---|
82 | UIMachineView( UIMachineWindow *pMachineWindow
|
---|
83 | , ulong uScreenId
|
---|
84 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
85 | , bool bAccelerate2DVideo
|
---|
86 | #endif /* VBOX_WITH_VIDEOHWACCEL */
|
---|
87 | );
|
---|
88 | /* Machine-view destructor: */
|
---|
89 | virtual ~UIMachineView();
|
---|
90 |
|
---|
91 | /* Prepare routines: */
|
---|
92 | virtual void prepareViewport();
|
---|
93 | virtual void prepareFrameBuffer();
|
---|
94 | virtual void prepareCommon();
|
---|
95 | virtual void prepareFilters();
|
---|
96 | virtual void prepareConsoleConnections();
|
---|
97 | virtual void loadMachineViewSettings();
|
---|
98 |
|
---|
99 | /* Cleanup routines: */
|
---|
100 | //virtual void saveMachineViewSettings() {}
|
---|
101 | //virtual void cleanupConsoleConnections() {}
|
---|
102 | //virtual void cleanupFilters() {}
|
---|
103 | //virtual void cleanupCommon() {}
|
---|
104 | virtual void cleanupFrameBuffer();
|
---|
105 | //virtual void cleanupViewport();
|
---|
106 |
|
---|
107 | /* Protected getters: */
|
---|
108 | UIMachineWindow* machineWindowWrapper() const { return m_pMachineWindow; }
|
---|
109 | UIMachineLogic* machineLogic() const;
|
---|
110 | UISession* uisession() const;
|
---|
111 | CSession& session();
|
---|
112 | QSize sizeHint() const;
|
---|
113 | int contentsX() const;
|
---|
114 | int contentsY() const;
|
---|
115 | int contentsWidth() const;
|
---|
116 | int contentsHeight() const;
|
---|
117 | int visibleWidth() const;
|
---|
118 | int visibleHeight() const;
|
---|
119 | ulong screenId() const { return m_uScreenId; }
|
---|
120 | UIFrameBuffer* frameBuffer() const { return m_pFrameBuffer; }
|
---|
121 | bool isMachineWindowResizeIgnored() const { return m_bIsMachineWindowResizeIgnored; }
|
---|
122 | const QPixmap& pauseShot() const { return m_pauseShot; }
|
---|
123 | QSize storedConsoleSize() const { return m_storedConsoleSize; }
|
---|
124 | DesktopGeo desktopGeometryType() const { return m_desktopGeometryType; }
|
---|
125 | QSize desktopGeometry() const;
|
---|
126 | QSize guestSizeHint();
|
---|
127 |
|
---|
128 | /* Protected setters: */
|
---|
129 | void setDesktopGeometry(DesktopGeo geometry, int iWidth, int iHeight);
|
---|
130 | void storeConsoleSize(int iWidth, int iHeight);
|
---|
131 | void setMachineWindowResizeIgnored(bool fIgnore = true) { m_bIsMachineWindowResizeIgnored = fIgnore; }
|
---|
132 | void storeGuestSizeHint(const QSize &sizeHint);
|
---|
133 |
|
---|
134 | /* Protected helpers: */
|
---|
135 | virtual void takePauseShotLive();
|
---|
136 | virtual void takePauseShotSnapshot();
|
---|
137 | virtual void resetPauseShot() { m_pauseShot = QPixmap(); }
|
---|
138 | virtual QRect workingArea() = 0;
|
---|
139 | virtual void calculateDesktopGeometry() = 0;
|
---|
140 | virtual void maybeRestrictMinimumSize() = 0;
|
---|
141 | virtual void updateSliders();
|
---|
142 | QPoint viewportToContents(const QPoint &vp) const;
|
---|
143 | void scrollBy(int dx, int dy);
|
---|
144 | static void dimImage(QImage &img);
|
---|
145 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
146 | void scrollContentsBy(int dx, int dy);
|
---|
147 | #endif /* VBOX_WITH_VIDEOHWACCEL */
|
---|
148 | #ifdef Q_WS_MAC
|
---|
149 | void updateDockIcon();
|
---|
150 | CGImageRef vmContentImage();
|
---|
151 | CGImageRef frameBuffertoCGImageRef(UIFrameBuffer *pFrameBuffer);
|
---|
152 | #endif /* Q_WS_MAC */
|
---|
153 |
|
---|
154 | /* Cross-platforms event processors: */
|
---|
155 | bool event(QEvent *pEvent);
|
---|
156 | bool eventFilter(QObject *pWatched, QEvent *pEvent);
|
---|
157 | void resizeEvent(QResizeEvent *pEvent);
|
---|
158 | void moveEvent(QMoveEvent *pEvent);
|
---|
159 | void paintEvent(QPaintEvent *pEvent);
|
---|
160 |
|
---|
161 | /* Platform specific event processors: */
|
---|
162 | #if defined(Q_WS_WIN)
|
---|
163 | bool winEvent(MSG *pMsg, long *puResult);
|
---|
164 | #elif defined(Q_WS_X11)
|
---|
165 | bool x11Event(XEvent *event);
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | /* Private members: */
|
---|
169 | UIMachineWindow *m_pMachineWindow;
|
---|
170 | ulong m_uScreenId;
|
---|
171 | UIFrameBuffer *m_pFrameBuffer;
|
---|
172 | KMachineState m_previousState;
|
---|
173 |
|
---|
174 | DesktopGeo m_desktopGeometryType;
|
---|
175 | QSize m_desktopGeometry;
|
---|
176 | QSize m_storedConsoleSize;
|
---|
177 |
|
---|
178 | bool m_bIsMachineWindowResizeIgnored : 1;
|
---|
179 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
180 | bool m_fAccelerate2DVideo : 1;
|
---|
181 | #endif /* VBOX_WITH_VIDEOHWACCEL */
|
---|
182 |
|
---|
183 | QPixmap m_pauseShot;
|
---|
184 |
|
---|
185 | /* Friend classes: */
|
---|
186 | friend class UIKeyboardHandler;
|
---|
187 | friend class UIMouseHandler;
|
---|
188 | friend class UIMachineLogic;
|
---|
189 | friend class UIFrameBuffer;
|
---|
190 | friend class UIFrameBufferQImage;
|
---|
191 | friend class UIFrameBufferQuartz2D;
|
---|
192 | friend class UIFrameBufferQGL;
|
---|
193 | template<class, class, class> friend class VBoxOverlayFrameBuffer;
|
---|
194 | };
|
---|
195 |
|
---|
196 | /* This maintenance class is a part of future roll-back mechanism.
|
---|
197 | * It allows to block main GUI thread until specific event received.
|
---|
198 | * Later it will become more abstract but now its just used to help
|
---|
199 | * fullscreen & seamless modes to restore normal guest size hint. */
|
---|
200 | class UIMachineViewBlocker : public QEventLoop
|
---|
201 | {
|
---|
202 | Q_OBJECT;
|
---|
203 |
|
---|
204 | public:
|
---|
205 |
|
---|
206 | UIMachineViewBlocker()
|
---|
207 | : QEventLoop(0)
|
---|
208 | , m_iTimerId(0)
|
---|
209 | {
|
---|
210 | /* Also start timer to unlock pool in case of
|
---|
211 | * required condition doesn't happens by some reason: */
|
---|
212 | m_iTimerId = startTimer(3000);
|
---|
213 | }
|
---|
214 |
|
---|
215 | virtual ~UIMachineViewBlocker()
|
---|
216 | {
|
---|
217 | /* Kill the timer: */
|
---|
218 | killTimer(m_iTimerId);
|
---|
219 | }
|
---|
220 |
|
---|
221 | protected:
|
---|
222 |
|
---|
223 | void timerEvent(QTimerEvent *pEvent)
|
---|
224 | {
|
---|
225 | /* If that timer event occurs => it seems
|
---|
226 | * guest resize event doesn't comes in time,
|
---|
227 | * shame on it, but we just unlocking 'this': */
|
---|
228 | QEventLoop::timerEvent(pEvent);
|
---|
229 | exit();
|
---|
230 | }
|
---|
231 |
|
---|
232 | int m_iTimerId;
|
---|
233 | };
|
---|
234 |
|
---|
235 | #endif // !___UIMachineView_h___
|
---|